-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
org 0x7c00 | ||
|
||
|
||
mov [BOOT_DISK], dl | ||
mov bp, 0x7c00 | ||
mov sp, bp | ||
call boot | ||
|
||
|
||
|
||
|
||
%include "bootloader/disk.asm" | ||
|
||
times (510-($-$$)) db 0 | ||
dw 0xaa55 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
PROGRAM_SPACE equ 0x7e00 | ||
|
||
boot: | ||
mov ah, 0x02 | ||
mov dl, [BOOT_DISK] | ||
mov bx, PROGRAM_SPACE | ||
mov al, 32 | ||
mov ch, 0x00 | ||
mov dh, 0x00 | ||
mov cl, 0x02 | ||
int 0x13 | ||
jmp PROGRAM_SPACE | ||
|
||
BOOT_DISK: | ||
db 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[bits 16] | ||
ClearScreen: | ||
mov ah, 00h | ||
mov al, 03h | ||
int 10h | ||
|
||
PrintString: | ||
push ax | ||
push bx | ||
|
||
mov ah, 0x0e | ||
.Loop: | ||
cmp [bx], byte 0 | ||
je .Exit | ||
mov al, [bx] | ||
int 0x10 | ||
inc bx | ||
jmp .Loop | ||
.Exit: | ||
pop ax | ||
pop bx | ||
ret | ||
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
nasm bootloader/bootloader.asm -f bin -o bootloader.bin | ||
nasm kernel/kernel.asm -f elf64 -o init.o | ||
wsl $WSLENV/x86_64-elf-gcc -ffreestanding -mno-red-zone -m64 -c "./kernel/kmain.cpp" -o "kernel.o" | ||
wsl $WSLENV/x86_64-elf-ld -o kernel.tmp -Ttext 0x7e00 init.o kernel.o | ||
wsl /usr/bin/objcopy -O binary kernel.tmp kernel.bin | ||
copy /b bootloader.bin+kernel.bin armenianOS-x86_64.flp | ||
move armenianOS-x86_64.flp ./build/x86_64/ | ||
del kernel.bin | ||
del bootloader.bin | ||
del kernel.o | ||
del init.o | ||
del kernel.tmp | ||
qemu-system-x86_64.exe build/x86_64/armenianOS-x86_64.flp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
_detectCpuId: | ||
pushfd | ||
pop eax | ||
|
||
mov ecx,eax | ||
|
||
xor eax, 1 << 21 | ||
push eax | ||
popfd | ||
pushfd | ||
pop eax | ||
push ecx | ||
popfd | ||
xor eax,ecx | ||
jz NoCPUID | ||
ret | ||
|
||
_detectLongMode: | ||
mov eax,0x80000001 | ||
cpuid | ||
test edx, 1 << 29 | ||
jz NoLongMode | ||
ret | ||
|
||
NoLongMode: | ||
hlt | ||
|
||
NoCPUID: | ||
hlt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
gdt_nulldesc: | ||
dd 0 | ||
dd 0 | ||
|
||
gdt_codedesc: | ||
dw 0xFFFF | ||
dw 0x0000 | ||
db 0x00 | ||
db 10011010b | ||
db 11001111b | ||
db 0x00 | ||
gdt_datasec: | ||
dw 0xFFFF | ||
dw 0x0000 | ||
db 0x00 | ||
db 10010010b | ||
db 11001111b | ||
db 0x00 | ||
|
||
gdt_end: | ||
|
||
gdt_descriptor: | ||
gdt_size: | ||
dw gdt_end - gdt_nulldesc - 1 | ||
dd gdt_nulldesc | ||
|
||
codeseg equ gdt_codedesc - gdt_nulldesc | ||
dataseg equ gdt_datasec - gdt_nulldesc | ||
|
||
[bits 32] | ||
EditGDT: | ||
mov [gdt_codedesc+6], byte 11001111b | ||
mov [gdt_datasec+6], byte 10101111b | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
[bits 16] | ||
[extern _kmain] | ||
_enterpm: | ||
call ClearScreen | ||
call EnableA20 | ||
cli | ||
lgdt [gdt_descriptor] | ||
mov eax, cr0 | ||
or eax, 1 | ||
mov cr0, eax | ||
jmp codeseg:_startpmode | ||
|
||
EnableA20: | ||
in al, 0x92 | ||
or al, 2 | ||
out 0x92, al | ||
ret | ||
|
||
%include "bootloader/print.asm" | ||
%include "kernel/gdt.asm" | ||
%include "kernel/cpuid.asm" | ||
%include "kernel/paging.asm" | ||
|
||
|
||
|
||
[bits 32] | ||
_startpmode: | ||
mov ax, dataseg | ||
mov ds,ax | ||
mov ss,ax | ||
mov es,ax | ||
mov fs,ax | ||
mov gs,ax | ||
call _kmain | ||
call _detectCpuId | ||
call _detectLongMode | ||
call _setuppaging | ||
call EditGDT | ||
jmp codeseg:Start64Bit | ||
|
||
[bits 64] | ||
Start64Bit: | ||
call _kmain | ||
|
||
|
||
|
||
|
||
|
||
times (2048-($-$$)) db 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
|
||
extern "C" int _kmain(){ | ||
*(char*)0xB8000 = 'H'; | ||
*(char*)0xB8002 = 'e'; | ||
*(char*)0xB8004 = 'l'; | ||
*(char*)0xB8006 = 'l'; | ||
*(char*)0xB8008 = 'o'; | ||
while(true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
PageTableEntry equ 0x1000 | ||
|
||
_setuppaging: | ||
mov edi, PageTableEntry | ||
mov cr3, edi | ||
mov dword [edi], 0x2003 | ||
add edi, 0x1000 | ||
mov dword [edi], 0x3003 | ||
add edi, 0x4003 | ||
mov ebx, 0x00000003 | ||
mov ecx, 512 | ||
|
||
.SetEntry: | ||
mov dword [edi], ebx | ||
add ebx, 0x1000 | ||
add edi, 8 | ||
loop .SetEntry | ||
mov eax, cr4 | ||
or eax, 1 << 5 | ||
mov cr4, eax | ||
|
||
|
||
mov ecx, 0xC00000000 | ||
rdmsr | ||
or eax, 1 << 8 | ||
wrmsr | ||
|
||
mov eax, cr0 | ||
or eax, 1 << 31 | ||
mov cr0, eax | ||
ret |