diff --git a/Makefile.am b/Makefile.am index 862c82d..f415210 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/README.md b/README.md index eb35ed6..32219f9 100644 --- a/README.md +++ b/README.md @@ -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 : +00000000 : 0: fa cli 1: f4 hlt - 2: eb fc jmp 0 + 2: eb fc jmp 0 -00000004 : +00000004 : 4: 0f 20 c0 mov %cr0,%eax 7: c3 ret -00000008 : +00000008 : 8: 0f 20 e0 mov %cr4,%eax b: c3 ret -0000000c : +0000000c : c: 8b 44 24 04 mov 0x4(%esp),%eax 10: 0f 22 c0 mov %eax,%cr0 13: c3 ret -00000014 : +00000014 : 14: 8b 44 24 04 mov 0x4(%esp),%eax 18: 0f 22 d8 mov %eax,%cr3 1b: c3 ret -0000001c : +0000001c : 1c: 8b 44 24 04 mov 0x4(%esp),%eax 20: 0f 22 e0 mov %eax,%cr4 23: c3 ret diff --git a/configure.ac b/configure.ac index a055f9c..4c4c5c4 100644 --- a/configure.ac +++ b/configure.ac @@ -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])]) diff --git a/include/Makefile.am b/include/Makefile.am index 05837cd..603326e 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -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 \ diff --git a/include/kernaux/arch/i386.h b/include/kernaux/arch/i386.h new file mode 100644 index 0000000..7c5e102 --- /dev/null +++ b/include/kernaux/arch/i386.h @@ -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 diff --git a/include/kernaux/arch/x86.h b/include/kernaux/arch/x86.h deleted file mode 100644 index cfa3745..0000000 --- a/include/kernaux/arch/x86.h +++ /dev/null @@ -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 diff --git a/src/arch/i386.S b/src/arch/i386.S new file mode 100644 index 0000000..2ac0b5b --- /dev/null +++ b/src/arch/i386.S @@ -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 diff --git a/src/arch/x86.S b/src/arch/x86.S deleted file mode 100644 index d3534a8..0000000 --- a/src/arch/x86.S +++ /dev/null @@ -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 diff --git a/src/console.c b/src/console.c index 0d21763..fdf4334 100644 --- a/src/console.c +++ b/src/console.c @@ -2,8 +2,8 @@ #include "config.h" #endif -#ifdef ARCH_X86 -#include +#ifdef ARCH_I386 +#include #endif #include @@ -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 }