7318c6c8bd15186afa03f57a2d5f5e1912498ebf
[fw/sdcc] / sim / ucsim / cmd.src / bp.cc
1 /*
2  * Simulator of microcontrollers (cmd.src/bp.cc)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  * 
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9
10 /* This file is part of microcontroller simulator: ucsim.
11
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING.  If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26 /*@1@*/
27
28 #include "ddconfig.h"
29
30 #include "stdlib.h"
31
32 // sim
33 #include "brkcl.h"
34 #include "argcl.h"
35 #include "simcl.h"
36
37 // cmd
38 #include "cmdsetcl.h"
39 #include "bpcl.h"
40
41
42 /*
43  * BREAK command
44  */
45
46 int
47 cl_break_cmd::do_work(class cl_sim *sim,
48                       class cl_cmdline *cmdline, class cl_console *con)
49 {
50   t_addr addr= 0;
51   int hit= 1;
52   char op;
53   class cl_mem *mem;
54   class cl_cmd_arg *params[4]= { cmdline->param(0),
55                                  cmdline->param(1),
56                                  cmdline->param(2),
57                                  cmdline->param(3) };
58
59   if (cmdline->syntax_match(sim, ADDRESS)) {
60     addr= params[0]->value.address;
61     hit= 1;
62     do_fetch(sim, addr, hit, con);
63   }
64   else if (cmdline->syntax_match(sim, ADDRESS NUMBER)) {
65     addr= params[0]->value.address;
66     hit= params[1]->value.number;
67     do_fetch(sim, addr, hit, con);
68   }
69   else if (cmdline->syntax_match(sim, MEMORY STRING ADDRESS)) {
70     mem= params[0]->value.memory;
71     op= *(params[1]->get_svalue());
72     addr= params[2]->value.address;
73     hit= 1;
74     do_event(sim, mem, op, addr, hit, con);
75   }
76   else if (cmdline->syntax_match(sim, MEMORY STRING ADDRESS NUMBER)) {
77     mem= params[0]->value.memory;
78     op= *(params[1]->get_svalue());
79     addr= params[2]->value.address;
80     hit= params[3]->value.number;
81     do_event(sim, mem, op, addr, hit, con);
82   }
83   else
84     {
85       con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
86       return(DD_FALSE);
87     }
88   return(DD_FALSE);
89 }
90
91 void
92 cl_break_cmd::do_fetch(class cl_sim *sim,
93                        t_addr addr, int hit, class cl_console *con)
94 {
95   if (hit > 99999)
96     {
97       con->printf("Hit value %d is too big.\n", hit);
98       return;
99     }
100   if (sim->uc->fbrk->bp_at(addr))
101     con->printf("Breakpoint at 0x%06x is already set.\n", addr);
102   else
103     {
104       class cl_brk *b= new cl_fetch_brk(sim->uc->make_new_brknr(),
105                                         addr, perm, hit);
106       b->init();
107       sim->uc->fbrk->add_bp(b);
108       char *s= sim->uc->disass(addr, NULL);
109       con->printf("Breakpoint %d at 0x%06x: %s\n", b->nr, addr, s);
110       free(s);
111     }
112 }
113
114 void
115 cl_break_cmd::do_event(class cl_sim *sim,
116                        class cl_mem *mem, char op, t_addr addr, int hit,
117                        class cl_console *con)
118 {
119   class cl_ev_brk *b= NULL;
120
121   b= sim->uc->mk_ebrk(perm, mem, op, addr, hit);
122   if (b)
123     sim->uc->ebrk->add_bp(b);
124   else
125     con->printf("Couldn't make event breakpoint\n");
126 }
127
128
129 /*
130  * CLEAR address
131  */
132
133 int
134 cl_clear_cmd::do_work(class cl_sim *sim,
135                       class cl_cmdline *cmdline, class cl_console *con)
136 {
137   int idx;
138   class cl_brk *brk= sim->uc->fbrk->get_bp(sim->uc->PC, &idx);
139
140   if (cmdline->param(0) == 0)
141     {
142       if (!brk)
143         {
144           con->printf("No breakpoint at this address.\n");
145           return(0);
146         }
147       sim->uc->fbrk->del_bp(sim->uc->PC);
148       return(0);
149     }
150
151   int i= 0;
152   class cl_cmd_arg *param;
153   while ((param= cmdline->param(i++)))
154     {
155       t_addr addr;
156       if (!param->as_address())
157         return(DD_FALSE);
158       addr= param->value.address;
159       if (sim->uc->fbrk->bp_at(addr) == 0)
160         sim->cmd->printf("No breakpoint at 0x%06x\n", addr);
161       else
162         sim->uc->fbrk->del_bp(addr);
163     }
164
165   return(DD_FALSE);
166 }
167
168
169 /*
170  * DELETE nr nr ...
171  */
172
173 int
174 cl_delete_cmd::do_work(class cl_sim *sim,
175                        class cl_cmdline *cmdline, class cl_console *con)
176 {
177   if (cmdline->param(0) == 0)
178     {
179       // delete all
180       sim->uc->remove_all_breaks();
181     }
182   else
183     {
184       int i= 0;
185       class cl_cmd_arg *param;
186       while ((param= cmdline->param(i++)))
187         {
188           long num;
189           if (param->get_ivalue(&num))
190             sim->uc->rm_brk(num);
191         }
192     }
193   return(DD_FALSE);
194 }
195
196
197 /* End of cmd.src/bp.cc */