diff --git a/Makefile b/Makefile index 1079496..984faba 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ image: grub-mkrescue -o boot.iso grubshit test: - qemu-system-i386 -hda boot.iso -m 512M + qemu-system-i386 -drive file=boot.iso,media=disk,format=raw -m 512M $(OUTPUT): $(OBJS) $(CC) -T $(LDSCRIPT) -o $@ $(OBJS) $(LDFLAGS) diff --git a/src/disk.c b/src/disk.c index ecc9568..ef8daff 100644 --- a/src/disk.c +++ b/src/disk.c @@ -57,35 +57,40 @@ void get_disk_info(disk_info *info) { // Send the identify command ide_send_command(IDE_CMD_IDENTIFY);//0xEC - uint8_t huy = inportb(0x1F7); - printf("huy is %X\n", huy); + uint8_t status = inportb(0x1F7); + printf("status is %X\n", status); - if(huy == 0) - return; + if(!status) + { + printf("!status\n"); + return; + } + while((inportb(0x1F7) & STATUS_BUSY) != 0); - // Wait for the data to be ready - while (ide_read_status() & STATUS_BUSY); + while(1){ + status = inportb(0x1F7); + if(status & STATUS_ERR) + { + printf("ERROR! drive has err set. returning...\n"); + return; + } + if(status & STATUS_DRQ) + break; + } + + printf("disk is online\n"); uint8_t lbaMID, lbaHI; lbaMID = inportb(0x1F4); lbaHI = inportb(0x1F5); - //TODO: FIX THIS FUCKERY if(lbaMID != 0 || lbaHI != 0) { printf("ERROR! lbaMID: %X, lbaHI: %X\n", lbaMID, lbaHI); + printf("The drive is not ATA\n"); return; } - //while(!(ide_read_status() & STATUS_DRQ));//wait for the DRQ bit to be set - - while(1) - { - uint8_t status = ide_read_status(); - if(status & STATUS_DRQ || status & STATUS_ERR) - break; - } - // Read the data unsigned short data[256]; for (int i = 0; i < 256; i++) { @@ -93,9 +98,9 @@ void get_disk_info(disk_info *info) { } // Extract the disk information - info->cylinders = (data[1] >> 8) | (data[2] << 8); - info->heads = data[3]; - info->sectors = data[6]; + info->cylinders = (data[1] >> 8) | (data[2] << 8); // Cylinder count + info->heads = data[6]; // Heads per cylinder + info->sectors = data[3]; // Sectors per track } // Function to check if a disk is present diff --git a/src/kernel.c b/src/kernel.c index b4fcd36..b4d0fe9 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -18,13 +18,13 @@ void kmain() char yooo[256] = "heheh"; printf("test string: %s\n", yooo); - printf("checking for disk...\n"); - int disk_present = ide_check_disk_present(); - printf("we got the result, it's %X\n", disk_present); + //printf("checking for disk...\n"); + //int disk_present = ide_check_disk_present(); + //printf("we got the result, it's %X\n", disk_present); - disk_info *info; - get_disk_info(info); - printf("CYL HEAD SECT: %X %X %X\n", info->cylinders, info->heads, info->sectors); + disk_info info; + get_disk_info(&info); + printf("CYL HEAD SECT: %X %X %X\n", info.cylinders, info.heads, info.sectors); while(1) {