This commit is contained in:
Aaron committed 2026-02-26 18:25:12 +00:00
1 parent 232f6b5485
commit 8b80b6864b
6 files changed
+1295 -7

No files matched your search

+585
View File
File diff suppressed because it is too large. Load diff
+79 -5
View File
@@ -108,7 +108,13 @@ begin
port^.sata_ctrl := port^.sata_ctrl or $FFFF0000; port^.sata_ctrl := port^.sata_ctrl or $FFFF0000;
timeout := 0;
while (port^.sata_status and $F) <> 3 do begin while (port^.sata_status and $F) <> 3 do begin
timeout := timeout + 1; /////////////////////////////////
if timeout > 1000 then begin
console.writestringln('AHCI: Port reset timeout (waiting for device ready).');
break;
end;
//wait for the port to be ready //wait for the port to be ready
end; end;
@@ -187,6 +193,9 @@ begin
device := PAHCI_Device(@controller^.devices[i]); device := PAHCI_Device(@controller^.devices[i]);
device^.port := port; device^.port := port;
console.writestring('AHCI: TFD: ');
console.writehexln(device^.port^.tfd);
//check if the port is active TODO //check if the port is active TODO
console.writestring('AHCI: signature: '); console.writestring('AHCI: signature: ');
@@ -214,8 +223,11 @@ begin
//NEEED TO STOP the port before doing anything //NEEED TO STOP the port before doing anything
stop_port(port); stop_port(port);
console.writestringln('AHCI: Port stopped'); reset_port(port);
console.writestringln('AHCI: Port stopped');
console.writestring('AHCI: TFD: ');
console.writehexln(device^.port^.tfd);
//allocate memory for the command list and ensure it is aligned to 1024 bytes //allocate memory for the command list and ensure it is aligned to 1024 bytes
cmd_list_base := kalloc(sizeof(THBA_CMD_HEADER) * 64); cmd_list_base := kalloc(sizeof(THBA_CMD_HEADER) * 64);
cmd_list_base := puint32((uint32(cmd_list_base) + 1023) and $FFFFFC00); cmd_list_base := puint32((uint32(cmd_list_base) + 1023) and $FFFFFC00);
@@ -260,10 +272,14 @@ begin
command_header^.cmd_table_base := vtop(uint32(cmd_table_base)) + (ii * sizeof(THBA_CMD_TABLE)); command_header^.cmd_table_base := vtop(uint32(cmd_table_base)) + (ii * sizeof(THBA_CMD_TABLE));
command_header^.cmd_table_baseu := 0; command_header^.cmd_table_baseu := 0;
end; end;
console.writestring('AHCI: TFD aft mem: ');
console.writehexln(device^.port^.tfd);
//reset the port //reset the port
reset_port(port); reset_port(port);
console.writestring('AHCI: TFD aft res: ');
console.writehexln(device^.port^.tfd);
//print sata status //print sata status
console.writestring('AHCI: sata status: '); console.writestring('AHCI: sata status: ');
console.writehexln(port^.sata_status); console.writehexln(port^.sata_status);
@@ -299,6 +315,21 @@ begin
console.writeintln(portIndex); console.writeintln(portIndex);
device := PAHCI_Device(@controller^.devices[portIndex]); device := PAHCI_Device(@controller^.devices[portIndex]);
console.writestring('AHCI: Error sata register: ');
console.writehexln(device^.port^.sata_error);
//print out busy flag
console.writestring('AHCI: Status: ');
console.writehexln(device^.port^.sata_status);
//print sata active flag
console.writestring('AHCI: Active flag: ');
console.writehexln(device^.port^.sata_active);
//print tfd
console.writestring('AHCI: TFD: ');
console.writehexln(device^.port^.tfd);
// (Optional) Print the device type if you store it: // (Optional) Print the device type if you store it:
console.writestring('AHCI: Device type: '); console.writestring('AHCI: Device type: ');
// For example: if device^.device_type = SATA then ... // For example: if device^.device_type = SATA then ...
@@ -349,7 +380,7 @@ begin
end else begin end else begin
fis^.command := ATA_CMD_IDENTIFY; fis^.command := ATA_CMD_IDENTIFY;
end; end;
fis^.device := $A0; // LBA mode 40? fis^.device := $40;
//waut for the port to be ready, bit 7 in the TFD register and bit 3 tfd //waut for the port to be ready, bit 7 in the TFD register and bit 3 tfd
while (device^.port^.tfd and $88) <> 0 do begin while (device^.port^.tfd and $88) <> 0 do begin
@@ -393,12 +424,24 @@ begin
console.writestringln('AHCI: Command complete'); console.writestringln('AHCI: Command complete');
// Check for an error flag in the command register (bit 1) // Check for an error flag in the command register (bit 1)
if (cmd and $2) <> 0 then begin if (cmd and $2 ) + 1 <> 0 then begin
console.writestringln('AHCI: Error sending identify command'); console.writestringln('AHCI: Error sending identify command');
// Check the error register for more information // Check the error register for more information
console.writestring('AHCI: Error register: '); console.writestring('AHCI: Error sata register: ');
console.writehexln(device^.port^.sata_error); console.writehexln(device^.port^.sata_error);
//print out busy flag
console.writestring('AHCI: Status: ');
console.writehexln(device^.port^.sata_status);
//print sata active flag
console.writestring('AHCI: Active flag: ');
console.writehexln(device^.port^.sata_active);
//print tfd
console.writestring('AHCI: TFD: ');
console.writehexln(device^.port^.tfd);
end; end;
// Dump the 512-byte IDENTIFY data for debugging (display 64 DWORDs) // Dump the 512-byte IDENTIFY data for debugging (display 64 DWORDs)
@@ -445,6 +488,31 @@ begin
end; end;
// procedure controller_reset(controller : PAHCI_Controller);
// begin
// //check sam TODO
// if (controller^.mio^.capabilites2 and $1) = 0 then begin
// console.writestringln('AHCI: Controller does not support reset');
// exit;
// end;
// //check ghc.ae is set to 1
// if (controller^.mio^.global_ctrl and $1) = 0 then begin
// console.writestringln('AHCI: Controller is not enabled');
// controller^.mio^.global_ctrl := controller^.mio^.global_ctrl or $1;
// end;
// while (controller^.mio^.global_ctrl and $1) <> 0 do begin
// //wait for the controller to be ready
// end;
// //set the reset bit
// controller^.mio^.global_ctrl := controller^.mio^.global_ctrl or $2;
// end;
function load(ptr : void) : boolean; function load(ptr : void) : boolean;
var var
device : PPCI_Device; device : PPCI_Device;
@@ -519,6 +587,12 @@ begin
end else begin end else begin
console.writestringln('AHCI: BIOS not holding controller or handoff already complete.'); console.writestringln('AHCI: BIOS not holding controller or handoff already complete.');
end; end;
//print ghc
console.writestring('AHCI: GHC: ');
console.writebin32ln(base^.global_ctrl);
base^.global_ctrl := base^.global_ctrl or AHCI_CONTROLLER_MODE;
base^.global_ctrl := base^.global_ctrl or 1; base^.global_ctrl := base^.global_ctrl or 1;
File diff suppressed because it is too large. Load diff
+2 -1
View File
@@ -109,7 +109,7 @@ type
base : uint16; base : uint16;
ctrl : uint16; ctrl : uint16;
bmide : uint16; bmide : uint16;
noInter : uint8 noInter : uint8;
end; end;
TIDE_Status = bitpacked record TIDE_Status = bitpacked record
@@ -122,6 +122,7 @@ type
IDDEX : Boolean; IDDEX : Boolean;
ERROR : Boolean; ERROR : Boolean;
end; end;
PIDE_Status = ^TIDE_Status; PIDE_Status = ^TIDE_Status;
TIDE_Device = record TIDE_Device = record
+32
View File
@@ -46,6 +46,9 @@ var
function discover_volumes(device : PStorage_device) : PDList; function discover_volumes(device : PStorage_device) : PDList;
function get_volume_list() : PDList; function get_volume_list() : PDList;
//utility functions
function controller_type_2_string(controllerType : TControllerType) : pchar;
implementation implementation
@@ -105,4 +108,33 @@ begin
end; end;
end; end;
////////////////////////////////////////////////////////////////////////////////
/// UTILITY FUNCTIONS ///
////////////////////////////////////////////////////////////////////////////////
{!!
@function(controller_type_2_string)
@desc(Converts a controller type to a string representation.)
@param(controllerType : TControllerType)
@return(pchar)
!!}
function controller_type_2_string(controllerType : TControllerType) : pchar;
begin
push_trace('VolumeManager.controller_type_2_string');
case controllerType of
ControllerATA: controller_type_2_string := 'ATA';
ControllerATAPI: controller_type_2_string := 'ATAPI';
ControllerUSB: controller_type_2_string := 'USB';
ControllerAHCI: controller_type_2_string := 'AHCI';
ControllerAHCI_ATAPI: controller_type_2_string := 'AHCI_ATAPI';
ControllerNVMe: controller_type_2_string := 'NVMe';
ControllerNET: controller_type_2_string := 'NET';
ControllerRAM: controller_type_2_string := 'RAM';
ControllerSCSI: controller_type_2_string := 'SCSI';
end;
pop_trace();
end;
end. end.
+3 -1
View File
@@ -58,7 +58,8 @@ uses
rand, rand,
terminal, terminal,
hashmap, vfs, hashmap, vfs,
AHCI; AHCI,
AHCITest;
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall; procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
@@ -231,6 +232,7 @@ begin
E1000.init(); E1000.init();
// IDE.init(); // IDE.init();
AHCI.init(); AHCI.init();
AHCITest.init();
console.outputln('KERNEL', 'DEVICE DRIVERS: INIT END.'); console.outputln('KERNEL', 'DEVICE DRIVERS: INIT END.');
{ Bus Drivers } { Bus Drivers }