Minimal device system, implement terminal device and libterminal
All checks were successful
Build documentation / build-and-deploy (push) Successful in 55s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 55s
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include <aux/compiler.h>
|
||||
#include <device/device.h>
|
||||
#include <libk/assert.h>
|
||||
#include <libk/fieldlengthof.h>
|
||||
#include <libk/std.h>
|
||||
#include <limine/requests.h>
|
||||
#include <m/status.h>
|
||||
@@ -166,6 +168,55 @@ DEFINE_SYSCALL (sys_mutex_unlock) {
|
||||
return SYSRESULT (ST_OK);
|
||||
}
|
||||
|
||||
/* int device_do (int device_id, int cmd, void* a1, void* a2, void* a3, void* a4) */
|
||||
DEFINE_SYSCALL (sys_device_do) {
|
||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||
|
||||
int device_id = (int)a1;
|
||||
int cmd = (int)a2;
|
||||
uintptr_t ua1 = a3, ka1 = 0;
|
||||
uintptr_t ua2 = a4, ka2 = 0;
|
||||
uintptr_t ua3 = a5, ka3 = 0;
|
||||
uintptr_t ua4 = a6, ka4 = 0;
|
||||
uintptr_t out_paddr;
|
||||
|
||||
if (!(cmd >= 0 && cmd < (int)fieldlengthof (struct device, ops)))
|
||||
return -ST_BAD_DEVICE_OP;
|
||||
|
||||
spin_lock (&proc->procgroup->lock);
|
||||
|
||||
out_paddr = mm_v2p (&proc->procgroup->pd, ua1);
|
||||
if (out_paddr != 0)
|
||||
ka1 = (uintptr_t)hhdm->offset + out_paddr;
|
||||
|
||||
out_paddr = mm_v2p (&proc->procgroup->pd, ua2);
|
||||
if (out_paddr != 0)
|
||||
ka2 = (uintptr_t)hhdm->offset + out_paddr;
|
||||
|
||||
out_paddr = mm_v2p (&proc->procgroup->pd, ua3);
|
||||
if (out_paddr != 0)
|
||||
ka3 = (uintptr_t)hhdm->offset + out_paddr;
|
||||
|
||||
out_paddr = mm_v2p (&proc->procgroup->pd, ua4);
|
||||
if (out_paddr != 0)
|
||||
ka4 = (uintptr_t)hhdm->offset + out_paddr;
|
||||
|
||||
spin_unlock (&proc->procgroup->lock);
|
||||
|
||||
struct device* device = device_find (device_id);
|
||||
|
||||
if (device == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
spin_lock (&device->lock);
|
||||
|
||||
int ret = device->ops[cmd]((void*)ka1, (void*)ka2, (void*)ka3, (void*)ka4);
|
||||
|
||||
spin_unlock (&device->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static syscall_handler_func_t handler_table[] = {
|
||||
[SYS_QUIT] = &sys_quit,
|
||||
[SYS_TEST] = &sys_test,
|
||||
@@ -178,6 +229,7 @@ static syscall_handler_func_t handler_table[] = {
|
||||
[SYS_MUTEX_DELETE] = &sys_mutex_delete,
|
||||
[SYS_MUTEX_LOCK] = &sys_mutex_lock,
|
||||
[SYS_MUTEX_UNLOCK] = &sys_mutex_unlock,
|
||||
[SYS_DEVICE_DO] = &sys_device_do,
|
||||
};
|
||||
|
||||
syscall_handler_func_t syscall_find_handler (int syscall_num) {
|
||||
|
||||
Reference in New Issue
Block a user