VirtualBox

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

Last change on this file since 296 was 1, checked in by vboxsync, 55 years ago

import

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