;=----------------------------------------------------------------------------=; ; GNU GPL OS/K ; ; ; ; Desc: Kernel (second stage) Loader for OS/K ; ; (x86_64 architecture only) ; ; ; ; ; ; Copyright © 2018-2019 The OS/K Team ; ; ; ; This file is part of OS/K. ; ; ; ; OS/K is free software: you can redistribute it and/or modify ; ; it under the terms of the GNU General Public License as published by ; ; the Free Software Foundation, either version 3 of the License, or ; ; (at your option) any later version. ; ; ; ; OS/K is distributed in the hope that it will be useful, ; ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; ; GNU General Public License for more details. ; ; ; ; You should have received a copy of the GNU General Public License ; ; along with OS/K. If not, see . ; ;=----------------------------------------------------------------------------=; %define DEBUG [BITS 32] [global _start] [ORG 0x100000] ; Where GRUB loads us. %include "boot/loader/multiboot/header.inc" ;; Normal entry point, but a little bit unused since we never use it because... _start: mov ax, cs ; correcting cs after the horrible far jump mov ds, ax ; hm... And ds too mov es, ax ; And es because it is jealous ;mov [Bootdrv], dl xor dl, dl jmp 0x0000:main ; pas sûr ;; Magnificent multiboot header for GRUB ------------------------------------ ;; MB_header: align 4 dd MB_HEADER_MAGIC dd MB_HEADER_FLAGS dd CHECKSUM dd MB_header ; Header address dd _start ; Address of code entry point dd 00 ; (end of code) not necessary dd 00 ; (bss) not necessary dd MB_start ; entry address GRUB will start at ;; Multiboot entry point for Grub ------------------------------------------- ;; MB_start: mov esp, KERNEL_STACK ; Setup the stack push 0 ; Reset EFLAGS popf push eax ; 2nd argument is magic number push ebx ; 1st argument multiboot info pointer mov ecx, eax call main add esp, 8 ; Cleanup arguments "A la MIPS" jmp Die ; Aufwiedersehen ;; THE HOLES ---------------------------------------------------------------- ;; Error: mov dword [0xb8000], 0x4f524f45 mov dword [0xb8004], 0x4f3a4f52 mov dword [0xb8008], 0x4f204f20 mov byte [0xb800a], al jmp Die Die: cli hlt ; die nooooow ;jmp 0xF000:0xFFF0 jmp $ ;; THE CODE ----------------------------------------------------------------- ;; main: call MB_check call Check_cpuid call Is64Bits call Setup_paging ;; Registering paging mov eax, PML4_table mov cr3, eax ; Load PML4 to cr3 mov eax, cr4 or eax, 1 << 5 mov cr4, eax ; Enable PAE ;; Activate long mode mov ecx, 0xC0000080 ; address of MSR rdmsr ; read MSR or eax, 1 << 8 ; LME = 1. (Long Mode Enable) wrmsr ; write MSR ;; Enable paging mov eax, cr0 or eax, 1 << 31 ; make MSR bit 31 (PG = Paging) to 1 : ; |1|000000000000000000000000000000 ; | ; `------ Paging bit mov cr0, eax mov dword [0xb8000], 0x2f4b2f4f ret ;; INCLUDES ----------------------------------------------------------------- ;; %include "boot/loader/cpu/cpuid.inc" %include "boot/loader/multiboot/check.inc" %include "boot/loader/mem/structures.inc" %include "boot/loader/mem/management.inc"