mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
commit
b9ee8c3897
3
COPYING
3
COPYING
@ -672,6 +672,3 @@ may consider it more useful to permit linking proprietary applications with
|
|||||||
the library. If this is what you want to do, use the GNU Lesser General
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
Public License instead of this License. But first, please read
|
Public License instead of this License. But first, please read
|
||||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
|
|
||||||
=======
|
|
||||||
|
|
||||||
|
20
Makefile
20
Makefile
@ -25,3 +25,23 @@ tests:
|
|||||||
make tests -f Makefile.out.2
|
make tests -f Makefile.out.2
|
||||||
rm Makefile.out Makefile.out.2
|
rm Makefile.out Makefile.out.2
|
||||||
|
|
||||||
|
ASM=nasm
|
||||||
|
ASMFLAGS=
|
||||||
|
BOOTFLAGS=-f bin
|
||||||
|
|
||||||
|
BOOTDIR=boot
|
||||||
|
OBJDIR=build/obj
|
||||||
|
BINDIR=build/bin
|
||||||
|
|
||||||
|
boot.mbr.asm: $(BOOTDIR)/mbr.asm $(BOOTDIR)/mbr.inc
|
||||||
|
$(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.asm -o $(OBJDIR)/boot/mbr.bin
|
||||||
|
|
||||||
|
boot.loader.asm: $(BOOTDIR)/loader.asm
|
||||||
|
$(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.asm -o $(OBJDIR)/boot/loader.bin
|
||||||
|
|
||||||
|
bootloader: boot.mbr.asm boot.loader.asm
|
||||||
|
cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin
|
||||||
|
cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin
|
||||||
|
|
||||||
|
all: bootloader kernel
|
||||||
|
|
||||||
|
16
Makefile.in
16
Makefile.in
@ -22,10 +22,6 @@ CFLAGS=$(CFLAGS1) $(CFLAGS2) $(SFLAG)
|
|||||||
|
|
||||||
CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES)
|
CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES)
|
||||||
|
|
||||||
ASM=nasm
|
|
||||||
ASMFLAGS=
|
|
||||||
BOOTFLAGS=-f bin
|
|
||||||
|
|
||||||
BINDIR=./build/bin
|
BINDIR=./build/bin
|
||||||
OBJDIR=./build/obj
|
OBJDIR=./build/obj
|
||||||
|
|
||||||
@ -35,18 +31,6 @@ KERNDIR=kaleid/kernel
|
|||||||
SYSTDIR=kaleid/system
|
SYSTDIR=kaleid/system
|
||||||
LINXDIR=kaleid/common/test
|
LINXDIR=kaleid/common/test
|
||||||
|
|
||||||
all: bootloader kernel
|
|
||||||
|
|
||||||
boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc
|
|
||||||
$(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.asm -o $(OBJDIR)/boot/mbr.bin
|
|
||||||
|
|
||||||
boot.loader.s: $(BOOTDIR)/loader.s
|
|
||||||
$(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.asm -o $(OBJDIR)/boot/loader.bin
|
|
||||||
|
|
||||||
bootloader: boot.mbr.s boot.loader.s
|
|
||||||
cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin
|
|
||||||
cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------#
|
//----------------------------------------------------------------------------#
|
||||||
// TESTING MAKEFILE
|
// TESTING MAKEFILE
|
||||||
|
|
||||||
|
103
Makefile.out.2
Normal file
103
Makefile.out.2
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
# 1 "./Makefile.in"
|
||||||
|
# 1 "<built-in>"
|
||||||
|
# 1 "<command-line>"
|
||||||
|
# 31 "<command-line>"
|
||||||
|
# 1 "/usr/include/stdc-predef.h" 1 3 4
|
||||||
|
# 32 "<command-line>" 2
|
||||||
|
# 1 "./Makefile.in"
|
||||||
|
# 11 "./Makefile.in"
|
||||||
|
# 1 "./build/preproc.h" 1
|
||||||
|
# 12 "./Makefile.in" 2
|
||||||
|
|
||||||
|
CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc"
|
||||||
|
CC2NAME=gcc
|
||||||
|
COPTIM=-O2
|
||||||
|
CWARNS=-Wall -Wextra -Wshadow -Wpedantic
|
||||||
|
CINCLUDES=-isystem./kaleid/include
|
||||||
|
|
||||||
|
CFLAGS1=-std=gnu11 -nostdlib -ffreestanding -mcmodel=large
|
||||||
|
CFLAGS2=-m64 -masm=intel -mno-red-zone -mno-mmx -mno-sse -mno-sse2
|
||||||
|
CFLAGS=$(CFLAGS1) $(CFLAGS2) $(SFLAG)
|
||||||
|
|
||||||
|
CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES)
|
||||||
|
|
||||||
|
ASM=nasm
|
||||||
|
ASMFLAGS=
|
||||||
|
BOOTFLAGS=-f bin
|
||||||
|
|
||||||
|
BINDIR=./build/bin
|
||||||
|
OBJDIR=./build/obj
|
||||||
|
|
||||||
|
BOOTDIR=boot
|
||||||
|
COMMDIR=kaleid/common
|
||||||
|
KERNDIR=kaleid/kernel
|
||||||
|
SYSTDIR=kaleid/system
|
||||||
|
LINXDIR=kaleid/common/test
|
||||||
|
|
||||||
|
all: bootloader kernel
|
||||||
|
|
||||||
|
boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc
|
||||||
|
$(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.asm -o $(OBJDIR)/boot/mbr.bin
|
||||||
|
|
||||||
|
boot.loader.s: $(BOOTDIR)/loader.s
|
||||||
|
$(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.asm -o $(OBJDIR)/boot/loader.bin
|
||||||
|
|
||||||
|
bootloader: boot.mbr.s boot.loader.s
|
||||||
|
cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin
|
||||||
|
cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pseudo_kern:
|
||||||
|
$(ASM) $(BOOTFLAGS) $(BOOTDIR)/pseudo_kernel.s -o $(OBJDIR)/boot/pkernel.bin
|
||||||
|
|
||||||
|
testing: bootloader pseudo_kern
|
||||||
|
cat $(BINDIR)/bootloader.bin $(OBJDIR)/boot/pkernel.bin > $(BINDIR)/boot.bin
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
COBJDIR=$(OBJDIR)/$(COMMDIR)
|
||||||
|
LOBJDIR=$(OBJDIR)/$(LINXDIR)
|
||||||
|
|
||||||
|
COMMOBJS=$(COBJDIR)/string.o $(COBJDIR)/status.o $(COBJDIR)/rand.o $(COBJDIR)/memory.o $(COBJDIR)/arith.o $(COBJDIR)/strtol.o $(COBJDIR)/itoa.o $(COBJDIR)/ltoa.o $(COBJDIR)/utoa.o $(COBJDIR)/ultoa.o $(COBJDIR)/atoi.o $(COBJDIR)/atol.o $(COBJDIR)/atou.o $(COBJDIR)/atoul.o
|
||||||
|
|
||||||
|
TCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES)
|
||||||
|
KCC=$(CC) -T ./build/kernel.ld -D_OSK_SOURCE -D_KALEID_KERNEL
|
||||||
|
|
||||||
|
comm-convert:
|
||||||
|
$(KCC) -c $(COMMDIR)/itoa.c -o $(COBJDIR)/itoa.o -D_NEED_ITOA
|
||||||
|
$(KCC) -c $(COMMDIR)/itoa.c -o $(COBJDIR)/ltoa.o -D_NEED_LTOA
|
||||||
|
$(KCC) -c $(COMMDIR)/itoa.c -o $(COBJDIR)/utoa.o -D_NEED_UTOA
|
||||||
|
$(KCC) -c $(COMMDIR)/itoa.c -o $(COBJDIR)/ultoa.o -D_NEED_ULTOA
|
||||||
|
$(KCC) -c $(COMMDIR)/atoi.c -o $(COBJDIR)/atoi.o -D_NEED_ATOI
|
||||||
|
$(KCC) -c $(COMMDIR)/atoi.c -o $(COBJDIR)/atol.o -D_NEED_ATOL
|
||||||
|
$(KCC) -c $(COMMDIR)/atoi.c -o $(COBJDIR)/atou.o -D_NEED_ATOU
|
||||||
|
$(KCC) -c $(COMMDIR)/atoi.c -o $(COBJDIR)/atoul.o -D_NEED_ATOUL
|
||||||
|
|
||||||
|
common: comm-convert
|
||||||
|
$(KCC) -c $(COMMDIR)/rand.c -o $(COBJDIR)/rand.o
|
||||||
|
$(KCC) -c $(COMMDIR)/arith.c -o $(COBJDIR)/arith.o
|
||||||
|
$(KCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o
|
||||||
|
$(KCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o
|
||||||
|
$(KCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o
|
||||||
|
$(KCC) -c $(COMMDIR)/strtol.c -o $(COBJDIR)/strtol.o
|
||||||
|
|
||||||
|
tests: common
|
||||||
|
$(TCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o
|
||||||
|
$(TCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/kaleid-common.elf
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
KOBJDIR=$(OBJDIR)/$(KERNDIR)
|
||||||
|
|
||||||
|
KERNOBJS=$(KOBJDIR)/init/init.o $(KOBJDIR)/init/table.o $(KOBJDIR)/ke/panic.o $(KOBJDIR)/ke/terminal.o
|
||||||
|
|
||||||
|
kernel: common
|
||||||
|
$(KCC) -c $(KERNDIR)/init/init.c -o $(KOBJDIR)/init/init.o
|
||||||
|
$(KCC) -c $(KERNDIR)/init/table.c -o $(KOBJDIR)/init/table.o
|
||||||
|
$(KCC) -c $(KERNDIR)/ke/panic.c -o $(KOBJDIR)/ke/panic.o
|
||||||
|
$(KCC) -c $(KERNDIR)/ke/terminal.c -o $(KOBJDIR)/ke/terminal.o
|
||||||
|
$(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/kaleid-kernel.elf
|
@ -60,8 +60,6 @@ src/
|
|||||||
| |
|
| |
|
||||||
| + kernel/
|
| + kernel/
|
||||||
| | |
|
| | |
|
||||||
| | - kernel.ld
|
|
||||||
| | |
|
|
||||||
| | + init/
|
| | + init/
|
||||||
| | | |
|
| | | |
|
||||||
| | | - init.c
|
| | | - init.c
|
||||||
@ -100,6 +98,8 @@ src/
|
|||||||
| - preproc.h
|
| - preproc.h
|
||||||
| - iddtool.h
|
| - iddtool.h
|
||||||
| |
|
| |
|
||||||
|
| - kernel.ld
|
||||||
|
| |
|
||||||
| + bin/
|
| + bin/
|
||||||
| + obj/
|
| + obj/
|
||||||
| |
|
| |
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# GNU-GPL OS/K (OS on Kaleid)
|
# GNU-GPL OS/K (OS on Kaleid)
|
||||||
|
|
||||||
### Fully open-source operating system from scratch (WIP), released under the GNU GPL version 3.0
|
### Fully open-source operating system from scratch (WIP), released under the GNU GPL version 3.0
|
||||||
|
|
||||||
#### Master Branch
|
#### Master Branch
|
||||||
|
|
||||||
For the project plan, see [OS/K Project](https://github.com/orgs/os-k-team/projects/1)
|
For the project plan, see [OS/K Project](https://github.com/orgs/os-k-team/projects/1)
|
||||||
|
10
boot/elf/elf.c
Normal file
10
boot/elf/elf.c
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
//----------------------------------------------------------------------------//
|
||||||
|
// GNU GPL OS/K //
|
||||||
|
// //
|
||||||
|
// Authors: spectral` //
|
||||||
|
// NeoX //
|
||||||
|
// //
|
||||||
|
// Desc: ELF64 Parser and Loader //
|
||||||
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
//STUB
|
102
boot/loader.asm
102
boot/loader.asm
@ -33,6 +33,8 @@
|
|||||||
%define volumeLabel bp+0x2b ; Volume Label
|
%define volumeLabel bp+0x2b ; Volume Label
|
||||||
%define fatTypeLabel bp+0x36 ; File system type
|
%define fatTypeLabel bp+0x36 ; File system type
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[BITS 16]
|
[BITS 16]
|
||||||
[ORG 0x1000]
|
[ORG 0x1000]
|
||||||
|
|
||||||
@ -41,14 +43,9 @@ mov ds, ax ; hm... And ds too
|
|||||||
mov es, ax ; And es because it is jealous
|
mov es, ax ; And es because it is jealous
|
||||||
|
|
||||||
mov [Bootdrv], dl
|
mov [Bootdrv], dl
|
||||||
|
xor dl, dl
|
||||||
jmp 0x0000:main
|
jmp 0x0000:main
|
||||||
|
|
||||||
;; DATA
|
|
||||||
|
|
||||||
Bootdrv db 0
|
|
||||||
VGA_HEIGHT dq 0
|
|
||||||
VIDEO_MODE dw 0
|
|
||||||
|
|
||||||
;; GDT WITH DOC
|
;; GDT WITH DOC
|
||||||
GDT64:
|
GDT64:
|
||||||
NULL_SELECTOR: ;; null selector within 64 bits
|
NULL_SELECTOR: ;; null selector within 64 bits
|
||||||
@ -57,7 +54,7 @@ GDT64:
|
|||||||
dd 0x0 ;
|
dd 0x0 ;
|
||||||
|
|
||||||
CODE_SELECTOR: ;; 32-bit code selector (ring 0)
|
CODE_SELECTOR: ;; 32-bit code selector (ring 0)
|
||||||
dw 0x0FFFF ; Segment Limit
|
dw 0x0000FFFF ; Segment Limit
|
||||||
db 0x0, 0x0, 0x0 ; Base Address
|
db 0x0, 0x0, 0x0 ; Base Address
|
||||||
db 10011010b ; |7|6|5|4|3|2|1|0|
|
db 10011010b ; |7|6|5|4|3|2|1|0|
|
||||||
; | | | | | | | `----- 1 when segment used.
|
; | | | | | | | `----- 1 when segment used.
|
||||||
@ -80,7 +77,7 @@ GDT64:
|
|||||||
db 0x0 ; Base Address
|
db 0x0 ; Base Address
|
||||||
|
|
||||||
DATA_SELECTOR: ;; flat data selector (ring 0)
|
DATA_SELECTOR: ;; flat data selector (ring 0)
|
||||||
dw 0x0FFFF ; Segment Limit
|
dw 0x0000FFFF ; Segment Limit
|
||||||
db 0x0, 0x0, 0x0 ; Base Address
|
db 0x0, 0x0, 0x0 ; Base Address
|
||||||
db 10010010b ; |7|6|5|4|3|2|1|0|
|
db 10010010b ; |7|6|5|4|3|2|1|0|
|
||||||
; | | | | | | | `----- 1 when segment used.
|
; | | | | | | | `----- 1 when segment used.
|
||||||
@ -103,7 +100,7 @@ GDT64:
|
|||||||
db 0x0 ; Base Address
|
db 0x0 ; Base Address
|
||||||
|
|
||||||
LONG_SELECTOR: ;; 64-bit code selector (ring 0)
|
LONG_SELECTOR: ;; 64-bit code selector (ring 0)
|
||||||
dw 0x0FFFF ; Segment Limit
|
dw 0x0000FFFF ; Segment Limit
|
||||||
db 0x0, 0x0, 0x0 ; Base Address
|
db 0x0, 0x0, 0x0 ; Base Address
|
||||||
db 10011010b ; |7|6|5|4|3|2|1|0|
|
db 10011010b ; |7|6|5|4|3|2|1|0|
|
||||||
; | | | | | | | `----- 1 when segment used.
|
; | | | | | | | `----- 1 when segment used.
|
||||||
@ -129,7 +126,9 @@ GDT64:
|
|||||||
%include "boot/loader16.inc"
|
%include "boot/loader16.inc"
|
||||||
|
|
||||||
main:
|
main:
|
||||||
|
|
||||||
;; compatibility check
|
;; compatibility check
|
||||||
|
push si
|
||||||
mov si, Init
|
mov si, Init
|
||||||
call PrintB
|
call PrintB
|
||||||
pop si
|
pop si
|
||||||
@ -138,8 +137,10 @@ main:
|
|||||||
push si
|
push si
|
||||||
mov si, Pass
|
mov si, Pass
|
||||||
call PrintB
|
call PrintB
|
||||||
|
pop si
|
||||||
|
|
||||||
;; Enabling A20
|
;; Enabling A20
|
||||||
|
push si
|
||||||
mov si, EnA20
|
mov si, EnA20
|
||||||
call PrintB
|
call PrintB
|
||||||
pop si
|
pop si
|
||||||
@ -149,6 +150,7 @@ main:
|
|||||||
push si
|
push si
|
||||||
mov si, Pass
|
mov si, Pass
|
||||||
call PrintB
|
call PrintB
|
||||||
|
pop si
|
||||||
|
|
||||||
;; DISABLING CURSOR BLINKING AND GETTING INFOS
|
;; DISABLING CURSOR BLINKING AND GETTING INFOS
|
||||||
call get_dimensions
|
call get_dimensions
|
||||||
@ -173,14 +175,34 @@ main:
|
|||||||
push dword [VGA_HEIGHT]
|
push dword [VGA_HEIGHT]
|
||||||
jmp (CODE_SELECTOR-GDT64):main32
|
jmp (CODE_SELECTOR-GDT64):main32
|
||||||
|
|
||||||
[BITS 32]
|
ErrorNo64:
|
||||||
VIDEO_MODE32 dw 0
|
mov si, NoLongMode
|
||||||
VGA_HEIGHT32 dw 0
|
call PrintB
|
||||||
|
Die:
|
||||||
|
cli
|
||||||
|
hlt ; die nooooow
|
||||||
|
jmp 0xF000:0xFFF0
|
||||||
|
|
||||||
|
[BITS 32]
|
||||||
main32:
|
main32:
|
||||||
pop dword [VGA_HEIGHT32]
|
pop dword [VGA_HEIGHT32]
|
||||||
pop dword [VIDEO_MODE32]
|
pop dword [VIDEO_MODE32]
|
||||||
|
|
||||||
|
;; VERIFY A20
|
||||||
|
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.
|
||||||
|
popad
|
||||||
|
jne .A20_on ;if not equivalent , A20 line is set.
|
||||||
|
mov WORD [A20_OK], 0
|
||||||
|
jmp .A20_end
|
||||||
|
.A20_on:
|
||||||
|
mov BYTE [A20_OK], 1
|
||||||
|
.A20_end:
|
||||||
|
|
||||||
;; INITIALIZE PROTECTED MODE SEGMENT REGISTERS
|
;; INITIALIZE PROTECTED MODE SEGMENT REGISTERS
|
||||||
mov ax, DATA_SELECTOR-GDT64
|
mov ax, DATA_SELECTOR-GDT64
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
@ -239,18 +261,33 @@ main32:
|
|||||||
%include "boot/loader64.inc"
|
%include "boot/loader64.inc"
|
||||||
|
|
||||||
;; DATA
|
;; DATA
|
||||||
txt db 0x09, " Switching to Long Mode... ", 0
|
|
||||||
Init db "Booting OS/K !", 0x0D, 0x0A, 0x0D, 0x0A, 0x09, " Checking CPUID...",0
|
Init db "Booting OS/K !", 0x0D, 0x0A, 0x0D, 0x0A, 0x09, " Checking CPUID...",0
|
||||||
Reinit db "Booting OS/K !", 0x0D, 0x0A, 0x0D, 0x0A, 0
|
|
||||||
CPUIDD db 0x09, " Checking CPUID...", 0
|
CPUIDD db 0x09, " Checking CPUID...", 0
|
||||||
EnA20 db 0x09, " Enabling A20 line...", 0
|
EnA20 db 0x09, " Enabling A20 line...", 0
|
||||||
NoLongMode db 0x0A, 0x0D, "ERROR : Your computer is not designed for x64 OS", 0
|
ReadAttempt db 0x09, " Attempt to read a sector with ATA commands...", 0x0A, 0x0D, 0x0A, 0x0D,0
|
||||||
|
txt db 0x09, " Switching to Long Mode... ", 0
|
||||||
|
Reinit db "Booting OS/K !", 0x0D, 0x0A, 0x0D, 0x0A, 0
|
||||||
Pass db " OK", 0x0A, 0x0D, 0
|
Pass db " OK", 0x0A, 0x0D, 0
|
||||||
|
Fail db " FAIL!", 0x0A, 0x0D, 0
|
||||||
|
msg db "The system is now in x64 mode. Is this not beautiful ?", 0x0A, 0x0D, 0
|
||||||
|
|
||||||
|
NoLongMode db 0x0A, 0x0D, "ERROR : Your computer is not designed for x64 OS", 0
|
||||||
|
FileNotFound db "Second Stage Error : The Kernel was not found.", 0x0A, 0x0D, 0
|
||||||
|
DiskError db "Second Stage Error : The Disk has crashed.", 0x0A, 0x0D, 0
|
||||||
|
|
||||||
|
filename db "KERNEL BIN"
|
||||||
|
|
||||||
|
Bootdrv db 0
|
||||||
|
UserData dw 0
|
||||||
|
VGA_HEIGHT dq 0
|
||||||
|
VIDEO_MODE dw 0
|
||||||
|
VIDEO_MODE32 dw 0
|
||||||
|
VGA_HEIGHT32 dw 0
|
||||||
NextTRAM dq 0x0B8000 ; Last position of cursor
|
NextTRAM dq 0x0B8000 ; Last position of cursor
|
||||||
VIDEO_MODE64 dq 0
|
VIDEO_MODE64 dq 0
|
||||||
VGA_HEIGHT64 dq 0
|
VGA_HEIGHT64 dq 0
|
||||||
VGA_X dq 0x0
|
VGA_X dq 0
|
||||||
msg db "The system is now in x64 mode. Is this not beautiful ?", 0x0A, 0x0D, 0
|
A20_OK db 0
|
||||||
|
|
||||||
main64:
|
main64:
|
||||||
pop qword [VGA_HEIGHT64]
|
pop qword [VGA_HEIGHT64]
|
||||||
@ -277,6 +314,13 @@ main64:
|
|||||||
mov esi, EnA20
|
mov esi, EnA20
|
||||||
call write
|
call write
|
||||||
|
|
||||||
|
cmp BYTE [A20_OK], 1
|
||||||
|
je .A20Success
|
||||||
|
mov bl, 0x0C
|
||||||
|
mov esi, Fail
|
||||||
|
call write
|
||||||
|
jmp Die
|
||||||
|
.A20Success:
|
||||||
mov bl, 0x0A
|
mov bl, 0x0A
|
||||||
mov esi, Pass
|
mov esi, Pass
|
||||||
call write
|
call write
|
||||||
@ -293,13 +337,21 @@ main64:
|
|||||||
mov esi, msg
|
mov esi, msg
|
||||||
call write
|
call write
|
||||||
|
|
||||||
|
mov bl, 0x0F
|
||||||
|
mov esi, ReadAttempt
|
||||||
|
call write
|
||||||
|
|
||||||
|
mov rcx, 2
|
||||||
|
.looping:
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
loop .looping ; Temporized because the ATA drive must be ready
|
||||||
|
|
||||||
|
call ata_read
|
||||||
|
|
||||||
jmp Die
|
jmp Die
|
||||||
|
|
||||||
[BITS 16]
|
; times 1024 nop
|
||||||
ErrorNo64:
|
; XXX ;
|
||||||
mov si, NoLongMode
|
; It seems impossible to have an executable > 2.0 kB...
|
||||||
call PrintB
|
|
||||||
Die:
|
|
||||||
cli
|
|
||||||
hlt ; die nooooow
|
|
||||||
jmp 0xF000:0xFFF0
|
|
||||||
|
@ -71,6 +71,129 @@ write:
|
|||||||
pop rax
|
pop rax
|
||||||
jmp .pLoop
|
jmp .pLoop
|
||||||
.scroll:
|
.scroll:
|
||||||
; XXX ;
|
; XXX I don't think I'll implement this, but never know...;
|
||||||
jmp .pLoop
|
jmp .pLoop
|
||||||
|
|
||||||
|
dump:
|
||||||
|
;-----------------------------------------------------------------------;
|
||||||
|
; x64/LM Dump Printing Functions ;
|
||||||
|
; bl : color code ;
|
||||||
|
; esi : string address ;
|
||||||
|
;-----------------------------------------------------------------------;
|
||||||
|
mov edi, [NextTRAM] ; TRAM ADDRESS
|
||||||
|
push rsi
|
||||||
|
push rdi
|
||||||
|
push rcx
|
||||||
|
mov rcx, 512
|
||||||
|
.pLoop:
|
||||||
|
lodsb
|
||||||
|
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
|
||||||
|
loop .pLoop
|
||||||
|
pop rcx
|
||||||
|
pop rdi
|
||||||
|
pop rsi
|
||||||
|
ret
|
||||||
|
|
||||||
|
ata_read:
|
||||||
|
;-----------------------------------------------------------------------;
|
||||||
|
; x64/LM ATA Reading function ;
|
||||||
|
; ;
|
||||||
|
; ;
|
||||||
|
;-----------------------------------------------------------------------;
|
||||||
|
|
||||||
|
; Technical infos about the ports (Intel Doc):
|
||||||
|
;
|
||||||
|
; Port Access Mode Misc
|
||||||
|
;
|
||||||
|
; 1f0 r/w Data register, the bytes of the disk itself
|
||||||
|
; 1f1 r Error register that can be handled
|
||||||
|
; 1f2 r/w Sector count, how many sectors to read
|
||||||
|
; 1f3 r/w Sector number, the actual sector wanted
|
||||||
|
; 1f4 r/w Cylinder low, cylinders is 0-1024
|
||||||
|
; 1f5 r/w Cylinder high, this makes up the rest of the 1024
|
||||||
|
; 1f6 r/w Drive/head
|
||||||
|
; bit 7 = 1
|
||||||
|
; bit 6 = 0
|
||||||
|
; bit 5 = 1
|
||||||
|
; bit 4 = 0 drive 0 select
|
||||||
|
; = 1 drive 1 select
|
||||||
|
; bit 3-0 head select bits
|
||||||
|
; 1f7 r Status register
|
||||||
|
; bit 7 = 1 controller is executing a command
|
||||||
|
; bit 6 = 1 drive is ready
|
||||||
|
; bit 5 = 1 write fault
|
||||||
|
; bit 4 = 1 seek complete
|
||||||
|
; bit 3 = 1 sector buffer requires servicing
|
||||||
|
; bit 2 = 1 disk data read corrected
|
||||||
|
; bit 1 = 1 index - set to 1 each revolution
|
||||||
|
; bit 0 = 1 previous command ended in an error
|
||||||
|
; 1f7 w Command register
|
||||||
|
; commands:
|
||||||
|
; 50h format track
|
||||||
|
; 20h read sectors with retry
|
||||||
|
; 21h read sectors without retry
|
||||||
|
; 22h read long with retry
|
||||||
|
; 23h read long without retry
|
||||||
|
; 30h write sectors with retry
|
||||||
|
; 31h write sectors without retry
|
||||||
|
; 32h write long with retry
|
||||||
|
; 33h write long without retry
|
||||||
|
;
|
||||||
|
|
||||||
|
push rax
|
||||||
|
push rbx
|
||||||
|
push rdx
|
||||||
|
push rcx
|
||||||
|
push rdi
|
||||||
|
mov dx,1f6h ;Drive and head port
|
||||||
|
mov al,0a0h ;Drive 0, head 0
|
||||||
|
out dx,al
|
||||||
|
|
||||||
|
mov dx,1f2h ;Sector count port
|
||||||
|
mov al,1 ;Read one sector
|
||||||
|
out dx,al
|
||||||
|
|
||||||
|
mov dx,1f3h ;Sector number port
|
||||||
|
mov al,1 ;Read sector one
|
||||||
|
out dx,al
|
||||||
|
|
||||||
|
mov dx,1f4h ;Cylinder low port
|
||||||
|
mov al,0 ;Cylinder 0
|
||||||
|
out dx,al
|
||||||
|
|
||||||
|
mov dx,1f5h ;Cylinder high port
|
||||||
|
mov al,0 ;The rest of the cylinder 0
|
||||||
|
out dx,al
|
||||||
|
|
||||||
|
mov dx,1f7h ;Command port
|
||||||
|
mov al,20h ;Read with retry.
|
||||||
|
out dx,al
|
||||||
|
still_going:
|
||||||
|
in al,dx
|
||||||
|
test al,8 ;This means the sector buffer requires
|
||||||
|
;servicing.
|
||||||
|
jz still_going ;Don't continue until the sector buffer
|
||||||
|
;is ready.
|
||||||
|
|
||||||
|
mov cx,512/2 ;One sector /2
|
||||||
|
mov rdi,buffer
|
||||||
|
mov dx,1f0h ;Data port - data comes in and out of here.
|
||||||
|
rep insw
|
||||||
|
pop rdi
|
||||||
|
pop rcx
|
||||||
|
pop rdx
|
||||||
|
pop rbx
|
||||||
|
pop rax
|
||||||
|
mov bl, 0x0F
|
||||||
|
mov esi, buffer
|
||||||
|
call dump
|
||||||
|
mov bl, 0x0A
|
||||||
|
mov esi, end
|
||||||
|
call write
|
||||||
|
ret
|
||||||
|
buffer: times 512 db "_"
|
||||||
|
end: db "[End of Sector]", 0x0
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
; Desc: Bootsector for OS/K INCLUDED FUNCTIONS ;
|
; Desc: Bootsector for OS/K INCLUDED FUNCTIONS ;
|
||||||
; (x86_64 architecture only) ;
|
; (x86_64 architecture only) ;
|
||||||
;=----------------------------------------------------------------------------=;
|
;=----------------------------------------------------------------------------=;
|
||||||
|
[BITS 16]
|
||||||
|
|
||||||
read_clusters:
|
read_clusters:
|
||||||
;---------------------------------------------------;
|
;---------------------------------------------------;
|
||||||
@ -100,7 +101,7 @@ read_sectors:
|
|||||||
shl ah, 1
|
shl ah, 1
|
||||||
or cl, ah ; Now cx is set with respective track and sector numbers
|
or cl, ah ; Now cx is set with respective track and sector numbers
|
||||||
mov dl, byte [Bootdrv] ; Set correct Bootdrv for int 13h
|
mov dl, byte [Bootdrv] ; Set correct Bootdrv for int 13h
|
||||||
mov di, 5 ; Try five times to read the sector because i love 5
|
mov di, 21 ; Try five times to read the sector because i love 21
|
||||||
.attempt_read:
|
.attempt_read:
|
||||||
mov ax, 0x0201 ; Read Sectors func of int 13h, read one sector
|
mov ax, 0x0201 ; Read Sectors func of int 13h, read one sector
|
||||||
int 0x13 ; Call int 13h (BIOS disk I/O)
|
int 0x13 ; Call int 13h (BIOS disk I/O)
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -15,9 +15,9 @@
|
|||||||
//
|
//
|
||||||
#define _ATOI_IMPL(_Name, _Type, _Func) \
|
#define _ATOI_IMPL(_Name, _Type, _Func) \
|
||||||
_Type _Name(const char *str) { \
|
_Type _Name(const char *str) { \
|
||||||
error_t old = errno; \
|
__get_errno(old); \
|
||||||
_Type ret = (_Type)_Func(str, NULL, 0); \
|
_Type ret = (_Type)_Func(str, NULL, 0); \
|
||||||
errno = old; \
|
__set_errno(old); \
|
||||||
return ret; \
|
return ret; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include <kaleid.h>
|
#include <kaleid.h>
|
||||||
|
|
||||||
error_t errno = 0;
|
error_t __errno = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static const char *descriptions[] = {
|
static const char *descriptions[] = {
|
||||||
|
@ -13,7 +13,7 @@ long strtol(const char *str, char **endp, int base) {
|
|||||||
(void)str;
|
(void)str;
|
||||||
(void)endp;
|
(void)endp;
|
||||||
(void)base;
|
(void)base;
|
||||||
errno = ENOSYS;
|
__set_errno(ENOSYS);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ ulong strtoul(const char *str, char **endp, int base) {
|
|||||||
(void)str;
|
(void)str;
|
||||||
(void)endp;
|
(void)endp;
|
||||||
(void)base;
|
(void)base;
|
||||||
errno = ENOSYS;
|
__set_errno(ENOSYS);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,24 @@ typedef struct { long quot, rem; } ldiv_t;
|
|||||||
// Global variables //
|
// Global variables //
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
|
|
||||||
extern error_t errno;
|
#ifndef _KALEID_KERNEL
|
||||||
|
|
||||||
|
extern error_t __errno;
|
||||||
|
|
||||||
|
#ifndef errno
|
||||||
|
#define errno __errno
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define __get_errno(x) error_t x = errno;
|
||||||
|
#define __set_errno(x) (errno = (x))
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define errno
|
||||||
|
#define __get_errno(x)
|
||||||
|
#define __set_errno(x)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
// Macros //
|
// Macros //
|
||||||
|
@ -184,7 +184,8 @@ void WriteByteOnPort(port_t port, port_t val)
|
|||||||
static inline
|
static inline
|
||||||
uchar ReadByteFromPort(port_t port)
|
uchar ReadByteFromPort(port_t port)
|
||||||
{
|
{
|
||||||
errno = ENOSYS;
|
|
||||||
|
KalAssert(FALSE && ENOSYS);
|
||||||
(void)port;
|
(void)port;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -192,7 +193,7 @@ uchar ReadByteFromPort(port_t port)
|
|||||||
static inline
|
static inline
|
||||||
ushort ReadWordFromPort(port_t port)
|
ushort ReadWordFromPort(port_t port)
|
||||||
{
|
{
|
||||||
errno = ENOSYS;
|
KalAssert(FALSE && ENOSYS);
|
||||||
(void)port;
|
(void)port;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user