VirtualBox

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

Last change on this file since 27968 was 22584, checked in by vboxsync, 15 years ago

Devices: tab

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