xref: /freebsd/sys/arm/arm/machdep_kdb.c (revision 9768746b)
1 /*	$NetBSD: arm32_machdep.c,v 1.44 2004/03/24 15:34:47 atatat Exp $	*/
2 
3 /*-
4  * Copyright (c) 2004 Olivier Houchard
5  * Copyright (c) 1994-1998 Mark Brinicombe.
6  * Copyright (c) 1994 Brini.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #include "opt_ddb.h"
32 
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35 
36 #include <sys/param.h>
37 #include <sys/proc.h>
38 #include <sys/reg.h>
39 #include <sys/systm.h>
40 
41 #include <machine/cpu.h>
42 #include <machine/pcb.h>
43 
44 #ifdef DDB
45 #include <ddb/ddb.h>
46 
47 DB_SHOW_COMMAND(cp15, db_show_cp15)
48 {
49 	u_int reg;
50 
51 	reg = cp15_midr_get();
52 	db_printf("Cpu ID: 0x%08x\n", reg);
53 	reg = cp15_ctr_get();
54 	db_printf("Current Cache Lvl ID: 0x%08x\n",reg);
55 
56 	reg = cp15_sctlr_get();
57 	db_printf("Ctrl: 0x%08x\n",reg);
58 	reg = cp15_actlr_get();
59 	db_printf("Aux Ctrl: 0x%08x\n",reg);
60 
61 	reg = cp15_id_pfr0_get();
62 	db_printf("Processor Feat 0: 0x%08x\n", reg);
63 	reg = cp15_id_pfr1_get();
64 	db_printf("Processor Feat 1: 0x%08x\n", reg);
65 	reg = cp15_id_dfr0_get();
66 	db_printf("Debug Feat 0: 0x%08x\n", reg);
67 	reg = cp15_id_afr0_get();
68 	db_printf("Auxiliary Feat 0: 0x%08x\n", reg);
69 	reg = cp15_id_mmfr0_get();
70 	db_printf("Memory Model Feat 0: 0x%08x\n", reg);
71 	reg = cp15_id_mmfr1_get();
72 	db_printf("Memory Model Feat 1: 0x%08x\n", reg);
73 	reg = cp15_id_mmfr2_get();
74 	db_printf("Memory Model Feat 2: 0x%08x\n", reg);
75 	reg = cp15_id_mmfr3_get();
76 	db_printf("Memory Model Feat 3: 0x%08x\n", reg);
77 	reg = cp15_ttbr_get();
78 	db_printf("TTB0: 0x%08x\n", reg);
79 }
80 
81 DB_SHOW_COMMAND(vtop, db_show_vtop)
82 {
83 	u_int reg;
84 
85 	if (have_addr) {
86 		cp15_ats1cpr_set(addr);
87 		reg = cp15_par_get();
88 		db_printf("Physical address reg: 0x%08x\n",reg);
89 	} else
90 		db_printf("show vtop <virt_addr>\n");
91 }
92 #endif /* DDB */
93 
94 int
95 fill_regs(struct thread *td, struct reg *regs)
96 {
97 	struct trapframe *tf = td->td_frame;
98 	bcopy(&tf->tf_r0, regs->r, sizeof(regs->r));
99 	regs->r_sp = tf->tf_usr_sp;
100 	regs->r_lr = tf->tf_usr_lr;
101 	regs->r_pc = tf->tf_pc;
102 	regs->r_cpsr = tf->tf_spsr;
103 	return (0);
104 }
105 
106 int
107 fill_fpregs(struct thread *td, struct fpreg *regs)
108 {
109 #ifdef VFP
110 	struct pcb *pcb;
111 
112 	pcb = td->td_pcb;
113 	if ((pcb->pcb_fpflags & PCB_FP_STARTED) != 0) {
114 		/*
115 		 * If we have just been running VFP instructions we will
116 		 * need to save the state to memcpy it below.
117 		 */
118 		if (td == curthread)
119 			vfp_save_state(td, pcb);
120 	}
121 	KASSERT(pcb->pcb_vfpsaved == &pcb->pcb_vfpstate,
122 	    ("Called fill_fpregs while the kernel is using the VFP"));
123 	memcpy(regs->fpr_r, pcb->pcb_vfpstate.reg,
124 	    sizeof(regs->fpr_r));
125 	regs->fpr_fpscr = pcb->pcb_vfpstate.fpscr;
126 #else
127 	memset(regs, 0, sizeof(*regs));
128 #endif
129 	return (0);
130 }
131 
132 int
133 set_regs(struct thread *td, struct reg *regs)
134 {
135 	struct trapframe *tf = td->td_frame;
136 
137 	bcopy(regs->r, &tf->tf_r0, sizeof(regs->r));
138 	tf->tf_usr_sp = regs->r_sp;
139 	tf->tf_usr_lr = regs->r_lr;
140 	tf->tf_pc = regs->r_pc;
141 	tf->tf_spsr &=  ~PSR_FLAGS;
142 	tf->tf_spsr |= regs->r_cpsr & PSR_FLAGS;
143 	return (0);
144 }
145 
146 int
147 set_fpregs(struct thread *td, struct fpreg *regs)
148 {
149 #ifdef VFP
150 	struct pcb *pcb;
151 
152 	pcb = td->td_pcb;
153 	KASSERT(pcb->pcb_vfpsaved == &pcb->pcb_vfpstate,
154 	    ("Called set_fpregs while the kernel is using the VFP"));
155 	memcpy(pcb->pcb_vfpstate.reg, regs->fpr_r, sizeof(regs->fpr_r));
156 	pcb->pcb_vfpstate.fpscr = regs->fpr_fpscr;
157 #endif
158 	return (0);
159 }
160 
161 int
162 fill_dbregs(struct thread *td, struct dbreg *regs)
163 {
164 
165 	bzero(regs, sizeof(*regs));
166 	return (0);
167 }
168 
169 int
170 set_dbregs(struct thread *td, struct dbreg *regs)
171 {
172 	return (0);
173 }
174