feat(kernel): wip serial logger

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-07-05 14:23:58 +02:00
parent 031e09b3ff
commit 41676291fe
7 changed files with 147 additions and 24 deletions

View file

@ -225,8 +225,9 @@ common32:
mov eax, STPDBOOT_MAGIC
mov ebx, boot_structure
mov eax, 0xC0000000
jmp eax
mov ecx, 0xC0000000
jmp ecx
hang:
hlt
jmp $

View file

@ -5,6 +5,8 @@ INSTALL = install
KERNEL = vmstupid.sys
SRCS = kernel.asm \
const.inc \
klog.inc \
dev/vga_console.inc \
mm/mm.inc
.PHONY: all

View file

@ -46,3 +46,5 @@ CR4_PKE = 0x0400000
CR4_CET = 0x0800000
CR4_PKS = 0x1000000
CR = 0x0D
LF = 0x0A

View file

@ -1,6 +1,16 @@
struc console
{
.buffer db 80*25 dup (?)
.lineno db ?
.colno db ?
}
VGA_COLUMNS = 80
VGA_LINES = 25
VGA_BASE = 0xC03B0000
vga_lineno db 0
vga_colno db 0
;; Function: vga_console_clear
vga_console_clear:
mov ecx, VGA_COLUMNS*VGA_LINES
xor al, al
mov edi, VGA_BASE
rep stosb
ret

10
kernel/init.inc Normal file
View file

@ -0,0 +1,10 @@
struc TSS {
.link dw ?
.link_h dw ?
.esp0 dd ?
.ss0 dw ?
.ss0_h dw ?
.esp1 dd ?
.ss1 dw ?
}

View file

@ -1,4 +1,6 @@
;; File: kernel.asm
format binary
include 'const.inc'
org KBASE
@ -9,9 +11,6 @@
db 'STPDKRNL'
db 32 dup(0)
include 'klog.inc'
include 'mm/mm.inc'
;; Function: kmain
;;
;; Parameters:
@ -20,24 +19,42 @@ db 32 dup(0)
;; EBX - Boot structure address
;;
kmain:
xchg bx, bx
mov [0xC03B0000], dword 0x08690948
mov [0xC03B0004], dword 0x05690648
; TODO: interupt, vmm
mov esp, stack_top
cmp eax, STPDBOOT_MAGIC
jne .halt
; init memory manager
; init idt, gdt
; copy boot structure
xchg bx, bx
call vga_console_clear
mov [0xC03B0000], dword 0x08740953
mov [0xC03B0004], dword 0x05700675
mov [0xC03B0008], dword 0x03640469
mov [0xC03B000C], dword 0x0153024F
;KLOG_INIT
;KLOG "kernel alive"
mov esi, szMsgKernelAlive
call klog
.halt:
hlt
jmp $
_edata:
include 'klog.inc'
include 'dev/vga_console.inc'
include 'mm/mm.inc'
; BSS
szMsgKernelAlive db "Kernel is alive", 0
align 4
stack_bottom:
rb 0x4000
stack_top:
_end:
dd 0x0

View file

@ -1,11 +1,92 @@
CMOS_ADDRESS = 0x70
CMOS_DATA = 0x71
CMOS_REG_SECOND = 0x00
CMOS_REG_MINUTE = 0x02
CMOS_REG_HOUR = 0x04
COM1 = 0x3F8
klog_print:
mov dx, COM1
@@:
lodsb
or al, al
jz @f
out dx, al
jmp @b
@@:
ret
klog_print_date:
clc
@@:
mov al, 0x0A
out CMOS_ADDRESS, al
in al, CMOS_DATA
and al, 0x80
jnz @b
mov al, CMOS_REG_HOUR
out CMOS_ADDRESS, al
in al, CMOS_DATA
mov ah, al
shr ah, 4
and ah, 0xF
and al, 0xF
add ah, 0x30
add al, 0x30
mov [szTime + 1], ah
mov [szTime + 2], al
mov al, CMOS_REG_MINUTE
out CMOS_ADDRESS, al
in al, CMOS_DATA
mov ah, al
shr ah, 4
and ah, 0xF
and al, 0xF
add ah, 0x30
add al, 0x30
mov [szTime + 4], ah
mov [szTime + 5], al
mov al, CMOS_REG_SECOND
out CMOS_ADDRESS, al
in al, CMOS_DATA
mov ah, al
shr ah, 4
and ah, 0xF
and al, 0xF
add ah, 0x30
add al, 0x30
mov [szTime + 7], ah
mov [szTime + 8], al
push esi
mov esi, szTime
call klog_print
pop esi
ret
macro KLOG_INIT {
}
;; Function: klog
;; Output kernel log
klog:
call klog_print_date
macro KLOG msg {
out 0xe9, al
}
call klog_print
mov esi, szCRLF
call klog_print
ret
szTime db '[00:00:00] ', 0
szCRLF db CR, LF, 0