Procházet zdrojové kódy

Added methods for efficiently declaring and accessing variables in

.data16.  librm will need to supply "char *data16", i.e. the virtual
address of the start of .data16.
tags/v0.9.3
Michael Brown před 19 roky
rodič
revize
f4429533a6

+ 4
- 0
src/arch/i386/include/libkir.h Zobrazit soubor

@@ -10,6 +10,10 @@
10 10
  *
11 11
  */
12 12
 
13
+/* Access to variables in .data16, in a way compatible with librm */
14
+#define __data16( variable ) variable
15
+#define __use_data16( variable ) variable
16
+
13 17
 /* Copy to/from base memory */
14 18
 
15 19
 static inline void copy_to_real_libkir ( uint16_t dest_seg, uint16_t dest_off,

+ 11
- 0
src/arch/i386/include/librm.h Zobrazit soubor

@@ -15,6 +15,17 @@
15 15
  *
16 16
  */
17 17
 
18
+/* Access to variables in .data16 */
19
+extern char *data16;
20
+
21
+#define __data16( variable )						\
22
+	_data16_ ## variable __asm__ ( #variable )			\
23
+	__attribute__ (( section ( ".data16" ) ))
24
+
25
+#define __use_data16( variable )					\
26
+	( * ( ( typeof ( _data16_ ## variable ) * )			\
27
+	      & ( data16 [ ( size_t ) & ( _data16_ ## variable ) ] ) ) )
28
+
18 29
 /* Variables in librm.S, present in the normal data segment */
19 30
 extern uint16_t rm_sp;
20 31
 extern uint16_t rm_ss;

+ 44
- 0
src/arch/i386/include/realmode.h Zobrazit soubor

@@ -38,6 +38,50 @@ typedef struct {
38 38
  *
39 39
  */
40 40
 
41
+/*
42
+ * Declaration of variables in .data16
43
+ *
44
+ * To place a variable in the .data16 segment, declare it using the
45
+ * pattern:
46
+ *
47
+ *   int __data16 ( foo );
48
+ *   #define foo __use_data16 ( foo );
49
+ *
50
+ *   extern uint32_t __data16 ( bar );
51
+ *   #define bar __use_data16 ( bar );
52
+ *
53
+ *   extern long __data16 ( baz ) = 0xff000000UL;
54
+ *   #define bar __use_data16 ( baz );
55
+ *
56
+ * i.e. take a normal declaration, add __data16() around the variable
57
+ * name, and add a line saying "#define <name> __use_data16 ( <name> )
58
+ *
59
+ * You can then access them just like any other variable, for example
60
+ *
61
+ *   int x = foo + bar;
62
+ *
63
+ * This magic is achieved at a cost of only around 7 extra bytes per
64
+ * group of accesses to .data16 variables.  When using KEEP_IT_REAL,
65
+ * there is no extra cost.
66
+ *
67
+ * You should place variables in .data16 when they need to be accessed
68
+ * by real-mode code.  Real-mode assembly (e.g. as created by
69
+ * REAL_EXEC()) can access these variables via the usual data segment.
70
+ * You can therefore write something like
71
+ *
72
+ *   static uint16_t __data16 ( foo );
73
+ *   #define foo __use_data16 ( foo )
74
+ *
75
+ *   int bar ( void ) {
76
+ *     REAL_EXEC ( baz,
77
+ *                 "int $0xff\n\t"
78
+ *                 "movw %ax, foo",
79
+ *                 ... );
80
+ *     return foo;
81
+ *   }
82
+ *
83
+ */
84
+
41 85
 /*
42 86
  * void copy_to_real ( uint16_t dest_seg, uint16_t dest_off,
43 87
  *		       void *src, size_t n )

Načítá se…
Zrušit
Uložit