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

This commit is contained in:
aaron 2018-04-11 22:14:08 +00:00
parent 5b8cdaf43e
commit f1beeca4c4
4 changed files with 34 additions and 14 deletions

View File

@ -20,7 +20,8 @@ uses
drivermanagement, drivermanagement,
vmemorymanager, vmemorymanager,
lmemorymanager, lmemorymanager,
storagemanagement; storagemanagement,
tracer;
type type
TIdentResponse = array[0..255] of uint16; TIdentResponse = array[0..255] of uint16;
@ -191,6 +192,7 @@ procedure init();
var var
devID : TDeviceIdentifier; devID : TDeviceIdentifier;
begin begin
push_trace('ide.init');
console.writestringln('IDE ATA Driver: Init()'); console.writestringln('IDE ATA Driver: Init()');
devID.bus:= biPCI; devID.bus:= biPCI;
devID.id0:= idANY; devID.id0:= idANY;
@ -202,6 +204,7 @@ begin
drivermanagement.register_driver('IDE ATA Driver', @devID, @load); drivermanagement.register_driver('IDE ATA Driver', @devID, @load);
terminal.registerCommand('IDE', @test_command, 'TEST IDE DRIVER'); terminal.registerCommand('IDE', @test_command, 'TEST IDE DRIVER');
buffer := Puint32(kalloc(1024*2)); buffer := Puint32(kalloc(1024*2));
pop_trace();
end; end;
function load(ptr : void) : boolean; function load(ptr : void) : boolean;
@ -209,6 +212,7 @@ var
storageDevice : TStorage_Device; storageDevice : TStorage_Device;
storageDevice1 : TStorage_Device; storageDevice1 : TStorage_Device;
begin begin
push_trace('ide.load');
//controller := PPCI_Device(ptr); //controller := PPCI_Device(ptr);
//check if bus is floating and identify device //check if bus is floating and identify device
@ -243,8 +247,8 @@ begin
storageDevice1.writeCallback:= @write; storageDevice1.writeCallback:= @write;
storagemanagement.register_device(@storageDevice1); storagemanagement.register_device(@storageDevice1);
end; end;
end end;
pop_trace();
end; end;
procedure noInt(drive : uint8); procedure noInt(drive : uint8);
@ -268,6 +272,7 @@ var
identResponse : TIdentResponse; identResponse : TIdentResponse;
t : uint32 = 0; t : uint32 = 0;
begin begin
push_trace('ide.identify_device');
if bus = 0 then begin if bus = 0 then begin
if drive = $A0 then noInt(0); if drive = $A0 then noInt(0);
@ -301,6 +306,7 @@ begin
identify_device:= identResponse; identify_device:= identResponse;
exit; exit;
end; end;
pop_trace();
end; end;
procedure writePIO28(drive : uint8; LBA : uint32; sectorCount : uint8; buffer : Puint32); procedure writePIO28(drive : uint8; LBA : uint32; sectorCount : uint8; buffer : Puint32);
@ -309,7 +315,7 @@ var
ii : uint8; ii : uint8;
iii : uint32; iii : uint32;
begin begin
push_trace('ide.writePIO28');
while true do if (inw($1f7) and (1 shl 7)) = 0 then break; //Wait until drive not busy while true do if (inw($1f7) and (1 shl 7)) = 0 then break; //Wait until drive not busy
@ -355,6 +361,7 @@ begin
end; end;
end; end;
pop_trace();
end; end;
procedure readPIO28(drive : uint8; LBA : uint32; sectorCount : uint8; buffer : puint32); procedure readPIO28(drive : uint8; LBA : uint32; sectorCount : uint8; buffer : puint32);
@ -363,7 +370,7 @@ var
ii : uint8; ii : uint8;
iii : uint32; iii : uint32;
begin begin
push_trace('ide.readPIO28');
while true do if (inw($1f7) and (1 shl 7)) = 0 then break; //Wait until drive not busy while true do if (inw($1f7) and (1 shl 7)) = 0 then break; //Wait until drive not busy
noInt(drive); noInt(drive);
@ -405,6 +412,7 @@ begin
end; end;
end; end;
end; end;
pop_trace();
end; end;
procedure readPIOPI(drive : uint8; LBA : uint32; buffer : Puint32); procedure readPIOPI(drive : uint8; LBA : uint32; buffer : Puint32);
@ -444,7 +452,7 @@ end;
procedure read(device : PStorage_device; LBA : uint32; sectorCount : uint32; buffer : Puint32); procedure read(device : PStorage_device; LBA : uint32; sectorCount : uint32; buffer : Puint32);
begin begin
readPIO28(device^.controllerId0, LBA, sectorCount, buffer); readPIO28(device^.controllerId0, LBA, sectorCount, buffer); //need to figure out max read/write amount per operation
end; end;
procedure write(device : PStorage_device; LBA : uint32; sectorCount : uint32; buffer : Puint32); procedure write(device : PStorage_device; LBA : uint32; sectorCount : uint32; buffer : Puint32);

