Moving components modules to a more proper directory

This commit is contained in:
2023-03-30 22:40:08 -07:00
parent 044d5a75b5
commit cc1bb63e27
26 changed files with 11 additions and 148 deletions

View File

@@ -0,0 +1,89 @@
#include "serial.h"
/*
* SERIAL_LINE_COMMAND_PORT configuration
* Bit: | 7 | 6 | 5 4 3 | 2 | 1 0 |
* Content: | d | b | prty | s | dl |
* d = enable/disable DLAB
* b = enable/disable break control
* prty = # of parity bits to use
* s = # no of stop bits [0 is 1] and [1 is 1.5 or 2]
* dl = length of data
*
*/
void serial_set_baud_rate(const u16 com_port, const u16 divisor) {
// Activate line - ready to send higher 8 bits of data
// send the higher 8 bits first
// send the lower 8 bits next
serialport_write_byte(SERIAL_LINE_COMMAND_PORT(com_port),
SERIAL_LINE_ENABLE);
serialport_write_byte(SERIAL_DATA_PORT(com_port),
(divisor>>8) & 0x00ff);
serialport_write_byte(SERIAL_DATA_PORT(com_port),
divisor & 0x00ff);
}
// Payload described above
void serial_configure_line(const u16 line, const u8 payload) {
serialport_write_byte(SERIAL_LINE_COMMAND_PORT(line), payload);
}
u8 serial_fifo_empty(const u16 com_port) {
// we get back 0x20 if it is empty
return serial_read_byte(SERIAL_LINE_STATUS_PORT(com_port)) &
SERIAL_FIFO_EMPTY_CODE;
}
u64 serial_write(const char* buffer, const u64 size) {
/*
* Writes a given buffer to the com1 serial port for debugging in bochs
*/
serialport_write_byte(SERIAL_DATA_PORT_INT_EN(SERIAL_COM1_BASE),
0x00);
serialport_write_byte(SERIAL_LINE_COMMAND_PORT(SERIAL_COM1_BASE),
SERIAL_LINE_ENABLE);
// quarter speed hopefully the fifo quue wont fill this way
serialport_write_byte(SERIAL_COM1_BASE,
0x01);
serialport_write_byte(SERIAL_DATA_PORT_INT_EN(SERIAL_COM1_BASE),
0x00);
serialport_write_byte(SERIAL_LINE_COMMAND_PORT(SERIAL_COM1_BASE),
SERIAL_DEFAULT_LINE_CFG);
serialport_write_byte(SERIAL_FIFO_COMMAND_PORT(SERIAL_COM1_BASE),
SERIAL_DEFAULT_BUFFER_CFG);
serialport_write_byte(SERIAL_MODEM_COMMAND_PORT(SERIAL_COM1_BASE),
0x0B);
u64 idx;
for(idx =0; idx < size; idx++) {
serialport_write_byte(SERIAL_COM1_BASE, buffer[idx]);
}
return idx;
}
void serial_pic_ack(u32 interrupt) {
// ignore things that are too small and too big
if(interrupt < PIC1_START_INT || interrupt > PIC2_END_INT) {
return;
}
// Send acknoldgement to the pic that we have handled the interrupt
// without this it literally just wait for the ack
if(interrupt < PIC2_START_INT) {
serialport_write_byte(PIC1_PORT, PIC_ACK);
}
else {
serialport_write_byte(PIC2_PORT, PIC_ACK);
}
}

View File

@@ -0,0 +1,43 @@
#include "types.h"
#include "ports.h"
// Serial driver interface
#define SERIAL_COM1_BASE 0x03F8
#define SERIAL_DATA_PORT(base) (base)
#define SERIAL_DATA_PORT_INT_EN(base) (base+1)
#define SERIAL_FIFO_COMMAND_PORT(base) (base+2)
#define SERIAL_LINE_COMMAND_PORT(base) (base+3)
#define SERIAL_MODEM_COMMAND_PORT(base) (base+4)
#define SERIAL_LINE_STATUS_PORT(base) (base+5)
#define SERIAL_LINE_ENABLE 0x80
// Default configurations for serial ports/lines/buffers etc.
// Rational can be found here: https://littleosbook.github.io/#configuring-the-buffers
#define SERIAL_DEFAULT_LINE_CFG 0x03
#define SERIAL_DEFAULT_BUFFER_CFG 0xc7
#define SERIAL_DEFAULT_MODEM_CFG 0x03
#define SERIAL_FIFO_EMPTY_CODE 0x20
#define PIC1_PORT 0x20
#define PIC2_PORT 0xA0
#define PIC1_START_INT 0x20
#define PIC1_END_INT 0x27
#define PIC2_START_INT 0x28
#define PIC2_END_INT 0x2F
#define PIC_ACK 0x20
void serial_set_baud_rate(const u16, const u16);
void serial_configure_line(const u16, const u8);
u8 serial_fifo_empty(const u16);
u64 serial_write(const char* buffer, const u64 size);
void serial_pic_ack(u32 interrupt);