;=----------------------------------------------------------------------------=; ; GNU GPL OS/K ; ; ; ; Desc: Kernel 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 . ; ;=----------------------------------------------------------------------------=; %include "boot/loader/multiboot/header.inc" %include "boot/loader/multiboot/check.inc" %include "boot/loader/cpu/cpuid.inc" %include "boot/loader/mem/management.inc" %include "boot/loader/io/terminal.inc" %include "boot/loader/cpu/cpu.inc" %include "boot/loader/mem/structures.inc" [BITS 32] [global MB_start] [section .multiboot] ;; MAGNIFICENT MULTIBOOT HEADER FOR GRUB ------------------------------------ ;; MB_header: ALIGN 4 dd MB_HEADER_MAGIC dd MB_HEADER_FLAGS dd CHECKSUM [section .text] ;;MULTIBOOT POINT ENTRY 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 _loader add esp, 8 ; Cleanup arguments "A la MIPS" jmp Die ; Aufwiedersehen ;; THE HOLES ---------------------------------------------------------------- ;; ; ---------------------------------------------------------------------------- ; ; Prints 'ERR:XX' where 'XX' is the str in AX ; ; ---------------------------------------------------------------------------- ; Error: mov word [CODE], ax push esi mov bl, 0x0c mov esi, ERGO call write32 pop esi jmp Die ERGO : db 219, 219, 219, " Error " CODE : db "00" db 0x0 ; ---------------------------------------------------------------------------- ; ; Kills the mind of your computer to get it prostrated ; ; ---------------------------------------------------------------------------- ; Die: cli hlt ; die nooooow jmp $ ;; THE CODE ----------------------------------------------------------------- ;; ; ---------------------------------------------------------------------------- ; ; _loader ; ; ; ; This is the function that initiates the launch of OS/K. It verifies that ; ; Grub has properly loaded this loader and makes the appropriate setup so ; ; that the kernel will work properly ; ; ; ; Why this original design ? Because it works well and prevent us to cause ; ; triple faults by aligment error or too long jumps (yup, it can be a problem); ; ; ; ---------------------------------------------------------------------------- ; _loader: jmp lbegin LOGO: db 219, 219, 219, " OS/K", 0 lbegin: call MB_check call Check_cpuid call Is64Bits call CheckA20 call Setup_paging call Go64 push esi mov bl, 0x0E mov esi, LOGO call write32 pop esi call disable_cursor lgdt [GDT64.pointer] jmp GDT64.code:_loader64 [BITS 64] Salut db "Now in x64 long mode", 0x0A, 0x0D, 0x0 GoKernel db "Launching Kernel...", 0 _loader64: ;; Some cleanup mov ax, 0 mov ss, ax mov ds, ax mov es, ax mov fs, ax mov gs, ax call bitemporize mov qword [NextTRAM], TRAM+80*4 ;; Hello world mov bl, 0x0A mov esi, Salut call write ;; Read ATA mov bl, 0x0F mov esi, GoKernel call write ;mov ecx, 4000 call tritemporize extern StartKern jmp StartKern jmp Die