Compare commits

..

3 Commits

Author SHA1 Message Date
b2ecbe58da Added licensing 2025-03-15 10:43:42 +00:00
2014ce4f9c AHCI Progress 2025-03-15 10:42:18 +00:00
6cd9ae4f46 Dynamic lists fixes and additions
# Conflicts:
#	src/include/lists.pas
2025-03-14 19:52:41 +00:00
5 changed files with 445 additions and 7 deletions

View File

@ -1,3 +1,23 @@
// Copyright 2021 Aaron Hance
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
{
Drivers->Storage->AHCI->AHCI - AHCI Driver.
@author(Aaron Hance <ah@aaronhance.me>)
}
unit AHCI;
interface
@ -10,13 +30,11 @@ uses
lmemorymanager,
console,
vmemorymanager,
AHCITypes;
AHCITypes,
lists;
var
ahciControllers : array[0..255] of pointer;
ahciControllerCount : uint32;
hba : array[0..255] of THBA_Memory;
ahciControllers : PDLList;
procedure init();
procedure load();
@ -36,10 +54,48 @@ begin
devID.id4:= idANY;
devID.ex:= nil;
drivermanagement.register_driver('ATA/PI AHCI Driver', @devID, @load);
//TODO check IDE devices in ide for sata devices
end;
procedure check_ports(controller : PAHCI_Controller);
var
i : uint32;
port : PHBA_Port;
begin
end;
procedure load(ptr : void);
var
device : PPCI_Device;
controller : PAHCI_Controller;
i : uint32;
base : PHBA_Memory;
begin
console.writestringln('AHCI: initilizing a new controller');
if ahciControllers = nil then begin
console.writestringln('AHCI: Initializing controller list');
ahciControllers := DL_New(SizeOf(TAHCI_Controller));
end;
device := PPCI_Device(ptr);
controller := DL_Add(ahciControllers);
controller^.device := device;
base: PHBA_Memory(kpalloc(device^.address5)); // get the base address of the controller
controller^.mio := base;
//enable AHCI mode, TODO check if is not already in AHCI mode and enable it, also perhaps remove if loaded as IDE
base^.ghc := base^.ghc or AHCI_CONTROLLER_MODE;
//clear any pending interrupts
base^.int_status := $FFFFFFFF;
// console.writestringln('AHCI: initilizing a new controller');
// ahciControllers[ahciControllerCount] := ptr;
// hba[ahciControllerCount] := PPCI_Device(ptr)^.address5;

View File

