Compare commits

...

3 Commits

Author SHA1 Message Date
d86bf47211 Store a List of discovered PCI devices 2023-10-24 08:49:11 -04:00
757f8f8c65 Make A1.allocate() zero returned memory 2023-10-24 08:48:26 -04:00
8303451929 Add List class 2023-10-24 08:48:00 -04:00
3 changed files with 74 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import hulk.hurl;
import hulk.hippo;
import hulk.util;
import hulk.pagetable;
import hulk.memory;
/**
* The A1 memory allocator is a one-shot memory allocator for kernel memory
@ -48,6 +49,8 @@ struct A1
current_limit += PAGE_SIZE;
}
memset64(cast(void *)address, 0, size / 8);
return cast(void *)address;
}

64
src/hulk/list.d Normal file
View File

@ -0,0 +1,64 @@
/**
* Linked list functionality.
*/
module hulk.list;
import hulk.hurl.a1;
/**
* Linked list structure.
*/
struct List(T)
{
/**
* Linked list item.
*/
T * item;
/**
* Next list entry.
*/
List!T * next;
/**
* Add an item to this linked list.
*/
public void add(T * item)
{
List!T * last_entry = last_entry();
List!T * new_entry = A1.allocate!(List!T)();
last_entry.item = item;
last_entry.next = new_entry;
}
/**
* Allow foreach iteration across a List.
*/
public int opApply(scope int delegate(ref T) dg)
{
List!T * entry = &this;
while (entry.next != null)
{
int result = dg(*entry.item);
if (result != 0)
{
return result;
}
entry = entry.next;
}
return 0;
}
/**
* Get the last linked list entry.
*/
private @property List!T * last_entry()
{
List!T * result = &this;
while (result.next != null)
{
result = result.next;
}
return result;
}
}

View File

@ -10,6 +10,7 @@ import hulk.hurl.a1;
import hulk.range;
import hulk.usb.xhci;
import hulk.acpi;
import hulk.list;
struct Pci
{
@ -196,6 +197,11 @@ struct Pci
}
}
/**
* Store a list of discovered PCI devices.
*/
public static __gshared List!Device devices;
private static uint read_config_register(Address address, uint register_id)
{
uint cfg_addr = 0x8000_0000u |
@ -361,6 +367,7 @@ struct Pci
if (config.vendor_id != 0xFFFFu)
{
Device * device = A1.allocate!Device();
devices.add(device);
device.initialize(Address(bus_nr, device_nr, function_nr), config);
if (device.multifunction)
{