+; vi:filetype=nasm ts=8 sts=8 sw=8:
+ section .text
+
+ ; expects the address of a zero-terminated string in esi
+ global dbglog_str
+dbglog_str:
+ mov al, [esi]
+ cmp al, 0
+ jz .end
+ inc esi
+ call ser_putchar
+ jmp dbglog_str
+.end: ret
+
+ global dbglog_str_num
+dbglog_str_num:
+ pusha
+ call dbglog_str
+ mov eax, [esp + 28] ; eax pushed by pusha
+
+ mov esi, numbuf + 16
+ mov byte [esi], 0
+ mov ebx, 10
+.convloop:
+ xor edx, edx
+ div ebx
+ add dl, '0'
+ dec esi
+ mov [esi], dl
+ cmp eax, 0
+ jnz .convloop
+
+ call dbglog_str
+ popa
+ ret
+
+
+UART_DATA equ 3f8h
+UART_LSTAT equ 3fdh
+LST_TREG_EMPTY equ 20h
+
+ser_putchar:
+ push edx
+ cmp al, 10
+ jnz .notlf
+ push eax
+ mov al, 13
+ call ser_putchar
+ pop eax
+
+.notlf: mov ah, al
+ ; wait until the transmit register is empty
+ mov dx, UART_LSTAT
+.wait: in al, dx
+ and al, LST_TREG_EMPTY
+ jz .wait
+ mov dx, UART_DATA
+ mov al, ah
+ out dx, al
+
+ pop edx
+ ret
+
+
+
+ section .data
+numbuf: times 16 db 0