Browse Source

(Redoing check-in lost by SourceForge's failure.)

Use .text16.data section with "aw" attributes, to avoid section type
conflicts when placing both code and data into .text16.

Add __from_{text16,data16}.
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
f7b963da51

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

15
 #define __text16( variable ) variable
15
 #define __text16( variable ) variable
16
 #define __use_data16( variable ) variable
16
 #define __use_data16( variable ) variable
17
 #define __use_text16( variable ) variable
17
 #define __use_text16( variable ) variable
18
+#define __from_data16( variable ) variable
19
+#define __from_text16( variable ) variable
18
 
20
 
19
 /* Copy to/from base memory */
21
 /* Copy to/from base memory */
20
 
22
 

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

25
 
25
 
26
 #define __text16( variable )						\
26
 #define __text16( variable )						\
27
 	_text16_ ## variable __asm__ ( #variable )			\
27
 	_text16_ ## variable __asm__ ( #variable )			\
28
-	__attribute__ (( section ( ".text16" ) ))
28
+	__attribute__ (( section ( ".text16.data" ) ))
29
 
29
 
30
 #define __use_data16( variable )					\
30
 #define __use_data16( variable )					\
31
 	( * ( ( typeof ( _data16_ ## variable ) * )			\
31
 	( * ( ( typeof ( _data16_ ## variable ) * )			\
35
 	( * ( ( typeof ( _text16_ ## variable ) * )			\
35
 	( * ( ( typeof ( _text16_ ## variable ) * )			\
36
 	      & ( text16 [ ( size_t ) & ( _text16_ ## variable ) ] ) ) )
36
 	      & ( text16 [ ( size_t ) & ( _text16_ ## variable ) ] ) ) )
37
 
37
 
38
+#define __from_data16( variable )					\
39
+	( * ( ( typeof ( variable ) * )					\
40
+	      ( ( ( void * ) &(variable) ) - ( ( void * ) data16 ) ) ) )
41
+
42
+#define __from_text16( variable )					\
43
+	( * ( ( typeof ( variable ) * )					\
44
+	      ( ( ( void * ) &(variable) ) - ( ( void * ) text16 ) ) ) )
45
+
38
 /* Variables in librm.S, present in the normal data segment */
46
 /* Variables in librm.S, present in the normal data segment */
39
 extern uint16_t rm_sp;
47
 extern uint16_t rm_sp;
40
 extern uint16_t rm_ss;
48
 extern uint16_t rm_ss;
58
 #define VIRTUAL(x,y) ( phys_to_virt ( ( ( x ) << 4 ) + ( y ) ) )
66
 #define VIRTUAL(x,y) ( phys_to_virt ( ( ( x ) << 4 ) + ( y ) ) )
59
 
67
 
60
 /* Copy to/from base memory */
68
 /* Copy to/from base memory */
61
-static inline void copy_to_real_librm ( uint16_t dest_seg, uint16_t dest_off,
62
-					void *src, size_t n ) {
69
+static inline __attribute__ (( always_inline )) void
70
+copy_to_real_librm ( unsigned int dest_seg, unsigned int dest_off,
71
+		     void *src, size_t n ) {
63
 	memcpy ( VIRTUAL ( dest_seg, dest_off ), src, n );
72
 	memcpy ( VIRTUAL ( dest_seg, dest_off ), src, n );
64
 }
73
 }
65
-static inline void copy_from_real_librm ( void *dest,
66
-					  uint16_t src_seg, uint16_t src_off,
67
-					  size_t n ) {
74
+static inline __attribute__ (( always_inline )) void
75
+copy_from_real_librm ( void *dest, unsigned int src_seg,
76
+		       unsigned int src_off, size_t n ) {
68
 	memcpy ( dest, VIRTUAL ( src_seg, src_off ), n );
77
 	memcpy ( dest, VIRTUAL ( src_seg, src_off ), n );
69
 }
78
 }
70
 #define put_real_librm( var, dest_seg, dest_off )			      \
79
 #define put_real_librm( var, dest_seg, dest_off )			      \

+ 12
- 4
src/arch/i386/include/realmode.h View File

15
 /* Segment:offset structure.  Note that the order within the structure
15
 /* Segment:offset structure.  Note that the order within the structure
16
  * is offset:segment.
16
  * is offset:segment.
17
  */
17
  */
18
-typedef struct {
18
+struct segoff {
19
 	uint16_t offset;
19
 	uint16_t offset;
20
 	uint16_t segment;
20
 	uint16_t segment;
21
-} __attribute__ (( packed )) segoff_t;
21
+} __attribute__ (( packed ));
22
+
23
+typedef struct segoff segoff_t;
22
 
24
 
23
 /* Macro hackery needed to stringify bits of inline assembly */
25
 /* Macro hackery needed to stringify bits of inline assembly */
24
 #define RM_XSTR(x) #x
26
 #define RM_XSTR(x) #x
50
  *   extern uint32_t __data16 ( bar );
52
  *   extern uint32_t __data16 ( bar );
51
  *   #define bar __use_data16 ( bar );
53
  *   #define bar __use_data16 ( bar );
52
  *
54
  *
53
- *   extern long __data16 ( baz ) = 0xff000000UL;
54
- *   #define bar __use_data16 ( baz );
55
+ *   static long __data16 ( baz ) = 0xff000000UL;
56
+ *   #define baz __use_data16 ( baz );
55
  *
57
  *
56
  * i.e. take a normal declaration, add __data16() around the variable
58
  * i.e. take a normal declaration, add __data16() around the variable
57
  * name, and add a line saying "#define <name> __use_data16 ( <name> )
59
  * name, and add a line saying "#define <name> __use_data16 ( <name> )
83
  * Variables may also be placed in .text16 using __text16 and
85
  * Variables may also be placed in .text16 using __text16 and
84
  * __use_text16.  Some variables (e.g. chained interrupt vectors) fit
86
  * __use_text16.  Some variables (e.g. chained interrupt vectors) fit
85
  * most naturally in .text16; most should be in .data16.
87
  * most naturally in .text16; most should be in .data16.
88
+ *
89
+ * If you have only a pointer to a magic symbol within .data16 or
90
+ * .text16, rather than the symbol itself, you can attempt to extract
91
+ * the underlying symbol name using __from_data16() or
92
+ * __from_text16().  This is not for the faint-hearted; check the
93
+ * assembler output to make sure that it's doing the right thing.
86
  */
94
  */
87
 
95
 
88
 /*
96
 /*

+ 5
- 3
src/arch/i386/transitions/librm.S View File

19
 #define SIZEOF_I386_ALL_REGS	( SIZEOF_REAL_MODE_REGS + SIZEOF_I386_FLAGS )
19
 #define SIZEOF_I386_ALL_REGS	( SIZEOF_REAL_MODE_REGS + SIZEOF_I386_FLAGS )
20
 	
20
 	
21
 	.arch i386
21
 	.arch i386
22
-	.section ".text16", "awx", @progbits
22
+	.section ".text16", "ax", @progbits
23
+	.section ".text16.data", "aw", @progbits
24
+	.section ".data16", "aw", @progbits
23
 
25
 
24
 /****************************************************************************
26
 /****************************************************************************
25
  * Global descriptor table
27
  * Global descriptor table
45
 #else
47
 #else
46
 #define RM_LIMIT_16_19__AVL__SIZE__GRANULARITY 0x00
48
 #define RM_LIMIT_16_19__AVL__SIZE__GRANULARITY 0x00
47
 #endif
49
 #endif
48
-	.section ".data16", "aw", @progbits
50
+	.section ".data16"
49
 	.align 16
51
 	.align 16
50
 gdt:
52
 gdt:
51
 gdt_limit:		.word gdt_length - 1
53
 gdt_limit:		.word gdt_length - 1
308
 p2r_jump_vector:
310
 p2r_jump_vector:
309
 	.word	p2r_jump_target
311
 	.word	p2r_jump_target
310
 rm_cs:	.word 0
312
 rm_cs:	.word 0
311
-	.section ".text16"
313
+	.section ".text16.data"
312
 rm_ds:	.word 0
314
 rm_ds:	.word 0
313
 	
315
 	
314
 /****************************************************************************
316
 /****************************************************************************

Loading…
Cancel
Save