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 SERIAL_PORT equ 0x3f8
serialinitialized db 0
serialinit: serialinit:
pushad push ax
;Disable ints ;Disable ints
mov dx, SERIAL_PORT+1 mov dx, SERIAL_PORT+1
@ -46,21 +47,44 @@ serialinit:
out dx, al out dx, al
in al, dx in al, dx
cmp al, 0xae 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 ;; Set serial to normal operation
mov dx, SERIAL_PORT+4 mov dx, SERIAL_PORT+4
mov al, 0x0f mov al, 0x0f
out dx, al out dx, al
.end:
popad pop ax
ret ret
.errormsg db "Serial init failed", 0
serialwrite: serialwrite:
cmp [serialinitialized], 0
je .notinitialized
push ebp push ebp
mov ebp, esp mov ebp, esp
pushad push esi
push ax
cld cld
mov esi, [ebp+8] mov esi, [ebp+8]
.loop: .loop:
@ -76,22 +100,9 @@ serialwrite:
out dx, al out dx, al
jmp .loop jmp .loop
.done: .done:
popad pop ax
pop esi
pop ebp pop ebp
ret ret
.notinitialized:
serialiniterror:
mov esi, .msg
mov edi, 0xb8000
mov ah, 64
cld
.loop:
lodsb
or al, al
jz .done
stosw
jmp .loop
.done:
popad
ret ret
.msg db "Serial init failed", 0