Revert "Revert "Paging work and stuff""
This reverts commit e924c00056b046e767491aac7405f4accc53d62c.
This commit is contained in:
parent
05d3f052ac
commit
6076a89687
|
@ -4,6 +4,7 @@
|
||||||
# Test files
|
# Test files
|
||||||
test-*.c
|
test-*.c
|
||||||
loader_dism.asm
|
loader_dism.asm
|
||||||
|
qemu.log
|
||||||
|
|
||||||
# Object files
|
# Object files
|
||||||
*.o
|
*.o
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -84,7 +84,7 @@ make_disk:
|
||||||
@echo ${CL2}[make_disk]${CL} OK${CL3}
|
@echo ${CL2}[make_disk]${CL} OK${CL3}
|
||||||
|
|
||||||
testloader: loader
|
testloader: loader
|
||||||
@qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset &
|
@qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall -s -S -enable-kvm 2> qemu.log &
|
||||||
@ndisasm $(OBJDIR)/boot/loader.bin -b 32 > loader_dism.asm
|
@ndisasm $(OBJDIR)/boot/loader.bin -b 32 > loader_dism.asm
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,65 +0,0 @@
|
||||||
;=----------------------------------------------------------------------------=;
|
|
||||||
; GNU GPL OS/K ;
|
|
||||||
; ;
|
|
||||||
; Desc: Basic realmode CPU Detection ;
|
|
||||||
; (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 <https://www.gnu.org/licenses/>. ;
|
|
||||||
;=----------------------------------------------------------------------------=;
|
|
||||||
|
|
||||||
[BITS 16]
|
|
||||||
|
|
||||||
;; GLOBAL DATA
|
|
||||||
NoLongMode db 0x0A, 0x0D, "ERROR : Your computer is not designed for x64 OS", 0
|
|
||||||
|
|
||||||
;; TEXT
|
|
||||||
|
|
||||||
Is64bits:
|
|
||||||
;-----------------------------------------------------------------------;
|
|
||||||
; Checks if the CPU is compatible with 64-bits operating systems ;
|
|
||||||
; If the 21th bit of the eax register is set, then CPUID is supported ;
|
|
||||||
; We then test CPUID's result to see if long mode is supported ;
|
|
||||||
;-----------------------------------------------------------------------;
|
|
||||||
pushfd ; recovering the flags in eax
|
|
||||||
pop eax
|
|
||||||
mov ecx, eax
|
|
||||||
xor eax, 0x200000
|
|
||||||
push eax
|
|
||||||
popfd
|
|
||||||
pushfd
|
|
||||||
pop eax
|
|
||||||
xor eax, ecx
|
|
||||||
shr eax, 21
|
|
||||||
and eax, 1 ; magical spell of murta
|
|
||||||
push ecx
|
|
||||||
popfd
|
|
||||||
test eax, eax
|
|
||||||
jz .NonCompat ; if (CPUID non supporté) goto NonCompat
|
|
||||||
mov eax, 0x80000000
|
|
||||||
cpuid
|
|
||||||
cmp eax, 0x80000001
|
|
||||||
jb .NonCompat ; if (eax <= 0x80000001) goto NonCompat
|
|
||||||
mov eax, 0x80000001
|
|
||||||
cpuid
|
|
||||||
test edx, 1 << 29
|
|
||||||
jz .NonCompat ; if (edx != 1 << 29) goto NonCompat
|
|
||||||
ret ; back to mbr.s
|
|
||||||
.NonCompat:
|
|
||||||
stc
|
|
||||||
ret
|
|
|
@ -1,113 +0,0 @@
|
||||||
;=----------------------------------------------------------------------------=;
|
|
||||||
; GNU GPL OS/K ;
|
|
||||||
; ;
|
|
||||||
; Desc: Basic Memory Realmode Driver ;
|
|
||||||
; (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 <https://www.gnu.org/licenses/>. ;
|
|
||||||
;=----------------------------------------------------------------------------=;
|
|
||||||
|
|
||||||
[BITS 16]
|
|
||||||
|
|
||||||
;; GDT WITH DOC
|
|
||||||
GDT64:
|
|
||||||
NULL_SELECTOR: ;; null selector within 64 bits
|
|
||||||
dw GDT_LENGTH ; limit of GDT
|
|
||||||
dw GDT64 ; linear address of GDT
|
|
||||||
dd 0x0 ;
|
|
||||||
|
|
||||||
CODE_SELECTOR: ;; 32-bit code selector (ring 0)
|
|
||||||
dw 0x0000FFFF ; Segment Limit
|
|
||||||
db 0x0, 0x0, 0x0 ; Base Address
|
|
||||||
db 10011010b ; |7|6|5|4|3|2|1|0|
|
|
||||||
; | | | | | | | `----- 1 when segment used.
|
|
||||||
; | | | | | | `------ 1 when writable.
|
|
||||||
; | | | | | `------- 1 if "conformant". Don't know what is it... spectral ? xD
|
|
||||||
; | | | | `-------- 1 always
|
|
||||||
; | | | `--------- 1 for segment descriptor, 0 for system descriptor
|
|
||||||
; | | `---------- DPL !!! 0 for ring 0
|
|
||||||
; | `----------- DPL (2/2)
|
|
||||||
; `------------ 1 if in physical memory, 0 if page fault
|
|
||||||
db 11001111b ; |7|6|5|4|3|2|1|0|
|
|
||||||
; | | | | | | | `----- Limit 16
|
|
||||||
; | | | | | | `------ Limit 17
|
|
||||||
; | | | | | `------- Limit 18
|
|
||||||
; | | | | `-------- Limit 19
|
|
||||||
; | | | `--------- available for use
|
|
||||||
; | | `---------- 0 always
|
|
||||||
; | `----------- size of data. 1 for 32bits
|
|
||||||
; `------------ 0 if limit is in Bytes, 1 if it's in pages (4ko)
|
|
||||||
db 0x0 ; Base Address
|
|
||||||
|
|
||||||
DATA_SELECTOR: ;; flat data selector (ring 0)
|
|
||||||
dw 0x0000FFFF ; Segment Limit
|
|
||||||
db 0x0, 0x0, 0x0 ; Base Address
|
|
||||||
db 10010010b ; |7|6|5|4|3|2|1|0|
|
|
||||||
; | | | | | | | `----- 1 when segment used.
|
|
||||||
; | | | | | | `------ 1 when writable.
|
|
||||||
; | | | | | `------- expansion direction. 1 for a LIFO
|
|
||||||
; | | | | `-------- 1 always
|
|
||||||
; | | | `--------- 1 for segment descriptor, 0 for system descriptor
|
|
||||||
; | | `---------- DPL !!! 0 for ring 0
|
|
||||||
; | `----------- DPL (2/2)
|
|
||||||
; `------------ 1 if in physical memory, 0 if page fault
|
|
||||||
db 10001111b ; |7|6|5|4|3|2|1|0|
|
|
||||||
; | | | | | | | `----- Limit 16
|
|
||||||
; | | | | | | `------ Limit 17
|
|
||||||
; | | | | | `------- Limit 18
|
|
||||||
; | | | | `-------- Limit 19
|
|
||||||
; | | | `--------- available for use
|
|
||||||
; | | `---------- 0 always
|
|
||||||
; | `----------- size of data. 1 for 32bits
|
|
||||||
; `------------ 0 if limit is in Bytes, 1 if it's in pages (4ko)
|
|
||||||
db 0x0 ; Base Address
|
|
||||||
|
|
||||||
LONG_SELECTOR: ;; 64-bit code selector (ring 0)
|
|
||||||
dw 0x0000FFFF ; Segment Limit
|
|
||||||
db 0x0, 0x0, 0x0 ; Base Address
|
|
||||||
db 10011010b ; |7|6|5|4|3|2|1|0|
|
|
||||||
; | | | | | | | `----- 1 when segment used.
|
|
||||||
; | | | | | | `------ 1 when writable.
|
|
||||||
; | | | | | `------- 1 if "conformant". Don't know what is it... spectral ? xD
|
|
||||||
; | | | | `-------- 1 always
|
|
||||||
; | | | `--------- 1 for segment descriptor, 0 for system descriptor
|
|
||||||
; | | `---------- DPL !!! 0 for ring 0
|
|
||||||
; | `----------- DPL (2/2)
|
|
||||||
; `------------ 1 if in physical memory, 0 if page fault
|
|
||||||
db 10101111b ; |7|6|5|4|3|2|1|0|
|
|
||||||
; | | | | | | | `----- Limit 16
|
|
||||||
; | | | | | | `------ Limit 17
|
|
||||||
; | | | | | `------- Limit 18
|
|
||||||
; | | | | `-------- Limit 19
|
|
||||||
; | | | `--------- available for use
|
|
||||||
; | | `---------- 0 always
|
|
||||||
; | `----------- size of data. 1 for 32bits
|
|
||||||
; `------------ 0 if limit is in Bytes, 1 if it's in pages (4ko)
|
|
||||||
db 0x0 ; Base Address
|
|
||||||
GDT_LENGTH:
|
|
||||||
|
|
||||||
;; TEXT
|
|
||||||
|
|
||||||
set_a20:
|
|
||||||
push ax
|
|
||||||
in al, 0x92
|
|
||||||
or al, 2
|
|
||||||
out 0x92, al
|
|
||||||
pop ax
|
|
||||||
ret
|
|
|
@ -1,70 +0,0 @@
|
||||||
;=----------------------------------------------------------------------------=;
|
|
||||||
; GNU GPL OS/K ;
|
|
||||||
; ;
|
|
||||||
; Desc: Basic realmode terminal functions ;
|
|
||||||
; (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 <https://www.gnu.org/licenses/>. ;
|
|
||||||
;=----------------------------------------------------------------------------=;
|
|
||||||
|
|
||||||
[BITS 16]
|
|
||||||
|
|
||||||
disable_cursor:
|
|
||||||
pushf
|
|
||||||
push eax
|
|
||||||
push edx
|
|
||||||
mov dx, 0x3D4
|
|
||||||
mov al, 0xA ; low cursor shape register
|
|
||||||
out dx, al
|
|
||||||
inc dx
|
|
||||||
mov al, 0x20 ; bits 6-7 unused, bit 5 disables the cursor, bits 0-4 control the cursor shape
|
|
||||||
out dx, al
|
|
||||||
pop edx
|
|
||||||
pop eax
|
|
||||||
popf
|
|
||||||
ret
|
|
||||||
|
|
||||||
get_dimensions:
|
|
||||||
push eax
|
|
||||||
push ebx
|
|
||||||
mov ah, 0x0F
|
|
||||||
int 0x10
|
|
||||||
mov [VGA_HEIGHT], ah
|
|
||||||
mov [VIDEO_MODE], al
|
|
||||||
pop ebx
|
|
||||||
pop eax
|
|
||||||
ret
|
|
||||||
|
|
||||||
PrintB:
|
|
||||||
;---------------------------------------------------;
|
|
||||||
; Print out a simple string. ;
|
|
||||||
; ;
|
|
||||||
; DS:SI = String to print ;
|
|
||||||
; ;
|
|
||||||
; Returns: None ;
|
|
||||||
; ;
|
|
||||||
;---------------------------------------------------;
|
|
||||||
lodsb ; Load byte from ds:si to al
|
|
||||||
or al, al ; If al is empty stop looping
|
|
||||||
jz .done ; Done looping and return
|
|
||||||
mov ah, 0x0e ; Teletype output
|
|
||||||
int 0x10 ; Video interupt
|
|
||||||
jmp PrintB ; Loop untill string is null
|
|
||||||
.done:
|
|
||||||
ret
|
|
|
@ -29,7 +29,7 @@
|
||||||
[global _start]
|
[global _start]
|
||||||
[ORG 0x100000] ; Where GRUB loads us.
|
[ORG 0x100000] ; Where GRUB loads us.
|
||||||
|
|
||||||
%include "boot/loader/multiboot.inc"
|
%include "boot/loader/multiboot/header.inc"
|
||||||
|
|
||||||
;; Normal entry point, but a little bit unused since we never use it because...
|
;; Normal entry point, but a little bit unused since we never use it because...
|
||||||
_start:
|
_start:
|
||||||
|
@ -59,18 +59,41 @@ 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
|
||||||
call main
|
call main
|
||||||
add esp, 8 ; Cleanup arguments "A la MIPS"
|
add esp, 8 ; Cleanup arguments "A la MIPS"
|
||||||
jmp Die ; Aufwiedersehen
|
jmp Die ; Aufwiedersehen
|
||||||
|
|
||||||
;; THE HOLE ----------------------------------------------------------------- ;;
|
;; THE HOLES ---------------------------------------------------------------- ;;
|
||||||
|
Error:
|
||||||
|
mov dword [0xb8000], 0x4f524f45
|
||||||
|
mov dword [0xb8004], 0x4f3a4f52
|
||||||
|
mov dword [0xb8008], 0x4f204f20
|
||||||
|
mov byte [0xb800a], al
|
||||||
|
jmp Die
|
||||||
|
|
||||||
Die:
|
Die:
|
||||||
cli
|
cli
|
||||||
hlt ; die nooooow
|
hlt ; die nooooow
|
||||||
;jmp 0xF000:0xFFF0
|
;jmp 0xF000:0xFFF0
|
||||||
jmp $
|
jmp $
|
||||||
|
|
||||||
;; THE CODE ------------------------------------------------------------------;;
|
;; THE CODE ----------------------------------------------------------------- ;;
|
||||||
main:
|
main:
|
||||||
|
call MB_check
|
||||||
|
|
||||||
|
call Check_cpuid
|
||||||
|
call Is64Bits
|
||||||
|
|
||||||
|
call Setup_paging
|
||||||
|
call Go64
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
jmp Die
|
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
;=----------------------------------------------------------------------------=;
|
|
||||||
; GNU GPL OS/K ;
|
|
||||||
; ;
|
|
||||||
; Desc: Multiboot header ;
|
|
||||||
; (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 <https://www.gnu.org/licenses/>. ;
|
|
||||||
;=----------------------------------------------------------------------------=;
|
|
||||||
|
|
||||||
;; MULTIBOOT HEADER
|
|
||||||
MB_AOUT_KLUDGE equ 1 << 16 ; We are not an ELF executable
|
|
||||||
MB_ALIGN equ 1 << 0 ; Ask to align loaded modules on page boundaries
|
|
||||||
MB_MEMINFO equ 1 << 1 ; Ask to provide memory map
|
|
||||||
MB_HEADER_MAGIC equ 0x1BADB002
|
|
||||||
MB_HEADER_FLAGS equ MB_AOUT_KLUDGE|MB_ALIGN|MB_MEMINFO
|
|
||||||
CHECKSUM equ -(MB_HEADER_MAGIC + MB_HEADER_FLAGS)
|
|
||||||
KERNEL_STACK equ 0x00200000 ; Stack starts at the 2mb address & grows down
|
|
Binary file not shown.
Loading…
Reference in New Issue