Compare commits

..

2 Commits

12 changed files with 54 additions and 2 deletions

View File

@ -17,6 +17,8 @@
#include "proc/ps2kbproc/ps2kbproc.h" #include "proc/ps2kbproc/ps2kbproc.h"
#include "rbuf/rbuf.h" #include "rbuf/rbuf.h"
IntrStackFrame *INTR_CURRENT_FRAME;
typedef struct BackTraceFrame { typedef struct BackTraceFrame {
struct BackTraceFrame *rbp; struct BackTraceFrame *rbp;
uint64_t rip; uint64_t rip;
@ -196,6 +198,8 @@ void intr_eoi(uint8_t irq) {
} }
void intr_handleintr(IntrStackFrame *frame) { void intr_handleintr(IntrStackFrame *frame) {
INTR_CURRENT_FRAME = frame;
if (frame->trapnum <= 31) { if (frame->trapnum <= 31) {
kprintf("ERROR %s, 0x%lX\n", exceptions[frame->trapnum], frame->errnum); kprintf("ERROR %s, 0x%lX\n", exceptions[frame->trapnum], frame->errnum);
intr_dumpframe(frame); intr_dumpframe(frame);

View File

@ -35,4 +35,6 @@ typedef struct {
void intr_init(void); void intr_init(void);
IntrStackFrame *INTR_CURRENT_FRAME;
#endif // HAL_INTR_H_ #endif // HAL_INTR_H_

17
kernel/syscall/sched.c Normal file
View File

@ -0,0 +1,17 @@
#include <stdint.h>
#include "syscall.h"
#include "sched.h"
#include "proc/proc.h"
#include "spinlock/spinlock.h"
#include "errors.h"
#include "hal/hal.h"
int32_t SYSCALL0(sys_schedrelease) {
spinlock_acquire(&PROCS.spinlock);
Proc *proc = PROCS.current;
spinlock_release(&PROCS.spinlock);
proc_sched((void *)INTR_CURRENT_FRAME);
return E_OK;
}

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

@ -0,0 +1,9 @@
#ifndef SYSCALL_SCHED_H_
#define SYSCALL_SCHED_H_
#include <stdint.h>
#include "syscall.h"
int32_t SYSCALL0(sys_schedrelease);
#endif // SYSCALL_SCHED_H_

View File

@ -7,6 +7,7 @@
#include "ioctl.h" #include "ioctl.h"
#include "ipcpipe.h" #include "ipcpipe.h"
#include "mman.h" #include "mman.h"
#include "sched.h"
int32_t SYSCALL1(sys_debugprint, string) { int32_t SYSCALL1(sys_debugprint, string) {
char *p = (char *)string; char *p = (char *)string;
@ -21,4 +22,5 @@ SyscallFn SYSCALL_TABLE[SYSCALLS_MAX] = {
[SYS_IPCPIPE] = &sys_ipcpipe, [SYS_IPCPIPE] = &sys_ipcpipe,
[SYS_MMAN_MAP] = &sys_mman_map, [SYS_MMAN_MAP] = &sys_mman_map,
[SYS_MMAN_UNMAP] = &sys_mman_unmap, [SYS_MMAN_UNMAP] = &sys_mman_unmap,
[SYS_SCHEDRELEASE] = &sys_schedrelease,
}; };

6
share/sysdefs/sched.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef SHARE_SYSDEFS_SHED_H_
#define SHARE_SYSDEFS_SHED_H_
#endif // SHARE_SYSDEFS_SHED_H_

View File

@ -8,6 +8,7 @@ enum {
SYS_IPCPIPE = 4, SYS_IPCPIPE = 4,
SYS_MMAN_MAP = 5, SYS_MMAN_MAP = 5,
SYS_MMAN_UNMAP = 6, SYS_MMAN_UNMAP = 6,
SYS_SCHEDRELEASE = 7,
}; };
#endif // SHARE_HDRS_SYSCALL_H_ #endif // SHARE_HDRS_SYSCALL_H_

View File

@ -30,3 +30,7 @@ int32_t mman_map(uint8_t *addr, size_t size, uint64_t prot, uint64_t flags, uint
int32_t mman_unmap(uint8_t *addr) { int32_t mman_unmap(uint8_t *addr) {
return syscall(SYS_MMAN_UNMAP, (uint64_t)addr, 0, 0, 0, 0, 0); return syscall(SYS_MMAN_UNMAP, (uint64_t)addr, 0, 0, 0, 0, 0);
} }
int32_t schedrelease(void) {
return syscall(SYS_SCHEDRELEASE, 0, 0, 0, 0, 0, 0);
}

View File

@ -10,5 +10,6 @@ int32_t processctl(uint64_t pid, uint64_t cmd, uint64_t arg1, uint64_t arg2, uin
int32_t ipcpipe(uint64_t pid, uint64_t pipenum, uint64_t cmd, uint8_t *buffer, size_t len); int32_t ipcpipe(uint64_t pid, uint64_t pipenum, uint64_t cmd, uint8_t *buffer, size_t len);
int32_t mman_map(uint8_t *addr, size_t size, uint64_t prot, uint64_t flags, uint8_t **out); int32_t mman_map(uint8_t *addr, size_t size, uint64_t prot, uint64_t flags, uint8_t **out);
int32_t mman_unmap(uint8_t *addr); int32_t mman_unmap(uint8_t *addr);
int32_t schedrelease(void);
#endif // ULIB_SYSTEM_SYSTEM_H_ #endif // ULIB_SYSTEM_SYSTEM_H_

View File

@ -20,7 +20,9 @@ void tb_runinitscript(void) {
processctl(tb, PCTL_RUN, 0, 0, 0); processctl(tb, PCTL_RUN, 0, 0, 0);
while(processctl(tb, PCTL_POLLSTATE, 0, 0, 0) != 4); while(processctl(tb, PCTL_POLLSTATE, 0, 0, 0) != 4) {
schedrelease();
}
} }
void main(void) { void main(void) {

View File

@ -239,7 +239,9 @@ bool interp_runstring(const char *string, InterpResult **res, bool logcmds) {
processctl(app, PCTL_RUN, 0, 0, 0); processctl(app, PCTL_RUN, 0, 0, 0);
while(processctl(app, PCTL_POLLSTATE, 0, 0, 0) != 4); while(processctl(app, PCTL_POLLSTATE, 0, 0, 0) != 4) {
schedrelease();
}
cleanup: cleanup:
for (size_t j = 0; j < argslen1; j++) { for (size_t j = 0; j < argslen1; j++) {

View File

@ -124,6 +124,8 @@ void do_mode_interactive(void) {
uprintf(ANSIQ_SCR_CLR_ALL); uprintf(ANSIQ_SCR_CLR_ALL);
goto begin; goto begin;
break; break;
} else {
schedrelease();
} }
if (b == '\n') { if (b == '\n') {