parent
7be54a602c
commit
bbb4931238
|
@ -12,6 +12,7 @@ qemu.log
|
||||||
*.obj
|
*.obj
|
||||||
*.elf
|
*.elf
|
||||||
*.S
|
*.S
|
||||||
|
build/obj/*/*/*/[^.]*
|
||||||
|
|
||||||
# CNAME STUFF
|
# CNAME STUFF
|
||||||
*.yml
|
*.yml
|
||||||
|
@ -54,6 +55,7 @@ build/bin/s**
|
||||||
*.hex
|
*.hex
|
||||||
*.bin
|
*.bin
|
||||||
*.img
|
*.img
|
||||||
|
build/bin/[^.]*
|
||||||
|
|
||||||
# Debug files
|
# Debug files
|
||||||
*.dSYM/
|
*.dSYM/
|
||||||
|
|
38
Makefile
38
Makefile
|
@ -42,8 +42,9 @@ tests:
|
||||||
|
|
||||||
#Programs
|
#Programs
|
||||||
ASM=nasm
|
ASM=nasm
|
||||||
ASMFLAGS=
|
LD=ld
|
||||||
BOOTFLAGS=-f bin
|
ASMFLAGS=-f elf64
|
||||||
|
LDFLAGS= -melf_x86_64
|
||||||
|
|
||||||
#Folders
|
#Folders
|
||||||
MBRDIR=boot/grub
|
MBRDIR=boot/grub
|
||||||
|
@ -51,6 +52,8 @@ LOADERDIR=boot/loader
|
||||||
OBJDIR=build/obj
|
OBJDIR=build/obj
|
||||||
BINDIR=build/bin
|
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
|
#Color codes
|
||||||
CL='\033[0;32m'
|
CL='\033[0;32m'
|
||||||
CL2='\033[1;31m'
|
CL2='\033[1;31m'
|
||||||
|
@ -65,17 +68,19 @@ boot.mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg
|
||||||
@rmdir $(BINDIR)/disk
|
@rmdir $(BINDIR)/disk
|
||||||
|
|
||||||
boot.loader.asm: $(LOADERDIR)/loader.asm
|
boot.loader.asm: $(LOADERDIR)/loader.asm
|
||||||
@echo ${CL2}[boot.loader.asm]${NC} Making loader.bin...${CL3}
|
@echo ${CL2}[boot.loader.asm]${NC} Making loader...${CL3}
|
||||||
@$(ASM) $(BOOTFLAGS) $(LOADERDIR)/loader.asm -o $(OBJDIR)/boot/loader.bin > /dev/null
|
@$(ASM) $(ASMFLAGS) $(LOADERDIR)/loader.asm -o $(OBJDIR)/boot/loader.o > /dev/null
|
||||||
@echo ${CL2}[boot.loader.asm]${CL} OK${CL3}
|
@echo ${CL2}[boot.loader.asm]${CL} OK${CL3}
|
||||||
|
|
||||||
loader: boot.loader.asm
|
loader: boot.loader.asm link copykernel
|
||||||
|
|
||||||
|
copykernel:
|
||||||
@mkdir -p $(BINDIR)/disk
|
@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
|
@$(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
|
@$(MBRDIR)/umount.sh $(BINDIR)/disk
|
||||||
@echo ${CL2}[loader]${CL} OK${CL3}
|
@echo ${CL2}[disk]${CL} OK${CL3}
|
||||||
@rmdir $(BINDIR)/disk
|
@rmdir $(BINDIR)/disk
|
||||||
|
|
||||||
make_disk:
|
make_disk:
|
||||||
|
@ -85,20 +90,27 @@ make_disk:
|
||||||
|
|
||||||
testloader: loader
|
testloader: loader
|
||||||
@qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -enable-kvm 2> qemu.log &
|
@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
|
testloader32: loader
|
||||||
@qemu-system-i386 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -enable-kvm 2> qemu.log &
|
@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
|
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 &
|
@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
|
boot: make_disk boot.mbr loader
|
||||||
@echo ${CL2}[[boot]]${CL} Terminated without error.${CL3}
|
@echo ${CL2}[[boot]]${CL} Terminated without error.${CL3}
|
||||||
|
|
||||||
all: boot kernel
|
all: kernel boot
|
||||||
@echo ${CL2}[[all]]${CL} Terminated without error.${CL3}
|
@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
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ kernel: common
|
||||||
COMPILE_KERNEL(io/cursor)
|
COMPILE_KERNEL(io/cursor)
|
||||||
COMPILE_KERNEL(io/term)
|
COMPILE_KERNEL(io/term)
|
||||||
COMPILE_KERNEL(io/vga)
|
COMPILE_KERNEL(io/vga)
|
||||||
LINK_KERNEL(kaleid-kernel.elf)
|
//LINK_KERNEL(kaleid-kernel.elf)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------#
|
//----------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,6 @@ set timeout=5
|
||||||
set default=0 #Set the default menu entry
|
set default=0 #Set the default menu entry
|
||||||
|
|
||||||
menuentry "OS/K (pre-pre-alpha 0.0.1)" {
|
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
|
boot
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,3 +44,14 @@ bitemporize:
|
||||||
loop .looping
|
loop .looping
|
||||||
pop rcx
|
pop rcx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
tritemporize:
|
||||||
|
push rcx
|
||||||
|
mov rcx, 20
|
||||||
|
.looping:
|
||||||
|
push rcx
|
||||||
|
call bitemporize
|
||||||
|
pop rcx
|
||||||
|
loop .looping
|
||||||
|
pop rcx
|
||||||
|
ret
|
||||||
|
|
|
@ -44,7 +44,7 @@ Is64Bits:
|
||||||
jz .no_64 ; If it's not set, there is no long mode
|
jz .no_64 ; If it's not set, there is no long mode
|
||||||
ret
|
ret
|
||||||
.no_64:
|
.no_64:
|
||||||
mov ax, "01" ; ERROR 01 : 64bits unsupported
|
mov ax, "03" ; ERROR 03 : 64bits unsupported
|
||||||
jmp Error
|
jmp Error
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------- ;
|
; ---------------------------------------------------------------------------- ;
|
||||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>. //
|
|
||||||
//=--------------------------------------------------------------------------=//
|
|
||||||
|
|
||||||
int stub;
|
|
|
@ -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 <https://www.gnu.org/licenses/>. ;
|
|
||||||
;=----------------------------------------------------------------------------=;
|
|
||||||
|
|
||||||
[BITS 64]
|
|
||||||
|
|
||||||
;; GLOBAL DATA
|
|
||||||
UserData dw 0
|
|
||||||
|
|
||||||
;; TEXT
|
|
||||||
|
|
||||||
nop
|
|
|
@ -25,23 +25,27 @@
|
||||||
|
|
||||||
|
|
||||||
;;VIDEO
|
;;VIDEO
|
||||||
%define TRAM 0x0B8000 ; [T]ext[RAM]
|
%define TRAM 0xB8000 ; [T]ext[RAM]
|
||||||
%define VRAM 0x0A0000 ; [V]ideo[RAM]
|
%define VRAM 0xA0000 ; [V]ideo[RAM]
|
||||||
|
%define VGA_HEIGHT 80
|
||||||
|
|
||||||
;; GLOBAL DATA
|
;; GLOBAL DATA
|
||||||
|
|
||||||
NextTRAM dq 0xB8000 ; Last position of cursor
|
NextTRAM dq 0xB8000 ; Last position of cursor
|
||||||
VGA_HEIGHT64 dq 80
|
NextTRAM32 dq 0xB8000 ; Last position of cursor
|
||||||
|
VGA_X32 dq 0
|
||||||
|
VGA_HEIGHT64 dq VGA_HEIGHT
|
||||||
VGA_X dq 0
|
VGA_X dq 0
|
||||||
|
|
||||||
;; TEXT
|
;; TEXT
|
||||||
|
|
||||||
[BITS 64]
|
[BITS 64]
|
||||||
|
|
||||||
clear:
|
|
||||||
;-----------------------------------------------------------------------;
|
;-----------------------------------------------------------------------;
|
||||||
; x64/LM Clear Text Screen Function ;
|
; x64/LM Clear Text Screen Function ;
|
||||||
;-----------------------------------------------------------------------;
|
;-----------------------------------------------------------------------;
|
||||||
|
clear:
|
||||||
mov qword [NextTRAM], TRAM
|
mov qword [NextTRAM], TRAM
|
||||||
mov edi, TRAM
|
mov edi, TRAM
|
||||||
push rsi
|
push rsi
|
||||||
|
@ -49,35 +53,36 @@ clear:
|
||||||
push rcx
|
push rcx
|
||||||
mov ah, 0
|
mov ah, 0
|
||||||
mov al, 0
|
mov al, 0
|
||||||
mov rcx, 0x4000 ; traditionnal value
|
mov rcx, 0x4000 ; traditionnal value
|
||||||
rep stosw ; fill screen with al while cx > 0
|
rep stosw ; fill screen with al while cx > 0
|
||||||
pop rcx
|
pop rcx
|
||||||
pop rsi
|
pop rsi
|
||||||
pop rdi
|
pop rdi
|
||||||
ret
|
ret
|
||||||
|
|
||||||
write:
|
|
||||||
;-----------------------------------------------------------------------;
|
;-----------------------------------------------------------------------;
|
||||||
; x64/LM Text Printing Functions ;
|
; x64/LM Text Printing Functions ;
|
||||||
; bl : color code ;
|
; bl : color code ;
|
||||||
; esi : string address ;
|
; esi : string address ;
|
||||||
;-----------------------------------------------------------------------;
|
;-----------------------------------------------------------------------;
|
||||||
mov edi, [NextTRAM] ; TRAM ADDRESS
|
write:
|
||||||
|
mov edi, [NextTRAM] ; TRAM ADDRESS
|
||||||
push rsi
|
push rsi
|
||||||
push rdi
|
push rdi
|
||||||
.pLoop:
|
.pLoop:
|
||||||
lodsb
|
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
|
je .pEnd
|
||||||
cmp al, 0x0A ; LF
|
cmp al, 0x0A ; LF
|
||||||
je .lf
|
je .lf
|
||||||
cmp al, 0x0D ; CR
|
cmp al, 0x0D ; CR
|
||||||
je .cr
|
je .cr
|
||||||
stosb ; text subpixel
|
stosb ; text subpixel
|
||||||
mov al, bl
|
mov al, bl
|
||||||
stosb ; color subpixel
|
stosb ; color subpixel
|
||||||
add qword [NextTRAM], 0x2 ; Cursor moving
|
add qword [NextTRAM], 0x2 ; Cursor moving
|
||||||
add qword [VGA_X], 0x2 ; coord + 2 because 2 subpixels
|
add qword [VGA_X], 0x2 ; coord + 2 because 2 subpixels
|
||||||
jmp .pLoop
|
jmp .pLoop
|
||||||
.pEnd:
|
.pEnd:
|
||||||
pop rdi
|
pop rdi
|
||||||
|
@ -85,15 +90,15 @@ write:
|
||||||
ret
|
ret
|
||||||
.lf:
|
.lf:
|
||||||
mov rax, [VGA_HEIGHT64]
|
mov rax, [VGA_HEIGHT64]
|
||||||
add [NextTRAM], rax ; Cursor moving
|
add [NextTRAM], rax ; Cursor moving
|
||||||
add [NextTRAM], rax
|
add [NextTRAM], rax
|
||||||
add edi, eax ; Address moving
|
add edi, eax ; Address moving
|
||||||
add edi, eax
|
add edi, eax
|
||||||
jmp .pLoop
|
jmp .pLoop
|
||||||
.cr:
|
.cr:
|
||||||
push rax
|
push rax
|
||||||
mov rax, qword [VGA_X]
|
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
|
sub edi, edx
|
||||||
mov qword [VGA_X], 0
|
mov qword [VGA_X], 0
|
||||||
pop rax
|
pop rax
|
||||||
|
@ -108,19 +113,63 @@ dump:
|
||||||
; bl : color code ;
|
; bl : color code ;
|
||||||
; esi : buffer address ;
|
; esi : buffer address ;
|
||||||
;-----------------------------------------------------------------------;
|
;-----------------------------------------------------------------------;
|
||||||
mov edi, [NextTRAM] ; TRAM ADDRESS
|
mov edi, [NextTRAM] ; TRAM ADDRESS
|
||||||
push rsi
|
push rsi
|
||||||
push rdi
|
push rdi
|
||||||
push rcx
|
push rcx
|
||||||
mov rcx, 512
|
mov rcx, 512
|
||||||
.pLoop:
|
.pLoop:
|
||||||
lodsb
|
lodsb
|
||||||
stosb ; text subpixel
|
stosb ; text subpixel
|
||||||
mov al, bl
|
mov al, bl
|
||||||
stosb ; color subpixel
|
stosb ; color subpixel
|
||||||
loop .pLoop
|
loop .pLoop
|
||||||
pop rcx
|
pop rcx
|
||||||
pop rdi
|
pop rdi
|
||||||
pop rsi
|
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
|
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]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
;=----------------------------------------------------------------------------=;
|
;=----------------------------------------------------------------------------=;
|
||||||
; GNU GPL OS/K ;
|
; GNU GPL OS/K ;
|
||||||
; ;
|
; ;
|
||||||
; Desc: Kernel (second stage) Loader for OS/K ;
|
; Desc: Kernel Loader for OS/K ;
|
||||||
; (x86_64 architecture only) ;
|
; (x86_64 architecture only) ;
|
||||||
; ;
|
; ;
|
||||||
; ;
|
; ;
|
||||||
|
@ -23,36 +23,29 @@
|
||||||
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
|
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
|
||||||
;=----------------------------------------------------------------------------=;
|
;=----------------------------------------------------------------------------=;
|
||||||
|
|
||||||
%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]
|
[BITS 32]
|
||||||
[global _start]
|
[global MB_start]
|
||||||
[ORG 0x100000] ; Where GRUB loads us.
|
|
||||||
|
|
||||||
%include "boot/loader/multiboot/header.inc"
|
[section .multiboot]
|
||||||
|
|
||||||
;; 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
|
|
||||||
|
|
||||||
;; MAGNIFICENT MULTIBOOT HEADER FOR GRUB ------------------------------------ ;;
|
;; MAGNIFICENT MULTIBOOT HEADER FOR GRUB ------------------------------------ ;;
|
||||||
MB_header:
|
MB_header:
|
||||||
align 4
|
ALIGN 4
|
||||||
dd MB_HEADER_MAGIC
|
dd MB_HEADER_MAGIC
|
||||||
dd MB_HEADER_FLAGS
|
dd MB_HEADER_FLAGS
|
||||||
dd CHECKSUM
|
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:
|
MB_start:
|
||||||
mov esp, KERNEL_STACK ; Setup the stack
|
mov esp, KERNEL_STACK ; Setup the stack
|
||||||
push 0 ; Reset EFLAGS
|
push 0 ; Reset EFLAGS
|
||||||
|
@ -65,30 +58,29 @@ MB_start:
|
||||||
jmp Die ; Aufwiedersehen
|
jmp Die ; Aufwiedersehen
|
||||||
|
|
||||||
;; THE HOLES ---------------------------------------------------------------- ;;
|
;; THE HOLES ---------------------------------------------------------------- ;;
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------- ;
|
; ---------------------------------------------------------------------------- ;
|
||||||
; Prints 'ERR:XX' where 'XX' is the str in AX ;
|
; Prints 'ERR:XX' where 'XX' is the str in AX ;
|
||||||
; ---------------------------------------------------------------------------- ;
|
; ---------------------------------------------------------------------------- ;
|
||||||
Error:
|
Error:
|
||||||
mov dword [0xb8000], 0x4f524f45
|
mov word [CODE], ax
|
||||||
mov dword [0xb8004], 0x4f3a4f52
|
push esi
|
||||||
mov dword [0xb8008], 0x4f204f20
|
mov bl, 0x0c
|
||||||
mov byte [0xb800a], al
|
mov esi, ERGO
|
||||||
mov byte [0xb800c], ah
|
call write32
|
||||||
mov byte [0xb800d], 0x4f
|
pop esi
|
||||||
jmp Die
|
jmp Die
|
||||||
|
ERGO : db 219, 219, 219, " Error "
|
||||||
|
CODE : db "00"
|
||||||
|
db 0x0
|
||||||
; ---------------------------------------------------------------------------- ;
|
; ---------------------------------------------------------------------------- ;
|
||||||
; Kills the mind of your computer to get it prostrated ;
|
; Kills the mind of your computer to get it prostrated ;
|
||||||
; ---------------------------------------------------------------------------- ;
|
; ---------------------------------------------------------------------------- ;
|
||||||
Die:
|
Die:
|
||||||
cli
|
cli
|
||||||
hlt ; die nooooow
|
hlt ; die nooooow
|
||||||
;jmp 0xF000:0xFFF0
|
|
||||||
jmp $
|
jmp $
|
||||||
|
|
||||||
;; THE CODE ----------------------------------------------------------------- ;;
|
;; THE CODE ----------------------------------------------------------------- ;;
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------- ;
|
; ---------------------------------------------------------------------------- ;
|
||||||
; _loader ;
|
; _loader ;
|
||||||
; ;
|
; ;
|
||||||
|
@ -103,10 +95,7 @@ Die:
|
||||||
_loader:
|
_loader:
|
||||||
jmp lbegin
|
jmp lbegin
|
||||||
|
|
||||||
%include "boot/loader/multiboot/check.inc"
|
LOGO: db 219, 219, 219, " OS/K", 0
|
||||||
%include "boot/loader/cpu/cpuid.inc"
|
|
||||||
%include "boot/loader/mem/structures.inc"
|
|
||||||
%include "boot/loader/mem/management.inc"
|
|
||||||
|
|
||||||
lbegin:
|
lbegin:
|
||||||
call MB_check
|
call MB_check
|
||||||
|
@ -118,18 +107,24 @@ lbegin:
|
||||||
call Setup_paging
|
call Setup_paging
|
||||||
call Go64
|
call Go64
|
||||||
|
|
||||||
|
push esi
|
||||||
|
mov bl, 0x0E
|
||||||
|
mov esi, LOGO
|
||||||
|
call write32
|
||||||
|
pop esi
|
||||||
|
|
||||||
|
call disable_cursor
|
||||||
|
|
||||||
lgdt [GDT64.pointer]
|
lgdt [GDT64.pointer]
|
||||||
jmp GDT64.code:l64
|
jmp GDT64.code:_loader64
|
||||||
|
|
||||||
[BITS 64]
|
[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
|
;; Some cleanup
|
||||||
mov ax, 0
|
mov ax, 0
|
||||||
mov ss, ax
|
mov ss, ax
|
||||||
|
@ -138,6 +133,10 @@ l64:
|
||||||
mov fs, ax
|
mov fs, ax
|
||||||
mov gs, ax
|
mov gs, ax
|
||||||
|
|
||||||
|
call bitemporize
|
||||||
|
|
||||||
|
mov qword [NextTRAM], TRAM+80*4
|
||||||
|
|
||||||
;; Hello world
|
;; Hello world
|
||||||
mov bl, 0x0A
|
mov bl, 0x0A
|
||||||
mov esi, Salut
|
mov esi, Salut
|
||||||
|
@ -145,16 +144,14 @@ l64:
|
||||||
|
|
||||||
;; Read ATA
|
;; Read ATA
|
||||||
mov bl, 0x0F
|
mov bl, 0x0F
|
||||||
mov esi, ReadAttempt
|
mov esi, GoKernel
|
||||||
call write
|
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
|
jmp Die
|
||||||
|
|
|
@ -31,25 +31,25 @@
|
||||||
Setup_paging:
|
Setup_paging:
|
||||||
;; Map the first PML4 entry to PDP table
|
;; Map the first PML4 entry to PDP table
|
||||||
mov eax, PDP_table
|
mov eax, PDP_table
|
||||||
or eax, 0b11 ; present + writable
|
or eax, 1 << 1 | 1 << 0 ; present + writable
|
||||||
mov [PML4_table], eax
|
mov [PML4_table], eax
|
||||||
|
|
||||||
;; Map the first PDP entry to PD table
|
;; Map the first PDP entry to PD table
|
||||||
mov eax, PD_table
|
mov eax, PD_table
|
||||||
or eax, 0b11 ; present + writable
|
or eax, 1 << 1 | 1 << 0 ; present + writable
|
||||||
mov [PDP_table], eax
|
mov [PDP_table], eax
|
||||||
|
|
||||||
;; Map each PD entry to a 'huge' 2MiB page
|
;; Map each PD entry to a 'huge' 2MiB page
|
||||||
mov ecx, 0 ; counter variable
|
mov ecx, 0x0 ; counter variable
|
||||||
.map_p2_table:
|
.map_p2_table:
|
||||||
;; map ecx-th PD entry to a huge page that starts at address 2MiB*ecx
|
;; map ecx-th PD entry to a huge page that starts at address 2MiB*ecx
|
||||||
mov eax, 0x200000
|
mov eax, 0x200000
|
||||||
mul ecx ; start address of ecx-th page
|
mul ecx ; start address of ecx-th page
|
||||||
or eax, 0b10000011 ; present + writable + huge
|
or eax, 1 << 7 | 1 << 1 | 1 << 0 ; present + writable + huge
|
||||||
mov [PD_table + ecx * 8], eax
|
mov [PD_table + ecx * 8], eax
|
||||||
inc ecx
|
inc ecx
|
||||||
cmp ecx, 512 ; if counter == 512, the whole PD table is mapped
|
cmp ecx, 512 ; PD table is mapped if 512
|
||||||
jne .map_p2_table ; else map the next entry
|
jne .map_p2_table ; else map the next entry
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
@ -61,24 +61,24 @@ Go64:
|
||||||
|
|
||||||
;; Registering paging
|
;; Registering paging
|
||||||
mov eax, PML4_table
|
mov eax, PML4_table
|
||||||
mov cr3, eax ; Load PML4 to cr3
|
mov cr3, eax ; Load PML4 to cr3
|
||||||
|
|
||||||
mov eax, cr4
|
mov eax, cr4
|
||||||
or eax, 1 << 5
|
or eax, 1 << 5
|
||||||
mov cr4, eax ; Enable PAE
|
mov cr4, eax ; Enable PAE
|
||||||
|
|
||||||
;; Activate long mode
|
;; Activate long mode
|
||||||
mov ecx, 0xC0000080 ; address of MSR
|
mov ecx, 0xC0000080 ; Address of MSR
|
||||||
rdmsr ; read MSR
|
rdmsr ; Read MSR
|
||||||
or eax, 1 << 8 ; LME = 1. (Long Mode Enable)
|
or eax, 1 << 8 ; LME = 1. (Long Mode Enable)
|
||||||
wrmsr ; write MSR
|
wrmsr ; Write MSR
|
||||||
|
|
||||||
;; Enable paging
|
;; Enable paging
|
||||||
mov eax, cr0
|
mov eax, cr0
|
||||||
or eax, 1 << 31 ; make MSR bit 31 (PG = Paging) to 1 :
|
or eax, 1 << 31 ; Make MSR bit 31 (PG = Paging) to 1 :
|
||||||
; |1|000000000000000000000000000000
|
; |1|000000000000000000000000000000
|
||||||
; |
|
; |
|
||||||
; `------ Paging bit
|
; `------ Paging bit
|
||||||
mov cr0, eax
|
mov cr0, eax
|
||||||
jmp .end
|
jmp .end
|
||||||
nop
|
nop
|
||||||
|
@ -93,16 +93,16 @@ Go64:
|
||||||
; ---------------------------------------------------------------------------- ;
|
; ---------------------------------------------------------------------------- ;
|
||||||
CheckA20:
|
CheckA20:
|
||||||
pushad
|
pushad
|
||||||
mov edi,0x112345 ;odd megabyte address.
|
mov edi, 0x112345 ; Odd megabyte address.
|
||||||
mov esi,0x012345 ;even megabyte address.
|
mov esi, 0x012345 ; Even megabyte address.
|
||||||
mov [esi],esi ;making sure that both addresses contain diffrent values.
|
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))
|
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.
|
cmpsd ; Compare addresses to see if the're equivalent.
|
||||||
popad
|
popad
|
||||||
jne .A20_on ;if not equivalent , A20 line is set.
|
jne .A20_on ; If not equivalent , A20 line is set.
|
||||||
jmp .A20_err
|
jmp .A20_err
|
||||||
.A20_on:
|
.A20_on:
|
||||||
ret
|
ret
|
||||||
.A20_err:
|
.A20_err:
|
||||||
mov ax, "03" ; ERROR 03 : A20 line failed
|
mov ax, "04" ; ERROR 04 : A20 line failed
|
||||||
jmp Error
|
jmp Error
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
;=----------------------------------------------------------------------------=;
|
;=----------------------------------------------------------------------------=;
|
||||||
|
|
||||||
[BITS 32]
|
[BITS 32]
|
||||||
|
section .rodata
|
||||||
;; GDT WITH DOC
|
;; GDT WITH DOC
|
||||||
ALIGN 4096
|
ALIGN 4096
|
||||||
GDT64:
|
GDT64:
|
||||||
|
@ -44,6 +44,7 @@ GDT64:
|
||||||
dq GDT64
|
dq GDT64
|
||||||
|
|
||||||
;; EMPTY PAGE TABLES (identity of the first 1GiB)
|
;; EMPTY PAGE TABLES (identity of the first 1GiB)
|
||||||
|
section .bss
|
||||||
ALIGN 4096
|
ALIGN 4096
|
||||||
PML4_table:
|
PML4_table:
|
||||||
resb 4096
|
resb 4096
|
||||||
|
@ -51,3 +52,4 @@ PDP_table:
|
||||||
resb 4096
|
resb 4096
|
||||||
PD_table:
|
PD_table:
|
||||||
resb 4096
|
resb 4096
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,11 @@
|
||||||
;=----------------------------------------------------------------------------=;
|
;=----------------------------------------------------------------------------=;
|
||||||
|
|
||||||
;; MULTIBOOT HEADER
|
;; MULTIBOOT HEADER
|
||||||
MB_AOUT_KLUDGE equ 1 << 16 ; We are not an ELF executable
|
MB_AOUT_KLUDGE equ 0 << 16 ; if we are not an ELF executable
|
||||||
MB_ALIGN equ 1 << 0 ; Ask to align loaded modules on page boundaries
|
MB_ALIGN equ 0 << 0 ; Ask to align loaded modules on page boundaries
|
||||||
MB_MEMINFO equ 1 << 1 ; Ask to provide memory map
|
MB_MEMINFO equ 1 << 1 ; Ask to provide memory map
|
||||||
MB_HEADER_MAGIC equ 0x1badb002
|
MB_HEADER_MAGIC equ 0x1badb002
|
||||||
MB_GRUB_MAGIC equ 0x2badb002
|
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)
|
CHECKSUM equ -(MB_HEADER_MAGIC + MB_HEADER_FLAGS)
|
||||||
KERNEL_STACK equ 0x00200000 ; Stack starts at the 2mb address & grows down
|
KERNEL_STACK equ 0x00200000 ; Stack starts at the 2mb address & grows down
|
||||||
|
|
Binary file not shown.
|
@ -1,44 +1,68 @@
|
||||||
ENTRY(StartKern)
|
/*----------------------------------------------------------------------------//
|
||||||
SECTIONS
|
// GNU GPL OS/K //
|
||||||
{
|
// //
|
||||||
. = 1M;
|
// 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 <https://www.gnu.org/licenses/>. //
|
||||||
|
//----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
.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 = .;
|
*(.multiboot)
|
||||||
*(.text)
|
|
||||||
*(.rodata*)
|
|
||||||
. = ALIGN(4096);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.data : AT(ADDR(.data) - 1M)
|
.text ALIGN (0x1000) : /* align at 4 KB */
|
||||||
{
|
{
|
||||||
_data = .;
|
*(.text) /* all text sections from all files */
|
||||||
*(.data)
|
}
|
||||||
. = ALIGN(4096);
|
|
||||||
}
|
|
||||||
|
|
||||||
.eh_frame : AT(ADDR(.eh_frame) - 1M)
|
.data ALIGN (0x1000) :
|
||||||
{
|
{
|
||||||
_ehframe = .;
|
_data = .;
|
||||||
*(.eh_frame)
|
*(.data)
|
||||||
. = ALIGN(4096);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.bss : AT(ADDR(.bss) - 1M)
|
.eh_frame ALIGN (0x1000) :
|
||||||
{
|
{
|
||||||
_bss = .;
|
_ehframe = .;
|
||||||
*(.bss)
|
*(.eh_frame)
|
||||||
|
}
|
||||||
|
|
||||||
*(COMMON)
|
.bss ALIGN (0x1000) : /* align at 4 KB */
|
||||||
. = ALIGN(4096);
|
{
|
||||||
}
|
*(.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)
|
*(.comment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -139,7 +139,6 @@ still_going:
|
||||||
mov dx, 0x1f0 ; Data port - data comes in and out of here.
|
mov dx, 0x1f0 ; Data port - data comes in and out of here.
|
||||||
rep insw
|
rep insw
|
||||||
pop rdi
|
pop rdi
|
||||||
%ifdef DEBUG
|
|
||||||
mov bl, 0x0F
|
mov bl, 0x0F
|
||||||
mov esi, buffer
|
mov esi, buffer
|
||||||
call dump
|
call dump
|
||||||
|
@ -147,11 +146,6 @@ still_going:
|
||||||
mov esi, ended
|
mov esi, ended
|
||||||
call write
|
call write
|
||||||
add qword [NextTRAM], 120 ; Cursor moving : 1120 = 80 * 2 * 7 lignes
|
add qword [NextTRAM], 120 ; Cursor moving : 1120 = 80 * 2 * 7 lignes
|
||||||
%else
|
|
||||||
mov bl, 0x0A
|
|
||||||
mov esi, Pass
|
|
||||||
call write
|
|
||||||
%endif
|
|
||||||
pop rdx
|
pop rdx
|
||||||
pop rcx
|
pop rcx
|
||||||
pop rbx
|
pop rbx
|
Loading…
Reference in New Issue