2019-01-16 11:04:44 +01:00
|
|
|
;=----------------------------------------------------------------------------=;
|
|
|
|
; GNU GPL OS/K ;
|
|
|
|
; ;
|
2019-03-08 08:43:44 +01:00
|
|
|
; Desc: Kernel Loader for OS/K ;
|
2019-01-16 11:04:44 +01:00
|
|
|
; (x86_64 architecture only) ;
|
2019-02-06 15:34:39 +01:00
|
|
|
; ;
|
|
|
|
; ;
|
|
|
|
; 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 <https://www.gnu.org/licenses/>. ;
|
2019-01-16 11:04:44 +01:00
|
|
|
;=----------------------------------------------------------------------------=;
|
|
|
|
|
2019-03-08 08:43:44 +01:00
|
|
|
%include "boot/loader/multiboot/header.inc"
|
|
|
|
%include "boot/loader/multiboot/check.inc"
|
2019-03-09 21:46:09 +01:00
|
|
|
%include "boot/loader/cpu/cpu32.inc"
|
2019-03-08 08:43:44 +01:00
|
|
|
%include "boot/loader/mem/management.inc"
|
|
|
|
%include "boot/loader/io/terminal.inc"
|
|
|
|
%include "boot/loader/cpu/cpu.inc"
|
|
|
|
%include "boot/loader/mem/structures.inc"
|
2019-01-17 14:09:08 +01:00
|
|
|
|
2019-02-12 14:58:26 +01:00
|
|
|
[BITS 32]
|
2019-03-08 08:43:44 +01:00
|
|
|
[global MB_start]
|
2019-02-12 14:58:26 +01:00
|
|
|
|
2019-03-08 08:43:44 +01:00
|
|
|
[section .multiboot]
|
2019-02-12 14:58:26 +01:00
|
|
|
|
2019-03-06 20:05:18 +01:00
|
|
|
;; MAGNIFICENT MULTIBOOT HEADER FOR GRUB ------------------------------------ ;;
|
2019-03-06 20:05:18 +01:00
|
|
|
MB_header:
|
2019-03-08 08:43:44 +01:00
|
|
|
ALIGN 4
|
2019-02-15 15:47:56 +01:00
|
|
|
dd MB_HEADER_MAGIC
|
|
|
|
dd MB_HEADER_FLAGS
|
|
|
|
dd CHECKSUM
|
2019-02-12 14:58:26 +01:00
|
|
|
|
2019-03-08 08:43:44 +01:00
|
|
|
[section .text]
|
|
|
|
|
|
|
|
;;MULTIBOOT POINT ENTRY FOR GRUB ------------------------------------------- ;;
|
2019-02-12 14:58:26 +01:00
|
|
|
MB_start:
|
2019-03-06 20:05:18 +01:00
|
|
|
mov esp, KERNEL_STACK ; Setup the stack
|
|
|
|
push 0 ; Reset EFLAGS
|
2019-02-12 14:58:26 +01:00
|
|
|
popf
|
2019-03-06 20:05:18 +01:00
|
|
|
push eax ; 2nd argument is magic number
|
|
|
|
push ebx ; 1st argument multiboot info pointer
|
2019-03-08 09:44:09 +01:00
|
|
|
mov ecx, eax ; For debug
|
2019-03-06 20:05:18 +01:00
|
|
|
call _loader
|
2019-03-06 20:05:18 +01:00
|
|
|
add esp, 8 ; Cleanup arguments "A la MIPS"
|
2019-03-08 09:44:09 +01:00
|
|
|
jmp Die ; Aufwiedersehen, but never used
|
2019-01-16 11:04:44 +01:00
|
|
|
|
2019-03-06 20:05:18 +01:00
|
|
|
;; THE HOLES ---------------------------------------------------------------- ;;
|
2019-03-06 20:05:18 +01:00
|
|
|
; ---------------------------------------------------------------------------- ;
|
|
|
|
; Prints 'ERR:XX' where 'XX' is the str in AX ;
|
|
|
|
; ---------------------------------------------------------------------------- ;
|
2019-03-06 20:05:18 +01:00
|
|
|
Error:
|
2019-03-08 08:43:44 +01:00
|
|
|
mov word [CODE], ax
|
|
|
|
push esi
|
|
|
|
mov bl, 0x0c
|
|
|
|
mov esi, ERGO
|
|
|
|
call write32
|
|
|
|
pop esi
|
2019-03-06 20:05:18 +01:00
|
|
|
jmp Die
|
2019-03-08 21:15:10 +01:00
|
|
|
ERGO : db "A", 219, 219, " Error "
|
2019-03-08 08:43:44 +01:00
|
|
|
CODE : db "00"
|
|
|
|
db 0x0
|
2019-03-06 20:05:18 +01:00
|
|
|
; ---------------------------------------------------------------------------- ;
|
|
|
|
; Kills the mind of your computer to get it prostrated ;
|
|
|
|
; ---------------------------------------------------------------------------- ;
|
2019-01-16 11:04:44 +01:00
|
|
|
Die:
|
|
|
|
cli
|
2019-03-06 20:05:18 +01:00
|
|
|
hlt ; die nooooow
|
2019-03-06 20:05:18 +01:00
|
|
|
jmp $
|
2019-01-16 11:04:44 +01:00
|
|
|
|
2019-03-06 20:05:18 +01:00
|
|
|
;; THE CODE ----------------------------------------------------------------- ;;
|
2019-03-06 20:05:18 +01:00
|
|
|
; ---------------------------------------------------------------------------- ;
|
|
|
|
; _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
|
|
|
|
|
2019-03-08 08:43:44 +01:00
|
|
|
LOGO: db 219, 219, 219, " OS/K", 0
|
2019-03-06 20:05:18 +01:00
|
|
|
|
2019-03-06 20:05:18 +01:00
|
|
|
lbegin:
|
2019-03-08 09:44:09 +01:00
|
|
|
call clear ; Clear the screen
|
2019-03-06 20:05:18 +01:00
|
|
|
|
2019-03-08 09:44:09 +01:00
|
|
|
;; BEGIN OF CHECKLIST
|
|
|
|
call MB_check ; Check Multiboot State
|
2019-03-06 20:05:18 +01:00
|
|
|
|
2019-03-08 09:44:09 +01:00
|
|
|
call Check_cpuid ; Check if cpuid supported
|
|
|
|
call Is64Bits ; Check if long mode available
|
|
|
|
call CheckA20 ; Check if A20 is correctly enable
|
2019-03-06 20:05:18 +01:00
|
|
|
|
2019-03-08 09:44:09 +01:00
|
|
|
;; BEGIN OF WORK
|
|
|
|
call Setup_paging ; Enable paging
|
|
|
|
call Go64 ; Prepare switch into long mode
|
|
|
|
|
|
|
|
push esi ; Print the logo
|
2019-03-08 08:43:44 +01:00
|
|
|
mov bl, 0x0E
|
|
|
|
mov esi, LOGO
|
|
|
|
call write32
|
|
|
|
pop esi
|
|
|
|
|
2019-03-08 21:15:10 +01:00
|
|
|
;call disable_cursor
|
2019-03-08 08:43:44 +01:00
|
|
|
|
2019-03-06 20:05:18 +01:00
|
|
|
lgdt [GDT64.pointer]
|
2019-03-08 09:44:09 +01:00
|
|
|
jmp GDT64.code:_loader64 ; SWITCH
|
2019-03-06 20:05:18 +01:00
|
|
|
|
|
|
|
[BITS 64]
|
|
|
|
|
2019-03-08 09:44:09 +01:00
|
|
|
x64_K db "Now in x64 long mode", 0x0A, 0x0D, 0x0
|
2019-03-08 08:43:44 +01:00
|
|
|
GoKernel db "Launching Kernel...", 0
|
|
|
|
|
|
|
|
_loader64:
|
2019-03-06 20:05:18 +01:00
|
|
|
;; Some cleanup
|
|
|
|
mov ax, 0
|
|
|
|
mov ss, ax
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov fs, ax
|
|
|
|
mov gs, ax
|
|
|
|
|
2019-03-08 08:43:44 +01:00
|
|
|
call bitemporize
|
|
|
|
|
2019-03-08 09:44:09 +01:00
|
|
|
mov qword [NextTRAM], TRAM+80*4 ; Because we don't want to overwrite
|
2019-03-08 08:43:44 +01:00
|
|
|
|
2019-03-06 20:05:18 +01:00
|
|
|
;; Hello world
|
|
|
|
mov bl, 0x0A
|
2019-03-08 09:44:09 +01:00
|
|
|
mov esi, x64_K
|
2019-03-06 20:05:18 +01:00
|
|
|
call write
|
|
|
|
mov bl, 0x0F
|
2019-03-08 08:43:44 +01:00
|
|
|
mov esi, GoKernel
|
2019-03-06 20:05:18 +01:00
|
|
|
call write
|
2019-03-06 20:05:18 +01:00
|
|
|
|
2019-03-08 09:44:09 +01:00
|
|
|
;; Launch the kernel !
|
|
|
|
call tritemporize ; Let time to see
|
2019-03-06 20:05:18 +01:00
|
|
|
|
2019-03-08 08:43:44 +01:00
|
|
|
extern StartKern
|
2019-03-09 21:47:35 +01:00
|
|
|
jmp StartKern
|
2019-03-06 20:05:18 +01:00
|
|
|
|
2019-03-08 09:44:09 +01:00
|
|
|
;; We must never reach this point ------------------------------------------- ;;
|
2019-03-06 20:05:18 +01:00
|
|
|
jmp Die
|