OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.3/] [sim/] [z8k/] [mem.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1181 sfurman
/* memory support for Z8KSIM
2
   Copyright (C) 1987, 1992 Free Software Foundation, Inc.
3
 
4
This file is part of Z8KSIM
5
 
6
Z8KSIM is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
Z8KSIM is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with Z8KZIM; if not, write to the Free Software
18
Foundation, 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
33
static
34
long
35
sitoptr (si)
36
long si;
37
{
38
  return ((si & 0xff000000) >> 8) | (si & 0xffff);
39
}
40
 
41
static
42
unsigned short *
43
get_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
 
60
void
61
sim_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
 
72
void
73
sim_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
 
85
void
86
sim_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
 
100
int
101
sim_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
 
111
unsigned
112
sim_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
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.