diff --git a/src/drivers/serial.asm b/src/drivers/serial.asm index ca997bc..0467557 100644 --- a/src/drivers/serial.asm +++ b/src/drivers/serial.asm @@ -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 ; ----------------------------------------------------------------------------- @@ -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 diff --git a/src/interrupt.asm b/src/interrupt.asm index 9d46297..0b66f90 100644 --- a/src/interrupt.asm +++ b/src/interrupt.asm @@ -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 diff --git a/src/syscalls/io.asm b/src/syscalls/io.asm index d1b8e57..f3357a9 100644 --- a/src/syscalls/io.asm +++ b/src/syscalls/io.asm @@ -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 ; ----------------------------------------------------------------------------- @@ -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 @@ -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 + ; -----------------------------------------------------------------------------