Rename arch "x86" to "i386"

This commit is contained in:
Alex Kotov 2020-12-08 07:56:38 +05:00
parent 41c51275be
commit b91a0306b5
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
9 changed files with 136 additions and 136 deletions

View File

@ -21,8 +21,8 @@ libkernaux_a_SOURCES = \
src/printf.c \
src/stdlib.c
if ARCH_X86
libkernaux_a_SOURCES += src/arch/x86.S
if ARCH_I386
libkernaux_a_SOURCES += src/arch/i386.S
endif
if ARCH_X86_64

View File

@ -46,10 +46,10 @@ Configure with cross-compiler in `$PATH` to make without it in `$PATH`:
```
./configure \
--host=x86-elf \
AR="$(which x86-elf-ar)" \
CC="$(which x86-elf-gcc)" \
RANLIB="$(which x86-elf-ranlib)" \
--host=i386-elf \
AR="$(which i386-elf-ar)" \
CC="$(which i386-elf-gcc)" \
RANLIB="$(which i386-elf-ranlib)" \
CFLAGS='-ffreestanding -nostdlib -fno-builtin -fno-stack-protector'
```
@ -93,39 +93,39 @@ just `make && sudo make install`. Instead use the following commands:
* `sudo make install-exec`
* `sudo make install-data`
Check if compilation targets x86: `objdump -d src/arch/x86.o`. It should
Check if compilation targets i386: `objdump -d src/arch/i386.o`. It should
output something like this:
```
src/arch/x86.o: file format elf32-i386
src/arch/i386.o: file format elf32-i386
Disassembly of section .text:
00000000 <kernaux_arch_x86_hang>:
00000000 <kernaux_arch_i386_hang>:
0: fa cli
1: f4 hlt
2: eb fc jmp 0 <kernaux_arch_x86_hang>
2: eb fc jmp 0 <kernaux_arch_i386_hang>
00000004 <kernaux_arch_x86_read_cr0>:
00000004 <kernaux_arch_i386_read_cr0>:
4: 0f 20 c0 mov %cr0,%eax
7: c3 ret
00000008 <kernaux_arch_x86_read_cr4>:
00000008 <kernaux_arch_i386_read_cr4>:
8: 0f 20 e0 mov %cr4,%eax
b: c3 ret
0000000c <kernaux_arch_x86_write_cr0>:
0000000c <kernaux_arch_i386_write_cr0>:
c: 8b 44 24 04 mov 0x4(%esp),%eax
10: 0f 22 c0 mov %eax,%cr0
13: c3 ret
00000014 <kernaux_arch_x86_write_cr3>:
00000014 <kernaux_arch_i386_write_cr3>:
14: 8b 44 24 04 mov 0x4(%esp),%eax
18: 0f 22 d8 mov %eax,%cr3
1b: c3 ret
0000001c <kernaux_arch_x86_write_cr4>:
0000001c <kernaux_arch_i386_write_cr4>:
1c: 8b 44 24 04 mov 0x4(%esp),%eax
20: 0f 22 e0 mov %eax,%cr4
23: c3 ret

View File

@ -15,14 +15,14 @@ AC_ARG_ENABLE([console], AS_HELP_STRING([--disable-console], [disable seri
AC_ARG_ENABLE([multiboot2], AS_HELP_STRING([--disable-multiboot2], [disable Multiboot 2 information parser]))
AC_ARG_ENABLE([pfa], AS_HELP_STRING([--disable-pfa], [disable Page Frame Allocator]))
AM_CONDITIONAL([ARCH_X86], [test "$host_cpu" = x86])
AM_CONDITIONAL([ARCH_I386], [test "$host_cpu" = i386])
AM_CONDITIONAL([ARCH_X86_64], [test "$host_cpu" = x86_64])
AM_CONDITIONAL([ENABLE_CMDLINE], [test "$enable_cmdline" != no])
AM_CONDITIONAL([ENABLE_CONSOLE], [test "$enable_console" != no])
AM_CONDITIONAL([ENABLE_MULTIBOOT2], [test "$enable_multiboot2" != no])
AM_CONDITIONAL([ENABLE_PFA], [test "$enable_pfa" != no])
AS_IF([test "$host_cpu" = x86], [AC_DEFINE([ARCH_X86], [1], [architecture is x86])])
AS_IF([test "$host_cpu" = i386], [AC_DEFINE([ARCH_I386], [1], [architecture is i386])])
AS_IF([test "$host_cpu" = x86_64], [AC_DEFINE([ARCH_X86_64], [1], [architecture is x86_64])])
AS_IF([test "$enable_cmdline" != no], [AC_DEFINE([ENABLE_CMDLINE], [1], [enabled command line parser])])
AS_IF([test "$enable_console" != no], [AC_DEFINE([ENABLE_CONSOLE], [1], [enabled serial console])])

View File

@ -1,5 +1,5 @@
nobase_include_HEADERS = \
kernaux/arch/x86.h \
kernaux/arch/i386.h \
kernaux/arch/x86_64.h \
kernaux/cmdline.h \
kernaux/console.h \

View File

@ -0,0 +1,76 @@
#ifndef KERNAUX_INCLUDED_ARCH_I386
#define KERNAUX_INCLUDED_ARCH_I386 1
#ifdef __cplusplus
extern "C" {
#endif
inline static unsigned char kernaux_arch_i386_inportb(unsigned short port);
inline static unsigned short kernaux_arch_i386_inportw(unsigned short port);
inline static unsigned int kernaux_arch_i386_inportd(unsigned short port);
inline static void
kernaux_arch_i386_outportb(unsigned short port, unsigned char value);
inline static void
kernaux_arch_i386_outportw(unsigned short port, unsigned short value);
inline static void
kernaux_arch_i386_outportd(unsigned short port, unsigned int value);
void kernaux_arch_i386_hang() __attribute__((noreturn));
unsigned long kernaux_arch_i386_read_cr0();
unsigned long kernaux_arch_i386_read_cr4();
void kernaux_arch_i386_write_cr0(volatile unsigned long value);
void kernaux_arch_i386_write_cr3(volatile unsigned long value);
void kernaux_arch_i386_write_cr4(volatile unsigned long value);
unsigned char kernaux_arch_i386_inportb(const unsigned short port)
{
register unsigned char result;
__asm__ volatile("inb %1, %0" : "=a" (result) : "dN" (port));
return result;
}
unsigned short kernaux_arch_i386_inportw(const unsigned short port)
{
register unsigned short result;
__asm__ volatile("inw %1, %0" : "=a" (result) : "dN" (port));
return result;
}
unsigned int kernaux_arch_i386_inportd(const unsigned short port)
{
register unsigned int result;
__asm__ volatile("ind %1, %0" : "=a" (result) : "dN" (port));
return result;
}
void kernaux_arch_i386_outportb(
const unsigned short port,
const unsigned char value
) {
__asm__ volatile("outb %1, %0" : : "dN" (port), "a" (value));
}
void kernaux_arch_i386_outportw(
const unsigned short port,
const unsigned short value
) {
__asm__ volatile("outw %1, %0" : : "dN" (port), "a" (value));
}
void kernaux_arch_i386_outportd(
const unsigned short port,
const unsigned int value
) {
__asm__ volatile("outd %1, %0" : : "dN" (port), "a" (value));
}
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,76 +0,0 @@
#ifndef KERNAUX_INCLUDED_ARCH_X86
#define KERNAUX_INCLUDED_ARCH_X86 1
#ifdef __cplusplus
extern "C" {
#endif
inline static unsigned char kernaux_arch_x86_inportb(unsigned short port);
inline static unsigned short kernaux_arch_x86_inportw(unsigned short port);
inline static unsigned int kernaux_arch_x86_inportd(unsigned short port);
inline static void
kernaux_arch_x86_outportb(unsigned short port, unsigned char value);
inline static void
kernaux_arch_x86_outportw(unsigned short port, unsigned short value);
inline static void
kernaux_arch_x86_outportd(unsigned short port, unsigned int value);
void kernaux_arch_x86_hang() __attribute__((noreturn));
unsigned long kernaux_arch_x86_read_cr0();
unsigned long kernaux_arch_x86_read_cr4();
void kernaux_arch_x86_write_cr0(volatile unsigned long value);
void kernaux_arch_x86_write_cr3(volatile unsigned long value);
void kernaux_arch_x86_write_cr4(volatile unsigned long value);
unsigned char kernaux_arch_x86_inportb(const unsigned short port)
{
register unsigned char result;
__asm__ volatile("inb %1, %0" : "=a" (result) : "dN" (port));
return result;
}
unsigned short kernaux_arch_x86_inportw(const unsigned short port)
{
register unsigned short result;
__asm__ volatile("inw %1, %0" : "=a" (result) : "dN" (port));
return result;
}
unsigned int kernaux_arch_x86_inportd(const unsigned short port)
{
register unsigned int result;
__asm__ volatile("ind %1, %0" : "=a" (result) : "dN" (port));
return result;
}
void kernaux_arch_x86_outportb(
const unsigned short port,
const unsigned char value
) {
__asm__ volatile("outb %1, %0" : : "dN" (port), "a" (value));
}
void kernaux_arch_x86_outportw(
const unsigned short port,
const unsigned short value
) {
__asm__ volatile("outw %1, %0" : : "dN" (port), "a" (value));
}
void kernaux_arch_x86_outportd(
const unsigned short port,
const unsigned int value
) {
__asm__ volatile("outd %1, %0" : : "dN" (port), "a" (value));
}
#ifdef __cplusplus
}
#endif
#endif

38
src/arch/i386.S Normal file
View File

@ -0,0 +1,38 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
.global kernaux_arch_i386_hang
.global kernaux_arch_i386_read_cr0
.global kernaux_arch_i386_read_cr4
.global kernaux_arch_i386_write_cr0
.global kernaux_arch_i386_write_cr3
.global kernaux_arch_i386_write_cr4
kernaux_arch_i386_hang:
cli
hlt
jmp kernaux_arch_i386_hang
kernaux_arch_i386_read_cr0:
mov %cr0, %eax
ret
kernaux_arch_i386_read_cr4:
mov %cr4, %eax
ret
kernaux_arch_i386_write_cr0:
mov 4(%esp), %eax
mov %eax, %cr0
ret
kernaux_arch_i386_write_cr3:
mov 4(%esp), %eax
mov %eax, %cr3
ret
kernaux_arch_i386_write_cr4:
mov 4(%esp), %eax
mov %eax, %cr4
ret

View File

@ -1,38 +0,0 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
.global kernaux_arch_x86_hang
.global kernaux_arch_x86_read_cr0
.global kernaux_arch_x86_read_cr4
.global kernaux_arch_x86_write_cr0
.global kernaux_arch_x86_write_cr3
.global kernaux_arch_x86_write_cr4
kernaux_arch_x86_hang:
cli
hlt
jmp kernaux_arch_x86_hang
kernaux_arch_x86_read_cr0:
mov %cr0, %eax
ret
kernaux_arch_x86_read_cr4:
mov %cr4, %eax
ret
kernaux_arch_x86_write_cr0:
mov 4(%esp), %eax
mov %eax, %cr0
ret
kernaux_arch_x86_write_cr3:
mov 4(%esp), %eax
mov %eax, %cr3
ret
kernaux_arch_x86_write_cr4:
mov 4(%esp), %eax
mov %eax, %cr4
ret

View File

@ -2,8 +2,8 @@
#include "config.h"
#endif
#ifdef ARCH_X86
#include <kernaux/arch/x86.h>
#ifdef ARCH_I386
#include <kernaux/arch/i386.h>
#endif
#include <kernaux/console.h>
@ -17,8 +17,8 @@ void kernaux_console_print(const char *const s)
void kernaux_console_putc(const char c __attribute__((unused)))
{
#ifdef ARCH_X86
kernaux_arch_x86_outportb(0x3F8, c);
#ifdef ARCH_I386
kernaux_arch_i386_outportb(0x3F8, c);
#endif
}