- skip SMM init if already done at first boot time (fixes reboot failure)
[bochs-mirror.git] / memory / memory.h
blob9560645cf89619fc978db4b563753bedbc2463df
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: memory.h,v 1.43 2007/11/01 18:03:48 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 #ifndef BX_MEM_H
30 # define BX_MEM_H 1
32 #if BX_USE_MEM_SMF
33 // if static member functions on, then there is only one memory
34 # define BX_MEM_SMF static
35 # define BX_MEM_THIS BX_MEM(0)->
36 #else
37 # define BX_MEM_SMF
38 # define BX_MEM_THIS this->
39 #endif
41 class BX_CPU_C;
43 // alignment of memory vector, must be a power of 2
44 #define BX_MEM_VECTOR_ALIGN 4096
45 #define BIOSROMSZ (1 << 19) // 512KB BIOS ROM @0xfff80000, must be a power of 2
46 #define EXROMSIZE 0x20000 // ROMs 0xc0000-0xdffff (area 0xe0000-0xfffff=bios mapped)
47 #define BIOS_MASK (BIOSROMSZ-1)
48 #define EXROM_MASK (EXROMSIZE-1)
50 typedef bx_bool (*memory_handler_t)(unsigned long addr, unsigned long len, void *data, void *param);
52 struct memory_handler_struct {
53 struct memory_handler_struct *next;
54 void *param;
55 bx_phy_address begin;
56 bx_phy_address end;
57 memory_handler_t read_handler;
58 memory_handler_t write_handler;
61 #define SMRAM_CODE 1
62 #define SMRAM_DATA 2
64 class BOCHSAPI BX_MEM_C : public logfunctions {
65 private:
66 struct memory_handler_struct **memory_handlers;
67 bx_bool rom_present[65];
68 bx_bool pci_enabled;
69 bx_bool smram_available;
70 bx_bool smram_enable;
71 bx_bool smram_restricted;
73 #if BX_SUPPORT_MONITOR_MWAIT
74 bx_bool *monitor_active;
75 Bit32u n_monitors;
76 #endif
78 public:
79 Bit8u *actual_vector;
80 Bit8u *vector; // aligned correctly
81 size_t len;
82 size_t megabytes; // (len in Megabytes)
83 Bit8u *rom; // 512k BIOS rom space + 128k expansion rom space
84 Bit8u *bogus; // 4k for unexisting memory
85 #if BX_DEBUGGER
86 Bit8u *dbg_dirty_pages;
87 #endif
89 BX_MEM_C();
90 ~BX_MEM_C();
91 BX_MEM_SMF void alloc_vector_aligned (size_t bytes, size_t alignment) BX_CPP_AttrRegparmN(2);
92 BX_MEM_SMF void init_memory(int memsize);
93 BX_MEM_SMF void cleanup_memory(void);
94 BX_MEM_SMF void enable_smram(bx_bool enable, bx_bool restricted);
95 BX_MEM_SMF void disable_smram(void);
96 BX_MEM_SMF bx_bool is_smram_accessible(void);
97 BX_MEM_SMF void readPhysicalPage(BX_CPU_C *cpu, bx_phy_address addr,
98 unsigned len, void *data) BX_CPP_AttrRegparmN(3);
99 BX_MEM_SMF void writePhysicalPage(BX_CPU_C *cpu, bx_phy_address addr,
100 unsigned len, void *data) BX_CPP_AttrRegparmN(3);
101 BX_MEM_SMF void load_ROM(const char *path, bx_phy_address romaddress, Bit8u type);
102 BX_MEM_SMF void load_RAM(const char *path, bx_phy_address romaddress, Bit8u type);
103 BX_MEM_SMF Bit32u get_memory_in_k(void);
104 BX_MEM_SMF bx_bool dbg_fetch_mem(BX_CPU_C *cpu, bx_phy_address addr, unsigned len, Bit8u *buf);
105 BX_MEM_SMF bx_bool dbg_set_mem(bx_phy_address addr, unsigned len, Bit8u *buf);
106 BX_MEM_SMF bx_bool dbg_crc32(bx_phy_address addr1, bx_phy_address addr2, Bit32u *crc);
107 BX_MEM_SMF Bit8u* getHostMemAddr(BX_CPU_C *cpu, bx_phy_address a20Addr, unsigned op, unsigned access_type);
108 BX_MEM_SMF bx_bool registerMemoryHandlers(void *param, memory_handler_t read_handler,
109 memory_handler_t write_handler, bx_phy_address begin_addr, bx_phy_address end_addr);
110 BX_MEM_SMF bx_bool unregisterMemoryHandlers(memory_handler_t read_handler, memory_handler_t write_handler,
111 bx_phy_address begin_addr, bx_phy_address end_addr);
112 BX_MEM_SMF Bit32u get_num_allocated_pages(void);
114 #if BX_SUPPORT_MONITOR_MWAIT
115 void set_monitor(unsigned cpu);
116 void clear_monitor(unsigned cpu);
117 bx_bool is_monitor(bx_phy_address begin_addr, unsigned len);
118 void check_monitor(bx_phy_address addr, unsigned len);
119 #endif
121 BX_MEM_SMF void register_state(void);
124 #if BX_PROVIDE_CPU_MEMORY==1
125 BOCHSAPI extern BX_MEM_C bx_mem;
126 #endif
128 #if BX_DEBUGGER
129 # define BX_DBG_DIRTY_PAGE(page) BX_MEM(0)->dbg_dirty_pages[page] = 1;
130 #else
131 # define BX_DBG_DIRTY_PAGE(page)
132 #endif
134 #endif