summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
authordzwdz2024-07-26 21:40:57 +0200
committerdzwdz2024-07-26 21:40:57 +0200
commit58514d351e1f0e8871f534422cf025109ddbb844 (patch)
tree43c91a3c6c325649be2f07f2a38d0753f0a68cf7 /src/kernel
parent69fd0dd9fda47aa52cccdbef6ca388cea38e693b (diff)
kernel: implement _sys_intr_return
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/proc.c1
-rw-r--r--src/kernel/syscalls.c41
2 files changed, 42 insertions, 0 deletions
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index 350f3ee..8be1080 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -413,6 +413,7 @@ static void proc_intr_deliver(Proc *p) {
d.rcx = p->regs.rcx;
d.rax = p->regs.rax;
d.rip = p->regs.rip;
+ d.flags = p->regs.flags;
// one more because the buffer itself isn't NUL terminated
// TODO ensure NUL termination
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 23a8883..ffd69b8 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -487,6 +487,46 @@ long _sys_duplex(hid_t from, hid_t to, int flags) {
return -1; // dummy
}
+void _sys_intr_return(struct intr_data __user *intr, int flags) {
+ CpuRegs *r = &proc_cur->regs;
+ struct intr_data d;
+ if (flags != 0 || pcpy_from(proc_cur, &d, intr, sizeof(d)) < sizeof(d)) {
+ proc_kill(proc_cur, EFAULT);
+ proc_switch_any(); /* doesn't return */
+ }
+ r->r15 = d.r15;
+ r->r14 = d.r14;
+ r->r13 = d.r13;
+ r->r12 = d.r12;
+ r->r11 = d.r11;
+ r->r10 = d.r10;
+ r->r9 = d.r9;
+ r->r8 = d.r8;
+ r->rdi = d.rdi;
+ r->rsi = d.rsi;
+ r->rbp = d.rbp;
+ r->rsp = d.rsp;
+ r->rbx = d.rbx;
+ r->rdx = d.rdx;
+ r->rcx = d.rcx;
+ r->rax = d.rax;
+ r->rip = d.rip;
+ /* preserved flags: (see intel vol 1 3.4.3.)
+ * 1<<0 = CF, carry flag
+ * 1<<2 = PF, parity flag
+ * 1<<4 = AC, auxilary carry
+ * 1<<6 = ZF, zero flag
+ * 1<<7 = SF, sign flag
+ * 1<<11 = OF, overflow flag
+ * 1<<10 = DF, direction flag
+ */
+ static_assert(
+ ((1<<0) | (1<<2) | (1<<4) | (1<<6) | (1<<7) | (1<<10) | (1<<11))
+ == 0xCD5
+ );
+ r->flags = (d.flags & 0xCD5) | (r->flags & ~0xCD5);
+}
+
long _sys_execbuf(void __user *ubuf, size_t len) {
if (len == 0) SYSCALL_RETURN(0);
static_assert(EXECBUF_MAX_LEN <= KMALLOC_MAX);
@@ -544,6 +584,7 @@ long _syscall(long num, long a, long b, long c, long d, long e) {
break; case _SYS_TIME: _sys_time(a);
break; case _SYS_GETNULL: _sys_getnull(a);
break; case _SYS_DUPLEX: _sys_duplex(a, b, c);
+ break; case _SYS_INTR_RETURN: _sys_intr_return((userptr_t)a, b);
break; case _SYS_EXECBUF: _sys_execbuf((userptr_t)a, b);
break; case _SYS_DEBUG_KLOG: _sys_debug_klog((userptr_t)a, b);
break;