Kernel: Replace i386 with i686

I don't really want to be working with i386 since it doesn't support
compare exchange instruction
This commit is contained in:
2024-03-26 02:48:26 +02:00
parent 93975fdc45
commit 99e30a4d7d
25 changed files with 31 additions and 26 deletions

21
kernel/arch/i686/GDT.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include <kernel/GDT.h>
namespace Kernel
{
GDT* GDT::create()
{
ASSERT_NOT_REACHED();
}
void GDT::write_entry(uint8_t, uint32_t, uint32_t, uint8_t, uint8_t)
{
ASSERT_NOT_REACHED();
}
void GDT::write_tss()
{
ASSERT_NOT_REACHED();
}
}

31
kernel/arch/i686/IDT.cpp Normal file
View File

@@ -0,0 +1,31 @@
#include <kernel/IDT.h>
namespace Kernel
{
IDT* IDT::create()
{
ASSERT_NOT_REACHED();
}
[[noreturn]] void IDT::force_triple_fault()
{
ASSERT_NOT_REACHED();
}
void IDT::register_irq_handler(uint8_t, Interruptable*)
{
ASSERT_NOT_REACHED();
}
void IDT::register_interrupt_handler(uint8_t, void (*)())
{
ASSERT_NOT_REACHED();
}
void IDT::register_syscall_handler(uint8_t, void (*)())
{
ASSERT_NOT_REACHED();
}
}

View File

@@ -0,0 +1,144 @@
#include <kernel/Memory/PageTable.h>
#include <kernel/Lock/SpinLock.h>
namespace Kernel
{
RecursiveSpinLock PageTable::s_fast_page_lock;
void PageTable::initialize()
{
ASSERT_NOT_REACHED();
}
PageTable& PageTable::kernel()
{
ASSERT_NOT_REACHED();
}
bool PageTable::is_valid_pointer(uintptr_t)
{
ASSERT_NOT_REACHED();
}
BAN::ErrorOr<PageTable*> PageTable::create_userspace()
{
ASSERT_NOT_REACHED();
}
PageTable::~PageTable()
{
ASSERT_NOT_REACHED();
}
void PageTable::unmap_page(vaddr_t)
{
ASSERT_NOT_REACHED();
}
void PageTable::unmap_range(vaddr_t, size_t)
{
ASSERT_NOT_REACHED();
}
void PageTable::map_range_at(paddr_t, vaddr_t, size_t, flags_t)
{
ASSERT_NOT_REACHED();
}
void PageTable::map_page_at(paddr_t, vaddr_t, flags_t)
{
ASSERT_NOT_REACHED();
}
paddr_t PageTable::physical_address_of(vaddr_t) const
{
ASSERT_NOT_REACHED();
}
PageTable::flags_t PageTable::get_page_flags(vaddr_t) const
{
ASSERT_NOT_REACHED();
}
bool PageTable::is_page_free(vaddr_t) const
{
ASSERT_NOT_REACHED();
}
bool PageTable::is_range_free(vaddr_t, size_t) const
{
ASSERT_NOT_REACHED();
}
bool PageTable::reserve_page(vaddr_t, bool)
{
ASSERT_NOT_REACHED();
}
bool PageTable::reserve_range(vaddr_t, size_t, bool)
{
ASSERT_NOT_REACHED();
}
vaddr_t PageTable::reserve_free_page(vaddr_t, vaddr_t)
{
ASSERT_NOT_REACHED();
}
vaddr_t PageTable::reserve_free_contiguous_pages(size_t, vaddr_t, vaddr_t)
{
ASSERT_NOT_REACHED();
}
void PageTable::load()
{
ASSERT_NOT_REACHED();
}
void PageTable::initial_load()
{
ASSERT_NOT_REACHED();
}
void PageTable::debug_dump()
{
ASSERT_NOT_REACHED();
}
uint64_t PageTable::get_page_data(vaddr_t) const
{
ASSERT_NOT_REACHED();
}
void PageTable::initialize_kernel()
{
ASSERT_NOT_REACHED();
}
void PageTable::map_kernel_memory()
{
ASSERT_NOT_REACHED();
}
void PageTable::prepare_fast_page()
{
ASSERT_NOT_REACHED();
}
void PageTable::invalidate(vaddr_t)
{
ASSERT_NOT_REACHED();
}
void PageTable::map_fast_page(paddr_t)
{
ASSERT_NOT_REACHED();
}
void PageTable::unmap_fast_page()
{
ASSERT_NOT_REACHED();
}
}

31
kernel/arch/i686/Signal.S Normal file
View File

@@ -0,0 +1,31 @@
.section .userspace, "aw"
// stack contains
// return address
// signal number
// signal handler
.global signal_trampoline
signal_trampoline:
ud2
pushl %ebp
movl %esp, %ebp
subl $8, %esp
pusha
movl 40(%esp), %edi
movl 36(%esp), %eax
subl $12, %esp
pushl %edi
call *%eax
addl $16, %esp
popa
leave
addl $8, %esp
ret

