This source file includes following definitions.
- cpu_fork
- cpu_exit
- cpu_wait
- cpu_coredump
- kvtop
- vmapbuf
- vunmapbuf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/proc.h>
48 #include <sys/signalvar.h>
49 #include <sys/malloc.h>
50 #include <sys/vnode.h>
51 #include <sys/buf.h>
52 #include <sys/user.h>
53 #include <sys/core.h>
54 #include <sys/exec.h>
55 #include <sys/ptrace.h>
56
57 #include <uvm/uvm_extern.h>
58
59 #include <machine/cpu.h>
60 #include <machine/gdt.h>
61 #include <machine/reg.h>
62 #include <machine/specialreg.h>
63
64 #include "npx.h"
65
66
67
68
69
70
71
72
73
74
75 void
76 cpu_fork(struct proc *p1, struct proc *p2, void *stack, size_t stacksize,
77 void (*func)(void *), void *arg)
78 {
79 struct pcb *pcb = &p2->p_addr->u_pcb;
80 struct trapframe *tf;
81 struct switchframe *sf;
82
83 #if NNPX > 0
84 npxsave_proc(p1, 1);
85 #endif
86
87 p2->p_md.md_flags = p1->p_md.md_flags;
88
89
90 if (p1 == curproc) {
91
92 savectx(curpcb);
93 }
94 #ifdef DIAGNOSTIC
95 else if (p1 != &proc0)
96 panic("cpu_fork: curproc");
97 #endif
98 *pcb = p1->p_addr->u_pcb;
99
100
101
102
103
104
105
106
107 p2->p_md.md_tss_sel = GSEL(GNULL_SEL, SEL_KPL);
108
109
110 pcb->pcb_tss.tss_ss0 = GSEL(GDATA_SEL, SEL_KPL);
111 pcb->pcb_tss.tss_esp0 = (int)p2->p_addr + USPACE - 16;
112
113 p2->p_md.md_tss_sel = tss_alloc(pcb);
114
115
116
117
118
119 p2->p_md.md_regs = tf = (struct trapframe *)pcb->pcb_tss.tss_esp0 - 1;
120 *tf = *p1->p_md.md_regs;
121
122
123
124
125 if (stack != NULL)
126 tf->tf_esp = (u_int)stack + stacksize;
127
128 sf = (struct switchframe *)tf - 1;
129 sf->sf_ppl = 0;
130 sf->sf_esi = (int)func;
131 sf->sf_ebx = (int)arg;
132 sf->sf_eip = (int)proc_trampoline;
133 pcb->pcb_esp = (int)sf;
134 }
135
136
137
138
139
140
141
142
143
144 void
145 cpu_exit(struct proc *p)
146 {
147 #if NNPX > 0
148
149 if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
150 npxsave_proc(p, 0);
151 #endif
152
153 pmap_deactivate(p);
154 switch_exit(p);
155 }
156
157 void
158 cpu_wait(struct proc *p)
159 {
160 tss_free(p->p_md.md_tss_sel);
161 }
162
163
164
165
166 struct md_core {
167 struct reg intreg;
168 struct fpreg freg;
169 };
170
171 int
172 cpu_coredump(struct proc *p, struct vnode *vp, struct ucred *cred,
173 struct core *chdr)
174 {
175 struct md_core md_core;
176 struct coreseg cseg;
177 int error;
178
179 CORE_SETMAGIC(*chdr, COREMAGIC, MID_I386, 0);
180 chdr->c_hdrsize = ALIGN(sizeof(*chdr));
181 chdr->c_seghdrsize = ALIGN(sizeof(cseg));
182 chdr->c_cpusize = sizeof(md_core);
183
184
185 error = process_read_regs(p, &md_core.intreg);
186 if (error)
187 return error;
188
189
190 error = process_read_fpregs(p, &md_core.freg);
191 if (error)
192 return error;
193
194 CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_I386, CORE_CPU);
195 cseg.c_addr = 0;
196 cseg.c_size = chdr->c_cpusize;
197
198 error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&cseg, chdr->c_seghdrsize,
199 (off_t)chdr->c_hdrsize, UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred,
200 NULL, p);
201 if (error)
202 return error;
203
204 error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&md_core, sizeof(md_core),
205 (off_t)(chdr->c_hdrsize + chdr->c_seghdrsize), UIO_SYSSPACE,
206 IO_NODELOCKED|IO_UNIT, cred, NULL, p);
207 if (error)
208 return error;
209
210 chdr->c_nseg++;
211 return 0;
212 }
213
214
215
216
217 int
218 kvtop(caddr_t addr)
219 {
220 paddr_t pa;
221
222 if (pmap_extract(pmap_kernel(), (vaddr_t)addr, &pa) == FALSE)
223 panic("kvtop: zero page frame");
224 return((int)pa);
225 }
226
227
228
229
230 void
231 vmapbuf(struct buf *bp, vsize_t len)
232 {
233 vaddr_t faddr, taddr, off;
234 paddr_t fpa;
235
236 if ((bp->b_flags & B_PHYS) == 0)
237 panic("vmapbuf");
238 faddr = trunc_page((vaddr_t)(bp->b_saveaddr = bp->b_data));
239 off = (vaddr_t)bp->b_data - faddr;
240 len = round_page(off + len);
241 taddr= uvm_km_valloc_wait(phys_map, len);
242 bp->b_data = (caddr_t)(taddr + off);
243
244
245
246
247
248
249
250
251
252
253
254
255 while (len) {
256 pmap_extract(vm_map_pmap(&bp->b_proc->p_vmspace->vm_map),
257 faddr, &fpa);
258 pmap_kenter_pa(taddr, fpa, VM_PROT_READ|VM_PROT_WRITE);
259 faddr += PAGE_SIZE;
260 taddr += PAGE_SIZE;
261 len -= PAGE_SIZE;
262 }
263 pmap_update(pmap_kernel());
264 }
265
266
267
268
269
270 void
271 vunmapbuf(struct buf *bp, vsize_t len)
272 {
273 vaddr_t addr, off;
274
275 if ((bp->b_flags & B_PHYS) == 0)
276 panic("vunmapbuf");
277 addr = trunc_page((vaddr_t)bp->b_data);
278 off = (vaddr_t)bp->b_data - addr;
279 len = round_page(off + len);
280 pmap_kremove(addr, len);
281 pmap_update(pmap_kernel());
282 uvm_km_free_wakeup(phys_map, addr, len);
283 bp->b_data = bp->b_saveaddr;
284 bp->b_saveaddr = 0;
285 }