new files of 0.5.2
[fw/sdcc] / sim / ucsim / cmd.src / cmdmem.cc
1 /*
2  * Simulator of microcontrollers (cmd.src/cmdmem.cc)
3  *
4  * Copyright (C) 2001,01 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 // prj
29 #include "globals.h"
30 #include "utils.h"
31
32 // sim
33 #include "simcl.h"
34
35 // local
36 #include "cmdmemcl.h"
37
38
39 /*
40  * Command: memory createchip
41  *----------------------------------------------------------------------------
42  */
43
44 //int
45 //cl_conf_addmem_cmd::do_work(class cl_sim *sim,
46 //                          class cl_cmdline *cmdline, class cl_console *con)
47 COMMAND_DO_WORK_UC(cl_memory_createchip_cmd)
48 {
49   class cl_cmd_arg *params[4]= { cmdline->param(0),
50                                  cmdline->param(1),
51                                  cmdline->param(2),
52                                  cmdline->param(3) };
53   char *memid= NULL;
54   int size= -1;
55   int width= 8;
56
57   if (cmdline->syntax_match(uc, STRING NUMBER)) {
58     memid= params[0]->value.string.string;
59     size= params[1]->value.number;
60   }
61   else if (cmdline->syntax_match(uc, STRING NUMBER NUMBER)) {
62     memid= params[0]->value.string.string;
63     size= params[1]->value.number;
64     width= params[2]->value.number;
65   }
66   else
67     con->dd_printf("Syntax error.\n");
68
69   if (!memid ||
70       !*memid)
71     con->dd_printf("Wrong id\n");
72   else if (size < 1)
73     con->dd_printf("Wrong size\n");
74   else
75     {
76       class cl_memory *mem= new cl_memory_chip(memid, size, width);
77       mem->init();
78       uc->memchips->add(mem);
79       mem->set_uc(uc);
80     }
81   return(DD_FALSE);
82 }
83
84
85 /*
86  * Command: memory createaddressspace
87  *----------------------------------------------------------------------------
88  */
89
90 //int
91 //cl_conf_addmem_cmd::do_work(class cl_sim *sim,
92 //                          class cl_cmdline *cmdline, class cl_console *con)
93 COMMAND_DO_WORK_UC(cl_memory_createaddressspace_cmd)
94 {
95   class cl_cmd_arg *params[4]= { cmdline->param(0),
96                                  cmdline->param(1),
97                                  cmdline->param(2),
98                                  cmdline->param(3) };
99   char *memid= NULL;
100   int start= 0, size= -1, width= 8;
101
102   if (cmdline->syntax_match(uc, STRING NUMBER)) {
103     memid= params[0]->value.string.string;
104     size= params[1]->value.number;
105   }
106   else if (cmdline->syntax_match(uc, STRING NUMBER NUMBER)) {
107     memid= params[0]->value.string.string;
108     start= params[1]->value.number;
109     size= params[2]->value.number;
110   }
111   else if (cmdline->syntax_match(uc, STRING NUMBER NUMBER NUMBER)) {
112     memid= params[0]->value.string.string;
113     start= params[1]->value.number;
114     size= params[2]->value.number;
115     width= params[3]->value.number;
116   }
117   else
118     con->dd_printf("Syntax error.\n");
119
120   if (!memid ||
121       !*memid)
122     con->dd_printf("Wrong id\n");
123   else if (size < 1)
124     con->dd_printf("Wrong size\n");
125   else
126     {
127       class cl_address_space *mem=
128         new cl_address_space(memid, start, size, width);
129       mem->init();
130       uc->address_spaces->add(mem);
131       mem->set_uc(uc);
132     }
133   return(DD_FALSE);
134 }
135
136
137 /*
138  * Command: memory createaddressdecoder
139  *----------------------------------------------------------------------------
140  */
141
142 //int
143 //cl_conf_addmem_cmd::do_work(class cl_sim *sim,
144 //                          class cl_cmdline *cmdline, class cl_console *con)
145 COMMAND_DO_WORK_UC(cl_memory_createaddressdecoder_cmd)
146 {
147   class cl_cmd_arg *params[5]= { cmdline->param(0),
148                                  cmdline->param(1),
149                                  cmdline->param(2),
150                                  cmdline->param(3),
151                                  cmdline->param(4) };
152   class cl_memory *as= 0, *chip= 0;
153   t_addr as_begin= 0, as_end= 0, chip_begin= 0;
154   
155   if (cmdline->syntax_match(uc, MEMORY MEMORY)) {
156     as= params[0]->value.memory.memory;
157     as_end= as->highest_valid_address();
158     chip= params[1]->value.memory.memory;
159   }
160   else if (cmdline->syntax_match(uc, MEMORY MEMORY NUMBER)) {
161     as= params[0]->value.memory.memory;
162     as_end= as->highest_valid_address();
163     chip= params[1]->value.memory.memory;
164     chip_begin= params[2]->value.number;
165   }
166   else if (cmdline->syntax_match(uc, MEMORY NUMBER MEMORY)) {
167     as= params[0]->value.memory.memory;
168     as_begin= params[1]->value.number;
169     as_end= as->highest_valid_address();
170     chip= params[2]->value.memory.memory;
171   }
172   else if (cmdline->syntax_match(uc, MEMORY NUMBER MEMORY NUMBER)) {
173     as= params[0]->value.memory.memory;
174     as_begin= params[1]->value.number;
175     as_end= as->highest_valid_address();
176     chip= params[2]->value.memory.memory;
177     chip_begin= params[3]->value.number;
178   }
179   else if (cmdline->syntax_match(uc, MEMORY NUMBER NUMBER MEMORY)) {
180     as= params[0]->value.memory.memory;
181     as_begin= params[1]->value.number;
182     as_end= params[2]->value.number;
183     chip= params[3]->value.memory.memory;
184   }
185   else if (cmdline->syntax_match(uc, MEMORY NUMBER NUMBER MEMORY NUMBER)) {
186     as= params[0]->value.memory.memory;
187     as_begin= params[1]->value.number;
188     as_end= params[2]->value.number;
189     chip= params[3]->value.memory.memory;
190     chip_begin= params[4]->value.number;
191   }
192   else
193     con->dd_printf("Syntax error.\n");
194
195   if (!as->is_address_space())
196     con->dd_printf("%s is not an address space\n", as->get_name("unknown"));
197   else if (!chip->is_chip())
198     con->dd_printf("%s is not a memory chip\n", chip->get_name("unknown"));
199   else if (as_begin > as_end)
200     con->dd_printf("Wrong address area specification\n");
201   else if (chip_begin >= chip->get_size())
202     con->dd_printf("Wrong chip area specification\n");
203   else if (as_begin < as->start_address ||
204            as_end >= as->highest_valid_address())
205     con->dd_printf("Specified area is out of address space\n");
206   else if (as_end-as_begin > chip->get_size()-chip_begin)
207     con->dd_printf("Specified area is out of chip size\n");
208   else
209     {
210       class cl_address_decoder *d=
211         new cl_address_decoder(as, chip, as_begin, as_end, chip_begin);
212       ((class cl_address_space *)as)->decoders->add(d);
213       d->activate(con);
214     }
215   return(DD_FALSE);
216 }
217
218
219 /* End of cmd.src/cmdmem.cc */