feat: log has now printf like formating

This commit is contained in:
d0p1 🏳️‍⚧️ 2023-01-19 16:49:20 +01:00
parent 067f09d6ca
commit a5581d8b7d
2 changed files with 88 additions and 13 deletions

View file

@ -44,5 +44,5 @@ serial_write:
mov ebp, esp mov ebp, esp
mov ecx, [ebp + 8] mov ecx, [ebp + 8]
COM_OUT COM1, THR, cl COM_OUT COM1, THR, cl
pop ebp leave
ret ret

View file

@ -9,9 +9,11 @@ section .text
putstr: putstr:
push ebp push ebp
mov ebp, esp mov ebp, esp
mov ebx, [ebp + 8] push edi
mov edi, [ebp + 8]
.loop: .loop:
mov eax, [ebx] mov eax, [edi]
cmp al, 0 cmp al, 0
je .end je .end
push eax push eax
@ -20,30 +22,56 @@ putstr:
%else %else
%endif %endif
add esp, 4 add esp, 4
inc ebx inc edi
jmp .loop jmp .loop
.end: .end:
pop ebp pop edi
leave
ret ret
putuint: puthex:
xchg bx, bx
push ebp push ebp
mov ebp, esp mov ebp, esp
push edi
push esi
mov edi, [ebp + 8] ; number
mov eax, hexprefix
push hexprefix
call putstr
add esp, 4
mov ebx, [ebp + 8] mov edx, 0xF
mov edx, [ebp + 12] 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
mov eax, buffer mov eax, buffer
push eax push eax
call putstr call putstr
add esp, 4
pop ebp pop esi
pop edi
leave
ret ret
global log_impl global log_impl
log_impl: log_impl:
push ebp push ebp
mov ebp, esp mov ebp, esp
push edi
push esi
push ebx
mov eax, [ebp + 8] mov eax, [ebp + 8]
push eax push eax
@ -51,19 +79,62 @@ log_impl:
add esp, 4 add esp, 4
%ifdef __KERNEL__ %ifdef __KERNEL__
push ':' mov eax, ':'
push eax
call serial_write call serial_write
add esp, 4 add esp, 4
%else %else
%endif %endif
mov edi, [ebp + 12]
mov esi, 12
.loop: .loop:
mov eax, [ebp + 12] 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]
push eax push eax
call putstr call putstr
add esp, 4 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
.end: .end:
;; print new line
%ifdef __KERNEL__ %ifdef __KERNEL__
mov al, 0xA mov al, 0xA
push eax push eax
@ -71,8 +142,12 @@ log_impl:
add esp, 4 add esp, 4
%else %else
%endif %endif
pop ebp pop ebx
pop esi
pop edi
leave
ret ret
digits db '0123456789ABCDEF' digits db '0123456789ABCDEF'
buffer db '0000000000', 0 hexprefix db '0x', 0
buffer db '00000000', 0