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