9 * Full API documentation for these functions is in realmode.h.
13 /* Access to variables in .data16 and .text16 in a way compatible with librm */
14 #define __data16( variable ) variable
15 #define __text16( variable ) variable
16 #define __use_data16( variable ) variable
17 #define __use_text16( variable ) variable
18 #define __from_data16( variable ) variable
19 #define __from_text16( variable ) variable
21 /* Copy to/from base memory */
23 static inline void copy_to_real_libkir ( uint16_t dest_seg, uint16_t dest_off,
24 void *src, size_t n ) {
25 __asm__ __volatile__ ( "movw %4, %%es\n\t"
28 "pushw %%ds\n\t" /* restore %es */
30 : "=S" ( src ), "=D" ( dest_off ),
31 "=c" ( n ) /* clobbered */
32 : "S" ( src ), "r" ( dest_seg ),
33 "D" ( dest_off ), "c" ( n )
37 static inline void copy_from_real_libkir ( void *dest,
38 uint16_t src_seg, uint16_t src_off,
40 __asm__ __volatile__ ( "movw %%ax, %%ds\n\t"
43 "pushw %%es\n\t" /* restore %ds */
45 : "=S" ( src_off ), "=D" ( dest ),
46 "=c" ( n ) /* clobbered */
47 : "a" ( src_seg ), "S" ( src_off ),
48 "D" ( dest ), "c" ( n )
51 #define copy_to_real copy_to_real_libkir
52 #define copy_from_real copy_from_real_libkir
55 * Transfer individual values to/from base memory. There may well be
56 * a neater way to do this. We have two versions: one for constant
57 * offsets (where the mov instruction must be of the form "mov
58 * %es:123, %xx") and one for non-constant offsets (where the mov
59 * instruction must be of the form "mov %es:(%xx), %yx". If it's
60 * possible to incorporate both forms into one __asm__ instruction, I
61 * don't know how to do it.
63 * Ideally, the mov instruction should be "mov%z0"; the "%z0" is meant
64 * to expand to either "b", "w" or "l" depending on the size of
65 * operand 0. This would remove the (minor) ambiguity in the mov
66 * instruction. However, gcc on at least my system barfs with an
67 * "internal compiler error" when confronted with %z0.
71 #define put_real_kir_const_off( var, seg, off ) \
72 __asm__ ( "movw %w1, %%es\n\t" \
73 "mov %0, %%es:%c2\n\t" \
74 "pushw %%ds\n\t" /* restore %es */ \
77 : "r,r" ( var ), "rm,rm" ( seg ), "i,!r" ( off ) \
80 #define put_real_kir_nonconst_off( var, seg, off ) \
81 __asm__ ( "movw %w1, %%es\n\t" \
82 "mov %0, %%es:(%2)\n\t" \
83 "pushw %%ds\n\t" /* restore %es */ \
86 : "r" ( var ), "rm" ( seg ), "r" ( off ) \
89 #define put_real_kir( var, seg, off ) \
91 if ( __builtin_constant_p ( off ) ) \
92 put_real_kir_const_off ( var, seg, off ); \
94 put_real_kir_nonconst_off ( var, seg, off ); \
97 #define get_real_kir_const_off( var, seg, off ) \
98 __asm__ ( "movw %w1, %%es\n\t" \
99 "mov %%es:%c2, %0\n\t" \
100 "pushw %%ds\n\t" /* restore %es */ \
103 : "rm,rm" ( seg ), "i,!r" ( off ) \
106 #define get_real_kir_nonconst_off( var, seg, off ) \
107 __asm__ ( "movw %w1, %%es\n\t" \
108 "mov %%es:(%2), %0\n\t" \
109 "pushw %%ds\n\t" /* restore %es */ \
112 : "rm" ( seg ), "r" ( off ) \
115 #define get_real_kir( var, seg, off ) \
117 if ( __builtin_constant_p ( off ) ) \
118 get_real_kir_const_off ( var, seg, off ); \
120 get_real_kir_nonconst_off ( var, seg, off ); \
123 #define put_real put_real_kir
124 #define get_real get_real_kir
126 /* Place/remove parameter on real-mode stack in a way that's
127 * compatible with libkir
129 #define BASEMEM_PARAMETER_INIT_LIBKIR( param ) \
130 ( ( uint16_t ) ( ( uint32_t ) & ( param ) ) )
131 #define BASEMEM_PARAMETER_DONE_LIBKIR( param )
132 #define BASEMEM_PARAMETER_INIT BASEMEM_PARAMETER_INIT_LIBKIR
133 #define BASEMEM_PARAMETER_DONE BASEMEM_PARAMETER_DONE_LIBKIR
135 /* REAL_FRAGMENT: Declare and define a real-mode code fragment in
136 * .text16. We don't need this for REAL_EXEC, since we can just
137 * execute our real-mode code inline, but it's handy in case someone
138 * genuinely wants to create a block of code that can be copied to a
139 * specific location and then executed.
141 * Note that we put the code in the data segment, since otherwise we
142 * can't (easily) access it in order to copy it to its target
143 * location. We should never be calling any REAL_FRAGMENT routines
146 #define REAL_FRAGMENT( name, asm_code_str ) \
147 extern void name ( void ); \
148 extern char name ## _size[]; \
149 __asm__ __volatile__ ( \
150 ".section \".data.text16\"\n\t" \
154 asm_code_str "\n\t" \
157 ".equ " #name "_size, " #name "_end - " #name "\n\t" \
162 #define FRAGMENT_SIZE( fragment ) ( (size_t) fragment ## _size )
164 /* REAL_CALL: call an external real-mode routine */
165 #define OUT_CONSTRAINTS(...) __VA_ARGS__
166 #define IN_CONSTRAINTS(...) "m" ( __routine ), ## __VA_ARGS__
167 #define CLOBBER(...) __VA_ARGS__
168 #define REAL_CALL( routine, num_out_constraints, out_constraints, \
169 in_constraints, clobber ) \
171 segoff_t __routine = routine; \
172 __asm__ __volatile__ ( \
173 "pushl %" #num_out_constraints "\n\t" \
175 "pushw %%gs\n\t" /* preserve segs */ \
179 "pushw %%cs\n\t" /* lcall to routine */ \
183 "addr32 pushl 12(%%esp)\n\t" \
186 "popw %%ds\n\t" /* restore segs */ \
190 "addw $4, %%sp\n\t" \
192 : out_constraints : in_constraints : clobber \
196 /* REAL_EXEC: execute some inline assembly code in a way that matches
197 * the interface of librm
200 #define IN_CONSTRAINTS_NO_ROUTINE( routine, ... ) __VA_ARGS__
201 #define REAL_EXEC( name, asm_code_str, num_out_constraints, out_constraints, \
202 in_constraints, clobber ) \
203 __asm__ __volatile__ ( \
217 : IN_CONSTRAINTS_NO_ROUTINE ( in_constraints ) \
221 #endif /* ASSEMBLY */
223 #endif /* LIBKIR_H */