瀏覽代碼

Create two easy-to-use entry points in libprefix: install and

install_prealloc.  I *think* these will suffice for all the 16-bit
prefixes.
tags/v0.9.3
Michael Brown 19 年之前
父節點
當前提交
10c28a51bd
共有 4 個檔案被更改,包括 122 行新增35 行删除
  1. 1
    8
      src/arch/i386/prefix/dskprefix.S
  2. 99
    10
      src/arch/i386/prefix/libprefix.S
  3. 21
    16
      src/arch/i386/scripts/i386.lds
  4. 1
    1
      src/arch/i386/transitions/librm.S

+ 1
- 8
src/arch/i386/prefix/dskprefix.S 查看文件

348
 	.word 0xAA55
348
 	.word 0xAA55
349
 
349
 
350
 start_runtime:
350
 start_runtime:
351
-	/* Install .text16 and .data16 to top of base memory */
352
-	call	alloc_basemem
353
-	call	install_basemem
354
-
355
-	/* Install .text and .data to 2MB mark */
356
-	movl	$(2<<20), %edi
357
-	call	install_highmem
351
+	call	install
358
 
352
 
359
 	/* Jump to .text16 segment */
353
 	/* Jump to .text16 segment */
360
 	pushw	%ax
354
 	pushw	%ax
362
 	lret
356
 	lret
363
 	.section ".text16", "awx", @progbits
357
 	.section ".text16", "awx", @progbits
364
 1:
358
 1:
365
-	call	init_gdt
366
 	pushl	$initialise
359
 	pushl	$initialise
367
 	data32 call	prot_call
360
 	data32 call	prot_call
368
 	popl	%eax /* discard */
361
 	popl	%eax /* discard */

+ 99
- 10
src/arch/i386/prefix/libprefix.S 查看文件

30
  * Parameters:
30
  * Parameters:
31
  *   %esi : byte offset within loaded image (must be a multiple of 16)
31
  *   %esi : byte offset within loaded image (must be a multiple of 16)
32
  *   %es:edi : destination address
32
  *   %es:edi : destination address
33
- *   %ecx : length to install
33
+ *   %ecx : length of (decompressed) data
34
+ *   %edx : total length of block (including any uninitialised data portion)
34
  * Returns:
35
  * Returns:
35
  *   none
36
  *   none
36
  * Corrupts:
37
  * Corrupts:
37
- *   %esi, %edi, %ecx
38
+ *   %esi, %edi, %ecx, %edx
38
  ****************************************************************************
39
  ****************************************************************************
39
  */
40
  */
40
 	.section ".prefix.lib"
41
 	.section ".prefix.lib"
42
 install_block:
43
 install_block:
43
 	/* Preserve registers */
44
 	/* Preserve registers */
44
 	pushw	%ds
45
 	pushw	%ds
45
-	pushw	%ax
46
+	pushw	%eax
46
 	
47
 	
47
 	/* Starting segment => %ds */
48
 	/* Starting segment => %ds */
48
 	movw	%cs, %ax
49
 	movw	%cs, %ax
51
 	movw	%ax, %ds
52
 	movw	%ax, %ds
52
 	xorl	%esi, %esi
53
 	xorl	%esi, %esi
53
 
54
 
55
+	/* Calculate start and length of uninitialised data portion */
56
+	leal	(%edi,%ecx), %eax
57
+	subl	%ecx, %edx
58
+	
54
 	/* Do the copy */
59
 	/* Do the copy */
55
 	cld
60
 	cld
56
-	addr32 rep movsb /* or "call decompress16" */
61
+	rep addr32 movsb /* or "call decompress16" */
62
+
63
+	/* Zero remaining space */
64
+	movl	%eax, %edi
65
+	movl	%edx, %ecx
66
+	xorb	%al, %al
67
+	rep addr32 stosb
57
 
68
 
58
 	/* Restore registers */
69
 	/* Restore registers */
59
-	popw	%ax
70
+	popw	%eax
60
 	popw	%ds
71
 	popw	%ds
61
 	ret
72
 	ret
62
 	.size install_block, . - install_block
73
 	.size install_block, . - install_block
79
  */
90
  */
80
 	.section ".prefix.lib"
91
 	.section ".prefix.lib"
81
 	.code16
92
 	.code16
82
-	.globl alloc_basemem
83
 alloc_basemem:
93
 alloc_basemem:
84
 	/* FBMS => %ax as segment address */
94
 	/* FBMS => %ax as segment address */
85
 	movw	$0x40, %ax
95
 	movw	$0x40, %ax
121
  */
