From 14f7c25f7c03c005139aee8047dd21c2fc74491a Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 6 Mar 2019 09:05:24 +0100 Subject: [PATCH] Revert "Paging work and stuff" This reverts commit f17bdd841f94a1d006604d12f38082d580c25781. --- .gitignore | 1 - Makefile | 2 +- boot/loader/cpu/cpuid.asm | 65 ++++++++++++++++++++++ boot/loader/io/rmmem.asm | 113 ++++++++++++++++++++++++++++++++++++++ boot/loader/io/rmterm.asm | 70 +++++++++++++++++++++++ boot/loader/loader.asm | 31 ++--------- boot/loader/multiboot.inc | 33 +++++++++++ build/obj/boot/loader.bin | Bin 12647 -> 74 bytes 8 files changed, 286 insertions(+), 29 deletions(-) create mode 100644 boot/loader/cpu/cpuid.asm create mode 100644 boot/loader/io/rmmem.asm create mode 100644 boot/loader/io/rmterm.asm create mode 100644 boot/loader/multiboot.inc diff --git a/.gitignore b/.gitignore index 9b168cc..e0c5b73 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ # Test files test-*.c loader_dism.asm -qemu.log # Object files *.o diff --git a/Makefile b/Makefile index 14af716..27b8da5 100644 --- a/Makefile +++ b/Makefile @@ -84,7 +84,7 @@ make_disk: @echo ${CL2}[make_disk]${CL} OK${CL3} testloader: loader - @qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall -s -S -enable-kvm 2> qemu.log & + @qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset & @ndisasm $(OBJDIR)/boot/loader.bin -b 32 > loader_dism.asm diff --git a/boot/loader/cpu/cpuid.asm b/boot/loader/cpu/cpuid.asm new file mode 100644 index 0000000..89c1bde --- /dev/null +++ b/boot/loader/cpu/cpuid.asm @@ -0,0 +1,65 @@ +;=----------------------------------------------------------------------------=; +; 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 . ; +;=----------------------------------------------------------------------------=; + +[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 diff --git a/boot/loader/io/rmmem.asm b/boot/loader/io/rmmem.asm new file mode 100644 index 0000000..865b9a9 --- /dev/null +++ b/boot/loader/io/rmmem.asm @@ -0,0 +1,113 @@ +;=----------------------------------------------------------------------------=; +; 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 . ; +;=----------------------------------------------------------------------------=; + +[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 diff --git a/boot/loader/io/rmterm.asm b/boot/loader/io/rmterm.asm new file mode 100644 index 0000000..275ff71 --- /dev/null +++ b/boot/loader/io/rmterm.asm @@ -0,0 +1,70 @@ +;=----------------------------------------------------------------------------=; +; 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 . ; +;=----------------------------------------------------------------------------=; + +[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 diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index 1fb8f51..0b9da7f 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -29,7 +29,7 @@ [global _start] [ORG 0x100000] ; Where GRUB loads us. -%include "boot/loader/multiboot/header.inc" +%include "boot/loader/multiboot.inc" ;; Normal entry point, but a little bit unused since we never use it because... _start: @@ -59,41 +59,18 @@ MB_start: 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 - +;; THE HOLE ----------------------------------------------------------------- ;; Die: cli hlt ; die nooooow ;jmp 0xF000:0xFFF0 jmp $ -;; THE CODE ----------------------------------------------------------------- ;; +;; THE CODE ------------------------------------------------------------------;; 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 diff --git a/boot/loader/multiboot.inc b/boot/loader/multiboot.inc new file mode 100644 index 0000000..8874596 --- /dev/null +++ b/boot/loader/multiboot.inc @@ -0,0 +1,33 @@ +;=----------------------------------------------------------------------------=; +; 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 . ; +;=----------------------------------------------------------------------------=; + +;; 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 diff --git a/build/obj/boot/loader.bin b/build/obj/boot/loader.bin index 8721f45ff79db257469fd909defc93f881d3203e..c5b1e9d04c8c64290d711872813bf39368172aab 100644 GIT binary patch delta 35 tcmV+;0NnrQVoD2UjL44Ij=(U|>PV3bFA(Sn0001k#0cvE`t-sE)5(5AL literal 12647 zcmeI(ze_?<6bJD0`~gzPeGN@5H=!xWm(Wnu(9qOy)fR_lhn66+EqL-KA&eSB7n?(e zh9@*UGw>}DG&veLXm1U~g6v%Nk7)S5;oNi1^Fbqm%C-pdjC8nlZZl%hm|lH z^rJF;bK23}*=KS6L?r2is_COrYp}t6=Oq@bb)sZ1(t*mVPBg+oam;_PUf|jq=D8-L$Ad(i5#7Db*4yiOU7zkDKmY;|fB*y_ z009U<00Izz00bZa0SG_<0uX=z1Rwwb2tWV=5P$##AOHafKmY;|fB*y_009U<00Izz z00bcLzXe=cGRg77_hgvl((1h6W>a6B-y%pFeZ(EkOOaQ-zh4|vh^Wx#hYCC+5?vvC bjxR-`*R+W|k%|+)SrC?xUYy5lk?`7o2fS}%