]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/omap/arch.c
audiohda: fix syntax error
[plan9front.git] / sys / src / 9 / omap / arch.c
1 #include "u.h"
2 #include "../port/lib.h"
3 #include "mem.h"
4 #include "dat.h"
5 #include "fns.h"
6 #include "../port/error.h"
7
8 #include <tos.h>
9 #include "ureg.h"
10
11 #include "arm.h"
12
13 /*
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.
17  */
18
19 /* Give enough context in the ureg to produce a kernel stack for
20  * a sleeping process
21  */
22 void
23 setkernur(Ureg* ureg, Proc* p)
24 {
25         ureg->pc = p->sched.pc;
26         ureg->sp = p->sched.sp+4;
27         ureg->r14 = (uintptr)sched;
28 }
29
30 /*
31  * called in sysfile.c
32  */
33 void
34 evenaddr(uintptr addr)
35 {
36         if(addr & 3){
37                 postnote(up, 1, "sys: odd address", NDebug);
38                 error(Ebadarg);
39         }
40 }
41
42 /*
43  *  return the userpc the last exception happened at
44  */
45 uintptr
46 userpc(void)
47 {
48         Ureg *ureg = up->dbgreg;
49         return ureg->pc;
50 }
51
52 /* This routine must save the values of registers the user is not permitted
53  * to write from devproc and then restore the saved values before returning.
54  */
55 void
56 setregisters(Ureg* ureg, char* pureg, char* uva, int n)
57 {
58         ulong v = ureg->psr;
59         memmove(pureg, uva, n);
60         ureg->psr = ureg->psr & ~(PsrMask|PsrDfiq|PsrDirq) | v & (PsrMask|PsrDfiq|PsrDirq);
61 }
62
63 /*
64  *  setup stack and initial PC for a new kernel proc.  This is architecture
65  *  dependent because of the starting stack location
66  */
67 void
68 kprocchild(Proc *p, void (*entry)(void))
69 {
70         p->sched.pc = (uintptr)entry;
71         p->sched.sp = (uintptr)p->kstack+KSTACK;
72 }
73
74 /*
75  *  pc output by dumpaproc
76  */
77 uintptr
78 dbgpc(Proc* p)
79 {
80         Ureg *ureg;
81
82         ureg = p->dbgreg;
83         if(ureg == 0)
84                 return 0;
85
86         return ureg->pc;
87 }
88
89 /*
90  *  set mach dependent process state for a new process
91  */
92 void
93 procsetup(Proc* p)
94 {
95         fpusysprocsetup(p);
96 }
97
98 void
99 procfork(Proc* p)
100 {
101         fpuprocfork(p);
102 }
103
104 /*
105  *  Save the mach dependent part of the process state.
106  */
107 void
108 procsave(Proc* p)
109 {
110 // TODO: save and restore VFPv3 FP state once 5[cal] know the new registers.
111         fpuprocsave(p);
112 }
113
114 void
115 procrestore(Proc* p)
116 {
117         fpuprocrestore(p);
118 }
119
120 int
121 userureg(Ureg* ureg)
122 {
123         return (ureg->psr & PsrMask) == PsrMusr;
124 }
125
126 int
127 cas32(void* addr, u32int old, u32int new)
128 {
129         int r, s;
130
131         s = splhi();
132         if(r = (*(u32int*)addr == old))
133                 *(u32int*)addr = new;
134         splx(s);
135         if (r)
136                 coherence();
137         return r;
138 }