From bbb4931238ece08d9570bb59d3d2305a18abb081 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Fri, 8 Mar 2019 08:43:44 +0100 Subject: [PATCH] Loader (#28) Loading the kernel is now successful --- .gitignore | 2 + Makefile | 38 ++++--- Makefile.in | 2 +- boot/grub/grub.cfg | 2 +- boot/loader/cpu/cpu.inc | 11 ++ boot/loader/cpu/cpuid.inc | 2 +- boot/loader/elf/elf.c | 26 ----- boot/loader/fs/fat.asm | 33 ------ boot/loader/io/terminal.inc | 95 +++++++++++++----- boot/loader/loader.asm | 95 +++++++++--------- boot/loader/mem/management.inc | 48 ++++----- boot/loader/mem/structures.inc | 4 +- boot/loader/multiboot/header.inc | 6 +- build/{obj/kaleid/common => bin}/.placeholder | 0 build/bin/comm-test | Bin 19576 -> 0 bytes build/kernel.ld | 90 +++++++++++------ .../obj/{kaleid/crtlib => boot}/.placeholder | 0 build/obj/boot/loader.bin | Bin 23674 -> 0 bytes build/obj/boot/mbr.bin | Bin 512 -> 0 bytes .../common/test/{.paceholder => .placeholder} | 0 .../crtlib/test/{.paceholder => .placeholder} | 0 {boot/loader => kaleid/kernel}/io/ata.inc | 6 -- 22 files changed, 246 insertions(+), 214 deletions(-) delete mode 100644 boot/loader/elf/elf.c delete mode 100644 boot/loader/fs/fat.asm rename build/{obj/kaleid/common => bin}/.placeholder (100%) delete mode 100755 build/bin/comm-test rename build/obj/{kaleid/crtlib => boot}/.placeholder (100%) delete mode 100644 build/obj/boot/loader.bin delete mode 100644 build/obj/boot/mbr.bin rename build/obj/kaleid/common/test/{.paceholder => .placeholder} (100%) rename build/obj/kaleid/crtlib/test/{.paceholder => .placeholder} (100%) rename {boot/loader => kaleid/kernel}/io/ata.inc (98%) diff --git a/.gitignore b/.gitignore index 9b168cc..49d6ef7 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ qemu.log *.obj *.elf *.S +build/obj/*/*/*/[^.]* # CNAME STUFF *.yml @@ -54,6 +55,7 @@ build/bin/s** *.hex *.bin *.img +build/bin/[^.]* # Debug files *.dSYM/ diff --git a/Makefile b/Makefile index d0bec82..b2f06ba 100644 --- a/Makefile +++ b/Makefile @@ -42,8 +42,9 @@ tests: #Programs ASM=nasm -ASMFLAGS= -BOOTFLAGS=-f bin +LD=ld +ASMFLAGS=-f elf64 +LDFLAGS= -melf_x86_64 #Folders MBRDIR=boot/grub @@ -51,6 +52,8 @@ LOADERDIR=boot/loader OBJDIR=build/obj BINDIR=build/bin +l_objects=./build/obj/kaleid/crtlib/memory.o ./build/obj/kaleid/crtlib/rand.o ./build/obj/kaleid/crtlib/string.o ./build/obj/kaleid/crtlib/ultoa.o ./build/obj/kaleid/crtlib/strtol.o ./build/obj/kaleid/crtlib/utoa.o ./build/obj/kaleid/crtlib/status.o ./build/obj/kaleid/crtlib/atoul.o ./build/obj/kaleid/crtlib/atol.o ./build/obj/kaleid/crtlib/itoa.o ./build/obj/kaleid/crtlib/ltoa.o ./build/obj/kaleid/crtlib/atou.o ./build/obj/kaleid/crtlib/arith.o ./build/obj/kaleid/crtlib/atoi.o ./build/obj/kaleid/extras/prog.o ./build/obj/kaleid/extras/argv.o ./build/obj/kaleid/kernel/init/table.o ./build/obj/kaleid/kernel/init/init.o ./build/obj/kaleid/kernel/io/vga.o ./build/obj/kaleid/kernel/io/cursor.o ./build/obj/kaleid/kernel/io/term.o ./build/obj/kaleid/kernel/ke/panic.o ./build/obj/boot/loader.o + #Color codes CL='\033[0;32m' CL2='\033[1;31m' @@ -65,17 +68,19 @@ boot.mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg @rmdir $(BINDIR)/disk boot.loader.asm: $(LOADERDIR)/loader.asm - @echo ${CL2}[boot.loader.asm]${NC} Making loader.bin...${CL3} - @$(ASM) $(BOOTFLAGS) $(LOADERDIR)/loader.asm -o $(OBJDIR)/boot/loader.bin > /dev/null + @echo ${CL2}[boot.loader.asm]${NC} Making loader...${CL3} + @$(ASM) $(ASMFLAGS) $(LOADERDIR)/loader.asm -o $(OBJDIR)/boot/loader.o > /dev/null @echo ${CL2}[boot.loader.asm]${CL} OK${CL3} -loader: boot.loader.asm +loader: boot.loader.asm link copykernel + +copykernel: @mkdir -p $(BINDIR)/disk - @echo ${CL2}[loader]${NC} Constructing kernel loader...${CL3} + @echo ${CL2}[disk]${NC} Integrating kernel...${CL3} @$(MBRDIR)/mount.sh $(BINDIR)/disk.img $(BINDIR)/disk - @cp $(OBJDIR)/boot/loader.bin $(BINDIR)/disk/boot/loader.bin + @cp $(BINDIR)/kaleid $(BINDIR)/disk/boot/kaleid @$(MBRDIR)/umount.sh $(BINDIR)/disk - @echo ${CL2}[loader]${CL} OK${CL3} + @echo ${CL2}[disk]${CL} OK${CL3} @rmdir $(BINDIR)/disk make_disk: @@ -85,20 +90,27 @@ make_disk: testloader: loader @qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -enable-kvm 2> qemu.log & - @ndisasm $(OBJDIR)/boot/loader.bin -b 32 > loader_dism.asm + @ndisasm $(OBJDIR)/boot/loader -b 32 > loader_dism.asm testloader32: loader @qemu-system-i386 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -enable-kvm 2> qemu.log & - @ndisasm $(OBJDIR)/boot/loader.bin -b 32 > loader_dism.asm + @ndisasm $(OBJDIR)/boot/loader -b 32 > loader_dism.asm debugloader: loader @qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -s -S -enable-kvm 2> qemu.log & - @ndisasm $(OBJDIR)/boot/loader.bin -b 32 > loader_dism.asm - + @ndisasm $(OBJDIR)/boot/loader -b 32 > loader_dism.asm boot: make_disk boot.mbr loader @echo ${CL2}[[boot]]${CL} Terminated without error.${CL3} -all: boot kernel +all: kernel boot @echo ${CL2}[[all]]${CL} Terminated without error.${CL3} +link: + @$(LD) $(LDFLAGS) -T build/kernel.ld $(l_objects) -o $(OBJDIR)/boot/kaleid.x86_64 + @x86_64-elf-objcopy -I elf64-x86-64 -O elf32-i386 $(OBJDIR)/boot/kaleid.x86_64 $(BINDIR)/kaleid + +clean: + rm -Rf $(BINDIR)/* + rm -Rf $(OBJDIR)/*/*/*/*.o + diff --git a/Makefile.in b/Makefile.in index 38ded8c..a791b0a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -106,7 +106,7 @@ kernel: common COMPILE_KERNEL(io/cursor) COMPILE_KERNEL(io/term) COMPILE_KERNEL(io/vga) - LINK_KERNEL(kaleid-kernel.elf) + //LINK_KERNEL(kaleid-kernel.elf) //----------------------------------------------------------------------------# diff --git a/boot/grub/grub.cfg b/boot/grub/grub.cfg index 878c1b8..4efc73e 100755 --- a/boot/grub/grub.cfg +++ b/boot/grub/grub.cfg @@ -27,6 +27,6 @@ set timeout=5 set default=0 #Set the default menu entry menuentry "OS/K (pre-pre-alpha 0.0.1)" { - multiboot /boot/loader.bin # The multiboot command replaces the kernel command + multiboot /boot/kaleid # The multiboot command replaces the kernel command boot } diff --git a/boot/loader/cpu/cpu.inc b/boot/loader/cpu/cpu.inc index b875758..1dc5158 100644 --- a/boot/loader/cpu/cpu.inc +++ b/boot/loader/cpu/cpu.inc @@ -44,3 +44,14 @@ bitemporize: loop .looping pop rcx ret + +tritemporize: + push rcx + mov rcx, 20 +.looping: + push rcx + call bitemporize + pop rcx + loop .looping + pop rcx + ret diff --git a/boot/loader/cpu/cpuid.inc b/boot/loader/cpu/cpuid.inc index 7dabd42..c67fb08 100644 --- a/boot/loader/cpu/cpuid.inc +++ b/boot/loader/cpu/cpuid.inc @@ -44,7 +44,7 @@ Is64Bits: jz .no_64 ; If it's not set, there is no long mode ret .no_64: - mov ax, "01" ; ERROR 01 : 64bits unsupported + mov ax, "03" ; ERROR 03 : 64bits unsupported jmp Error ; ---------------------------------------------------------------------------- ; diff --git a/boot/loader/elf/elf.c b/boot/loader/elf/elf.c deleted file mode 100644 index fe48cde..0000000 --- a/boot/loader/elf/elf.c +++ /dev/null @@ -1,26 +0,0 @@ -//=--------------------------------------------------------------------------=// -// GNU GPL OS/K // -// // -// Desc: ELF64 Parser and Loader // -// (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 . // -//=--------------------------------------------------------------------------=// - -int stub; diff --git a/boot/loader/fs/fat.asm b/boot/loader/fs/fat.asm deleted file mode 100644 index 978d7ed..0000000 --- a/boot/loader/fs/fat.asm +++ /dev/null @@ -1,33 +0,0 @@ -;=----------------------------------------------------------------------------=; -; GNU GPL OS/K ; -; ; -; Desc: Basic File Allocation Table Long mode 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 64] - -;; GLOBAL DATA -UserData dw 0 - -;; TEXT - -nop diff --git a/boot/loader/io/terminal.inc b/boot/loader/io/terminal.inc index 77fcadb..1037c10 100644 --- a/boot/loader/io/terminal.inc +++ b/boot/loader/io/terminal.inc @@ -25,23 +25,27 @@ ;;VIDEO -%define TRAM 0x0B8000 ; [T]ext[RAM] -%define VRAM 0x0A0000 ; [V]ideo[RAM] +%define TRAM 0xB8000 ; [T]ext[RAM] +%define VRAM 0xA0000 ; [V]ideo[RAM] +%define VGA_HEIGHT 80 ;; GLOBAL DATA -NextTRAM dq 0xB8000 ; Last position of cursor -VGA_HEIGHT64 dq 80 +NextTRAM dq 0xB8000 ; Last position of cursor +NextTRAM32 dq 0xB8000 ; Last position of cursor +VGA_X32 dq 0 +VGA_HEIGHT64 dq VGA_HEIGHT VGA_X dq 0 ;; TEXT [BITS 64] -clear: + ;-----------------------------------------------------------------------; ; x64/LM Clear Text Screen Function ; ;-----------------------------------------------------------------------; +clear: mov qword [NextTRAM], TRAM mov edi, TRAM push rsi @@ -49,35 +53,36 @@ clear: push rcx mov ah, 0 mov al, 0 - mov rcx, 0x4000 ; traditionnal value - rep stosw ; fill screen with al while cx > 0 + mov rcx, 0x4000 ; traditionnal value + rep stosw ; fill screen with al while cx > 0 pop rcx pop rsi pop rdi ret -write: + ;-----------------------------------------------------------------------; ; x64/LM Text Printing Functions ; ; bl : color code ; ; esi : string address ; ;-----------------------------------------------------------------------; - mov edi, [NextTRAM] ; TRAM ADDRESS +write: + mov edi, [NextTRAM] ; TRAM ADDRESS push rsi push rdi .pLoop: lodsb - cmp al, 0 ; while @al, i.e. while we're not hitting '\0' + cmp al, 0 ; while @al, i.e. while we're not hitting '\0' je .pEnd - cmp al, 0x0A ; LF + cmp al, 0x0A ; LF je .lf - cmp al, 0x0D ; CR + cmp al, 0x0D ; CR je .cr - stosb ; text subpixel + stosb ; text subpixel mov al, bl - stosb ; color subpixel - add qword [NextTRAM], 0x2 ; Cursor moving - add qword [VGA_X], 0x2 ; coord + 2 because 2 subpixels + stosb ; color subpixel + add qword [NextTRAM], 0x2 ; Cursor moving + add qword [VGA_X], 0x2 ; coord + 2 because 2 subpixels jmp .pLoop .pEnd: pop rdi @@ -85,15 +90,15 @@ write: ret .lf: mov rax, [VGA_HEIGHT64] - add [NextTRAM], rax ; Cursor moving + add [NextTRAM], rax ; Cursor moving add [NextTRAM], rax - add edi, eax ; Address moving + add edi, eax ; Address moving add edi, eax jmp .pLoop .cr: push rax mov rax, qword [VGA_X] - sub qword [NextTRAM], rax ; pos = X + Y * VGA_HEIGHT64. Donc pos - X = début de ligne + sub qword [NextTRAM], rax ; pos = X + Y * VGA_HEIGHT64. Donc pos - X = début de ligne sub edi, edx mov qword [VGA_X], 0 pop rax @@ -108,19 +113,63 @@ dump: ; bl : color code ; ; esi : buffer address ; ;-----------------------------------------------------------------------; - mov edi, [NextTRAM] ; TRAM ADDRESS + mov edi, [NextTRAM] ; TRAM ADDRESS push rsi push rdi push rcx mov rcx, 512 .pLoop: lodsb - stosb ; text subpixel + stosb ; text subpixel mov al, bl - stosb ; color subpixel + stosb ; color subpixel loop .pLoop pop rcx pop rdi pop rsi - add qword [NextTRAM], 1000 ; Cursor moving : 1120 = 80 * 2 * 7 lignes + add qword [NextTRAM], 1000 ; Cursor moving : 1120 = 80 * 2 * 7 lignes ret + +[BITS 32] +;-----------------------------------------------------------------------; +; x32 Text Printing Functions ; +; bl : color code ; +; esi : string address ; +;-----------------------------------------------------------------------; +write32: + mov edi, TRAM ; TRAM ADDRESS + push esi + push edi +.pLoop: + lodsb + cmp al, 0 ; while @al, i.e. while we're not hitting '\0' + je .pEnd + stosb ; text subpixel + mov al, bl + stosb ; color subpixel + jmp .pLoop +.pEnd: + pop edi + pop esi + ret + +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 + +[BITS 64] diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index d421bd0..ef67137 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -1,7 +1,7 @@ ;=----------------------------------------------------------------------------=; ; GNU GPL OS/K ; ; ; -; Desc: Kernel (second stage) Loader for OS/K ; +; Desc: Kernel Loader for OS/K ; ; (x86_64 architecture only) ; ; ; ; ; @@ -23,36 +23,29 @@ ; along with OS/K. If not, see . ; ;=----------------------------------------------------------------------------=; -%define DEBUG +%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 _start] -[ORG 0x100000] ; Where GRUB loads us. +[global MB_start] -%include "boot/loader/multiboot/header.inc" - -;; NORMAL ENTRY POINT, BUT A LITTLE BIT UNUSED SINCE WE NEVER USE IT BECAUSE... -_start: - 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 - ;mov [Bootdrv], dl - xor dl, dl - jmp 0x0000:_loader ; pas sûr +[section .multiboot] ;; MAGNIFICENT MULTIBOOT HEADER FOR GRUB ------------------------------------ ;; MB_header: - align 4 + ALIGN 4 dd MB_HEADER_MAGIC dd MB_HEADER_FLAGS dd CHECKSUM - 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 -;; MULTIBOOT POINT ENTRY FOR GRUB ------------------------------------------- ;; +[section .text] + +;;MULTIBOOT POINT ENTRY FOR GRUB ------------------------------------------- ;; MB_start: mov esp, KERNEL_STACK ; Setup the stack push 0 ; Reset EFLAGS @@ -65,30 +58,29 @@ MB_start: jmp Die ; Aufwiedersehen ;; THE HOLES ---------------------------------------------------------------- ;; - ; ---------------------------------------------------------------------------- ; ; Prints 'ERR:XX' where 'XX' is the str in AX ; ; ---------------------------------------------------------------------------- ; Error: - mov dword [0xb8000], 0x4f524f45 - mov dword [0xb8004], 0x4f3a4f52 - mov dword [0xb8008], 0x4f204f20 - mov byte [0xb800a], al - mov byte [0xb800c], ah - mov byte [0xb800d], 0x4f + 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 0xF000:0xFFF0 jmp $ ;; THE CODE ----------------------------------------------------------------- ;; - ; ---------------------------------------------------------------------------- ; ; _loader ; ; ; @@ -103,10 +95,7 @@ Die: _loader: jmp lbegin -%include "boot/loader/multiboot/check.inc" -%include "boot/loader/cpu/cpuid.inc" -%include "boot/loader/mem/structures.inc" -%include "boot/loader/mem/management.inc" +LOGO: db 219, 219, 219, " OS/K", 0 lbegin: call MB_check @@ -118,18 +107,24 @@ lbegin: 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:l64 + jmp GDT64.code:_loader64 [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: +Salut db "Now in x64 long mode", 0x0A, 0x0D, 0x0 +GoKernel db "Launching Kernel...", 0 + +_loader64: ;; Some cleanup mov ax, 0 mov ss, ax @@ -138,6 +133,10 @@ l64: mov fs, ax mov gs, ax + call bitemporize + + mov qword [NextTRAM], TRAM+80*4 + ;; Hello world mov bl, 0x0A mov esi, Salut @@ -145,16 +144,14 @@ l64: ;; Read ATA mov bl, 0x0F - mov esi, ReadAttempt + mov esi, GoKernel call write - call temporize + ;mov ecx, 4000 + call tritemporize + extern StartKern + jmp StartKern - ;; Reading a sector of the disk - mov bl, 1 - mov bh, 1 - call ata_read - jmp Die diff --git a/boot/loader/mem/management.inc b/boot/loader/mem/management.inc index 57f86d7..876d2fe 100644 --- a/boot/loader/mem/management.inc +++ b/boot/loader/mem/management.inc @@ -31,25 +31,25 @@ Setup_paging: ;; Map the first PML4 entry to PDP table mov eax, PDP_table - or eax, 0b11 ; present + writable + or eax, 1 << 1 | 1 << 0 ; present + writable mov [PML4_table], eax ;; Map the first PDP entry to PD table mov eax, PD_table - or eax, 0b11 ; present + writable + or eax, 1 << 1 | 1 << 0 ; present + writable mov [PDP_table], eax ;; Map each PD entry to a 'huge' 2MiB page - mov ecx, 0 ; counter variable + mov ecx, 0x0 ; counter variable .map_p2_table: ;; map ecx-th PD entry to a huge page that starts at address 2MiB*ecx mov eax, 0x200000 - mul ecx ; start address of ecx-th page - or eax, 0b10000011 ; present + writable + huge + mul ecx ; start address of ecx-th page + or eax, 1 << 7 | 1 << 1 | 1 << 0 ; present + writable + huge mov [PD_table + ecx * 8], eax inc ecx - cmp ecx, 512 ; if counter == 512, the whole PD table is mapped - jne .map_p2_table ; else map the next entry + cmp ecx, 512 ; PD table is mapped if 512 + jne .map_p2_table ; else map the next entry ret @@ -61,24 +61,24 @@ Go64: ;; Registering paging mov eax, PML4_table - mov cr3, eax ; Load PML4 to cr3 + mov cr3, eax ; Load PML4 to cr3 mov eax, cr4 or eax, 1 << 5 - mov cr4, eax ; Enable PAE + mov cr4, eax ; Enable PAE ;; Activate long mode - mov ecx, 0xC0000080 ; address of MSR - rdmsr ; read MSR - or eax, 1 << 8 ; LME = 1. (Long Mode Enable) - wrmsr ; write MSR + mov ecx, 0xC0000080 ; Address of MSR + rdmsr ; Read MSR + or eax, 1 << 8 ; LME = 1. (Long Mode Enable) + wrmsr ; Write MSR ;; Enable paging mov eax, cr0 - or eax, 1 << 31 ; make MSR bit 31 (PG = Paging) to 1 : - ; |1|000000000000000000000000000000 - ; | - ; `------ Paging bit + or eax, 1 << 31 ; Make MSR bit 31 (PG = Paging) to 1 : + ; |1|000000000000000000000000000000 + ; | + ; `------ Paging bit mov cr0, eax jmp .end nop @@ -93,16 +93,16 @@ Go64: ; ---------------------------------------------------------------------------- ; CheckA20: pushad - mov edi,0x112345 ;odd megabyte address. - mov esi,0x012345 ;even megabyte address. - mov [esi],esi ;making sure that both addresses contain diffrent values. - mov [edi],edi ;(if A20 line is cleared the two pointers would point to the address 0x012345 that would contain 0x112345 (edi)) - cmpsd ;compare addresses to see if the're equivalent. + mov edi, 0x112345 ; Odd megabyte address. + mov esi, 0x012345 ; Even megabyte address. + mov [esi],esi ; Making sure that both addresses contain diffrent values. + mov [edi],edi ; (if A20 line is cleared the two pointers would point to the address 0x012345 that would contain 0x112345 (edi)) + cmpsd ; Compare addresses to see if the're equivalent. popad - jne .A20_on ;if not equivalent , A20 line is set. + jne .A20_on ; If not equivalent , A20 line is set. jmp .A20_err .A20_on: ret .A20_err: - mov ax, "03" ; ERROR 03 : A20 line failed + mov ax, "04" ; ERROR 04 : A20 line failed jmp Error diff --git a/boot/loader/mem/structures.inc b/boot/loader/mem/structures.inc index e1be0bd..4b92e56 100644 --- a/boot/loader/mem/structures.inc +++ b/boot/loader/mem/structures.inc @@ -24,7 +24,7 @@ ;=----------------------------------------------------------------------------=; [BITS 32] - +section .rodata ;; GDT WITH DOC ALIGN 4096 GDT64: @@ -44,6 +44,7 @@ GDT64: dq GDT64 ;; EMPTY PAGE TABLES (identity of the first 1GiB) +section .bss ALIGN 4096 PML4_table: resb 4096 @@ -51,3 +52,4 @@ PDP_table: resb 4096 PD_table: resb 4096 + diff --git a/boot/loader/multiboot/header.inc b/boot/loader/multiboot/header.inc index 8688c28..be4e105 100644 --- a/boot/loader/multiboot/header.inc +++ b/boot/loader/multiboot/header.inc @@ -24,11 +24,11 @@ ;=----------------------------------------------------------------------------=; ;; 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_AOUT_KLUDGE equ 0 << 16 ; if we are not an ELF executable +MB_ALIGN equ 0 << 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_GRUB_MAGIC equ 0x2badb002 -MB_HEADER_FLAGS equ MB_AOUT_KLUDGE|MB_ALIGN|MB_MEMINFO +MB_HEADER_FLAGS equ 0x0 ; 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/kaleid/common/.placeholder b/build/bin/.placeholder similarity index 100% rename from build/obj/kaleid/common/.placeholder rename to build/bin/.placeholder diff --git a/build/bin/comm-test b/build/bin/comm-test deleted file mode 100755 index ea0cd8f3fffe1bc41dfe9cc46c27bbf04fbc8c1d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 19576 zcmeHPeRNaDm4A}IWN;)03^5-mN`SYFarF4jr}l_V)Zt_dky_PuTM}RcQ534muZ3@@|(-cxAOX?^GgA5zo5K&X}P~~*Xq*c{`w++V{@>h zsKdUxXmx3ETTAf@W;f|4-c8lpSxv%^R^+J7dHACkpz>er-#M#y%U23b`;UF))jys3 z{P*X+&_ev#_#+);SNanCz%7JPs`~RU)gRZie_hL6`?~{>^;%dWHM6F`=T3t=r@;fj zt@zWYPXn;(LFB(Q4ZaHatyA!S6xb}uEcNh!D&#yfL2s1iNpgvmAtK%+^hX`Jf3@WC zv<6ysH+!3Wxb(KQ`2vck!Q1GUS_6&EN`us<1nTw#nuC56*L8S34UNrSf8&1QCMBLW z#S4ihZ)3CMan)}2)cXRy-HmOEFHpO=!r#*DtM%^k6Zh_>mS)cFkvvuHo~@j(!cWz< zY2s4~Z*sdfRCrbtuP7!5AQ{9b0(r^--DaipcEDNiPk4zc`yBHz$0^lp36-y%sbktwL6M2?z`Z;Oq5 z47H-ICAQc@eGT2VGcNV`qq6!ZIsEo`O|3hcap!E3xuFlE9HM?|#gG+7;&dq>vGhJN|@RV5$Fp61GOG-aB+USDY4AlRhf?Q(eCZo1kIeM*j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3F<_<+6*slC<8U!4WUXc`qwmO|JNY#86vC73M-SrvL=&1>`}L=rr_g}v z>zY~vL*r#x4_XX%O}P4$h< zo?x4A(${T1WpAR=)?IZdA<9Yg1oS_$0~#zIJlB?mIWI z`vQUH$xdzFpU@6xF}ppx+S-y$1rB8^rqG73=GY1GNo#kIFDCn$vW+e99}kVj#8oiS zQ2ID<%5&pfhK{K7{%=lcYg;RI4349VQO3C#&aasOonN2w06NplVwY^^$KhGE=v;Ch zX0f2+(>@X0#!knJmh7i!N@1yJ2{yz1N$2i4FKGsze9C_6s6*fKa6ogK6EUdu`YuT- zZrj(Scz1zfC@{K5T;WW=FVHF#H@7IhV#fwok>cIWbGw^^#k+!y_(vKV>!o7K?eVtl zk&5g0HAA09F-%wqg);S5at8BBalq&Ik^sMI^(#^_i?(817VmCBR-sw6n5J|vwXnIN z*tdsI;(O|$MC3G4Z8p~=#P!GOz=mqPO^tPELyJP{fzU)#jHr}~=^ll9g}871FDdQx z81RQ>KTBetQBeK%7V#!0y3f{BKFq>E#U09?Xx7-i##jQx`38eqWv*`A*k5@rsXx+F671YB(3+bG)c&d z{d_^i{ykV&();gGptM&m>KFT}g7W2*B-$_d1bqzhwD&IZv>v4-sFmfk_Y2AG=diRN z7bGI&V_aTPVZW$fZ-0c#Z{P~W`vgHtI8O59Grjy%z^GkfJ5cQV3M$@HfQ2RAJdu@D zTqVnk{b4~x{X&2*6Y=b#C2jw2vVO6TEU0L&kk{wGhJxh!#dD0HNBBBi$cuVK{u?@Z zu`ewse;g3(tgjLoT>Lwi7yW1D`#XZ3NoK~izW(p&?<5U#|B3h(^@@IY7P86pi+%l}8#I*m!z%D6+9T#~8egLA8Ylm~Tch6+6CZ~~y@K~fTudeZEvgJD KM<<}mO8*1Z5frNc diff --git a/build/kernel.ld b/build/kernel.ld index 34408e0..ea46357 100644 --- a/build/kernel.ld +++ b/build/kernel.ld @@ -1,44 +1,68 @@ -ENTRY(StartKern) -SECTIONS -{ - . = 1M; +/*----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Desc: OS/K KERNEL LINKER // +// (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 . // +//----------------------------------------------------------------------------*/ - .text : AT(ADDR(.text) - 1M) + +ENTRY(MB_start) /* the name of the entry label */ + +SECTIONS { + . = 0x00100000; /* the code should be loaded at 1 MB */ + + .boot ALIGN (0x1000) : /* align at 4 KB */ { - _code = .; - *(.text) - *(.rodata*) - . = ALIGN(4096); + *(.multiboot) } - .data : AT(ADDR(.data) - 1M) - { - _data = .; - *(.data) - . = ALIGN(4096); - } + .text ALIGN (0x1000) : /* align at 4 KB */ + { + *(.text) /* all text sections from all files */ + } - .eh_frame : AT(ADDR(.eh_frame) - 1M) - { - _ehframe = .; - *(.eh_frame) - . = ALIGN(4096); - } + .data ALIGN (0x1000) : + { + _data = .; + *(.data) + } - .bss : AT(ADDR(.bss) - 1M) - { - _bss = .; - *(.bss) + .eh_frame ALIGN (0x1000) : + { + _ehframe = .; + *(.eh_frame) + } - *(COMMON) - . = ALIGN(4096); - } + .bss ALIGN (0x1000) : /* align at 4 KB */ + { + *(.bss) /* all bss sections from all files */ + } - _end = .; + .rodata ALIGN (0x1000) : /* align at 4 KB */ + { + *(.rodata) /* all rodata sections from all files */ + } - /DISCARD/ : - { + /DISCARD/ : + { *(.comment) - } + } } - diff --git a/build/obj/kaleid/crtlib/.placeholder b/build/obj/boot/.placeholder similarity index 100% rename from build/obj/kaleid/crtlib/.placeholder rename to build/obj/boot/.placeholder diff --git a/build/obj/boot/loader.bin b/build/obj/boot/loader.bin deleted file mode 100644 index aa061943967b20e5b9d84eddee8eb76d504d6709..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 23674 zcmeI)&r1|x7zgm@U6pigneEUis29US1hyFkl~EfA3mtY>BQ?owNv8~S%f{-^LD`E- zu}FvLkWh9g`augu?Jl8P8|_|-=#tRIqQlrkNLFT6)AR0FP=7(u_dPuC^ZuBb*AMS3 z%)wVbQ%p`KbG~P9PLY?0T&bHY%1F>cF#OtE>QTK;@p1bek)*>k5^7G|H@9+s{9&b4 zU#OsgYHAEN1q&7BoHYfva8}8g49eiBo0Fm1r5qnscsK?v`trg0K3yFm8l2}xuI(3j zJ?&d>-AVH;2ei>`f~!7nT2!1nMlQ65M>ZFok^1R=+qQ>M zAOHafKmY;|fB*y_009U<00I#BQ^5JMUySD^X+&PT;oS&M=wSlN&oR+9s3 zoZ&Uk)hbkvDy`Oe>)fwLhBFH9hI-hm`L;+$V9>e7EF;QOdt+~>jOntu>wppK+vj$B zD1!2T3xt}(O)Yx%lSo~Br)S@bp-HZ0#n5N2K8O@?_0g&3L`uGUd$rP7&@&_g6PLoy z4%D+VVpi{ojA`Sl%Zz=q?J@UwQspyWZTsi0Ke@N9y)_@sJY7P>|IhSlp>45Yn*9Fp zcFkAGow1nF-Fr|5o7e4QdX5;u*E}p^O zAZsB?6cn61{dOE+@4L}=;MWcYw!RB{7zBRrWsu>xR3gzKR>!b~V$4Pwr4)_?{;Cy^MQemz%)%G%;p3zQr{RjC?f=`xzAaj_+q+c(D}7Wa#!2 zG(6CLYF|CWPHu+J%SuF>4=4bI8IQMLeDq?UE5nPc3@`36sCB#Y2N)iJ7}a^O+l>!o zKnlnJkXZr|FL)WcfNpukAi%)z<;7Zt1U7^JhL-}GUodsW@qT~I%vQr-@V3j3_k{sN zgyE&#Obp*2%Z2R&y5!zIpk>GGx>@4nn}7T$=5IXCz*Ky==TO5jfxbhpcd;iPPGIZ& z9S~@E>3f+(=S4>lE!AJdXN8OT4W678_AmXkFPY(m7{hCY z$Os4KIPPM0sHu-O0!>}RaiD~43*T9R*Iy4C9ylwug>M7zS%D2)5DXNN3|$2PxWBq- diff --git a/build/obj/kaleid/common/test/.paceholder b/build/obj/kaleid/common/test/.placeholder similarity index 100% rename from build/obj/kaleid/common/test/.paceholder rename to build/obj/kaleid/common/test/.placeholder diff --git a/build/obj/kaleid/crtlib/test/.paceholder b/build/obj/kaleid/crtlib/test/.placeholder similarity index 100% rename from build/obj/kaleid/crtlib/test/.paceholder rename to build/obj/kaleid/crtlib/test/.placeholder diff --git a/boot/loader/io/ata.inc b/kaleid/kernel/io/ata.inc similarity index 98% rename from boot/loader/io/ata.inc rename to kaleid/kernel/io/ata.inc index c37cfc6..9802449 100644 --- a/boot/loader/io/ata.inc +++ b/kaleid/kernel/io/ata.inc @@ -139,7 +139,6 @@ still_going: mov dx, 0x1f0 ; Data port - data comes in and out of here. rep insw pop rdi -%ifdef DEBUG mov bl, 0x0F mov esi, buffer call dump @@ -147,11 +146,6 @@ still_going: mov esi, ended call write add qword [NextTRAM], 120 ; Cursor moving : 1120 = 80 * 2 * 7 lignes -%else - mov bl, 0x0A - mov esi, Pass - call write -%endif pop rdx pop rcx pop rbx