View File

@@ -0,0 +1,19 @@
.global sys_fork_trampoline
sys_fork_trampoline:
ud2
subl $4, %esp
pushl %ebx
pushl %ebp
call read_ip
testl %eax, %eax
je .done
subl $8, %esp
pushl %eax
pushl %esp
call sys_fork
addl $16, %esp
.done:
popl %ebp
popl %ebx
addl $4, %esp
ret

20
kernel/arch/i686/Thread.S Normal file
View File

@@ -0,0 +1,20 @@
# uint32_t read_ip()
.global read_ip
read_ip:
popl %eax
jmp *%eax
# void start_thread(uint32_t sp, uint32_t ip)
.global start_thread
start_thread:
ud2
# void continue_thread(uint32_t sp, uint32_t ip)
.global continue_thread
continue_thread:
ud2
# void thread_userspace_trampoline(uint32_t sp, uint32_t ip, int argc, char** argv, char** envp)
.global thread_userspace_trampoline
thread_userspace_trampoline:
ud2

268
kernel/arch/i686/boot.S Normal file
View File

@@ -0,0 +1,268 @@
.set PG_PRESENT, 1<<0
.set PG_READ_WRITE, 1<<1
.set PG_PAGE_SIZE, 1<<7
.set FB_WIDTH, 800
.set FB_HEIGHT, 600
.set FB_BPP, 32
#define KERNEL_OFFSET 0xC0000000
#define V2P(vaddr) ((vaddr) - KERNEL_OFFSET)
.code32
# multiboot2 header
.section .multiboot, "aw"
.align 8
multiboot2_start:
.long 0xE85250D6
.long 0
.long multiboot2_end - multiboot2_start
.long -(0xE85250D6 + (multiboot2_end - multiboot2_start))
# framebuffer tag
.align 8
.short 5
.short 0
.long 20
.long FB_WIDTH
.long FB_HEIGHT
.long FB_BPP
# legacy start
.align 8
.short 3
.short 0
.long 12
.long V2P(_start)
.align 8
.short 0
.short 0
.long 8
multiboot2_end:
.section .bananboot, "aw"
.align 8
bananboot_start:
.long 0xBABAB007
.long -(0xBABAB007 + FB_WIDTH + FB_HEIGHT + FB_BPP)
.long FB_WIDTH
.long FB_HEIGHT
.long FB_BPP
bananboot_end:
.section .bss, "aw", @nobits
boot_stack_bottom:
.skip 4096 * 4
boot_stack_top:
.global g_kernel_cmdline
g_kernel_cmdline:
.skip 4096
bootloader_magic:
.skip 8
bootloader_info:
.skip 8
.section .data
.align 4096
boot_pml4:
boot_pdpt_lo:
boot_pdpt_hi:
boot_pd:
boot_gdt:
.quad 0x0000000000000000 # null descriptor
.quad 0x00CF9A000000FFFF # kernel code
.quad 0x00CF92000000FFFF # kernel data
boot_gdtr:
.short . - boot_gdt - 1
.long V2P(boot_gdt)
.global g_ap_startup_done
g_ap_startup_done:
.byte 0
.global g_ap_running_count
g_ap_running_count:
.byte 0
.global g_ap_stack_loaded
g_ap_stack_loaded:
.byte 0
.section .text
has_cpuid:
pushfl
pushfl
xorl $0x00200000, (%esp)
popfl
pushfl
popl %eax
xorl (%esp), %eax
popfl
testl $0x00200000, %eax
ret
check_requirements:
call has_cpuid
jz .exit
ret
.exit:
jmp system_halt
enable_sse:
movl %cr0, %eax
andw $0xFFFB, %ax
orw $0x0002, %ax
movl %eax, %cr0
movl %cr4, %eax
orw $0x0600, %ax
movl %eax, %cr4
ret
initialize_paging:
# enable PAE
movl %cr4, %ecx
orl $0x20, %ecx
movl %ecx, %cr4
# set address of paging structures
movl $V2P(boot_pml4), %ecx
movl %ecx, %cr3
# enable paging
movl %cr0, %ecx
orl $0x80000000, %ecx
movl %ecx, %cr0
ret
.global _start
.type _start, @function
_start:
cli; cld
# Initialize stack and multiboot info
movl %eax, V2P(bootloader_magic)
movl %ebx, V2P(bootloader_info)
movl $V2P(boot_stack_top), %esp
call check_requirements
call enable_sse
call initialize_paging
# flush gdt
lgdt V2P(boot_gdtr)
ljmpl $0x08, $V2P(gdt_flush)
gdt_flush:
movw $0x10, %ax
movw %ax, %ds
movw %ax, %ss
movw %ax, %es
# move stack pointer to higher half
movl %esp, %esp
addl $KERNEL_OFFSET, %esp
# jump to higher half
leal higher_half, %ecx
jmp *%ecx
higher_half:
# call global constuctors
call _init
# call to the kernel itself (clear ebp for stacktrace)
xorl %ebp, %ebp
movl V2P(bootloader_magic), %edi
movl V2P(bootloader_info), %esi
call kernel_main
# call global destructors
call _fini
system_halt:
xchgw %bx, %bx
cli
1: hlt
jmp 1b
.section .ap_init, "ax"
.code16
.global ap_trampoline
ap_trampoline:
jmp 1f
.align 8
ap_stack_ptr:
.skip 4
1:
cli; cld
ljmpl $0x00, $ap_cs_clear
ap_cs_clear:
xorw %ax, %ax
movw %ax, %ds
# load ap gdt and enter protected mode
lgdt ap_gdtr
movl %cr0, %eax
orb $1, %al
movl %eax, %cr0
ljmpl $0x08, $ap_protected_mode
.code32
ap_protected_mode:
movw $0x10, %ax
movw %ax, %ds
movw %ax, %ss
movw %ax, %es
movl ap_stack_ptr, %esp
movb $1, V2P(g_ap_stack_loaded)
call V2P(enable_sse)
call V2P(initialize_paging)
# load boot gdt and enter long mode
lgdt V2P(boot_gdtr)
ljmpl $0x08, $ap_flush_gdt
ap_flush_gdt:
# move stack pointer to higher half
movl %esp, %esp
addl $KERNEL_OFFSET, %esp
# jump to higher half
leal ap_higher_half, %ecx
jmp *%ecx
ap_higher_half:
# clear rbp for stacktrace
xorl %ebp, %ebp
1: pause
cmpb $0, g_ap_startup_done
jz 1b
lock incb g_ap_running_count
call ap_main
jmp system_halt
ap_gdt:
.quad 0x0000000000000000 # null descriptor
.quad 0x00CF9A000000FFFF # 32 bit code
.quad 0x00CF92000000FFFF # 32 bit data
ap_gdtr:
.short . - ap_gdt - 1
.long ap_gdt

