StupidOS/lib/base/log.s

159 lines
1.7 KiB
ArmAsm
Raw Normal View History

2023-05-22 12:01:20 +00:00
; file: log.s
2023-01-15 19:25:25 +00:00
[BITS 32]
%ifdef __KERNEL__
extern serial_write
%endif
section .text
2023-05-22 12:01:20 +00:00
; Function: putstr
;
2023-01-15 19:25:25 +00:00
putstr:
push ebp
mov ebp, esp
push edi
mov edi, [ebp + 8]
2023-01-15 19:25:25 +00:00
.loop:
mov eax, [edi]
2023-01-15 19:25:25 +00:00
cmp al, 0
je .end
push eax
%ifdef __KERNEL__
call serial_write
%else
%endif
add esp, 4
inc edi
2023-01-15 19:25:25 +00:00
jmp .loop
.end:
pop edi
leave
2023-01-15 19:25:25 +00:00
ret
2023-05-22 12:01:20 +00:00
; Function: puthex
;
puthex:
2023-01-15 19:25:25 +00:00
push ebp
mov ebp, esp
push edi
push esi
mov edi, [ebp + 8] ; number
mov eax, hexprefix
push hexprefix
call putstr
add esp, 4
2023-01-15 19:25:25 +00:00
mov edx, 0xF
mov ecx, 0x8
mov esi, buffer
.loop:
rol edi, 4
mov eax, edi
and eax, edx
mov al, [digits + eax]
mov [esi], al
inc esi
dec ecx
jnz .loop
2023-01-15 19:25:25 +00:00
mov eax, buffer
push eax
call putstr
add esp, 4
2023-01-15 19:25:25 +00:00
pop esi
pop edi
leave
2023-01-15 19:25:25 +00:00
ret
2023-05-22 12:01:20 +00:00
; Function: log_impl
;
2023-01-15 19:25:25 +00:00
global log_impl
log_impl:
push ebp
mov ebp, esp
push edi
push esi
push ebx
2023-01-15 19:25:25 +00:00
mov eax, [ebp + 8]
push eax
call putstr
add esp, 4
%ifdef __KERNEL__
mov eax, ':'
push eax
2023-01-15 19:25:25 +00:00
call serial_write
add esp, 4
%else
%endif
2023-01-17 10:35:11 +00:00
mov edi, [ebp + 12]
mov esi, 12
2023-01-17 10:35:11 +00:00
.loop:
mov eax, [edi]
cmp al, 0
je .end
cmp al, '%'
jne .putchar
inc edi
mov eax, [edi]
cmp al, '%'
je .next
cmp al, 'x'
jne .check_s
add esi, 4
mov ebx, ebp
add ebx, esi
mov eax, [ebx]
push eax
call puthex
add esp, 4
jmp .next
.check_s:
cmp al, 's'
jne .unknown_format
add esi, 4
mov ebx, ebp
add ebx, esi
mov eax, [ebx]
2023-01-15 19:25:25 +00:00
push eax
call putstr
add esp, 4
jmp .next
.unknown_format:
mov al, '?'
.putchar:
push eax
%ifdef __KERNEL__
call serial_write
%else
;; TODO
%endif
add esp, 4
.next:
inc edi
jmp .loop
2023-01-17 10:35:11 +00:00
.end:
2023-01-15 19:25:25 +00:00
;; print new line
2023-01-15 19:25:25 +00:00
%ifdef __KERNEL__
mov al, 0xA
push eax
call serial_write
add esp, 4
%else
%endif
pop ebx
pop esi
pop edi
leave
2023-01-15 19:25:25 +00:00
ret
digits db '0123456789ABCDEF'
hexprefix db '0x', 0
buffer db '00000000', 0