Skip to content

Commit f4ded2c

Browse files
author
Ian Seyler
committed
Serial input if no-LFB
- Enable serial interrupt - Add serial interrupt handler - `b_output_serial` will automatically output CR if LF is detected
1 parent d703d40 commit f4ded2c

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

src/drivers/serial.asm

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,26 @@ serial_init:
1515
bt ax, 0 ; LEGACY_DEVICES
1616
jnc serial_init_error
1717

18-
; TODO - Enable interrupts if needed
19-
2018
; Set flag that Serial was enabled
2119
or qword [os_SysConfEn], 1 << 2
2220

21+
%ifdef NO_LFB
22+
; Configure interrupt handler
23+
mov edi, 0x24
24+
mov rax, int_serial
25+
call create_gate
26+
27+
; Enable specific interrupts
28+
mov ecx, 4 ; Serial IRQ
29+
mov eax, 0x24 ; Serial Interrupt Vector
30+
call os_ioapic_mask_clear
31+
32+
; Enable serial port interrupts
33+
mov dx, COM_PORT_INTERRUPT_ENABLE
34+
mov al, 1 ; Set bit 0 for Received Data Available
35+
out dx, al
36+
%endif
37+
2338
serial_init_error:
2439
ret
2540
; -----------------------------------------------------------------------------
@@ -90,6 +105,19 @@ serial_recv_backspace:
90105
; -----------------------------------------------------------------------------
91106

92107

108+
; -----------------------------------------------------------------------------
109+
; serial_interrupt -- Receives a character via the configured serial port
110+
serial_interrupt:
111+
push rax
112+
113+
call serial_recv
114+
mov [key], al ; Treat the character as being from the keyboard
115+
116+
pop rax
117+
ret
118+
; -----------------------------------------------------------------------------
119+
120+
93121
; Port Registers
94122
COM_BASE equ 0x3F8
95123
COM_PORT_DATA equ COM_BASE + 0

src/interrupt.asm

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,29 @@ int_keyboard:
4949
; -----------------------------------------------------------------------------
5050

5151

52+
; -----------------------------------------------------------------------------
53+
; Serial interrupt. IRQ 0x04, INT 0x24
54+
; This IRQ runs whenever there is input on the serial port
55+
align 8
56+
int_serial:
57+
push rcx
58+
push rax
59+
60+
call serial_interrupt ; Call interrupt code in serial driver
61+
62+
; Acknowledge the IRQ
63+
mov ecx, APIC_EOI
64+
xor eax, eax
65+
call os_apic_write
66+
67+
call b_smp_wakeup_all ; A terrible hack
68+
69+
pop rax
70+
pop rcx
71+
iretq
72+
; -----------------------------------------------------------------------------
73+
74+
5275
; -----------------------------------------------------------------------------
5376
; Mouse interrupt. IRQ 0x0C, INT 0x2C
5477
; This IRQ runs whenever there is input on the mouse

src/syscalls/io.asm

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88

99
; -----------------------------------------------------------------------------
10-
; b_input -- Scans keyboard for input
10+
; b_input -- Scans for input
1111
; IN: Nothing
1212
; OUT: AL = 0 if no key pressed, otherwise ASCII code, other regs preserved
1313
; All other registers preserved
1414
b_input:
15-
mov al, [key]
15+
mov al, [key] ; Keyboard/Serial interrupt handler sets key
1616
test al, al
1717
jz b_input_no_key
18-
mov byte [key], 0x00 ; clear the variable as the keystroke is in AL now
18+
mov byte [key], 0x00 ; Clear the variable as the keystroke is in AL now
1919
b_input_no_key:
2020
ret
2121
; -----------------------------------------------------------------------------
@@ -44,6 +44,12 @@ b_output_serial:
4444

4545
b_output_serial_next:
4646
lodsb ; Load a byte from the string into AL
47+
cmp al, 10 ; Check for Line Feed
48+
jne b_output_serial_send
49+
mov al, 13 ; Carriage Return
50+
call serial_send
51+
mov al, 10
52+
b_output_serial_send:
4753
call serial_send ; Output it via serial
4854
dec cx ; Decrement the counter
4955
jnz b_output_serial_next ; Loop if counter isn't zero

0 commit comments

Comments
 (0)