From ce5e04acd5f27d02c46553922307b6b9e20144d4 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Fri, 8 Mar 2019 09:44:09 +0100 Subject: [PATCH] clean-up --- Makefile | 19 +++++++++++-------- boot/folder.desc | 18 ++++++++++-------- boot/loader/loader.asm | 39 ++++++++++++++++++++------------------- kaleid/kernel/init/init.c | 2 +- 4 files changed, 42 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index b2f06ba..4157a4e 100644 --- a/Makefile +++ b/Makefile @@ -90,15 +90,19 @@ make_disk: testloader: loader @qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -enable-kvm 2> qemu.log & - @ndisasm $(OBJDIR)/boot/loader -b 32 > loader_dism.asm + @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm + @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm -testloader32: loader + +testloader: loader @qemu-system-i386 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -enable-kvm 2> qemu.log & - @ndisasm $(OBJDIR)/boot/loader -b 32 > loader_dism.asm + @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm + @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm -debugloader: loader +testloader: loader @qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -s -S -enable-kvm 2> qemu.log & - @ndisasm $(OBJDIR)/boot/loader -b 32 > loader_dism.asm + @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm + @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm boot: make_disk boot.mbr loader @echo ${CL2}[[boot]]${CL} Terminated without error.${CL3} @@ -111,6 +115,5 @@ link: @x86_64-elf-objcopy -I elf64-x86-64 -O elf32-i386 $(OBJDIR)/boot/kaleid.x86_64 $(BINDIR)/kaleid clean: - rm -Rf $(BINDIR)/* - rm -Rf $(OBJDIR)/*/*/*/*.o - + @rm -Rf $(BINDIR)/* + @rm -Rf $(OBJDIR)/*/*/*/*.o diff --git a/boot/folder.desc b/boot/folder.desc index 3eb3f85..e4a46a5 100644 --- a/boot/folder.desc +++ b/boot/folder.desc @@ -23,17 +23,19 @@ #=----------------------------------------------------------------------------=# -This folder contains the source for OS/K's bootloader. +This folder contains the source for OS/K's early loader. OS/K being intended to only run on x86-64 systems, we have not divided this folder into one sub-folder per architecture. -The bootloader itself is external to the OS/K project. We are using GRUB 2 to load -our kernel loader in memory. +The bootloader itself is external to the OS/K project. We are using GRUB 2 to + load our kernel loader in memory. The kernel loader, that we call the loader, is the main subject of this folder. -This loader is intended to load the ELF64 kernel at the specified address and -prepare it for the hard work it have to do : +This loader is linked whith the kernel and loaded by Grub at the specified +address and prepare it for the hard work it have to do : - - Parsing the ELF64 - - Load the kernel - - Prepare a structure for it with memory map, cpu infos, and other devices infos. + - Check the multiboot state + - Check if CPUID and long mode is supported + - Send a structure for it with memory map, cpu infos, and other devices +infos, prepared by GRUB. + - Switch into long mode diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index ef67137..8e30929 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -52,10 +52,10 @@ MB_start: popf push eax ; 2nd argument is magic number push ebx ; 1st argument multiboot info pointer - mov ecx, eax + mov ecx, eax ; For debug call _loader add esp, 8 ; Cleanup arguments "A la MIPS" - jmp Die ; Aufwiedersehen + jmp Die ; Aufwiedersehen, but never used ;; THE HOLES ---------------------------------------------------------------- ;; ; ---------------------------------------------------------------------------- ; @@ -98,16 +98,20 @@ _loader: LOGO: db 219, 219, 219, " OS/K", 0 lbegin: - call MB_check + call clear ; Clear the screen - call Check_cpuid - call Is64Bits - call CheckA20 + ;; BEGIN OF CHECKLIST + call MB_check ; Check Multiboot State - call Setup_paging - call Go64 + call Check_cpuid ; Check if cpuid supported + call Is64Bits ; Check if long mode available + call CheckA20 ; Check if A20 is correctly enable - push esi + ;; BEGIN OF WORK + call Setup_paging ; Enable paging + call Go64 ; Prepare switch into long mode + + push esi ; Print the logo mov bl, 0x0E mov esi, LOGO call write32 @@ -116,12 +120,11 @@ lbegin: call disable_cursor lgdt [GDT64.pointer] - jmp GDT64.code:_loader64 + jmp GDT64.code:_loader64 ; SWITCH [BITS 64] - -Salut db "Now in x64 long mode", 0x0A, 0x0D, 0x0 +x64_K db "Now in x64 long mode", 0x0A, 0x0D, 0x0 GoKernel db "Launching Kernel...", 0 _loader64: @@ -135,23 +138,21 @@ _loader64: call bitemporize - mov qword [NextTRAM], TRAM+80*4 + mov qword [NextTRAM], TRAM+80*4 ; Because we don't want to overwrite ;; Hello world mov bl, 0x0A - mov esi, Salut + mov esi, x64_K call write - - ;; Read ATA mov bl, 0x0F mov esi, GoKernel call write - ;mov ecx, 4000 - call tritemporize + ;; Launch the kernel ! + call tritemporize ; Let time to see extern StartKern jmp StartKern - +;; We must never reach this point ------------------------------------------- ;; jmp Die diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index d28a79d..c50108a 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -28,7 +28,7 @@ // // Entry point of the Kaleid kernel // -noreturn void StartKern(void) +noreturn void StartKern(void* multibooot_info, int multiboot_magic) { // We're not ready to deal with interrupts DisableIRQs();