This commit is contained in:
Adrien Bourmault 2019-03-08 09:44:09 +01:00
parent cd0913ed13
commit ce5e04acd5
4 changed files with 42 additions and 36 deletions

View File

@ -90,15 +90,19 @@ make_disk:
testloader: loader testloader: loader
@qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -enable-kvm 2> qemu.log & @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 & @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 & @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 boot: make_disk boot.mbr loader
@echo ${CL2}[[boot]]${CL} Terminated without error.${CL3} @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 @x86_64-elf-objcopy -I elf64-x86-64 -O elf32-i386 $(OBJDIR)/boot/kaleid.x86_64 $(BINDIR)/kaleid
clean: clean:
rm -Rf $(BINDIR)/* @rm -Rf $(BINDIR)/*
rm -Rf $(OBJDIR)/*/*/*/*.o @rm -Rf $(OBJDIR)/*/*/*/*.o

View File

@ -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 OS/K being intended to only run on x86-64 systems, we have not divided
this folder into one sub-folder per architecture. 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 The bootloader itself is external to the OS/K project. We are using GRUB 2 to
our kernel loader in memory. load our kernel loader in memory.
The kernel loader, that we call the loader, is the main subject of this folder. 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 This loader is linked whith the kernel and loaded by Grub at the specified
prepare it for the hard work it have to do : address and prepare it for the hard work it have to do :
- Parsing the ELF64 - Check the multiboot state
- Load the kernel - Check if CPUID and long mode is supported
- Prepare a structure for it with memory map, cpu infos, and other devices infos. - Send a structure for it with memory map, cpu infos, and other devices
infos, prepared by GRUB.
- Switch into long mode

View File

@ -52,10 +52,10 @@ MB_start:
popf popf
push eax ; 2nd argument is magic number push eax ; 2nd argument is magic number
push ebx ; 1st argument multiboot info pointer push ebx ; 1st argument multiboot info pointer
mov ecx, eax mov ecx, eax ; For debug
call _loader call _loader
add esp, 8 ; Cleanup arguments "A la MIPS" add esp, 8 ; Cleanup arguments "A la MIPS"
jmp Die ; Aufwiedersehen jmp Die ; Aufwiedersehen, but never used
;; THE HOLES ---------------------------------------------------------------- ;; ;; THE HOLES ---------------------------------------------------------------- ;;
; ---------------------------------------------------------------------------- ; ; ---------------------------------------------------------------------------- ;
@ -98,16 +98,20 @@ _loader:
LOGO: db 219, 219, 219, " OS/K", 0 LOGO: db 219, 219, 219, " OS/K", 0
lbegin: lbegin:
call MB_check call clear ; Clear the screen
call Check_cpuid ;; BEGIN OF CHECKLIST
call Is64Bits call MB_check ; Check Multiboot State
call CheckA20
call Setup_paging call Check_cpuid ; Check if cpuid supported
call Go64 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 bl, 0x0E
mov esi, LOGO mov esi, LOGO
call write32 call write32
@ -116,12 +120,11 @@ lbegin:
call disable_cursor call disable_cursor
lgdt [GDT64.pointer] lgdt [GDT64.pointer]
jmp GDT64.code:_loader64 jmp GDT64.code:_loader64 ; SWITCH
[BITS 64] [BITS 64]
x64_K db "Now in x64 long mode", 0x0A, 0x0D, 0x0
Salut db "Now in x64 long mode", 0x0A, 0x0D, 0x0
GoKernel db "Launching Kernel...", 0 GoKernel db "Launching Kernel...", 0
_loader64: _loader64:
@ -135,23 +138,21 @@ _loader64:
call bitemporize call bitemporize
mov qword [NextTRAM], TRAM+80*4 mov qword [NextTRAM], TRAM+80*4 ; Because we don't want to overwrite
;; Hello world ;; Hello world
mov bl, 0x0A mov bl, 0x0A
mov esi, Salut mov esi, x64_K
call write call write
;; Read ATA
mov bl, 0x0F mov bl, 0x0F
mov esi, GoKernel mov esi, GoKernel
call write call write
;mov ecx, 4000 ;; Launch the kernel !
call tritemporize call tritemporize ; Let time to see
extern StartKern extern StartKern
jmp StartKern jmp StartKern
;; We must never reach this point ------------------------------------------- ;;
jmp Die jmp Die

View File

@ -28,7 +28,7 @@
// //
// Entry point of the Kaleid kernel // 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 // We're not ready to deal with interrupts
DisableIRQs(); DisableIRQs();