More cleanup

This commit is contained in:
Aaron Hance 2025-03-23 10:20:55 +00:00
parent ed0f8d9c08
commit 569b2f0bca
10 changed files with 1222 additions and 507 deletions

View File

@ -23,17 +23,17 @@ unit AHCI;
interface interface
uses uses
util,
PCI,
drivertypes,
drivermanagement,
lmemorymanager,
console,
vmemorymanager,
AHCITypes, AHCITypes,
lists, console,
drivermanagement,
drivertypes,
idetypes, idetypes,
isrmanager; isrmanager,
lists,
lmemorymanager,
PCI,
util,
vmemorymanager;
var var
ahciControllers : PDList; ahciControllers : PDList;
@ -188,9 +188,6 @@ begin
device^.port := port; device^.port := port;
//check if the port is active TODO //check if the port is active TODO
// if ((port^.sata_status shr 8) <> 1) and ((port^.sata_status and $0F) <> 3) then begin
// continue; wrong
// end;
console.writestring('AHCI: signature: '); console.writestring('AHCI: signature: ');
console.writehexln(port^.signature); console.writehexln(port^.signature);
@ -281,8 +278,6 @@ begin
end; end;
controller^.mio^.int_status := $FFFFFFFF; controller^.mio^.int_status := $FFFFFFFF;
// identify_device(controller, DL_Size(controller^.devices) - 1);
end; end;
end; end;
end; end;
@ -315,8 +310,8 @@ begin
console.writeintln(uint32(device^.device_type)); console.writeintln(uint32(device^.device_type));
//clear any pending interrupts //clear any pending interrupts
device^.port^.int_status := $0; device^.port^.int_status := $FFFFFFFF;
device^.port^.int_enable := $FFFFFFFF; device^.port^.int_enable := $0;
// Allocate a 512-byte DMA buffer for the IDENTIFY data // Allocate a 512-byte DMA buffer for the IDENTIFY data
buffer := kalloc(512); buffer := kalloc(512);
@ -325,7 +320,6 @@ begin
// Use command slot 0 for the IDENTIFY command. // Use command slot 0 for the IDENTIFY command.
cmd_header := device^.command_list; // Assuming slot 0 is at the beginning. cmd_header := device^.command_list; // Assuming slot 0 is at the beginning.
cmd_header^.cmd_fis_length := sizeof(THBA_FIS_REG_H2D) div sizeof(uint32); cmd_header^.cmd_fis_length := sizeof(THBA_FIS_REG_H2D) div sizeof(uint32);
// cmd_header^.command := ATA_CMD_IDENTIFY;
cmd_header^.wrt := 0; cmd_header^.wrt := 0;
cmd_header^.prdtl := 1; cmd_header^.prdtl := 1;
cmd_header^.clear_busy := 1; cmd_header^.clear_busy := 1;
@ -340,10 +334,10 @@ begin
cmd_table^.prdt[0].dbc := 511; // 512 bytes (0-based count) cmd_table^.prdt[0].dbc := 511; // 512 bytes (0-based count)
cmd_table^.prdt[0].int := 1; // Interrupt on completion cmd_table^.prdt[0].int := 1; // Interrupt on completion
if isATAPI then begin // if isATAPI then begin
// ATAPI Identify Device command // // ATAPI Identify Device command
buffer[0] := $A1; // ATAPI Identify Device // buffer[0] := $A1; // ATAPI Identify Device
end; // end;
// Construct the Command FIS in the command table's CFIS area // Construct the Command FIS in the command table's CFIS area
fis := PHBA_FIS_REG_H2D(@device^.command_table^.cmd_fis); fis := PHBA_FIS_REG_H2D(@device^.command_table^.cmd_fis);
@ -376,6 +370,7 @@ begin
repeat repeat
cmd := device^.port^.cmd_issue; // Command Issue register cmd := device^.port^.cmd_issue; // Command Issue register
tfd := device^.port^.tfd; // Task File Data often contains error/status info. tfd := device^.port^.tfd; // Task File Data often contains error/status info.
device^.port^.int_status := $FFFFFFFF; // Clear any pending interrupts
timeout := timeout + 10; timeout := timeout + 10;
if timeout > 100000 then begin if timeout > 100000 then begin
console.writestringln('AHCI: IDENTIFY command timeout'); console.writestringln('AHCI: IDENTIFY command timeout');