View File

@ -13,7 +13,7 @@ unit FAT32;
interface interface
uses uses
console, storagemanagement; console, storagemanagement, util, lmemorymanager;
type type
@ -49,7 +49,6 @@ type
end; end;
byteArray8 = array[0..7] of char; byteArray8 = array[0..7] of char;
byteArray12 = array[0..11] of uint8;
TDirectory = bitpacked record TDirectory = bitpacked record
fileName : uint64; fileName : uint64;
@ -66,6 +65,7 @@ type
clusterLow : uint16; clusterLow : uint16;
byteSize : uint32; byteSize : uint32;
end; end;
PDirectory = ^TDirectory;
TFilesystemInfo = record TFilesystemInfo = record
FATBaseAddress : uint32; FATBaseAddress : uint32;
@ -143,7 +143,7 @@ begin
bootrecord.sectorsize:= disk^.sectorSize; bootrecord.sectorsize:= disk^.sectorSize;
bootrecord.spc:= PFatVolumeInfo(config)^.sectorsPerCluster; bootrecord.spc:= PFatVolumeInfo(config)^.sectorsPerCluster;
bootrecord.rsvSectors:= 32; //Is this acceptable? bootrecord.rsvSectors:= 32; //Is this acceptable?
bootrecord.numFats:= 2; bootrecord.numFats:= 1;
bootrecord.numDirEnt:= 0; bootrecord.numDirEnt:= 0;
bootRecord.numSectors:= 0; bootRecord.numSectors:= 0;
bootrecord.mediaDescp:= $F8; bootrecord.mediaDescp:= $F8;
@ -154,7 +154,7 @@ begin
bootRecord.manySectors:= sectors; bootRecord.manySectors:= sectors;
BootRecord.FATSize:= ((sectors DIV PFatVolumeInfo(config)^.sectorsPerCluster) * 16 DIV disk^.sectorSize); BootRecord.FATSize:= ((sectors DIV PFatVolumeInfo(config)^.sectorsPerCluster) * 16 DIV disk^.sectorSize);
BootRecord.flags:= 1 shl 7; BootRecord.flags:= 0; //1 shl 7 for mirroring
BootRecord.FATVersion:= 0; BootRecord.FATVersion:= 0;
BootRecord.rootCluster:= 2; // can be changed if needed. BootRecord.rootCluster:= 2; // can be changed if needed.
BootRecord.FSInfoCluster:=1; //TODO need FSINFO BootRecord.FSInfoCluster:=1; //TODO need FSINFO
@ -166,12 +166,21 @@ begin
BootRecord.bsignature:= $29; BootRecord.bsignature:= $29;
BootRecord.identString:= fatArray; BootRecord.identString:= fatArray;
puint32(buffer + (127))^:= $55AA; //end marker
buffer:= @bootrecord; buffer:= @bootrecord;
disk^.writeCallback(disk, 1, sizeof(TBootRecord), buffer); disk^.writeCallback(disk, start + 1, 1, buffer);
//TODO FSINFO struct
//write fat
buffer := puint32(kalloc((sectors DIV bootrecord.spc) * 4));
memset(uint32(buffer), 0, sectors DIV bootrecord.spc);
puint32(buffer + 1)^:= $FFF8; //root directory table cluster, currently root is only 1 cluster long
disk^.writeCallback(disk, start + 2, sectors DIV bootrecord.spc, buffer);
//disk^.writeCallback(disk, start + 2 + (sectors Div bootrecord.sectorsPerCluster DIV 512), sectors DIV bootrecord.sectorsPerCluster, buffer);
//448bytes bootstrap
//2bytes end mark 55AA
end; end;

View File

@ -78,6 +78,8 @@ procedure register_filesystem(filesystem : TFilesystem);
//procedure register_volume(volume : TStorage_Volume); //procedure register_volume(volume : TStorage_Volume);
//TODO write partition table
implementation implementation
procedure disk_command(params : PParamList); procedure disk_command(params : PParamList);

View File

@ -39,7 +39,8 @@ uses
IDE, IDE,
storagemanagement, storagemanagement,
lists, lists,
net; net,
fat32;
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall; procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;