2019-01-16 11:04:44 +01:00
|
|
|
;=----------------------------------------------------------------------------=;
|
|
|
|
; GNU GPL OS/K ;
|
|
|
|
; ;
|
|
|
|
; Desc: Kernel (second stage) Loader for OS/K ;
|
|
|
|
; (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-01-17 14:09:08 +01:00
|
|
|
%define DEBUG
|
|
|
|
|
2019-02-12 14:58:26 +01:00
|
|
|
[BITS 32]
|
|
|
|
[global _start]
|
2019-03-06 20:05:18 +01:00
|
|
|
[ORG 0x100000] ; Where GRUB loads us.
|
2019-02-12 14:58:26 +01:00
|
|
|
|
2019-03-06 20:05:18 +01:00
|
|
|
%include "boot/loader/multiboot/header.inc"
|
2019-02-12 14:58:26 +01:00
|
|
|
|
2019-03-06 20:05:18 +01:00
|
|
|
;; NORMAL ENTRY POINT, BUT A LITTLE BIT UNUSED SINCE WE NEVER USE IT BECAUSE...
|
2019-02-12 14:58:26 +01:00
|
|
|
_start:
|
2019-03-06 20:05:18 +01:00
|
|
|
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
|
2019-03-06 20:05:18 +01:00
|
|
|
;mov [Bootdrv], dl
|
2019-02-12 14:58:26 +01:00
|
|
|
xor dl, dl
|
2019-03-06 20:05:18 +01:00
|
|
|
jmp 0x0000:_loader ; pas sûr
|
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-02-15 15:47:56 +01:00
|
|
|
align 4
|
|
|
|
dd MB_HEADER_MAGIC
|
|
|
|
dd MB_HEADER_FLAGS
|
|
|
|
dd CHECKSUM
|
2019-03-06 20:05:18 +01:00
|
|
|
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
|
2019-02-12 14:58:26 +01:00
|
|
|
|
2019-03-06 20:05:18 +01:00
|
|
|
;; 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-06 20:05:18 +01:00
|
|
|
mov ecx, eax
|
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"
|
|
|
|
jmp Die ; Aufwiedersehen
|
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:
|
|
|
|
mov dword [0xb8000], 0x4f524f45
|
|
|
|
mov dword [0xb8004], 0x4f3a4f52
|
|
|
|
mov dword [0xb8008], 0x4f204f20
|
|
|
|
mov byte [0xb800a], al
|
2019-03-06 20:05:18 +01:00
|
|
|
mov byte [0xb800c], ah
|
|
|
|
mov byte [0xb800d], 0x4f
|
2019-03-06 20:05:18 +01:00
|
|
|
jmp Die
|
|
|
|
|
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 0xF000:0xFFF0
|
|
|
|
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
|
|
|
|
|
|
|
|
%include "boot/loader/multiboot/check.inc"
|
2019-03-06 20:05:18 +01:00
|
|
|
%include "boot/loader/cpu/cpuid.inc"
|
|
|
|
%include "boot/loader/mem/structures.inc"
|
|
|
|
%include "boot/loader/mem/management.inc"
|
|
|
|
|
2019-03-06 20:05:18 +01:00
|
|
|
lbegin:
|
2019-03-06 20:05:18 +01:00
|
|
|
call MB_check
|
|
|
|
|
|
|
|
call Check_cpuid
|
|
|
|
call Is64Bits
|
2019-03-06 20:05:18 +01:00
|
|
|
call CheckA20
|
2019-03-06 20:05:18 +01:00
|
|
|
|
|
|
|
call Setup_paging
|
2019-03-06 20:05:18 +01:00
|
|
|
call Go64
|
2019-03-06 20:05:18 +01:00
|
|
|
|
2019-03-06 20:05:18 +01:00
|
|
|
lgdt [GDT64.pointer]
|
|
|
|
jmp GDT64.code:l64
|
|
|
|
|
|
|
|
[BITS 64]
|
|
|
|
%include "boot/loader/io/terminal.inc"
|
|
|
|
%include "boot/loader/io/ata.inc"
|
|
|
|
%include "boot/loader/cpu/cpu.inc"
|
|
|
|
|
|
|
|
Salut db 0x09, " Booting OS/K ", 0x09, 0x0A, 0x0D, 0x0
|
|
|
|
ReadAttempt db 0x09, " Attempt to read a sector with ATA commands...", 0
|
|
|
|
|
|
|
|
l64:
|
|
|
|
;; Some cleanup
|
|
|
|
mov ax, 0
|
|
|
|
mov ss, ax
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov fs, ax
|
|
|
|
mov gs, ax
|
|
|
|
|
|
|
|
;; Hello world
|
|
|
|
mov bl, 0x0A
|
|
|
|
mov esi, Salut
|
|
|
|
call write
|
|
|
|
|
|
|
|
;; Read ATA
|
|
|
|
mov bl, 0x0F
|
|
|
|
mov esi, ReadAttempt
|
|
|
|
call write
|
2019-03-06 20:05:18 +01:00
|
|
|
|
2019-03-06 20:05:18 +01:00
|
|
|
call temporize
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Reading a sector of the disk
|
|
|
|
mov bl, 1
|
|
|
|
mov bh, 1
|
|
|
|
call ata_read
|
|
|
|
|
|
|
|
jmp Die
|