From ef72082b2df5da98de13bbc8c35b66d891bd4b78 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Thu, 26 Dec 2019 14:04:41 -0500 Subject: serial ports, echo vga output over COM2 --- src/kernel/serial.asm | 71 ++++++++++++++++++++++++++++++++++++++++++++++----- src/kernel/serial.h | 3 --- src/kernel/vga.c | 2 +- 3 files changed, 66 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/kernel/serial.asm b/src/kernel/serial.asm index 9ebf84c..9077d99 100644 --- a/src/kernel/serial.asm +++ b/src/kernel/serial.asm @@ -18,12 +18,71 @@ global send_byte global read_byte -section .text -;COM1: COM2: COM3: COM4: -;0x03f8, 0x02f8, 0x03e8, 0x02e8 - send_byte:;void send_byte(uint8_t value, uint8_t port) - ;TODO + push ebp + mov ebp, esp + + mov cl, byte [ebp + 8] ;value + xor edx, edx + mov dl, byte [ebp + 12];port + + test dl, 0xfc + jnz .leave + + xchg ebx, edx + shl bl, 1 + mov ax, word [ebx + com_ports] + mov ebx, edx + mov dx, ax + + or dx, 5 + +.check_ready: + in al, dx + test al, 0x20 + jz .check_ready + + and dx, 0xfff8 + + mov al, cl + out dx, al + +.leave: + leave + ret read_byte:;uint8_t read_byte(uint8_t port) - ;TODO \ No newline at end of file + push ebp + mov ebp, esp + + xor eax, eax + + xor edx, edx + mov dl, byte [ebp + 8];port + + test dl, 0xfc + jnz .leave + + xchg ebx, edx + shl bl, 1 + mov cx, word [ebx + com_ports] + mov ebx, edx + mov dx, cx + + or dx, 5 + +.check_ready: + in al, dx + test al, 0x01 + jz .check_ready + + and dx, 0xfff8 + + in al, dx + +.leave: + leave + ret + +section .rodata +com_ports dw 0x03f8, 0x02f8, 0x03e8, 0x02e8 \ No newline at end of file diff --git a/src/kernel/serial.h b/src/kernel/serial.h index d5e4038..88d3712 100644 --- a/src/kernel/serial.h +++ b/src/kernel/serial.h @@ -29,10 +29,7 @@ enum serials { COM4 = 3 }; -/* -Commenting out so I don't accidentally call garbage while these are unimplemented. void send_byte(uint8_t value, uint8_t port); uint8_t read_byte(uint8_t port); -*/ #endif \ No newline at end of file diff --git a/src/kernel/vga.c b/src/kernel/vga.c index 3d8de43..78da721 100644 --- a/src/kernel/vga.c +++ b/src/kernel/vga.c @@ -43,7 +43,7 @@ void scroll(void) { } void put_char(uint8_t ch) { - //send_byte(ch, COM2); + send_byte(ch, COM2); switch (ch) { case '\b': if (cursor_pos) -- cgit v1.2.3