2 * Simulator of microcontrollers (cmd.src/cmdmem.cc)
4 * Copyright (C) 2001,01 Drotos Daniel, Talker Bt.
6 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
10 /* This file is part of microcontroller simulator: ucsim.
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.
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.
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
40 * Command: memory createchip
41 *----------------------------------------------------------------------------
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)
49 class cl_cmd_arg *params[4]= { cmdline->param(0),
57 if (cmdline->syntax_match(uc, STRING NUMBER)) {
58 memid= params[0]->value.string.string;
59 size= params[1]->value.number;
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;
67 con->dd_printf("Syntax error.\n");
71 con->dd_printf("Wrong id\n");
73 con->dd_printf("Wrong size\n");
76 class cl_memory *mem= new cl_memory_chip(memid, size, width);
78 uc->memchips->add(mem);
86 * Command: memory createaddressspace
87 *----------------------------------------------------------------------------
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)
95 class cl_cmd_arg *params[4]= { cmdline->param(0),
100 int start= 0, size= -1, width= 8;
102 if (cmdline->syntax_match(uc, STRING NUMBER)) {
103 memid= params[0]->value.string.string;
104 size= params[1]->value.number;
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;
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;
118 con->dd_printf("Syntax error.\n");
122 con->dd_printf("Wrong id\n");
124 con->dd_printf("Wrong size\n");
127 class cl_address_space *mem=
128 new cl_address_space(memid, start, size, width);
130 uc->address_spaces->add(mem);
138 * Command: memory createaddressdecoder
139 *----------------------------------------------------------------------------
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)
147 class cl_cmd_arg *params[5]= { cmdline->param(0),
152 class cl_memory *as= 0, *chip= 0;
153 t_addr as_begin= 0, as_end= 0, chip_begin= 0;
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;
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;
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;
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;
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;
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;
193 con->dd_printf("Syntax error.\n");
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");
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);
219 /* End of cmd.src/cmdmem.cc */