- started infrastructure for proper multi-target support (active
[wine] / programs / winedbg / be_ppc.c
1 /*
2  * Debugger Power PC specific functions
3  *
4  * Copyright 2000-2003 Marcus Meissner
5  *                2004 Eric Pouech
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "debugger.h"
23
24 #if defined(__powerpc__)
25
26 static unsigned be_ppc_get_addr(HANDLE hThread, const CONTEXT* ctx, 
27                                 enum be_cpu_addr bca, ADDRESS* addr)
28 {
29     switch (bca)
30     {
31     case be_cpu_addr_pc:
32         return be_cpu_build_addr(hThread, ctx, addr, 0, ctx->Iar);
33     default:
34     case be_cpu_addr_stack:
35     case be_cpu_addr_frame:
36         dbg_printf("not done\n");
37     }
38     return FALSE;
39 }
40
41 static void be_ppc_single_step(CONTEXT* ctx, unsigned enable)
42 {
43 #ifndef MSR_SE
44 # define MSR_SE (1<<10)
45 #endif 
46     if (enable) ctx->Msr |= MSR_SE;
47     else ctx->Msr &= ~MSR_SE;
48 }
49
50 static void be_ppc_print_context(HANDLE hThread, const CONTEXT* ctx)
51 {
52     dbg_printf("Context printing for PPC not done yet\n");
53 }
54
55 static void be_ppc_print_segment_info(HANDLE hThread, const CONTEXT* ctx)
56 {
57 }
58
59 static struct dbg_internal_var be_ppc_ctx[] =
60 {
61     {0,                 NULL,           0,                                      dbg_itype_none}
62 };
63
64 static const struct dbg_internal_var* be_ppc_init_registers(CONTEXT* ctx)
65 {
66     dbg_printf("not done\n");
67     return be_ppc_ctx;
68 }
69
70 static unsigned be_ppc_is_step_over_insn(void* insn)
71 {
72     dbg_printf("not done\n");
73     return FALSE;
74 }
75
76 static unsigned be_ppc_is_function_return(void* insn)
77 {
78     dbg_printf("not done\n");
79     return FALSE;
80 }
81
82 static unsigned be_ppc_is_break_insn(void* insn)
83 {
84     dbg_printf("not done\n");
85     return FALSE;
86 }
87
88 static unsigned be_ppc_is_func_call(void* insn, void** insn_callee)
89 {
90     return FALSE;
91 }
92
93 static void be_ppc_disasm_one_insn(ADDRESS* addr, int display)
94 {
95     dbg_printf("Disasm NIY\n");
96 }
97
98 static unsigned be_ppc_insert_Xpoint(HANDLE hProcess, struct be_process_io* pio,
99                                      CONTEXT* ctx, enum be_xpoint_type type,
100                                      void* addr, unsigned long* val, unsigned size)
101 {
102     unsigned long       xbp;
103     unsigned long       sz;
104
105     switch (type)
106     {
107     case be_xpoint_break:
108         if (!size) return 0;
109         if (!pio->read(hProcess, addr, val, 4, &sz) || sz != 4) return 0;
110         xbp = 0x7d821008; /* 7d 82 10 08 ... in big endian */
111         if (!pio->write(hProcess, addr, &xbp, 4, &sz) || sz != 4) return 0;
112         break;
113     default:
114         dbg_printf("Unknown/unsupported bp type %c\n", type);
115         return 0;
116     }
117     return 1;
118 }
119
120 static unsigned be_ppc_remove_Xpoint(HANDLE hProcess, struct be_process_io* pio,
121                                      CONTEXT* ctx, enum be_xpoint_type type,
122                                      void* addr, unsigned long val, unsigned size)
123 {
124     unsigned long       sz;
125
126     switch (type)
127     {
128     case be_xpoint_break:
129         if (!size) return 0;
130         if (!pio->write(hProcess, addr, &val, 4, &sz) || sz == 4) return 0;
131         break;
132     default:
133         dbg_printf("Unknown/unsupported bp type %c\n", type);
134         return 0;
135     }
136     return 1;
137 }
138
139 static unsigned be_ppc_is_watchpoint_set(const CONTEXT* ctx, unsigned idx)
140 {
141     dbg_printf("not done\n");
142     return FALSE;
143 }
144
145 static void be_ppc_clear_watchpoint(CONTEXT* ctx, unsigned idx)
146 {
147     dbg_printf("not done\n");
148 }
149
150 static int be_ppc_adjust_pc_for_break(CONTEXT* ctx, BOOL way)
151 {
152     dbg_printf("not done\n");
153     return 0;
154 }
155
156 static int be_ppc_fetch_integer(const struct dbg_lvalue* lvalue, unsigned size,
157                                 unsigned ext_sign, long long int* ret)
158 {
159     dbg_printf("not done\n");
160     return FALSE;
161 }
162
163 static int be_ppc_fetch_float(const struct dbg_lvalue* lvalue, unsigned size, 
164                               long double* ret)
165 {
166     dbg_printf("not done\n");
167     return FALSE;
168 }
169
170 struct backend_cpu be_ppc =
171 {
172     be_cpu_linearize,
173     be_cpu_build_addr,
174     be_ppc_get_addr,
175     be_ppc_single_step,
176     be_ppc_print_context,
177     be_ppc_print_segment_info,
178     be_ppc_init_registers,
179     be_ppc_is_step_over_insn,
180     be_ppc_is_function_return,
181     be_ppc_is_break_insn,
182     be_ppc_is_func_call,
183     be_ppc_disasm_one_insn,
184     be_ppc_insert_Xpoint,
185     be_ppc_remove_Xpoint,
186     be_ppc_is_watchpoint_set,
187     be_ppc_clear_watchpoint,
188     be_ppc_adjust_pc_for_break,
189     be_ppc_fetch_integer,
190     be_ppc_fetch_float,
191 };
192 #endif