Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/drivers/serial.asm
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,26 @@ serial_init:
bt ax, 0 ; LEGACY_DEVICES
jnc serial_init_error

; TODO - Enable interrupts if needed

; Set flag that Serial was enabled
or qword [os_SysConfEn], 1 << 2

%ifdef NO_LFB
; Configure interrupt handler
mov edi, 0x24
mov rax, int_serial
call create_gate

; Enable specific interrupts
mov ecx, 4 ; Serial IRQ
mov eax, 0x24 ; Serial Interrupt Vector
call os_ioapic_mask_clear

; Enable serial port interrupts
mov dx, COM_PORT_INTERRUPT_ENABLE
mov al, 1 ; Set bit 0 for Received Data Available
out dx, al
%endif

serial_init_error:
ret
; -----------------------------------------------------------------------------
Expand Down Expand Up @@ -90,6 +105,19 @@ serial_recv_backspace:
; -----------------------------------------------------------------------------


; -----------------------------------------------------------------------------
; serial_interrupt -- Receives a character via the configured serial port
serial_interrupt:
push rax

call serial_recv
mov [key], al ; Treat the character as being from the keyboard

pop rax
ret
; -----------------------------------------------------------------------------


; Port Registers
COM_BASE equ 0x3F8
COM_PORT_DATA equ COM_BASE + 0
Expand Down
23 changes: 23 additions & 0 deletions src/interrupt.asm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ int_keyboard:
; -----------------------------------------------------------------------------


; -----------------------------------------------------------------------------
; Serial interrupt. IRQ 0x04, INT 0x24
; This IRQ runs whenever there is input on the serial port
align 8
int_serial:
push rcx
push rax

call serial_interrupt ; Call interrupt code in serial driver

; Acknowledge the IRQ
mov ecx, APIC_EOI
xor eax, eax
call os_apic_write

call b_smp_wakeup_all ; A terrible hack

pop rax
pop rcx
iretq
; -----------------------------------------------------------------------------


; -----------------------------------------------------------------------------
; Mouse interrupt. IRQ 0x0C, INT 0x2C
; This IRQ runs whenever there is input on the mouse
Expand Down
19 changes: 16 additions & 3 deletions src/syscalls/io.asm
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@


; -----------------------------------------------------------------------------
; b_input -- Scans keyboard for input
; b_input -- Scans for input
; IN: Nothing
; OUT: AL = 0 if no key pressed, otherwise ASCII code, other regs preserved
; All other registers preserved
b_input:
mov al, [key]
mov al, [key] ; Keyboard/Serial interrupt handler sets key
test al, al
jz b_input_no_key
mov byte [key], 0x00 ; clear the variable as the keystroke is in AL now
mov byte [key], 0x00 ; Clear the variable as the keystroke is in AL now
b_input_no_key:
ret
; -----------------------------------------------------------------------------
Expand Down Expand Up @@ -44,6 +44,14 @@ b_output_serial:

b_output_serial_next:
lodsb ; Load a byte from the string into AL
cmp al, 3 ; Check for Decrement cursor
je b_output_serial_decrement
cmp al, 10 ; Check for Line Feed
jne b_output_serial_send
mov al, 13 ; Carriage Return
call serial_send
mov al, 10
b_output_serial_send:
call serial_send ; Output it via serial
dec cx ; Decrement the counter
jnz b_output_serial_next ; Loop if counter isn't zero
Expand All @@ -52,6 +60,11 @@ b_output_serial_next:
pop rcx
pop rsi
ret

b_output_serial_decrement:
mov al, 8 ; Backspace
jmp b_output_serial_send

; -----------------------------------------------------------------------------


Expand Down