Browse Source

[bios] Make uses of REAL_CODE() and PHYS_CODE() 64-bit clean

On a 64-bit CPU, any modification of a register by 32-bit or 16-bit
code will destroy the invisible upper 32 bits of the corresponding
64-bit register.  For example: a 32-bit "pushl %eax" followed by a
"popl %eax" will zero the upper half of %rax.  This differs from the
treatment of upper halves of 32-bit registers by 16-bit code: a
"pushw %ax" followed by a "popw %ax" will leave the upper 16 bits of
%eax unmodified.

Inline assembly generated using REAL_CODE() or PHYS_CODE() will
therefore have to preserve the upper halves of all registers, to avoid
clobbering registers that gcc expects to be preserved.

Output operands from REAL_CODE() and PHYS_CODE() assembly may
therefore contain undefined values in the upper 32 bits.

Fix by using explicit variable widths (e.g. uint32_t) for
non-discarded output operands, to ensure that undefined values in the
upper 32 bits of 64-bit registers are ignored.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
a3b4d6328c

+ 2
- 2
src/arch/x86/image/nbi.c View File

@@ -241,7 +241,7 @@ static int nbi_process_segments ( struct image *image,
241 241
  */
242 242
 static int nbi_boot16 ( struct image *image, struct imgheader *imgheader ) {
243 243
 	int discard_D, discard_S, discard_b;
244
-	int rc;
244
+	int32_t rc;
245 245
 
246 246
 	DBGC ( image, "NBI %p executing 16-bit image at %04x:%04x\n", image,
247 247
 	       imgheader->execaddr.segoff.segment,
@@ -283,7 +283,7 @@ static int nbi_boot32 ( struct image *image, struct imgheader *imgheader ) {
283 283
 		0
284 284
 	};
285 285
 	int discard_D, discard_S, discard_b;
286
-	int rc;
286
+	int32_t rc;
287 287
 
288 288
 	DBGC ( image, "NBI %p executing 32-bit image at %lx\n",
289 289
 	       image, imgheader->execaddr.linear );

+ 2
- 2
src/arch/x86/interface/pcbios/memmap.c View File

@@ -174,7 +174,7 @@ static int meme820 ( struct memory_map *memmap ) {
174 174
 	struct memory_region *prev_region = NULL;
175 175
 	uint32_t next = 0;
176 176
 	uint32_t smap;
177
-	size_t size;
177
+	uint32_t size;
178 178
 	unsigned int flags;
179 179
 	unsigned int discard_D;
180 180
 
@@ -216,7 +216,7 @@ static int meme820 ( struct memory_map *memmap ) {
216 216
 		}
217 217
 
218 218
 		if ( size < E820_MIN_SIZE ) {
219
-			DBG ( "INT 15,e820 returned only %zd bytes\n", size );
219
+			DBG ( "INT 15,e820 returned only %d bytes\n", size );
220 220
 			return -EINVAL;
221 221
 		}
222 222
 

+ 4
- 4
src/arch/x86/interface/pcbios/pcibios.c View File

@@ -70,7 +70,7 @@ static int pcibios_num_bus ( void ) {
70 70
  */
71 71
 int pcibios_read ( struct pci_device *pci, uint32_t command, uint32_t *value ){
72 72
 	int discard_b, discard_D;
73
-	int status;
73
+	uint16_t status;
74 74
 
75 75
 	__asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
76 76
 					   "int $0x1a\n\t"
@@ -85,7 +85,7 @@ int pcibios_read ( struct pci_device *pci, uint32_t command, uint32_t *value ){
85 85
 				 "b" ( pci->busdevfn )
86 86
 			       : "edx" );
87 87
 
88
-	return ( ( status >> 8 ) & 0xff );
88
+	return ( status >> 8 );
89 89
 }
90 90
 
91 91
 /**
@@ -98,7 +98,7 @@ int pcibios_read ( struct pci_device *pci, uint32_t command, uint32_t *value ){
98 98
  */
99 99
 int pcibios_write ( struct pci_device *pci, uint32_t command, uint32_t value ){
100 100
 	int discard_b, discard_c, discard_D;
101
-	int status;
101
+	uint16_t status;
102 102
 
103 103
 	__asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
104 104
 					   "int $0x1a\n\t"
@@ -111,7 +111,7 @@ int pcibios_write ( struct pci_device *pci, uint32_t command, uint32_t value ){
111 111
 			         "b" ( pci->busdevfn ), "c" ( value )
112 112
 			       : "edx" );
113 113
 	
114
-	return ( ( status >> 8 ) & 0xff );
114
+	return ( status >> 8 );
115 115
 }
116 116
 
117 117
 PROVIDE_PCIAPI ( pcbios, pci_num_bus, pcibios_num_bus );

+ 1
- 1
src/arch/x86/interface/pcbios/rtc_entropy.c View File

@@ -187,7 +187,7 @@ uint8_t rtc_sample ( void ) {
187 187
 			    /* Disable interrupts */
188 188
 			    "cli\n\t"
189 189
 			    )
190
-		: "=a" ( after ), "=d" ( before ), "=q" ( temp )
190
+		: "=a" ( after ), "=d" ( before ), "=Q" ( temp )
191 191
 		: "2" ( 0 ) );
192 192
 
193 193
 	return ( after - before );

+ 8
- 4
src/arch/x86/interface/pxeparent/pxeparent.c View File

@@ -208,8 +208,10 @@ int pxeparent_call ( SEGOFF16_t entry, unsigned int function,
208 208
 		     void *params, size_t params_len ) {
209 209
 	struct pxeparent_profiler *profiler = pxeparent_profiler ( function );
210 210
 	PXENV_EXIT_t exit;
211
-	unsigned long started;
212
-	unsigned long stopped;
211
+	uint32_t before;
212
+	uint32_t started;
213
+	uint32_t stopped;
214
+	uint32_t after;
213 215
 	int discard_D;
214 216
 	int rc;
215 217
 
@@ -240,12 +242,14 @@ int pxeparent_call ( SEGOFF16_t entry, unsigned int function,
240 242
 			         "D" ( __from_data16 ( &pxeparent_params ) )
241 243
 			       : "ecx", "esi" );
242 244
 	profile_stop ( &profiler->total );
243
-	profile_start_at ( &profiler->p2r, profile_started ( &profiler->total));
245
+	before = profile_started ( &profiler->total );
246
+	after = profile_stopped ( &profiler->total );
247
+	profile_start_at ( &profiler->p2r, before );
244 248
 	profile_stop_at ( &profiler->p2r, started );
245 249
 	profile_start_at ( &profiler->ext, started );
246 250
 	profile_stop_at ( &profiler->ext, stopped );
247 251
 	profile_start_at ( &profiler->r2p, stopped );
248
-	profile_stop_at ( &profiler->r2p, profile_stopped ( &profiler->total ));
252
+	profile_stop_at ( &profiler->r2p, after );
249 253
 
250 254
 	/* Determine return status code based on PXENV_EXIT and
251 255
 	 * PXENV_STATUS

Loading…
Cancel
Save