diff options
author | Marvin Borner | 2021-04-09 01:09:07 +0200 |
---|---|---|
committer | Marvin Borner | 2021-04-09 01:09:07 +0200 |
commit | f8d841fe268ebba43686729af535e035702438f7 (patch) | |
tree | 91dc31bbfb89a1474dc9c875fa6809843dc1869e | |
parent | cff1032555afc9853a490714d7cfa22fdb4c499d (diff) |
Using booting drive instead of ata detection
-rw-r--r-- | boot/entry.asm | 3 | ||||
-rw-r--r-- | boot/load.c | 69 |
2 files changed, 4 insertions, 68 deletions
diff --git a/boot/entry.asm b/boot/entry.asm index 8f12dff..dc65b97 100644 --- a/boot/entry.asm +++ b/boot/entry.asm @@ -454,6 +454,9 @@ protected_mode: mov ax, (gdt_tss - gdt) | 0b11 ; Load TSS in ring 3 ltr ax + mov eax, drive ; Pass drive to kernel loader + push eax ; Push as third kernel parameter + mov eax, vid_info ; Pass VBE struct to kernel loader push eax ; Push as second kernel parameter diff --git a/boot/load.c b/boot/load.c index 12102a2..dfa6e9c 100644 --- a/boot/load.c +++ b/boot/load.c @@ -508,55 +508,6 @@ static void print(const char *data) * IDE/ATA */ -static u8 *ide_buf = NULL; - -static void ide_select_drive(u8 bus, u8 drive) -{ - if (bus == ATA_PRIMARY) { - if (drive == ATA_MASTER) - outb(ATA_PRIMARY_IO + ATA_REG_HDDEVSEL, 0xa0); - else - outb(ATA_PRIMARY_IO + ATA_REG_HDDEVSEL, 0xb0); - } else { - if (drive == ATA_MASTER) - outb(ATA_SECONDARY_IO + ATA_REG_HDDEVSEL, 0xa0); - else - outb(ATA_SECONDARY_IO + ATA_REG_HDDEVSEL, 0xb0); - } -} - -static u8 ide_find(u8 bus, u8 drive) -{ - u16 io = bus == ATA_PRIMARY ? ATA_PRIMARY_IO : ATA_SECONDARY_IO; - ide_select_drive(bus, drive); - - // Reset - outb(io + ATA_REG_SECCOUNT0, 0); - outb(io + ATA_REG_LBA0, 0); - outb(io + ATA_REG_LBA1, 0); - outb(io + ATA_REG_LBA2, 0); - - // Identify - outb(io + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - u8 status = inb(io + ATA_REG_STATUS); - if (!status) - return 0; - - while ((inb(io + ATA_REG_STATUS) & ATA_SR_BSY) != 0) - ; - - do { - status = inb(io + ATA_REG_STATUS); - if (status & ATA_SR_ERR) - return 0; - } while ((status & ATA_SR_DRQ) == 0); - - for (int i = 0; i < BLOCK_COUNT; i++) - *(u16 *)(ide_buf + i * 2) = inw(io + ATA_REG_DATA); - - return 1; -} - static void ide_delay(u16 io) // 400ns { for (int i = 0; i < 4; i++) @@ -611,23 +562,6 @@ static u32 ata_read(void *buf, u32 lba, u32 sector_count, u8 drive) return sector_count; } -static u8 ata_probe(void) -{ - for (u8 i = 0; i < 4; i++) { - u32 bus = i < 2 ? ATA_PRIMARY : ATA_SECONDARY; - u32 drive = i % 2 ? ATA_MASTER : ATA_SLAVE; - - if (!ide_find(bus, drive)) - continue; - - u8 found_drive = (bus << 1) | drive; - // TODO: What about the other drives? - return found_drive; - } - - return 0; -} - /** * EXT2 */ @@ -885,12 +819,11 @@ static s32 elf_load(const char *path, u8 drive) * Let's go! */ -int main(void *first, void *second) +int main(void *first, void *second, u8 drive) { serial_install(); print("Loaded bootloader!\n"); - u8 drive = ata_probe(); assert(drive); s32 elf = elf_load("/apps/kernel/exec", drive); |