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