StupidOS/boot/loader/logger.inc

183 lines
2.2 KiB
PHP
Raw Normal View History

2024-04-28 06:41:36 +00:00
bios_log_time:
clc
mov ah, 0x02
int 0x1A
; print hours
2024-04-28 06:41:36 +00:00
mov al, ch
2024-05-03 10:00:17 +00:00
mov ah, al
shr ah, 4
and ah, 0xF
and al, 0xF
2024-04-28 06:41:36 +00:00
add ah, 0x30
add al, 0x30
mov [szTime + 1], ah
mov [szTime + 2], al
2024-04-28 06:41:36 +00:00
; print minutes
2024-04-28 06:41:36 +00:00
mov al, cl
2024-05-03 10:00:17 +00:00
mov ah, al
shr ah, 4
and ah, 0xF
and al, 0xF
2024-04-28 06:41:36 +00:00
add ah, 0x30
add al, 0x30
mov [szTime + 4], ah
mov [szTime + 5], al
2024-04-28 06:41:36 +00:00
; print seconds
2024-04-28 06:41:36 +00:00
mov al, dh
2024-05-03 10:00:17 +00:00
mov ah, al
shr ah, 4
and ah, 0xF
and al, 0xF
2024-04-28 06:41:36 +00:00
add ah, 0x30
add al, 0x30
mov [szTime + 7], ah
mov [szTime + 8], al
2024-04-28 06:41:36 +00:00
push si
mov si, szTime
2024-04-28 06:41:36 +00:00
call bios_print
pop si
2024-04-28 06:41:36 +00:00
ret
2024-06-12 11:53:51 +00:00
;; Function: bios_log_number
;;
;; Parameters:
;; DI - number
bios_log_number:
push dx
push bx
xor cx, cx
mov ax, di
mov bx, 10
.loop_calc:
xor dx, dx
div bx
push dx
inc cx
or ax, ax
jnz .loop_calc
.loop_print:
pop ax
add al, '0'
mov ah, 0x0E
int 0x10
dec cx
or cl, cl
jnz .loop_print
pop bx
pop dx
ret
2024-05-02 11:34:27 +00:00
;; Function: bios_log_hex
;;
;; Parameters:
;; EDI - number
2024-04-28 06:41:36 +00:00
bios_log_hex:
push si
mov si, szHexPrefix
2024-05-02 11:34:27 +00:00
call bios_print
pop si
2024-05-02 11:34:27 +00:00
or edi, edi
jz .print_zero
push si
2024-06-12 11:53:51 +00:00
mov si, szBuffer
xor cl, cl
2024-05-02 11:34:27 +00:00
.loop:
cmp cl, 8
je .print_number
2024-05-02 11:34:27 +00:00
rol edi, 4
mov eax, edi
and eax, 0xF
mov al, byte [sDigits + eax]
mov [si], al
inc si
inc cl
2024-05-02 11:34:27 +00:00
jmp .loop
.print_zero:
mov al, '0'
mov ah, 0x0E
int 0x10
jmp .end
.print_number:
mov [si], byte 0
2024-06-12 11:53:51 +00:00
mov si, szBuffer
2024-05-02 11:34:27 +00:00
call bios_print
pop si
2024-05-02 11:34:27 +00:00
.end:
2024-04-28 06:41:36 +00:00
ret
;; Function: bios_log
;;
;; Parameters:
;; SI - string to print
;; [STACK] - variadic arguments
;;
bios_log:
call bios_log_time
2024-05-02 11:34:27 +00:00
.loop:
mov al, [si]
or al, al
jz .end
cmp al, '%'
jne .putchar
inc si
mov al, [si]
cmp al, '%'
je .putchar
cmp al, 's'
jne .check_x
mov di, si
pop ax
pop si
push ax
2024-04-28 06:41:36 +00:00
call bios_print
2024-05-02 11:34:27 +00:00
mov si, di
jmp .next
.check_x:
cmp al, 'x'
2024-06-12 11:53:51 +00:00
jne .check_d
2024-05-02 11:34:27 +00:00
pop ax
pop dword edi
2024-05-02 11:34:27 +00:00
push ax
call bios_log_hex
jmp .next
2024-06-12 11:53:51 +00:00
.check_d:
cmp al, 'd'
jne .unknown_format
pop ax
pop word di
push ax
call bios_log_number
jmp .next
2024-05-02 11:34:27 +00:00
.unknown_format:
mov al, '?'
.putchar:
mov ah, 0x0E
int 0x10
.next:
inc si
jmp .loop
.end:
mov si, szEndLine
2024-04-28 06:41:36 +00:00
call bios_print
2024-05-02 11:34:27 +00:00
2024-04-28 06:41:36 +00:00
ret
szTime db '[00:00:00] ', 0
szHexPrefix db '0x', 0
sDigits db '0123456789ABCDEF'
szEndLine db CR, LF, 0
2024-06-12 11:53:51 +00:00
szBuffer db '00000000', 0