source: trunk/packages/xen-3.1/xen-3.1/tools/firmware/rombios/32bit/rombios_compat.h @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 2.0 KB
Line 
1#ifndef ROMBIOS_COMPAT
2#define ROMBIOS_COMPAT
3
4/*
5 * Compatibility functions and structures for transitioning between
6 * 16 bit Bochs BIOS and 32 bit BIOS code.
7 */
8#include <stdint.h>
9
10#define ADDR_FROM_SEG_OFF(seg, off)  (void *)((((uint32_t)(seg)) << 4) + (off))
11
12typedef uint8_t  Bit8u;
13typedef uint16_t Bit16u;
14typedef uint32_t Bit32u;
15
16#define SetCF(x)   (x)->u.r8.flagsl |= 0x01
17#define SetZF(x)   (x)->u.r8.flagsl |= 0x40
18#define ClearCF(x) (x)->u.r8.flagsl &= 0xfe
19#define ClearZF(x) (x)->u.r8.flagsl &= 0xbf
20#define GetCF(x)   ((x)->u.r8.flagsl & 0x01)
21
22#define SET_CF()     *FLAGS |= 0x0001
23#define CLEAR_CF()   *FLAGS &= 0xfffe
24#define GET_CF()     (*FLAGS & 0x0001)
25
26#define SET_ZF()     *FLAGS |= 0x0040
27#define CLEAR_ZF()   *FLAGS &= 0xffbf
28
29
30typedef struct {
31 union {
32  struct {
33    Bit32u edi, esi, ebp, esp;
34    Bit32u ebx, edx, ecx, eax;
35    } r32;
36  struct {
37    Bit16u di, filler1, si, filler2, bp, filler3, sp, filler4;
38    Bit16u bx, filler5, dx, filler6, cx, filler7, ax, filler8;
39    } r16;
40  struct {
41    Bit32u filler[4];
42    Bit8u  bl, bh;
43    Bit16u filler1;
44    Bit8u  dl, dh;
45    Bit16u filler2;
46    Bit8u  cl, ch;
47    Bit16u filler3;
48    Bit8u  al, ah;
49    Bit16u filler4;
50    } r8;
51  } u;
52} __attribute__((packed)) pushad_regs_t;
53
54
55
56static inline Bit32u read_dword(Bit16u seg, Bit16u off)
57{
58        uint32_t *addr = (uint32_t *)ADDR_FROM_SEG_OFF(seg,off);
59        return *addr;
60}
61
62static inline Bit16u read_word(Bit16u seg, Bit16u off)
63{
64        uint16_t *addr = (uint16_t *)ADDR_FROM_SEG_OFF(seg,off);
65        return *addr;
66}
67
68static inline Bit8u read_byte(Bit16u seg, Bit16u off)
69{
70        uint8_t *addr = (uint8_t *)ADDR_FROM_SEG_OFF(seg,off);
71        return *addr;
72}
73
74static inline void write_dword(Bit16u seg, Bit16u off, Bit32u val)
75{
76        uint32_t *addr = (uint32_t *)ADDR_FROM_SEG_OFF(seg,off);
77        *addr = val;
78}
79
80static inline void write_word(Bit16u seg, Bit16u off, Bit16u val)
81{
82        uint16_t *addr = (uint16_t *)ADDR_FROM_SEG_OFF(seg,off);
83        *addr = val;
84}
85
86static inline void write_byte(Bit16u seg, Bit16u off, Bit8u val)
87{
88        uint8_t *addr = (uint8_t *)ADDR_FROM_SEG_OFF(seg,off);
89        *addr = val;
90}
91
92#endif
Note: See TracBrowser for help on using the repository browser.