Guest User

Untitled

a guest
Dec 2nd, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. int ata_Identify(uint16_t bus, uint8_t ms) {
  2.    
  3.     outb(bus + DEVICE, ms);
  4.  
  5.     outb(bus + SEC_COUNT,0);
  6.     outb(bus + LBA_L,0);
  7.     outb(bus + LBA_M,0);
  8.     outb(bus + LBA_H,0);
  9.  
  10.     outb(bus + COMMAND,0xEC);
  11.  
  12.     if(ata_Status(bus + COMMAND) == 0) {
  13.         return -1;
  14.     }
  15.  
  16.     // Retrieve Status until BSY clears
  17.     while(ata_Status(bus + COMMAND) & BSY) {
  18.         kprintf("Stuck\n");
  19.     }
  20.  
  21.     // Check for lba mid and high
  22.     if(inb(bus+LBA_M) != 0 || inb(bus+LBA_H) != 0) {
  23.         return -1;
  24.     }
  25.  
  26.     uint8_t status;
  27.     while(((status = ata_Status(bus + COMMAND) & 0x9) == 0)) {
  28.         kprintf("Stuck2\n");
  29.     }
  30.  
  31.     if(status & ERR) {
  32.         return -1;
  33.     }
  34.  
  35.     uint16_t data[256];
  36.     for(int i = 0; i < 256; i++) {
  37.         data[i] = inb(bus);
  38.     }
  39.  
  40.     kprintf("%x",((uint32_t)data[61] << 16 | data[60]));
  41.    
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment