xref: /openbmc/qemu/target/m68k/gdbstub.c (revision 4ea5fe99)
1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth  * m68k gdb server stub
3fcf5ef2aSThomas Huth  *
4fcf5ef2aSThomas Huth  * Copyright (c) 2003-2005 Fabrice Bellard
5fcf5ef2aSThomas Huth  * Copyright (c) 2013 SUSE LINUX Products GmbH
6fcf5ef2aSThomas Huth  *
7fcf5ef2aSThomas Huth  * This library is free software; you can redistribute it and/or
8fcf5ef2aSThomas Huth  * modify it under the terms of the GNU Lesser General Public
9fcf5ef2aSThomas Huth  * License as published by the Free Software Foundation; either
10d749fb85SThomas Huth  * version 2.1 of the License, or (at your option) any later version.
11fcf5ef2aSThomas Huth  *
12fcf5ef2aSThomas Huth  * This library is distributed in the hope that it will be useful,
13fcf5ef2aSThomas Huth  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14fcf5ef2aSThomas Huth  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15fcf5ef2aSThomas Huth  * Lesser General Public License for more details.
16fcf5ef2aSThomas Huth  *
17fcf5ef2aSThomas Huth  * You should have received a copy of the GNU Lesser General Public
18fcf5ef2aSThomas Huth  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19fcf5ef2aSThomas Huth  */
20fcf5ef2aSThomas Huth #include "qemu/osdep.h"
21fcf5ef2aSThomas Huth #include "cpu.h"
22*4ea5fe99SAlex Bennée #include "gdbstub/helpers.h"
23fcf5ef2aSThomas Huth 
m68k_cpu_gdb_read_register(CPUState * cs,GByteArray * mem_buf,int n)24a010bdbeSAlex Bennée int m68k_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
25fcf5ef2aSThomas Huth {
26fcf5ef2aSThomas Huth     M68kCPU *cpu = M68K_CPU(cs);
27fcf5ef2aSThomas Huth     CPUM68KState *env = &cpu->env;
28fcf5ef2aSThomas Huth 
29fcf5ef2aSThomas Huth     if (n < 8) {
30fcf5ef2aSThomas Huth         /* D0-D7 */
31fcf5ef2aSThomas Huth         return gdb_get_reg32(mem_buf, env->dregs[n]);
32fcf5ef2aSThomas Huth     } else if (n < 16) {
33fcf5ef2aSThomas Huth         /* A0-A7 */
34fcf5ef2aSThomas Huth         return gdb_get_reg32(mem_buf, env->aregs[n - 8]);
35fcf5ef2aSThomas Huth     } else {
36fcf5ef2aSThomas Huth         switch (n) {
37fcf5ef2aSThomas Huth         case 16:
38bf1fa691SLucien Murray-Pitts             /* SR is made of SR+CCR, CCR is many 1bit flags so uses helper */
39bf1fa691SLucien Murray-Pitts             return gdb_get_reg32(mem_buf, env->sr | cpu_m68k_get_ccr(env));
40fcf5ef2aSThomas Huth         case 17:
41fcf5ef2aSThomas Huth             return gdb_get_reg32(mem_buf, env->pc);
42fcf5ef2aSThomas Huth         }
43fcf5ef2aSThomas Huth     }
44808d77bcSLucien Murray-Pitts     /*
45808d77bcSLucien Murray-Pitts      * FP registers not included here because they vary between
46808d77bcSLucien Murray-Pitts      * ColdFire and m68k.  Use XML bits for these.
47808d77bcSLucien Murray-Pitts      */
48fcf5ef2aSThomas Huth     return 0;
49fcf5ef2aSThomas Huth }
50fcf5ef2aSThomas Huth 
m68k_cpu_gdb_write_register(CPUState * cs,uint8_t * mem_buf,int n)51fcf5ef2aSThomas Huth int m68k_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
52fcf5ef2aSThomas Huth {
53fcf5ef2aSThomas Huth     M68kCPU *cpu = M68K_CPU(cs);
54fcf5ef2aSThomas Huth     CPUM68KState *env = &cpu->env;
55fcf5ef2aSThomas Huth     uint32_t tmp;
56fcf5ef2aSThomas Huth 
57fcf5ef2aSThomas Huth     tmp = ldl_p(mem_buf);
58fcf5ef2aSThomas Huth 
59fcf5ef2aSThomas Huth     if (n < 8) {
60fcf5ef2aSThomas Huth         /* D0-D7 */
61fcf5ef2aSThomas Huth         env->dregs[n] = tmp;
62fcf5ef2aSThomas Huth     } else if (n < 16) {
63fcf5ef2aSThomas Huth         /* A0-A7 */
64fcf5ef2aSThomas Huth         env->aregs[n - 8] = tmp;
65fcf5ef2aSThomas Huth     } else {
66fcf5ef2aSThomas Huth         switch (n) {
67fcf5ef2aSThomas Huth         case 16:
686e22b28eSLaurent Vivier             cpu_m68k_set_sr(env, tmp);
69fcf5ef2aSThomas Huth             break;
70fcf5ef2aSThomas Huth         case 17:
71fcf5ef2aSThomas Huth             env->pc = tmp;
72fcf5ef2aSThomas Huth             break;
73fcf5ef2aSThomas Huth         default:
74fcf5ef2aSThomas Huth             return 0;
75fcf5ef2aSThomas Huth         }
76fcf5ef2aSThomas Huth     }
77fcf5ef2aSThomas Huth     return 4;
78fcf5ef2aSThomas Huth }
79