feat(boot/loader): logger display hex number

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-06-11 10:34:41 +02:00
parent a12220d492
commit 98d95256f0
2 changed files with 45 additions and 48 deletions

View file

@ -63,6 +63,7 @@ _start:
; 0 512 1024 ; 0 512 1024
; ;
; for now fat12 is asumed ; for now fat12 is asumed
call fat_load_root call fat_load_root
mov si, szKernelFile mov si, szKernelFile
@ -118,10 +119,10 @@ _start:
include 'video.inc' include 'video.inc'
include 'gdt.inc' include 'gdt.inc'
uDrive rb 1 uDrive rb 1
bDriveLBA db FALSE bDriveLBA db FALSE
szMsgStage2 db "StupidOS Loader", 0 szMsgStage2 db "StupidOS Loader %x", 0
szKernelFile db "VMSTUPIDSYS", 0 szKernelFile db "VMSTUPIDSYS", 0
szMsgErrorA20 db "ERROR: can't enable a20 line", 0 szMsgErrorA20 db "ERROR: can't enable a20 line", 0
szMsgErrorMemory db "ERROR: can't detect available memory", 0 szMsgErrorMemory db "ERROR: can't detect available memory", 0

View file

@ -3,77 +3,75 @@ bios_log_time:
mov ah, 0x02 mov ah, 0x02
int 0x1A int 0x1A
; print hours
mov al, ch mov al, ch
mov ah, al mov ah, al
shr ah, 4 shr ah, 4
and ah, 0xF and ah, 0xF
and al, 0xF and al, 0xF
;aam
add ah, 0x30 add ah, 0x30
add al, 0x30 add al, 0x30
mov [time + 1], ah mov [szTime + 1], ah
mov [time + 2], al mov [szTime + 2], al
; print minutes
mov al, cl mov al, cl
mov ah, al mov ah, al
shr ah, 4 shr ah, 4
and ah, 0xF and ah, 0xF
and al, 0xF and al, 0xF
;aam
add ah, 0x30 add ah, 0x30
add al, 0x30 add al, 0x30
mov [time + 4], ah mov [szTime + 4], ah
mov [time + 5], al mov [szTime + 5], al
; print seconds
mov al, dh mov al, dh
mov ah, al mov ah, al
shr ah, 4 shr ah, 4
and ah, 0xF and ah, 0xF
and al, 0xF and al, 0xF
;aam
add ah, 0x30 add ah, 0x30
add al, 0x30 add al, 0x30
mov [time + 7], ah mov [szTime + 7], ah
mov [time + 8], al mov [szTime + 8], al
mov si, time push si
mov si, szTime
call bios_print call bios_print
pop si
ret ret
;; Function: bios_log_number
;;
;; Parameters:
;; XX - number
;;
bios_log_number:
push ebp
mov ebp, esp
sub esp, 10
leave
ret
;; Function: bios_log_hex ;; Function: bios_log_hex
;; ;;
;; Parameters:
;; EDI - number
bios_log_hex: bios_log_hex:
push bp push si
mov ebp, esp mov si, szHexPrefix
sub esp, 12
mov si, hex_prefix
call bios_print call bios_print
pop si
or edi, edi or edi, edi
jz .print_zero jz .print_zero
push si
mov si, szHexBuffer
xor cl, cl
.loop: .loop:
or edi, edi xchg bx, bx
jz .print_number cmp cl, 8
je .print_number
rol edi, 4 rol edi, 4
mov eax, edi mov eax, edi
and eax, 0xF and eax, 0xF
mov al, [hex_digits + eax] mov al, byte [sDigits + eax]
mov [esp], al mov [si], al
inc esp inc si
inc cl
jmp .loop jmp .loop
.print_zero: .print_zero:
mov al, '0' mov al, '0'
@ -81,11 +79,11 @@ bios_log_hex:
int 0x10 int 0x10
jmp .end jmp .end
.print_number: .print_number:
mov [esp], byte 0 mov [si], byte 0
mov si, [ebp - 12] mov si, szHexBuffer
call bios_print call bios_print
pop si
.end: .end:
leave
ret ret
;; Function: bios_log ;; Function: bios_log
@ -95,9 +93,7 @@ bios_log_hex:
;; [STACK] - variadic arguments ;; [STACK] - variadic arguments
;; ;;
bios_log: bios_log:
push si
call bios_log_time call bios_log_time
pop si
.loop: .loop:
mov al, [si] mov al, [si]
@ -122,11 +118,9 @@ bios_log:
cmp al, 'x' cmp al, 'x'
jne .unknown_format jne .unknown_format
pop ax pop ax
pop edi pop dword edi
push ax push ax
push si
call bios_log_hex call bios_log_hex
pop si
jmp .next jmp .next
.unknown_format: .unknown_format:
mov al, '?' mov al, '?'
@ -137,12 +131,14 @@ bios_log:
inc si inc si
jmp .loop jmp .loop
.end: .end:
mov si, endline mov si, szEndLine
call bios_print call bios_print
ret ret
time db '[00:00:00] ', 0
hex_prefix db '0x', 0 szTime db '[00:00:00] ', 0
hex_digits db '0123456789ABCDEF' szHexPrefix db '0x', 0
endline db CR, LF, 0 sDigits db '0123456789ABCDEF'
szHexBuffer db '00000000', 0
szEndLine db CR, LF, 0