Browse Source

[i386] Change semantics of __from_data16 and __from_text16

__from_data16 and __from_text16 now take a pointer to a
.data16/.text16 variable, and return the real-mode offset within the
appropriate segment.  This matches the use case for every occurrence
of these macros, and prevents potential future bugs such as that fixed
in commit d51d80f.  (The bug arose essentially because "&pointer" is
still syntactically valid.)
tags/v0.9.4
Michael Brown 16 years ago
parent
commit
4fbbf651d7

+ 2
- 2
src/arch/i386/drivers/net/undiload.c View File

@@ -93,8 +93,8 @@ int undi_load ( struct undi_device *undi, struct undi_rom *undirom ) {
93 93
 					   "lcall *%c2\n\t"
94 94
 					   "addw $4, %%sp\n\t" )
95 95
 			       : "=a" ( exit )
96
-			       : "a" ( & __from_data16 ( undi_loader ) ),
97
-			         "p" ( & __from_data16 ( undi_loader_entry ) )
96
+			       : "a" ( __from_data16 ( &undi_loader ) ),
97
+			         "p" ( __from_data16 ( &undi_loader_entry ) )
98 98
 			       : "ebx", "ecx", "edx", "esi", "edi", "ebp" );
99 99
 
100 100
 	/* UNDI API calls may rudely change the status of A20 and not

+ 6
- 9
src/arch/i386/drivers/net/undinet.c View File

@@ -176,9 +176,9 @@ static int undinet_call ( struct undi_nic *undinic, unsigned int function,
176 176
 					   "addw $6, %%sp\n\t" )
177 177
 			       : "=a" ( exit ), "=b" ( discard_b ),
178 178
 			         "=D" ( discard_D )
179
-			       : "p" ( &__from_data16 ( undinet_entry_point )),
179
+			       : "p" ( __from_data16 ( &undinet_entry_point )),
180 180
 			         "b" ( function ),
181
-			         "D" ( &__from_data16 ( undinet_params ) )
181
+			         "D" ( __from_data16 ( &undinet_params ) )
182 182
 			       : "ecx", "edx", "esi", "ebp" );
183 183
 
184 184
 	/* UNDI API calls may rudely change the status of A20 and not
@@ -211,7 +211,7 @@ static int undinet_call ( struct undi_nic *undinic, unsigned int function,
211 211
 	if ( rc != 0 ) {
212 212
 		SEGOFF16_t rm_params = {
213 213
 			.segment = rm_ds,
214
-			.offset = (intptr_t) &__from_data16 ( undinet_params ),
214
+			.offset = __from_data16 ( &undinet_params ),
215 215
 		};
216 216
 
217 217
 		DBGC ( undinic, "UNDINIC %p %s failed: %s\n", undinic,
@@ -357,17 +357,14 @@ static int undinet_transmit ( struct net_device *netdev,
357 357
 	/* Create PXENV_UNDI_TRANSMIT data structure */
358 358
 	memset ( &undi_transmit, 0, sizeof ( undi_transmit ) );
359 359
 	undi_transmit.DestAddr.segment = rm_ds;
360
-	undi_transmit.DestAddr.offset
361
-		= ( ( unsigned ) & __from_data16 ( undinet_tbd ) );
360
+	undi_transmit.DestAddr.offset = __from_data16 ( &undinet_tbd );
362 361
 	undi_transmit.TBD.segment = rm_ds;
363
-	undi_transmit.TBD.offset
364
-		= ( ( unsigned ) & __from_data16 ( undinet_tbd ) );
362
+	undi_transmit.TBD.offset = __from_data16 ( &undinet_tbd );
365 363
 
366 364
 	/* Create PXENV_UNDI_TBD data structure */
367 365
 	undinet_tbd.ImmedLength = len;
368 366
 	undinet_tbd.Xmit.segment = rm_ds;
369
-	undinet_tbd.Xmit.offset 
370
-		= ( ( unsigned ) & __from_data16 ( basemem_packet ) );
367
+	undinet_tbd.Xmit.offset = __from_data16 ( basemem_packet );
371 368
 
372 369
 	/* Issue PXE API call */
