Adding upstream version 3.61.
[syslinux-debian/hramrach.git] / com32 / include / com32.h
blob8be872116ccc223c2f2804b2f35d9fa65ab485b9
1 /* ----------------------------------------------------------------------- *
2 * Not Copyright 2002-2008 H. Peter Anvin
3 * This file is in the public domain.
4 * ----------------------------------------------------------------------- */
6 /*
7 * com32.h
9 * Common declarations for com32 programs.
12 #ifndef _COM32_H
13 #define _COM32_H
15 #include <stdint.h>
16 #include <klibc/compiler.h> /* For __cdecl */
19 * This structure defines the register frame used by the
20 * system call interface.
22 * The syscall interface is:
24 * __intcall(interrupt_#, source_regs, return_regs)
25 * __farcall(seg, offs, source_regs, return_regs)
27 typedef union {
28 uint32_t l;
29 uint16_t w[2];
30 uint8_t b[4];
31 } reg32_t;
33 typedef struct {
34 uint16_t gs; /* Offset 0 */
35 uint16_t fs; /* Offset 2 */
36 uint16_t es; /* Offset 4 */
37 uint16_t ds; /* Offset 6 */
39 reg32_t edi; /* Offset 8 */
40 reg32_t esi; /* Offset 12 */
41 reg32_t ebp; /* Offset 16 */
42 reg32_t _unused_esp; /* Offset 20 */
43 reg32_t ebx; /* Offset 24 */
44 reg32_t edx; /* Offset 28 */
45 reg32_t ecx; /* Offset 32 */
46 reg32_t eax; /* Offset 36 */
48 reg32_t eflags; /* Offset 40 */
49 } com32sys_t;
51 /* EFLAGS definitions */
52 #define EFLAGS_CF 0x00000001
53 #define EFLAGS_PF 0x00000004
54 #define EFLAGS_AF 0x00000010
55 #define EFLAGS_ZF 0x00000040
56 #define EFLAGS_SF 0x00000080
57 #define EFLAGS_TF 0x00000100
58 #define EFLAGS_IF 0x00000200
59 #define EFLAGS_DF 0x00000400
60 #define EFLAGS_OF 0x00000800
61 #define EFLAGS_IOPL 0x00003000
62 #define EFLAGS_NT 0x00004000
63 #define EFLAGS_RF 0x00010000
64 #define EFLAGS_VM 0x00020000
65 #define EFLAGS_AC 0x00040000
66 #define EFLAGS_VIF 0x00080000
67 #define EFLAGS_VIP 0x00100000
68 #define EFLAGS_ID 0x00200000
70 extern struct com32_sys_args {
71 uint32_t cs_sysargs;
72 char *cs_cmdline;
73 void __cdecl (*cs_intcall)(uint8_t, const com32sys_t *, com32sys_t *);
74 void *cs_bounce;
75 uint32_t cs_bounce_size;
76 void __cdecl (*cs_farcall)(uint32_t, const com32sys_t *, com32sys_t *);
77 int __cdecl (*cs_cfarcall)(uint32_t, const void *, uint32_t);
78 } __com32;
81 * System call wrapper functions
83 void __intcall(uint8_t __i, const com32sys_t *__sr, com32sys_t *__dr);
84 void __farcall(uint16_t __cs, uint16_t __ip,
85 const com32sys_t *__sr, com32sys_t *__dr);
86 int __cfarcall(uint16_t __cs, uint16_t __ip,
87 const void *__stack, uint32_t __stack_size);
88 extern const com32sys_t __com32_zero_regs;
91 * These functions convert between linear pointers in the range
92 * 0..0xFFFFF and real-mode style SEG:OFFS pointers. Note that a
93 * 32-bit linear pointer is not compatible with a SEG:OFFS pointer
94 * stored in two consecutive 16-bit words.
96 * Use OFFS_WRT() if you want to compute an offset relative to a
97 * specific segment. OFFS_VALID() will return whether or not the
98 * pointer is actually reachable from the target segment.
100 static inline uint16_t SEG(const volatile void *__p)
102 return (uint16_t)(((uintptr_t)__p) >> 4);
105 static inline uint16_t OFFS(const volatile void *__p)
107 /* The double cast here is to shut up gcc */
108 return (uint16_t)(uintptr_t)__p & 0x000F;
111 static inline uint16_t OFFS_WRT(const volatile void *__p, uint16_t seg)
113 return (uint16_t)((uintptr_t)__p - ((uintptr_t)seg << 4));
116 static inline int OFFS_VALID(const volatile void *__p, uint16_t seg)
118 uintptr_t __segstart = (uintptr_t)seg << 4;
119 uintptr_t __ptr = (uintptr_t)__p;
121 return (__ptr >= __segstart) && (__ptr <= __segstart+0xffff);
124 static inline void *MK_PTR(uint16_t __seg, uint16_t __offs)
126 return (void *)((__seg << 4) + __offs);
129 /* Some tools to handle 16:16 far pointers in memory */
131 struct __far_ptr {
132 uint32_t __ptr;
133 } __attribute__((packed));
135 typedef struct __far_ptr far_ptr_t;
138 static inline void *GET_PTR(far_ptr_t __fptr)
140 return MK_PTR(__fptr.__ptr >> 16, __fptr.__ptr);
143 static inline far_ptr_t FAR_PTR(void *__ptr)
145 far_ptr_t __fptr;
147 __fptr.__ptr = (SEG(__ptr) << 16) + OFFS(__ptr);
148 return __fptr;
151 #endif /* _COM32_H */