From 99e30a4d7dc75e36d369ccbf1f821ec4f55770af Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 26 Mar 2024 02:48:26 +0200 Subject: [PATCH] Kernel: Replace i386 with i686 I don't really want to be working with i386 since it doesn't support compare exchange instruction --- LibELF/LibELF/LoadableELF.cpp | 2 +- LibELF/include/LibELF/ELF.h | 2 +- LibELF/include/LibELF/Types.h | 2 +- kernel/CMakeLists.txt | 22 ++++++++++---------- kernel/arch/{i386 => i686}/GDT.cpp | 0 kernel/arch/{i386 => i686}/IDT.cpp | 0 kernel/arch/{i386 => i686}/PageTable.cpp | 0 kernel/arch/{i386 => i686}/Signal.S | 2 ++ kernel/arch/{i386 => i686}/Syscall.S | 1 + kernel/arch/{i386 => i686}/Thread.S | 0 kernel/arch/{i386 => i686}/boot.S | 0 kernel/arch/{i386 => i686}/crt0.S | 0 kernel/arch/{i386 => i686}/crti.S | 0 kernel/arch/{i386 => i686}/crtn.S | 0 kernel/arch/{i386 => i686}/linker.ld | 0 kernel/include/kernel/Arch.h | 8 ++++--- kernel/include/kernel/FS/TmpFS/Definitions.h | 2 +- kernel/include/kernel/Memory/Types.h | 2 +- kernel/include/kernel/Processor.h | 2 +- kernel/kernel/Random.cpp | 2 +- kernel/kernel/Scheduler.cpp | 4 ++-- kernel/kernel/Thread.cpp | 2 +- libc/arch/{i386 => i686}/crt0.S | 0 libc/arch/{i386 => i686}/crti.S | 2 +- libc/arch/{i386 => i686}/crtn.S | 2 +- 25 files changed, 31 insertions(+), 26 deletions(-) rename kernel/arch/{i386 => i686}/GDT.cpp (100%) rename kernel/arch/{i386 => i686}/IDT.cpp (100%) rename kernel/arch/{i386 => i686}/PageTable.cpp (100%) rename kernel/arch/{i386 => i686}/Signal.S (98%) rename kernel/arch/{i386 => i686}/Syscall.S (98%) rename kernel/arch/{i386 => i686}/Thread.S (100%) rename kernel/arch/{i386 => i686}/boot.S (100%) rename kernel/arch/{i386 => i686}/crt0.S (100%) rename kernel/arch/{i386 => i686}/crti.S (100%) rename kernel/arch/{i386 => i686}/crtn.S (100%) rename kernel/arch/{i386 => i686}/linker.ld (100%) rename libc/arch/{i386 => i686}/crt0.S (100%) rename libc/arch/{i386 => i686}/crti.S (94%) rename libc/arch/{i386 => i686}/crtn.S (92%) diff --git a/LibELF/LibELF/LoadableELF.cpp b/LibELF/LibELF/LoadableELF.cpp index 83ef8ba35b..941929010d 100644 --- a/LibELF/LibELF/LoadableELF.cpp +++ b/LibELF/LibELF/LoadableELF.cpp @@ -86,7 +86,7 @@ namespace LibELF return BAN::Error::from_errno(ENOEXEC); } -#if ARCH(i386) +#if ARCH(i686) if (m_file_header.e_ident[EI_CLASS] != ELFCLASS32) #elif ARCH(x86_64) if (m_file_header.e_ident[EI_CLASS] != ELFCLASS64) diff --git a/LibELF/include/LibELF/ELF.h b/LibELF/include/LibELF/ELF.h index a36c9dd0b9..a3eea008b9 100644 --- a/LibELF/include/LibELF/ELF.h +++ b/LibELF/include/LibELF/ELF.h @@ -42,7 +42,7 @@ namespace LibELF const Elf32SectionHeader& section_header32(size_t) const; const char* lookup_section_name32(uint32_t) const; const char* lookup_string32(size_t, uint32_t) const; -#if ARCH(i386) +#if ARCH(i686) const Elf32FileHeader& file_header_native() const { return file_header32(); } const Elf32ProgramHeader& program_header_native(size_t index) const { return program_header32(index); } const Elf32SectionHeader& section_header_native(size_t index) const { return section_header32(index); } diff --git a/LibELF/include/LibELF/Types.h b/LibELF/include/LibELF/Types.h index bcaf0cc319..cf0c0a9ad2 100644 --- a/LibELF/include/LibELF/Types.h +++ b/LibELF/include/LibELF/Types.h @@ -155,7 +155,7 @@ namespace LibELF Elf64Xword p_align; }; -#if ARCH(i386) +#if ARCH(i686) using ElfNativeAddr = Elf32Addr; using ElfNativeOff = Elf32Off; using ElfNativeHalf = Elf32Half; diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 2fb59ab17d..f5344d73fd 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -4,7 +4,7 @@ project(kernel CXX C ASM) if("${BANAN_ARCH}" STREQUAL "x86_64") set(ELF_FORMAT elf64-x86-64) -elseif("${BANAN_ARCH}" STREQUAL "i386") +elseif("${BANAN_ARCH}" STREQUAL "i686") set(ELF_FORMAT elf32-i386) endif() @@ -120,16 +120,16 @@ if("${BANAN_ARCH}" STREQUAL "x86_64") ${LAI_SOURCES} kernel/lai_host.cpp ) -elseif("${BANAN_ARCH}" STREQUAL "i386") +elseif("${BANAN_ARCH}" STREQUAL "i686") set(KERNEL_SOURCES ${KERNEL_SOURCES} - arch/i386/boot.S - arch/i386/GDT.cpp - arch/i386/IDT.cpp - arch/i386/PageTable.cpp - arch/i386/Signal.S - arch/i386/Syscall.S - arch/i386/Thread.S + arch/i686/boot.S + arch/i686/GDT.cpp + arch/i686/IDT.cpp + arch/i686/PageTable.cpp + arch/i686/Signal.S + arch/i686/Syscall.S + arch/i686/Thread.S ) else() message(FATAL_ERROR "unsupported architecure ${BANAN_ARCH}") @@ -182,8 +182,8 @@ if("${BANAN_ARCH}" STREQUAL "x86_64") target_compile_options(kernel PUBLIC -mcmodel=kernel -mno-red-zone) target_link_options(kernel PUBLIC LINKER:-z,max-page-size=4096) target_link_options(kernel PUBLIC LINKER:-T,${CMAKE_CURRENT_SOURCE_DIR}/arch/x86_64/linker.ld) -elseif("${BANAN_ARCH}" STREQUAL "i386") - target_link_options(kernel PUBLIC LINKER:-T,${CMAKE_CURRENT_SOURCE_DIR}/arch/i386/linker.ld) +elseif("${BANAN_ARCH}" STREQUAL "i686") + target_link_options(kernel PUBLIC LINKER:-T,${CMAKE_CURRENT_SOURCE_DIR}/arch/i686/linker.ld) endif() target_link_options(kernel PUBLIC -ffreestanding -nostdlib) diff --git a/kernel/arch/i386/GDT.cpp b/kernel/arch/i686/GDT.cpp similarity index 100% rename from kernel/arch/i386/GDT.cpp rename to kernel/arch/i686/GDT.cpp diff --git a/kernel/arch/i386/IDT.cpp b/kernel/arch/i686/IDT.cpp similarity index 100% rename from kernel/arch/i386/IDT.cpp rename to kernel/arch/i686/IDT.cpp diff --git a/kernel/arch/i386/PageTable.cpp b/kernel/arch/i686/PageTable.cpp similarity index 100% rename from kernel/arch/i386/PageTable.cpp rename to kernel/arch/i686/PageTable.cpp diff --git a/kernel/arch/i386/Signal.S b/kernel/arch/i686/Signal.S similarity index 98% rename from kernel/arch/i386/Signal.S rename to kernel/arch/i686/Signal.S index 41a3b834a7..c22d1c4ce1 100644 --- a/kernel/arch/i386/Signal.S +++ b/kernel/arch/i686/Signal.S @@ -7,6 +7,8 @@ .global signal_trampoline signal_trampoline: + ud2 + pushl %ebp movl %esp, %ebp subl $8, %esp diff --git a/kernel/arch/i386/Syscall.S b/kernel/arch/i686/Syscall.S similarity index 98% rename from kernel/arch/i386/Syscall.S rename to kernel/arch/i686/Syscall.S index f4a40759b7..39f892016a 100644 --- a/kernel/arch/i386/Syscall.S +++ b/kernel/arch/i686/Syscall.S @@ -1,5 +1,6 @@ .global sys_fork_trampoline sys_fork_trampoline: + ud2 subl $4, %esp pushl %ebx pushl %ebp diff --git a/kernel/arch/i386/Thread.S b/kernel/arch/i686/Thread.S similarity index 100% rename from kernel/arch/i386/Thread.S rename to kernel/arch/i686/Thread.S diff --git a/kernel/arch/i386/boot.S b/kernel/arch/i686/boot.S similarity index 100% rename from kernel/arch/i386/boot.S rename to kernel/arch/i686/boot.S diff --git a/kernel/arch/i386/crt0.S b/kernel/arch/i686/crt0.S similarity index 100% rename from kernel/arch/i386/crt0.S rename to kernel/arch/i686/crt0.S diff --git a/kernel/arch/i386/crti.S b/kernel/arch/i686/crti.S similarity index 100% rename from kernel/arch/i386/crti.S rename to kernel/arch/i686/crti.S diff --git a/kernel/arch/i386/crtn.S b/kernel/arch/i686/crtn.S similarity index 100% rename from kernel/arch/i386/crtn.S rename to kernel/arch/i686/crtn.S diff --git a/kernel/arch/i386/linker.ld b/kernel/arch/i686/linker.ld similarity index 100% rename from kernel/arch/i386/linker.ld rename to kernel/arch/i686/linker.ld diff --git a/kernel/include/kernel/Arch.h b/kernel/include/kernel/Arch.h index ee3b2e7add..9c9692b8fb 100644 --- a/kernel/include/kernel/Arch.h +++ b/kernel/include/kernel/Arch.h @@ -1,11 +1,11 @@ #pragma once #define x86_64 1 -#define i386 2 +#define i686 2 #define ARCH(arch) (__arch == arch) -#if !defined(__arch) || (__arch != x86_64 && __arch != i386) +#if !defined(__arch) || (__arch != x86_64 && __arch != i686) #error "Unsupported architecture" #endif @@ -13,10 +13,12 @@ #define read_rsp(rsp) asm volatile("movq %%rsp, %0" : "=r"(rsp)) #define push_callee_saved() asm volatile("pushq %rbx; pushq %rbp; pushq %r12; pushq %r13; pushq %r14; pushq %r15") #define pop_callee_saved() asm volatile("popq %r15; popq %r14; popq %r13; popq %r12; popq %rbp; popq %rbx") -#else +#elif ARCH(i686) #define read_rsp(rsp) asm volatile("movl %%esp, %0" : "=r"(rsp)) #define push_callee_saved() asm volatile("pushal") #define pop_callee_saved() asm volatile("popal") +#else + #error #endif #include diff --git a/kernel/include/kernel/FS/TmpFS/Definitions.h b/kernel/include/kernel/FS/TmpFS/Definitions.h index bfbe33d3d1..e2e50772a7 100644 --- a/kernel/include/kernel/FS/TmpFS/Definitions.h +++ b/kernel/include/kernel/FS/TmpFS/Definitions.h @@ -28,7 +28,7 @@ namespace Kernel // 1x triply indirect BAN::Array block; static constexpr size_t direct_block_count = 2; -#elif ARCH(i386) +#elif ARCH(i686) // 14x direct blocks // 1x singly indirect // 1x doubly indirect diff --git a/kernel/include/kernel/Memory/Types.h b/kernel/include/kernel/Memory/Types.h index 5c06c52e7b..4911b70db1 100644 --- a/kernel/include/kernel/Memory/Types.h +++ b/kernel/include/kernel/Memory/Types.h @@ -4,7 +4,7 @@ #if ARCH(x86_64) #define KERNEL_OFFSET 0xFFFFFFFF80000000 -#elif ARCH(i386) +#elif ARCH(i686) #define KERNEL_OFFSET 0xC0000000 #else #error diff --git a/kernel/include/kernel/Processor.h b/kernel/include/kernel/Processor.h index f559f308d0..f01f116320 100644 --- a/kernel/include/kernel/Processor.h +++ b/kernel/include/kernel/Processor.h @@ -19,7 +19,7 @@ namespace Kernel using ProcessorID = uint32_t; constexpr ProcessorID PROCESSOR_NONE = 0xFFFFFFFF; -#if ARCH(x86_64) || ARCH(i386) +#if ARCH(x86_64) || ARCH(i686) class Processor { BAN_NON_COPYABLE(Processor); diff --git a/kernel/kernel/Random.cpp b/kernel/kernel/Random.cpp index 447019ed3d..ce65370494 100644 --- a/kernel/kernel/Random.cpp +++ b/kernel/kernel/Random.cpp @@ -22,7 +22,7 @@ namespace Kernel { #if ARCH(x86_64) asm volatile("rdrand %0" : "=r"(s_rand_seed)); -#elif ARCH(i386) +#elif ARCH(i686) uint32_t lo, hi; asm volatile( "rdrand %[lo];" diff --git a/kernel/kernel/Scheduler.cpp b/kernel/kernel/Scheduler.cpp index 4a64eae682..a2440e963d 100644 --- a/kernel/kernel/Scheduler.cpp +++ b/kernel/kernel/Scheduler.cpp @@ -21,7 +21,7 @@ namespace Kernel { #if ARCH(x86_64) asm volatile("movq %0, %%rsp" :: "rm"(Processor::current_stack_top())); -#elif ARCH(i386) +#elif ARCH(i686) asm volatile("movl %0, %%esp" :: "rm"(Processor::current_stack_top())); #else #error @@ -221,7 +221,7 @@ namespace Kernel "orq $(1 << 3), %rax;" "movq %rax, %cr0" ); -#elif ARCH(i386) +#elif ARCH(i686) asm volatile( "movl %cr0, %eax;" "orl $(1 << 3), %eax;" diff --git a/kernel/kernel/Thread.cpp b/kernel/kernel/Thread.cpp index d757673f78..413335adb6 100644 --- a/kernel/kernel/Thread.cpp +++ b/kernel/kernel/Thread.cpp @@ -111,7 +111,7 @@ namespace Kernel ); save_sse(); asm volatile("movq %0, %%cr0" :: "r"(cr0)); - #elif ARCH(i386) + #elif ARCH(i686) uintptr_t cr0; asm volatile( "movl %%cr0, %%eax;" diff --git a/libc/arch/i386/crt0.S b/libc/arch/i686/crt0.S similarity index 100% rename from libc/arch/i386/crt0.S rename to libc/arch/i686/crt0.S diff --git a/libc/arch/i386/crti.S b/libc/arch/i686/crti.S similarity index 94% rename from libc/arch/i386/crti.S rename to libc/arch/i686/crti.S index 75175fd594..64945d13a2 100644 --- a/libc/arch/i386/crti.S +++ b/libc/arch/i686/crti.S @@ -1,4 +1,4 @@ -/* i386 crti.s */ +/* i686 crti.s */ .section .init .global _init .type _init, @function diff --git a/libc/arch/i386/crtn.S b/libc/arch/i686/crtn.S similarity index 92% rename from libc/arch/i386/crtn.S rename to libc/arch/i686/crtn.S index 935c8d1b82..9adcd82053 100644 --- a/libc/arch/i386/crtn.S +++ b/libc/arch/i686/crtn.S @@ -1,4 +1,4 @@ -/* i386 crtn.s */ +/* i686 crtn.s */ .section .init /* gcc will nicely put the contents of crtend.o's .init section here. */ popl %ebp