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/param.h>
34#include <sys/proc.h>
35#include <sys/reg.h>
36#include <sys/systm.h>
37
38#include <machine/cpu.h>
39#include <machine/pcb.h>
40
41#ifdef DDB
42#include <ddb/ddb.h>
43
44DB_SHOW_COMMAND(cp15, db_show_cp15)
45{
46	u_int reg;
47
48	reg = cp15_midr_get();
49	db_printf("Cpu ID: 0x%08x\n", reg);
50	reg = cp15_ctr_get();
51	db_printf("Current Cache Lvl ID: 0x%08x\n",reg);
52
53	reg = cp15_sctlr_get();
54	db_printf("Ctrl: 0x%08x\n",reg);
55	reg = cp15_actlr_get();
56	db_printf("Aux Ctrl: 0x%08x\n",reg);
57
58	reg = cp15_id_pfr0_get();
59	db_printf("Processor Feat 0: 0x%08x\n", reg);
60	reg = cp15_id_pfr1_get();
61	db_printf("Processor Feat 1: 0x%08x\n", reg);
62	reg = cp15_id_dfr0_get();
63	db_printf("Debug Feat 0: 0x%08x\n", reg);
64	reg = cp15_id_afr0_get();
65	db_printf("Auxiliary Feat 0: 0x%08x\n", reg);
66	reg = cp15_id_mmfr0_get();
67	db_printf("Memory Model Feat 0: 0x%08x\n", reg);
68	reg = cp15_id_mmfr1_get();
69	db_printf("Memory Model Feat 1: 0x%08x\n", reg);
70	reg = cp15_id_mmfr2_get();
71	db_printf("Memory Model Feat 2: 0x%08x\n", reg);
72	reg = cp15_id_mmfr3_get();
73	db_printf("Memory Model Feat 3: 0x%08x\n", reg);
74	reg = cp15_ttbr_get();
75	db_printf("TTB0: 0x%08x\n", reg);
76}
77
78DB_SHOW_COMMAND(vtop, db_show_vtop)
79{
80	u_int reg;
81
82	if (have_addr) {
83		cp15_ats1cpr_set(addr);
84		reg = cp15_par_get();
85		db_printf("Physical address reg: 0x%08x\n",reg);
86	} else
87		db_printf("show vtop <virt_addr>\n");
88}
89#endif /* DDB */
90
91int
92fill_regs(struct thread *td, struct reg *regs)
93{
94	struct trapframe *tf = td->td_frame;
95	bcopy(&tf->tf_r0, regs->r, sizeof(regs->r));
96	regs->r_sp = tf->tf_usr_sp;
97	regs->r_lr = tf->tf_usr_lr;
98	regs->r_pc = tf->tf_pc;
99	regs->r_cpsr = tf->tf_spsr;
100	return (0);
101}
102
103int
104fill_fpregs(struct thread *td, struct fpreg *regs)
105{
106#ifdef VFP
107	struct pcb *pcb;
108
109	pcb = td->td_pcb;
110	if ((pcb->pcb_fpflags & PCB_FP_STARTED) != 0) {
111		/*
112		 * If we have just been running VFP instructions we will
113		 * need to save the state to memcpy it below.
114		 */
115		if (td == curthread)
116			vfp_save_state(td, pcb);
117	}
118	KASSERT(pcb->pcb_vfpsaved == &pcb->pcb_vfpstate,
119	    ("Called fill_fpregs while the kernel is using the VFP"));
120	memcpy(regs->fpr_r, pcb->pcb_vfpstate.reg,
121	    sizeof(regs->fpr_r));
122	regs->fpr_fpscr = pcb->pcb_vfpstate.fpscr;
123#else
124	memset(regs, 0, sizeof(*regs));
125#endif
126	return (0);
127}
128
129int
130set_regs(struct thread *td, struct reg *regs)
131{
132	struct trapframe *tf = td->td_frame;
133
134	bcopy(regs->r, &tf->tf_r0, sizeof(regs->r));
135	tf->tf_usr_sp = regs->r_sp;
136	tf->tf_usr_lr = regs->r_lr;
137	tf->tf_pc = regs->r_pc;
138	tf->tf_spsr &=  ~PSR_FLAGS;
139	tf->tf_spsr |= regs->r_cpsr & PSR_FLAGS;
140	return (0);
141}
142
143int
144set_fpregs(struct thread *td, struct fpreg *regs)
145{
146#ifdef VFP
147	struct pcb *pcb;
148
149	pcb = td->td_pcb;
150	KASSERT(pcb->pcb_vfpsaved == &pcb->pcb_vfpstate,
151	    ("Called set_fpregs while the kernel is using the VFP"));
152	memcpy(pcb->pcb_vfpstate.reg, regs->fpr_r, sizeof(regs->fpr_r));
153	pcb->pcb_vfpstate.fpscr = regs->fpr_fpscr;
154#endif
155	return (0);
156}
157
158int
159fill_dbregs(struct thread *td, struct dbreg *regs)
160{
161
162	bzero(regs, sizeof(*regs));
163	return (0);
164}
165
166int
167set_dbregs(struct thread *td, struct dbreg *regs)
168{
169	return (0);
170}
171