View File

@ -26,20 +26,18 @@ interface
uses uses
ata, ata,
atapi, atapi,
util,
drivertypes,
console, console,
terminal,
drivermanagement, drivermanagement,
vmemorymanager, drivertypes,
lmemorymanager,
storagemanagement,
strings,
tracer,
drivemanager,
storagetypes,
idetypes, idetypes,
isrmanager; isrmanager,
lmemorymanager,
storagetypes,
strings,
terminal,
tracer,
util,
vmemorymanager;
var var
@ -442,8 +440,8 @@ begin
// end; // end;
end; end;
//register the device //register the device TODO
drivemanager.register_device(storageDevice); // drivemanager.register_device(storageDevice);
end else begin end else begin
console.writestringln('[IDE] (load_device) Device is not present'); console.writestringln('[IDE] (load_device) Device is not present');

View File

@ -22,19 +22,17 @@ unit ata;
interface interface
uses uses
util,
drivertypes,
console, console,
terminal,
drivermanagement, drivermanagement,
vmemorymanager, drivertypes,
idetypes,
lmemorymanager, lmemorymanager,
storagemanagement,
strings,
tracer,
drivemanager,
storagetypes, storagetypes,
idetypes; strings,
terminal,
tracer,
util,
vmemorymanager;
var var

View File

@ -27,19 +27,17 @@ unit atapi;
interface interface
uses uses
util,
drivertypes,
console, console,
terminal,
drivermanagement, drivermanagement,
vmemorymanager, drivertypes,
idetypes,
lmemorymanager, lmemorymanager,
storagemanagement,
strings,
tracer,
drivemanager,
storagetypes, storagetypes,
idetypes; strings,
terminal,
tracer,
util,
vmemorymanager;
var var
@ -54,7 +52,8 @@ var
implementation implementation
uses uses
ide, ata; ata,
ide;
procedure ide_irq(); procedure ide_irq();

View File

@ -26,8 +26,26 @@ uses
type type
TControllerType = (ControllerATA, ControllerATAPI, ControllerUSB, ControllerAHCI, TControllerType = (
ControllerNET, ControllerRAM, rsvctr1, rsvctr2, rsvctr3); ControllerATA,
ControllerATAPI,
ControllerUSB,
ControllerAHCI,
ControllerAHCI_ATAPI,
ControllerNVMe,
ControllerNET,
ControllerRAM,
ControllerSCSI
);
TFileSystemType = (
FileSystemFAT32,
FileSystemExFAT,
FileSystemEXT,
FileSystemEXT2,
FileSystemCDFS,
FileSystemOther
);
PStorage_device = ^TStorage_Device; PStorage_device = ^TStorage_Device;
PDrive_Error = ^TDrive_Error; PDrive_Error = ^TDrive_Error;
@ -44,13 +62,26 @@ type
controller : TControllerType; controller : TControllerType;
controllerId0 : uint32; controllerId0 : uint32;
writable : boolean; writable : boolean;
volumes : PLinkedListBase; volumes : PDList;
writeCallback : PPHIOHook; writeCallback : PPHIOHook;
readCallback : PPHIOHook; readCallback : PPHIOHook;
maxSectorCount : uint32; maxSectorCount : uint32;
sectorSize : uint32; sectorSize : uint32; //in bytes
start : uint32; //start of device in sectors
end; end;
{ Generic storage volume }
TStorage_Volume = record
id : uint32;
device : PStorage_device;
name : pchar;
fileSystem : TFileSystemType;
size : uint32; //size of volume in sectors
start : uint32; //start of volume in sectors
end;
PStorage_Volume = ^TStorage_Volume;
TDrive_Error = record TDrive_Error = record
code : uint16; code : uint16;
description : pchar; description : pchar;

View File