131
  */
122
 	.section ".prefix.lib"
132
 	.section ".prefix.lib"
123
 	.code16
133
 	.code16
124
-	.globl install_basemem
125
 install_basemem:
134
 install_basemem:
126
 	/* Preserve registers */
135
 	/* Preserve registers */
127
 	pushw	%es
136
 	pushw	%es
128
 	pushl	%esi
137
 	pushl	%esi
129
 	pushl	%edi
138
 	pushl	%edi
130
 	pushl	%ecx
139
 	pushl	%ecx
140
+	pushl	%edx
131
 
141
 
132
 	/* Install .text16 */
142
 	/* Install .text16 */
133
 	movw	%ax, %es
143
 	movw	%ax, %es
134
 	xorl	%edi, %edi
144
 	xorl	%edi, %edi
135
 	movl	$_text16_load_offset, %esi
145
 	movl	$_text16_load_offset, %esi
136
 	movl	$_text16_size, %ecx
146
 	movl	$_text16_size, %ecx
147
+	movl	%ecx, %edx
137
 	call	install_block
148
 	call	install_block
138
 
149
 
139
 	/* Install .data16 */
150
 	/* Install .data16 */
141
 	xorl	%edi, %edi	
152
 	xorl	%edi, %edi	
142
 	movl	$_data16_load_offset, %esi
153
 	movl	$_data16_load_offset, %esi
143
 	movl	$_data16_progbits_size, %ecx
154
 	movl	$_data16_progbits_size, %ecx
155
+	movl	$_data16_size, %edx
144
 	call	install_block
156
 	call	install_block
145
 
157
 
146
 	/* Restore registers */
158
 	/* Restore registers */
159
+	popl	%edx
147
 	popl	%ecx
160
 	popl	%ecx
148
 	popl	%edi
161
 	popl	%edi
149
 	popl	%esi
162
 	popl	%esi
160
  * simpler.
173
  * simpler.
161
  ****************************************************************************
174
  ****************************************************************************
162
  */
175
  */
176
+	
177
+#ifndef KEEP_IT_REAL
178
+	
163
 	.section ".prefix.lib"
179
 	.section ".prefix.lib"
164
 	.align 16
180
 	.align 16
165
 gdt:
181
 gdt:
180
 gdt_end:
196
 gdt_end:
181
 	.equ	gdt_length, gdt_end - gdt
197
 	.equ	gdt_length, gdt_end - gdt
182
 	.size gdt, . - gdt
198
 	.size gdt, . - gdt
199
+	
200
+#endif /* KEEP_IT_REAL */
183
 
201
 
184
 /****************************************************************************
202
 /****************************************************************************
185
  * set_segment_limits (real-mode near call)
203
  * set_segment_limits (real-mode near call)
190
  *   %cx : Segment limit ($REAL_DS or $FLAT_DS)
208
  *   %cx : Segment limit ($REAL_DS or $FLAT_DS)
191
  ****************************************************************************
209
  ****************************************************************************
192
  */
210
  */
211
+
212
+#ifndef KEEP_IT_REAL
213
+	
193
 	.section ".prefix.lib"
214
 	.section ".prefix.lib"
194
 	.code16
215
 	.code16
195
 set_segment_limits:
216
 set_segment_limits:
222
 	ret
243
 	ret
223
 	.size set_segment_limits, . - set_segment_limits
244
 	.size set_segment_limits, . - set_segment_limits
224
 	
245
 	
246
+#endif /* KEEP_IT_REAL */
247
+	
225
 /****************************************************************************
248
 /****************************************************************************
226
  * install_highmem (real-mode near call)
249
  * install_highmem (real-mode near call)
227
  *
250
  *
235
  *   none
258
  *   none
236
  ****************************************************************************
259
  ****************************************************************************
237
  */
260
  */
261
+
262
+#ifndef KEEP_IT_REAL
263
+
238
 	.section ".prefix.lib"
264
 	.section ".prefix.lib"
239
 	.code16
265
 	.code16
240
-	.globl install_highmem
241
 install_highmem:
266
 install_highmem:
242
 	/* Preserve registers and interrupt status */
267
 	/* Preserve registers and interrupt status */
243
 	pushfl
268
 	pushfl
244
 	pushl	%esi
269
 	pushl	%esi
245
 	pushl	%edi
270
 	pushl	%edi
246
 	pushl	%ecx
271
 	pushl	%ecx
272
+	pushl	%edx
247
 		
273
 		
248
 	/* Disable interrupts and flatten real mode */
274
 	/* Disable interrupts and flatten real mode */
