From ec7e798c70e54cf10e6dddf465cb7f741f760e79 Mon Sep 17 00:00:00 2001 From: EmulatedSeasons <89668582+EmulatedSeasons@users.noreply.github.com> Date: Thu, 18 Jan 2024 23:16:56 -0500 Subject: added beginning and end kernel symbols --- .bochsrc | 15 +++++++++++++++ .gitignore | 1 + kernel/arch/i386/boot.asm | 13 +++++++++++-- kernel/arch/i386/isr_handler.cpp | 2 +- kernel/arch/i386/linker.ld | 5 +++++ kernel/kernel.cpp | 17 ++++++----------- kernel/makefile | 2 +- libs/libck/libck.a | Bin 38554 -> 0 bytes libs/libck/printf.c | 1 - 9 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 .bochsrc delete mode 100644 libs/libck/libck.a diff --git a/.bochsrc b/.bochsrc new file mode 100644 index 0000000..8cd280b --- /dev/null +++ b/.bochsrc @@ -0,0 +1,15 @@ +ata0-master: type=cdrom, path="emuos.iso", status=inserted +boot: cdrom + +megs: 256 + +display_library: sdl2 +#display_library: sdl2, options="gui_debug" + +vga: extension=vbe + +magic_break: enabled=1 + +clock: sync=none, time0=local + +cpu: reset_on_triple_fault=0 diff --git a/.gitignore b/.gitignore index b20cc07..cc56a26 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ build/ *.iso *.o *.d +*.a # i have no idea what this is for bx_enh_dbg.ini diff --git a/kernel/arch/i386/boot.asm b/kernel/arch/i386/boot.asm index b5dfe11..494d3ba 100644 --- a/kernel/arch/i386/boot.asm +++ b/kernel/arch/i386/boot.asm @@ -30,10 +30,19 @@ _start: ; setup stack mov esp, stack_top - ; get multiboot header data (for memory map) - extern multiboot_main + ; push the multiboot header data into the stack for later use push eax push ebx + + ; setup paging (to map kernel to the higher half) + ;mov eax, 0 + ;mov cr3, eax + ;mov eax, cr0 + ;or eax, 0x80000001 + ;mov cr0, eax + + ; get multiboot header data (for memory map) + extern multiboot_main call multiboot_main extern _init diff --git a/kernel/arch/i386/isr_handler.cpp b/kernel/arch/i386/isr_handler.cpp index ba825dd..ac8fb49 100644 --- a/kernel/arch/i386/isr_handler.cpp +++ b/kernel/arch/i386/isr_handler.cpp @@ -10,7 +10,7 @@ extern "C" void exception_handler(int e) { //unsigned char errorcode[2]{((unsigned char) e) + 48}; //terminal_initialize(); - printf("Exception\n"); + printf("Exception %x\n", e); } #define PS2_DATA 0x60 diff --git a/kernel/arch/i386/linker.ld b/kernel/arch/i386/linker.ld index 24cfa84..bac95d2 100644 --- a/kernel/arch/i386/linker.ld +++ b/kernel/arch/i386/linker.ld @@ -5,6 +5,9 @@ SECTIONS { . = 1M; + /* Used to get the beginning and end address of the kernel */ + _begin = .; + /* code. multiboot header comes first */ .text BLOCK(4K) : ALIGN(4K) { @@ -30,4 +33,6 @@ SECTIONS *(COMMON) *(.bss) } + + _end = .; } \ No newline at end of file diff --git a/kernel/kernel.cpp b/kernel/kernel.cpp index 579e642..877f860 100644 --- a/kernel/kernel.cpp +++ b/kernel/kernel.cpp @@ -7,14 +7,10 @@ #include #include -// compiler and target check -#if defined(__linux__) -#error "you're not using a cross compiler" -#endif +// linker symbols +unsigned int _begin; +unsigned int _end; -#if !defined(__i386__) -#error "needs to be compiled using an ix86-elf cross compiler" -#endif extern "C" void kernel_main(void) { // Initialize terminal @@ -24,7 +20,6 @@ extern "C" void kernel_main(void) { //keyboard_init(); printf("Hello world!\n"); - printf("among\n"); - printf("balls\n"); - printf("a%db", 1); -} \ No newline at end of file + printf("a%db\n", 1); + printf("_begin: %x, _end: %x", &_begin, &_end); +} diff --git a/kernel/makefile b/kernel/makefile index a9407bd..88659d9 100644 --- a/kernel/makefile +++ b/kernel/makefile @@ -55,7 +55,7 @@ LINKLST += crtn.o -include $(DEPFILES) -.PHONY: all crt clean +.PHONY: all crt clean kernel.bin all: crti.o crtn.o kernel.bin diff --git a/libs/libck/libck.a b/libs/libck/libck.a deleted file mode 100644 index 1dba359..0000000 Binary files a/libs/libck/libck.a and /dev/null differ diff --git a/libs/libck/printf.c b/libs/libck/printf.c index fe45892..72a4749 100644 --- a/libs/libck/printf.c +++ b/libs/libck/printf.c @@ -15,7 +15,6 @@ static bool print(const char* data, size_t length) { // for %d and %x. static const char* itoa(unsigned int num, char* str, unsigned int base) { - asm("xchgw %bx, %bx"); int cou = 0; // nt if (num == 0) { // 0 -- cgit v1.2.3-70-g09d2