diff --git a/Makefile b/Makefile index cb3156b..388b52f 100644 --- a/Makefile +++ b/Makefile @@ -2,13 +2,12 @@ run_kernel: compile_kernel qemu-system-i386 -kernel target/kernel.bin compile_kernel: - nasm -f bin kernel/boot.asm -o target/kernel_boot.o + nasm -felf32 kernel/boot.asm -o target/boot.o i686-elf-gcc -c kernel/kernel.c -o target/kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra - i686-elf-gcc -T kernel/linker.ld -o target/kernel.bin -ffreestanding -O2 -nostdlib target/kernel_boot.o target/kernel.o -lgcc + i686-elf-gcc -T kernel/linker.ld -o target/kernel.bin -ffreestanding -O2 -nostdlib target/boot.o target/kernel.o -lgcc -compile_bootloader: +compile_bootloader: compile_kernel rm -rf target/boot.bin - nasm -f bin bootloader/test_kernel.asm -o target/kernel.bin nasm -f bin -o target/boot.bin bootloader/main.asm run_bootloader: compile_bootloader diff --git a/bootloader/main.asm b/bootloader/main.asm index ef517f2..06a0fac 100644 --- a/bootloader/main.asm +++ b/bootloader/main.asm @@ -219,7 +219,19 @@ mov ss, ax ; set up stack mov esp, 0x090000 -jmp 0x08:0x8000 +; load offset from ELF file +; mind the differing endian +mov edx, 0x8018 +mov ah, [ds:edx+2] +mov al, [ds:edx+3] +shl eax, 16 +mov ah, [ds:edx] +mov al, [ds:edx+1] + +; add the beginning 0x8000 +add eax, 0x8000 + +jmp eax .end: jmp .end diff --git a/kernel/kernel.c b/kernel/kernel.c index 86f55e7..8a7e29e 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -110,9 +110,9 @@ void kernel_main(void) terminal_initialize(); /* Newline support is left as an exercise. */ - terminal_writestring("Hello, "); - terminal_setcolor(vga_entry_color(VGA_COLOR_GREEN, VGA_COLOR_BLACK)); - terminal_writestring("kernel"); - terminal_setcolor(vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK)); - terminal_writestring(" World!\n"); + // terminal_writestring("Hello, "); + // terminal_setcolor(vga_entry_color(VGA_COLOR_GREEN, VGA_COLOR_BLACK)); + // terminal_writestring("kernel"); + // terminal_setcolor(vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK)); + // terminal_writestring(" World!\n"); } \ No newline at end of file diff --git a/kernel/linker.ld b/kernel/linker.ld index 7292df5..846b2ec 100644 --- a/kernel/linker.ld +++ b/kernel/linker.ld @@ -6,9 +6,8 @@ ENTRY(_start) kernel image. */ SECTIONS { - /* Begin putting sections at 1 MiB, a conventional place for kernels to be - loaded at by the bootloader. */ - . = 1M; + /* Set this to 0, so the program entry is the relative position to the start of the kernel */ + . = 0; /* First put the multiboot header, as it is required to be put very early early in the image or the bootloader won't recognize the file format.