瀏覽代碼

[bios] Allow librm to be compiled for x86_64

This commit does not make librm functional for x86_64; it merely
allows it to compile without errors.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 年之前
父節點
當前提交
1a457e933a
共有 3 個檔案被更改,包括 30 行新增15 行删除
  1. 12
    3
      src/arch/i386/include/librm.h
  2. 5
    5
      src/arch/i386/transitions/librm_mgmt.c
  3. 13
    7
      src/arch/i386/transitions/librm_test.c

+ 12
- 3
src/arch/i386/include/librm.h 查看文件

@@ -173,17 +173,24 @@ extern uint16_t __text16 ( rm_ds );
173 173
 extern uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size );
174 174
 extern void remove_user_from_rm_stack ( userptr_t data, size_t size );
175 175
 
176
+/* CODE_DEFAULT: restore default .code32/.code64 directive */
177
+#ifdef __x86_64__
178
+#define CODE_DEFAULT ".code64"
179
+#else
180
+#define CODE_DEFAULT ".code32"
181
+#endif
182
+
176 183
 /* TEXT16_CODE: declare a fragment of code that resides in .text16 */
177 184
 #define TEXT16_CODE( asm_code_str )			\
178 185
 	".section \".text16\", \"ax\", @progbits\n\t"	\
179 186
 	".code16\n\t"					\
180 187
 	asm_code_str "\n\t"				\
181
-	".code32\n\t"					\
188
+	CODE_DEFAULT "\n\t"				\
182 189
 	".previous\n\t"
183 190
 
184 191
 /* REAL_CODE: declare a fragment of code that executes in real mode */
185 192
 #define REAL_CODE( asm_code_str )			\
186
-	"pushl $1f\n\t"					\
193
+	"push $1f\n\t"					\
187 194
 	"call real_call\n\t"				\
188 195
 	"addl $4, %%esp\n\t"				\
189 196
 	TEXT16_CODE ( "\n1:\n\t"			\
@@ -194,8 +201,10 @@ extern void remove_user_from_rm_stack ( userptr_t data, size_t size );
194 201
 /* PHYS_CODE: declare a fragment of code that executes in flat physical mode */
195 202
 #define PHYS_CODE( asm_code_str )			\
196 203
 	"call _virt_to_phys\n\t"			\
204
+	".code32\n\t"					\
197 205
 	asm_code_str					\
198
-	"call _phys_to_virt\n\t"
206
+	"call _phys_to_virt\n\t"			\
207
+	CODE_DEFAULT "\n\t"
199 208
 
200 209
 /** Number of interrupts */
201 210
 #define NUM_INT 256

+ 5
- 5
src/arch/i386/transitions/librm_mgmt.c 查看文件

@@ -80,8 +80,8 @@ void set_interrupt_vector ( unsigned int intr, void *vector ) {
80 80
 	idte = &idt[intr];
81 81
 	idte->segment = VIRTUAL_CS;
82 82
 	idte->attr = ( vector ? ( IDTE_PRESENT | IDTE_TYPE_IRQ32 ) : 0 );
83
-	idte->low = ( ( ( uint32_t ) vector ) & 0xffff );
84
-	idte->high = ( ( ( uint32_t ) vector ) >> 16 );
83
+	idte->low = ( ( ( intptr_t ) vector ) & 0xffff );
84
+	idte->high = ( ( ( intptr_t ) vector ) >> 16 );
85 85
 }
86 86
 
87 87
 /**
@@ -99,8 +99,8 @@ void init_idt ( void ) {
99 99
 		vec->movb = MOVB_INSN;
100 100
 		vec->intr = intr;
101 101
 		vec->jmp = JMP_INSN;
102
-		vec->offset = ( ( uint32_t ) interrupt_wrapper -
103
-				( uint32_t ) vec->next );
102
+		vec->offset = ( ( intptr_t ) interrupt_wrapper -
103
+				( intptr_t ) vec->next );
104 104
 		set_interrupt_vector ( intr, vec );
105 105
 	}
106 106
 	DBGC ( &intr_vec[0], "INTn vector at %p+%zxn (phys %#lx+%zxn)\n",
@@ -132,7 +132,7 @@ static struct profiler * interrupt_profiler ( int intr ) {
132 132
  *
133 133
  * @v intr		Interrupt number
134 134
  */
135
-void __attribute__ (( cdecl, regparm ( 1 ) )) interrupt ( int intr ) {
135
+void __attribute__ (( regparm ( 1 ) )) interrupt ( int intr ) {
136 136
 	struct profiler *profiler = interrupt_profiler ( intr );
137 137
 	uint32_t discard_eax;
138 138
 

+ 13
- 7
src/arch/i386/transitions/librm_test.c 查看文件

@@ -69,9 +69,11 @@ static void librm_test_prot_call ( void ) {
69 69
 static void librm_test_exec ( void ) {
70 70
 	unsigned int i;
71 71
 	unsigned long timestamp;
72
-	unsigned long started;
73
-	unsigned long stopped;
74
-	unsigned int discard_d;
72
+	uint32_t timestamp_lo;
73
+	uint32_t timestamp_hi;
74
+	uint32_t started;
75
+	uint32_t stopped;
76
+	uint32_t discard_d;
75 77
 
76 78
 	/* Profile mode transitions.  We want to profile each
77 79
 	 * direction of the transition separately, so perform an RDTSC
@@ -81,8 +83,12 @@ static void librm_test_exec ( void ) {
81 83
 	for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
82 84
 		profile_start ( &p2r_profiler );
83 85
 		__asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t" )
84
-				       : "=a" ( timestamp ), "=d" ( discard_d )
86
+				       : "=a" ( timestamp_lo ),
87
+					 "=d" ( timestamp_hi )
85 88
 				       : );
89
+		timestamp = timestamp_lo;
90
+		if ( sizeof ( timestamp ) > sizeof ( timestamp_lo ) )
91
+			timestamp |= ( ( ( uint64_t ) timestamp_hi ) << 32 );
86 92
 		profile_start_at ( &r2p_profiler, timestamp );
87 93
 		profile_stop ( &r2p_profiler );
88 94
 		profile_stop_at ( &p2r_profiler, timestamp );
@@ -98,14 +104,14 @@ static void librm_test_exec ( void ) {
98 104
 	/* Profile complete protected-mode call cycle */
99 105
 	for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
100 106
 		__asm__ __volatile__ ( REAL_CODE ( "rdtsc\n\t"
101
-						   "movl %0, %2\n\t"
102
-						   "pushl %3\n\t"
107
+						   "movl %k0, %k2\n\t"
108
+						   "pushl %k3\n\t"
103 109
 						   "pushw %%cs\n\t"
104 110
 						   "call prot_call\n\t"
105 111
 						   "addw $4, %%sp\n\t"
106 112
 						   "rdtsc\n\t" )
107 113
 				       : "=a" ( stopped ), "=d" ( discard_d ),
108
-					 "=r" ( started )
114
+					 "=R" ( started )
109 115
 				       : "i" ( librm_test_prot_call ) );
110 116
 		profile_start_at ( &prot_call_profiler, started );
111 117
 		profile_stop_at ( &prot_call_profiler, stopped );

Loading…
取消
儲存