Some fixes towards 0.2.37-pre5
[fw/sdcc] / sim / ucsim / s51.src / cmd_brk.cc
1 /*
2  * Simulator of microcontrollers (cmd_brk.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 <stdio.h>
31 #include <stdlib.h>
32 #include <ctype.h>
33 #include "i_string.h"
34
35 #include "simcl.h"
36
37 #include "uc51cl.h" //FIXME
38 #include "globals.h"
39
40
41 /*
42  * BREAKPOINT SET f|d addr [hit]
43  */
44 //FIXME
45 /*bool
46 cmd_brk_setf(char *cmd, class t_uc51 *uc, class cl_sim *sim)
47 {
48   char *s;
49   uint addr;
50   int  hit= 1;
51   enum brk_perm perm;
52   class cl_brk *b;
53
54   if ((s= strtok(NULL, delimiters)) == NULL)
55     {
56       sim->cmd->printf("Permanency has not given\n");
57       return(FALSE);
58     }
59   switch (*s)
60     {
61     case 'f': case 'F':
62       perm= brkFIX;
63       break;
64     case 'd': case 'D':
65       perm= brkDYNAMIC;
66       break;
67     default:
68       sim->cmd->printf("Unknow permanency\n");
69       return(FALSE);
70     }
71   if ((s= strtok(NULL, delimiters)) == NULL)
72     {
73       sim->cmd->printf("Address has not given\n");
74       return(FALSE);
75     }
76   addr= (uint)strtol(s, NULL, 0);
77   if ((s= strtok(NULL, delimiters)) != NULL)
78     hit= strtol(s, NULL, 0);
79   if (uc->fbrk_at(addr))
80     sim->cmd->printf("Breakpoint at %06x is already set.\n", addr);
81   else
82     {
83       b= new cl_fetch_brk(addr, perm, hit);
84       uc->fbrk->add_bp(b);
85     }
86   return(FALSE);
87 }
88 */
89
90 /*
91  * BREAKPOINT SET EVENT wi|ri|wx|rx|ws|rs|rc f|d addr [hit]
92  */
93 //FIXME
94 bool
95 cmd_brk_sete(char *cmd, class t_uc51 *uc, class cl_sim *sim)
96 {
97   char *s;
98   char *id;
99   uint addr;
100   int  hit= 1;
101   enum brk_perm perm;
102   class cl_ev_brk *b= NULL;
103
104   if ((id= strtok(NULL, delimiters)) == NULL)
105     {
106       sim->cmd->printf("Event has not given.\n");
107       return(DD_FALSE);
108     }
109   if ((s= strtok(NULL, delimiters)) == NULL)
110     {
111       sim->cmd->printf("Permanency has not given\n");
112       return(DD_FALSE);
113     }
114   switch (*s)
115     {
116     case 'f': case 'F':
117       perm= brkFIX;
118       break;
119     case 'd': case 'D':
120       perm= brkDYNAMIC;
121       break;
122     default:
123       sim->cmd->printf("Unknow permanency\n");
124       return(DD_FALSE);
125     }
126   if ((s= strtok(NULL, delimiters)) == NULL)
127     {
128       sim->cmd->printf("Address has not given\n");
129       return(DD_FALSE);
130     }
131   addr= (uint)strtol(s, NULL, 0);
132   if ((s= strtok(NULL, delimiters)) != NULL)
133     hit= strtol(s, NULL, 0);
134   else
135     {
136       if (!strcmp(id, "wi"))
137         b= new cl_wi_brk(uc->ebrk->make_new_nr(), addr, perm, hit);
138       else if (!strcmp(id, "ri"))
139         b= new cl_ri_brk(uc->ebrk->make_new_nr(), addr, perm, hit);
140       else if (!strcmp(id, "wx"))
141         b= new cl_wx_brk(uc->ebrk->make_new_nr(), addr, perm, hit);
142       else if (!strcmp(id, "rx"))
143         b= new cl_rx_brk(uc->ebrk->make_new_nr(), addr, perm, hit);
144       else if (!strcmp(id, "ws"))
145         b= new cl_ws_brk(uc->ebrk->make_new_nr(), addr, perm, hit);
146       else if (!strcmp(id, "rs"))
147         b= new cl_rs_brk(uc->ebrk->make_new_nr(), addr, perm, hit);
148       else if (!strcmp(id, "rc"))
149         b= new cl_rc_brk(uc->ebrk->make_new_nr(), addr, perm, hit);
150       else
151         sim->cmd->printf("Event %s is unknown.\n", id);
152       if (b)
153         uc->ebrk->add_bp(b);
154     }
155   return(DD_FALSE);
156 }
157
158
159 /*
160  * BREAKPOINT DELETE addr
161  */
162 //FIXME
163 /*bool
164 cmd_brk_delf(char *cmd, class t_uc51 *uc, class cl_sim *sim)
165 {
166   uint addr;
167   char *s;
168
169   if ((s= strtok(NULL, delimiters)) == NULL)
170     sim->cmd->printf("Address has not given.\n");
171   else
172     {
173       addr= (uint)strtol(s, NULL, 0);
174       if (uc->fbrk_at(addr) == NULL)
175         sim->cmd->printf("No breakpoint at %06x\n", addr);
176       else
177         uc->fbrk->del_bp(addr);
178     }
179   return(DD_FALSE);
180 }*/
181
182
183 /*
184  * BREAKPOINT DELETE EVENT wi|ri|wx|rx|ws|rs|rc addr
185  */
186 //FIXME
187 bool
188 cmd_brk_dele(char *cmd, class t_uc51 *uc, class cl_sim *sim)
189 {
190   uint addr;
191   char *s, *id;
192
193   if ((id= strtok(NULL, delimiters)) == NULL)
194     {
195       fprintf(sim->cmd_out(), "Event has not given.\n");
196       return(DD_FALSE);
197     }
198   if ((s= strtok(NULL, delimiters)) == NULL)
199     fprintf(sim->cmd_out(), "Address has not given.\n");
200   else
201     {
202       addr= (uint)strtol(s, NULL, 0);
203       if (uc->ebrk_at(addr, id) == NULL)
204         fprintf(sim->cmd_out(), "No %s breakpoint at %06x\n", id, addr);
205       else
206         uc->rm_ebrk(addr, id);
207     }
208   return(DD_FALSE);
209 }
210
211
212 /*
213  * BREAKPOINT DELETE ALL
214  */
215 //FIXME
216 bool
217 cmd_brk_delall(char *cmd, class t_uc51 *uc, class cl_sim *sim)
218 {
219   while (uc->fbrk->count)
220     {
221       class cl_brk *brk= (class cl_brk *)(uc->fbrk->at(0));
222       uc->fbrk->del_bp(brk->addr);
223     }
224   while (uc->ebrk->count)
225     uc->ebrk->free_at(0);
226   return(DD_FALSE);
227 }
228
229
230 /*
231  * BREAKPOINT LIST
232  */
233 //FIXME
234 /*bool
235 cmd_brk_lst(char *cmd, class t_uc51 *uc, class cl_sim *sim)
236 {
237   class cl_fetch_brk *fb;
238   class cl_ev_brk *eb;
239   int i;
240   char *s;
241
242   for (i= 0; i < uc->fbrk->count; i++)
243     {
244       fb= (class cl_fetch_brk *)(uc->fbrk->at(i));
245       s = uc->disass(fb->addr, NULL);
246       fprintf(sim->cmd_out(), "%c %d(%d) %06x %02x %s\n",
247               (fb->perm==brkFIX)?'F':'D',
248               fb->hit, fb->cnt,
249               fb->addr, uc->get_mem(MEM_ROM, fb->addr), s);
250       free(s);
251     }
252   for (i= 0; i < uc->ebrk->count; i++)
253     {
254       eb= (class cl_ev_brk *)(uc->ebrk->at(i));
255       fprintf(sim->cmd_out(), "%c %d(%d) %06x %s\n",
256               (eb->perm==brkFIX)?'F':'D',
257               eb->hit, eb->cnt,
258               eb->addr, eb->id);
259     }
260   return(DD_FALSE);
261 }*/
262
263
264 /* End of s51.src/cmd_brk.cc */