2 #include "../port/lib.h"
6 #include "../port/error.h"
14 * A lot of this stuff doesn't belong here
15 * but this is a convenient dumping ground for
16 * later sorting into the appropriate buckets.
19 /* Give enough context in the ureg to produce a kernel stack for
23 setkernur(Ureg* ureg, Proc* p)
25 ureg->pc = p->sched.pc;
26 ureg->sp = p->sched.sp+4;
27 ureg->r14 = (uintptr)sched;
34 evenaddr(uintptr addr)
37 postnote(up, 1, "sys: odd address", NDebug);
42 /* go to user space */
49 /* precise time accounting, kernel exit */
50 tos = (Tos*)(USTKTOP-sizeof(Tos));
52 tos->kcycles += t - up->kentry;
53 tos->pcycles = up->pcycles;
54 tos->cyclefreq = m->cpuhz;
57 /* make visible immediately to user phase */
58 l1cache->wbse(tos, sizeof *tos);
62 * return the userpc the last exception happened at
67 Ureg *ureg = up->dbgreg;
71 /* This routine must save the values of registers the user is not permitted
72 * to write from devproc and then restore the saved values before returning.
75 setregisters(Ureg* ureg, char* pureg, char* uva, int n)
78 memmove(pureg, uva, n);
79 ureg->psr = ureg->psr & ~(PsrMask|PsrDfiq|PsrDirq) | v & (PsrMask|PsrDfiq|PsrDirq);
83 * this is the body for all kproc's
90 pexit("kproc exiting", 0);
94 * setup stack and initial PC for a new kernel proc. This is architecture
95 * dependent because of the starting stack location
98 kprocchild(Proc *p, void (*func)(void*), void *arg)
100 p->sched.pc = (uintptr)linkproc;
101 p->sched.sp = (uintptr)p->kstack+KSTACK;
108 * pc output by dumpaproc
123 * set mach dependent process state for a new process
132 * Save the mach dependent part of the process state.
143 l1cache->wbse(p, sizeof *p); /* is this needed? */
144 l1cache->wb(); /* is this needed? */
150 p->kentry = up->kentry;
151 p->pcycles = -p->kentry;
165 wakewfi(); /* in case there's another runnable proc */
167 /* let it fault in at first use */
168 // fpuprocrestore(p);
169 l1cache->wb(); /* system is more stable with this */
175 return (ureg->psr & PsrMask) == PsrMusr;