The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sparc64/sparc64/machdep.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: facd6a20c31c355387181b0dec3a8321


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.