d926e3259beba358a85a4b95913d67818db70cb7
[fw/sdcc] / sim / ucsim / cmd.src / bp.cc
1 /*
2  * Simulator of microcontrollers (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
40
41 /*
42  * BREAK command
43  */
44
45 int
46 cl_break_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
47 {
48   long addr;
49   int  hit= 1;
50   class cl_cmd_arg *params[2]= { cmdline->param(0),
51                                  cmdline->param(1) };
52
53   if (params[0] == 0)
54     {
55       con->printf("Address is missing.\n");
56       return(DD_FALSE);
57     }
58   addr= (params[0])->get_address();
59   if (params[1])
60     hit= (params[1])->get_ivalue();
61   if (hit > 99999)
62     {
63       con->printf("Hit value %d is too big.\n", hit);
64       return(0);
65     }
66   if (sim->uc->fbrk->bp_at(addr))
67     con->printf("Breakpoint at 0x%06x is already set.\n", addr);
68   else
69     {
70       class cl_brk *b= new cl_fetch_brk(sim->uc->fbrk->make_new_nr(),
71                                         addr, perm, hit);
72       b->init();
73       sim->uc->fbrk->add_bp(b);
74       char *s= sim->uc->disass(addr, NULL);
75       con->printf("Breakpoint %d at 0x%06x: %s\n", b->nr, addr, s);
76       free(s);
77     }
78   return(0);
79 }
80
81
82 /*
83  * CLEAR address
84  */
85
86 int
87 cl_clear_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
88 {
89   uint addr;
90   int idx;
91   class cl_brk *brk= sim->uc->fbrk->get_bp(sim->uc->PC, &idx);
92
93   if (cmdline->param(0) == 0)
94     {
95       if (!brk)
96         {
97           con->printf("No breakpoint at this address.\n");
98           return(0);
99         }
100       sim->uc->fbrk->del_bp(sim->uc->PC);
101       return(0);
102     }
103
104   int i= 0;
105   class cl_cmd_arg *param;
106   while ((param= cmdline->param(i++)))
107     {
108       addr= param->get_ivalue();
109       if (sim->uc->fbrk->bp_at(addr) == 0)
110         sim->cmd->printf("No breakpoint at 0x%06x\n", addr);
111       else
112         sim->uc->fbrk->del_bp(addr);
113     }
114
115   return(0);
116 }
117
118
119 /* End of bp.cc */