VirtualBox

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

Last change on this file since 1071 was 1019, checked in by vboxsync, 18 years ago

Converted serial card to PCI device

  • 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 struct SerialState SerialState;
79typedef struct {
80 int speed;
81 int parity;
82 int data_bits;
83 int stop_bits;
84} QEMUSerialSetParams;
85
86
87
88/*
89 * Timers.
90 */
91#define QEMUTimerCB FNTMTIMERQEMU
92typedef struct TMTIMER QEMUTimer;
93#define rt_clock TMCLOCK_REAL
94#define vm_clock TMCLOCK_VIRTUAL
95#define ticks_per_sec TMCpuTicksPerSecond((PVM)cpu_single_env->pVM)
96#define qemu_get_clock(enmClock) TMR3Clock((PVM)cpu_single_env->pVM, enmClock)
97#define qemu_new_timer(clock, callback, user) (QEMUTimer *)TMR3TimerCreateExternal((PVM)cpu_single_env->pVM, clock, callback, user, __FUNCTION__ )
98#define qemu_free_timer(timer) TMTimerDestroy(timer)
99#define qemu_del_timer(timer) TMTimerStop(timer)
100#define qemu_mod_timer(timer, expire) TMTimerSet(timer, (uint64_t)expire)
101#define qemu_timer_pending(timer) TMTimerIsActive(timer)
102#define cpu_disable_ticks() TMCpuTickPause((PVM)cpu_single_env->pVM)
103#define cpu_enable_ticks() TMCpuTickResume((PVM)cpu_single_env->pVM)
104#define cpu_calibrate_ticks() do {} while (0)
105#define init_timers() do {} while (0)
106#define quit_timers() do {} while (0)
107
108
109#ifdef IN_RING3
110/*
111 * Saved state.
112 */
113typedef struct SSMHANDLE QEMUFile;
114
115#define qemu_put_buffer(f, pv, cb) SSMR3PutMem((f), (pv), (cb))
116#define qemu_put_byte(f, u8) SSMR3PutU8((f), (uint8_t)(u8))
117#define qemu_put_8s(f, pu8) SSMR3PutU8((f), *(pu8))
118#define qemu_put_be16s(f, pu16) SSMR3PutU16((f), *(pu16))
119#define qemu_put_be32s(f, pu32) SSMR3PutU32((f), *(pu32))
120#define qemu_put_be64s(f, pu64) SSMR3PutU64((f), *(pu64))
121#define qemu_put_be16(f, u16) SSMR3PutU16((f), (uint16_t)(u16))
122#define qemu_put_be32(f, u32) SSMR3PutU32((f), (uint32_t)(u32))
123#define qemu_put_be64(f, u64) SSMR3PutU64((f), (uint64_t)(u64))
124
125#define qemu_get_8s(f, pu8) SSMR3GetU8((f), (pu8))
126#define qemu_get_be16s(f, pu16) SSMR3GetU16((f), (pu16))
127#define qemu_get_be32s(f, pu32) SSMR3GetU32((f), (pu32))
128#define qemu_get_be64s(f, pu64) SSMR3GetU64((f), (pu64))
129
130DECLINLINE(int) qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size)
131{
132 int rc = SSMR3GetMem(f, buf, size);
133 return VBOX_SUCCESS(rc) ? size : 0;
134}
135
136DECLINLINE(int) qemu_get_byte(QEMUFile *f)
137{
138 uint8_t u8;
139 int rc = SSMR3GetU8(f, &u8);
140 return VBOX_SUCCESS(rc) ? (int)u8 : -1;
141}
142
143DECLINLINE(unsigned) qemu_get_be16(QEMUFile *f)
144{
145 uint16_t u16;
146 int rc = SSMR3GetU16(f, &u16);
147 return VBOX_SUCCESS(rc) ? u16 : ~0;
148}
149
150DECLINLINE(unsigned) qemu_get_be32(QEMUFile *f)
151{
152 uint32_t u32;
153 int rc = SSMR3GetU32(f, &u32);
154 return VBOX_SUCCESS(rc) ? u32 : ~0;
155}
156
157DECLINLINE(int64_t) qemu_get_be64(QEMUFile *f)
158{
159 uint64_t u64;
160 int rc = SSMR3GetU64(f, &u64);
161 return VBOX_SUCCESS(rc) ? u64 : ~0;
162}
163
164#define qemu_put_timer(f, ts) TMR3TimerSave((ts), (f))
165#define qemu_get_timer(f, ts) TMR3TimerLoad((ts), (f))
166
167#endif /* IN_RING3 */
168
169
170/*
171 * Memory access.
172 */
173
174DECLINLINE(int) lduw_raw(void *ptr)
175{
176 uint8_t *p = (uint8_t *)ptr;
177 return p[0] | (p[1] << 8);
178}
179
180/*
181 * Misc.
182 */
183uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
184
185
186#ifdef _MSC_VER
187/**
188 * ffs -- vax ffs instruction
189 */
190inline int ffs(int mask)
191{
192 int bit;
193 if (mask == 0)
194 return(0);
195 for (bit = 1; !(mask & 1); bit++)
196 mask >>= 1;
197 return(bit);
198}
199#endif /* _MSC_VER */
200
201/* bswap.h */
202#ifdef _MSC_VER
203#ifndef LITTLE_ENDIAN
204#define LITTLE_ENDIAN 1234
205#endif
206#ifndef BYTE_ORDER
207#define BYTE_ORDER LITTLE_ENDIAN
208#endif
209
210static _inline uint16_t bswap_16(register uint16_t x)
211{
212 return ((uint16_t)( \
213 (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \
214 (((uint16_t)(x) & (uint16_t)0xff00U) >> 8) )); \
215}
216
217static _inline uint32_t bswap_32(register uint32_t x) \
218{ \
219 return ((uint32_t)( \
220 (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
221 (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \
222 (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \
223 (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24) )); \
224}
225
226static _inline uint64_t bswap_64(register uint64_t x) \
227{ \
228 return ((uint64_t)( \
229 (uint64_t)(((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \
230 (uint64_t)(((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
231 (uint64_t)(((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
232 (uint64_t)(((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
233 (uint64_t)(((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
234 (uint64_t)(((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
235 (uint64_t)(((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
236 (uint64_t)(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56) )); \
237}
238
239#else
240#undef __extension__
241#undef __attribute__
242
243#ifndef LITTLE_ENDIAN
244#define LITTLE_ENDIAN 1234
245#endif
246#ifndef BYTE_ORDER
247#define BYTE_ORDER LITTLE_ENDIAN
248#endif
249
250#define bswap_16(x) \
251(__extension__ ({ \
252 uint16_t __x = (x); \
253 ((uint16_t)( \
254 (((uint16_t)(__x) & (uint16_t)0x00ffU) << 8) | \
255 (((uint16_t)(__x) & (uint16_t)0xff00U) >> 8) )); \
256}))
257
258#define bswap_32(x) \
259(__extension__ ({ \
260 uint32_t __x = (x); \
261 ((uint32_t)( \
262 (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
263 (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
264 (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
265 (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
266}))
267
268#define bswap_64(x) \
269(__extension__ ({ \
270 uint64_t __x = (x); \
271 ((uint64_t)( \
272 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
273 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
274 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
275 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
276 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
277 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
278 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
279 (uint64_t)(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) )); \
280}))
281#endif
282
283
284#ifndef bswap16
285DECLINLINE(uint16_t) bswap16(uint16_t x)
286{
287 return bswap_16(x);
288}
289#endif
290
291#ifndef bswap32
292DECLINLINE(uint32_t) bswap32(uint32_t x)
293{
294 return bswap_32(x);
295}
296#endif
297
298#ifndef bswap64
299DECLINLINE(uint64_t) bswap64(uint64_t x)
300{
301 return bswap_64(x);
302}
303#endif
304
305DECLINLINE(void) bswap16s(uint16_t *s)
306{
307 *s = bswap16(*s);
308}
309
310DECLINLINE(void) bswap32s(uint32_t *s)
311{
312 *s = bswap32(*s);
313}
314
315DECLINLINE(void) bswap64s(uint64_t *s)
316{
317 *s = bswap64(*s);
318}
319
320#define le_bswap(v, size) (v)
321#define be_bswap(v, size) bswap ## size(v)
322#define le_bswaps(v, size)
323#define be_bswaps(p, size) *p = bswap ## size(*p);
324
325#define CPU_CONVERT(endian, size, type)\
326DECLINLINE(type) endian ## size ## _to_cpu(type v)\
327{\
328 return endian ## _bswap(v, size);\
329}\
330\
331DECLINLINE(type) cpu_to_ ## endian ## size(type v)\
332{\
333 return endian ## _bswap(v, size);\
334}\
335\
336DECLINLINE(void) endian ## size ## _to_cpus(type *p)\
337{\
338 endian ## _bswaps(p, size)\
339}\
340\
341DECLINLINE(void) cpu_to_ ## endian ## size ## s(type *p)\
342{\
343 endian ## _bswaps(p, size)\
344}\
345\
346DECLINLINE(type) endian ## size ## _to_cpup(const type *p)\
347{\
348 return endian ## size ## _to_cpu(*p);\
349}\
350\
351DECLINLINE(void) cpu_to_ ## endian ## size ## w(type *p, type v)\
352{\
353 *p = cpu_to_ ## endian ## size(v);\
354}
355
356CPU_CONVERT(be, 16, uint16_t)
357CPU_CONVERT(be, 32, uint32_t)
358CPU_CONVERT(be, 64, uint64_t)
359
360CPU_CONVERT(le, 16, uint16_t)
361CPU_CONVERT(le, 32, uint32_t)
362CPU_CONVERT(le, 64, uint64_t)
363
364
365#define cpu_to_le16wu(p, v) cpu_to_le16w(p, v)
366#define cpu_to_le32wu(p, v) cpu_to_le32w(p, v)
367#define le16_to_cpupu(p) le16_to_cpup(p)
368#define le32_to_cpupu(p) le32_to_cpup(p)
369
370#define cpu_to_be16wu(p, v) cpu_to_be16w(p, v)
371#define cpu_to_be32wu(p, v) cpu_to_be32w(p, v)
372
373#define cpu_to_32wu cpu_to_le32wu
374
375#undef le_bswap
376#undef be_bswap
377#undef le_bswaps
378#undef be_bswaps
379
380/* end of bswap.h */
381
382__END_DECLS
383
384#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