Reimplement the terminal user access via separate syscalls

This commit is contained in:
2025-11-15 00:38:54 +01:00
parent 3726cc49da
commit ecee481b33
8 changed files with 32 additions and 36 deletions

View File

@ -3,7 +3,6 @@
#include "spinlock/spinlock.h"
#include "std/string.h"
#include "dev/dev.h"
#include "dev/termdev.h"
#include "dev/ps2kbdev.h"
#include "dev/serialdev.h"
#include "dev/fbdev.h"
@ -15,7 +14,6 @@ void dev_init(void) {
memset(&DEVTABLE, 0, sizeof(DEVTABLE));
spinlock_init(&DEVTABLE.spinlock);
termdev_init();
ps2kbdev_init();
serialdev_init();
fbdev_init();

View File

@ -1,22 +0,0 @@
#include <stdint.h>
#include <stddef.h>
#include "dev/termdev.h"
#include "dev/dev.h"
#include "util/util.h"
#include "sysdefs/dev.h"
#include "kprintf.h"
#include "hshtb.h"
#include "errors.h"
int32_t termdev_putch(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid) {
(void)dev; (void)pid;
kprintf("%.*s", (int)len, (char *)buffer);
return E_OK;
}
void termdev_init(void) {
Dev *termdev = NULL;
HSHTB_ALLOC(DEVTABLE.devs, ident, "termdev", termdev);
termdev->fns[DEV_TERMDEV_PUTCH] = &termdev_putch;
spinlock_init(&termdev->spinlock);
}

View File

@ -1,10 +0,0 @@
#ifndef DEV_TERMDEV_H_
#define DEV_TERMDEV_H_
#include <stdint.h>
#include <stddef.h>
#include "dev.h"
void termdev_init(void);
#endif // DEV_TERMDEV_H_

View File

@ -11,6 +11,7 @@
#include "syscall/dev.h"
#include "syscall/time.h"
#include "syscall/ipcmbus.h"
#include "syscall/term.h"
#include "errors.h"
#include "kprintf.h"
@ -75,4 +76,6 @@ SyscallFn SYSCALL_TABLE[SYSCALLS_MAX] = {
[SYS_IPC_MBUSCONSUME] = &sys_ipc_mbusconsume,
[SYS_IPC_MBUSATTCH] = &sys_ipc_mbusattch,
[SYS_IPC_MBUSDTTCH] = &sys_ipc_mbusdttch,
[SYS_TERM_WRITE] = &sys_term_write,
};

18
kernel/syscall/term.c Normal file
View File

@ -0,0 +1,18 @@
#include <stdint.h>
#include <stddef.h>
#include "syscall/syscall.h"
#include "kprintf.h"
#include "errors.h"
int32_t SYSCALL2(sys_term_write, buffer1, len1) {
const char *buffer = (const char *)buffer1;
size_t len = len1;
if (buffer == NULL) {
return E_INVALIDARGUMENT;
}
kprintf("%.*s", (int)len, buffer);
return E_OK;
}

10
kernel/syscall/term.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef SYSCALL_TERM_H_
#define SYSCALL_TERM_H_
#include <stdint.h>
#include <stddef.h>
#include "syscall/syscall.h"
int32_t SYSCALL2(sys_term_write, buffer1, len1);
#endif // SYSCALL_TERM_H_

View File

@ -4,8 +4,6 @@
#include <stdint.h>
#include <stddef.h>
#define DEV_TERMDEV_PUTCH 0
#define DEV_SERIALDEV_SENDB 0
#define DEV_SERIALDEV_SENDREADY 1
#define DEV_SERIALDEV_RECVB 2

View File

@ -45,5 +45,6 @@
#define SYS_IPC_MBUSCONSUME 43
#define SYS_IPC_MBUSATTCH 44
#define SYS_IPC_MBUSDTTCH 45
#define SYS_TERM_WRITE 46
#endif // SHARE_HDRS_SYSCALL_H_