diff options
author | dzwdz | 2021-10-07 21:53:35 +0200 |
---|---|---|
committer | dzwdz | 2021-10-07 21:53:35 +0200 |
commit | 1ad3593c1b97027ffae0f1a97f58508d2980df00 (patch) | |
tree | f9591eb84c8a7b47def0b242d5928aac7eea7b2e /src | |
parent | c52451dbe1628839c26500db42a05cfdb454afde (diff) |
ATA: read identify data, detect drive size
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/arch/i386/ata.c | 18 |
1 files changed, 15 insertions, 3 deletions
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 <kernel/arch/io.h> +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"); } } |