From ebf9982c0786af22f391b1e287718929c00adeaa Mon Sep 17 00:00:00 2001 From: Jarkko Toivanen Date: Mon, 24 Jul 2023 17:08:48 +0300 Subject: [PATCH] Improved serial init handling. Optimized pushing/poping. --- src/serial.asm | 57 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/serial.asm b/src/serial.asm index 4f6585e..39293ec 100644 --- a/src/serial.asm +++ b/src/serial.asm @@ -1,7 +1,8 @@ SERIAL_PORT equ 0x3f8 +serialinitialized db 0 serialinit: - pushad + push ax ;Disable ints mov dx, SERIAL_PORT+1 @@ -46,21 +47,44 @@ serialinit: out dx, al in al, dx cmp al, 0xae - jne serialiniterror - - + je .noerror +.error: + push esi + push edi + push ax + mov esi, .errormsg + mov edi, 0xb8000 + mov ah, 64 + cld +.errorloop: + lodsb + or al, al + jz .errordone + stosw + jmp .errorloop +.errordone: + pop ax + pop edi + pop esi + jmp .end +.noerror: + mov [serialinitialized], 1 ;; Set serial to normal operation mov dx, SERIAL_PORT+4 mov al, 0x0f out dx, al - - popad +.end: + pop ax ret +.errormsg db "Serial init failed", 0 serialwrite: + cmp [serialinitialized], 0 + je .notinitialized push ebp mov ebp, esp - pushad + push esi + push ax cld mov esi, [ebp+8] .loop: @@ -76,22 +100,9 @@ serialwrite: out dx, al jmp .loop .done: - popad + pop ax + pop esi pop ebp ret - -serialiniterror: - mov esi, .msg - mov edi, 0xb8000 - mov ah, 64 - cld -.loop: - lodsb - or al, al - jz .done - stosw - jmp .loop -.done: - popad +.notinitialized: ret -.msg db "Serial init failed", 0