From e8c6577617bffa4402c07c7aa20e3c24f03c1c20 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 6 Sep 2020 00:48:07 -0400 Subject: program loading, others big kernel additions: paging, elf loading, separate kernel and user page allocation it now properly loads and runs sd0:bin/init.elf still need to determine which disk was booted from, and start the init on that disk --- src/kernel/ide.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'src/kernel/ide.c') diff --git a/src/kernel/ide.c b/src/kernel/ide.c index a4ba34c..70b1dee 100644 --- a/src/kernel/ide.c +++ b/src/kernel/ide.c @@ -15,7 +15,7 @@ struct ide_drive_info { }; static struct ide_drive_info ide_drives[MAX_IDE_DRIVES]; -static drive_id_t n_ide_drives = 0; +static drive_id_t n_ide_drives; typedef uint16_t spinner_t; @@ -53,7 +53,7 @@ static uint8_t wait_for_data_ready_not_busy(uint16_t base_port) { panic("Spun out in IDE driver."); } -static uint8_t ide_ata_rs(const struct drive *d, uint32_t start, uint32_t count, void *buffer) { +static uint32_t ide_ata_rs(const struct drive *d, uint32_t start, uint32_t count, void *buffer) { if (start >= d->n_sectors) return 0; if (start + count > d->n_sectors) @@ -91,21 +91,29 @@ static uint8_t ide_ata_rs(const struct drive *d, uint32_t start, uint32_t count, return count; } -static uint8_t ide_ata_ws(const struct drive *d, uint32_t start, uint32_t count, const void *buffer) { +static uint32_t ide_ata_ws(const struct drive *d, uint32_t start, uint32_t count, const void *buffer) { panic("IDE ATA writing not implemented yet"); return 0; } -static uint8_t ide_atapi_rs(const struct drive *d, uint32_t start, uint32_t count, void *buffer) { - //panic("IDE ATAPI reading not implemented yet"); - return 0; +static uint32_t ide_atapi_rs(const struct drive *d, uint32_t start, uint32_t count, void *buffer) { + if (start >= d->n_sectors) + return 0; + if (start + count > d->n_sectors) + count = d->n_sectors - start; + if (!count) + return 0; + + } -static uint8_t ide_atapi_ws(const struct drive *d, uint32_t start, uint32_t count, const void *buffer) { +static uint32_t ide_atapi_ws(const struct drive *d, uint32_t start, uint32_t count, const void *buffer) { panic("IDE ATAPI writing not implemented yet"); return 0; } +static void nop(const struct drive *d) { } + struct id_space { uint8_t skip1[120]; uint32_t max_lba;//120 @@ -132,9 +140,13 @@ static void test_drive(uint16_t base_port, uint16_t alt_port, bool slave) { outb(base_port | ATA_REG_CMD, ATA_CMD_ID); - if (!inb(base_port | ATA_REG_STATUS)) + uint8_t status = inb(base_port | ATA_REG_STATUS); + if (!status || (status == 0x7f)) return; + next_d.ready = &nop; + next_d.done = &nop; + struct id_space ids; if (!(wait_for_error_or_ready(base_port) & ATA_STATUS_ERROR)) { @@ -157,7 +169,7 @@ static void test_drive(uint16_t base_port, uint16_t alt_port, bool slave) { next_d.write_sectors = &ide_atapi_ws; //TODO: issue proper identify command - ids.max_lba = -1; + return; } else if (code == 0xc33c) { next_d.drive_type = "IDE SATA"; @@ -177,6 +189,8 @@ static void test_drive(uint16_t base_port, uint16_t alt_port, bool slave) { } void init_ide() { + n_ide_drives = 0; + uint16_t check_from = 0; struct pci_device *device; //double parentheses to let gcc know this assignment isn't a mistake -- cgit v1.2.3