@ -23,17 +23,86 @@ unit volumemanager;
interface interface
uses uses
util,
drivertypes,
console, console,
terminal,
drivermanagement, drivermanagement,
lmemorymanager, drivertypes,
strings,
lists, lists,
tracer, lmemorymanager,
rtc,
MBR, MBR,
rtc,
serial, serial,
storagetypes, storagetypes,
drivemanager; strings,
terminal,
tracer,
util;
var
storageDevices : PDList; //index in this array is global drive id
volumes : PDList;
procedure init();
procedure register_device(device : PStorage_Device);
function discover_volumes(device : PStorage_device) : PDList;
function get_volume_list() : PDList;
implementation
procedure init();
begin
push_trace('VolumeManager.init');
storageDevices := DL_New(sizeof(PStorage_Device));
volumes := DL_New(sizeof(PStorage_Volume));
//TODO register commnads
pop_trace();
end;
procedure register_device(device : PStorage_Device);
var
diskVolumes : PDList;
begin
push_trace('VolumeManager.register_device');
DL_Add(storageDevices);
DL_Set(storageDevices, DL_Size(storageDevices) - 1, puint32(device));
diskVolumes := discover_volumes(device);
if volumes <> nil then begin
volumes := DL_Concat(volumes, diskVolumes);
end;
pop_trace();
end;
function discover_volumes(device : PStorage_device) : PDList;
begin
push_trace('VolumeManager.discover_volumes');
discover_volumes := nil;
//TODO implement
pop_trace();
end;
function get_volume_list() : PDList;
var
newList : PDList;
i : uint32;
begin
push_trace('VolumeManager.get_volume_list');
//get copy of volume list
newList := DL_New(sizeof(PStorage_Volume)); //TODO need to add DL_Copy function
for i := 0 to DL_Size(volumes) - 1 do begin
DL_Add(newList);
DL_Set(newList, i, DL_Get(volumes, i));
end;
end;
end.

File diff suppressed because it is too large Load Diff

View File

@ -40,13 +40,13 @@ uses
testdriver, testdriver,
E1000, E1000,
IDE, IDE,
storagemanagement, // storagemanagement,
drivemanager, // drivemanager,
volumemanager, volumemanager,
lists, lists,
net, net,
fat32, // fat32,
flatfs, // flatfs,
isrmanager, isrmanager,
faults, faults,
fonts, fonts,
@ -210,8 +210,8 @@ begin
drivermanagement.init(); drivermanagement.init();
tracer.push_trace('kmain.STRMGMT'); tracer.push_trace('kmain.STRMGMT');
// storagemanagement.init(); // storagemanagement.init();
drivemanager.init(); // drivemanager.init();
volumemanager.init(); // volumemanager.init();
{ Hook Timer for Ticks } { Hook Timer for Ticks }
tracer.push_trace('kmain.TMR'); tracer.push_trace('kmain.TMR');
@ -219,8 +219,8 @@ begin
TMR_0_ISR.hook(uint32(@bios_data_area.tick_update)); TMR_0_ISR.hook(uint32(@bios_data_area.tick_update));
{ Filsystems } { Filsystems }
fat32.init(); // fat32.init();
flatfs.init(); // flatfs.init();
{ Device Drivers } { Device Drivers }
tracer.push_trace('kmain.DEVDRV'); tracer.push_trace('kmain.DEVDRV');

View File

@ -22,7 +22,15 @@ unit edit;
interface interface
uses uses
console, terminal, keyboard, shell, strings, tracer, storagemanagement, lmemorymanager, util; console,
keyboard,
lmemorymanager,
shell,
storagemanagement,
strings,
terminal,
tracer,
util;
procedure init(); procedure init();

View File

@ -25,7 +25,7 @@ uses
tracer, console, tracer, console,
//progs //progs
base64_prog, md5sum, shell, terminal, base64_prog, md5sum, shell, terminal,
edit, netlog, themer, netlog, themer,
memview, udpcat, dhclient, vbeinfo; memview, udpcat, dhclient, vbeinfo;
{ Initialize all baked-in programs } { Initialize all baked-in programs }
@ -43,8 +43,8 @@ begin
themer.init(); themer.init();
tracer.push_trace('progmanager.netlog.init'); tracer.push_trace('progmanager.netlog.init');
netlog.init(); netlog.init();
tracer.push_trace('progmanager.edit.init'); // tracer.push_trace('progmanager.edit.init');
edit.init(); // edit.init();
tracer.push_trace('progmanager.udpcat.init'); tracer.push_trace('progmanager.udpcat.init');
udpcat.init(); udpcat.init();
tracer.push_trace('progmanager.md5sum.init'); tracer.push_trace('progmanager.md5sum.init');