1 /*-
2 * Copyright (c) 2001 Jake Burkholder.
3 * Copyright (c) 1992 Terrence R. Lambert.
4 * Copyright (c) 1982, 1987, 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * William Jolitz.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91
39 * from: FreeBSD: src/sys/i386/i386/machdep.c,v 1.477 2001/08/27
40 * $FreeBSD: releng/5.1/sys/sparc64/sparc64/machdep.c 114983 2003-05-13 20:36:02Z jhb $
41 */
42
43 #include "opt_compat.h"
44 #include "opt_ddb.h"
45 #include "opt_msgbuf.h"
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/cons.h>
50 #include <sys/imgact.h>
51 #include <sys/kernel.h>
52 #include <sys/ktr.h>
53 #include <sys/linker.h>
54 #include <sys/lock.h>
55 #include <sys/malloc.h>
56 #include <sys/msgbuf.h>
57 #include <sys/mutex.h>
58 #include <sys/pcpu.h>
59 #include <sys/proc.h>
60 #include <sys/reboot.h>
61 #include <sys/bio.h>
62 #include <sys/buf.h>
63 #include <sys/bus.h>
64 #include <sys/eventhandler.h>
65 #include <sys/interrupt.h>
66 #include <sys/ptrace.h>
67 #include <sys/signalvar.h>
68 #include <sys/smp.h>
69 #include <sys/sysent.h>
70 #include <sys/sysproto.h>
71 #include <sys/timetc.h>
72 #include <sys/user.h>
73 #include <sys/ucontext.h>
74 #include <sys/user.h>
75 #include <sys/ucontext.h>
76 #include <sys/exec.h>
77
78 #include <dev/ofw/openfirm.h>
79
80 #include <vm/vm.h>
81 #include <vm/vm_param.h>
82 #include <vm/vm_kern.h>
83 #include <vm/vm_object.h>
84 #include <vm/vm_page.h>
85 #include <vm/vm_map.h>
86 #include <vm/vm_pager.h>
87 #include <vm/vm_extern.h>
88
89 #include <ddb/ddb.h>
90
91 #include <machine/cache.h>
92 #include <machine/clock.h>
93 #include <machine/cpu.h>
94 #include <machine/fp.h>
95 #include <machine/fsr.h>
96 #include <machine/intr_machdep.h>
97 #include <machine/md_var.h>
98 #include <machine/metadata.h>
99 #include <machine/ofw_machdep.h>
100 #include <machine/smp.h>
101 #include <machine/pmap.h>
102 #include <machine/pstate.h>
103 #include <machine/reg.h>
104 #include <machine/sigframe.h>
105 #include <machine/tick.h>
106 #include <machine/tlb.h>
107 #include <machine/tstate.h>
108 #include <machine/upa.h>
109 #include <machine/ver.h>
110
111 typedef int ofw_vec_t(void *);
112
113 struct tlb_entry *kernel_tlbs;
114 int kernel_tlb_slots;
115
116 int cold = 1;
117 long Maxmem;
118
119 char pcpu0[PCPU_PAGES * PAGE_SIZE];
120 char uarea0[UAREA_PAGES * PAGE_SIZE];
121 struct trapframe frame0;
122
123 vm_offset_t kstack0;
124 vm_paddr_t kstack0_phys;
125
126 struct kva_md_info kmi;
127
128 u_long ofw_vec;
129 u_long ofw_tba;
130
131 static struct timecounter tick_tc;
132
133 char sparc64_model[32];
134
135 static int cpu_use_vis = 1;
136
137 cpu_block_copy_t *cpu_block_copy;
138 cpu_block_zero_t *cpu_block_zero;
139
140 static timecounter_get_t tick_get_timecount;
141 void sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3,
142 ofw_vec_t *vec);
143 void sparc64_shutdown_final(void *dummy, int howto);
144
145 static void cpu_startup(void *);
146 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
147
148 CTASSERT((1 << INT_SHIFT) == sizeof(int));
149 CTASSERT((1 << PTR_SHIFT) == sizeof(char *));
150
151 CTASSERT(sizeof(struct reg) == 256);
152 CTASSERT(sizeof(struct fpreg) == 272);
153 CTASSERT(sizeof(struct __mcontext) == 512);
154
155 CTASSERT((sizeof(struct pcb) & (64 - 1)) == 0);
156 CTASSERT((offsetof(struct pcb, pcb_kfp) & (64 - 1)) == 0);
157 CTASSERT((offsetof(struct pcb, pcb_ufp) & (64 - 1)) == 0);
158 CTASSERT(sizeof(struct pcb) <= ((KSTACK_PAGES * PAGE_SIZE) / 8));
159
160 CTASSERT(sizeof(struct pcpu) <= ((PCPU_PAGES * PAGE_SIZE) / 2));
161
162 static void
163 cpu_startup(void *arg)
164 {
165
166 tick_tc.tc_get_timecount = tick_get_timecount;
167 tick_tc.tc_poll_pps = NULL;
168 tick_tc.tc_counter_mask = ~0u;
169 tick_tc.tc_frequency = tick_freq;
170 tick_tc.tc_name = "tick";
171 tc_init(&tick_tc);
172
173 printf("real memory = %lu (%lu MB)\n", physmem * PAGE_SIZE,
174 physmem / ((1024 * 1024) / PAGE_SIZE));
175
176 vm_ksubmap_init(&kmi);
177
178 bufinit();
179 vm_pager_bufferinit();
180
181 EVENTHANDLER_REGISTER(shutdown_final, sparc64_shutdown_final, NULL,
182 SHUTDOWN_PRI_LAST);
183
184 printf("avail memory = %lu (%lu MB)\n", cnt.v_free_count * PAGE_SIZE,
185 cnt.v_free_count / ((1024 * 1024) / PAGE_SIZE));
186
187 if (bootverbose)
188 printf("machine: %s\n", sparc64_model);
189
190 cpu_identify(rdpr(ver), tick_freq, PCPU_GET(cpuid));
191 }
192
193 void
194 cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size)
195 {
196 struct intr_request *ir;
197 int i;
198
199 pcpu->pc_irtail = &pcpu->pc_irhead;
200 for (i = 0; i < IR_FREE; i++) {
201 ir = &pcpu->pc_irpool[i];
202 ir->ir_next = pcpu->pc_irfree;
203 pcpu->pc_irfree = ir;
204 }
205 }
206
207 unsigned
208 tick_get_timecount(struct timecounter *tc)
209 {
210 return ((unsigned)rd(tick));
211 }
212
213 void
214 sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3, ofw_vec_t *vec)
215 {
216 phandle_t child;
217 phandle_t root;
218 struct pcpu *pc;
219 vm_offset_t end;
220 caddr_t kmdp;
221 u_int clock;
222 char *env;
223 char type[8];
224
225 end = 0;
226 kmdp = NULL;
227
228 /*
229 * Find out what kind of cpu we have first, for anything that changes
230 * behaviour.
231 */
232 cpu_impl = VER_IMPL(rdpr(ver));
233
234 /*
235 * Initialize openfirmware (needed for console).
236 */
237 OF_init(vec);
238
239 /*
240 * Parse metadata if present and fetch parameters. Must be before the
241 * console is inited so cninit gets the right value of boothowto.
242 */
243 if (mdp != NULL) {
244 preload_metadata = mdp;
245 kmdp = preload_search_by_type("elf kernel");
246 if (kmdp != NULL) {
247 boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
248 kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *);
249 end = MD_FETCH(kmdp, MODINFOMD_KERNEND, vm_offset_t);
250 kernel_tlb_slots = MD_FETCH(kmdp, MODINFOMD_DTLB_SLOTS,
251 int);
252 kernel_tlbs = (void *)preload_search_info(kmdp,
253 MODINFO_METADATA | MODINFOMD_DTLB);
254 }
255 }
256
257 /*
258 * Initialize the console before printing anything.
259 */
260 cninit();
261
262 /*
263 * Panic is there is no metadata. Most likely the kernel was booted
264 * directly, instead of through loader(8).
265 */
266 if (mdp == NULL || kmdp == NULL) {
267 printf("sparc64_init: no loader metadata.\n"
268 "This probably means you are not using loader(8).\n");
269 panic("sparc64_init");
270 }
271
272 /*
273 * Sanity check the kernel end, which is important.
274 */
275 if (end == 0) {
276 printf("sparc64_init: warning, kernel end not specified.\n"
277 "Attempting to continue anyway.\n");
278 end = (vm_offset_t)_end;
279 }
280
281 root = OF_peer(0);
282 for (child = OF_child(root); child != 0; child = OF_peer(child)) {
283 OF_getprop(child, "device_type", type, sizeof(type));
284 if (strcmp(type, "cpu") == 0)
285 break;
286 }
287 if (child == 0)
288 panic("cpu_startup: no cpu\n");
289 cache_init(child);
290
291 getenv_int("machdep.use_vis", &cpu_use_vis);
292 if (cpu_use_vis) {
293 cpu_block_copy = spitfire_block_copy;
294 cpu_block_zero = spitfire_block_zero;
295 } else {
296 cpu_block_copy = bcopy;
297 cpu_block_zero = bzero;
298 }
299
300 #ifdef DDB
301 kdb_init();
302 #endif
303
304 #ifdef SMP
305 mp_tramp = mp_tramp_alloc();
306 #endif
307
308 /*
309 * Initialize virtual memory and calculate physmem.
310 */
311 pmap_bootstrap(end);
312
313 /*
314 * Initialize tunables.
315 */
316 init_param1();
317 init_param2(physmem);
318 env = getenv("kernelname");
319 if (env != NULL) {
320 strlcpy(kernelname, env, sizeof(kernelname));
321 freeenv(env);
322 }
323
324 /*
325 * Disable tick for now.
326 */
327 tick_stop();
328
329 /*
330 * Initialize the interrupt tables.
331 */
332 intr_init1();
333
334 /*
335 * Initialize proc0 stuff (p_contested needs to be done early).
336 */
337 proc_linkup(&proc0, &ksegrp0, &kse0, &thread0);
338 proc0.p_md.md_sigtramp = NULL;
339 proc0.p_md.md_utrap = NULL;
340 proc0.p_uarea = (struct user *)uarea0;
341 proc0.p_stats = &proc0.p_uarea->u_stats;
342 thread0.td_kstack = kstack0;
343 thread0.td_pcb = (struct pcb *)
344 (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1;
345 frame0.tf_tstate = TSTATE_IE | TSTATE_PEF | TSTATE_PRIV;
346 thread0.td_frame = &frame0;
347
348 /*
349 * Prime our per-cpu data page for use. Note, we are using it for our
350 * stack, so don't pass the real size (PAGE_SIZE) to pcpu_init or
351 * it'll zero it out from under us.
352 */
353 pc = (struct pcpu *)(pcpu0 + (PCPU_PAGES * PAGE_SIZE)) - 1;
354 pcpu_init(pc, 0, sizeof(struct pcpu));
355 pc->pc_curthread = &thread0;
356 pc->pc_curpcb = thread0.td_pcb;
357 pc->pc_mid = UPA_CR_GET_MID(ldxa(0, ASI_UPA_CONFIG_REG));
358 pc->pc_addr = (vm_offset_t)pcpu0;
359 pc->pc_node = child;
360 pc->pc_tlb_ctx = TLB_CTX_USER_MIN;
361 pc->pc_tlb_ctx_min = TLB_CTX_USER_MIN;
362 pc->pc_tlb_ctx_max = TLB_CTX_USER_MAX;
363
364 /*
365 * Initialize global registers.
366 */
367 cpu_setregs(pc);
368
369 /*
370 * Initialize the message buffer (after setting trap table).
371 */
372 msgbufinit(msgbufp, MSGBUF_SIZE);
373
374 mutex_init();
375 intr_init2();
376
377 OF_getprop(PCPU_GET(node), "clock-frequency", &clock, sizeof(clock));
378 tick_init(clock);
379
380 OF_getprop(root, "name", sparc64_model, sizeof(sparc64_model) - 1);
381 }
382
383 void
384 set_openfirm_callback(ofw_vec_t *vec)
385 {
386 ofw_tba = rdpr(tba);
387 ofw_vec = (u_long)vec;
388 }
389
390 void
391 sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
392 {
393 struct trapframe *tf;
394 struct sigframe *sfp;
395 struct sigacts *psp;
396 struct sigframe sf;
397 struct thread *td;
398 struct frame *fp;
399 struct proc *p;
400 int oonstack;
401 u_long sp;
402
403 oonstack = 0;
404 td = curthread;
405 p = td->td_proc;
406 PROC_LOCK_ASSERT(p, MA_OWNED);
407 psp = p->p_sigacts;
408 mtx_assert(&psp->ps_mtx, MA_OWNED);
409 tf = td->td_frame;
410 sp = tf->tf_sp + SPOFF;
411 oonstack = sigonstack(sp);
412
413 CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm,
414 catcher, sig);
415
416 /* Make sure we have a signal trampoline to return to. */
417 if (p->p_md.md_sigtramp == NULL) {
418 /*
419 * No signal tramoline... kill the process.
420 */
421 CTR0(KTR_SIG, "sendsig: no sigtramp");
422 printf("sendsig: %s is too old, rebuild it\n", p->p_comm);
423 sigexit(td, sig);
424 /* NOTREACHED */
425 }
426
427 /* Save user context. */
428 bzero(&sf, sizeof(sf));
429 sf.sf_uc.uc_sigmask = *mask;
430 sf.sf_uc.uc_stack = p->p_sigstk;
431 sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
432 ? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
433 bcopy(tf, &sf.sf_uc.uc_mcontext, sizeof(*tf));
434
435 /* Allocate and validate space for the signal handler context. */
436 if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
437 SIGISMEMBER(psp->ps_sigonstack, sig)) {
438 sfp = (struct sigframe *)(p->p_sigstk.ss_sp +
439 p->p_sigstk.ss_size - sizeof(struct sigframe));
440 } else
441 sfp = (struct sigframe *)sp - 1;
442 mtx_unlock(&psp->ps_mtx);
443 PROC_UNLOCK(p);
444
445 fp = (struct frame *)sfp - 1;
446
447 /* Translate the signal if appropriate. */
448 if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
449 sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
450
451 /* Build the argument list for the signal handler. */
452 tf->tf_out[0] = sig;
453 tf->tf_out[1] = (register_t)&sfp->sf_si;
454 tf->tf_out[2] = (register_t)&sfp->sf_uc;
455 tf->tf_out[4] = (register_t)catcher;
456 /* Fill siginfo structure. */
457 sf.sf_si.si_signo = sig;
458 sf.sf_si.si_code = code;
459 sf.sf_si.si_addr = (void *)tf->tf_sfar;
460
461 /* Copy the sigframe out to the user's stack. */
462 if (rwindow_save(td) != 0 || copyout(&sf, sfp, sizeof(*sfp)) != 0 ||
463 suword(&fp->fr_in[6], tf->tf_out[6]) != 0) {
464 /*
465 * Something is wrong with the stack pointer.
466 * ...Kill the process.
467 */
468 CTR2(KTR_SIG, "sendsig: sigexit td=%p sfp=%p", td, sfp);
469 PROC_LOCK(p);
470 sigexit(td, SIGILL);
471 /* NOTREACHED */
472 }
473
474 tf->tf_tpc = (u_long)p->p_md.md_sigtramp;
475 tf->tf_tnpc = tf->tf_tpc + 4;
476 tf->tf_sp = (u_long)fp - SPOFF;
477
478 CTR3(KTR_SIG, "sendsig: return td=%p pc=%#lx sp=%#lx", td, tf->tf_tpc,
479 tf->tf_sp);
480
481 PROC_LOCK(p);
482 mtx_lock(&psp->ps_mtx);
483 }
484
485 #ifndef _SYS_SYSPROTO_H_
486 struct sigreturn_args {
487 ucontext_t *ucp;
488 };
489 #endif
490
491 /*
492 * MPSAFE
493 */
494 int
495 sigreturn(struct thread *td, struct sigreturn_args *uap)
496 {
497 struct trapframe *tf;
498 struct proc *p;
499 mcontext_t *mc;
500 ucontext_t uc;
501
502 p = td->td_proc;
503 if (rwindow_save(td)) {
504 PROC_LOCK(p);
505 sigexit(td, SIGILL);
506 }
507
508 CTR2(KTR_SIG, "sigreturn: td=%p ucp=%p", td, uap->sigcntxp);
509 if (copyin(uap->sigcntxp, &uc, sizeof(uc)) != 0) {
510 CTR1(KTR_SIG, "sigreturn: efault td=%p", td);
511 return (EFAULT);
512 }
513
514 mc = &uc.uc_mcontext;
515 tf = td->td_frame;
516 if (!TSTATE_SECURE(mc->mc_tstate))
517 return (EINVAL);
518 mc->mc_wstate = tf->tf_wstate;
519 bcopy(mc, tf, sizeof(*tf));
520
521 PROC_LOCK(p);
522 td->td_sigmask = uc.uc_sigmask;
523 SIG_CANTMASK(td->td_sigmask);
524 signotify(td);
525 PROC_UNLOCK(p);
526
527 CTR4(KTR_SIG, "sigreturn: return td=%p pc=%#lx sp=%#lx tstate=%#lx",
528 td, tf->tf_tpc, tf->tf_sp, tf->tf_tstate);
529 return (EJUSTRETURN);
530 }
531
532 #ifdef COMPAT_FREEBSD4
533 int
534 freebsd4_sigreturn(struct thread *td, struct freebsd4_sigreturn_args *uap)
535 {
536
537 return sigreturn(td, (struct sigreturn_args *)uap);
538 }
539 #endif
540
541 int
542 get_mcontext(struct thread *td, mcontext_t *mc, int clear_ret)
543 {
544 struct trapframe *tf;
545 struct pcb *pcb;
546
547 tf = td->td_frame;
548 pcb = td->td_pcb;
549 bcopy(tf, mc, sizeof(*tf));
550 if (clear_ret != 0) {
551 mc->mc_out[0] = 0;
552 mc->mc_out[1] = 0;
553 }
554 mc->mc_flags = _MC_VERSION;
555 critical_enter();
556 if ((tf->tf_fprs & FPRS_FEF) != 0) {
557 savefpctx(pcb->pcb_ufp);
558 tf->tf_fprs &= ~FPRS_FEF;
559 pcb->pcb_flags |= PCB_FEF;
560 }
561 if ((pcb->pcb_flags & PCB_FEF) != 0) {
562 bcopy(pcb->pcb_ufp, mc->mc_fp, sizeof(mc->mc_fp));
563 mc->mc_fprs |= FPRS_FEF;
564 }
565 critical_exit();
566 return (0);
567 }
568
569 int
570 set_mcontext(struct thread *td, const mcontext_t *mc)
571 {
572 struct trapframe *tf;
573 struct pcb *pcb;
574 uint64_t wstate;
575
576 if (!TSTATE_SECURE(mc->mc_tstate) ||
577 (mc->mc_flags & ((1L << _MC_VERSION_BITS) - 1)) != _MC_VERSION)
578 return (EINVAL);
579 tf = td->td_frame;
580 pcb = td->td_pcb;
581 wstate = tf->tf_wstate;
582 bcopy(mc, tf, sizeof(*tf));
583 tf->tf_wstate = wstate;
584 if ((mc->mc_fprs & FPRS_FEF) != 0) {
585 tf->tf_fprs = 0;
586 bcopy(mc->mc_fp, pcb->pcb_ufp, sizeof(pcb->pcb_ufp));
587 pcb->pcb_flags |= PCB_FEF;
588 }
589 return (0);
590 }
591
592 /*
593 * Exit the kernel and execute a firmware call that will not return, as
594 * specified by the arguments.
595 */
596 void
597 cpu_shutdown(void *args)
598 {
599
600 #ifdef SMP
601 cpu_mp_shutdown();
602 #endif
603 openfirmware_exit(args);
604 }
605
606 /*
607 * Duplicate OF_exit() with a different firmware call function that restores
608 * the trap table, otherwise a RED state exception is triggered in at least
609 * some firmware versions.
610 */
611 void
612 cpu_halt(void)
613 {
614 static struct {
615 cell_t name;
616 cell_t nargs;
617 cell_t nreturns;
618 } args = {
619 (cell_t)"exit",
620 0,
621 0
622 };
623
624 cpu_shutdown(&args);
625 }
626
627 void
628 sparc64_shutdown_final(void *dummy, int howto)
629 {
630 static struct {
631 cell_t name;
632 cell_t nargs;
633 cell_t nreturns;
634 } args = {
635 (cell_t)"SUNW,power-off",
636 0,
637 0
638 };
639
640 /* Turn the power off? */
641 if ((howto & RB_POWEROFF) != 0)
642 cpu_shutdown(&args);
643 /* In case of halt, return to the firmware */
644 if ((howto & RB_HALT) != 0)
645 cpu_halt();
646 }
647
648 int
649 ptrace_set_pc(struct thread *td, u_long addr)
650 {
651
652 td->td_frame->tf_tpc = addr;
653 td->td_frame->tf_tnpc = addr + 4;
654 return (0);
655 }
656
657 int
658 ptrace_single_step(struct thread *td)
659 {
660 /* TODO; */
661 return (0);
662 }
663
664 void
665 exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
666 {
667 struct trapframe *tf;
668 struct md_utrap *ut;
669 struct pcb *pcb;
670 struct proc *p;
671 u_long sp;
672
673 /* XXX no cpu_exec */
674 p = td->td_proc;
675 p->p_md.md_sigtramp = NULL;
676 if ((ut = p->p_md.md_utrap) != NULL) {
677 ut->ut_refcnt--;
678 if (ut->ut_refcnt == 0)
679 free(ut, M_SUBPROC);
680 p->p_md.md_utrap = NULL;
681 }
682
683 pcb = td->td_pcb;
684 tf = td->td_frame;
685 sp = rounddown(stack, 16);
686 bzero(pcb, sizeof(*pcb));
687 bzero(tf, sizeof(*tf));
688 tf->tf_out[0] = stack;
689 tf->tf_out[3] = p->p_sysent->sv_psstrings;
690 tf->tf_out[6] = sp - SPOFF - sizeof(struct frame);
691 tf->tf_tnpc = entry + 4;
692 tf->tf_tpc = entry;
693 tf->tf_tstate = TSTATE_IE | TSTATE_PEF | TSTATE_MM_TSO;
694
695 td->td_retval[0] = tf->tf_out[0];
696 td->td_retval[1] = tf->tf_out[1];
697 }
698
699 void
700 Debugger(const char *msg)
701 {
702
703 printf("Debugger(\"%s\")\n", msg);
704 critical_enter();
705 breakpoint();
706 critical_exit();
707 }
708
709 int
710 fill_regs(struct thread *td, struct reg *regs)
711 {
712
713 bcopy(td->td_frame, regs, sizeof(*regs));
714 return (0);
715 }
716
717 int
718 set_regs(struct thread *td, struct reg *regs)
719 {
720 struct trapframe *tf;
721
722 if (!TSTATE_SECURE(regs->r_tstate))
723 return (EINVAL);
724 tf = td->td_frame;
725 regs->r_wstate = tf->tf_wstate;
726 bcopy(regs, tf, sizeof(*regs));
727 return (0);
728 }
729
730 int
731 fill_dbregs(struct thread *td, struct dbreg *dbregs)
732 {
733
734 return (ENOSYS);
735 }
736
737 int
738 set_dbregs(struct thread *td, struct dbreg *dbregs)
739 {
740
741 return (ENOSYS);
742 }
743
744 int
745 fill_fpregs(struct thread *td, struct fpreg *fpregs)
746 {
747 struct trapframe *tf;
748 struct pcb *pcb;
749
750 pcb = td->td_pcb;
751 tf = td->td_frame;
752 bcopy(pcb->pcb_ufp, fpregs->fr_regs, sizeof(fpregs->fr_regs));
753 fpregs->fr_fsr = tf->tf_fsr;
754 fpregs->fr_gsr = tf->tf_gsr;
755 return (0);
756 }
757
758 int
759 set_fpregs(struct thread *td, struct fpreg *fpregs)
760 {
761 struct trapframe *tf;
762 struct pcb *pcb;
763
764 pcb = td->td_pcb;
765 tf = td->td_frame;
766 tf->tf_fprs &= ~FPRS_FEF;
767 bcopy(fpregs->fr_regs, pcb->pcb_ufp, sizeof(pcb->pcb_ufp));
768 tf->tf_fsr = fpregs->fr_fsr;
769 tf->tf_gsr = fpregs->fr_gsr;
770 return (0);
771 }
Cache object: 4e881bbf534e3bd2dc1c0026ea068958
|