feat: fixed some bugs for running on real hardware

This commit is contained in:
2021-03-05 22:23:39 +01:00
parent e532099ea7
commit 310f3621a2
6 changed files with 43 additions and 15 deletions

View File

@@ -125,12 +125,13 @@ char *exception_messages[] = {
};
void isr_handler(isr_registers_t r) {
char msg[256];
if (r.int_no == 128) {
syscall_handle(&r);
return;
}
printf("Received interrupt: %d - %s\n", r.int_no, exception_messages[r.int_no]);
k_panic();
sprintf(msg, "Received interrupt: %d - %s\n", r.int_no, exception_messages[r.int_no]);
k_panics(msg);
}
void register_interrupt_handler(uint8_t n, isr_t handler) {

View File

@@ -32,6 +32,8 @@ const pci_driver *pci_drivers[MAX_PCI_DRIVERS];
int last_pci_device_index = 0;
pci_device pci_devices[MAX_PCI_DEVICES];
void pci_check_bus(uint8_t bus);
uint32_t pci_register_driver(const pci_driver *pci_driver) {
for (int i = 0; i < MAX_PCI_DRIVERS; ++i) {
if (pci_drivers[i] != NULL) {
@@ -137,9 +139,16 @@ void pci_check_function(uint8_t bus, uint8_t slot, uint8_t func) {
pci_devices[last_pci_device_index].config_line_2 = pci_config_read_double_word(bus, slot, func, PCI_CONFIG_LINE_2);
pci_devices[last_pci_device_index].config_line_3 = pci_config_read_double_word(bus, slot, func, PCI_CONFIG_LINE_3);
pci_devices[last_pci_device_index].device_state.present = 1;
pci_pick_driver(&pci_devices[last_pci_device_index]);
last_pci_device_index++;
if (pci_devices[last_pci_device_index-1].class == 0x06 && pci_devices[last_pci_device_index-1].subclass == 0x04) {
uint8_t secondary_bus = pci_config_read_byte(bus, slot, func, PCI_CONFIG_SECONDARY_BUS_NUMBER);
printf("Found secondary bus: %d\n", secondary_bus);
pci_check_bus(secondary_bus);
} else {
pci_pick_driver(&pci_devices[last_pci_device_index-1]);
}
// todo do something with the function
}

View File

@@ -57,6 +57,23 @@
#define PCI_CONFIG_MAX_GRANT 0x3E
#define PCI_CONFIG_MAX_LATENCY 0x3F
// header type 1
#define PCI_CONFIG_PRIMARY_BUS_NUMBER 0x18
#define PCI_CONFIG_SECONDARY_BUS_NUMBER 0x19
#define PCI_CONFIG_SUBORDINATE_BUS_NUMBER 0x1A
#define PCI_CONFIG_SECONDARY_LATENCY_TIMER 0x1B
#define PCI_CONFIG_IO_BASE 0x1C
#define PCI_CONFIG_IO_LIMIT 0x1D
#define PCI_CONFIG_SECONDARY_STATUS 0x1E
#define PCI_CONFIG_MEMORY_BASE 0x20
#define PCI_CONFIG_MEMORY_LIMIT 0x22
#define PCI_CONFIG_MEMORY_BASE_UPPER 0x28
#define PCI_CONFIG_MEMORY_LIMIT_UPPER 0x2C
#define PCI_CONFIG_IO_BASE_UPPER 0x30
#define PCI_CONFIG_IO_LIMIT_UPPER 0x32
#define PCI_CONFIG_EXPANSION_ROM 0x38
#define PCI_CONFIG_BRIDGE_CONTROL 0x3E
#define PCI_INTERRUPT_LINE_DISABLED 0xff
typedef struct pci_driver pci_driver;

View File

@@ -123,6 +123,11 @@ void print_chars(char *chars, int amount) {
uint8_t fat_check_device(const block_device *device, uint8_t *first_sector) {
fat_bpb bpb;
memcpy((uint8_t *) &bpb, first_sector, sizeof(fat_bpb));
if (bpb.bpb.sectors_per_fat == 0 || bpb.bpb.sectors_per_cluster == 0) {
printf("Definitely not FAT\n");
return BLOCK_DEV_DRIVER_CHECK_NO_MATCH;
}
printf("OEM: ");
print_chars(bpb.bpb.oem_identifier, 11);
printf("\n");

View File

@@ -11,21 +11,12 @@
#include "kprint.h"
#define MAX_HANDLERS 8
#define STREAM_SIZE 512
#define STREAM_SIZE (32*1024)
#define PRINT_BUFFER_SIZE 64
stream_t *kprint_stream;
kprint_handler handlers[MAX_HANDLERS] = {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
kprint_handler handlers[MAX_HANDLERS] = {0};
void kprint_register(kprint_handler handler) {
for (int i = 0; i < MAX_HANDLERS; ++i) {

View File

@@ -8,6 +8,7 @@
#include <libk/syscall.h>
#include <stdbool.h>
#include <libc/kprintf.h>
#include <libc/libc.h>
typedef struct lock_fifo_entry {
uint32_t tid;
@@ -32,6 +33,7 @@ struct spinlock {
semaphore_t *semaphore_create(int32_t start) {
semaphore_t *semaphore = malloc(sizeof(semaphore_t));
memset((uint8_t *) semaphore, 0, sizeof(semaphore_t));
semaphore->value = start;
return semaphore;
}
@@ -43,6 +45,7 @@ void semaphore_wait(semaphore_t *semaphore) {
task_lock_acquire();
lock_fifo_entry_t *lock = malloc(sizeof(lock_fifo_entry_t));
lock->tid = task_get_current_tid();
lock->next = NULL;
if (semaphore->first_wait == NULL) {
semaphore->first_wait = lock;
} else {
@@ -77,6 +80,7 @@ void semaphore_free(semaphore_t *semaphore) {
mutex_t *mutex_create() {
mutex_t *mutex = malloc(sizeof(mutex_t));
memset((uint8_t *) mutex, 0, sizeof(mutex_t));
mutex->value = 1;
return mutex;
}
@@ -88,6 +92,7 @@ void mutex_acquire(mutex_t *mutex) {
task_lock_acquire();
lock_fifo_entry_t *lock = malloc(sizeof(lock_fifo_entry_t));
lock->tid = task_get_current_tid();
lock->next = NULL;
if (mutex->first_wait == NULL) {
mutex->first_wait = lock;
} else {