249
 	cli
275
 	cli
253
 	/* Install .text and .data to specified address */
279
 	/* Install .text and .data to specified address */
254
 	xorw	%cx, %cx
280
 	xorw	%cx, %cx
255
 	movw	%cx, %es
281
 	movw	%cx, %es
256
-	movl	$_text_load_offset, %esi
257
-	movl	$_text_progbits_size, %ecx
282
+	movl	$_textdata_load_offset, %esi
283
+	movl	$_textdata_progbits_size, %ecx
284
+	movl	$_textdata_size, %edx
258
 	call	install_block
285
 	call	install_block
259
 
286
 
260
 	/* Unflatten real mode */
287
 	/* Unflatten real mode */
262
 	call	set_segment_limits
289
 	call	set_segment_limits
263
 
290
 
264
 	/* Restore registers and interrupt status */
291
 	/* Restore registers and interrupt status */
292
+	popl	%edx
265
 	popl	%ecx
293
 	popl	%ecx
266
 	popl	%edi
294
 	popl	%edi
267
 	popl	%esi
295
 	popl	%esi
268
 	popfl
296
 	popfl
269
 	ret
297
 	ret
270
 	.size install_highmem, . - install_highmem
298
 	.size install_highmem, . - install_highmem
299
+	
300
+#endif /* KEEP_IT_REAL */
301
+	
302
+/****************************************************************************
303
+ * install (real-mode near call)
304
+ * install_prealloc (real-mode near call)
305
+ *
306
+ * Install all text and data segments.
307
+ *
308
+ * Parameters:
309
+ *   %ax : .text16 segment address (install_prealloc only)
310
+ *   %bx : .data16 segment address (install_prealloc only)
311
+ * Returns:
312
+ *   %ax : .text16 segment address
313
+ *   %bx : .data16 segment address
314
+ *   %edi : .text physical address (if applicable)
315
+ * Corrupts:
316
+ *   none
317
+ ****************************************************************************
318
+ */
319
+	.section ".prefix.lib"
320
+	.code16
321
+	.globl install
322
+install:
323
+	/* Allocate space for .text16 and .data16 */
324
+	call	alloc_basemem
325
+	.size install, . - install
326
+	.globl install_prealloc
327
+install_prealloc:
328
+	/* Install .text16 and .data16 */
329
+	call	install_basemem
330
+
331
+#ifndef KEEP_IT_REAL
332
+	/* Install .text and .data to 2MB mark.  Use 2MB to avoid
333
+	 * problems with A20.
334
+	 */
335
+	movl	$(2<<20), %edi
336
+	call	install_highmem
337
+
338
+	/* Continue executing in .text16 segment */
339
+	pushw	%cs
340
+	pushw	$2f
341
+	pushw	%ax
342
+	pushw	$1f
343
+	lret
344
+	.section ".text16", "awx", @progbits
345
+1:
346
+	/* Set up protected-mode GDT, call relocate(), reset GDT */
347
+	call	init_gdt
348
+	pushl	$relocate
349
+	data32 call	prot_call
350
+	addw	$4, %sp
351
+	call	init_gdt
352
+
353
+	/* Return to executing in .prefix section */
354
+	lret
355
+	.section ".prefix.lib"
356
+2:
357
+#endif
358
+	ret
359
+	.size install_prealloc, . - install_prealloc

+ 21
- 16
src/arch/i386/scripts/i386.lds 查看文件

20
      * will default to:
20
      * will default to:
21
      *
21
      *
22
      *   _prefix_link_addr	= 0
22
      *   _prefix_link_addr	= 0
23
-     *   _text_link_addr	= 0
23
+     *   _textdata_link_addr	= 0
24
      *   _load_addr		= 0
24
      *   _load_addr		= 0
25
      *   _max_align		= 16
25
      *   _max_align		= 16
26
      * 
26
      * 
108
      * The 32-bit sections
108
      * The 32-bit sections
109
      */
109
      */
110
 
110
 
111
-    _text_link_addr = DEFINED ( _text_link_addr ) ? _text_link_addr : 0;
112
-    . = _text_link_addr;
111
+    _textdata_link_addr = ( DEFINED ( _textdata_link_addr ) ?
112
+			    _textdata_link_addr : 0 );
113
+    . = _textdata_link_addr;
114
+    _textdata = .;
115
+
113
     _text = .;
116
     _text = .;
114
 
117
 
