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 ecx, [ebp + 8]
COM_OUT COM1, THR, cl
pop ebp
leave
ret

View file

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