2 * Copyright (C) 2006 Semihalf, Marian Balakowicz <m8@semihalf.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Copyright (C) 2001 Benno Rice
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
40 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
41 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
43 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
45 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
46 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
47 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
48 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
49 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 * $NetBSD: machdep.c,v 1.74.2.1 2000/11/01 16:13:48 tv Exp $
53 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
54 * Copyright (C) 1995, 1996 TooLs GmbH.
55 * All rights reserved.
57 * Redistribution and use in source and binary forms, with or without
58 * modification, are permitted provided that the following conditions
60 * 1. Redistributions of source code must retain the above copyright
61 * notice, this list of conditions and the following disclaimer.
62 * 2. Redistributions in binary form must reproduce the above copyright
63 * notice, this list of conditions and the following disclaimer in the
64 * documentation and/or other materials provided with the distribution.
65 * 3. All advertising materials mentioning features or use of this software
66 * must display the following acknowledgement:
67 * This product includes software developed by TooLs GmbH.
68 * 4. The name of TooLs GmbH may not be used to endorse or promote products
69 * derived from this software without specific prior written permission.
71 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
72 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
73 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
74 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
75 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
76 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
77 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
78 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
79 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
80 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83 #include <sys/cdefs.h>
84 __FBSDID("$FreeBSD$");
86 #include "opt_compat.h"
87 #include "opt_kstack_pages.h"
89 #include <sys/cdefs.h>
90 #include <sys/types.h>
92 #include <sys/param.h>
94 #include <sys/systm.h>
102 #include <sys/kernel.h>
103 #include <sys/lock.h>
104 #include <sys/mutex.h>
105 #include <sys/sysctl.h>
106 #include <sys/exec.h>
108 #include <sys/sysproto.h>
109 #include <sys/signalvar.h>
110 #include <sys/sysent.h>
111 #include <sys/imgact.h>
112 #include <sys/msgbuf.h>
113 #include <sys/ptrace.h>
117 #include <vm/vm_page.h>
118 #include <vm/vm_object.h>
119 #include <vm/vm_pager.h>
121 #include <machine/cpu.h>
122 #include <machine/kdb.h>
123 #include <machine/reg.h>
124 #include <machine/vmparam.h>
125 #include <machine/spr.h>
126 #include <machine/hid.h>
127 #include <machine/psl.h>
128 #include <machine/trap.h>
129 #include <machine/md_var.h>
130 #include <machine/mmuvar.h>
131 #include <machine/pmap.h>
132 #include <machine/sigframe.h>
133 #include <machine/metadata.h>
134 #include <machine/bootinfo.h>
135 #include <machine/powerpc.h>
137 #include <sys/linker.h>
138 #include <sys/reboot.h>
141 #define debugf(fmt, args...) printf(fmt, ##args)
143 #define debugf(fmt, args...)
146 extern unsigned char kernel_text[];
147 extern unsigned char _etext[];
148 extern unsigned char _edata[];
149 extern unsigned char __bss_start[];
150 extern unsigned char __sbss_start[];
151 extern unsigned char __sbss_end[];
152 extern unsigned char _end[];
154 extern struct mem_region availmem_regions[];
155 extern int availmem_regions_sz;
157 extern void dcache_enable(void);
158 extern void dcache_inval(void);
159 extern void icache_enable(void);
160 extern void icache_inval(void);
162 struct kva_md_info kmi;
163 struct pcpu __pcpu[MAXCPU];
164 struct trapframe frame0;
169 struct bootinfo *bootinfo;
171 char machine[] = "powerpc";
172 SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, "");
174 int cacheline_size = 32;
176 SYSCTL_INT(_machdep, CPU_CACHELINE, cacheline_size,
177 CTLFLAG_RD, &cacheline_size, 0, "");
179 static void cpu_e500_startup(void *);
180 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_e500_startup, NULL);
182 void print_kernel_section_addr(void);
183 void dump_bootinfo(void);
184 void dump_kenv(void);
185 u_int e500_init(u_int32_t, u_int32_t, void *);
188 cpu_e500_startup(void *dummy)
192 /* Initialise the decrementer-based clock. */
195 /* Good {morning,afternoon,evening,night}. */
196 cpu_setup(PCPU_GET(cpuid));
198 printf("real memory = %ld (%ld MB)\n", ptoa(physmem),
199 ptoa(physmem) / 1048576);
202 /* Display any holes after the first chunk of extended memory. */
204 printf("Physical memory chunk(s):\n");
205 for (indx = 0; phys_avail[indx + 1] != 0; indx += 2) {
206 size = phys_avail[indx + 1] - phys_avail[indx];
207 printf("0x%08x - 0x%08x, %d bytes (%d pages)\n",
208 phys_avail[indx], phys_avail[indx + 1] - 1, size,
213 vm_ksubmap_init(&kmi);
215 printf("avail memory = %ld (%ld MB)\n", ptoa(cnt.v_free_count),
216 ptoa(cnt.v_free_count) / 1048576);
218 /* Set up buffers, so they can be used to read disk labels. */
220 vm_pager_bufferinit();
243 debugf("loader passed (static) kenv:\n");
244 if (kern_envp == NULL) {
245 debugf(" no env, null ptr\n");
248 debugf(" kern_envp = 0x%08x\n", (u_int32_t)kern_envp);
251 for (cp = kern_envp; cp != NULL; cp = kenv_next(cp))
252 debugf(" %x %s\n", (u_int32_t)cp, cp);
258 struct bi_mem_region *mr;
259 struct bi_eth_addr *eth;
262 debugf("bootinfo:\n");
263 if (bootinfo == NULL) {
264 debugf(" no bootinfo, null ptr\n");
268 debugf(" version = 0x%08x\n", bootinfo->bi_version);
269 debugf(" ccsrbar = 0x%08x\n", bootinfo->bi_bar_base);
270 debugf(" cpu_clk = 0x%08x\n", bootinfo->bi_cpu_clk);
271 debugf(" bus_clk = 0x%08x\n", bootinfo->bi_bus_clk);
273 debugf(" mem regions:\n");
274 mr = (struct bi_mem_region *)bootinfo->bi_data;
275 for (i = 0; i < bootinfo->bi_mem_reg_no; i++, mr++)
276 debugf(" #%d, base = 0x%08x, size = 0x%08x\n", i,
277 mr->mem_base, mr->mem_size);
279 debugf(" eth addresses:\n");
280 eth = (struct bi_eth_addr *)mr;
281 for (i = 0; i < bootinfo->bi_eth_addr_no; i++, eth++) {
282 debugf(" #%d, addr = ", i);
283 for (j = 0; j < 6; j++)
284 debugf("%02x ", eth->mac_addr[j]);
290 print_kernel_section_addr(void)
293 debugf("kernel image addresses:\n");
294 debugf(" kernel_text = 0x%08x\n", (u_int32_t)kernel_text);
295 debugf(" _etext (sdata) = 0x%08x\n", (u_int32_t)_etext);
296 debugf(" _edata = 0x%08x\n", (u_int32_t)_edata);
297 debugf(" __sbss_start = 0x%08x\n", (u_int32_t)__sbss_start);
298 debugf(" __sbss_end = 0x%08x\n", (u_int32_t)__sbss_end);
299 debugf(" __sbss_start = 0x%08x\n", (u_int32_t)__bss_start);
300 debugf(" _end = 0x%08x\n", (u_int32_t)_end);
303 struct bi_mem_region *
307 return((struct bi_mem_region *)bootinfo->bi_data);
313 struct bi_mem_region *mr;
314 struct bi_eth_addr *eth;
317 /* Advance to the eth section */
319 for (i = 0; i < bootinfo->bi_mem_reg_no; i++, mr++)
322 eth = (struct bi_eth_addr *)mr;
327 e500_init(u_int32_t startkernel, u_int32_t endkernel, void *mdp)
332 struct bi_mem_region *mr;
341 * Parse metadata and fetch parameters. This must be done as the first
342 * step as we need bootinfo data to at least init the console
345 preload_metadata = mdp;
346 kmdp = preload_search_by_type("elf kernel");
348 bootinfo = (struct bootinfo *)preload_search_info(kmdp,
349 MODINFO_METADATA|MODINFOMD_BOOTINFO);
351 boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
352 kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *);
353 end = MD_FETCH(kmdp, MODINFOMD_KERNEND, vm_offset_t);
357 * We should scream but how? - without CCSR bar (in bootinfo)
358 * cannot even output anything...
362 * FIXME add return value and handle in the locore so we can
363 * return to the loader maybe? (this seems not very easy to
364 * restore everything as the TLB have all been reprogrammed
365 * in the locore etc...)
370 /* Initialize memory regions table */
372 for (i = 0; i < bootinfo->bi_mem_reg_no; i++, mr++) {
373 if (i == MEM_REGIONS)
375 availmem_regions[i].mr_start = mr->mem_base;
376 availmem_regions[i].mr_size = mr->mem_size;
378 availmem_regions_sz = i;
380 /* Initialize TLB1 handling */
381 tlb1_init(bootinfo->bi_bar_base);
384 * Time Base and Decrementer are updated every 8 CCB bus clocks.
385 * HID0[SEL_TBCLK] = 0
387 decr_config(bootinfo->bi_bus_clk/8);
389 /* Init params/tunables that can be overridden by the loader. */
392 /* Start initializing proc0 and thread0. */
393 proc_linkup(&proc0, &thread0);
394 thread0.td_frame = &frame0;
396 /* Set up per-cpu data and store the pointer in SPR general 0. */
398 pcpu_init(pc, 0, sizeof(struct pcpu));
399 pc->pc_curthread = &thread0;
401 __asm __volatile("mtsprg 0, %0" :: "r"(pc));
403 /* Initialize system mutexes. */
406 /* Initialize the console before printing anything. */
409 /* Print out some debug info... */
410 debugf("e500_init: console initialized\n");
411 debugf(" arg1 startkernel = 0x%08x\n", startkernel);
412 debugf(" arg2 endkernel = 0x%08x\n", endkernel);
413 debugf(" arg3 midp = 0x%08x\n", (u_int32_t)mdp);
414 debugf(" end = 0x%08x\n", (u_int32_t)end);
415 debugf(" boothowto = 0x%08x\n", boothowto);
416 debugf(" kernel ccsrbar = 0x%08x\n", CCSRBAR_VA);
417 debugf(" MSR = 0x%08x\n", mfmsr());
419 print_kernel_section_addr();
421 //tlb1_print_entries();
422 //tlb1_print_tlbentries();
427 if (boothowto & RB_KDB)
428 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
432 /* Initialise virtual memory. */
433 pmap_mmu_install(MMU_TYPE_BOOKE, 0);
434 pmap_bootstrap(startkernel, end);
435 debugf("MSR = 0x%08x\n", mfmsr());
436 //tlb1_print_entries();
437 //tlb1_print_tlbentries();
439 /* Initialize params/tunables that are derived from memsize. */
440 init_param2(physmem);
442 /* Finish setting up thread0. */
443 thread0.td_pcb = (struct pcb *)
444 ((thread0.td_kstack + thread0.td_kstack_pages * PAGE_SIZE -
445 sizeof(struct pcb)) & ~15);
446 bzero((void *)thread0.td_pcb, sizeof(struct pcb));
447 pc->pc_curpcb = thread0.td_pcb;
449 /* Initialise the message buffer. */
450 msgbufinit(msgbufp, MSGBUF_SIZE);
452 /* Enable Machine Check interrupt. */
453 mtmsr(mfmsr() | PSL_ME);
456 /* Enable D-cache if applicable */
457 csr = mfspr(SPR_L1CSR0);
458 if ((csr & L1CSR0_DCE) == 0) {
462 csr = mfspr(SPR_L1CSR0);
463 if ((boothowto & RB_VERBOSE) != 0 || (csr & L1CSR0_DCE) == 0)
464 printf("L1 D-cache %sabled\n",
465 (csr & L1CSR0_DCE) ? "en" : "dis");
467 /* Enable L1 I-cache if applicable. */
468 csr = mfspr(SPR_L1CSR1);
469 if ((csr & L1CSR1_ICE) == 0) {
473 csr = mfspr(SPR_L1CSR1);
474 if ((boothowto & RB_VERBOSE) != 0 || (csr & L1CSR1_ICE) == 0)
475 printf("L1 I-cache %sabled\n",
476 (csr & L1CSR1_ICE) ? "en" : "dis");
478 debugf("e500_init: SP = 0x%08x\n", ((uintptr_t)thread0.td_pcb - 16) & ~15);
479 debugf("e500_init: e\n");
481 return (((uintptr_t)thread0.td_pcb - 16) & ~15);
484 /* Initialise a struct pcpu. */
486 cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t sz)
491 /* Set set up registers on exec. */
493 exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
495 struct trapframe *tf;
496 struct ps_strings arginfo;
499 bzero(tf, sizeof *tf);
500 tf->fixreg[1] = -roundup(-stack + 8, 16);
503 * XXX Machine-independent code has already copied arguments and
504 * XXX environment to userland. Get them back here.
506 (void)copyin((char *)PS_STRINGS, &arginfo, sizeof(arginfo));
509 * Set up arguments for _start():
510 * _start(argc, argv, envp, obj, cleanup, ps_strings);
513 * - obj and cleanup are the auxilliary and termination
514 * vectors. They are fixed up by ld.elf_so.
515 * - ps_strings is a NetBSD extention, and will be
516 * ignored by executables which are strictly
517 * compliant with the SVR4 ABI.
519 * XXX We have to set both regs and retval here due to different
520 * XXX calling convention in trap.c and init_main.c.
523 * XXX PG: these get overwritten in the syscall return code.
524 * execve() should return EJUSTRETURN, like it does on NetBSD.
525 * Emulate by setting the syscall return value cells. The
526 * registers still have to be set for init's fork trampoline.
528 td->td_retval[0] = arginfo.ps_nargvstr;
529 td->td_retval[1] = (register_t)arginfo.ps_argvstr;
530 tf->fixreg[3] = arginfo.ps_nargvstr;
531 tf->fixreg[4] = (register_t)arginfo.ps_argvstr;
532 tf->fixreg[5] = (register_t)arginfo.ps_envstr;
533 tf->fixreg[6] = 0; /* auxillary vector */
534 tf->fixreg[7] = 0; /* termination vector */
535 tf->fixreg[8] = (register_t)PS_STRINGS; /* NetBSD extension */
538 tf->srr1 = PSL_USERSET;
539 td->td_pcb->pcb_flags = 0;
543 fill_regs(struct thread *td, struct reg *regs)
545 struct trapframe *tf;
548 memcpy(regs, tf, sizeof(struct reg));
554 fill_fpregs(struct thread *td, struct fpreg *fpregs)
560 /* Get current clock frequency for the given cpu id. */
562 cpu_est_clockrate(int cpu_id, uint64_t *rate)
569 * Construct a PCB from a trapframe. This is called from kdb_trap() where
570 * we want to start a backtrace from the function that caused us to enter
571 * the debugger. We have the context in the trapframe, but base the trace
572 * on the PCB. The PCB doesn't have to be perfect, as long as it contains
573 * enough for a backtrace.
576 makectx(struct trapframe *tf, struct pcb *pcb)
579 pcb->pcb_lr = tf->srr0;
580 pcb->pcb_sp = tf->fixreg[1];
584 * get_mcontext/sendsig helper routine that doesn't touch the
588 grab_mcontext(struct thread *td, mcontext_t *mcp, int flags)
593 memset(mcp, 0, sizeof(mcontext_t));
595 mcp->mc_vers = _MC_VERSION;
597 memcpy(&mcp->mc_frame, td->td_frame, sizeof(struct trapframe));
598 if (flags & GET_MC_CLEAR_RET) {
603 /* XXX Altivec context ? */
605 mcp->mc_len = sizeof(*mcp);
610 get_mcontext(struct thread *td, mcontext_t *mcp, int flags)
614 error = grab_mcontext(td, mcp, flags);
616 PROC_LOCK(curthread->td_proc);
617 mcp->mc_onstack = sigonstack(td->td_frame->fixreg[1]);
618 PROC_UNLOCK(curthread->td_proc);
625 set_mcontext(struct thread *td, const mcontext_t *mcp)
628 struct trapframe *tf;
633 if (mcp->mc_vers != _MC_VERSION || mcp->mc_len != sizeof(*mcp))
636 memcpy(tf, mcp->mc_frame, sizeof(mcp->mc_frame));
638 /* XXX Altivec context? */
644 sigreturn(struct thread *td, struct sigreturn_args *uap)
650 CTR2(KTR_SIG, "sigreturn: td=%p ucp=%p", td, uap->sigcntxp);
652 if (copyin(uap->sigcntxp, &uc, sizeof(uc)) != 0) {
653 CTR1(KTR_SIG, "sigreturn: efault td=%p", td);
657 error = set_mcontext(td, &uc.uc_mcontext);
663 td->td_sigmask = uc.uc_sigmask;
664 SIG_CANTMASK(td->td_sigmask);
668 CTR3(KTR_SIG, "sigreturn: return td=%p pc=%#x sp=%#x",
669 td, uc.uc_mcontext.mc_srr0, uc.uc_mcontext.mc_gpr[1]);
671 return (EJUSTRETURN);
674 #ifdef COMPAT_FREEBSD4
676 freebsd4_sigreturn(struct thread *td, struct freebsd4_sigreturn_args *uap)
679 return sigreturn(td, (struct sigreturn_args *)uap);
686 * Set Wait state enable.
695 if ((msr & PSL_EE) != PSL_EE) {
696 struct thread *td = curthread;
697 printf("td msr %x\n", td->td_md.md_saved_msr);
698 panic("ints disabled in idleproc!");
703 * Freescale E500 core RM section 6.4.1
717 cpu_idle_wakeup(int cpu)
729 if (td->td_md.md_spinlock_count == 0)
730 td->td_md.md_saved_msr = intr_disable();
731 td->td_md.md_spinlock_count++;
742 td->td_md.md_spinlock_count--;
743 if (td->td_md.md_spinlock_count == 0)
744 intr_restore(td->td_md.md_saved_msr);
747 /* Shutdown the CPU as much as possible. */
752 mtmsr(mfmsr() & ~(PSL_CE | PSL_EE | PSL_ME | PSL_DE));
757 set_regs(struct thread *td, struct reg *regs)
759 struct trapframe *tf;
762 memcpy(tf, regs, sizeof(struct reg));
767 fill_dbregs(struct thread *td, struct dbreg *dbregs)
770 /* No debug registers on PowerPC */
775 set_dbregs(struct thread *td, struct dbreg *dbregs)
778 /* No debug registers on PowerPC */
783 set_fpregs(struct thread *td, struct fpreg *fpregs)
790 ptrace_set_pc(struct thread *td, unsigned long addr)
792 struct trapframe *tf;
795 tf->srr0 = (register_t)addr;
801 ptrace_single_step(struct thread *td)
803 struct trapframe *tf;
806 reg = mfspr(SPR_DBCR0);
807 reg |= DBCR0_IC | DBCR0_IDM;
808 mtspr(SPR_DBCR0, reg);
816 ptrace_clear_single_step(struct thread *td)
818 struct trapframe *tf;
826 kdb_cpu_clear_singlestep(void)
830 r = mfspr(SPR_DBCR0);
831 mtspr(SPR_DBCR0, r & ~DBCR0_IC);
832 kdb_frame->srr1 &= ~PSL_DE;
836 kdb_cpu_set_singlestep(void)
840 r = mfspr(SPR_DBCR0);
841 mtspr(SPR_DBCR0, r | DBCR0_IC | DBCR0_IDM);
842 kdb_frame->srr1 |= PSL_DE;
846 sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
848 struct trapframe *tf;
849 struct sigframe *sfp;
854 int oonstack, rndfsize;
859 PROC_LOCK_ASSERT(p, MA_OWNED);
860 sig = ksi->ksi_signo;
861 code = ksi->ksi_code;
863 mtx_assert(&psp->ps_mtx, MA_OWNED);
865 oonstack = sigonstack(tf->fixreg[1]);
867 rndfsize = ((sizeof(sf) + 15) / 16) * 16;
869 CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm,
875 memset(&sf, 0, sizeof(sf));
876 grab_mcontext(td, &sf.sf_uc.uc_mcontext, 0);
877 sf.sf_uc.uc_sigmask = *mask;
878 sf.sf_uc.uc_stack = td->td_sigstk;
879 sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
880 ? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
882 sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
885 * Allocate and validate space for the signal handler context.
887 if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
888 SIGISMEMBER(psp->ps_sigonstack, sig)) {
889 sfp = (struct sigframe *)((caddr_t)td->td_sigstk.ss_sp +
890 td->td_sigstk.ss_size - rndfsize);
892 sfp = (struct sigframe *)(tf->fixreg[1] - rndfsize);
896 * Translate the signal if appropriate (Linux emu ?)
898 if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
899 sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
902 * Save the floating-point state, if necessary, then copy it.
907 * Set up the registers to return to sigcode.
909 * r1/sp - sigframe ptr
910 * lr - sig function, dispatched to by blrl in trampoline
912 * r4 - SIGINFO ? &siginfo : exception code
914 * srr0 - trampoline function addr
916 tf->lr = (register_t)catcher;
917 tf->fixreg[1] = (register_t)sfp;
918 tf->fixreg[FIRSTARG] = sig;
919 tf->fixreg[FIRSTARG+2] = (register_t)&sfp->sf_uc;
920 if (SIGISMEMBER(psp->ps_siginfo, sig)) {
922 * Signal handler installed with SA_SIGINFO.
924 tf->fixreg[FIRSTARG+1] = (register_t)&sfp->sf_si;
927 * Fill siginfo structure.
929 sf.sf_si = ksi->ksi_info;
930 sf.sf_si.si_signo = sig;
931 sf.sf_si.si_addr = (void *) ((tf->exc == EXC_DSI) ?
932 tf->cpu.booke.dear : tf->srr0);
934 /* Old FreeBSD-style arguments. */
935 tf->fixreg[FIRSTARG+1] = code;
936 tf->fixreg[FIRSTARG+3] = (tf->exc == EXC_DSI) ?
937 tf->cpu.booke.dear : tf->srr0;
939 mtx_unlock(&psp->ps_mtx);
942 tf->srr0 = (register_t)(PS_STRINGS - *(p->p_sysent->sv_szsigcode));
945 * copy the frame out to userland.
947 if (copyout((caddr_t)&sf, (caddr_t)sfp, sizeof(sf)) != 0) {
949 * Process has trashed its stack. Kill it.
951 CTR2(KTR_SIG, "sendsig: sigexit td=%p sfp=%p", td, sfp);
956 CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td,
957 tf->srr0, tf->fixreg[1]);
960 mtx_lock(&psp->ps_mtx);
964 bzero(void *buf, size_t len)
970 while (((vm_offset_t) p & (sizeof(u_long) - 1)) && len) {
975 while (len >= sizeof(u_long) * 8) {
977 *((u_long*) p + 1) = 0;
978 *((u_long*) p + 2) = 0;
979 *((u_long*) p + 3) = 0;
980 len -= sizeof(u_long) * 8;
981 *((u_long*) p + 4) = 0;
982 *((u_long*) p + 5) = 0;
983 *((u_long*) p + 6) = 0;
984 *((u_long*) p + 7) = 0;
985 p += sizeof(u_long) * 8;
988 while (len >= sizeof(u_long)) {
990 len -= sizeof(u_long);
1001 * XXX what is the better/proper place for this routine?
1004 mem_valid(vm_offset_t addr, int len)