First pass at getting Acadia running under bochs.
- Create a bochs build script. - Properly configure COM1
This commit is contained in:
parent
93d1299bd9
commit
5a20c23569
9 changed files with 153 additions and 40 deletions
|
|
@ -39,3 +39,52 @@ void dbgln(const glcr::StringView& str) {
|
|||
dbg(str);
|
||||
dbg("\n");
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Helper function to write a byte to a specified COM1 register offset
|
||||
void write_serial_port(uint16_t offset, uint8_t value) {
|
||||
outb(COM1 + offset, value);
|
||||
}
|
||||
|
||||
// Helper function to read a byte from a specified COM1 register offset
|
||||
uint8_t read_serial_port(uint16_t offset) { return inb(COM1 + offset); }
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace serial {
|
||||
|
||||
// Function to initialize the serial port with a given baud rate
|
||||
void initialize(uint32_t baud_rate) {
|
||||
// Disable interrupts
|
||||
write_serial_port(1, 0x00);
|
||||
|
||||
// Enable DLAB (Divisor Latch Access Bit) in Line Control Register (LCR)
|
||||
write_serial_port(3, read_serial_port(3) | 0x80);
|
||||
|
||||
// Calculate the divisor
|
||||
// Baud rate = 115200 / divisor (approximately)
|
||||
uint16_t divisor = 115200 / baud_rate;
|
||||
|
||||
// Set the low byte of the divisor
|
||||
write_serial_port(0, divisor & 0xFF);
|
||||
|
||||
// Set the high byte of the divisor
|
||||
write_serial_port(1, (divisor >> 8) & 0xFF);
|
||||
|
||||
// Clear DLAB and set data bits, stop bits, and parity
|
||||
// 8 data bits, 1 stop bit, no parity
|
||||
write_serial_port(3, 0x03); // 00000011b
|
||||
|
||||
// Enable FIFO, clear buffers, set trigger level (e.g., 1 byte)
|
||||
write_serial_port(2, 0xC7); // 11000111b
|
||||
|
||||
// Enable IRQs (optional, for interrupt-driven communication)
|
||||
// write_serial_port(1, 0x01);
|
||||
|
||||
// Set Modem Control Register (MCR)
|
||||
// Enable RTS, DTR, OUT1, OUT2, loopback off, IRQs enabled
|
||||
write_serial_port(4, 0x0B); // 00001011b
|
||||
}
|
||||
|
||||
} // namespace serial
|
||||
|
|
|
|||
|
|
@ -37,3 +37,9 @@ void panic(const char* str, Args&&... args) {
|
|||
#define UNREACHABLE \
|
||||
panic("Unreachable {}, {}", glcr::StringView(__FILE__), __LINE__); \
|
||||
__builtin_unreachable();
|
||||
|
||||
namespace serial {
|
||||
|
||||
void initialize(uint32_t baud_rate);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue