* som.c (log2): Rename to exact_log2. Adjust all callers.
[deliverable/binutils-gdb.git] / sim / z8k / mem.c
CommitLineData
c906108c
SS
1/* memory support for Z8KSIM
2 Copyright (C) 1987, 1992 Free Software Foundation, Inc.
3
4This file is part of Z8KSIM
5
6Z8KSIM is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11Z8KSIM is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with Z8KZIM; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20#include "config.h"
21
22#include <ansidecl.h>
23
24#ifdef HAVE_STDLIB_H
25#include <stdlib.h>
26#endif
27
28#include "tm.h"
29#include "mem.h"
30#include "sim.h"
31
32#define INLINE
33static
34long
35sitoptr (si)
36long si;
37{
38 return ((si & 0xff000000) >> 8) | (si & 0xffff);
39}
40
41static
42unsigned short *
43get_page_and_offset (context, where, offset_ptr)
44 sim_state_type *context;
45 sim_phys_addr_type where;
46 int *offset_ptr;
47{
48 /* Is the page allocated ? */
49
50 if (context->memory == 0)
51 {
52 /* Must allocate 16MB in order to run Z8001 programs. */
53 context->memory = (unsigned short *)calloc(64*1024*64,4);
54 }
55
56 *offset_ptr = sitoptr(where);
57 return context->memory;
58}
59
60void
61sim_write_byte (context, where, what)
62 sim_state_type *context;
63 sim_phys_addr_type where;
64 int what;
65{
66 unsigned int offset;
67 char *ptr = (char *)get_page_and_offset (context, where, &offset);
68
69 ptr[offset] = what;
70}
71
72void
73sim_write_short (context, where, what)
74 sim_state_type *context;
75 sim_phys_addr_type where;
76 int what;
77{
78 int offset;
79 char *ptr = (char *)get_page_and_offset (context, where, &offset);
80
81 ptr[offset] = what >> 8;
82 ptr[offset + 1] = what;
83}
84
85void
86sim_write_long (context, where, what)
87 sim_state_type *context;
88 sim_phys_addr_type where;
89 int what;
90{
91 int offset;
92 char *ptr = (char *)get_page_and_offset (context, where, &offset);
93
94 ptr[offset] = what >> 24;
95 ptr[offset + 1] = what >> 16;
96 ptr[offset + 3] = what >> 8;
97 ptr[offset + 4] = what;
98}
99
100int
101sim_read_byte (context, where)
102 sim_state_type *context;
103 sim_phys_addr_type where;
104{
105 int offset;
106 char *ptr = (char *)get_page_and_offset (context, where, &offset);
107
108 return ptr[offset];
109}
110
111unsigned
112sim_read_short (context, where)
113 sim_state_type *context;
114 sim_phys_addr_type where;
115{
116 int what;
117 int offset;
118
119 char *ptr = (char *)get_page_and_offset (context, where, &offset);
120
121 what = (ptr[offset] << 8) | ptr[offset + 1];
122 return what;
123}
124
125
126
This page took 0.212933 seconds and 4 git commands to generate.