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,6 +15,8 @@
15 15
 #define __text16( variable ) variable
16 16
 #define __use_data16( variable ) variable
17 17
 #define __use_text16( variable ) variable
18
+#define __from_data16( variable ) variable
19
+#define __from_text16( variable ) variable
18 20
 
19 21
 /* Copy to/from base memory */
20 22
 

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

@@ -25,7 +25,7 @@ extern char *text16;
25 25
 
26 26
 #define __text16( variable )						\
27 27
 	_text16_ ## variable __asm__ ( #variable )			\
28
-	__attribute__ (( section ( ".text16" ) ))
28
+	__attribute__ (( section ( ".text16.data" ) ))
29 29
 
30 30
 #define __use_data16( variable )					\
31 31
 	( * ( ( typeof ( _data16_ ## variable ) * )			\
@@ -35,6 +35,14 @@ extern char *text16;
35 35
 	( * ( ( typeof ( _text16_ ## variable ) * )			\
36 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 46
 /* Variables in librm.S, present in the normal data segment */
39 47
 extern uint16_t rm_sp;
40 48
 extern uint16_t rm_ss;
@@ -58,13 +66,14 @@ extern void gateA20_set ( void );
58 66
 #define VIRTUAL(x,y) ( phys_to_virt ( ( ( x ) << 4 ) + ( y ) ) )
59 67
 
60 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 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 77
 	memcpy ( dest, VIRTUAL ( src_seg, src_off ), n );
69 78
 }
70 79
 #define put_real_librm( var, dest_seg, dest_off )			      \

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

@@ -15,10 +15,12 @@
15 15
 /* Segment:offset structure.  Note that the order within the structure
16 16
  * is offset:segment.
17 17
  */
18
-typedef struct {
18
+struct segoff {
19 19
 	uint16_t offset;
20 20
 	uint16_t segment;
21
-} __attribute__ (( packed )) segoff_t;
21
+} __attribute__ (( packed ));
22
+
23
+typedef struct segoff segoff_t;
22 24
 
23 25
 /* Macro hackery needed to stringify bits of inline assembly */
24 26
 #define RM_XSTR(x) #x
@@ -50,8 +52,8 @@ typedef struct {
50 52
  *   extern uint32_t __data16 ( bar );
51 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 58
  * i.e. take a normal declaration, add __data16() around the variable
57 59
  * name, and add a line saying "#define <name> __use_data16 ( <name> )
@@ -83,6 +85,12 @@ typedef struct {
83 85
  * Variables may also be placed in .text16 using __text16 and
84 86
  * __use_text16.  Some variables (e.g. chained interrupt vectors) fit
85 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,7 +19,9 @@
19 19
 #define SIZEOF_I386_ALL_REGS	( SIZEOF_REAL_MODE_REGS + SIZEOF_I386_FLAGS )
20 20
 	
21 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 27
  * Global descriptor table
@@ -45,7 +47,7 @@
45 47
 #else
46 48
 #define RM_LIMIT_16_19__AVL__SIZE__GRANULARITY 0x00
47 49
 #endif
48
-	.section ".data16", "aw", @progbits
50
+	.section ".data16"
49 51
 	.align 16
50 52
 gdt:
51 53
 gdt_limit:		.word gdt_length - 1
@@ -308,7 +310,7 @@ p2r_jump_target:
308 310
 p2r_jump_vector:
309 311
 	.word	p2r_jump_target
310 312
 rm_cs:	.word 0
311
-	.section ".text16"
313
+	.section ".text16.data"
312 314
 rm_ds:	.word 0
313 315
 	
314 316
 /****************************************************************************

Loading…
Cancel
Save