1 /////////////////////////////////////////////////////////////////////////
2 // $Id: memory.h,v 1.53 2008/12/05 22:34:42 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
5 // Copyright (C) 2001 MandrakeSoft S.A.
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // I/O memory handlers API Copyright (C) 2003 by Frank Cornelis
15 // This library is free software; you can redistribute it and/or
16 // modify it under the terms of the GNU Lesser General Public
17 // License as published by the Free Software Foundation; either
18 // version 2 of the License, or (at your option) any later version.
20 // This library is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 // Lesser General Public License for more details.
25 // You should have received a copy of the GNU Lesser General Public
26 // License along with this library; if not, write to the Free Software
27 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 /////////////////////////////////////////////////////////////////////////
35 // if static member functions on, then there is only one memory
36 # define BX_MEM_SMF static
37 # define BX_MEM_THIS BX_MEM(0)->
40 # define BX_MEM_THIS this->
45 // alignment of memory vector, must be a power of 2
46 #define BIOSROMSZ (1 << 19) // 512KB BIOS ROM @0xfff80000, must be a power of 2
47 #define EXROMSIZE 0x20000 // ROMs 0xc0000-0xdffff (area 0xe0000-0xfffff=bios mapped)
48 #define BIOS_MASK (BIOSROMSZ-1)
49 #define EXROM_MASK (EXROMSIZE-1)
51 typedef bx_bool (*memory_handler_t
)(bx_phy_address addr
, unsigned len
, void *data
, void *param
);
53 struct memory_handler_struct
{
54 struct memory_handler_struct
*next
;
58 memory_handler_t read_handler
;
59 memory_handler_t write_handler
;
65 class BOCHSAPI BX_MEM_C
: public logfunctions
{
67 struct memory_handler_struct
**memory_handlers
;
68 bx_bool rom_present
[65];
70 bx_bool smram_available
;
72 bx_bool smram_restricted
;
74 #if BX_SUPPORT_MONITOR_MWAIT
75 bx_bool
*monitor_active
;
81 Bit8u
*vector
; // aligned correctly
82 Bit8u
*rom
; // 512k BIOS rom space + 128k expansion rom space
83 Bit8u
*bogus
; // 4k for unexisting memory
87 Bit8u
*dbg_dirty_pages
;
93 BX_MEM_SMF Bit8u
* get_vector(void);
94 BX_MEM_SMF Bit8u
* get_vector(bx_phy_address addr
);
95 BX_MEM_SMF
void init_memory(Bit32u memsize
);
96 BX_MEM_SMF
void cleanup_memory(void);
97 BX_MEM_SMF
void enable_smram(bx_bool enable
, bx_bool restricted
);
98 BX_MEM_SMF
void disable_smram(void);
99 BX_MEM_SMF bx_bool
is_smram_accessible(void);
100 BX_MEM_SMF
void readPhysicalPage(BX_CPU_C
*cpu
, bx_phy_address addr
,
101 unsigned len
, void *data
);
102 BX_MEM_SMF
void writePhysicalPage(BX_CPU_C
*cpu
, bx_phy_address addr
,
103 unsigned len
, void *data
);
104 BX_MEM_SMF
void load_ROM(const char *path
, bx_phy_address romaddress
, Bit8u type
);
105 BX_MEM_SMF
void load_RAM(const char *path
, bx_phy_address romaddress
, Bit8u type
);
106 BX_MEM_SMF Bit32u
get_memory_in_k(void);
107 #if (BX_DEBUGGER || BX_DISASM || BX_GDBSTUB)
108 BX_MEM_SMF bx_bool
dbg_fetch_mem(BX_CPU_C
*cpu
, bx_phy_address addr
, unsigned len
, Bit8u
*buf
);
110 #if (BX_DEBUGGER || BX_GDBSTUB)
111 BX_MEM_SMF bx_bool
dbg_set_mem(bx_phy_address addr
, unsigned len
, Bit8u
*buf
);
112 BX_MEM_SMF bx_bool
dbg_crc32(bx_phy_address addr1
, bx_phy_address addr2
, Bit32u
*crc
);
114 BX_MEM_SMF Bit8u
* getHostMemAddr(BX_CPU_C
*cpu
, bx_phy_address a20Addr
, unsigned rw
);
115 BX_MEM_SMF bx_bool
registerMemoryHandlers(void *param
, memory_handler_t read_handler
,
116 memory_handler_t write_handler
, bx_phy_address begin_addr
, bx_phy_address end_addr
);
117 BX_MEM_SMF bx_bool
unregisterMemoryHandlers(memory_handler_t read_handler
, memory_handler_t write_handler
,
118 bx_phy_address begin_addr
, bx_phy_address end_addr
);
119 BX_MEM_SMF Bit32u
get_num_allocated_pages(void);
120 BX_MEM_SMF Bit32u
get_memory_len(void);
122 #if BX_SUPPORT_MONITOR_MWAIT
123 BX_MEM_SMF
void set_monitor(unsigned cpu
);
124 BX_MEM_SMF
void clear_monitor(unsigned cpu
);
125 BX_MEM_SMF bx_bool
is_monitor(bx_phy_address begin_addr
, unsigned len
);
126 BX_MEM_SMF
void check_monitor(bx_phy_address addr
, unsigned len
);
129 BX_MEM_SMF
void register_state(void);
132 #if BX_PROVIDE_CPU_MEMORY
133 BOCHSAPI
extern BX_MEM_C bx_mem
;
136 BX_CPP_INLINE Bit8u
* BX_MEM_C::get_vector(void)
138 return (BX_MEM_THIS vector
);
141 BX_CPP_INLINE Bit8u
* BX_MEM_C::get_vector(bx_phy_address addr
)
143 return (BX_MEM_THIS vector
+ addr
);
146 BX_CPP_INLINE Bit32u
BX_MEM_C::get_memory_len(void)
148 return(BX_MEM_THIS len
);
151 BX_CPP_INLINE Bit32u
BX_MEM_C::get_memory_in_k(void)
153 return(BX_MEM_THIS len
/ 1024);
156 BX_CPP_INLINE Bit32u
BX_MEM_C::get_num_allocated_pages(void)
158 return(BX_MEM_THIS len
>> 12);
162 #define BX_DBG_DIRTY_PAGE(page) BX_MEM(0)->dbg_dirty_pages[page] = 1;