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
//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,44 +79,56 @@ 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);
status := inb(commandPort[busNo]);
if status <> $FF then begin
outb(devicePort[busNo], drive);
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 = 0 then exit;
while((status and $08 = 08) and (status and $01 <> 1)) do begin
status := inb(commandPort[busNo])
if status = $0 then begin
console.writestring('No drive found');
exit;
end;
while true do begin
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);
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;
end else begin
console.writestringln('no device');
end;
console.writestring('Drive found!');
end;