summaryrefslogtreecommitdiff
path: root/src/kernel/arch
diff options
context:
space:
mode:
authordzwdz2021-10-07 21:53:35 +0200
committerdzwdz2021-10-07 21:53:35 +0200
commit1ad3593c1b97027ffae0f1a97f58508d2980df00 (patch)
treef9591eb84c8a7b47def0b242d5928aac7eea7b2e /src/kernel/arch
parentc52451dbe1628839c26500db42a05cfdb454afde (diff)
ATA: read identify data, detect drive size
Diffstat (limited to 'src/kernel/arch')
-rw-r--r--src/kernel/arch/i386/ata.c18
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");
}
}