Debian Codegraph @

include/mem.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2002-2010 The DOSBox Team
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #ifndef DOSBOX_MEM_H
20 #define DOSBOX_MEM_H
21
22 #ifndef DOSBOX_DOSBOX_H
23 #include "dosbox.h"
24 #endif
25
26 typedef Bit32u PhysPt;
27 typedef Bit8u * HostPt;
28 typedef Bit32u RealPt;
29
30 typedef Bit32s MemHandle;
31
32 #define MEM_PAGESIZE 4096
33
34 extern HostPt MemBase;
35 HostPt GetMemBase(void);
36
37 bool MEM_A20_Enabled(void);
38 void MEM_A20_Enable(bool enable);
39
40 /* Memory management / EMS mapping */
41 HostPt MEM_GetBlockPage(void);
42 Bitu MEM_FreeTotal(void); //Free 4 kb pages
43 Bitu MEM_FreeLargest(void); //Largest free 4 kb pages block
44 Bitu MEM_TotalPages(void); //Total amount of 4 kb pages
45 Bitu MEM_AllocatedPages(MemHandle handle); // amount of allocated pages of handle
46 MemHandle MEM_AllocatePages(Bitu pages,bool sequence);
47 MemHandle MEM_GetNextFreePage(void);
48 PhysPt MEM_AllocatePage(void);
49 void MEM_ReleasePages(MemHandle handle);
50 bool MEM_ReAllocatePages(MemHandle & handle,Bitu pages,bool sequence);
51
52 MemHandle MEM_NextHandle(MemHandle handle);
53 MemHandle MEM_NextHandleAt(MemHandle handle,Bitu where);
54
55 /*
56 The folowing six functions are used everywhere in the end so these should be changed for
57 Working on big or little endian machines
58 */
59
60 #if defined(WORDS_BIGENDIAN) || !defined(C_UNALIGNED_MEMORY)
61
62 static INLINE Bit8u host_readb(HostPt off) {
63 return off[0];
64 }
65 static INLINE Bit16u host_readw(HostPt off) {
66 return off[0] | (off[1] << 8);
67 }
68 static INLINE Bit32u host_readd(HostPt off) {
69 return off[0] | (off[1] << 8) | (off[2] << 16) | (off[3] << 24);
70 }
71 static INLINE void host_writeb(HostPt off,Bit8u val) {
72 off[0]=val;
73 }
74 static INLINE void host_writew(HostPt off,Bit16u val) {
75 off[0]=(Bit8u)(val);
76 off[1]=(Bit8u)(val >> 8);
77 }
78 static INLINE void host_writed(HostPt off,Bit32u val) {
79 off[0]=(Bit8u)(val);
80 off[1]=(Bit8u)(val >> 8);
81 off[2]=(Bit8u)(val >> 16);
82 off[3]=(Bit8u)(val >> 24);
83 }
84
85 #else
86
87 static INLINE Bit8u host_readb(HostPt off) {
88 return *(Bit8u *)off;
89 }
90 static INLINE Bit16u host_readw(HostPt off) {
91 return *(Bit16u *)off;
92 }
93 static INLINE Bit32u host_readd(HostPt off) {
94 return *(Bit32u *)off;
95 }
96 static INLINE void host_writeb(HostPt off,Bit8u val) {
97 *(Bit8u *)(off)=val;
98 }
99 static INLINE void host_writew(HostPt off,Bit16u val) {
100 *(Bit16u *)(off)=val;
101 }
102 static INLINE void host_writed(HostPt off,Bit32u val) {
103 *(Bit32u *)(off)=val;
104 }
105
106 #endif
107
108
109 static INLINE void var_write(Bit8u * var, Bit8u val) {
110 host_writeb((HostPt)var, val);
111 }
112
113 static INLINE void var_write(Bit16u * var, Bit16u val) {
114 host_writew((HostPt)var, val);
115 }
116
117 static INLINE void var_write(Bit32u * var, Bit32u val) {
118 host_writed((HostPt)var, val);
119 }
120
121 /* The Folowing six functions are slower but they recognize the paged memory system */
122
123 Bit8u mem_readb(PhysPt pt);
124 Bit16u mem_readw(PhysPt pt);
125 Bit32u mem_readd(PhysPt pt);
126
127 void mem_writeb(PhysPt pt,Bit8u val);
128 void mem_writew(PhysPt pt,Bit16u val);
129 void mem_writed(PhysPt pt,Bit32u val);
130
131 static INLINE void phys_writeb(PhysPt addr,Bit8u val) {
132 host_writeb(MemBase+addr,val);
133 }
134 static INLINE void phys_writew(PhysPt addr,Bit16u val){
135 host_writew(MemBase+addr,val);
136 }
137 static INLINE void phys_writed(PhysPt addr,Bit32u val){
138 host_writed(MemBase+addr,val);
139 }
140
141 static INLINE Bit8u phys_readb(PhysPt addr) {
142 return host_readb(MemBase+addr);
143 }
144 static INLINE Bit16u phys_readw(PhysPt addr){
145 return host_readw(MemBase+addr);
146 }
147 static INLINE Bit32u phys_readd(PhysPt addr){
148 return host_readd(MemBase+addr);
149 }
150
151 /* These don't check for alignment, better be sure it's correct */
152
153 void MEM_BlockWrite(PhysPt pt,void const * const data,Bitu size);
154 void MEM_BlockRead(PhysPt pt,void * data,Bitu size);
155 void MEM_BlockCopy(PhysPt dest,PhysPt src,Bitu size);
156 void MEM_StrCopy(PhysPt pt,char * data,Bitu size);
157
158 void mem_memcpy(PhysPt dest,PhysPt src,Bitu size);
159 Bitu mem_strlen(PhysPt pt);
160 void mem_strcpy(PhysPt dest,PhysPt src);
161
162 /* The folowing functions are all shortcuts to the above functions using physical addressing */
163
164 static INLINE Bit8u real_readb(Bit16u seg,Bit16u off) {
165 return mem_readb((seg<<4)+off);
166 }
167 static INLINE Bit16u real_readw(Bit16u seg,Bit16u off) {
168 return mem_readw((seg<<4)+off);
169 }
170 static INLINE Bit32u real_readd(Bit16u seg,Bit16u off) {
171 return mem_readd((seg<<4)+off);
172 }
173
174 static INLINE void real_writeb(Bit16u seg,Bit16u off,Bit8u val) {
175 mem_writeb(((seg<<4)+off),val);
176 }
177 static INLINE void real_writew(Bit16u seg,Bit16u off,Bit16u val) {
178 mem_writew(((seg<<4)+off),val);
179 }
180 static INLINE void real_writed(Bit16u seg,Bit16u off,Bit32u val) {
181 mem_writed(((seg<<4)+off),val);
182 }
183
184
185 static INLINE Bit16u RealSeg(RealPt pt) {
186 return (Bit16u)(pt>>16);
187 }
188
189 static INLINE Bit16u RealOff(RealPt pt) {
190 return (Bit16u)(pt&0xffff);
191 }
192
193 static INLINE PhysPt Real2Phys(RealPt pt) {
194 return (RealSeg(pt)<<4) +RealOff(pt);
195 }
196
197 static INLINE PhysPt PhysMake(Bit16u seg,Bit16u off) {
198 return (seg<<4)+off;
199 }
200
201 static INLINE RealPt RealMake(Bit16u seg,Bit16u off) {
202 return (seg<<16)+off;
203 }
204
205 static INLINE void RealSetVec(Bit8u vec,RealPt pt) {
206 mem_writed(vec<<2,pt);
207 }
208
209 static INLINE void RealSetVec(Bit8u vec,RealPt pt,RealPt &old) {
210 old = mem_readd(vec<<2);
211 mem_writed(vec<<2,pt);
212 }
213
214 static INLINE RealPt RealGetVec(Bit8u vec) {
215 return mem_readd(vec<<2);
216 }
217
218 #endif
219