Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.

Commit 4525a95

Browse files
committed
complete FAT16 driver
1 parent 26cb93d commit 4525a95

9 files changed

Lines changed: 726 additions & 394 deletions

File tree

src/kernel/driver/ata.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
#include <util/console.h>
44
#include <interrupt/irq.h>
55

6+
/* Detected drive id recorded after successful ata_init() */
7+
static int g_ata_detected_drive = -1;
8+
9+
int ata_get_detected_drive(void) {
10+
return g_ata_detected_drive;
11+
}
12+
613
/**
714
* @brief ATAデバイスの準備完了を待つ
815
*/
@@ -81,11 +88,12 @@ int ata_init(void) {
8188
const struct {
8289
uint16_t base;
8390
uint8_t drive_sel;
91+
uint8_t drive_id; /* drive id used by ata_read_sectors */
8492
const char *name;
8593
} drives[] = {
86-
{ ATA_PRIMARY_DATA, ATA_SLAVE, "Primary Slave (hdb)" },
87-
{ ATA_SECONDARY_DATA, ATA_MASTER, "Secondary Master (hdc)" },
88-
{ ATA_PRIMARY_DATA, ATA_MASTER, "Primary Master (hda)" },
94+
{ ATA_PRIMARY_DATA, ATA_SLAVE, 1, "Primary Slave (hdb)" },
95+
{ ATA_SECONDARY_DATA, ATA_MASTER, 2, "Secondary Master (hdc)" },
96+
{ ATA_PRIMARY_DATA, ATA_MASTER, 0, "Primary Master (hda)" },
8997
};
9098

9199
for (int i = 0; i < 3; i++) {
@@ -168,11 +176,21 @@ int ata_init(void) {
168176
printk("ATA: reading IDENTIFY data from base 0x%x\n",
169177
drives[i].base);
170178
#endif
179+
#ifdef INIT_MSG
180+
for (int j = 0; j < 256; j++) {
181+
(void)inw(drives[i].base);
182+
}
183+
#else
171184
for (int j = 0; j < 256; j++) {
172185
(void)inw(drives[i].base);
173186
}
187+
#endif
188+
#ifdef INIT_MSG
189+
#endif
190+
g_ata_detected_drive = drives[i].drive_id;
174191
#ifdef INIT_MSG
175-
printk("ATA: %s detected successfully!\n", drives[i].name);
192+
printk("ATA: %s detected successfully! (drive=%u)\n",
193+
drives[i].name, g_ata_detected_drive);
176194
#endif
177195
return 0;
178196
}

src/kernel/driver/ata.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@
6464
*/
6565
int ata_init(void);
6666

67+
/**
68+
* @brief Get the detected ATA drive id after ata_init()
69+
*
70+
* @return drive id (0=Primary Master,1=Primary Slave,2=Secondary Master,3=Secondary Slave) or -1 if none
71+
*/
72+
int ata_get_detected_drive(void);
73+
6774
/**
6875
* @brief ATAデバイスからセクタを読み取る
6976
*

0 commit comments

Comments
 (0)