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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [bochs486/] [memory/] [memory.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/////////////////////////////////////////////////////////////////////////
2
// $Id: memory.h 11556 2012-12-02 19:59:23Z vruppert $
3
/////////////////////////////////////////////////////////////////////////
4
//
5
//  Copyright (C) 2001-2009  The Bochs Project
6
//
7
//  I/O memory handlers API Copyright (C) 2003 by Frank Cornelis
8
//
9
//  This library is free software; you can redistribute it and/or
10
//  modify it under the terms of the GNU Lesser General Public
11
//  License as published by the Free Software Foundation; either
12
//  version 2 of the License, or (at your option) any later version.
13
//
14
//  This library is distributed in the hope that it will be useful,
15
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
//  Lesser General Public License for more details.
18
//
19
//  You should have received a copy of the GNU Lesser General Public
20
//  License along with this library; if not, write to the Free Software
21
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
22
//
23
/////////////////////////////////////////////////////////////////////////
24
 
25
#ifndef BX_MEM_H
26
#  define BX_MEM_H 1
27
 
28
#if BX_USE_MEM_SMF
29
// if static member functions on, then there is only one memory
30
#  define BX_MEM_SMF  static
31
#  define BX_MEM_THIS BX_MEM(0)->
32
#else
33
#  define BX_MEM_SMF
34
#  define BX_MEM_THIS this->
35
#endif
36
 
37
class BX_CPU_C;
38
 
39
                                       // 512K BIOS ROM @0xfff80000
40
#define BIOSROMSZ ((Bit32u)(1 << 21))  //   2M BIOS ROM @0xffe00000, must be a power of 2
41
#define EXROMSIZE  (0x20000)           // ROMs 0xc0000-0xdffff (area 0xe0000-0xfffff=bios mapped)
42
#define BIOS_MASK (BIOSROMSZ-1)
43
#define EXROM_MASK (EXROMSIZE-1)
44
 
45
#define BIOS_MAP_LAST128K(addr) (((addr) | 0xfff00000) & BIOS_MASK)
46
 
47
enum memory_area_t {
48
  BX_MEM_AREA_C0000 = 0,
49
  BX_MEM_AREA_C4000,
50
  BX_MEM_AREA_C8000,
51
  BX_MEM_AREA_CC000,
52
  BX_MEM_AREA_D0000,
53
  BX_MEM_AREA_D4000,
54
  BX_MEM_AREA_D8000,
55
  BX_MEM_AREA_DC000,
56
  BX_MEM_AREA_E0000,
57
  BX_MEM_AREA_E4000,
58
  BX_MEM_AREA_E8000,
59
  BX_MEM_AREA_EC000,
60
  BX_MEM_AREA_F0000
61
};
62
 
63
typedef bx_bool (*memory_handler_t)(bx_phy_address addr, unsigned len, void *data, void *param);
64
// return a pointer to 4K region containing <addr> or NULL if direct access is not allowed
65
// same format as getHostMemAddr method
66
typedef Bit8u* (*memory_direct_access_handler_t)(bx_phy_address addr, unsigned rw, void *param);
67
 
68
struct memory_handler_struct {
69
  struct memory_handler_struct *next;
70
  void *param;
71
  bx_phy_address begin;
72
  bx_phy_address end;
73
  Bit16u bitmap;
74
  memory_handler_t read_handler;
75
  memory_handler_t write_handler;
76
  memory_direct_access_handler_t da_handler;
77
};
78
 
79
#define SMRAM_CODE  1
80
#define SMRAM_DATA  2
81
 
82
class BOCHSAPI BX_MEM_C : public logfunctions {
83
private:
84
  struct memory_handler_struct **memory_handlers;
85
  bx_bool pci_enabled;
86
  bx_bool bios_write_enabled;
87
  bx_bool smram_available;
88
  bx_bool smram_enable;
89
  bx_bool smram_restricted;
90
 
91
  Bit64u  len, allocated;  // could be > 4G
92
  Bit8u   *actual_vector;
93
  Bit8u   *vector;   // aligned correctly
94
  Bit8u  **blocks;
95
  Bit8u   *rom;      // 512k BIOS rom space + 128k expansion rom space
96
  Bit8u   *bogus;    // 4k for unexisting memory
97
  bx_bool rom_present[65];
98
  bx_bool memory_type[13][2];
99
 
100
  Bit32u used_blocks;
101
#if BX_LARGE_RAMFILE
102
  static Bit8u * const swapped_out; // NULL; // (NULL - sizeof(Bit8u));
103
  Bit32u  next_swapout_idx;
104
  FILE    *overflow_file;
105
 
106
  BX_MEM_SMF void   read_block(Bit32u block);
107
#endif
108
 
109
public:
110
  BX_MEM_C();
111
 ~BX_MEM_C();
112
 
113
  BX_MEM_SMF Bit8u*  get_vector(bx_phy_address addr);
114
  BX_MEM_SMF void    init_memory(Bit64u guest, Bit64u host);
115
  BX_MEM_SMF void    cleanup_memory(void);
116
 
117
  BX_MEM_SMF void    enable_smram(bx_bool enable, bx_bool restricted);
118
  BX_MEM_SMF void    disable_smram(void);
119
  BX_MEM_SMF bx_bool is_smram_accessible(void);
120
 
121
  BX_MEM_SMF void    set_bios_write(bx_bool enabled);
122
  BX_MEM_SMF void    set_memory_type(memory_area_t area, bx_bool rw, bx_bool dram);
123
 
124
  BX_MEM_SMF Bit8u*  getHostMemAddr(BX_CPU_C *cpu, bx_phy_address addr, unsigned rw);
125
 
126
  // Note: accesses should always be contained within a single page
127
  BX_MEM_SMF void    readPhysicalPage(BX_CPU_C *cpu, bx_phy_address addr,
128
                                      unsigned len, void *data);
129
  BX_MEM_SMF void    writePhysicalPage(BX_CPU_C *cpu, bx_phy_address addr,
130
                                       unsigned len, void *data);
131
 
132
  BX_MEM_SMF void    dmaReadPhysicalPage(bx_phy_address addr, unsigned len, Bit8u *data);
133
  BX_MEM_SMF void    dmaWritePhysicalPage(bx_phy_address addr, unsigned len, Bit8u *data);
134
 
135
  BX_MEM_SMF void    load_ROM(const char *path, bx_phy_address romaddress, Bit8u type);
136
  BX_MEM_SMF void    load_RAM(const char *path, bx_phy_address romaddress, Bit8u type);
137
 
138
#if (BX_DEBUGGER || BX_DISASM || BX_GDBSTUB)
139
  BX_MEM_SMF bx_bool dbg_fetch_mem(BX_CPU_C *cpu, bx_phy_address addr, unsigned len, Bit8u *buf);
140
#endif
141
#if (BX_DEBUGGER || BX_GDBSTUB)
142
  BX_MEM_SMF bx_bool dbg_set_mem(bx_phy_address addr, unsigned len, Bit8u *buf);
143
  BX_MEM_SMF bx_bool dbg_crc32(bx_phy_address addr1, bx_phy_address addr2, Bit32u *crc);
144
#endif
145
 
146
  BX_MEM_SMF bx_bool registerMemoryHandlers(void *param, memory_handler_t read_handler,
147
                  memory_handler_t write_handler, memory_direct_access_handler_t da_handler,
148
                  bx_phy_address begin_addr, bx_phy_address end_addr);
149
  BX_MEM_SMF BX_CPP_INLINE bx_bool registerMemoryHandlers(void *param, memory_handler_t read_handler,
150
                  memory_handler_t write_handler,
151
                  bx_phy_address begin_addr, bx_phy_address end_addr)
152
  {
153
     return registerMemoryHandlers(param, read_handler, write_handler, NULL, begin_addr, end_addr);
154
  }
155
  BX_MEM_SMF bx_bool unregisterMemoryHandlers(void *param, bx_phy_address begin_addr, bx_phy_address end_addr);
156
 
157
  BX_MEM_SMF Bit64u  get_memory_len(void);
158
  BX_MEM_SMF void allocate_block(Bit32u index);
159
  BX_MEM_SMF Bit8u* alloc_vector_aligned(Bit32u bytes, Bit32u alignment);
160
 
161
#if BX_SUPPORT_MONITOR_MWAIT
162
  BX_MEM_SMF bx_bool is_monitor(bx_phy_address begin_addr, unsigned len);
163
  BX_MEM_SMF void    check_monitor(bx_phy_address addr, unsigned len);
164
#endif
165
 
166
  void register_state(void);
167
 
168
  friend void ramfile_save_handler(void *devptr, FILE *fp);
169
  friend Bit64s memory_param_save_handler(void *devptr, bx_param_c *param);
170
  friend void memory_param_restore_handler(void *devptr, bx_param_c *param, Bit64s val);
171
};
172
 
173
BOCHSAPI extern BX_MEM_C bx_mem;
174
 
175
// must be power of two
176
#define BX_MEM_BLOCK_LEN (1024*1024) /* 1M blocks */
177
 
178
/*
179
BX_CPP_INLINE Bit8u* BX_MEM_C::get_vector(bx_phy_address addr)
180
{
181
  return (BX_MEM_THIS vector + addr);
182
}
183
*/
184
 
185
BX_CPP_INLINE Bit8u* BX_MEM_C::get_vector(bx_phy_address addr)
186
{
187
  Bit32u block = (Bit32u)(addr / BX_MEM_BLOCK_LEN);
188
#if (BX_LARGE_RAMFILE)
189
  if (!BX_MEM_THIS blocks[block] || (BX_MEM_THIS blocks[block] == BX_MEM_THIS swapped_out))
190
#else
191
  if (!BX_MEM_THIS blocks[block])
192
#endif
193
    allocate_block(block);
194
 
195
  return BX_MEM_THIS blocks[block] + (Bit32u)(addr & (BX_MEM_BLOCK_LEN-1));
196
}
197
 
198
BX_CPP_INLINE Bit64u BX_MEM_C::get_memory_len(void)
199
{
200
  return (BX_MEM_THIS len);
201
}
202
 
203
#endif

powered by: WebSVN 2.1.0

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