| 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 |
|
| 9 |
#define ADDR_FROM_SEG_OFF(seg, off) (void *)((((uint32_t)(seg)) << 4) + (off)) |
| 10 |
|
| 11 |
#include <stdint.h> |
| 12 |
|
| 13 |
typedef uint8_t Bit8u; |
| 14 |
typedef uint16_t Bit16u; |
| 15 |
typedef uint32_t Bit32u; |
| 16 |
|
| 17 |
#define SetCF(x) (x)->u.r8.flagsl |= 0x01 |
| 18 |
#define SetZF(x) (x)->u.r8.flagsl |= 0x40 |
| 19 |
#define ClearCF(x) (x)->u.r8.flagsl &= 0xfe |
| 20 |
#define ClearZF(x) (x)->u.r8.flagsl &= 0xbf |
| 21 |
#define GetCF(x) ((x)->u.r8.flagsl & 0x01) |
| 22 |
|
| 23 |
#define SET_CF() *FLAGS |= 0x0001 |
| 24 |
#define CLEAR_CF() *FLAGS &= 0xfffe |
| 25 |
#define GET_CF() (*FLAGS & 0x0001) |
| 26 |
|
| 27 |
#define SET_ZF() *FLAGS |= 0x0040 |
| 28 |
#define CLEAR_ZF() *FLAGS &= 0xffbf |
| 29 |
|
| 30 |
|
| 31 |
typedef struct { |
| 32 |
union { |
| 33 |
struct { |
| 34 |
Bit32u edi, esi, ebp, esp; |
| 35 |
Bit32u ebx, edx, ecx, eax; |
| 36 |
} r32; |
| 37 |
struct { |
| 38 |
Bit16u di, filler1, si, filler2, bp, filler3, sp, filler4; |
| 39 |
Bit16u bx, filler5, dx, filler6, cx, filler7, ax, filler8; |
| 40 |
} r16; |
| 41 |
struct { |
| 42 |
Bit32u filler[4]; |
| 43 |
Bit8u bl, bh; |
| 44 |
Bit16u filler1; |
| 45 |
Bit8u dl, dh; |
| 46 |
Bit16u filler2; |
| 47 |
Bit8u cl, ch; |
| 48 |
Bit16u filler3; |
| 49 |
Bit8u al, ah; |
| 50 |
Bit16u filler4; |
| 51 |
} r8; |
| 52 |
} u; |
| 53 |
} pushad_regs_t; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
static inline Bit32u read_dword(Bit16u seg, Bit16u off) |
| 58 |
{ |
| 59 |
uint32_t *addr = (uint32_t *)ADDR_FROM_SEG_OFF(seg,off); |
| 60 |
return *addr; |
| 61 |
} |
| 62 |
|
| 63 |
static inline Bit16u read_word(Bit16u seg, Bit16u off) |
| 64 |
{ |
| 65 |
uint16_t *addr = (uint16_t *)ADDR_FROM_SEG_OFF(seg,off); |
| 66 |
return *addr; |
| 67 |
} |
| 68 |
|
| 69 |
static inline Bit8u read_byte(Bit16u seg, Bit16u off) |
| 70 |
{ |
| 71 |
uint8_t *addr = (uint8_t *)ADDR_FROM_SEG_OFF(seg,off); |
| 72 |
return *addr; |
| 73 |
} |
| 74 |
|
| 75 |
static inline void write_dword(Bit16u seg, Bit16u off, Bit32u val) |
| 76 |
{ |
| 77 |
uint32_t *addr = (uint32_t *)ADDR_FROM_SEG_OFF(seg,off); |
| 78 |
*addr = val; |
| 79 |
} |
| 80 |
|
| 81 |
static inline void write_word(Bit16u seg, Bit16u off, Bit16u val) |
| 82 |
{ |
| 83 |
uint16_t *addr = (uint16_t *)ADDR_FROM_SEG_OFF(seg,off); |
| 84 |
*addr = val; |
| 85 |
} |
| 86 |
|
| 87 |
static inline void write_byte(Bit16u seg, Bit16u off, Bit8u val) |
| 88 |
{ |
| 89 |
uint8_t *addr = (uint8_t *)ADDR_FROM_SEG_OFF(seg,off); |
| 90 |
*addr = val; |
| 91 |
} |
| 92 |
|
| 93 |
#define X(idx, ret, fn, args...) ret fn (args); |
| 94 |
#include "32bitprotos.h" |
| 95 |
#undef X |
| 96 |
|
| 97 |
#endif |