Added support for setting up a serial port. This first serial driver appears to only work correctly in QEMU.

This commit is contained in:
2020-05-24 03:24:25 -05:00
parent cf88cb98fb
commit b409b3e9d2
11 changed files with 113 additions and 27 deletions
+59
View File
@@ -0,0 +1,59 @@
#include "../includes/io.h"
/* Sets the speed of the data being sent. The default speed of a serial port
is 115,200 bits/s. The argument is a divisor of that number, hence the resulting
speed becomes 115,200 / divisor bits/s.
*/
void set_serial_baud_rate(unsigned short com, unsigned short divisor){
outb(com + 3, 0x80);//SERIAL_LINE_ENABLE_DLAB);
outb(com, (divisor >> 8) & 0x00FF);
outb(com, divisor & 0x00FF);
}
void configure_serial_line(unsigned short com){
// Configuring the Line
/* d: Enables (1) or disables (0) DLAB
b: Break if controls is enabled (1)
parity: The number of parity bits to use
s: The number of stop bits to use (0 = One Stop, 1 = 1.5 or 2 stops)
dl: Describes the langth of the data
Bit: | 7 | 6 | 5 4 3 | 2 | 1 0 |
Content: | d | b | parity| s | dl |
Value: | 0 | 0 | 0 0 0 | 0 | 1 1 | = 0x03
*/
outb(com + 3, 0x03);
// Configuring the Buffers
/* lvl: How many bytes should be stored in the FIFO buffers
bs: If the buffers should be 16 or 64 bytes large
r: Reserved
dma: How the serial port data should be accessed
clt: Clear the transmission FIFO buffer
clr: Clear the reciever FIFO buffer
e: If the FIFO bufffer should be enabled or not
Bit: | 7 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Content: | lvl | bs| r | dma| clt| clr| e |
Value: | 1 1 | 0 | 0 | 0 | 1 | 1 | 1 |
*/
outb(com + 2, 0xC7);
// Confirgure the Modem
outb(com + 4, 0x03);
}
/* @return 0 if the FIFO is not empty
1 if the FIFO is empty
*/
int serial_transmit_fifo_empty(unsigned int com){
// 0x20 = 0010 0000
return inb((com + 5) & 0x20);
}
void write_to_com(unsigned int com, char* msg){
for(int i = 0; msg[i] != '\0'; i++){
while(serial_transmit_fifo_empty(com) == 0);
outb(com, (char) msg[i]);
}
}