still working on ata :(
This commit is contained in:
@@ -31,12 +31,96 @@ void scan_drives() {
|
||||
ide_devices[0].device = IDE_DRIVE_MASTER;
|
||||
ide_devices->type = type;
|
||||
|
||||
atapi_identify_data_t* ident_result = (atapi_identify_data_t*)secondary_master_info_buffer;
|
||||
atapi_identify_t* ident_result = (atapi_identify_t*)secondary_master_info_buffer;
|
||||
ide_devices->ident_info_struct = (void*)ident_result;
|
||||
|
||||
kprintf("Detected ATAPI master device on secondary bus\n");
|
||||
kprintf("Assigned ATAPI master device on secondary bus to drive %d\n", 0);
|
||||
uint8_t buf[2048];
|
||||
int rtn = read_atapi(IDE_SECONDARY_IO_BASE, IDE_DRIVE_MASTER, 0x10, 1, (uint16_t*)buf);
|
||||
if (rtn < 0) {
|
||||
if (rtn == -1) {
|
||||
kprintf("Read error, failed to send command\n");
|
||||
}
|
||||
|
||||
if (rtn == -2) {
|
||||
kprintf("Read error, failed to read sector\n");
|
||||
}
|
||||
|
||||
fix_ata_string(ident_result->model_num, 40);
|
||||
kprintf("Model Number: %s\n", ident_result->model_num);
|
||||
kprintf("Read error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
kprintf("Read first sector of drive\n");
|
||||
|
||||
if (buf[0] != 0x01) {
|
||||
kprintf("First byte not valid for ISO drive\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (buf[1] != 'C' || buf[2] != 'D') {
|
||||
kprintf("Magic bytes are invalid for ISO drive\n");
|
||||
return;
|
||||
}
|
||||
|
||||
kprintf("ISO filesystem detected on drive\n");
|
||||
}
|
||||
}
|
||||
|
||||
extern void outb(uint8_t port, uint8_t data);
|
||||
extern uint8_t inb(uint8_t port);
|
||||
extern void atapi_wait(uint16_t port);
|
||||
|
||||
int read_atapi(uint16_t bus, uint8_t drive, uint32_t lba, uint32_t sectors, uint16_t* buf) {
|
||||
volatile uint8_t read_cmd[12] = {0xA8, 0,
|
||||
(lba >> 0x18) & 0xFF, (lba >> 0x10) & 0xFF, (lba >> 0x08) & 0xFF,
|
||||
(lba >> 0x00) & 0xFF,
|
||||
(sectors >> 0x18) & 0xFF, (sectors >> 0x10) & 0xFF, (sectors >> 0x08) & 0xFF,
|
||||
(sectors >> 0x00) & 0xFF,
|
||||
0, 0};
|
||||
|
||||
outb(bus + IO_DRIVE_SELECT_REG, drive); // select drive
|
||||
atapi_wait(bus);
|
||||
outb(bus + IO_FEATURE_REG, 0x00);
|
||||
outb(bus + IO_LBA_MID_REG, 2048 & 0xFF);
|
||||
outb(bus + IO_LBA_HI_REG, 2048 >> 8);
|
||||
outb(bus + IO_CMD_REG, 0xA0);
|
||||
|
||||
atapi_wait(bus);
|
||||
atapi_wait(bus);
|
||||
|
||||
while (1) {
|
||||
kprintf("waiting bsy\n");
|
||||
uint8_t status = inb(bus + IO_STATUS_REG);
|
||||
if (status & STATUS_REG_BSY) {
|
||||
atapi_wait(bus);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (status & STATUS_REG_ERR)
|
||||
return -1;
|
||||
|
||||
if (status & STATUS_REG_DRQ)
|
||||
break;
|
||||
|
||||
atapi_wait(bus);
|
||||
}
|
||||
|
||||
send_scsi_packet(bus, (void*)read_cmd, 6);
|
||||
|
||||
for (uint32_t i = 0; i < sectors; i++) {
|
||||
while (1) {
|
||||
uint8_t status = inb(bus + IO_STATUS_REG);
|
||||
if (status & STATUS_REG_ERR)
|
||||
return -2;
|
||||
if (!(status & STATUS_REG_BSY) && (status & STATUS_REG_DRQ))
|
||||
break;
|
||||
atapi_wait(bus);
|
||||
}
|
||||
int bytes = inb(bus + IO_LBA_HI_REG) << 8 | inb(bus + IO_LBA_MID_REG);
|
||||
int words = bytes / 2;
|
||||
|
||||
read_data_words(bus, ((uint8_t*)buf + i * 0x800), words);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user