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