@ -1,4 +1,22 @@
// Copyright 2021 Aaron Hance
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
{
Drivers->Storage->AHCI->AHCITypes - AHCI Driver Types.
@author(Aaron Hance <ah@aaronhance.me>)
}
unit AHCITypes;
interface
uses
@ -11,6 +29,13 @@ uses
vmemorymanager;
const
AHCI_CONTROLLER_MODE = $80000000;
//device type signatures
SATA_SIG_ATA = $00000101;
SATA_SIG_ATAPI = $EB140101;
SATA_SIG_SEMB = $C33C0101;
SATA_SIG_PM = $96690101;
@ -72,6 +97,8 @@ type
ports: array[0..31] of THBA_Port;
end;
PHBA_Memory = ^THBA_Memory;
{
AHCI Host Bus Adapter (HBA) FIS (Frame Information Structure) Interface
This structure is used to access the AHCI HBA's FIS (Frame Information Structure)
@ -163,10 +190,72 @@ type
PHBA = ^THBA;
//////////////////////////////////////////
//////////// Asuro AHCI types ////////////
//////////////////////////////////////////
{
Device type enum
}
TDeviceType = (
SATA,
ATAPI,
SEMB,
PM
);
{
controller reference
}
TAHCI_Controller = bitpacked record
pci_device : PPCI_Device;
mio: PHBA_Memory;
devices : array[0..31] of uint8; //TODO type for devices
end;
PAHCI_Controller = ^TAHCI_Controller;
function get_device_type(sig : uint32) : TDeviceType;
function get_device_type_string(deive_type : TDeviceType) : string;
implementation
function get_device_type(sig : uint32) : TDeviceType;
begin
case sig of
SATA_SIG_ATA: begin
get_device_type := SATA;
end;
SATA_SIG_ATAPI: begin
get_device_type := ATAPI;
end;
SATA_SIG_SEMB: begin
get_device_type := SEMB;
end;
SATA_SIG_PM: begin
get_device_type := PM;
end;
end;
end;
function get_device_type_string(deive_type : TDeviceType) : string;
begin
case deive_type of
SATA: begin
get_device_type_string := 'SATA';
end;
ATAPI: begin
get_device_type_string := 'ATAPI';
end;
SEMB: begin
get_device_type_string := 'SEMB';
end;
PM: begin
get_device_type_string := 'PM';
end;
end;
end;
end.

View File

@ -1,3 +1,22 @@
// Copyright 2021 Aaron Hance
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
{
Drivers->Storage->ide - IDE Driver.
@author(Aaron Hance <ah@aaronhance.me>)
}
unit ide;
interface

View File

@ -1,3 +1,22 @@
// Copyright 2021 Aaron Hance
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
{
Drivers->Storage->ATA - ATA Driver.
@author(Aaron Hance <ah@aaronhance.me>)
}
unit ata;
interface

View File

@ -1,4 +1,4 @@
// Copyright 2021 Kieron Morris
// Copyright 2021 Kieron Morris & Aaron Hance
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -16,6 +16,7 @@
Include->Lists - Linked List Data Structures & Helpers.
@author(Kieron Morris <kjm@kieronmorris.me>)
@author(Aaron Hance <ah@aaronhance.me>)
}
unit lists;
@ -44,6 +45,19 @@ type
ElementSize : uint32;
end;
{ Dynamic List }
PDList = ^TDList;
TDList = record
Count : uint32;
Data : void;
ElementSize : uint32;
DataSize : uint32;
end;
{ Dynamic List Iterator }
{ String Linked List }
procedure STRLL_Add(LinkedList : PLinkedListBase; str : pchar);
@ -66,6 +80,24 @@ function LL_Get(LinkedList : PLinkedListBase; idx : uint32) : Void;
procedure LL_Free(LinkedList : PLinkedListBase);
function LL_FromString(str : pchar; delimter : char) : PLinkedListBase;
{ Dynamic List }
function DL_New(ElementSize : uint32) : PDList;
function DL_Add(DList : PDList) : Void;
function DL_Delete(DList : PDList; idx : uint32) : boolean;
function DL_Size(DList : PDList) : uint32;
function DL_Set(DList : PDList; idx : uint32; elm : puint32) : boolean;
function DL_Get(DList : PDList; idx : uint32) : Void;
procedure DL_Free(DList : PDList);
function DL_IndexOf(DList : PDList; elm : puint32) : uint32;
function DL_Contains(DList : PDList; elm : puint32) : boolean;
function DL_Concat(DList1 : PDList; DList2 : PDList) : PDList;
{ Dynamic List Iterator }
implementation
uses
@ -351,4 +383,227 @@ begin
end;
end;
{ Dynamic List }
function DL_New(ElementSize : uint32) : PDList;
var
DL : PDList;
begin
DL := PDList(kalloc(sizeof(DL)));
DL^.ElementSize:= ElementSize;
DL^.count := 0;
if ElementSize > 128 then begin
DL^.data := kalloc(ElementSize * 4);
Dl^.DataSize:= ElementSize * 4;
end else if ElementSize > 64 then begin
DL^.data := kalloc(ElementSize * 8);
Dl^.DataSize:= ElementSize * 8;
end else if ElementSize > 32 then begin
DL^.data := kalloc(ElementSize * 16);
Dl^.DataSize:= ElementSize * 16;
end else if ElementSize > 16 then begin
DL^.data := kalloc(ElementSize * 32);
Dl^.DataSize:= ElementSize * 32;
end else begin
DL^.data := kalloc(ElementSize * 64);
Dl^.DataSize:= ElementSize * 64;
end;
DL_New := DL;
end;
function DL_Add(DList : PDList) : Void;
var
elm : puint32;
tempList : puint32;
begin
//check if we need to resize
if (DList^.count + 1) * DList^.ElementSize > DList^.DataSize then begin
push_trace('lists.DL_Add: Resizing');
tempList := DList^.Data;
DList^.Data := kalloc(DList^.DataSize * 2);
memset(uint32(DList^.Data), 0, DList^.DataSize * 2);
memcpy(uint32(tempList), uint32(DList^.Data), DList^.DataSize);
DList^.DataSize:= DList^.DataSize * 2;
kfree(void(tempList));
end;
push_trace('lists.DL_Add');
elm := puint32(@puint8(DList^.Data)[(DList^.count * DList^.ElementSize)]);
elm^ := 0;
push_trace('lists.DL_Add: Adding');
DList^.count := DList^.count + 1;
DL_Add := elm;
end;
function DL_Delete(DList : PDList; idx : uint32) : boolean;
var
elm : puint32;
tempList : puint32;
begin
if idx >= DList^.count then begin
DL_Delete := false;
exit;
end;
elm := puint32( puint8(DList^.Data) + (idx * DList^.ElementSize));
memcpy(uint32( puint8(elm) + DList^.ElementSize), uInt32(elm), (DList^.count - idx) * DList^.ElementSize);
DList^.count := DList^.count - 1;
if (DList^.count * DList^.ElementSize) < DList^.DataSize DIV 2 then begin
tempList := DList^.Data;
DList^.DataSize:= DList^.DataSize DIV 2;
DList^.Data := kalloc(DList^.DataSize);
memcpy(uint32(tempList), uint32(DList^.Data), DList^.DataSize);
kfree(void(tempList));
end;
DL_Delete := true;
end;
function DL_Get(DList : PDList; idx : uint32) : Void;
var
elm : puint32;
begin
if idx >= DList^.count then begin
DL_Get := nil;
exit;
end;
elm := puint32(DList^.Data + (idx * DList^.ElementSize));
DL_Get := elm;
end;
function DL_Set(DList : PDList; idx : uint32; elm : puint32) : boolean;
var
tempList : PuInt32;
size : uint32;
begin
if idx >= DList^.count then begin
DL_Set := false;
exit;
end;
//check if we need to resize
if (idx + 1) * Dlist^.ElementSize > DList^.DataSize then begin
console.writestring('resising thisthinghere');
size := idx * DList^.ElementSize * 2;
tempList := DList^.Data;
DList^.Data := kalloc(size);
memset(uint32(DList^.Data), 0, size);
memcpy(uint32(tempList), uint32(DList^.Data), DList^.DataSize);
DList^.DataSize := size;
kfree(void(tempList));
end;
console.writeString('offset: ');
console.writeintln(idx * DList^.ElementSize);
memcpy(uint32(elm), uint32( PuInt8(DList^.Data) + (idx * DList^.ElementSize)), DList^.ElementSize);
//check if count is smaller than idx and if so, increase count
if DList^.count < idx then DList^.count := idx;
DL_Set := true;
end;
function DL_Size(DList : PDList) : uint32;
begin
DL_Size := DList^.count;
end;
procedure DL_Free(DList : PDList);
begin
kfree(void(DList^.Data));
kfree(void(DList));
end;
function DL_IndexOf(DList : PDList; elm : puint32) : uint32;
var
i : uint32;
temp : puint32;
begin
for i := 0 to DList^.count - 1 do begin
temp := puint32( puint8(DList^.Data) + (i * DList^.ElementSize));
if temp = elm then begin
DL_IndexOf := i;
exit;
end;
end;
DL_IndexOf := -1;
end;
function DL_Contains(DList : PDList; elm : puint32) : boolean;
var
i : uint32;
begin
i := DL_IndexOf(DList, elm);
if i = -1 then begin
DL_Contains := false;
exit;
end;
DL_Contains := true;
end;
function DL_Concat(DList1 : PDList; DList2 : PDList) : PDList;
var
i : uint32;
temp : puint32;
begin
//check element size
if DList1^.ElementSize <> DList2^.ElementSize then begin
DL_Concat := nil;
exit;
end;
//check if we need to resize
while true do begin
if (DList1^.count + DList2^.count) * DList1^.ElementSize > DList1^.DataSize then begin
temp := DList1^.Data;
DList1^.Data := kalloc(DList1^.DataSize * 2);
memset(uint32(DList1^.Data), 0, DList1^.DataSize * 2);
memcpy(uint32(temp), uint32(DList1^.Data), DList1^.DataSize);
DList1^.DataSize:= DList1^.DataSize * 2;
kfree(void(temp));
end else Break;
end;
for i := 0 to DList2^.count - 1 do begin
temp := DL_Add(DList1);
memcpy(uint32(DL_Get(DList2, i)), uint32(temp), DList1^.ElementSize);
end;
DL_Concat := DList1;
end;
end.