File: cmdmem.cc

package info (click to toggle)
cc1111 2.9.0-4
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 38,692 kB
  • ctags: 132,262
  • sloc: ansic: 442,650; cpp: 37,006; sh: 10,334; makefile: 5,511; asm: 5,279; yacc: 2,953; lisp: 1,524; perl: 807; awk: 493; python: 468; lex: 447
file content (219 lines) | stat: -rw-r--r-- 6,846 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
 * Simulator of microcontrollers (cmd.src/cmdmem.cc)
 *
 * Copyright (C) 2001,01 Drotos Daniel, Talker Bt.
 *
 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
 *
 */

/* This file is part of microcontroller simulator: ucsim.

UCSIM is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

UCSIM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with UCSIM; see the file COPYING.  If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/*@1@*/

// prj
#include "globals.h"
#include "utils.h"

// sim
#include "simcl.h"

// local
#include "cmdmemcl.h"


/*
 * Command: memory createchip
 *----------------------------------------------------------------------------
 */

//int
//cl_conf_addmem_cmd::do_work(class cl_sim *sim,
//                          class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_memory_createchip_cmd)
{
  class cl_cmd_arg *params[4]= { cmdline->param(0),
                                 cmdline->param(1),
                                 cmdline->param(2),
                                 cmdline->param(3) };
  char *memid= NULL;
  int size= -1;
  int width= 8;

  if (cmdline->syntax_match(uc, STRING NUMBER)) {
    memid= params[0]->value.string.string;
    size= params[1]->value.number;
  }
  else if (cmdline->syntax_match(uc, STRING NUMBER NUMBER)) {
    memid= params[0]->value.string.string;
    size= params[1]->value.number;
    width= params[2]->value.number;
  }
  else
    con->dd_printf("Syntax error.\n");

  if (!memid ||
      !*memid)
    con->dd_printf("Wrong id\n");
  else if (size < 1)
    con->dd_printf("Wrong size\n");
  else
    {
      class cl_memory *mem= new cl_memory_chip(memid, size, width);
      mem->init();
      uc->memchips->add(mem);
      mem->set_uc(uc);
    }
  return(DD_FALSE);
}


/*
 * Command: memory createaddressspace
 *----------------------------------------------------------------------------
 */

//int
//cl_conf_addmem_cmd::do_work(class cl_sim *sim,
//                          class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_memory_createaddressspace_cmd)
{
  class cl_cmd_arg *params[4]= { cmdline->param(0),
                                 cmdline->param(1),
                                 cmdline->param(2),
                                 cmdline->param(3) };
  char *memid= NULL;
  int start= 0, size= -1, width= 8;

  if (cmdline->syntax_match(uc, STRING NUMBER)) {
    memid= params[0]->value.string.string;
    size= params[1]->value.number;
  }
  else if (cmdline->syntax_match(uc, STRING NUMBER NUMBER)) {
    memid= params[0]->value.string.string;
    start= params[1]->value.number;
    size= params[2]->value.number;
  }
  else if (cmdline->syntax_match(uc, STRING NUMBER NUMBER NUMBER)) {
    memid= params[0]->value.string.string;
    start= params[1]->value.number;
    size= params[2]->value.number;
    width= params[3]->value.number;
  }
  else
    con->dd_printf("Syntax error.\n");

  if (!memid ||
      !*memid)
    con->dd_printf("Wrong id\n");
  else if (size < 1)
    con->dd_printf("Wrong size\n");
  else
    {
      class cl_address_space *mem=
        new cl_address_space(memid, start, size, width);
      mem->init();
      uc->address_spaces->add(mem);
      mem->set_uc(uc);
    }
  return(DD_FALSE);
}


/*
 * Command: memory createaddressdecoder
 *----------------------------------------------------------------------------
 */

//int
//cl_conf_addmem_cmd::do_work(class cl_sim *sim,
//                          class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_memory_createaddressdecoder_cmd)
{
  class cl_cmd_arg *params[5]= { cmdline->param(0),
                                 cmdline->param(1),
                                 cmdline->param(2),
                                 cmdline->param(3),
                                 cmdline->param(4) };
  class cl_memory *as= 0, *chip= 0;
  t_addr as_begin= 0, as_end= 0, chip_begin= 0;

  if (cmdline->syntax_match(uc, MEMORY MEMORY)) {
    as= params[0]->value.memory.memory;
    as_end= as->highest_valid_address();
    chip= params[1]->value.memory.memory;
  }
  else if (cmdline->syntax_match(uc, MEMORY MEMORY NUMBER)) {
    as= params[0]->value.memory.memory;
    as_end= as->highest_valid_address();
    chip= params[1]->value.memory.memory;
    chip_begin= params[2]->value.number;
  }
  else if (cmdline->syntax_match(uc, MEMORY NUMBER MEMORY)) {
    as= params[0]->value.memory.memory;
    as_begin= params[1]->value.number;
    as_end= as->highest_valid_address();
    chip= params[2]->value.memory.memory;
  }
  else if (cmdline->syntax_match(uc, MEMORY NUMBER MEMORY NUMBER)) {
    as= params[0]->value.memory.memory;
    as_begin= params[1]->value.number;
    as_end= as->highest_valid_address();
    chip= params[2]->value.memory.memory;
    chip_begin= params[3]->value.number;
  }
  else if (cmdline->syntax_match(uc, MEMORY NUMBER NUMBER MEMORY)) {
    as= params[0]->value.memory.memory;
    as_begin= params[1]->value.number;
    as_end= params[2]->value.number;
    chip= params[3]->value.memory.memory;
  }
  else if (cmdline->syntax_match(uc, MEMORY NUMBER NUMBER MEMORY NUMBER)) {
    as= params[0]->value.memory.memory;
    as_begin= params[1]->value.number;
    as_end= params[2]->value.number;
    chip= params[3]->value.memory.memory;
    chip_begin= params[4]->value.number;
  }
  else
    con->dd_printf("Syntax error.\n");

  if (!as->is_address_space())
    con->dd_printf("%s is not an address space\n", as->get_name("unknown"));
  else if (!chip->is_chip())
    con->dd_printf("%s is not a memory chip\n", chip->get_name("unknown"));
  else if (as_begin > as_end)
    con->dd_printf("Wrong address area specification\n");
  else if (chip_begin >= chip->get_size())
    con->dd_printf("Wrong chip area specification\n");
  else if (as_begin < as->start_address ||
           as_end > as->highest_valid_address())
    con->dd_printf("Specified area is out of address space\n");
  else if (as_end-as_begin > chip->get_size()-chip_begin)
    con->dd_printf("Specified area is out of chip size\n");
  else
    {
      class cl_address_decoder *d=
        new cl_address_decoder(as, chip, as_begin, as_end, chip_begin);
      ((class cl_address_space *)as)->decoders->add(d);
      d->activate(con);
    }
  return(DD_FALSE);
}


/* End of cmd.src/cmdmem.cc */