Improved serial init handling. Optimized pushing/poping.

This commit is contained in:
Jarkko Toivanen 2023-07-24 17:08:48 +03:00
parent 9fc1cd0064
commit ebf9982c07
Signed by: jt
GPG key ID: 9151B109B73ECAD5

View file

@ -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