This commit is contained in:
2025-09-27 15:16:26 +02:00
parent 5af7c5276a
commit 3b1bb9d531
63 changed files with 1087 additions and 407 deletions

65
kernel/syscall/devctl.c Normal file
View File

@ -0,0 +1,65 @@
#include <stdint.h>
#include <stddef.h>
#include "kprintf.h"
#include "syscall.h"
#include "errors.h"
#include "spinlock/spinlock.h"
#include "proc/proc.h"
#include "sysdefs/devctl.h"
#include "dev/termdev.h"
#include "util/util.h"
Dev *DEVS[] = {
[0x10] = &TERMDEV,
};
int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1) {
uint64_t *devh = (uint64_t *)devh1;
uint64_t cmd = cmd1;
int32_t ret = E_OK;
spinlock_acquire(&PROCS.spinlock);
Proc *proc = PROCS.current;
spinlock_release(&PROCS.spinlock);
switch (cmd) {
case DEVCTL_GET_HANDLE: {
uint64_t devid = buffer1;
if (devid >= LEN(DEVS)) {
ret = E_INVALIDARGUMENT;
goto done;
}
bool found = false;
for (size_t i = 0; i < PROC_DEVHANDLES_MAX; i++) {
if (proc->devs[i] == NULL) {
found = true;
proc->devs[i] = DEVS[devid];
break;
}
}
if (!found) {
ret = E_NOENTRY;
goto done;
}
} break;
default: {
if (devh == NULL) {
ret = E_INVALIDARGUMENT;
goto done;
}
if (cmd >= DEV_FNS_MAX) {
ret = E_INVALIDARGUMENT;
goto done;
}
Dev *dev = proc->devs[*devh];
ret = dev->fns[cmd]((uint8_t *)buffer1, (size_t)len1, (void *)extra1);
} break;
}
done:
return ret;
}

9
kernel/syscall/devctl.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef SYSCALL_DEVCTL_H_
#define SYSCALL_DEVCTL_H_
#include <stdint.h>
#include "syscall.h"
int32_t SYSCALL5(sys_devctl, devh1, cmd1, buffer1, len1, extra1);
#endif // SYSCALL_DEVCTL_H_

View File

@ -10,6 +10,7 @@
#include "sysdefs/mman.h"
#include "bootinfo/bootinfo.h"
#include "dlmalloc/malloc.h"
#include "kprintf.h"
int32_t SYSCALL5(sys_mman_map, addr1, size1, prot1, flags1, out1) {
uint8_t *addr = (uint8_t *)addr1;
@ -27,9 +28,6 @@ int32_t SYSCALL5(sys_mman_map, addr1, size1, prot1, flags1, out1) {
size_t pages = _DIV_ROUNDUP(size, HAL_PAGE_SIZE);
uint8_t *phys = (uint8_t *)pmm_alloc(pages);
if (phys == NULL) {
return E_NOMEMORY;
}
hal_memset(VIRT(phys), 0, pages * HAL_PAGE_SIZE);
spinlock_acquire(&PROCS.spinlock);

View File

@ -63,8 +63,10 @@ int32_t SYSCALL5(sys_processctl, pid1, cmd1, arg1, arg2, arg3) {
size_t argslen = arg3;
char *(*args)[] = (char *(*)[])arg2;
for (size_t i = 0; i < argslen; i++) {
PROC_ARG(newproc, (*args)[i]);
if (args != NULL && argslen > 0) {
for (size_t i = 0; i < argslen; i++) {
PROC_ARG(newproc, (*args)[i]);
}
}
for (size_t i = 0; i < PROC_PIPEHANDLES_MAX; i++) {

View File

@ -11,7 +11,7 @@ int32_t SYSCALL0(sys_schedrelease) {
Proc *proc = PROCS.current;
spinlock_release(&PROCS.spinlock);
proc_sched((void *)frame);
/* proc_sched((void *)frame); */
return E_OK;
}

View File

@ -8,6 +8,7 @@
#include "ipcpipe.h"
#include "mman.h"
#include "sched.h"
#include "devctl.h"
int32_t SYSCALL1(sys_debugprint, string) {
char *p = (char *)string;
@ -23,4 +24,5 @@ SyscallFn SYSCALL_TABLE[SYSCALLS_MAX] = {
[SYS_MMAN_MAP] = &sys_mman_map,
[SYS_MMAN_UNMAP] = &sys_mman_unmap,
[SYS_SCHEDRELEASE] = &sys_schedrelease,
[SYS_DEVCTL] = &sys_devctl,
};