9 * Full API documentation for these functions is in realmode.h.
13 /* Copy to/from base memory */
15 static inline void copy_to_real_libkir ( uint16_t dest_seg, uint16_t dest_off,
16 void *src, size_t n ) {
17 __asm__ ( "movw %4, %%es\n\t"
20 "pushw %%ds\n\t" /* restore %es */
22 : "=S" ( src ), "=D" ( dest_off ), "=c" ( n ) /* clobbered */
23 : "S" ( src ), "r" ( dest_seg ), "D" ( dest_off ), "c" ( n )
28 static inline void copy_from_real_libkir ( void *dest,
29 uint16_t src_seg, uint16_t src_off,
31 __asm__ ( "movw %%ax, %%ds\n\t"
34 "pushw %%es\n\t" /* restore %ds */
36 : "=S" ( src_off ), "=D" ( dest ), "=c" ( n ) /* clobbered */
37 : "a" ( src_seg ), "S" ( src_off ), "D" ( dest ), "c" ( n )
41 #define copy_to_real copy_to_real_libkir
42 #define copy_from_real copy_from_real_libkir
45 * Transfer individual values to/from base memory. There may well be
46 * a neater way to do this. We have two versions: one for constant
47 * offsets (where the mov instruction must be of the form "mov
48 * %es:123, %xx") and one for non-constant offsets (where the mov
49 * instruction must be of the form "mov %es:(%xx), %yx". If it's
50 * possible to incorporate both forms into one __asm__ instruction, I
51 * don't know how to do it.
53 * Ideally, the mov instruction should be "mov%z0"; the "%z0" is meant
54 * to expand to either "b", "w" or "l" depending on the size of
55 * operand 0. This would remove the (minor) ambiguity in the mov
56 * instruction. However, gcc on at least my system barfs with an
57 * "internal compiler error" when confronted with %z0.
61 #define put_real_kir_const_off( var, seg, off ) \
62 __asm__ ( "movw %w1, %%es\n\t" \
63 "mov %0, %%es:%c2\n\t" \
64 "pushw %%ds\n\t" /* restore %es */ \
67 : "r,r" ( var ), "rm,rm" ( seg ), "i,!r" ( off ) \
70 #define put_real_kir_nonconst_off( var, seg, off ) \
71 __asm__ ( "movw %w1, %%es\n\t" \
72 "mov %0, %%es:(%2)\n\t" \
73 "pushw %%ds\n\t" /* restore %es */ \
76 : "r" ( var ), "rm" ( seg ), "r" ( off ) \
79 #define put_real_kir( var, seg, off ) \
81 if ( __builtin_constant_p ( off ) ) \
82 put_real_kir_const_off ( var, seg, off ); \
84 put_real_kir_nonconst_off ( var, seg, off ); \
87 #define get_real_kir_const_off( var, seg, off ) \
88 __asm__ ( "movw %w1, %%es\n\t" \
89 "mov %%es:%c2, %0\n\t" \
90 "pushw %%ds\n\t" /* restore %es */ \
93 : "rm,rm" ( seg ), "i,!r" ( off ) \
96 #define get_real_kir_nonconst_off( var, seg, off ) \
97 __asm__ ( "movw %w1, %%es\n\t" \
98 "mov %%es:(%2), %0\n\t" \
99 "pushw %%ds\n\t" /* restore %es */ \
102 : "rm" ( seg ), "r" ( off ) \
105 #define get_real_kir( var, seg, off ) \
107 if ( __builtin_constant_p ( off ) ) \
108 get_real_kir_const_off ( var, seg, off ); \
110 get_real_kir_nonconst_off ( var, seg, off ); \
113 #define put_real put_real_kir
114 #define get_real get_real_kir
116 /* Place/remove parameter on real-mode stack in a way that's
117 * compatible with libkir
119 #define BASEMEM_PARAMETER_INIT_LIBKIR( param ) \
120 ( ( uint16_t ) ( ( uint32_t ) & ( param ) ) )
121 #define BASEMEM_PARAMETER_DONE_LIBKIR( param )
122 #define BASEMEM_PARAMETER_INIT BASEMEM_PARAMETER_INIT_LIBKIR
123 #define BASEMEM_PARAMETER_DONE BASEMEM_PARAMETER_DONE_LIBKIR
125 /* REAL_CALL: call an external real-mode routine */
126 #define OUT_CONSTRAINTS(...) __VA_ARGS__
127 #define IN_CONSTRAINTS(...) "m" ( __routine ), ## __VA_ARGS__
128 #define CLOBBER(...) __VA_ARGS__
129 #define REAL_CALL( routine, num_out_constraints, out_constraints, \
130 in_constraints, clobber ) \
132 segoff_t __routine = routine; \
133 __asm__ __volatile__ ( \
134 "pushl %" #num_out_constraints "\n\t" \
136 "pushw %%gs\n\t" /* preserve segs */ \
140 "pushw %%cs\n\t" /* lcall to routine */ \
144 "addr32 pushl 12(%%esp)\n\t" \
147 "popw %%ds\n\t" /* restore segs */ \
151 "addw $4, %%sp\n\t" \
153 : out_constraints : in_constraints : clobber \
157 /* REAL_EXEC: execute some inline assembly code in a way that matches
158 * the interface of librm
161 #define IN_CONSTRAINTS_NO_ROUTINE( routine, ... ) __VA_ARGS__
162 #define REAL_EXEC( name, asm_code_str, num_out_constraints, out_constraints, \
163 in_constraints, clobber ) \
164 __asm__ __volatile__ ( \
178 : IN_CONSTRAINTS_NO_ROUTINE ( in_constraints ) \
182 #endif /* ASSEMBLY */
184 #endif /* LIBKIR_H */