373 370
 	if ( ( rc = undinet_call ( undinic, PXENV_UNDI_TRANSMIT,

+ 1
- 1
src/arch/i386/firmware/pcbios/memmap.c View File

@@ -147,7 +147,7 @@ static int meme820 ( struct memory_map *memmap ) {
147 147
 					 "=b" ( next ), "=D" ( discard_D ),
148 148
 					 "=c" ( discard_c ), "=d" ( discard_d )
149 149
 				       : "a" ( 0xe820 ), "b" ( next ),
150
-					 "D" ( &__from_data16 ( e820buf ) ),
150
+					 "D" ( __from_data16 ( &e820buf ) ),
151 151
 					 "c" ( sizeof ( e820buf ) ),
152 152
 					 "d" ( SMAP )
153 153
 				       : "memory" );

+ 2
- 2
src/arch/i386/include/libkir.h View File

@@ -19,8 +19,8 @@
19 19
 #define __text16_array( variable,array ) variable array
20 20
 #define __use_data16( variable ) variable
21 21
 #define __use_text16( variable ) variable
22
-#define __from_data16( variable ) variable
23
-#define __from_text16( variable ) variable
22
+#define __from_data16( pointer ) pointer
23
+#define __from_text16( pointer ) pointer
24 24
 
25 25
 /* Real-mode data and code segments */
26 26
 static inline __attribute__ (( always_inline )) unsigned int _rm_cs ( void ) {

+ 6
- 6
src/arch/i386/include/librm.h View File

@@ -51,13 +51,13 @@ extern char *text16;
51 51
 	( * ( ( typeof ( _text16_ ## variable ) * )			\
52 52
 	      & ( text16 [ ( size_t ) & ( _text16_ ## variable ) ] ) ) )
53 53
 
54
-#define __from_data16( variable )					\
55
-	( * ( ( typeof ( variable ) * )					\
56
-	      ( ( ( void * ) &(variable) ) - ( ( void * ) data16 ) ) ) )
54
+#define __from_data16( pointer )					\
55
+	( ( unsigned int )						\
56
+	  ( ( ( void * ) (pointer) ) - ( ( void * ) data16 ) ) )
57 57
 
58
-#define __from_text16( variable )					\
59
-	( * ( ( typeof ( variable ) * )					\
60
-	      ( ( ( void * ) &(variable) ) - ( ( void * ) text16 ) ) ) )
58
+#define __from_text16( pointer )					\
59
+	( ( unsigned int )						\
60
+	  ( ( ( void * ) (pointer) ) - ( ( void * ) text16 ) ) )
61 61
 
62 62
 /* Variables in librm.S, present in the normal data segment */
63 63
 extern uint16_t __data16 ( rm_cs );

+ 2
- 2
src/arch/i386/interface/pxe/pxe_call.c View File

@@ -441,8 +441,8 @@ int pxe_start_nbp ( void ) {
441 441
 					   "addw $4, %%sp\n\t" )
442 442
 			       : "=a" ( rc ), "=b" ( discard_b ),
443 443
 			         "=c" ( discard_c )
444
-			       :  "a" ( & __from_text16 ( ppxe ) ),
445
-			          "b" ( & __from_text16 ( pxenv ) ),
444
+			       :  "a" ( __from_text16 ( &ppxe ) ),
445
+			          "b" ( __from_text16 ( &pxenv ) ),
446 446
 			          "c" ( rm_cs )
447 447
 			       : "edx", "esi", "edi", "ebp", "memory" );
448 448
 

+ 2
- 4
src/interface/pxe/pxe_loader.c View File

@@ -42,11 +42,9 @@ PXENV_EXIT_t undi_loader ( struct s_UNDI_LOADER *undi_loader ) {
42 42
 
43 43
 	/* Fill in UNDI loader structure */
44 44
 	undi_loader->PXEptr.segment = rm_cs;
45
-	undi_loader->PXEptr.offset =
46
-		( ( unsigned ) & __from_text16 ( ppxe ) );
45
+	undi_loader->PXEptr.offset = __from_text16 ( &ppxe );
47 46
 	undi_loader->PXENVptr.segment = rm_cs;
48
-	undi_loader->PXENVptr.offset =
49
-		( ( unsigned ) & __from_text16 ( pxenv ) );
47
+	undi_loader->PXENVptr.offset = __from_text16 ( &pxenv );
50 48
 
51 49
 	undi_loader->Status = PXENV_STATUS_SUCCESS;
52 50
 	return PXENV_EXIT_SUCCESS;

+ 1
- 2
src/interface/pxe/pxe_preboot.c View File

@@ -196,8 +196,7 @@ PXENV_EXIT_t pxenv_get_cached_info ( struct s_PXENV_GET_CACHED_INFO
196 196
 		 * fill it in.
197 197
 		 */
198 198
 		get_cached_info->Buffer.segment = rm_ds;
199
-		get_cached_info->Buffer.offset =
200
-			( unsigned ) ( & __from_data16 ( *info ) );
199
+		get_cached_info->Buffer.offset = __from_data16 ( info );
201 200
 		get_cached_info->BufferSize = sizeof ( *info );
202 201
 		DBG ( " returning %04x:%04x+%04x['%x']",
203 202
 		      get_cached_info->Buffer.segment,

+ 1
- 2
src/interface/pxe/pxe_undi.c View File

@@ -597,8 +597,7 @@ PXENV_EXIT_t pxenv_undi_isr ( struct s_PXENV_UNDI_ISR *undi_isr ) {
597 597
 		undi_isr->FrameHeaderLength =
598 598
 			pxe_netdev->ll_protocol->ll_header_len;
599 599
 		undi_isr->Frame.segment = rm_ds;
600
-		undi_isr->Frame.offset =
601
-			( ( unsigned ) & __from_data16 ( basemem_packet ) );
600
+		undi_isr->Frame.offset = __from_data16 ( basemem_packet );
602 601
 		/* Probably ought to fill in packet type */
603 602
 		undi_isr->ProtType = P_UNKNOWN;
604 603
 		undi_isr->PktType = XMT_DESTADDR;

Loading…
Cancel
Save