23
kernel/arch/i686/crt0.S Normal file
View File

@@ -0,0 +1,23 @@
.section .text
.global _start
_start:
# Set up end of the stack frame linked list.
movl $0, %ebp
pushl %ebp # rip=0
pushl %ebp # rbp=0
movl %esp, %ebp
# Prepare signals, memory allocation, stdio and such.
#call initialize_standard_library
# Run the global constructors.
call _init
# Run main
call main
# Terminate the process with the exit code.
movl %eax, %edi
call exit
.size _start, . - _start

16
kernel/arch/i686/crti.S Normal file
View File

@@ -0,0 +1,16 @@
/* x86 crti.s */
.section .init
.global _init
.type _init, @function
_init:
push %ebp
movl %esp, %ebp
/* gcc will nicely put the contents of crtbegin.o's .init section here. */
.section .fini
.global _fini
.type _fini, @function
_fini:
push %ebp
movl %esp, %ebp
/* gcc will nicely put the contents of crtbegin.o's .fini section here. */

10
kernel/arch/i686/crtn.S Normal file
View File

@@ -0,0 +1,10 @@
/* x86 crtn.s */
.section .init
/* gcc will nicely put the contents of crtend.o's .init section here. */
popl %ebp
ret
.section .fini
/* gcc will nicely put the contents of crtend.o's .fini section here. */
popl %ebp
ret

View File

@@ -0,0 +1,45 @@
ENTRY (_start)
KERNEL_OFFSET = 0xC0000000;
SECTIONS
{
. = 0xF000;
.ap_init ALIGN(4K) : AT(ADDR(.ap_init))
{
g_ap_init_addr = .;
*(.ap_init)
}
. = 0x00100000 + KERNEL_OFFSET;
g_kernel_start = .;
.text ALIGN(4K) : AT(ADDR(.text) - KERNEL_OFFSET)
{
g_kernel_execute_start = .;
*(.multiboot)
*(.bananboot)
*(.text.*)
}
.userspace ALIGN(4K) : AT(ADDR(.userspace) - KERNEL_OFFSET)
{
g_userspace_start = .;
*(.userspace)
g_userspace_end = .;
g_kernel_execute_end = .;
}
.rodata ALIGN(4K) : AT(ADDR(.rodata) - KERNEL_OFFSET)
{
*(.rodata.*)
}
.data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET)
{
*(.data)
}
.bss ALIGN(4K) : AT(ADDR(.bss) - KERNEL_OFFSET)
{
*(COMMON)
*(.bss)
}
g_kernel_end = .;
}