git-svn-id: https://spexeah.com:8443/svn/Asuro@243 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c

This commit is contained in:
aaron 2017-10-25 09:23:53 +00:00
parent 22a34b5918
commit a974ee305d

View File

@ -25,21 +25,21 @@ type
var var
//0 = primary, 1 = secondary //0 = primary, 1 = secondary
dataPort : array[0..1] of uint16; dataPort : array[0..3] of uint16;
errorPort : array[0..1] of uint8; errorPort : array[0..3] of uint8;
sectorCountPort : array[0..1] of uint8; sectorCountPort : array[0..3] of uint8;
lbaLowPort : array[0..1] of uint8; lbaLowPort : array[0..3] of uint8;
lbaMidPort : array[0..1] of uint8; lbaMidPort : array[0..3] of uint8;
lbaHiPort : array[0..1] of uint8; lbaHiPort : array[0..3] of uint8;
devicePort : array[0..1] of uint8; devicePort : array[0..3] of uint8;
commandPort : array[0..1] of uint8; commandPort : array[0..3] of uint8;
controlPort : array[0..1] of uint8; controlPort : array[0..3] of uint8;
bytes_per_sector : uint16 = 512; bytes_per_sector : uint16 = 512;
controller : TPCI_device; controller : TPCI_device;
procedure init(device : TPCI_device); procedure init();
procedure identify(drive : uint8; bus : uint8); procedure identify(drive : uint8; bus : uint8);
procedure read28(sector : uint32); procedure read28(sector : uint32);
procedure write28(sector : uint32; data : intptr; count : uint32); procedure write28(sector : uint32; data : intptr; count : uint32);
@ -47,12 +47,13 @@ procedure flush();
implementation implementation
procedure init(device : TPCI_device); procedure init();
begin begin
controller := device; //controller := device;
controller.address0 := $1f0; controller.address0 := $1f0;
// 0x1f0, 0x170 controller.address1 := $170;
// 0x1f0, 0x170, 0x3F6, 0x376
console.writehexln(controller.address0); console.writehexln(controller.address0);
dataPort[0] := controller.address0; dataPort[0] := controller.address0;
errorPort[0] := controller.address0 + 1; errorPort[0] := controller.address0 + 1;
@ -62,7 +63,9 @@ begin
lbaHiPort[0] := controller.address0 + 5; lbaHiPort[0] := controller.address0 + 5;
devicePort[0] := controller.address0 + 6; devicePort[0] := controller.address0 + 6;
commandPort[0] := controller.address0 + 7; 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($A0, $A0);
identify($B0, $A0); identify($B0, $A0);
@ -76,44 +79,56 @@ var
data : array[0..265] of uint16; data : array[0..265] of uint16;
begin begin
outb(controlPort[0], 2);
busNo := 0; busNo := 0;
if bus = $A0 then busNo := 0; if bus = $A0 then busNo := 0;
outb(devicePort[busNo], drive); outb(devicePort[busNo], drive);
outb(controlPort[busNo], 0); psleep(1);
outb(devicePort[busNo], bus);
status := inb(commandPort[busNo]);
if status <> $FF then begin
outb(devicePort[busNo], drive);
outb(sectorCountPort[busNo], 0); outb(sectorCountPort[busNo], 0);
psleep(1);
outb(lbaLowPort[busNo], 0); outb(lbaLowPort[busNo], 0);
psleep(1);
outb(lbaMidPort[busNo], 0); outb(lbaMidPort[busNo], 0);
psleep(1);
outb(lbaHiPort[busNo], 0); outb(lbaHiPort[busNo], 0);
psleep(1);
outb(commandPort[busNo], $EC); outb(commandPort[busNo], $EC);
psleep(1);
status := inb(commandPort[busNo]); status := inb(commandPort[busNo]);
if status = 0 then exit; if status = $0 then begin
console.writestring('No drive found');
while((status and $08 = 08) and (status and $01 <> 1)) do begin exit;
status := inb(commandPort[busNo])
end; end;
while true do begin
status := inb(commandPort[busNo]); status := inb(commandPort[busNo]);
if status and $01 = 1 then begin if status = 1 then begin
console.writestringln('ATA DEVICE ERROR'); console.writestringln('Drive error');
end else begin exit;
for i:=0 to 265 do begin end;
data[i] := inw(dataPort[busNo]);
console.writestringln(pchar(@data[i])); if (status and $80) = 0 then break;
//console.writeint(data[i]);
psleep(10); 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;
end; end;
end else begin console.writestring('Drive found!');
console.writestringln('no device');
end;
end; end;