2023-03-13 01:26

This commit is contained in:
Emanuele HF 2023-03-13 01:26:59 +01:00
parent a7134393f7
commit f619b9f100
8 changed files with 44 additions and 14 deletions

View File

@ -10,6 +10,7 @@
#define CMOS_ADDRESS 0x70
#define CMOS_DATA 0x71
#define CMOS_IRQ 8
#define REG_SECONDS 0x00
#define REG_MINUTES 0x02
@ -55,7 +56,7 @@ static void cmos_write_reg(uint8_t reg, uint8_t val);
static void cmos_read_date_unsafe(datetime_t *date);
void cmos_init(void) {
irq_register(8, cmos_irq_handler);
irq_register(CMOS_IRQ, cmos_irq_handler);
uint8_t val = cmos_read_reg(REG_STATUS_B);
val |= RB_INT_UPD;
@ -122,7 +123,7 @@ static void cmos_read_date_unsafe(datetime_t *date) {
}
static void cmos_irq_handler(uint8_t irq) {
if (irq != 8) {
if (irq != CMOS_IRQ) {
return;
}

View File

@ -11,6 +11,8 @@
#include <arch/i386/io.h>
#include <arch/i386/devices/serial.h>
#define KB_IRQ 1
typedef enum {
KB_WAIT,
KB_RECV_E0,
@ -40,11 +42,11 @@ static void kb_irq_handler(uint8_t irq);
void kb_init(void) {
cb_init(&kb_cb, kb_buffer, sizeof(kb_buffer));
irq_register(1, kb_irq_handler);
irq_register(KB_IRQ, kb_irq_handler);
}
static void kb_irq_handler(uint8_t irq) {
if (irq != 1) {
if (irq != KB_IRQ) {
return;
}

View File

@ -5,6 +5,8 @@
#include <arch/i386/devices/terminal.h>
#include <arch/i386/io.h>
#define PIT_IRQ 0
#define PIT_FREQUENCY 100
#define PIT_COMMAND 0x43
@ -22,11 +24,11 @@ void pit_init(void) {
outb(PIT_CH0_DATA, divisor & 0xff);
outb(PIT_CH0_DATA, divisor >> 8);
irq_register(0, pit_irq_handler);
irq_register(PIT_IRQ, pit_irq_handler);
}
static void pit_irq_handler(uint8_t irq) {
if (irq != 0) {
if (irq != PIT_IRQ) {
return;
}

View File

@ -85,7 +85,7 @@ static void serial_irq_handler(uint8_t irq);
static bool serial_setup(uint8_t id);
void serial_init(void) {
for (uint8_t i = 0; i < 4; i++) {
for (uint8_t i = 1; i <= SERIAL_PORT_NUM; i++) {
if (serial_setup(i)) {
PRINTK("serial: COM%d: ready", i);
}
@ -94,7 +94,7 @@ void serial_init(void) {
static bool serial_setup(uint8_t id) {
uint16_t port = serial_ports[id].port;
uint16_t divisor = 115200 / 38400;
uint16_t divisor = 115200 / 9600;
outb(port + REG_IER, 0x00); // 0b00000000
outb(port + REG_LCR, LCR_DLAB); // 0b10000000
@ -103,11 +103,13 @@ static bool serial_setup(uint8_t id) {
outb(port + REG_LCR, LCR_MODE(8, PAR_NONE, 1));
outb(port + REG_IIR, 0xC7); // 0b11000111
outb(port + REG_MCR, MCR_DTR | MCR_RTS | MCR_OUT2);
// outb(port + REG_MCR, MCR_DTR | MCR_RTS | MCR_OUT2);
outb(port + REG_MCR, MCR_RTS | MCR_OUT1 | MCR_OUT2 | MCR_LOOP);
outb(port + REG_DATA, 0xAE); // 0b10101110
if (inb(port + REG_DATA) != 0xAE) {
outb(port + REG_DATA, 0x58);
uint8_t tmp = inb(port + REG_DATA);
PRINTK("inb(%04x + REG_DATA) = %02x;", port, tmp);
if (tmp != 0x58) {
return false;
}

View File

@ -23,6 +23,25 @@ typedef struct {
} pci_driver_t;
pci_driver_t pci_drivers[] = {
{ .vendor_id = 0x1022, .device_id = 0x1200, .init = NULL, .exit = NULL, .name = "Family 10h Processor HyperTransport Configuration" },
{ .vendor_id = 0x1022, .device_id = 0x1201, .init = NULL, .exit = NULL, .name = "Family 10h Processor Address Map" },
{ .vendor_id = 0x1022, .device_id = 0x1202, .init = NULL, .exit = NULL, .name = "Family 10h Processor DRAM Controller" },
{ .vendor_id = 0x1022, .device_id = 0x1203, .init = NULL, .exit = NULL, .name = "Family 10h Processor Miscellaneous Control" },
{ .vendor_id = 0x1022, .device_id = 0x1204, .init = NULL, .exit = NULL, .name = "Family 10h Processor Link Control" },
{ .vendor_id = 0x10de, .device_id = 0x03d6, .init = NULL, .exit = NULL, .name = "C61 [GeForce 7025 / nForce 630a]" },
{ .vendor_id = 0x10de, .device_id = 0x03e1, .init = NULL, .exit = NULL, .name = "MCP61 LPC Bridge" },
{ .vendor_id = 0x10de, .device_id = 0x03e2, .init = NULL, .exit = NULL, .name = "MCP61 Host Bridge" },
{ .vendor_id = 0x10de, .device_id = 0x03e8, .init = NULL, .exit = NULL, .name = "MCP61 PCI Express bridge" },
{ .vendor_id = 0x10de, .device_id = 0x03e9, .init = NULL, .exit = NULL, .name = "MCP61 PCI Express bridge" },
{ .vendor_id = 0x10de, .device_id = 0x03eb, .init = NULL, .exit = NULL, .name = "MCP61 SMBus" },
{ .vendor_id = 0x10de, .device_id = 0x03ec, .init = NULL, .exit = NULL, .name = "MCP61 IDE" },
{ .vendor_id = 0x10de, .device_id = 0x03ef, .init = NULL, .exit = NULL, .name = "MCP61 Ethernet" },
{ .vendor_id = 0x10de, .device_id = 0x03f0, .init = NULL, .exit = NULL, .name = "MCP61 High Definition Audio" },
{ .vendor_id = 0x10de, .device_id = 0x03f1, .init = NULL, .exit = NULL, .name = "MCP61 USB 1.1 Controller" },
{ .vendor_id = 0x10de, .device_id = 0x03f2, .init = NULL, .exit = NULL, .name = "MCP61 USB 2.0 Controller" },
{ .vendor_id = 0x10de, .device_id = 0x03f3, .init = NULL, .exit = NULL, .name = "MCP61 PCI bridge" },
{ .vendor_id = 0x10de, .device_id = 0x03f5, .init = NULL, .exit = NULL, .name = "MCP61 Memory Controller" },
{ .vendor_id = 0x10de, .device_id = 0x03f6, .init = NULL, .exit = NULL, .name = "MCP61 SATA Controller" },
{ .vendor_id = 0x10ec, .device_id = 0x8168, .init = rtl8169_init, .exit = rtl8169_exit, .name = "RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller" },
{ .vendor_id = 0x1234, .device_id = 0x1111, .init = NULL, .exit = NULL, .name = "@ QEMU VGA" },
{ .vendor_id = 0x14e4, .device_id = 0x4315, .init = NULL, .exit = NULL, .name = "BCM4312 802.11b/g LP-PHY" },

View File

@ -51,6 +51,7 @@ void k_main(uint32_t mb_magic, multiboot_info_t *mb_info) {
parse_command_line((char *)(mb_info->cmdline));
platform_late_init();
console = 2;
mem_init((multiboot_memory_map_t *)(mb_info->mmap_addr), mb_info->mmap_length);
PRINTK("stub: %p-%p -> %p-%p", &stub_start_v, &stub_end_v, &stub_start_p, &stub_end_p);
@ -75,7 +76,7 @@ void k_main(uint32_t mb_magic, multiboot_info_t *mb_info) {
// proc_init();
// proc_print();
while (timer_uptime < 200) {};
while (timer_uptime < 500) {};
PRINTK("Date (k): %04d-%02d-%02d %02d:%02d:%02d.%09d",
global_dt.year, global_dt.month, global_dt.day,
global_dt.hour, global_dt.minute, global_dt.second, global_dt.nanosec);

View File

@ -7,6 +7,8 @@
#include <misc.h>
#include <utils/bit.h>
uint8_t console = 1;
const char *measure_units[] = {
"B",
"KiB",

View File

@ -6,9 +6,10 @@
#include <datetime.h>
#define PRINTK(_fmt, ...) printk(1, "[%5d.%02d] " _fmt "\r\n", timer_uptime / 100, timer_uptime % 100, ##__VA_ARGS__)
#define PRINT_EXPR(expr) printk(1, #expr " = %d;\r\n", expr);
#define PRINTK(_fmt, ...) printk(console, "[%5d.%02d] " _fmt "\r\n", timer_uptime / 100, timer_uptime % 100, ##__VA_ARGS__)
#define PRINT_EXPR(expr) PRINTK(#expr " = %d;\r\n", expr);
extern uint8_t console;
extern const char *measure_units[];
uint8_t get_measure_unit(uint32_t value);