1161588Smarcel/*-
2161588Smarcel * Copyright (c) 2006 Marcel Moolenaar
3161588Smarcel * All rights reserved.
4161588Smarcel *
5161588Smarcel * Redistribution and use in source and binary forms, with or without
6161588Smarcel * modification, are permitted provided that the following conditions
7161588Smarcel * are met:
8161588Smarcel *
9161588Smarcel * 1. Redistributions of source code must retain the above copyright
10161588Smarcel *    notice, this list of conditions and the following disclaimer.
11161588Smarcel * 2. Redistributions in binary form must reproduce the above copyright
12161588Smarcel *    notice, this list of conditions and the following disclaimer in the
13161588Smarcel *    documentation and/or other materials provided with the distribution.
14161588Smarcel *
15161588Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16161588Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17161588Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18161588Smarcel * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19161588Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20161588Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21161588Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22161588Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23161588Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24161588Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25161588Smarcel */
26161588Smarcel
27161588Smarcel#include <sys/cdefs.h>
28161588Smarcel__FBSDID("$FreeBSD$");
29161588Smarcel
30161588Smarcel#include <sys/param.h>
31161588Smarcel#include <sys/systm.h>
32161588Smarcel#include <sys/kdb.h>
33161588Smarcel#include <sys/kernel.h>
34161588Smarcel#include <sys/proc.h>
35161588Smarcel#include <sys/signal.h>
36161588Smarcel
37161588Smarcel#include <machine/gdb_machdep.h>
38161588Smarcel#include <machine/pcb.h>
39161588Smarcel#include <machine/reg.h>
40176777Sraj
41176777Sraj#include <machine/hid.h>
42176777Sraj#include <machine/spr.h>
43176777Sraj
44161588Smarcel#include <machine/trap.h>
45161588Smarcel
46161588Smarcel#include <gdb/gdb.h>
47161588Smarcel#include <gdb/gdb_int.h>
48161588Smarcel
49161588Smarcelvoid *
50161588Smarcelgdb_cpu_getreg(int regnum, size_t *regsz)
51161588Smarcel{
52161588Smarcel
53161588Smarcel	*regsz = gdb_cpu_regsz(regnum);
54176777Sraj
55176777Sraj	if (kdb_thread == curthread) {
56177288Smarcel		if (regnum == 0 || (regnum >= 2 && regnum <= 31))
57177288Smarcel			return (kdb_frame->fixreg + regnum);
58177288Smarcel		if (regnum == 64)
59177288Smarcel			return (&kdb_frame->srr0);
60177288Smarcel		if (regnum == 67)
61177288Smarcel			return (&kdb_frame->lr);
62176777Sraj	}
63176777Sraj
64177288Smarcel	if (regnum == 1)
65177288Smarcel		return (&kdb_thrctx->pcb_sp);
66177288Smarcel	if (regnum >= 14 && regnum <= 31)
67177288Smarcel		return (kdb_thrctx->pcb_context + (regnum - 14));
68177288Smarcel	if (regnum == 64)
69177288Smarcel		return (&kdb_thrctx->pcb_lr);
70176777Sraj
71161588Smarcel	return (NULL);
72161588Smarcel}
73161588Smarcel
74161588Smarcelvoid
75161588Smarcelgdb_cpu_setreg(int regnum, void *val)
76161588Smarcel{
77161588Smarcel
78161588Smarcel	switch (regnum) {
79161588Smarcel	case GDB_REG_PC:
80161588Smarcel		break;
81161588Smarcel	}
82161588Smarcel}
83161588Smarcel
84161588Smarcelint
85161588Smarcelgdb_cpu_signal(int vector, int dummy __unused)
86161588Smarcel{
87176777Sraj#ifdef E500
88176777Sraj	if (vector == EXC_DEBUG || vector == EXC_PGM)
89176777Sraj		return (SIGTRAP);
90176777Sraj#else
91161588Smarcel	if (vector == EXC_TRC || vector == EXC_RUNMODETRC)
92161588Smarcel		return (SIGTRAP);
93176777Sraj#endif
94176777Sraj
95176777Sraj	if (vector <= 255)
96176777Sraj		return (vector);
97176777Sraj	else
98176777Sraj		return (SIGEMT);
99161588Smarcel}
100