diff --git a/sys/dev/x86/ide.c b/sys/dev/x86/ide.c index f24ec03..c0b8a70 100644 --- a/sys/dev/x86/ide.c +++ b/sys/dev/x86/ide.c @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -30,7 +31,9 @@ typedef struct ATAIdentifyDevice uint16_t udmaMode; // 88 - Ultra DMA Mode uint16_t _rsvd5[11]; // 89-99 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 } 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 IDE_Identify(IDE *ide, int drive) { @@ -165,8 +190,6 @@ IDE_Identify(IDE *ide, int drive) return; } - kprintf("IDE: Waiting for ready! %08x\n", status); - // XXX: Need timeout while (1) { if ((status & IDE_STATUS_BSY) == 0) @@ -179,12 +202,22 @@ IDE_Identify(IDE *ide, int drive) return; } - kprintf("IDE: Ready!\n"); - 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); } diff --git a/sys/include/kassert.h b/sys/include/kassert.h index 1e068aa..dc367a3 100644 --- a/sys/include/kassert.h +++ b/sys/include/kassert.h @@ -10,6 +10,7 @@ NO_RETURN void Panic(const char *str); int kprintf(const char *fmt, ...); +void Debug_PrintHex(const char *data, size_t length, off_t off, size_t limit); #endif /* __KASSERT_H__ */