]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/m68hc11/interp.c
sim: cris/m68hc11: move default endian/alignment to configure
[thirdparty/binutils-gdb.git] / sim / m68hc11 / interp.c
CommitLineData
5abb9efa 1/* interp.c -- Simulator for Motorola 68HC11/68HC12
32d0add0 2 Copyright (C) 1999-2015 Free Software Foundation, Inc.
63f36def 3 Written by Stephane Carrez (stcarrez@nerim.fr)
e0709f50
AC
4
5This file is part of GDB, the GNU debugger.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
4744ac1b
JB
9the Free Software Foundation; either version 3 of the License, or
10(at your option) any later version.
e0709f50
AC
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
4744ac1b
JB
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>. */
e0709f50
AC
19
20#include "sim-main.h"
21#include "sim-assert.h"
22#include "sim-hw.h"
23#include "sim-options.h"
24#include "hw-tree.h"
25#include "hw-device.h"
26#include "hw-ports.h"
77342e5e 27#include "elf32-m68hc1x.h"
e0709f50
AC
28
29#ifndef MONITOR_BASE
30# define MONITOR_BASE (0x0C000)
31# define MONITOR_SIZE (0x04000)
32#endif
33
34static void sim_get_info (SIM_DESC sd, char *cmd);
35
e0709f50
AC
36struct sim_info_list
37{
38 const char *name;
39 const char *device;
40};
41
81e09ed8 42struct sim_info_list dev_list_68hc11[] = {
e0709f50
AC
43 {"cpu", "/m68hc11"},
44 {"timer", "/m68hc11/m68hc11tim"},
45 {"sio", "/m68hc11/m68hc11sio"},
46 {"spi", "/m68hc11/m68hc11spi"},
47 {"eeprom", "/m68hc11/m68hc11eepr"},
48 {0, 0}
49};
50
81e09ed8
SC
51struct sim_info_list dev_list_68hc12[] = {
52 {"cpu", "/m68hc12"},
53 {"timer", "/m68hc12/m68hc12tim"},
54 {"sio", "/m68hc12/m68hc12sio"},
55 {"spi", "/m68hc12/m68hc12spi"},
56 {"eeprom", "/m68hc12/m68hc12eepr"},
57 {0, 0}
58};
59
60/* Cover function of sim_state_free to free the cpu buffers as well. */
61
62static void
63free_state (SIM_DESC sd)
64{
65 if (STATE_MODULES (sd) != NULL)
66 sim_module_uninstall (sd);
67
68 sim_state_free (sd);
69}
70
e0709f50
AC
71/* Give some information about the simulator. */
72static void
73sim_get_info (SIM_DESC sd, char *cmd)
74{
75 sim_cpu *cpu;
76
81e09ed8 77 cpu = STATE_CPU (sd, 0);
e0709f50
AC
78 if (cmd != 0 && (cmd[0] == ' ' || cmd[0] == '-'))
79 {
80 int i;
81 struct hw *hw_dev;
81e09ed8
SC
82 struct sim_info_list *dev_list;
83 const struct bfd_arch_info *arch;
84
85 arch = STATE_ARCHITECTURE (sd);
e0709f50
AC
86 cmd++;
87
81e09ed8
SC
88 if (arch->arch == bfd_arch_m68hc11)
89 dev_list = dev_list_68hc11;
90 else
91 dev_list = dev_list_68hc12;
92
e0709f50
AC
93 for (i = 0; dev_list[i].name; i++)
94 if (strcmp (cmd, dev_list[i].name) == 0)
95 break;
96
97 if (dev_list[i].name == 0)
98 {
99 sim_io_eprintf (sd, "Device '%s' not found.\n", cmd);
100 sim_io_eprintf (sd, "Valid devices: cpu timer sio eeprom\n");
101 return;
102 }
103 hw_dev = sim_hw_parse (sd, dev_list[i].device);
104 if (hw_dev == 0)
105 {
106 sim_io_eprintf (sd, "Device '%s' not found\n", dev_list[i].device);
107 return;
108 }
109 hw_ioctl (hw_dev, 23, 0);
110 return;
111 }
112
e0709f50
AC
113 cpu_info (sd, cpu);
114 interrupts_info (sd, &cpu->cpu_interrupts);
115}
116
117
118void
119sim_board_reset (SIM_DESC sd)
120{
121 struct hw *hw_cpu;
122 sim_cpu *cpu;
81e09ed8
SC
123 const struct bfd_arch_info *arch;
124 const char *cpu_type;
e0709f50
AC
125
126 cpu = STATE_CPU (sd, 0);
81e09ed8
SC
127 arch = STATE_ARCHITECTURE (sd);
128
e0709f50 129 /* hw_cpu = sim_hw_parse (sd, "/"); */
81e09ed8
SC
130 if (arch->arch == bfd_arch_m68hc11)
131 {
132 cpu->cpu_type = CPU_M6811;
133 cpu_type = "/m68hc11";
134 }
135 else
136 {
137 cpu->cpu_type = CPU_M6812;
138 cpu_type = "/m68hc12";
139 }
140
141 hw_cpu = sim_hw_parse (sd, cpu_type);
e0709f50
AC
142 if (hw_cpu == 0)
143 {
81e09ed8 144 sim_io_eprintf (sd, "%s cpu not found in device tree.", cpu_type);
e0709f50
AC
145 return;
146 }
147
148 cpu_reset (cpu);
149 hw_port_event (hw_cpu, 3, 0);
150 cpu_restart (cpu);
151}
152
39762100 153static int
81e09ed8
SC
154sim_hw_configure (SIM_DESC sd)
155{
156 const struct bfd_arch_info *arch;
157 struct hw *device_tree;
81e09ed8
SC
158 sim_cpu *cpu;
159
160 arch = STATE_ARCHITECTURE (sd);
161 if (arch == 0)
162 return 0;
163
164 cpu = STATE_CPU (sd, 0);
165 cpu->cpu_configured_arch = arch;
166 device_tree = sim_hw_parse (sd, "/");
167 if (arch->arch == bfd_arch_m68hc11)
168 {
169 cpu->cpu_interpretor = cpu_interp_m6811;
170 if (hw_tree_find_property (device_tree, "/m68hc11/reg") == 0)
171 {
172 /* Allocate core managed memory */
173
174 /* the monitor */
175 sim_do_commandf (sd, "memory region 0x%lx@%d,0x%lx",
176 /* MONITOR_BASE, MONITOR_SIZE */
177 0x8000, M6811_RAM_LEVEL, 0x8000);
178 sim_do_commandf (sd, "memory region 0x000@%d,0x8000",
179 M6811_RAM_LEVEL);
180 sim_hw_parse (sd, "/m68hc11/reg 0x1000 0x03F");
77342e5e
SC
181 if (cpu->bank_start < cpu->bank_end)
182 {
183 sim_do_commandf (sd, "memory region 0x%lx@%d,0x100000",
184 cpu->bank_virtual, M6811_RAM_LEVEL);
185 sim_hw_parse (sd, "/m68hc11/use_bank 1");
186 }
81e09ed8 187 }
77342e5e
SC
188 if (cpu->cpu_start_mode)
189 {
190 sim_hw_parse (sd, "/m68hc11/mode %s", cpu->cpu_start_mode);
191 }
81e09ed8
SC
192 if (hw_tree_find_property (device_tree, "/m68hc11/m68hc11sio/reg") == 0)
193 {
194 sim_hw_parse (sd, "/m68hc11/m68hc11sio/reg 0x2b 0x5");
195 sim_hw_parse (sd, "/m68hc11/m68hc11sio/backend stdio");
196 sim_hw_parse (sd, "/m68hc11 > cpu-reset reset /m68hc11/m68hc11sio");
197 }
198 if (hw_tree_find_property (device_tree, "/m68hc11/m68hc11tim/reg") == 0)
199 {
200 /* M68hc11 Timer configuration. */
201 sim_hw_parse (sd, "/m68hc11/m68hc11tim/reg 0x1b 0x5");
202 sim_hw_parse (sd, "/m68hc11 > cpu-reset reset /m68hc11/m68hc11tim");
827ec39a 203 sim_hw_parse (sd, "/m68hc11 > capture capture /m68hc11/m68hc11tim");
81e09ed8
SC
204 }
205
206 /* Create the SPI device. */
207 if (hw_tree_find_property (device_tree, "/m68hc11/m68hc11spi/reg") == 0)
208 {
209 sim_hw_parse (sd, "/m68hc11/m68hc11spi/reg 0x28 0x3");
210 sim_hw_parse (sd, "/m68hc11 > cpu-reset reset /m68hc11/m68hc11spi");
211 }
212 if (hw_tree_find_property (device_tree, "/m68hc11/nvram/reg") == 0)
213 {
214 /* M68hc11 persistent ram configuration. */
215 sim_hw_parse (sd, "/m68hc11/nvram/reg 0x0 256");
216 sim_hw_parse (sd, "/m68hc11/nvram/file m68hc11.ram");
217 sim_hw_parse (sd, "/m68hc11/nvram/mode save-modified");
218 /*sim_hw_parse (sd, "/m68hc11 > cpu-reset reset /m68hc11/pram"); */
219 }
220 if (hw_tree_find_property (device_tree, "/m68hc11/m68hc11eepr/reg") == 0)
221 {
222 sim_hw_parse (sd, "/m68hc11/m68hc11eepr/reg 0xb000 512");
223 sim_hw_parse (sd, "/m68hc11 > cpu-reset reset /m68hc11/m68hc11eepr");
224 }
dcceded2
SC
225 sim_hw_parse (sd, "/m68hc11 > port-a cpu-write-port /m68hc11");
226 sim_hw_parse (sd, "/m68hc11 > port-b cpu-write-port /m68hc11");
227 sim_hw_parse (sd, "/m68hc11 > port-c cpu-write-port /m68hc11");
228 sim_hw_parse (sd, "/m68hc11 > port-d cpu-write-port /m68hc11");
827ec39a 229 cpu->hw_cpu = sim_hw_parse (sd, "/m68hc11");
81e09ed8
SC
230 }
231 else
232 {
233 cpu->cpu_interpretor = cpu_interp_m6812;
234 if (hw_tree_find_property (device_tree, "/m68hc12/reg") == 0)
235 {
236 /* Allocate core external memory. */
237 sim_do_commandf (sd, "memory region 0x%lx@%d,0x%lx",
77342e5e 238 0x8000, M6811_RAM_LEVEL, 0x8000);
81e09ed8
SC
239 sim_do_commandf (sd, "memory region 0x000@%d,0x8000",
240 M6811_RAM_LEVEL);
77342e5e
SC
241 if (cpu->bank_start < cpu->bank_end)
242 {
243 sim_do_commandf (sd, "memory region 0x%lx@%d,0x100000",
244 cpu->bank_virtual, M6811_RAM_LEVEL);
245 sim_hw_parse (sd, "/m68hc12/use_bank 1");
246 }
81e09ed8
SC
247 sim_hw_parse (sd, "/m68hc12/reg 0x0 0x3FF");
248 }
249
250 if (!hw_tree_find_property (device_tree, "/m68hc12/m68hc12sio@1/reg"))
251 {
252 sim_hw_parse (sd, "/m68hc12/m68hc12sio@1/reg 0xC0 0x8");
253 sim_hw_parse (sd, "/m68hc12/m68hc12sio@1/backend stdio");
254 sim_hw_parse (sd, "/m68hc12 > cpu-reset reset /m68hc12/m68hc12sio@1");
255 }
81e09ed8
SC
256 if (hw_tree_find_property (device_tree, "/m68hc12/m68hc12tim/reg") == 0)
257 {
258 /* M68hc11 Timer configuration. */
259 sim_hw_parse (sd, "/m68hc12/m68hc12tim/reg 0x1b 0x5");
260 sim_hw_parse (sd, "/m68hc12 > cpu-reset reset /m68hc12/m68hc12tim");
dcceded2 261 sim_hw_parse (sd, "/m68hc12 > capture capture /m68hc12/m68hc12tim");
81e09ed8
SC
262 }
263
264 /* Create the SPI device. */
265 if (hw_tree_find_property (device_tree, "/m68hc12/m68hc12spi/reg") == 0)
266 {
267 sim_hw_parse (sd, "/m68hc12/m68hc12spi/reg 0x28 0x3");
268 sim_hw_parse (sd, "/m68hc12 > cpu-reset reset /m68hc12/m68hc12spi");
269 }
270 if (hw_tree_find_property (device_tree, "/m68hc12/nvram/reg") == 0)
271 {
272 /* M68hc11 persistent ram configuration. */
273 sim_hw_parse (sd, "/m68hc12/nvram/reg 0x2000 8192");
274 sim_hw_parse (sd, "/m68hc12/nvram/file m68hc12.ram");
275 sim_hw_parse (sd, "/m68hc12/nvram/mode save-modified");
276 }
277 if (hw_tree_find_property (device_tree, "/m68hc12/m68hc12eepr/reg") == 0)
278 {
279 sim_hw_parse (sd, "/m68hc12/m68hc12eepr/reg 0x0800 2048");
280 sim_hw_parse (sd, "/m68hc12 > cpu-reset reset /m68hc12/m68hc12eepr");
281 }
827ec39a 282
dcceded2
SC
283 sim_hw_parse (sd, "/m68hc12 > port-a cpu-write-port /m68hc12");
284 sim_hw_parse (sd, "/m68hc12 > port-b cpu-write-port /m68hc12");
285 sim_hw_parse (sd, "/m68hc12 > port-c cpu-write-port /m68hc12");
286 sim_hw_parse (sd, "/m68hc12 > port-d cpu-write-port /m68hc12");
827ec39a 287 cpu->hw_cpu = sim_hw_parse (sd, "/m68hc12");
81e09ed8 288 }
39762100 289 return 1;
81e09ed8
SC
290}
291
77342e5e
SC
292/* Get the memory bank parameters by looking at the global symbols
293 defined by the linker. */
81e09ed8 294static int
77342e5e 295sim_get_bank_parameters (SIM_DESC sd, bfd* abfd)
81e09ed8
SC
296{
297 sim_cpu *cpu;
77342e5e
SC
298 long symsize;
299 long symbol_count, i;
300 unsigned size;
301 asymbol** asymbols;
302 asymbol** current;
81e09ed8
SC
303
304 cpu = STATE_CPU (sd, 0);
305
77342e5e
SC
306 symsize = bfd_get_symtab_upper_bound (abfd);
307 if (symsize < 0)
308 {
309 sim_io_eprintf (sd, "Cannot read symbols of program");
310 return 0;
311 }
312 asymbols = (asymbol **) xmalloc (symsize);
313 symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
314 if (symbol_count < 0)
315 {
316 sim_io_eprintf (sd, "Cannot read symbols of program");
317 return 0;
318 }
319
320 size = 0;
321 for (i = 0, current = asymbols; i < symbol_count; i++, current++)
322 {
323 const char* name = bfd_asymbol_name (*current);
324
325 if (strcmp (name, BFD_M68HC11_BANK_START_NAME) == 0)
326 {
327 cpu->bank_start = bfd_asymbol_value (*current);
328 }
329 else if (strcmp (name, BFD_M68HC11_BANK_SIZE_NAME) == 0)
330 {
331 size = bfd_asymbol_value (*current);
332 }
333 else if (strcmp (name, BFD_M68HC11_BANK_VIRTUAL_NAME) == 0)
334 {
335 cpu->bank_virtual = bfd_asymbol_value (*current);
336 }
337 }
338 free (asymbols);
339
340 cpu->bank_end = cpu->bank_start + size;
341 cpu->bank_shift = 0;
342 for (; size > 1; size >>= 1)
343 cpu->bank_shift++;
344
345 return 0;
346}
347
348static int
349sim_prepare_for_program (SIM_DESC sd, bfd* abfd)
350{
351 sim_cpu *cpu;
352 int elf_flags = 0;
353
354 cpu = STATE_CPU (sd, 0);
39762100 355
81e09ed8
SC
356 if (abfd != NULL)
357 {
31c7c532 358 asection *s;
77342e5e
SC
359
360 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
361 elf_flags = elf_elfheader (abfd)->e_flags;
362
81e09ed8 363 cpu->cpu_elf_start = bfd_get_start_address (abfd);
31c7c532
SC
364 /* See if any section sets the reset address */
365 cpu->cpu_use_elf_start = 1;
366 for (s = abfd->sections; s && cpu->cpu_use_elf_start; s = s->next)
367 {
368 if (s->flags & SEC_LOAD)
369 {
370 bfd_size_type size;
371
84b11e2e 372 size = bfd_get_section_size (s);
31c7c532
SC
373 if (size > 0)
374 {
375 bfd_vma lma;
376
377 if (STATE_LOAD_AT_LMA_P (sd))
378 lma = bfd_section_lma (abfd, s);
379 else
380 lma = bfd_section_vma (abfd, s);
381
382 if (lma <= 0xFFFE && lma+size >= 0x10000)
383 cpu->cpu_use_elf_start = 0;
384 }
385 }
386 }
77342e5e
SC
387
388 if (elf_flags & E_M68HC12_BANKS)
389 {
390 if (sim_get_bank_parameters (sd, abfd) != 0)
391 sim_io_eprintf (sd, "Memory bank parameters are not initialized\n");
392 }
81e09ed8
SC
393 }
394
77342e5e
SC
395 if (!sim_hw_configure (sd))
396 return SIM_RC_FAIL;
397
81e09ed8
SC
398 /* reset all state information */
399 sim_board_reset (sd);
400
401 return SIM_RC_OK;
402}
403
bea3f671
MF
404static sim_cia
405m68hc11_pc_get (sim_cpu *cpu)
406{
407 return cpu_get_pc (cpu);
408}
409
410static void
411m68hc11_pc_set (sim_cpu *cpu, sim_cia pc)
412{
413 cpu_set_pc (cpu, pc);
414}
415
e1211e55
MF
416static int m68hc11_reg_fetch (SIM_CPU *, int, unsigned char *, int);
417static int m68hc11_reg_store (SIM_CPU *, int, unsigned char *, int);
418
e0709f50
AC
419SIM_DESC
420sim_open (SIM_OPEN_KIND kind, host_callback *callback,
77342e5e 421 bfd *abfd, char **argv)
e0709f50 422{
bea3f671 423 int i;
e0709f50
AC
424 SIM_DESC sd;
425 sim_cpu *cpu;
e0709f50
AC
426
427 sd = sim_state_alloc (kind, callback);
e0709f50
AC
428
429 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
430
bea3f671
MF
431 /* The cpu data is kept in a separately allocated chunk of memory. */
432 if (sim_cpu_alloc_all (sd, 1, /*cgen_cpu_max_extra_bytes ()*/0) != SIM_RC_OK)
433 {
434 free_state (sd);
435 return 0;
436 }
437
438 cpu = STATE_CPU (sd, 0);
439
e0709f50
AC
440 cpu_initialize (sd, cpu);
441
e0709f50 442 if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
81e09ed8
SC
443 {
444 free_state (sd);
445 return 0;
446 }
e0709f50
AC
447
448 /* getopt will print the error message so we just have to exit if this fails.
449 FIXME: Hmmm... in the case of gdb we need getopt to call
450 print_filtered. */
451 if (sim_parse_args (sd, argv) != SIM_RC_OK)
452 {
453 /* Uninstall the modules to avoid memory leaks,
454 file descriptor leaks, etc. */
81e09ed8 455 free_state (sd);
e0709f50
AC
456 return 0;
457 }
458
e0709f50
AC
459 /* Check for/establish the a reference program image. */
460 if (sim_analyze_program (sd,
461 (STATE_PROG_ARGV (sd) != NULL
462 ? *STATE_PROG_ARGV (sd)
463 : NULL), abfd) != SIM_RC_OK)
464 {
81e09ed8 465 free_state (sd);
e0709f50
AC
466 return 0;
467 }
468
469 /* Establish any remaining configuration options. */
470 if (sim_config (sd) != SIM_RC_OK)
471 {
81e09ed8 472 free_state (sd);
e0709f50
AC
473 return 0;
474 }
475
476 if (sim_post_argv_init (sd) != SIM_RC_OK)
477 {
478 /* Uninstall the modules to avoid memory leaks,
479 file descriptor leaks, etc. */
81e09ed8 480 free_state (sd);
e0709f50
AC
481 return 0;
482 }
77342e5e
SC
483 if (sim_prepare_for_program (sd, abfd) != SIM_RC_OK)
484 {
485 free_state (sd);
486 return 0;
487 }
e0709f50 488
bea3f671
MF
489 /* CPU specific initialization. */
490 for (i = 0; i < MAX_NR_PROCESSORS; ++i)
491 {
492 SIM_CPU *cpu = STATE_CPU (sd, i);
493
e1211e55
MF
494 CPU_REG_FETCH (cpu) = m68hc11_reg_fetch;
495 CPU_REG_STORE (cpu) = m68hc11_reg_store;
bea3f671
MF
496 CPU_PC_FETCH (cpu) = m68hc11_pc_get;
497 CPU_PC_STORE (cpu) = m68hc11_pc_set;
498 }
499
e0709f50
AC
500 return sd;
501}
502
e0709f50
AC
503/* Generic implementation of sim_engine_run that works within the
504 sim_engine setjmp/longjmp framework. */
505
506void
507sim_engine_run (SIM_DESC sd,
508 int next_cpu_nr, /* ignore */
509 int nr_cpus, /* ignore */
510 int siggnal) /* ignore */
511{
512 sim_cpu *cpu;
513
514 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
515 cpu = STATE_CPU (sd, 0);
516 while (1)
517 {
518 cpu_single_step (cpu);
519
520 /* process any events */
521 if (sim_events_tickn (sd, cpu->cpu_current_cycle))
522 {
523 sim_events_process (sd);
524 }
525 }
526}
527
e0709f50
AC
528void
529sim_info (SIM_DESC sd, int verbose)
530{
81e09ed8
SC
531 const char *cpu_type;
532 const struct bfd_arch_info *arch;
533
00d0c012
SC
534 /* Nothing to do if there is no verbose flag set. */
535 if (verbose == 0 && STATE_VERBOSE_P (sd) == 0)
536 return;
537
81e09ed8
SC
538 arch = STATE_ARCHITECTURE (sd);
539 if (arch->arch == bfd_arch_m68hc11)
540 cpu_type = "68HC11";
541 else
542 cpu_type = "68HC12";
543
e0709f50 544 sim_io_eprintf (sd, "Simulator info:\n");
81e09ed8 545 sim_io_eprintf (sd, " CPU Motorola %s\n", cpu_type);
e0709f50
AC
546 sim_get_info (sd, 0);
547 sim_module_info (sd, verbose || STATE_VERBOSE_P (sd));
548}
549
550SIM_RC
6b4a8935 551sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
e0709f50
AC
552 char **argv, char **env)
553{
81e09ed8 554 return sim_prepare_for_program (sd, abfd);
e0709f50
AC
555}
556
e1211e55
MF
557static int
558m68hc11_reg_fetch (SIM_CPU *cpu, int rn, unsigned char *memory, int length)
e0709f50 559{
e0709f50 560 uint16 val;
63f36def 561 int size = 2;
e0709f50 562
e0709f50
AC
563 switch (rn)
564 {
565 case A_REGNUM:
566 val = cpu_get_a (cpu);
63f36def 567 size = 1;
e0709f50
AC
568 break;
569
570 case B_REGNUM:
571 val = cpu_get_b (cpu);
63f36def 572 size = 1;
e0709f50
AC
573 break;
574
575 case D_REGNUM:
576 val = cpu_get_d (cpu);
577 break;
578
579 case X_REGNUM:
580 val = cpu_get_x (cpu);
581 break;
582
583 case Y_REGNUM:
584 val = cpu_get_y (cpu);
585 break;
586
587 case SP_REGNUM:
588 val = cpu_get_sp (cpu);
589 break;
590
591 case PC_REGNUM:
592 val = cpu_get_pc (cpu);
593 break;
594
595 case PSW_REGNUM:
596 val = cpu_get_ccr (cpu);
63f36def
SC
597 size = 1;
598 break;
599
600 case PAGE_REGNUM:
601 val = cpu_get_page (cpu);
602 size = 1;
e0709f50
AC
603 break;
604
e0709f50 605 default:
9830501b 606 val = 0;
e0709f50
AC
607 break;
608 }
00416c6e
SC
609 if (size == 1)
610 {
611 memory[0] = val;
612 }
613 else
614 {
615 memory[0] = val >> 8;
616 memory[1] = val & 0x0FF;
617 }
63f36def 618 return size;
e0709f50
AC
619}
620
e1211e55
MF
621static int
622m68hc11_reg_store (SIM_CPU *cpu, int rn, unsigned char *memory, int length)
e0709f50
AC
623{
624 uint16 val;
e0709f50
AC
625
626 val = *memory++;
627 if (length == 2)
628 val = (val << 8) | *memory;
629
630 switch (rn)
631 {
632 case D_REGNUM:
633 cpu_set_d (cpu, val);
634 break;
635
636 case A_REGNUM:
637 cpu_set_a (cpu, val);
63f36def 638 return 1;
e0709f50
AC
639
640 case B_REGNUM:
641 cpu_set_b (cpu, val);
63f36def 642 return 1;
e0709f50
AC
643
644 case X_REGNUM:
645 cpu_set_x (cpu, val);
646 break;
647
648 case Y_REGNUM:
649 cpu_set_y (cpu, val);
650 break;
651
652 case SP_REGNUM:
653 cpu_set_sp (cpu, val);
654 break;
655
656 case PC_REGNUM:
657 cpu_set_pc (cpu, val);
658 break;
659
660 case PSW_REGNUM:
661 cpu_set_ccr (cpu, val);
63f36def
SC
662 return 1;
663
664 case PAGE_REGNUM:
665 cpu_set_page (cpu, val);
666 return 1;
e0709f50 667
e0709f50 668 default:
e0709f50
AC
669 break;
670 }
671
672 return 2;
673}