From 1ad3593c1b97027ffae0f1a97f58508d2980df00 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 7 Oct 2021 21:53:35 +0200 Subject: ATA: read identify data, detect drive size --- src/kernel/arch/i386/ata.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/kernel') diff --git a/src/kernel/arch/i386/ata.c b/src/kernel/arch/i386/ata.c index aaf05ff..e33b5af 100644 --- a/src/kernel/arch/i386/ata.c +++ b/src/kernel/arch/i386/ata.c @@ -4,6 +4,10 @@ #include +static struct { + uint32_t sectors; +} ata_drives[4]; + enum { LBAlo = 3, LBAmid = 4, @@ -29,8 +33,11 @@ static void ata_driveselect(int drive, int block) { static bool ata_identify(int drive) { uint16_t iobase = ata_iobase(drive); + uint16_t data[256]; uint8_t v; + // TODO test for float + ata_driveselect(drive, 0); for (int i = 2; i < 6; i++) port_out8(iobase + i, 0); @@ -49,7 +56,9 @@ static bool ata_identify(int drive) { while (!((v = port_in8(iobase + STATUS) & 0x9))); if (v & 1) return false; /* ERR was set, bail */ - // now I can read 512 bytes of data, TODO + for (int i = 0; i < 256; i++) + data[i] = port_in16(iobase); + ata_drives[drive].sectors = data[60] | (data[61] << 16); return true; } @@ -58,8 +67,11 @@ void ata_init(void) { for (int i = 0; i < 4; i++) { tty_const("probing drive "); _tty_var(i); - if (ata_identify(i)) - tty_const(" - exists"); + if (ata_identify(i)) { + tty_const(" - "); + _tty_var(ata_drives[i].sectors); + tty_const(" sectors (512b)"); + } tty_const("\n"); } } -- cgit v1.2.3