syslinux-3.08-2 sources from FC4
[bootcd.git] / syslinux / com32 / include / com32.h
1 /* ----------------------------------------------------------------------- *
2  *   Not Copyright 2002 H. Peter Anvin
3  *   This file is in the public domain.
4  * ----------------------------------------------------------------------- */
5
6 /*
7  * com32.h
8  *
9  * Common declarations for com32 programs.
10  */
11
12 #ifndef _COM32_H
13 #define _COM32_H
14
15 #include <stdint.h>
16 #include <klibc/compiler.h>     /* For __cdecl */
17
18 /*
19  * This structure defines the register frame used by the
20  * system call interface.
21  *
22  * The syscall interface is:
23  *
24  * __intcall(interrupt_#, source_regs, return_regs)
25  * __farcall(seg, offs, source_regs, return_regs)
26  */
27 typedef union {
28   uint32_t l;
29   uint16_t w[2];
30   uint8_t  b[4];
31 } reg32_t;
32
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 */
38
39   reg32_t edi;                  /* Offset  8 */
40   reg32_t esi;                  /* Offset 12 */
41   reg32_t ebp;                  /* Offset 16 */
42   reg32_t _unused;              /* 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 */
47
48   reg32_t eflags;               /* Offset 40 */
49 } com32sys_t;
50
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
69
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 } __com32;
78
79 /*
80  * System call macros
81  */
82 static inline void
83 __intcall(uint8_t __i, const com32sys_t *__sr, com32sys_t *__dr)
84 {
85   __com32.cs_intcall(__i, __sr, __dr);
86 }
87
88 static inline void
89 __farcall(uint16_t __es, uint16_t __eo,
90           const com32sys_t *__sr, com32sys_t *__dr)
91 {
92   __com32.cs_farcall((__es << 16) + __eo, __sr, __dr);
93 }
94
95 /*
96  * These functions convert between linear pointers in the range
97  * 0..0xFFFFF and real-mode style SEG:OFFS pointers.  Note that a
98  * 32-bit linear pointer is not compatible with a SEG:OFFS pointer
99  * stored in two consecutive 16-bit words.
100  */
101 static inline uint16_t SEG(void *__p)
102 {
103   return (uint16_t)(((uintptr_t)__p) >> 4);
104 }
105
106 static inline uint16_t OFFS(void *__p)
107 {
108   /* The double cast here is to shut up gcc */
109   return (uint16_t)(uintptr_t)__p & 0x000F;
110 }
111
112 static inline void *MK_PTR(uint16_t __seg, uint16_t __offs)
113 {
114   return (void *)((__seg << 4) + __offs);
115 }
116
117 #endif /* _COM32_H */