VirtualBox

source: vbox/trunk/src/VBox/Devices/build/vl_vbox.h@ 49983

Last change on this file since 49983 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.3 KB
Line 
1/* $Id: vl_vbox.h 44528 2013-02-04 14:27:54Z vboxsync $ */
2/** @file
3 * VBox vl.h Replacement.
4 *
5 * Avoid including this file whenever possible.
6 */
7
8/*
9 * Copyright (C) 2006-2011 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#ifndef ___build_vl_vbox_h
21#define ___build_vl_vbox_h
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#include <VBox/cdefs.h>
27#include <VBox/types.h>
28#include <VBox/param.h>
29#include <VBox/vmm/ssm.h>
30#include <VBox/vmm/tm.h>
31#include <VBox/vmm/pdm.h>
32#include <VBox/err.h>
33#include <VBox/pci.h>
34
35#include <iprt/string.h>
36
37#include "VBoxDD.h"
38
39RT_C_DECLS_BEGIN
40
41/*
42 * Misc macros.
43 */
44#define TARGET_PAGE_BITS (PAGE_SHIFT)
45#define TARGET_PAGE_SIZE (PAGE_SIZE)
46#define TARGET_PAGE_MASK (~PAGE_OFFSET_MASK)
47
48/*
49 * Necessary for pckbd and vga.
50 */
51#define TARGET_I386 1
52
53#ifndef glue
54# define _glue(x, y) x ## y
55# define glue(x, y) _glue(x, y)
56# define tostring(s) #s
57# define stringify(s) tostring(s)
58#endif
59
60#if defined(_MSC_VER) && !defined(__cplusplus)
61#define inline _inline
62#endif
63
64#ifdef _MSC_VER
65#define __func__ __FUNCTION__
66#endif
67
68
69/*
70 * Misc types.
71 */
72typedef RTGCPHYS target_phys_addr_t;
73typedef PCIDEVICE PCIDevice;
74typedef RTGCUINTREG target_ulong;
75
76
77
78/*
79 * Timers.
80 */
81#define QEMUTimerCB FNTMTIMERQEMU
82typedef struct TMTIMER QEMUTimer;
83#define rt_clock TMCLOCK_REAL
84#define vm_clock TMCLOCK_VIRTUAL
85#define ticks_per_sec TMCpuTicksPerSecond((PVM)cpu_single_env->pVM)
86#define qemu_get_clock(enmClock) TMR3Clock((PVM)cpu_single_env->pVM, enmClock)
87#define qemu_new_timer(clock, callback, user) (QEMUTimer *)TMR3TimerCreateExternal((PVM)cpu_single_env->pVM, clock, callback, user, __FUNCTION__ )
88#define qemu_free_timer(timer) TMR3TimerDestroy(timer)
89#define qemu_del_timer(timer) TMTimerStop(timer)
90#define qemu_mod_timer(timer, expire) TMTimerSet(timer, (uint64_t)expire)
91#define qemu_timer_pending(timer) TMTimerIsActive(timer)
92#define cpu_disable_ticks() ASMBreakpoint()
93#define cpu_enable_ticks() ASMBreakpoint()
94#define cpu_calibrate_ticks() do {} while (0)
95#define init_timers() do {} while (0)
96#define quit_timers() do {} while (0)
97
98
99#ifdef IN_RING3
100/*
101 * Saved state.
102 */
103typedef struct SSMHANDLE QEMUFile;
104
105#define qemu_put_buffer(f, pv, cb) SSMR3PutMem((f), (pv), (cb))
106#define qemu_put_byte(f, u8) SSMR3PutU8((f), (uint8_t)(u8))
107#define qemu_put_8s(f, pu8) SSMR3PutU8((f), *(pu8))
108#define qemu_put_be16s(f, pu16) SSMR3PutU16((f), *(pu16))
109#define qemu_put_be32s(f, pu32) SSMR3PutU32((f), *(pu32))
110#define qemu_put_be64s(f, pu64) SSMR3PutU64((f), *(pu64))
111#define qemu_put_be16(f, u16) SSMR3PutU16((f), (uint16_t)(u16))
112#define qemu_put_be32(f, u32) SSMR3PutU32((f), (uint32_t)(u32))
113#define qemu_put_be64(f, u64) SSMR3PutU64((f), (uint64_t)(u64))
114
115#define qemu_get_8s(f, pu8) SSMR3GetU8((f), (pu8))
116#define qemu_get_be16s(f, pu16) SSMR3GetU16((f), (pu16))
117#define qemu_get_be32s(f, pu32) SSMR3GetU32((f), (pu32))
118#define qemu_get_be64s(f, pu64) SSMR3GetU64((f), (pu64))
119
120DECLINLINE(int) qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size)
121{
122 int rc = SSMR3GetMem(f, buf, size);
123 return RT_SUCCESS(rc) ? size : 0;
124}
125
126DECLINLINE(int) qemu_get_byte(QEMUFile *f)
127{
128 uint8_t u8;
129 int rc = SSMR3GetU8(f, &u8);
130 return RT_SUCCESS(rc) ? (int)u8 : -1;
131}
132
133DECLINLINE(unsigned) qemu_get_be16(QEMUFile *f)
134{
135 uint16_t u16;
136 int rc = SSMR3GetU16(f, &u16);
137 return RT_SUCCESS(rc) ? u16 : ~0;
138}
139
140DECLINLINE(unsigned) qemu_get_be32(QEMUFile *f)
141{
142 uint32_t u32;
143 int rc = SSMR3GetU32(f, &u32);
144 return RT_SUCCESS(rc) ? u32 : ~0U;
145}
146
147DECLINLINE(int64_t) qemu_get_be64(QEMUFile *f)
148{
149 uint64_t u64;
150 int rc = SSMR3GetU64(f, &u64);
151 return RT_SUCCESS(rc) ? (int64_t)u64 : ~0;
152}
153
154#define qemu_put_timer(f, ts) TMR3TimerSave((ts), (f))
155#define qemu_get_timer(f, ts) TMR3TimerLoad((ts), (f))
156
157#endif /* IN_RING3 */
158
159
160/*
161 * Memory access.
162 */
163
164DECLINLINE(int) lduw_raw(void *ptr)
165{
166 uint8_t *p = (uint8_t *)ptr;
167 return p[0] | (p[1] << 8);
168}
169
170/*
171 * Misc.
172 */
173
174#ifdef _MSC_VER
175/**
176 * ffs -- vax ffs instruction
177 */
178inline int ffs(int mask)
179{
180 int bit;
181 if (mask == 0)
182 return(0);
183 for (bit = 1; !(mask & 1); bit++)
184 mask >>= 1;
185 return(bit);
186}
187#endif /* _MSC_VER */
188
189/* bswap.h */
190#ifdef _MSC_VER
191#ifndef LITTLE_ENDIAN
192#define LITTLE_ENDIAN 1234
193#endif
194#ifndef BYTE_ORDER
195#define BYTE_ORDER LITTLE_ENDIAN
196#endif
197
198static _inline uint16_t bswap_16(register uint16_t x)
199{
200 return ((uint16_t)( \
201 (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \
202 (((uint16_t)(x) & (uint16_t)0xff00U) >> 8) )); \
203}
204
205static _inline uint32_t bswap_32(register uint32_t x) \
206{ \
207 return ((uint32_t)( \
208 (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
209 (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \
210 (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \
211 (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24) )); \
212}
213
214static _inline uint64_t bswap_64(register uint64_t x) \
215{ \
216 return ((uint64_t)( \
217 (uint64_t)(((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \
218 (uint64_t)(((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
219 (uint64_t)(((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
220 (uint64_t)(((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
221 (uint64_t)(((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
222 (uint64_t)(((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
223 (uint64_t)(((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
224 (uint64_t)(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56) )); \
225}
226
227#else
228#undef __extension__
229#undef __attribute__
230
231#ifndef LITTLE_ENDIAN
232#define LITTLE_ENDIAN 1234
233#endif
234#ifndef BYTE_ORDER
235#define BYTE_ORDER LITTLE_ENDIAN
236#endif
237
238#define bswap_16(x) \
239(__extension__ ({ \
240 uint16_t __x = (x); \
241 ((uint16_t)( \
242 (((uint16_t)(__x) & (uint16_t)0x00ffU) << 8) | \
243 (((uint16_t)(__x) & (uint16_t)0xff00U) >> 8) )); \
244}))
245
246#define bswap_32(x) \
247(__extension__ ({ \
248 uint32_t __x = (x); \
249 ((uint32_t)( \
250 (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
251 (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
252 (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
253 (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
254}))
255
256#define bswap_64(x) \
257(__extension__ ({ \
258 uint64_t __x = (x); \
259 ((uint64_t)( \
260 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
261 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
262 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
263 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
264 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
265 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
266 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
267 (uint64_t)(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) )); \
268}))
269#endif
270
271
272#ifndef bswap16
273DECLINLINE(uint16_t) bswap16(uint16_t x)
274{
275 return bswap_16(x);
276}
277#endif
278
279#ifndef bswap32
280DECLINLINE(uint32_t) bswap32(uint32_t x)
281{
282 return bswap_32(x);
283}
284#endif
285
286#ifndef bswap64
287DECLINLINE(uint64_t) bswap64(uint64_t x)
288{
289 return bswap_64(x);
290}
291#endif
292
293DECLINLINE(void) bswap16s(uint16_t *s)
294{
295 *s = bswap16(*s);
296}
297
298DECLINLINE(void) bswap32s(uint32_t *s)
299{
300 *s = bswap32(*s);
301}
302
303DECLINLINE(void) bswap64s(uint64_t *s)
304{
305 *s = bswap64(*s);
306}
307
308#define le_bswap(v, size) (v)
309#define be_bswap(v, size) bswap ## size(v)
310#define le_bswaps(v, size)
311#define be_bswaps(p, size) *p = bswap ## size(*p);
312
313#define CPU_CONVERT(endian, size, type)\
314DECLINLINE(type) endian ## size ## _to_cpu(type v)\
315{\
316 return endian ## _bswap(v, size);\
317}\
318\
319DECLINLINE(type) cpu_to_ ## endian ## size(type v)\
320{\
321 return endian ## _bswap(v, size);\
322}\
323\
324DECLINLINE(void) endian ## size ## _to_cpus(type *p)\
325{\
326 NOREF(p); \
327 endian ## _bswaps(p, size)\
328}\
329\
330DECLINLINE(void) cpu_to_ ## endian ## size ## s(type *p)\
331{\
332 NOREF(p); \
333 endian ## _bswaps(p, size)\
334}\
335\
336DECLINLINE(type) endian ## size ## _to_cpup(const type *p)\
337{\
338 return endian ## size ## _to_cpu(*p);\
339}\
340\
341DECLINLINE(void) cpu_to_ ## endian ## size ## w(type *p, type v)\
342{\
343 *p = cpu_to_ ## endian ## size(v);\
344}
345
346CPU_CONVERT(be, 16, uint16_t)
347CPU_CONVERT(be, 32, uint32_t)
348CPU_CONVERT(be, 64, uint64_t)
349
350CPU_CONVERT(le, 16, uint16_t)
351CPU_CONVERT(le, 32, uint32_t)
352CPU_CONVERT(le, 64, uint64_t)
353
354
355#define cpu_to_le16wu(p, v) cpu_to_le16w(p, v)
356#define cpu_to_le32wu(p, v) cpu_to_le32w(p, v)
357#define le16_to_cpupu(p) le16_to_cpup(p)
358#define le32_to_cpupu(p) le32_to_cpup(p)
359
360#define cpu_to_be16wu(p, v) cpu_to_be16w(p, v)
361#define cpu_to_be32wu(p, v) cpu_to_be32w(p, v)
362
363#define cpu_to_32wu cpu_to_le32wu
364
365#undef le_bswap
366#undef be_bswap
367#undef le_bswaps
368#undef be_bswaps
369
370/* end of bswap.h */
371
372RT_C_DECLS_END
373
374#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette