feat(core): implement Linux-grade architecture (printk with loglevels, list.h, errno.h, procfs, devfs, slab cache, CMOS RTC & 16550A UART serial)
This commit is contained in:
1 parent
2bbeb3f345
commit
1832e7ecff
19 files changed
+805
-6
No files matched your search
@@ -0,0 +1,53 @@
|
||||
#include <airlys/rtc.h>
|
||||
#include <airlys/io.h>
|
||||
|
||||
#define CMOS_ADDRESS 0x70
|
||||
#define CMOS_DATA 0x71
|
||||
|
||||
static uint8_t cmos_read(uint8_t reg) {
|
||||
outb(CMOS_ADDRESS, reg);
|
||||
return inb(CMOS_DATA);
|
||||
}
|
||||
|
||||
static uint8_t bcd_to_binary(uint8_t bcd) {
|
||||
return ((bcd / 16) * 10) + (bcd & 0x0F);
|
||||
}
|
||||
|
||||
void rtc_init(void) {
|
||||
/* Initialize and verify RTC availability */
|
||||
}
|
||||
|
||||
rtc_time_t rtc_get_time(void) {
|
||||
rtc_time_t t;
|
||||
|
||||
/* Wait if RTC update in progress */
|
||||
while (cmos_read(0x0A) & 0x80) {}
|
||||
|
||||
t.second = cmos_read(0x00);
|
||||
t.minute = cmos_read(0x02);
|
||||
t.hour = cmos_read(0x04);
|
||||
t.day = cmos_read(0x07);
|
||||
t.month = cmos_read(0x08);
|
||||
uint8_t year_byte = cmos_read(0x09);
|
||||
|
||||
uint8_t register_b = cmos_read(0x0B);
|
||||
|
||||
/* Convert BCD to binary if needed */
|
||||
if (!(register_b & 0x04)) {
|
||||
t.second = bcd_to_binary(t.second);
|
||||
t.minute = bcd_to_binary(t.minute);
|
||||
t.hour = bcd_to_binary(t.hour & 0x7F) | (t.hour & 0x80);
|
||||
t.day = bcd_to_binary(t.day);
|
||||
t.month = bcd_to_binary(t.month);
|
||||
year_byte = bcd_to_binary(year_byte);
|
||||
}
|
||||
|
||||
/* Convert 12 hour clock to 24 hour if necessary */
|
||||
if (!(register_b & 0x02) && (t.hour & 0x80)) {
|
||||
t.hour = ((t.hour & 0x7F) + 12) % 24;
|
||||
}
|
||||
|
||||
t.year = 2000 + year_byte;
|
||||
|
||||
return t;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <airlys/serial.h>
|
||||
#include <airlys/io.h>
|
||||
|
||||
void serial_init(void) {
|
||||
outb(COM1_PORT + 1, 0x00); /* Disable all interrupts */
|
||||
outb(COM1_PORT + 3, 0x80); /* Enable DLAB (set baud rate divisor) */
|
||||
outb(COM1_PORT + 0, 0x01); /* Set divisor to 1 (115200 baud) */
|
||||
outb(COM1_PORT + 1, 0x00);
|
||||
outb(COM1_PORT + 3, 0x03); /* 8 bits, no parity, one stop bit */
|
||||
outb(COM1_PORT + 2, 0xC7); /* Enable FIFO, clear them, with 14-byte threshold */
|
||||
outb(COM1_PORT + 4, 0x0B); /* IRQs enabled, RTS/DSR set */
|
||||
}
|
||||
|
||||
static inline bool is_transmit_empty(void) {
|
||||
return (inb(COM1_PORT + 5) & 0x20) != 0;
|
||||
}
|
||||
|
||||
void serial_putchar(char c) {
|
||||
while (!is_transmit_empty()) {}
|
||||
outb(COM1_PORT, c);
|
||||
}
|
||||
|
||||
void serial_puts(const char* str) {
|
||||
if (!str) return;
|
||||
while (*str) {
|
||||
if (*str == '\n') {
|
||||
serial_putchar('\r');
|
||||
}
|
||||
serial_putchar(*str++);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user