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 = PTR2UINT(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)
77 USED(ureg, pureg, uva, n);
81 * this is the body for all kproc's
88 pexit("kproc exiting", 0);
92 * setup stack and initial PC for a new kernel proc. This is architecture
93 * dependent because of the starting stack location
96 kprocchild(Proc *p, void (*func)(void*), void *arg)
98 p->sched.pc = PTR2UINT(linkproc);
99 p->sched.sp = PTR2UINT(p->kstack+KSTACK);
106 * pc output by dumpaproc
121 * set mach dependent process state for a new process
130 * Save the mach dependent part of the process state.
141 l1cache->wbse(p, sizeof *p); /* is this needed? */
142 l1cache->wb(); /* is this needed? */
148 p->kentry = up->kentry;
149 p->pcycles = -p->kentry;
163 wakewfi(); /* in case there's another runnable proc */
165 /* let it fault in at first use */
166 // fpuprocrestore(p);
167 l1cache->wb(); /* system is more stable with this */
173 return (ureg->psr & PsrMask) == PsrMusr;