4 /* Drag in protected-mode segment selector values */
14 * Data structures and type definitions
18 /* Real-mode call parameter block, as passed to real_call */
19 struct real_call_params {
26 /* Current location of librm in base memory */
27 extern char *installed_librm;
29 /* Start and size of our source copy of librm (i.e. the one that we
30 * can install by copying it to base memory and setting
34 extern size_t _librm_size[];
36 /* Linker symbols for offsets within librm. Other symbols should
37 * almost certainly not be referred to from C code.
39 extern void (*_real_to_prot[]) ( void );
40 extern void (*_prot_to_real[]) ( void );
41 extern void (*_prot_call[]) ( void );
42 extern void (*_real_call[]) ( void );
43 extern uint32_t _librm_base[];
44 extern segoff_t _rm_stack[];
45 extern uint32_t _pm_stack[];
46 extern char _librm_ref_count[];
48 /* Symbols within current installation of librm */
49 #define LIBRM_VAR( sym ) \
50 ( * ( ( typeof ( * _ ## sym ) * ) \
51 & ( installed_librm [ (int) _ ## sym ] ) ) )
52 #define LIBRM_FN( sym ) \
53 ( ( typeof ( * _ ## sym ) ) \
54 & ( installed_librm [ (int) _ ## sym ] ) )
55 #define LIBRM_CONSTANT( sym ) \
56 ( ( typeof ( * _ ## sym ) ) ( _ ## sym ) )
57 #define inst_real_to_prot LIBRM_FN ( real_to_prot )
58 #define inst_prot_to_real LIBRM_FN ( prot_to_real )
59 #define inst_prot_call LIBRM_FN ( prot_call )
60 #define inst_real_call LIBRM_FN ( real_call )
61 #define inst_librm_base LIBRM_VAR ( librm_base )
62 #define inst_rm_stack LIBRM_VAR ( rm_stack )
63 #define inst_pm_stack LIBRM_VAR ( pm_stack )
64 #define inst_librm_ref_count LIBRM_VAR ( librm_ref_count )
65 #define librm_size LIBRM_CONSTANT ( librm_size )
67 /* Symbols within local (uninstalled) copy of librm */
68 extern uint32_t librm_base;
70 /* Functions that librm expects to be able to link to. Included here
71 * so that the compiler will catch prototype mismatches.
73 extern void _phys_to_virt ( void );
74 extern void _virt_to_phys ( void );
75 extern void gateA20_set ( void );
78 * librm_mgmt: functions for manipulating base memory and executing
81 * Full API documentation for these functions is in realmode.h.
85 /* Macro for obtaining a physical address from a segment:offset pair. */
86 #define VIRTUAL(x,y) ( phys_to_virt ( ( ( x ) << 4 ) + ( y ) ) )
88 /* Copy to/from base memory */
89 static inline void copy_to_real_librm ( uint16_t dest_seg, uint16_t dest_off,
90 void *src, size_t n ) {
91 memcpy ( VIRTUAL ( dest_seg, dest_off ), src, n );
93 static inline void copy_from_real_librm ( void *dest,
94 uint16_t src_seg, uint16_t src_off,
96 memcpy ( dest, VIRTUAL ( src_seg, src_off ), n );
98 #define put_real_librm( var, dest_seg, dest_off ) \
100 * ( ( typeof(var) * ) VIRTUAL ( dest_seg, dest_off ) ) = var; \
102 #define get_real_librm( var, src_seg, src_off ) \
104 var = * ( ( typeof(var) * ) VIRTUAL ( src_seg, src_off ) ); \
106 #define copy_to_real copy_to_real_librm
107 #define copy_from_real copy_from_real_librm
108 #define put_real put_real_librm
109 #define get_real get_real_librm
111 /* Copy to/from real-mode stack */
112 extern uint16_t copy_to_rm_stack ( void *data, size_t size );
113 extern void remove_from_rm_stack ( void *data, size_t size );
115 /* Place/remove parameter on real-mode stack in a way that's
116 * compatible with libkir
118 #define BASEMEM_PARAMETER_INIT_LIBRM( param ) \
119 copy_to_rm_stack ( & ( param ), sizeof ( param ) )
120 #define BASEMEM_PARAMETER_DONE_LIBRM( param ) \
121 remove_from_rm_stack ( & ( param ), sizeof ( param ) )
122 #define BASEMEM_PARAMETER_INIT BASEMEM_PARAMETER_INIT_LIBRM
123 #define BASEMEM_PARAMETER_DONE BASEMEM_PARAMETER_DONE_LIBRM
125 /* REAL_FRAGMENT: Declare and define a real-mode code fragment in .text16 */
126 #define REAL_FRAGMENT( name, asm_code_str ) \
127 extern void name ( void ); \
128 extern char name ## _size[]; \
129 __asm__ __volatile__ ( \
130 ".section \".text16\"\n\t" \
134 asm_code_str "\n\t" \
137 ".equ " #name "_size, " #name "_end - " #name "\n\t" \
142 #define FRAGMENT_SIZE( fragment ) ( (size_t) fragment ## _size )
144 /* REAL_CALL: call a real-mode routine via librm */
145 #define OUT_CONSTRAINTS(...) __VA_ARGS__
146 #define IN_CONSTRAINTS(...) "m" ( __routine ), ## __VA_ARGS__
147 #define CLOBBER(...) __VA_ARGS__
148 #define REAL_CALL( routine, num_out_constraints, out_constraints, \
149 in_constraints, clobber ) \
151 segoff_t __routine = routine; \
152 __asm__ __volatile__ ( \
153 "pushl %" #num_out_constraints "\n\t" \
157 "pushl installed_librm\n\t" \
158 "addl $_real_call, 0(%%esp)\n\t" \
161 "addl $4, %%esp\n\t" \
168 /* REAL_EXEC: combine RM_FRAGMENT and REAL_CALL into one handy unit */
169 #define PASSTHRU(...) __VA_ARGS__
170 #define REAL_EXEC( name, asm_code_str, num_out_constraints, out_constraints, \
171 in_constraints, clobber ) \
175 REAL_FRAGMENT ( name, asm_code_str ); \
177 fragment.segment = inst_rm_stack.segment; \
179 copy_to_rm_stack ( name, FRAGMENT_SIZE ( name ) ); \
181 REAL_CALL ( fragment, num_out_constraints, \
182 PASSTHRU ( out_constraints ), \
183 PASSTHRU ( in_constraints ), \
184 PASSTHRU ( clobber ) ); \
186 remove_from_rm_stack ( NULL, FRAGMENT_SIZE ( name ) ); \
189 #endif /* ASSEMBLY */