115
-    .text : AT ( _text_load_offset + __text ) {
118
+    .text : AT ( _textdata_load_offset + __text ) {
116
 	__text = .;
119
 	__text = .;
117
 	*(.text)
120
 	*(.text)
118
 	*(.text.*)
121
 	*(.text.*)
122
 
125
 
123
     _data = .;
126
     _data = .;
124
 
127
 
125
-    .rodata : AT ( _text_load_offset + __rodata ) {
128
+    .rodata : AT ( _textdata_load_offset + __rodata ) {
126
 	__rodata = .;
129
 	__rodata = .;
127
 	*(.rodata)
130
 	*(.rodata)
128
 	*(.rodata.*)
131
 	*(.rodata.*)
129
     }
132
     }
130
-    .data : AT ( _text_load_offset + __data ) {
133
+    .data : AT ( _textdata_load_offset + __data ) {
131
 	__data = .;
134
 	__data = .;
132
 	*(.data)
135
 	*(.data)
133
 	*(.data.*)
136
 	*(.data.*)
134
 	*(SORT(.tbl.*))		/* Various tables.  See include/tables.h */
137
 	*(SORT(.tbl.*))		/* Various tables.  See include/tables.h */
135
-	_etext_progbits = .;
138
+	_etextdata_progbits = .;
136
     }
139
     }
137
-    .bss : AT ( _text_load_offset + __bss ) {
140
+    .bss : AT ( _textdata_load_offset + __bss ) {
138
 	__bss = .;
141
 	__bss = .;
139
 	_bss = .;
142
 	_bss = .;
140
 	*(.bss)
143
 	*(.bss)
142
 	*(COMMON)
145
 	*(COMMON)
143
 	_ebss = .;
146
 	_ebss = .;
144
     }
147
     }
145
-    .stack : AT ( _text_load_offset + __stack ) {
148
+    .stack : AT ( _textdata_load_offset + __stack ) {
146
 	__stack = .;
149
 	__stack = .;
147
 	*(.stack)
150
 	*(.stack)
148
 	*(.stack.*)
151
 	*(.stack.*)
150
 
153
 
151
     _edata = .;
154
     _edata = .;
152
 
155
 
156
+    _etextdata = .;
157
+
153
     _end = .;
158
     _end = .;
154
 
159
 
155
     /*
160
     /*
194
     _data16_progbits_size   = _edata16_progbits - _data16;
199
     _data16_progbits_size   = _edata16_progbits - _data16;
195
     .			    = _data16_load_addr + _data16_progbits_size;
200
     .			    = _data16_load_addr + _data16_progbits_size;
196
 
201
 
197
-    .			   -= _text_link_addr;
198
-    _text_load_offset	    = ALIGN ( _max_align );
199
-    _text_load_addr	    = _text_link_addr + _text_load_offset;
200
-    _text_size		    = _etext - _text;
201
-    _text_progbits_size	    = _etext_progbits - _text;
202
-    .			    = _text_load_addr + _text_progbits_size;
202
+    .			   -= _textdata_link_addr;
203
+    _textdata_load_offset   = ALIGN ( _max_align );
204
+    _textdata_load_addr	    = _textdata_link_addr + _textdata_load_offset;
205
+    _textdata_size	    = _etextdata - _textdata;
206
+    _textdata_progbits_size = _etextdata_progbits - _textdata;
207
+    .			    = _textdata_load_addr + _textdata_progbits_size;
203
 
208
 
204
     .			    = ALIGN ( _max_align );
209
     .			    = ALIGN ( _max_align );
205
 
210
 
223
     _assert = ASSERT ( ( . == ALIGN ( _max_align ) ),
228
     _assert = ASSERT ( ( . == ALIGN ( _max_align ) ),
224
 		       "_data16 is badly aligned" );
229
 		       "_data16 is badly aligned" );
225
 
230
 
226
-    . = _text_load_addr - _text_link_addr;
231
+    . = _textdata_load_addr - _textdata_link_addr;
227
     _assert = ASSERT ( ( . == ALIGN ( _max_align ) ),
232
     _assert = ASSERT ( ( . == ALIGN ( _max_align ) ),
228
 		       "_text is badly aligned" );
233
 		       "_text is badly aligned" );
229
 
234
 

+ 1
- 1
src/arch/i386/transitions/librm.S 查看文件

357
 	popw	%gs
357
 	popw	%gs
358
 	popal
358
 	popal
359
 	popfl
359
 	popfl
360
-	ret
360
+	data32 ret
361
 
361
 
362
 /****************************************************************************
362
 /****************************************************************************
363
  * real_call (protected-mode near call, 32-bit virtual return address)
363
  * real_call (protected-mode near call, 32-bit virtual return address)

Loading…
取消
儲存