UEFI and ATA PIO mode
Posted: Sun Mar 22, 2020 6:01 pm
Recently, I've switched to UEFI. I'm trying to use ATA PIO to load my kernel from the disk. I do not wish to store any part of the kernel in the EFI partition. Whenever I try to issue a command, it always responds with the error: 0x4 (Command aborted). I'm using 64 UEFI, compiled with gcc targeted for windows. I used the EFI loaded image protocol to get the drive information.
Code: Select all
#define ERROR 1
#define LBA_LOW 3
#define LBA_MID 4
#define LBA_HIGH 5
#define DRIVE 6
#define STATUS 7
#define COMMAND 7
UINT16 bus;
if (info.Drive.ATAPI.primarySecondary == ATAPI_PRIMARY) {
bus = 0x1f0;
} else {
bus = 0x170;
}
UINT8 selector;
if (info.Drive.ATAPI.masterSlave == ATAPI_MASTER) {
selector = 0xa0;
} else {
selector = 0xb0;
}
// Identify the drive
outb(bus+DRIVE, selector);
outb(bus+LBA_LOW, 0);
outb(bus+LBA_MID, 0);
outb(bus+LBA_HIGH, 0);
outb(bus+COMMAND, 0xec);
uint8_t status = inb(bus+STATUS);
if (status == 0) {
return 0;
}
while (status & 0x80) {
status = inb(bus+STATUS);
}
while (!(status & 7) || !(status & 1)) {
status = inb(bus+STATUS);
}
if (status & 1) {
printhex(status, 0);
print(" ");
status = inb(bus+ERROR);
printhex(status, 1);
return 0;
}