This commit is contained in:
2026-07-15 22:09:13 +02:00
commit cf33867e68
152 changed files with 9663 additions and 0 deletions
+236
View File
@@ -0,0 +1,236 @@
#include <zinnia/mem.h>
#include <zinnia/system.h>
#include <common/compiler.h>
#include <stdio.h>
#include <stdlib.h>
#include <uacpi/kernel_api.h>
uacpi_status uacpi_kernel_get_rsdp(uacpi_phys_addr* out_rsdp_address) {
*out_rsdp_address = 0x7fb7e014; // TODO: Get the actual rsdp
return UACPI_STATUS_OK;
}
void* uacpi_kernel_map(uacpi_phys_addr addr, uacpi_size len) {
zn_handle_t phys;
zn_vmo_create_phys(addr, len, &phys);
uintptr_t target_addr = 0;
zn_vmo_map(phys, ZN_HANDLE_THIS_VAS, 0, &target_addr, len, ZN_VM_MAP_READ | ZN_VM_MAP_WRITE);
return (void*)target_addr;
}
void uacpi_kernel_unmap(void* addr, uacpi_size len) {
// TODO
}
void uacpi_kernel_log(uacpi_log_level, const uacpi_char* msg, ...) {
char buf[1024];
va_list args;
va_start(args, msg);
int32_t len = snprintf(buf, sizeof(buf), "devd: ");
len += vsnprintf(buf + len, sizeof(buf) - len, msg, args);
va_end(args);
zn_log(buf, len);
}
void uacpi_kernel_vlog(uacpi_log_level, const uacpi_char* msg, uacpi_va_list args) {
char buf[1024];
int32_t len = snprintf(buf, sizeof(buf), "devd: ");
len += vsnprintf(buf + len, sizeof(buf) - len, msg, args);
zn_log(buf, len);
}
uacpi_status uacpi_kernel_pci_device_open(uacpi_pci_address address, uacpi_handle* out_handle) {
return UACPI_STATUS_UNIMPLEMENTED;
}
void uacpi_kernel_pci_device_close(uacpi_handle) {
// TODO
}
uacpi_status uacpi_kernel_pci_read8(uacpi_handle device, uacpi_size offset, uacpi_u8* value) {
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_status uacpi_kernel_pci_read16(uacpi_handle device, uacpi_size offset, uacpi_u16* value) {
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_status uacpi_kernel_pci_read32(uacpi_handle device, uacpi_size offset, uacpi_u32* value) {
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_status uacpi_kernel_pci_write8(uacpi_handle device, uacpi_size offset, uacpi_u8 value) {
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_status uacpi_kernel_pci_write16(uacpi_handle device, uacpi_size offset, uacpi_u16 value) {
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_status uacpi_kernel_pci_write32(uacpi_handle device, uacpi_size offset, uacpi_u32 value) {
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_status uacpi_kernel_io_map(uacpi_io_addr base, uacpi_size len, uacpi_handle* out_handle) {
return UACPI_STATUS_UNIMPLEMENTED;
}
void uacpi_kernel_io_unmap(uacpi_handle handle) {
// TODO
}
uacpi_status uacpi_kernel_io_read8(uacpi_handle, uacpi_size offset, uacpi_u8* out_value) {
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_status uacpi_kernel_io_read16(uacpi_handle, uacpi_size offset, uacpi_u16* out_value) {
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_status uacpi_kernel_io_read32(uacpi_handle, uacpi_size offset, uacpi_u32* out_value) {
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_status uacpi_kernel_io_write8(uacpi_handle, uacpi_size offset, uacpi_u8 in_value) {
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_status uacpi_kernel_io_write16(uacpi_handle, uacpi_size offset, uacpi_u16 in_value) {
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_status uacpi_kernel_io_write32(uacpi_handle, uacpi_size offset, uacpi_u32 in_value) {
return UACPI_STATUS_UNIMPLEMENTED;
}
void* uacpi_kernel_alloc(uacpi_size size) {
return malloc(size);
}
void uacpi_kernel_free(void* mem) {
free(mem);
}
#define uacpi_kernel_log(...)
uacpi_u64 uacpi_kernel_get_nanoseconds_since_boot(void) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_get_nanoseconds_since_boot()\n");
// TODO
return zn_time();
}
void uacpi_kernel_stall(uacpi_u8 usec) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_stall(%hhu)\n", usec);
// TODO
}
void uacpi_kernel_sleep(uacpi_u64 msec) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_sleep(%lu)\n", msec);
// TODO
}
uacpi_handle uacpi_kernel_create_mutex(void) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_create_mutex()\n");
// TODO
return (uacpi_handle)malloc(sizeof(int));
}
void uacpi_kernel_free_mutex(uacpi_handle handle) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_free_mutex(%p)\n", handle);
// TODO
free(handle);
}
uacpi_handle uacpi_kernel_create_event(void) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_create_event()\n");
// TODO
return malloc(sizeof(int));
}
void uacpi_kernel_free_event(uacpi_handle handle) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_free_event(%p)\n", handle);
free(handle);
}
uacpi_thread_id uacpi_kernel_get_thread_id(void) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_get_thread_id()\n");
// TODO
return 0;
}
uacpi_interrupt_state uacpi_kernel_disable_interrupts(void) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_disable_interrupts()\n");
// TODO
return false;
}
void uacpi_kernel_restore_interrupts(uacpi_interrupt_state state) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_disable_interrupts()\n");
// TODO
}
uacpi_status uacpi_kernel_acquire_mutex(uacpi_handle handle, uacpi_u16 flags) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_acquire_mutex(%p, %#hx)\n", handle, flags);
return UACPI_STATUS_OK;
}
void uacpi_kernel_release_mutex(uacpi_handle handle) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_release_mutex(%p)\n", handle);
// TODO
}
uacpi_bool uacpi_kernel_wait_for_event(uacpi_handle handle, uacpi_u16 timeout) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_wait_for_event(%p, %hx)\n", handle, timeout);
// TODO
return true;
}
void uacpi_kernel_signal_event(uacpi_handle) {
// TODO
}
void uacpi_kernel_reset_event(uacpi_handle) {
// TODO
}
uacpi_status uacpi_kernel_handle_firmware_request(uacpi_firmware_request*) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_handle_firmware_request()\n");
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_status uacpi_kernel_install_interrupt_handler(
uacpi_u32 irq,
uacpi_interrupt_handler,
uacpi_handle ctx,
uacpi_handle* out_irq_handle
) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_install_interrupt_handler()\n");
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_status uacpi_kernel_uninstall_interrupt_handler(uacpi_interrupt_handler, uacpi_handle irq_handle) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_uninstall_interrupt_handler()\n");
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_handle uacpi_kernel_create_spinlock(void) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_create_spinlock()\n");
// TODO
return malloc(sizeof(int));
}
void uacpi_kernel_free_spinlock(uacpi_handle handle) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_free_spinlock(%p)\n", handle);
// TODO
free(handle);
}
uacpi_cpu_flags uacpi_kernel_lock_spinlock(uacpi_handle handle) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_lock_spinlock(%p)\n", handle);
// TODO
return 0;
}
void uacpi_kernel_unlock_spinlock(uacpi_handle handle, uacpi_cpu_flags flags) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_unlock_spinlock(%p, %#lx)\n", handle, flags);
// TODO
}
uacpi_status uacpi_kernel_schedule_work(uacpi_work_type, uacpi_work_handler, uacpi_handle ctx) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_schedule_work()\n");
return UACPI_STATUS_UNIMPLEMENTED;
}
uacpi_status uacpi_kernel_wait_for_work_completion(void) {
uacpi_kernel_log(UACPI_LOG_WARN, "uacpi_kernel_wait_for_work_completion()\n");
return UACPI_STATUS_UNIMPLEMENTED;
}
+42
View File
@@ -0,0 +1,42 @@
#include <zinnia/channel.h>
#include <zinnia/handle.h>
#include <zinnia/ipc/init.h>
#include <zinnia/system.h>
#include <common/compiler.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/auxv.h>
#include <uacpi/uacpi.h>
[[__format(printf, 1, 2)]]
static void zn_printf(const char* msg, ...) {
char buf[1024];
va_list args;
va_start(args, msg);
int32_t len = vsnprintf(buf, sizeof(buf), msg, args);
va_end(args);
zn_log(buf, len);
}
int main(int argc, char* argv[], char* envp[]) {
zn_printf("devd: starting...\n");
zn_handle_t channel = getauxval(AT_INIT_HANDLE);
// while (true) {}
uacpi_status status = uacpi_initialize(0);
if (status != UACPI_STATUS_OK) {
zn_printf("devd: uacpi_initialize failed: %s\n", uacpi_status_to_string(status));
return EXIT_FAILURE;
}
status = uacpi_namespace_load();
if (status != UACPI_STATUS_OK) {
zn_printf("devd: uacpi_namespace_load failed: %s\n", uacpi_status_to_string(status));
return EXIT_FAILURE;
}
uacpi_namespace_initialize();
return 0;
}
+15
View File
@@ -0,0 +1,15 @@
executable(
'devd',
'main.c',
'acpi/glue.c',
uacpi_sources,
c_args: [
'-DUACPI_FORMATTED_LOGGING',
],
link_args: '-static',
include_directories: [
common_includes,
uacpi_includes,
],
install: true,
)
+68
View File
@@ -0,0 +1,68 @@
#include <zinnia/channel.h>
#include <zinnia/handle.h>
#include <zinnia/ipc/init.h>
#include <zinnia/mem.h>
#include <zinnia/status.h>
#include <zinnia/system.h>
#include <common/compiler.h>
#include <common/utils.h>
#include <stdarg.h>
#include <stdatomic.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/auxv.h>
#define ZN_ASSERT(expr) \
do { \
zn_status_t status = expr; \
if (status != ZN_OK) { \
zn_printf("initd: " #expr " failed: %s\n", zn_status_to_string(status)); \
return EXIT_FAILURE; \
} \
} while (0)
[[__format(printf, 1, 2)]]
static void zn_printf(const char* msg, ...) {
char buf[1024];
va_list args;
va_start(args, msg);
int32_t len = vsnprintf(buf, sizeof(buf), msg, args);
va_end(args);
zn_log(buf, len);
}
int main(int argc, char* argv[], char* envp[]) {
zn_printf("initd: starting...\n");
zn_handle_t channel = getauxval(AT_INIT_HANDLE);
while (true) {
static thread_local zn_handle_t handles[32];
static thread_local char buf[1024];
ZN_ASSERT(zn_channel_read(channel, handles, buf, ARRAY_SIZE(handles), ARRAY_SIZE(buf), nullptr, nullptr));
enum ipc_msg_id* msg = (enum ipc_msg_id*)buf;
switch (*msg) {
case IPC_MSG_FOO: {
struct ipc_init_register_rq* foo = (struct ipc_init_register_rq*)msg;
char buf[32] = {0};
IPC_GET_STRING(foo->data, &foo->name, buf);
zn_printf("initd: ipc_init_register_rq, peer = \"%s\"\n", buf);
} break;
case IPC_MSG_BAR: {
struct ipc_kernel_msg* foo = (struct ipc_kernel_msg*)msg;
char buf[32] = {0};
IPC_GET_STRING(foo->data, &foo->name, buf);
zn_printf("initd: ipc_kernel_msg, msg = \"%s\"\n", buf);
} break;
case IPC_MSG_BAZ:
break;
}
}
}
+8
View File
@@ -0,0 +1,8 @@
executable(
'initd',
'main.c',
# The init process is linked statically because the dynamic loader can't be read before posixd is up.
link_args: '-static',
include_directories: common_includes,
install: true,
)
+3
View File
@@ -0,0 +1,3 @@
subdir('initd')
subdir('devd')
subdir('posixd')
+86
View File
@@ -0,0 +1,86 @@
#pragma once
#include <zinnia/handle.h>
#include <zinnia/status.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/time.h>
#include <unistd.h>
struct file;
struct inode;
struct path;
// struct file_ops {
// zn_status_t (*open)(struct file* self, uint32_t flags);
// zn_status_t (*close)(struct file* self);
// zn_status_t (*read)(struct file* self, struct iovec_iter* iter, ssize_t* out_read);
// zn_status_t (*write)(struct file* self, struct iovec_iter* iter, ssize_t* out_written);
// zn_status_t (*devctl)(struct file* self, uint32_t dcmd, void* data, size_t num, int* out_info);
// zn_status_t (*poll)(struct file* self, int16_t mask, int16_t* out_mask); // TODO: This is not correct.
// zn_status_t (*mmap)(
// struct file* self,
// zn_handle_t* space,
// void* addr,
// size_t len,
// int prot,
// int flags,
// off_t offset
// );
// };
struct file {
const struct file_ops* ops;
struct inode* inode;
uint32_t mode;
uint32_t flags;
};
struct file* file_alloc();
struct file* file_from_fd(int fd);
struct inode_ops {
union {
struct {
zn_status_t (*lookup)(struct inode* inode, struct path* path);
} dir;
struct {
zn_status_t (*truncate)(struct inode* inode);
} reg;
};
};
struct inode_attr {
struct timespec atime, mtime, ctime;
uid_t uid;
gid_t gid;
};
struct inode {
const struct inode_ops* ops;
struct inode_attr attr;
};
struct entry {
const char* name;
struct inode* inode;
uint8_t state;
};
struct path {
struct entry* entry;
struct mount* mount;
};
struct mount {
uint32_t flags;
struct entry root;
struct path mount_point;
};
struct file_system_ops {};
struct file_system {
const char* name;
struct file_system_ops ops;
};
+66
View File
@@ -0,0 +1,66 @@
#include <zinnia/channel.h>
#include <zinnia/handle.h>
#include <zinnia/ipc/init.h>
#include <zinnia/mem.h>
#include <zinnia/status.h>
#include <zinnia/system.h>
#include <zinnia/thread.h>
#include <common/compiler.h>
#include <common/utils.h>
#include <errno.h>
#include <stdarg.h>
#include <stdatomic.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/auxv.h>
#include <threads.h>
thread_local char buf[1024];
[[__format(printf, 1, 2)]]
static void zn_printf(const char* msg, ...) {
va_list args;
va_start(args, msg);
int32_t len = vsnprintf(buf, sizeof(buf), msg, args);
va_end(args);
zn_log(buf, len);
}
zn_handle_t channel;
int other_fn(void* arg) {
zn_printf("posixd: Hello from the other thread named \"%s\"!\n", (const char*)arg);
channel = getauxval(AT_INIT_HANDLE);
struct ipc_init_register_rq msg = {
.id = IPC_MSG_FOO,
};
char name[] = "posixd";
zn_status_t status = zn_channel_write(channel, nullptr, &msg, 0, sizeof(msg) + sizeof(name));
if (status != ZN_OK) {
zn_printf("posixd: %s\n", zn_status_to_string(status));
}
return 69;
}
int main(int argc, char* argv[], char* envp[]) {
zn_printf("posixd: starting...\n");
const char* thread_name = "posix_second_thread";
thrd_t thread;
int res = thrd_create(&thread, other_fn, (void*)thread_name);
if (res != thrd_success)
zn_printf("posixd: errno: %s\n", strerror(errno));
zn_printf("posixd: second thread created\n");
int res2;
zn_printf("posixd: waiting on second thread...\n");
thrd_join(thread, &res2);
zn_printf("posixd: second thread exited with: %i\n", res2);
return 0;
}
+10
View File
@@ -0,0 +1,10 @@
configure_file(configuration: cfg, output: 'config.h')
executable(
'posixd',
'main.c',
'uname.c',
link_args: '-static',
include_directories: [common_includes, 'include'],
install: true,
)
+10
View File
@@ -0,0 +1,10 @@
#include <config.h>
#include <sys/utsname.h>
static struct utsname uname_buf = {
.sysname = "Zinnia",
.release = ZINNIA_VERSION,
.version = ZINNIA_COMPILER_ID " " ZINNIA_LINKER_ID,
.nodename = "localhost",
.machine = ZINNIA_ARCH,
};