Print IDE identify information

This commit is contained in:
Ali Mashtizadeh 2014-07-06 14:18:09 -07:00
parent 25ff76e4d7
commit 1acd37a644
2 changed files with 41 additions and 7 deletions

View File

@ -1,6 +1,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include <kassert.h> #include <kassert.h>
#include <sga.h> #include <sga.h>
@ -30,7 +31,9 @@ typedef struct ATAIdentifyDevice
uint16_t udmaMode; // 88 - Ultra DMA Mode uint16_t udmaMode; // 88 - Ultra DMA Mode
uint16_t _rsvd5[11]; // 89-99 uint16_t _rsvd5[11]; // 89-99
uint64_t lbaSectors; // 100-103 - User Addressable Logical Sectors uint64_t lbaSectors; // 100-103 - User Addressable Logical Sectors
uint16_t _rsvd6[151]; // 104-254 uint16_t _rsvd6[2]; // 104-105
uint16_t sectorSize; // 106 - Physical Sector Size
uint16_t _rsvd7[148]; // 107-254
uint16_t chksum; // 255 - Checksum uint16_t chksum; // 255 - Checksum
} ATAIdentifyDevice; } ATAIdentifyDevice;
@ -138,6 +141,28 @@ IDE_Reset(IDE *ide)
} }
} }
void
IDE_SwapAndTruncateString(char *str, int len)
{
int i;
ASSERT(len % 2 == 0);
for (i = 0; i < len/2; i++)
{
char tmp = str[2*i];
str[2*i] = str[2*i+1];
str[2*i+1] = tmp;
}
for (i = len - 1; i > 0; i--) {
if (str[i] == ' ' || str[i] == '\0')
str[i] = '\0';
else
break;
}
}
void void
IDE_Identify(IDE *ide, int drive) IDE_Identify(IDE *ide, int drive)
{ {
@ -165,8 +190,6 @@ IDE_Identify(IDE *ide, int drive)
return; return;
} }
kprintf("IDE: Waiting for ready! %08x\n", status);
// XXX: Need timeout // XXX: Need timeout
while (1) { while (1) {
if ((status & IDE_STATUS_BSY) == 0) if ((status & IDE_STATUS_BSY) == 0)
@ -179,12 +202,22 @@ IDE_Identify(IDE *ide, int drive)
return; return;
} }
kprintf("IDE: Ready!\n");
insw(ide->base, (void *)&ident, 256); insw(ide->base, (void *)&ident, 256);
kprintf("IDE: Ready!\n"); // Cleanup model and serial for printing
char model[41];
char serial[21];
Debug_PrintHex((const char *)&ident, 512, 0, 512); memcpy(&model[0], &ident.model[0], 40);
model[40] = '\0';
IDE_SwapAndTruncateString(&model[0], 40);
memcpy(&serial[0], &ident.serial[0], 20);
serial[20] = '\0';
IDE_SwapAndTruncateString(&serial[0], 20);
kprintf("IDE: Drive %d Model: %s Serial: %s\n", drive, model, serial);
kprintf("IDE: Drive %d %llu Sectors (%llu MBs)\n",
drive, ident.lbaSectors, ident.lbaSectors / 2048ULL);
} }

View File

@ -10,6 +10,7 @@
NO_RETURN void Panic(const char *str); NO_RETURN void Panic(const char *str);
int kprintf(const char *fmt, ...); int kprintf(const char *fmt, ...);
void Debug_PrintHex(const char *data, size_t length, off_t off, size_t limit);
#endif /* __KASSERT_H__ */ #endif /* __KASSERT_H__ */