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
 					   "lcall *%c2\n\t"
93
 					   "lcall *%c2\n\t"
94
 					   "addw $4, %%sp\n\t" )
94
 					   "addw $4, %%sp\n\t" )
95
 			       : "=a" ( exit )
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
 			       : "ebx", "ecx", "edx", "esi", "edi", "ebp" );
98
 			       : "ebx", "ecx", "edx", "esi", "edi", "ebp" );
99
 
99
 
100
 	/* UNDI API calls may rudely change the status of A20 and not
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
 					   "addw $6, %%sp\n\t" )
176
 					   "addw $6, %%sp\n\t" )
177
 			       : "=a" ( exit ), "=b" ( discard_b ),
177
 			       : "=a" ( exit ), "=b" ( discard_b ),
178
 			         "=D" ( discard_D )
178
 			         "=D" ( discard_D )
179
-			       : "p" ( &__from_data16 ( undinet_entry_point )),
179
+			       : "p" ( __from_data16 ( &undinet_entry_point )),
180
 			         "b" ( function ),
180
 			         "b" ( function ),
181
-			         "D" ( &__from_data16 ( undinet_params ) )
181
+			         "D" ( __from_data16 ( &undinet_params ) )
182
 			       : "ecx", "edx", "esi", "ebp" );
182
 			       : "ecx", "edx", "esi", "ebp" );
183
 
183
 
184
 	/* UNDI API calls may rudely change the status of A20 and not
184
 	/* UNDI API calls may rudely change the status of A20 and not
211
 	if ( rc != 0 ) {
211
 	if ( rc != 0 ) {
212
 		SEGOFF16_t rm_params = {
212
 		SEGOFF16_t rm_params = {
213
 			.segment = rm_ds,
213
 			.segment = rm_ds,
214
-			.offset = (intptr_t) &__from_data16 ( undinet_params ),
214
+			.offset = __from_data16 ( &undinet_params ),
215
 		};
215
 		};
216
 
216
 
217
 		DBGC ( undinic, "UNDINIC %p %s failed: %s\n", undinic,
217
 		DBGC ( undinic, "UNDINIC %p %s failed: %s\n", undinic,
357
 	/* Create PXENV_UNDI_TRANSMIT data structure */
357
 	/* Create PXENV_UNDI_TRANSMIT data structure */
358
 	memset ( &undi_transmit, 0, sizeof ( undi_transmit ) );
358
 	memset ( &undi_transmit, 0, sizeof ( undi_transmit ) );
359
 	undi_transmit.DestAddr.segment = rm_ds;
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
 	undi_transmit.TBD.segment = rm_ds;
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
 	/* Create PXENV_UNDI_TBD data structure */
364
 	/* Create PXENV_UNDI_TBD data structure */
367
 	undinet_tbd.ImmedLength = len;
365
 	undinet_tbd.ImmedLength = len;
368
 	undinet_tbd.Xmit.segment = rm_ds;
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
 	/* Issue PXE API call */
369
 	/* Issue PXE API call */
373
 	if ( ( rc = undinet_call ( undinic, PXENV_UNDI_TRANSMIT,
370
 	if ( ( rc = undinet_call ( undinic, PXENV_UNDI_TRANSMIT,

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

147
 					 "=b" ( next ), "=D" ( discard_D ),
147
 					 "=b" ( next ), "=D" ( discard_D ),
148
 					 "=c" ( discard_c ), "=d" ( discard_d )
148
 					 "=c" ( discard_c ), "=d" ( discard_d )
149
 				       : "a" ( 0xe820 ), "b" ( next ),
149
 				       : "a" ( 0xe820 ), "b" ( next ),
150
-					 "D" ( &__from_data16 ( e820buf ) ),
150
+					 "D" ( __from_data16 ( &e820buf ) ),
151
 					 "c" ( sizeof ( e820buf ) ),
151
 					 "c" ( sizeof ( e820buf ) ),
152
 					 "d" ( SMAP )
152
 					 "d" ( SMAP )
153
 				       : "memory" );
153
 				       : "memory" );

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

19
 #define __text16_array( variable,array ) variable array
19
 #define __text16_array( variable,array ) variable array
20
 #define __use_data16( variable ) variable
20
 #define __use_data16( variable ) variable
21
 #define __use_text16( variable ) variable
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
 /* Real-mode data and code segments */
25
 /* Real-mode data and code segments */
26
 static inline __attribute__ (( always_inline )) unsigned int _rm_cs ( void ) {
26
 static inline __attribute__ (( always_inline )) unsigned int _rm_cs ( void ) {

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

51
 	( * ( ( typeof ( _text16_ ## variable ) * )			\
51
 	( * ( ( typeof ( _text16_ ## variable ) * )			\
52
 	      & ( text16 [ ( size_t ) & ( _text16_ ## variable ) ] ) ) )
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
 /* Variables in librm.S, present in the normal data segment */
62
 /* Variables in librm.S, present in the normal data segment */
63
 extern uint16_t __data16 ( rm_cs );
63
 extern uint16_t __data16 ( rm_cs );

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

441
 					   "addw $4, %%sp\n\t" )
441
 					   "addw $4, %%sp\n\t" )
442
 			       : "=a" ( rc ), "=b" ( discard_b ),
442
 			       : "=a" ( rc ), "=b" ( discard_b ),
443
 			         "=c" ( discard_c )
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
 			          "c" ( rm_cs )
446
 			          "c" ( rm_cs )
447
 			       : "edx", "esi", "edi", "ebp", "memory" );
447
 			       : "edx", "esi", "edi", "ebp", "memory" );
448
 
448
 

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

42
 
42
 
43
 	/* Fill in UNDI loader structure */
43
 	/* Fill in UNDI loader structure */
44
 	undi_loader->PXEptr.segment = rm_cs;
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
 	undi_loader->PXENVptr.segment = rm_cs;
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
 	undi_loader->Status = PXENV_STATUS_SUCCESS;
49
 	undi_loader->Status = PXENV_STATUS_SUCCESS;
52
 	return PXENV_EXIT_SUCCESS;
50
 	return PXENV_EXIT_SUCCESS;

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

196
 		 * fill it in.
196
 		 * fill it in.
197
 		 */
197
 		 */
198
 		get_cached_info->Buffer.segment = rm_ds;
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
 		get_cached_info->BufferSize = sizeof ( *info );
200
 		get_cached_info->BufferSize = sizeof ( *info );
202
 		DBG ( " returning %04x:%04x+%04x['%x']",
201
 		DBG ( " returning %04x:%04x+%04x['%x']",
203
 		      get_cached_info->Buffer.segment,
202
 		      get_cached_info->Buffer.segment,

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

597
 		undi_isr->FrameHeaderLength =
597
 		undi_isr->FrameHeaderLength =
598
 			pxe_netdev->ll_protocol->ll_header_len;
598
 			pxe_netdev->ll_protocol->ll_header_len;
599
 		undi_isr->Frame.segment = rm_ds;
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
 		/* Probably ought to fill in packet type */
601
 		/* Probably ought to fill in packet type */
603
 		undi_isr->ProtType = P_UNKNOWN;
602
 		undi_isr->ProtType = P_UNKNOWN;
604
 		undi_isr->PktType = XMT_DESTADDR;
603
 		undi_isr->PktType = XMT_DESTADDR;

Loading…
Cancel
Save