From a974ee305db72fccd5518f2d86d72710726db8d8 Mon Sep 17 00:00:00 2001 From: aaron Date: Wed, 25 Oct 2017 09:23:53 +0000 Subject: [PATCH] git-svn-id: https://spexeah.com:8443/svn/Asuro@243 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c --- src/driver/ATA.pas | 105 ++++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 45 deletions(-) diff --git a/src/driver/ATA.pas b/src/driver/ATA.pas index c4c03718..9f644dc7 100644 --- a/src/driver/ATA.pas +++ b/src/driver/ATA.pas @@ -25,21 +25,21 @@ type var //0 = primary, 1 = secondary - dataPort : array[0..1] of uint16; - errorPort : array[0..1] of uint8; - sectorCountPort : array[0..1] of uint8; - lbaLowPort : array[0..1] of uint8; - lbaMidPort : array[0..1] of uint8; - lbaHiPort : array[0..1] of uint8; - devicePort : array[0..1] of uint8; - commandPort : array[0..1] of uint8; - controlPort : array[0..1] of uint8; + dataPort : array[0..3] of uint16; + errorPort : array[0..3] of uint8; + sectorCountPort : array[0..3] of uint8; + lbaLowPort : array[0..3] of uint8; + lbaMidPort : array[0..3] of uint8; + lbaHiPort : array[0..3] of uint8; + devicePort : array[0..3] of uint8; + commandPort : array[0..3] of uint8; + controlPort : array[0..3] of uint8; bytes_per_sector : uint16 = 512; controller : TPCI_device; -procedure init(device : TPCI_device); +procedure init(); procedure identify(drive : uint8; bus : uint8); procedure read28(sector : uint32); procedure write28(sector : uint32; data : intptr; count : uint32); @@ -47,12 +47,13 @@ procedure flush(); implementation -procedure init(device : TPCI_device); +procedure init(); begin - controller := device; + //controller := device; controller.address0 := $1f0; - // 0x1f0, 0x170 + controller.address1 := $170; + // 0x1f0, 0x170, 0x3F6, 0x376 console.writehexln(controller.address0); dataPort[0] := controller.address0; errorPort[0] := controller.address0 + 1; @@ -62,7 +63,9 @@ begin lbaHiPort[0] := controller.address0 + 5; devicePort[0] := controller.address0 + 6; commandPort[0] := controller.address0 + 7; - controlPort[0] := controller.address0 + $206; + controlPort[0] := controller.address1 + 2; + + console.writestringln('Checking for ATA devices:'); identify($A0, $A0); identify($B0, $A0); @@ -76,45 +79,57 @@ var data : array[0..265] of uint16; begin + outb(controlPort[0], 2); + busNo := 0; if bus = $A0 then busNo := 0; outb(devicePort[busNo], drive); - outb(controlPort[busNo], 0); - outb(devicePort[busNo], bus); + psleep(1); + outb(sectorCountPort[busNo], 0); + psleep(1); + outb(lbaLowPort[busNo], 0); + psleep(1); + outb(lbaMidPort[busNo], 0); + psleep(1); + outb(lbaHiPort[busNo], 0); + psleep(1); + + outb(commandPort[busNo], $EC); + psleep(1); + status := inb(commandPort[busNo]); - if status <> $FF then begin - outb(devicePort[busNo], drive); - outb(sectorCountPort[busNo], 0); - outb(lbaLowPort[busNo], 0); - outb(lbaMidPort[busNo], 0); - outb(lbaHiPort[busNo], 0); - outb(commandPort[busNo], $EC); - status := inb(commandPort[busNo]); - - if status = 0 then exit; - - while((status and $08 = 08) and (status and $01 <> 1)) do begin - status := inb(commandPort[busNo]) - end; - status := inb(commandPort[busNo]); - - if status and $01 = 1 then begin - console.writestringln('ATA DEVICE ERROR'); - end else begin - for i:=0 to 265 do begin - data[i] := inw(dataPort[busNo]); - console.writestringln(pchar(@data[i])); - //console.writeint(data[i]); - psleep(10); - end; - end; - - end else begin - console.writestringln('no device'); + if status = $0 then begin + console.writestring('No drive found'); + exit; end; + while true do begin + status := inb(commandPort[busNo]); + + if status = 1 then begin + console.writestringln('Drive error'); + exit; + end; + + if (status and $80) = 0 then break; + + status := inb(errorPort[0]); + psleep(1); + if status = 1 then console.writestringln('ERROR ERROR ERROR'); + + status := inb(lbaMidPort[busNo]); + psleep(1); + + if status <> 0 then begin + console.writestringln('Device found, but is not ATA'); + exit; + end; + end; + + console.writestring('Drive found!'); + end; procedure read28(sector : uint32); begin