]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/mips/mips/vm_machdep.c
Merge llvm, clang, lld, lldb, compiler-rt and libc++ trunk r321545,
[FreeBSD/FreeBSD.git] / sys / mips / mips / vm_machdep.c
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1982, 1986 The Regents of the University of California.
5  * Copyright (c) 1989, 1990 William Jolitz
6  * Copyright (c) 1994 John Dyson
7  * All rights reserved.
8  *
9  * This code is derived from software contributed to Berkeley by
10  * the Systems Programming Group of the University of Utah Computer
11  * Science Department, and William Jolitz.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *      from: @(#)vm_machdep.c  7.3 (Berkeley) 5/13/91
38  *      Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
39  *      from: src/sys/i386/i386/vm_machdep.c,v 1.132.2.2 2000/08/26 04:19:26 yokota
40  *      JNPR: vm_machdep.c,v 1.8.2.2 2007/08/16 15:59:17 girish
41  */
42
43 #include <sys/cdefs.h>
44 __FBSDID("$FreeBSD$");
45
46 #include "opt_compat.h"
47 #include "opt_ddb.h"
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/malloc.h>
52 #include <sys/proc.h>
53 #include <sys/syscall.h>
54 #include <sys/sysent.h>
55 #include <sys/buf.h>
56 #include <sys/vnode.h>
57 #include <sys/vmmeter.h>
58 #include <sys/kernel.h>
59 #include <sys/sysctl.h>
60 #include <sys/unistd.h>
61
62 #include <machine/cache.h>
63 #include <machine/clock.h>
64 #include <machine/cpu.h>
65 #include <machine/cpufunc.h>
66 #include <machine/cpuinfo.h>
67 #include <machine/md_var.h>
68 #include <machine/pcb.h>
69 #include <machine/tls.h>
70
71 #include <vm/vm.h>
72 #include <vm/vm_extern.h>
73 #include <vm/pmap.h>
74 #include <vm/vm_kern.h>
75 #include <vm/vm_map.h>
76 #include <vm/vm_page.h>
77 #include <vm/vm_pageout.h>
78 #include <vm/vm_param.h>
79 #include <vm/uma.h>
80 #include <vm/uma_int.h>
81
82 #include <sys/user.h>
83 #include <sys/mbuf.h>
84
85 /* Duplicated from asm.h */
86 #if defined(__mips_o32)
87 #define SZREG   4
88 #else
89 #define SZREG   8
90 #endif
91 #if defined(__mips_o32) || defined(__mips_o64)
92 #define CALLFRAME_SIZ   (SZREG * (4 + 2))
93 #elif defined(__mips_n32) || defined(__mips_n64)
94 #define CALLFRAME_SIZ   (SZREG * 4)
95 #endif
96
97 /*
98  * Finish a fork operation, with process p2 nearly set up.
99  * Copy and update the pcb, set up the stack so that the child
100  * ready to run and return to user mode.
101  */
102 void
103 cpu_fork(struct thread *td1, struct proc *p2, struct thread *td2,int flags)
104 {
105         struct proc *p1;
106         struct pcb *pcb2;
107
108         p1 = td1->td_proc;
109         if ((flags & RFPROC) == 0)
110                 return;
111         /* It is assumed that the vm_thread_alloc called
112          * cpu_thread_alloc() before cpu_fork is called.
113          */
114
115         /* Point the pcb to the top of the stack */
116         pcb2 = td2->td_pcb;
117
118         /* Copy p1's pcb, note that in this case
119          * our pcb also includes the td_frame being copied
120          * too. The older mips2 code did an additional copy
121          * of the td_frame, for us that's not needed any
122          * longer (this copy does them both) 
123          */
124         bcopy(td1->td_pcb, pcb2, sizeof(*pcb2));
125
126         /* Point mdproc and then copy over td1's contents
127          * md_proc is empty for MIPS
128          */
129         td2->td_md.md_flags = td1->td_md.md_flags & MDTD_FPUSED;
130
131         /*
132          * Set up return-value registers as fork() libc stub expects.
133          */
134         td2->td_frame->v0 = 0;
135         td2->td_frame->v1 = 1;
136         td2->td_frame->a3 = 0;
137
138         if (td1 == PCPU_GET(fpcurthread))
139                 MipsSaveCurFPState(td1);
140
141         pcb2->pcb_context[PCB_REG_RA] = (register_t)(intptr_t)fork_trampoline;
142         /* Make sp 64-bit aligned */
143         pcb2->pcb_context[PCB_REG_SP] = (register_t)(((vm_offset_t)td2->td_pcb &
144             ~(sizeof(__int64_t) - 1)) - CALLFRAME_SIZ);
145         pcb2->pcb_context[PCB_REG_S0] = (register_t)(intptr_t)fork_return;
146         pcb2->pcb_context[PCB_REG_S1] = (register_t)(intptr_t)td2;
147         pcb2->pcb_context[PCB_REG_S2] = (register_t)(intptr_t)td2->td_frame;
148         pcb2->pcb_context[PCB_REG_SR] = mips_rd_status() &
149             (MIPS_SR_KX | MIPS_SR_UX | MIPS_SR_INT_MASK);
150         /*
151          * FREEBSD_DEVELOPERS_FIXME:
152          * Setup any other CPU-Specific registers (Not MIPS Standard)
153          * and/or bits in other standard MIPS registers (if CPU-Specific)
154          *  that are needed.
155          */
156
157         td2->td_md.md_tls = td1->td_md.md_tls;
158         td2->td_md.md_tls_tcb_offset = td1->td_md.md_tls_tcb_offset;
159         td2->td_md.md_saved_intr = MIPS_SR_INT_IE;
160         td2->td_md.md_spinlock_count = 1;
161 #ifdef CPU_CNMIPS
162         if (td1->td_md.md_flags & MDTD_COP2USED) {
163                 if (td1->td_md.md_cop2owner == COP2_OWNER_USERLAND) {
164                         if (td1->td_md.md_ucop2)
165                                 octeon_cop2_save(td1->td_md.md_ucop2);
166                         else
167                                 panic("cpu_fork: ucop2 is NULL but COP2 is enabled");
168                 }
169                 else {
170                         if (td1->td_md.md_cop2)
171                                 octeon_cop2_save(td1->td_md.md_cop2);
172                         else
173                                 panic("cpu_fork: cop2 is NULL but COP2 is enabled");
174                 }
175         }
176
177         if (td1->td_md.md_cop2) {
178                 td2->td_md.md_cop2 = octeon_cop2_alloc_ctx();
179                 memcpy(td2->td_md.md_cop2, td1->td_md.md_cop2, 
180                         sizeof(*td1->td_md.md_cop2));
181         }
182         if (td1->td_md.md_ucop2) {
183                 td2->td_md.md_ucop2 = octeon_cop2_alloc_ctx();
184                 memcpy(td2->td_md.md_ucop2, td1->td_md.md_ucop2, 
185                         sizeof(*td1->td_md.md_ucop2));
186         }
187         td2->td_md.md_cop2owner = td1->td_md.md_cop2owner;
188         pcb2->pcb_context[PCB_REG_SR] |= MIPS_SR_PX | MIPS_SR_UX | MIPS_SR_KX | MIPS_SR_SX;
189         /* Clear COP2 bits for userland & kernel */
190         td2->td_frame->sr &= ~MIPS_SR_COP_2_BIT;
191         pcb2->pcb_context[PCB_REG_SR] &= ~MIPS_SR_COP_2_BIT;
192 #endif
193 }
194
195 /*
196  * Intercept the return address from a freshly forked process that has NOT
197  * been scheduled yet.
198  *
199  * This is needed to make kernel threads stay in kernel mode.
200  */
201 void
202 cpu_fork_kthread_handler(struct thread *td, void (*func)(void *), void *arg)
203 {
204         /*
205          * Note that the trap frame follows the args, so the function
206          * is really called like this:  func(arg, frame);
207          */
208         td->td_pcb->pcb_context[PCB_REG_S0] = (register_t)(intptr_t)func;
209         td->td_pcb->pcb_context[PCB_REG_S1] = (register_t)(intptr_t)arg;
210 }
211
212 void
213 cpu_exit(struct thread *td)
214 {
215 }
216
217 void
218 cpu_thread_exit(struct thread *td)
219 {
220
221         if (PCPU_GET(fpcurthread) == td)
222                 PCPU_GET(fpcurthread) = (struct thread *)0;
223 #ifdef  CPU_CNMIPS
224         if (td->td_md.md_cop2)
225                 memset(td->td_md.md_cop2, 0,
226                         sizeof(*td->td_md.md_cop2));
227         if (td->td_md.md_ucop2)
228                 memset(td->td_md.md_ucop2, 0,
229                         sizeof(*td->td_md.md_ucop2));
230 #endif
231 }
232
233 void
234 cpu_thread_free(struct thread *td)
235 {
236 #ifdef  CPU_CNMIPS
237         if (td->td_md.md_cop2)
238                 octeon_cop2_free_ctx(td->td_md.md_cop2);
239         if (td->td_md.md_ucop2)
240                 octeon_cop2_free_ctx(td->td_md.md_ucop2);
241         td->td_md.md_cop2 = NULL;
242         td->td_md.md_ucop2 = NULL;
243 #endif
244 }
245
246 void
247 cpu_thread_clean(struct thread *td)
248 {
249 }
250
251 void
252 cpu_thread_swapin(struct thread *td)
253 {
254         pt_entry_t *pte;
255         int i;
256
257         /*
258          * The kstack may be at a different physical address now.
259          * Cache the PTEs for the Kernel stack in the machine dependent
260          * part of the thread struct so cpu_switch() can quickly map in
261          * the pcb struct and kernel stack.
262          */
263         for (i = 0; i < KSTACK_PAGES; i++) {
264                 pte = pmap_pte(kernel_pmap, td->td_kstack + i * PAGE_SIZE);
265                 td->td_md.md_upte[i] = *pte & ~TLBLO_SWBITS_MASK;
266         }
267 }
268
269 void
270 cpu_thread_swapout(struct thread *td)
271 {
272 }
273
274 void
275 cpu_thread_alloc(struct thread *td)
276 {
277         pt_entry_t *pte;
278         int i;
279
280         KASSERT((td->td_kstack & (1 << PAGE_SHIFT)) == 0, ("kernel stack must be aligned."));
281         td->td_pcb = (struct pcb *)(td->td_kstack +
282             td->td_kstack_pages * PAGE_SIZE) - 1;
283         td->td_frame = &td->td_pcb->pcb_regs;
284
285         for (i = 0; i < KSTACK_PAGES; i++) {
286                 pte = pmap_pte(kernel_pmap, td->td_kstack + i * PAGE_SIZE);
287                 td->td_md.md_upte[i] = *pte & ~TLBLO_SWBITS_MASK;
288         }
289 }
290
291 void
292 cpu_set_syscall_retval(struct thread *td, int error)
293 {
294         struct trapframe *locr0 = td->td_frame;
295         unsigned int code;
296         int quad_syscall;
297
298         code = locr0->v0;
299         quad_syscall = 0;
300 #if defined(__mips_n32) || defined(__mips_n64)
301 #ifdef COMPAT_FREEBSD32
302         if (code == SYS___syscall && SV_PROC_FLAG(td->td_proc, SV_ILP32))
303                 quad_syscall = 1;
304 #endif
305 #else
306         if (code == SYS___syscall)
307                 quad_syscall = 1;
308 #endif
309
310         if (code == SYS_syscall)
311                 code = locr0->a0;
312         else if (code == SYS___syscall) {
313                 if (quad_syscall)
314                         code = _QUAD_LOWWORD ? locr0->a1 : locr0->a0;
315                 else
316                         code = locr0->a0;
317         }
318
319         switch (error) {
320         case 0:
321                 if (quad_syscall && code != SYS_lseek) {
322                         /*
323                          * System call invoked through the
324                          * SYS___syscall interface but the
325                          * return value is really just 32
326                          * bits.
327                          */
328                         locr0->v0 = td->td_retval[0];
329                         if (_QUAD_LOWWORD)
330                                 locr0->v1 = td->td_retval[0];
331                         locr0->a3 = 0;
332                 } else {
333                         locr0->v0 = td->td_retval[0];
334                         locr0->v1 = td->td_retval[1];
335                         locr0->a3 = 0;
336                 }
337                 break;
338
339         case ERESTART:
340                 locr0->pc = td->td_pcb->pcb_tpc;
341                 break;
342
343         case EJUSTRETURN:
344                 break;  /* nothing to do */
345
346         default:
347                 if (quad_syscall && code != SYS_lseek) {
348                         locr0->v0 = error;
349                         if (_QUAD_LOWWORD)
350                                 locr0->v1 = error;
351                         locr0->a3 = 1;
352                 } else {
353                         locr0->v0 = error;
354                         locr0->a3 = 1;
355                 }
356         }
357 }
358
359 /*
360  * Initialize machine state, mostly pcb and trap frame for a new
361  * thread, about to return to userspace.  Put enough state in the new
362  * thread's PCB to get it to go back to the fork_return(), which
363  * finalizes the thread state and handles peculiarities of the first
364  * return to userspace for the new thread.
365  */
366 void
367 cpu_copy_thread(struct thread *td, struct thread *td0)
368 {
369         struct pcb *pcb2;
370
371         /* Point the pcb to the top of the stack. */
372         pcb2 = td->td_pcb;
373
374         /*
375          * Copy the upcall pcb.  This loads kernel regs.
376          * Those not loaded individually below get their default
377          * values here.
378          *
379          * XXXKSE It might be a good idea to simply skip this as
380          * the values of the other registers may be unimportant.
381          * This would remove any requirement for knowing the KSE
382          * at this time (see the matching comment below for
383          * more analysis) (need a good safe default).
384          * In MIPS, the trapframe is the first element of the PCB
385          * and gets copied when we copy the PCB. No separate copy
386          * is needed.
387          */
388         bcopy(td0->td_pcb, pcb2, sizeof(*pcb2));
389
390         /*
391          * Set registers for trampoline to user mode.
392          */
393
394         pcb2->pcb_context[PCB_REG_RA] = (register_t)(intptr_t)fork_trampoline;
395         /* Make sp 64-bit aligned */
396         pcb2->pcb_context[PCB_REG_SP] = (register_t)(((vm_offset_t)td->td_pcb &
397             ~(sizeof(__int64_t) - 1)) - CALLFRAME_SIZ);
398         pcb2->pcb_context[PCB_REG_S0] = (register_t)(intptr_t)fork_return;
399         pcb2->pcb_context[PCB_REG_S1] = (register_t)(intptr_t)td;
400         pcb2->pcb_context[PCB_REG_S2] = (register_t)(intptr_t)td->td_frame;
401         /* Dont set IE bit in SR. sched lock release will take care of it */
402         pcb2->pcb_context[PCB_REG_SR] = mips_rd_status() &
403             (MIPS_SR_PX | MIPS_SR_KX | MIPS_SR_UX | MIPS_SR_INT_MASK);
404
405         /*
406          * FREEBSD_DEVELOPERS_FIXME:
407          * Setup any other CPU-Specific registers (Not MIPS Standard)
408          * that are needed.
409          */
410
411         /* Setup to release spin count in in fork_exit(). */
412         td->td_md.md_spinlock_count = 1;
413         td->td_md.md_saved_intr = MIPS_SR_INT_IE;
414 #if 0
415             /* Maybe we need to fix this? */
416         td->td_md.md_saved_sr = ( (MIPS_SR_COP_2_BIT | MIPS_SR_COP_0_BIT) |
417                                   (MIPS_SR_PX | MIPS_SR_UX | MIPS_SR_KX | MIPS_SR_SX) |
418                                   (MIPS_SR_INT_IE | MIPS_HARD_INT_MASK));
419 #endif
420 }
421
422 /*
423  * Set that machine state for performing an upcall that starts
424  * the entry function with the given argument.
425  */
426 void
427 cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg,
428     stack_t *stack)
429 {
430         struct trapframe *tf;
431         register_t sp;
432
433         /*
434          * At the point where a function is called, sp must be 8
435          * byte aligned[for compatibility with 64-bit CPUs]
436          * in ``See MIPS Run'' by D. Sweetman, p. 269
437          * align stack
438          */
439         sp = (((intptr_t)stack->ss_sp + stack->ss_size) & ~0x7) -
440             CALLFRAME_SIZ;
441
442         /*
443          * Set the trap frame to point at the beginning of the uts
444          * function.
445          */
446         tf = td->td_frame;
447         bzero(tf, sizeof(struct trapframe));
448         tf->sp = sp;
449         tf->pc = (register_t)(intptr_t)entry;
450         /* 
451          * MIPS ABI requires T9 to be the same as PC 
452          * in subroutine entry point
453          */
454         tf->t9 = (register_t)(intptr_t)entry; 
455         tf->a0 = (register_t)(intptr_t)arg;
456
457         /*
458          * Keep interrupt mask
459          */
460         td->td_frame->sr = MIPS_SR_KSU_USER | MIPS_SR_EXL | MIPS_SR_INT_IE |
461             (mips_rd_status() & MIPS_SR_INT_MASK);
462 #if defined(__mips_n32) 
463         td->td_frame->sr |= MIPS_SR_PX;
464 #elif  defined(__mips_n64)
465         td->td_frame->sr |= MIPS_SR_PX | MIPS_SR_UX | MIPS_SR_KX;
466 #endif
467 /*      tf->sr |= (ALL_INT_MASK & idle_mask) | SR_INT_ENAB; */
468         /**XXX the above may now be wrong -- mips2 implements this as panic */
469         /*
470          * FREEBSD_DEVELOPERS_FIXME:
471          * Setup any other CPU-Specific registers (Not MIPS Standard)
472          * that are needed.
473          */
474 }
475
476 /*
477  * Implement the pre-zeroed page mechanism.
478  * This routine is called from the idle loop.
479  */
480
481 #define ZIDLE_LO(v)     ((v) * 2 / 3)
482 #define ZIDLE_HI(v)     ((v) * 4 / 5)
483
484 /*
485  * Software interrupt handler for queued VM system processing.
486  */
487 void
488 swi_vm(void *dummy)
489 {
490
491         if (busdma_swi_pending)
492                 busdma_swi();
493 }
494
495 int
496 cpu_set_user_tls(struct thread *td, void *tls_base)
497 {
498
499 #if defined(__mips_n64) && defined(COMPAT_FREEBSD32)
500         if (td->td_proc && SV_PROC_FLAG(td->td_proc, SV_ILP32))
501                 td->td_md.md_tls_tcb_offset = TLS_TP_OFFSET + TLS_TCB_SIZE32;
502         else
503 #endif
504         td->td_md.md_tls_tcb_offset = TLS_TP_OFFSET + TLS_TCB_SIZE;
505         td->td_md.md_tls = (char*)tls_base;
506         if (td == curthread && cpuinfo.userlocal_reg == true) {
507                 mips_wr_userlocal((unsigned long)tls_base +
508                     td->td_md.md_tls_tcb_offset);
509         }
510
511         return (0);
512 }
513
514 #ifdef DDB
515 #include <ddb/ddb.h>
516
517 #define DB_PRINT_REG(ptr, regname)                      \
518         db_printf("  %-12s %p\n", #regname, (void *)(intptr_t)((ptr)->regname))
519
520 #define DB_PRINT_REG_ARRAY(ptr, arrname, regname)       \
521         db_printf("  %-12s %p\n", #regname, (void *)(intptr_t)((ptr)->arrname[regname]))
522
523 static void
524 dump_trapframe(struct trapframe *trapframe)
525 {
526
527         db_printf("Trapframe at %p\n", trapframe);
528
529         DB_PRINT_REG(trapframe, zero);
530         DB_PRINT_REG(trapframe, ast);
531         DB_PRINT_REG(trapframe, v0);
532         DB_PRINT_REG(trapframe, v1);
533         DB_PRINT_REG(trapframe, a0);
534         DB_PRINT_REG(trapframe, a1);
535         DB_PRINT_REG(trapframe, a2);
536         DB_PRINT_REG(trapframe, a3);
537 #if defined(__mips_n32) || defined(__mips_n64)
538         DB_PRINT_REG(trapframe, a4);
539         DB_PRINT_REG(trapframe, a5);
540         DB_PRINT_REG(trapframe, a6);
541         DB_PRINT_REG(trapframe, a7);
542         DB_PRINT_REG(trapframe, t0);
543         DB_PRINT_REG(trapframe, t1);
544         DB_PRINT_REG(trapframe, t2);
545         DB_PRINT_REG(trapframe, t3);
546 #else
547         DB_PRINT_REG(trapframe, t0);
548         DB_PRINT_REG(trapframe, t1);
549         DB_PRINT_REG(trapframe, t2);
550         DB_PRINT_REG(trapframe, t3);
551         DB_PRINT_REG(trapframe, t4);
552         DB_PRINT_REG(trapframe, t5);
553         DB_PRINT_REG(trapframe, t6);
554         DB_PRINT_REG(trapframe, t7);
555 #endif
556         DB_PRINT_REG(trapframe, s0);
557         DB_PRINT_REG(trapframe, s1);
558         DB_PRINT_REG(trapframe, s2);
559         DB_PRINT_REG(trapframe, s3);
560         DB_PRINT_REG(trapframe, s4);
561         DB_PRINT_REG(trapframe, s5);
562         DB_PRINT_REG(trapframe, s6);
563         DB_PRINT_REG(trapframe, s7);
564         DB_PRINT_REG(trapframe, t8);
565         DB_PRINT_REG(trapframe, t9);
566         DB_PRINT_REG(trapframe, k0);
567         DB_PRINT_REG(trapframe, k1);
568         DB_PRINT_REG(trapframe, gp);
569         DB_PRINT_REG(trapframe, sp);
570         DB_PRINT_REG(trapframe, s8);
571         DB_PRINT_REG(trapframe, ra);
572         DB_PRINT_REG(trapframe, sr);
573         DB_PRINT_REG(trapframe, mullo);
574         DB_PRINT_REG(trapframe, mulhi);
575         DB_PRINT_REG(trapframe, badvaddr);
576         DB_PRINT_REG(trapframe, cause);
577         DB_PRINT_REG(trapframe, pc);
578 }
579
580 DB_SHOW_COMMAND(pcb, ddb_dump_pcb)
581 {
582         struct thread *td;
583         struct pcb *pcb;
584         struct trapframe *trapframe;
585
586         /* Determine which thread to examine. */
587         if (have_addr)
588                 td = db_lookup_thread(addr, true);
589         else
590                 td = curthread;
591         
592         pcb = td->td_pcb;
593
594         db_printf("Thread %d at %p\n", td->td_tid, td);
595
596         db_printf("PCB at %p\n", pcb);
597
598         trapframe = &pcb->pcb_regs;
599         dump_trapframe(trapframe);
600
601         db_printf("PCB Context:\n");
602         DB_PRINT_REG_ARRAY(pcb, pcb_context, PCB_REG_S0);
603         DB_PRINT_REG_ARRAY(pcb, pcb_context, PCB_REG_S1);
604         DB_PRINT_REG_ARRAY(pcb, pcb_context, PCB_REG_S2);
605         DB_PRINT_REG_ARRAY(pcb, pcb_context, PCB_REG_S3);
606         DB_PRINT_REG_ARRAY(pcb, pcb_context, PCB_REG_S4);
607         DB_PRINT_REG_ARRAY(pcb, pcb_context, PCB_REG_S5);
608         DB_PRINT_REG_ARRAY(pcb, pcb_context, PCB_REG_S6);
609         DB_PRINT_REG_ARRAY(pcb, pcb_context, PCB_REG_S7);
610         DB_PRINT_REG_ARRAY(pcb, pcb_context, PCB_REG_SP);
611         DB_PRINT_REG_ARRAY(pcb, pcb_context, PCB_REG_S8);
612         DB_PRINT_REG_ARRAY(pcb, pcb_context, PCB_REG_RA);
613         DB_PRINT_REG_ARRAY(pcb, pcb_context, PCB_REG_SR);
614         DB_PRINT_REG_ARRAY(pcb, pcb_context, PCB_REG_GP);
615         DB_PRINT_REG_ARRAY(pcb, pcb_context, PCB_REG_PC);
616
617         db_printf("PCB onfault = %p\n", pcb->pcb_onfault);
618         db_printf("md_saved_intr = 0x%0lx\n", (long)td->td_md.md_saved_intr);
619         db_printf("md_spinlock_count = %d\n", td->td_md.md_spinlock_count);
620
621         if (td->td_frame != trapframe) {
622                 db_printf("td->td_frame %p is not the same as pcb_regs %p\n",
623                           td->td_frame, trapframe);
624         }
625 }
626
627 /*
628  * Dump the trapframe beginning at address specified by first argument.
629  */
630 DB_SHOW_COMMAND(trapframe, ddb_dump_trapframe)
631 {
632         
633         if (!have_addr)
634                 return;
635
636         dump_trapframe((struct trapframe *)addr);
637 }
638
639 #endif  /* DDB */