- added instructions how to update the online documentation
[bochs-mirror.git] / memory / memory.h
blob3013e0737b73bc9ccc1a1bde6d10368be5af1ad9
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: memory.h,v 1.53 2008/12/05 22:34:42 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2001 MandrakeSoft S.A.
6 //
7 // MandrakeSoft S.A.
8 // 43, rue d'Aboukir
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 /////////////////////////////////////////////////////////////////////////
31 #ifndef BX_MEM_H
32 # define BX_MEM_H 1
34 #if BX_USE_MEM_SMF
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)->
38 #else
39 # define BX_MEM_SMF
40 # define BX_MEM_THIS this->
41 #endif
43 class BX_CPU_C;
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;
55 void *param;
56 bx_phy_address begin;
57 bx_phy_address end;
58 memory_handler_t read_handler;
59 memory_handler_t write_handler;
62 #define SMRAM_CODE 1
63 #define SMRAM_DATA 2
65 class BOCHSAPI BX_MEM_C : public logfunctions {
66 private:
67 struct memory_handler_struct **memory_handlers;
68 bx_bool rom_present[65];
69 bx_bool pci_enabled;
70 bx_bool smram_available;
71 bx_bool smram_enable;
72 bx_bool smram_restricted;
74 #if BX_SUPPORT_MONITOR_MWAIT
75 bx_bool *monitor_active;
76 Bit32u n_monitors;
77 #endif
79 Bit32u len;
80 Bit8u *actual_vector;
81 Bit8u *vector; // aligned correctly
82 Bit8u *rom; // 512k BIOS rom space + 128k expansion rom space
83 Bit8u *bogus; // 4k for unexisting memory
85 public:
86 #if BX_DEBUGGER
87 Bit8u *dbg_dirty_pages;
88 #endif
90 BX_MEM_C();
91 ~BX_MEM_C();
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);
109 #endif
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);
113 #endif
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);
127 #endif
129 BX_MEM_SMF void register_state(void);
132 #if BX_PROVIDE_CPU_MEMORY
133 BOCHSAPI extern BX_MEM_C bx_mem;
134 #endif
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);
161 #if BX_DEBUGGER
162 #define BX_DBG_DIRTY_PAGE(page) BX_MEM(0)->dbg_dirty_pages[page] = 1;
163 #endif
165 #endif