;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) HexOS author 2019-2022. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
format binary as "sec"
use16
org 0x07C00
jmp boot_entry
nop
boot_entry:
mov ax, 3
int 16
mov ah, 2
mov al, 10
mov cx, 2
mov bx, 0x07E00
mov bp, 0
mov es, bp
int 13h
mov sp, 7E0h
mov bp, 7E00h
mov ds, bp
jmp 0000:7E00h
cli
hlt
jmp $-2
times 510-$+$$ db 00h
dw 0AA55h
; MACROS
macro movs reg, src {
push ax
mov ax, src
mov reg, ax
pop ax
}
; HEADER
org 0x8100
jmp p32
nop
db "system/kernel.hex", 00h
times 243-$+$$ db 00h
dd 00000000h
dd 00000000h
dd 00001000h
db 10000000b
; DATA
osname db "HexOS", 00h
osver db "v0.9.4", 00h
oscopy db "Ivan Chetchasov Vladimirovich 2019-2022 (c) All rights reserved.", 00h
; SYSDATA
GDT: dw 0
.size dw @f-GDT-1
.linear dd GDT
.code = $ - GDT
dw -1,0
db 0,9ah,0cfh,0
.data = $ - GDT
dw -1,0
db 0,92h,0cfh,0
.pointer:
dw GDT.size
dd GDT
@@:
; EXECUTABLE
; switch to P-mode
p32:
cli ; NO more interrupts
lgdt fword[GDT.pointer] ; Load GDT
mov eax, cr0 ; Where my CR0?
or al, 1 ; set lowest bit
mov cr0,eax ; apply changes
jmp GDT.code:pmode ; jump next
macro IRQ IRP {
dw IRP AND 65535
dw 8
db ?
db 10001111b
dw (IRP SHR 16) AND 65535
}
use32
curx dd 0
cury dd 0
winw dd 160
winh dd 50
color:
.normal db 0x0F
.error db 0xFC
.block db 0x70
.bsod db 0x1F
printsz:
mov ebx, 0xB8000
.cycle:
lodsb
cmp al, 00h
je .end
push ebx
add ebx, [curx]
add [curx], 2
mov word [ebx], ax
pop ebx
jmp .cycle
.end:
ret
IDT:
; ISRs
IRQ ISR._0
IRQ ISR._1
IRQ ISR._2
IRQ ISR._3
IRQ ISR._4
; pointer
.pointer:
dw @f-IDT-1
dd IDT
@@:
raise_bsod:
mov ah, [color.bsod]
mov esi, bsod
call printsz
cli
hlt
ISR:
._0: ; #DE
call raise_bsod
iret
._1: ; #DB
cli
hlt
iret
._2: ; #NMI
call raise_bsod
iret
._3: ; #BP
cli
hlt
iret
._4: ; #OF
call raise_bsod
iret
;
bsod:
db " "
db " "
db " "
db " "
db " (((((( "
db " ((::::::( ERROR OCCURRED "
db " ((:::::::( "
db " (:::::::(( "
db " (::::::( "
db " :::::: (:::::( Patential reasons: "
db " :::::: (:::::( - Corrupted file system/kernel.hex "
db " :::::: (:::::( - This is an unstable kernel "
db " (:::::( Ways to solve the problem: "
db " (:::::( - reinstall system "
db " (:::::( - install stable kernel "
db " :::::: (::::::( "
db " :::::: (:::::::(( If it is not unstable realise or "
db " :::::: ((:::::::( kernel was not touched, write me "
db " ((::::::( in Habr OS writing blog. Thanks. "
db " (((((( "
db " "
db " "
db " "
db " "
db " ", 0x00
pmode:
use32
; I also need to set data segment
mov ax, GDT.data
mov ds, ax
; stack segment
mov ss, ax
; graphic segment
movs gs, ax
lidt fword [IDT.pointer]
; Call 32-bit kernel
call main
; footer, just halt
; because os mustn`t
; reach this part of
; code so maybe fatal
; error happened.
cli
hlt
jmp $-2
; 32-BIT PART
main:
int 0
ret
db 128
times 5120-$+$$ db 00h