Spinlock save cpu flags

This commit is contained in:
2026-03-12 22:48:34 +01:00
parent 19793e9126
commit 4760818118
50 changed files with 704 additions and 461 deletions

View File

@@ -33,14 +33,16 @@ struct device_table {
static struct device_table device_table;
struct device* device_find (const char* key) {
uint64_t fdt;
struct hash_node_link* found_link = NULL;
size_t key_len = strlen_null (key);
uint32_t hash = hash_fnv32 (key, key_len);
spin_lock (&device_table.lock);
spin_lock (&device_table.lock, &fdt);
hash_find (&device_table, key, key_len, hash, lengthof (device_table.device_buckets),
device_buckets, struct device, device_table_link, key, found_link);
spin_unlock (&device_table.lock);
spin_unlock (&device_table.lock, fdt);
if (found_link == NULL)
return NULL;
@@ -51,6 +53,8 @@ struct device* device_find (const char* key) {
struct device* device_create (const char* key, device_op_func_t* ops, size_t ops_len,
device_init_func_t init, device_fini_func_t fini, void* arg,
struct proc* proc, struct reschedule_ctx* rctx) {
uint64_t fdt;
if (ops_len >= fieldlengthof (struct device, ops))
return NULL;
@@ -75,12 +79,12 @@ struct device* device_create (const char* key, device_op_func_t* ops, size_t ops
uint32_t device_hash = hash_fnv32 (device->key, strlen_null (device->key));
spin_lock (&device_table.lock);
spin_lock (&device_table.lock, &fdt);
hash_insert (&device_table, &device->device_table_link, device_hash,
lengthof (device_table.device_buckets), device_buckets);
spin_unlock (&device_table.lock);
spin_unlock (&device_table.lock, fdt);
DEBUG ("Created device %s\n", device->key);
@@ -94,7 +98,8 @@ static void debugconsole_device_init (void) {
device_op_func_t ops[] = {
[DEBUGCONSOLE_PUTSTR] = &debugconsole_putstr,
};
device_create ("DEBUGCONSOLE", ops, lengthof (ops), &debugconsole_init, &debugconsole_fini, NULL, thiscpu->kproc, &rctx);
device_create ("DEBUGCONSOLE", ops, lengthof (ops), &debugconsole_init, &debugconsole_fini, NULL,
thiscpu->kproc, &rctx);
}
static void terminal_device_init (void) {
@@ -105,7 +110,8 @@ static void terminal_device_init (void) {
[TERMINAL_PUTSTR] = &terminal_putstr,
[TERMINAL_DIMENSIONS] = &terminal_dimensions,
};
device_create ("TERMINAL", ops, lengthof (ops), &terminal_init, &terminal_fini, NULL, thiscpu->kproc, &rctx);
device_create ("TERMINAL", ops, lengthof (ops), &terminal_init, &terminal_fini, NULL,
thiscpu->kproc, &rctx);
}
static void ramdisk_device_init (void) {
@@ -149,7 +155,8 @@ static void ramdisk_device_init (void) {
.sector_size = 512,
.buffer = unpack_buffer,
};
device_create ("RD0", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init, thiscpu->kproc, &rctx);
device_create ("RD0", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init, thiscpu->kproc,
&rctx);
LZ4F_freeDecompressionContext (dctx);
}
@@ -170,7 +177,8 @@ static void temp_device_init (void) {
.total_size = 1024 * 1024 * 20,
.sector_size = 512,
};
device_create ("TEMP0", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init, thiscpu->kproc, &rctx);
device_create ("TEMP0", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init, thiscpu->kproc,
&rctx);
}
#if defined(__x86_64__)