Browse Source

[pcbios] Support arbitrary splits of the e820 memory map

Allow for an arbitrary number of splits of the system memory map via
INT 15,e820.

Features of the new map-mangling algorithm include:

  Supports random access to e820 map entries.

  Requires only sequential access support from the underlying e820
  map, even if our caller uses random access.

  Empty regions will always be stripped.

  Always terminates with %ebx=0, even if the underlying map terminates
  with CF=1.

  Allows for an arbitrary number of hidden regions, with underlying
  regions split into as many subregions as necessary.

Total size increase to achieve this is 193 bytes.
tags/v0.9.4
Michael Brown 16 years ago
parent
commit
320b072c7a

+ 2
- 2
src/arch/i386/core/umalloc.c View File

194
 
194
 
195
 	/* Collect any free blocks and update hidden memory region */
195
 	/* Collect any free blocks and update hidden memory region */
196
 	ecollect_free();
196
 	ecollect_free();
197
-	hide_region ( EXTMEM, user_to_phys ( bottom, -sizeof ( extmem ) ),
198
-		      user_to_phys ( top, 0 ) );
197
+	hide_umalloc ( user_to_phys ( bottom, -sizeof ( extmem ) ),
198
+		       user_to_phys ( top, 0 ) );
199
 
199
 
200
 	return ( new_size ? new : UNOWHERE );
200
 	return ( new_size ? new : UNOWHERE );
201
 }
201
 }

+ 73
- 311
src/arch/i386/firmware/pcbios/e820mangler.S View File

26
 #define SMAP 0x534d4150
26
 #define SMAP 0x534d4150
27
 
27
 
28
 /****************************************************************************
28
 /****************************************************************************
29
- * Check for overlap
30
  *
29
  *
31
- * Parameters:
32
- *  %edx:%eax	Region start
33
- *  %ecx:%ebx	Region end
34
- *  %si		Pointer to hidden region descriptor
35
- * Returns:
36
- *  CF set	Region overlaps
37
- *  CF clear	No overlap
38
- ****************************************************************************
39
- */ 
40
-	.section ".text16"
41
-check_overlap:
42
-	/* If start >= hidden_end, there is no overlap. */
43
-	testl	%edx, %edx
44
-	jnz	no_overlap
45
-	cmpl	4(%si), %eax
46
-	jae	no_overlap
47
-	/* If end <= hidden_start, there is no overlap; equivalently,
48
-	 * if end > hidden_start, there is overlap.
49
-	*/
50
-	testl	%ecx, %ecx
51
-	jnz	overlap
52
-	cmpl	0(%si), %ebx
53
-	ja	overlap
54
-no_overlap:
55
-	clc
56
-	ret
57
-overlap:
58
-	stc
59
-	ret
60
-	.size check_overlap, . - check_overlap
61
-
62
-/****************************************************************************
63
- * Check for overflow/underflow
30
+ * Allowed memory windows
64
  *
31
  *
65
- * Parameters:
66
- *  %edx:%eax	Region start
67
- *  %ecx:%ebx	Region end
68
- * Returns:
69
- *  CF set	start < end
70
- *  CF clear	start >= end
71
- ****************************************************************************
72
- */
73
-	.section ".text16"
74
-check_overflow:
75
-	pushl	%ecx
76
-	pushl	%ebx
77
-	subl	%eax, %ebx
78
-	sbbl	%edx, %ecx
79
-	popl	%ebx
80
-	popl	%ecx
81
-	ret
82
-	.size check_overflow, . - check_overflow
83
-	
84
-/****************************************************************************
85
- * Truncate towards start of region
32
+ * There are two ways to view this list.  The first is as a list of
33
+ * (non-overlapping) allowed memory regions, sorted by increasing
34
+ * address.  The second is as a list of (non-overlapping) hidden
35
+ * memory regions, again sorted by increasing address.  The second
36
+ * view is offset by half an entry from the first: think about this
37
+ * for a moment and it should make sense.
86
  *
38
  *
87
- * Parameters:
88
- *  %edx:%eax	Region start
89
- *  %ecx:%ebx	Region end
90
- *  %si		Pointer to hidden region descriptor
91
- * Returns:
92
- *  %edx:%eax	Modified region start
93
- *  %ecx:%ebx	Modified region end
94
- *  CF set	Region was truncated
95
- *  CF clear	Region was not truncated
96
- ****************************************************************************
97
- */
98
-	.section ".text16"
99
-truncate_to_start:
100
-	/* If overlaps, set region end = hidden region start */
101
-	call	check_overlap
102
-	jnc	99f
103
-	movl	0(%si), %ebx
104
-	xorl	%ecx, %ecx
105
-	/* If region end < region start, set region end = region start */
106
-	call	check_overflow
107
-	jnc	1f
108
-	movl	%eax, %ebx
109
-	movl	%edx, %ecx
110
-1:	stc
111
-99:	ret
112
-	.size truncate_to_start, . - truncate_to_start
113
-
114
-/****************************************************************************
115
- * Truncate towards end of region
39
+ * xxx_memory_window is used to indicate an "allowed region"
40
+ * structure, hidden_xxx_memory is used to indicate a "hidden region"
41
+ * structure.  Each structure is 16 bytes in length.
116
  *
42
  *
117
- * Parameters:
118
- *  %edx:%eax	Region start
119
- *  %ecx:%ebx	Region end
120
- *  %si		Pointer to hidden region descriptor
121
- * Returns:
122
- *  %edx:%eax	Modified region start
123
- *  %ecx:%ebx	Modified region end
124
- *  CF set	Region was truncated
125
- *  CF clear	Region was not truncated
126
  ****************************************************************************
43
  ****************************************************************************
127
  */
44
  */
128
-	.section ".text16"
129
-truncate_to_end:
130
-	/* If overlaps, set region start = hidden region end */
131
-	call	check_overlap
132
-	jnc	99f
133
-	movl	4(%si), %eax
134
-	xorl	%edx, %edx
135
-	/* If region start > region end, set region start = region end */
136
-	call	check_overflow
137
-	jnc	1f
138
-	movl	%ebx, %eax
139
-	movl	%ecx, %edx
140
-1:	stc
141
-99:	ret
142
-	.size truncate_to_end, . - truncate_to_end
143
-	
45
+	.section ".data16"
46
+	.align 16
47
+	.globl hidemem_base
48
+	.globl hidemem_umalloc
49
+	.globl hidemem_text
50
+memory_windows:
51
+base_memory_window:	.long 0x00000000, 0x00000000 /* Start of memory */
52
+
53
+hidemem_base:		.long 0x000a0000, 0x00000000 /* Changes at runtime */
54
+ext_memory_window:	.long 0x000a0000, 0x00000000 /* 640kB mark */
55
+
56
+hidemem_umalloc:	.long 0xffffffff, 0xffffffff /* Changes at runtime */
57
+			.long 0xffffffff, 0xffffffff /* Changes at runtime */
58
+
59
+hidemem_text:		.long 0xffffffff, 0xffffffff /* Changes at runtime */
60
+			.long 0xffffffff, 0xffffffff /* Changes at runtime */
61
+
62
+			.long 0xffffffff, 0xffffffff /* End of memory */
63
+memory_windows_end:
64
+
144
 /****************************************************************************
65
 /****************************************************************************
145
- * Truncate region
66
+ * Truncate region to memory window
146
  *
67
  *
147
  * Parameters:
68
  * Parameters:
148
- *  %edx:%eax	Region start
149
- *  %ecx:%ebx	Region length (*not* region end)
150
- *  %bp		truncate_to_start or truncate_to_end
69
+ *  %edx:%eax	Start of region
70
+ *  %ecx:%ebx	Length of region
71
+ *  %si		Memory window
151
  * Returns:
72
  * Returns:
152
- *  %edx:%eax	Modified region start
153
- *  %ecx:%ebx	Modified region length
154
- *  CF set	Region was truncated
155
- *  CF clear	Region was not truncated
73
+ *  %edx:%eax	Start of windowed region
74
+ *  %ecx:%ebx	Length of windowed region
156
  ****************************************************************************
75
  ****************************************************************************
157
  */
76
  */
158
 	.section ".text16"
77
 	.section ".text16"
159
-truncate:
160
-	pushw	%si
161
-	pushfw
162
-	/* Convert (start,len) to (start,end) */
78
+window_region:
79
+	/* Convert (start,len) to (start, end) */
163
 	addl	%eax, %ebx
80
 	addl	%eax, %ebx
164
 	adcl	%edx, %ecx
81
 	adcl	%edx, %ecx
165
-	/* Hide all hidden regions, truncating as directed */
166
-	movw	$hidden_regions, %si
167
-1:	call	*%bp
168
-	jnc	2f
169
-	popfw	/* If CF was set, set stored CF in flags word on stack */
170
-	stc
171
-	pushfw
172
-2:	addw	$8, %si
173
-	cmpl	$0, 0(%si)
174
-	jne	1b
175
-	/* Convert modified (start,end) back to (start,len) */
82
+	/* Truncate to window start */
83
+	cmpl	4(%si), %edx
84
+	jne	1f
85
+	cmpl	0(%si), %eax
86
+1:	jae	2f
87
+	movl	4(%si), %edx
88
+	movl	0(%si), %eax
89
+2:	/* Truncate to window end */
90
+	cmpl	12(%si), %ecx
91
+	jne	1f
92
+	cmpl	8(%si), %ebx
93
+1:	jbe	2f
94
+	movl	12(%si), %ecx
95
+	movl	8(%si), %ebx
96
+2:	/* Convert (start, end) back to (start, len) */
176
 	subl	%eax, %ebx
97
 	subl	%eax, %ebx
177
 	sbbl	%edx, %ecx
98
 	sbbl	%edx, %ecx
178
-	popfw
179
-	popw	%si
99
+	/* If length is <0, set length to 0 */
100
+	jae	1f
101
+	xorl	%ebx, %ebx
102
+	xorl	%ecx, %ecx
180
 	ret
103
 	ret
181
-	.size truncate, . - truncate
104
+	.size	window_region, . - window_region
182
 
105
 
183
 /****************************************************************************
106
 /****************************************************************************
184
  * Patch "memory above 1MB" figure
107
  * Patch "memory above 1MB" figure
187
  *  %ax		Memory above 1MB, in 1kB blocks
110
  *  %ax		Memory above 1MB, in 1kB blocks
188
  * Returns:
111
  * Returns:
189
  *  %ax		Modified memory above 1M in 1kB blocks
112
  *  %ax		Modified memory above 1M in 1kB blocks
190
- *  CF set	Region was truncated
191
- *  CF clear	Region was not truncated
192
  ****************************************************************************
113
  ****************************************************************************
193
  */
114
  */
194
 	.section ".text16"
115
 	.section ".text16"
195
 patch_1m:
116
 patch_1m:
196
 	pushal
117
 	pushal
197
 	/* Convert to (start,len) format and call truncate */
118
 	/* Convert to (start,len) format and call truncate */
198
-	movw	$truncate_to_start, %bp
199
 	xorl	%ecx, %ecx
119
 	xorl	%ecx, %ecx
200
 	movzwl	%ax, %ebx
120
 	movzwl	%ax, %ebx
201
 	shll	$10, %ebx
121
 	shll	$10, %ebx
202
 	xorl	%edx, %edx
122
 	xorl	%edx, %edx
203
 	movl	$0x100000, %eax
123
 	movl	$0x100000, %eax
204
-	call	truncate
124
+	movw	$ext_memory_window, %si
125
+	call	window_region
205
 	/* Convert back to "memory above 1MB" format and return via %ax */
126
 	/* Convert back to "memory above 1MB" format and return via %ax */
206
 	pushfw
127
 	pushfw
207
 	shrl	$10, %ebx
128
 	shrl	$10, %ebx
219
  *  %bx		Memory above 16MB, in 64kB blocks
140
  *  %bx		Memory above 16MB, in 64kB blocks
220
  * Returns:
141
  * Returns:
221
  *  %bx		Modified memory above 16M in 64kB blocks
142
  *  %bx		Modified memory above 16M in 64kB blocks
222
- *  CF set	Region was truncated
223
- *  CF clear	Region was not truncated
224
  ****************************************************************************
143
  ****************************************************************************
225
  */
144
  */
226
 	.section ".text16"
145
 	.section ".text16"
227
 patch_16m:
146
 patch_16m:
228
 	pushal
147
 	pushal
229
 	/* Convert to (start,len) format and call truncate */
148
 	/* Convert to (start,len) format and call truncate */
230
-	movw	$truncate_to_start, %bp
231
 	xorl	%ecx, %ecx
149
 	xorl	%ecx, %ecx
232
 	shll	$16, %ebx
150
 	shll	$16, %ebx
233
 	xorl	%edx, %edx
151
 	xorl	%edx, %edx
234
 	movl	$0x1000000, %eax
152
 	movl	$0x1000000, %eax
235
-	call	truncate
153
+	movw	$ext_memory_window, %si
154
+	call	window_region
236
 	/* Convert back to "memory above 16MB" format and return via %bx */
155
 	/* Convert back to "memory above 16MB" format and return via %bx */
237
 	pushfw
156
 	pushfw
238
 	shrl	$16, %ebx
157
 	shrl	$16, %ebx
252
  * Returns:
171
  * Returns:
253
  *  %ax		Modified memory between 1MB and 16MB, in 1kB blocks
172
  *  %ax		Modified memory between 1MB and 16MB, in 1kB blocks
254
  *  %bx		Modified memory above 16MB, in 64kB blocks
173
  *  %bx		Modified memory above 16MB, in 64kB blocks
255
- *  CF set	Region was truncated
256
- *  CF clear	Region was not truncated
257
  ****************************************************************************
174
  ****************************************************************************
258
  */
175
  */
259
 	.section ".text16"
176
 	.section ".text16"
260
 patch_1m_16m:
177
 patch_1m_16m:
261
 	call	patch_1m
178
 	call	patch_1m
262
-	jc	1f
263
 	call	patch_16m
179
 	call	patch_16m
264
-	ret
265
-1:	/* 1m region was truncated; kill the 16m region */
180
+	/* If 1M region is no longer full-length, kill off the 16M region */
181
+	cmpw	$( 15 * 1024 ), %ax
182
+	je	1f
266
 	xorw	%bx, %bx
183
 	xorw	%bx, %bx
267
-	ret
184
+1:	ret
268
 	.size patch_1m_16m, . - patch_1m_16m
185
 	.size patch_1m_16m, . - patch_1m_16m
269
 
186
 
270
 /****************************************************************************
187
 /****************************************************************************
337
 	je	2f /* 'SMAP' missing: error */
254
 	je	2f /* 'SMAP' missing: error */
338
 1:	/* An error occurred: return values returned by underlying e820 call */
255
 1:	/* An error occurred: return values returned by underlying e820 call */
339
 	stc	/* Force CF set if SMAP was missing */
256
 	stc	/* Force CF set if SMAP was missing */
340
-	leal	16(%esp), %esp /* avoid changing other flags */
257
+	addr32 leal 16(%esp), %esp /* avoid changing other flags */
341
 	ret
258
 	ret
342
 2:	/* No error occurred */
259
 2:	/* No error occurred */
343
 	movl	%ebx, underlying_e820_ebx
260
 	movl	%ebx, underlying_e820_ebx
400
  *
317
  *
401
  ****************************************************************************
318
  ****************************************************************************
402
  */
319
  */
403
-
404
-	.section ".tbl.data16.memory_windows.00"
405
-	.align 16
406
-memory_windows:
407
-
408
-	// Dummy memory window encompassing entire 64-bit address space
409
-	.long 0, 0, 0xffffffff, 0xffffffff
410
-
411
-	.section ".tbl.data16.memory_windows.99"
412
-	.align 16
413
-memory_windows_end:
414
-	
415
 	.section ".text16"
320
 	.section ".text16"
416
 get_windowed_e820:
321
 get_windowed_e820:
417
 
322
 
421
 
326
 
422
 	/* Split %ebx into %si:%bx, store original %bx in %bp */
327
 	/* Split %ebx into %si:%bx, store original %bx in %bp */
423
 	pushl	%ebx
328
 	pushl	%ebx
424
-	xorl	%esi, %esi
425
 	popw	%bp
329
 	popw	%bp
426
 	popw	%si
330
 	popw	%si
427
 
331
 
441
 	movl	%es:4(%di), %edx
345
 	movl	%es:4(%di), %edx
442
 	movl	%es:8(%di), %ebx
346
 	movl	%es:8(%di), %ebx
443
 	movl	%es:12(%di), %ecx
347
 	movl	%es:12(%di), %ecx
444
-	/* Convert (start,len) to (start, end) */
445
-	addl	%eax, %ebx
446
-	adcl	%edx, %ecx
447
-	/* Truncate to window start */
448
-	cmpl	4(%esi), %edx
449
-	jne	1f
450
-	cmpl	0(%esi), %eax
451
-1:	jae	2f
452
-	movl	4(%esi), %edx
453
-	movl	0(%esi), %eax
454
-2:	/* Truncate to window end */
455
-	cmpl	12(%esi), %ecx
456
-	jne	1f
457
-	cmpl	8(%esi), %ebx
458
-1:	jbe	2f
459
-	movl	12(%esi), %ecx
460
-	movl	8(%esi), %ebx
461
-2:	/* Convert (start, end) back to (start, len) */
462
-	subl	%eax, %ebx
463
-	sbbl	%edx, %ecx
464
-	/* If length is <0, set length to 0 */
465
-	jae	1f
466
-	xorl	%ebx, %ebx
467
-	xorl	%ecx, %ecx
348
+	/* Truncate region to current window */
349
+	call	window_region
468
 1:	/* Store modified values in e820 map entry */
350
 1:	/* Store modified values in e820 map entry */
469
 	movl	%eax, %es:0(%di)
351
 	movl	%eax, %es:0(%di)
470
 	movl	%edx, %es:4(%di)
352
 	movl	%edx, %es:4(%di)
537
 98:	/* Clear CF */
419
 98:	/* Clear CF */
538
 	clc
420
 	clc
539
 99:	/* Return values from underlying call */
421
 99:	/* Return values from underlying call */
540
-	leal	12(%esp), %esp /* avoid changing flags */
422
+	addr32 leal 12(%esp), %esp /* avoid changing flags */
541
 	ret
423
 	ret
542
 	.size get_nonempty_e820, . - get_nonempty_e820
424
 	.size get_nonempty_e820, . - get_nonempty_e820
543
 
425
 
572
 	popw	%es
454
 	popw	%es
573
 	movw	%sp, %di
455
 	movw	%sp, %di
574
 	call	get_nonempty_e820
456
 	call	get_nonempty_e820
575
-	leal	20(%esp), %esp /* avoid changing flags */
457
+	addr32 leal 20(%esp), %esp /* avoid changing flags */
576
 	popal
458
 	popal
577
 	jnc	99f /* There are further nonempty regions */
459
 	jnc	99f /* There are further nonempty regions */
578
 
460
 
584
 	.size get_mangled_e820, . - get_mangled_e820
466
 	.size get_mangled_e820, . - get_mangled_e820
585
 
467
 
586
 /****************************************************************************
468
 /****************************************************************************
587
- * Patch E820 memory map entry
588
- *
589
- * Parameters:
590
- *  %es:di	Pointer to E820 memory map descriptor
591
- *  %bp		truncate_to_start or truncate_to_end
592
- * Returns:
593
- *  %es:di	Pointer to now-modified E820 memory map descriptor
594
- *  CF set	Region was truncated
595
- *  CF clear	Region was not truncated
596
- ****************************************************************************
597
- */
598
-	.section ".text16"
599
-patch_e820:
600
-	pushal
601
-	movl	%es:0(%di), %eax
602
-	movl	%es:4(%di), %edx
603
-	movl	%es:8(%di), %ebx
604
-	movl	%es:12(%di), %ecx
605
-	call	truncate
606
-	movl	%eax, %es:0(%di)
607
-	movl	%edx, %es:4(%di)
608
-	movl	%ebx, %es:8(%di)
609
-	movl	%ecx, %es:12(%di)
610
-	popal
611
-	ret
612
-	.size patch_e820, . - patch_e820
613
-
614
-/****************************************************************************
615
- * Split E820 memory map entry if necessary
616
- *
617
- * Parameters: 
618
- *   As for INT 15,e820
619
- * Returns:
620
- *   As for INT 15,e820
621
- *
622
- * Calls the underlying INT 15,e820 and returns a modified memory map.
623
- * Regions will be split around any hidden regions.
469
+ * INT 15,e820 handler
624
  ****************************************************************************
470
  ****************************************************************************
625
  */
471
  */
626
 	.section ".text16"
472
 	.section ".text16"
627
-split_e820:
628
-	pushw	%si
629
-	pushw	%bp
630
-	/* Caller's %bx => %si, real %ebx to %ebx, call previous handler */
631
-	pushfw
632
-	movw	%bx, %si
633
-	testl	%ebx, %ebx
634
-	jnz	1f
635
-	movl	%ebx, %cs:real_ebx
636
-1:	movl	%cs:real_ebx, %ebx
637
-
638
-//	lcall	*%cs:int15_vector
639
-	/* Hacked in call to get_mangled_e820 in place of underlying INT15 */
640
-	popfw
473
+int15_e820:
641
 	pushw	%ds
474
 	pushw	%ds
642
 	pushw	%cs:rm_ds
475
 	pushw	%cs:rm_ds
643
 	popw	%ds
476
 	popw	%ds
644
 	call	get_mangled_e820
477
 	call	get_mangled_e820
645
 	popw	%ds
478
 	popw	%ds
646
-
647
-	pushfw
648
-	/* Edit result */
649
-	pushw	%ds
650
-	pushw	%cs:rm_ds
651
-	popw	%ds
652
-	movw	$truncate_to_start, %bp
653
-	incw	%si
654
-	jns	2f
655
-	movw	$truncate_to_end, %bp
656
-2:	call	patch_e820
657
-	jnc	3f
658
-	xorw	$0x8000, %si
659
-3:	testw	%si, %si
660
-	js	4f
661
-	movl	%ebx, %cs:real_ebx
662
-	testl	%ebx, %ebx
663
-	jz	5f
664
-4:	movw	%si, %bx
665
-5:	popw	%ds
666
-	/* Restore flags returned by previous handler and return */
667
-	popfw
668
-	popw	%bp
669
-	popw	%si
670
-	ret
671
-	.size split_e820, . - split_e820
672
-
673
-	.section ".text16.data"
674
-real_ebx:
675
-	.long 0
676
-	.size real_ebx, . - real_ebx
677
-
678
-/****************************************************************************
679
- * INT 15,e820 handler
680
- ****************************************************************************
681
- */
682
-	.section ".text16"
683
-int15_e820:
684
-	pushl	%eax
685
-	pushl	%ecx
686
-	pushl	%edx	
687
-	call	split_e820
688
-	pushfw
689
-	/* If we've hit an error, exit immediately */
690
-	jc	99f
691
-	/* If region is non-empty, return this region */
692
-	pushl	%eax
693
-	movl	%es:8(%di), %eax
694
-	orl	%es:12(%di), %eax
695
-	popl	%eax
696
-	jnz	99f
697
-	/* Region is empty.  If this is not the end of the map,
698
-	 * skip over this region.
699
-	 */
700
-	testl	%ebx, %ebx
701
-	jz	1f
702
-	popfw
703
-	popl	%edx
704
-	popl	%ecx
705
-	popl	%eax
706
-	jmp	int15_e820
707
-1:	/* Region is empty and this is the end of the map.  Return
708
-	 * with CF set to avoid placing an empty region at the end of
709
-	 * the map.
710
-	 */
711
-	popfw
712
-	stc
713
-	pushfw
714
-99:	/* Restore flags from original INT 15,e820 call and return */
715
-	popfw
716
-	addr32 leal	12(%esp), %esp /* avoid changing flags */
717
 	lret	$2
479
 	lret	$2
718
 	.size int15_e820, . - int15_e820
480
 	.size int15_e820, . - int15_e820
719
 	
481
 	

+ 46
- 36
src/arch/i386/firmware/pcbios/hidemem.c View File

15
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
  */
16
  */
17
 
17
 
18
+#include <assert.h>
18
 #include <realmode.h>
19
 #include <realmode.h>
19
 #include <biosint.h>
20
 #include <biosint.h>
20
 #include <basemem.h>
21
 #include <basemem.h>
25
 #define ALIGN_HIDDEN 4096   /* 4kB page alignment should be enough */
26
 #define ALIGN_HIDDEN 4096   /* 4kB page alignment should be enough */
26
 
27
 
27
 /**
28
 /**
28
- * A hidden region of Etherboot
29
+ * A hidden region of gPXE
29
  *
30
  *
30
  * This represents a region that will be edited out of the system's
31
  * This represents a region that will be edited out of the system's
31
  * memory map.
32
  * memory map.
34
  * changed.
35
  * changed.
35
  */
36
  */
36
 struct hidden_region {
37
 struct hidden_region {
37
-	/* Physical start address */
38
-	physaddr_t start;
39
-	/* Physical end address */
40
-	physaddr_t end;
38
+	/** Physical start address */
39
+	uint64_t start;
40
+	/** Physical end address */
41
+	uint64_t end;
41
 };
42
 };
42
 
43
 
43
-/**
44
- * List of hidden regions
45
- *
46
- * Must be terminated by a zero entry.
47
- */
48
-struct hidden_region __data16_array ( hidden_regions, [] ) = {
49
-	[TEXT] = { 0, 0 },
50
-	[BASEMEM] = { ( 640 * 1024 ), ( 640 * 1024 ) },
51
-	[EXTMEM] = { 0, 0 },
52
-	{ 0, 0, } /* Terminator */
53
-};
54
-#define hidden_regions __use_data16 ( hidden_regions )
44
+/** Hidden base memory */
45
+extern struct hidden_region __data16 ( hidemem_base );
46
+#define hidemem_base __use_data16 ( hidemem_base )
47
+
48
+/** Hidden umalloc memory */
49
+extern struct hidden_region __data16 ( hidemem_umalloc );
50
+#define hidemem_umalloc __use_data16 ( hidemem_umalloc )
51
+
52
+/** Hidden text memory */
53
+extern struct hidden_region __data16 ( hidemem_text );
54
+#define hidemem_text __use_data16 ( hidemem_text )
55
 
55
 
56
 /** Assembly routine in e820mangler.S */
56
 /** Assembly routine in e820mangler.S */
57
 extern void int15();
57
 extern void int15();
60
 extern struct segoff __text16 ( int15_vector );
60
 extern struct segoff __text16 ( int15_vector );
61
 #define int15_vector __use_text16 ( int15_vector )
61
 #define int15_vector __use_text16 ( int15_vector )
62
 
62
 
63
+/* The linker defines these symbols for us */
64
+extern char _text[];
65
+extern char _end[];
66
+
63
 /**
67
 /**
64
  * Hide region of memory from system memory map
68
  * Hide region of memory from system memory map
65
  *
69
  *
70
+ * @v region		Hidden memory region
66
  * @v start		Start of region
71
  * @v start		Start of region
67
  * @v end		End of region
72
  * @v end		End of region
68
  */
73
  */
69
-void hide_region ( unsigned int region_id, physaddr_t start, physaddr_t end ) {
70
-	struct hidden_region *region = &hidden_regions[region_id];
74
+static void hide_region ( struct hidden_region *region,
75
+			  physaddr_t start, physaddr_t end ) {
71
 
76
 
72
 	/* Some operating systems get a nasty shock if a region of the
77
 	/* Some operating systems get a nasty shock if a region of the
73
 	 * E820 map seems to start on a non-page boundary.  Make life
78
 	 * E820 map seems to start on a non-page boundary.  Make life
76
 	region->start = ( start & ~( ALIGN_HIDDEN - 1 ) );
81
 	region->start = ( start & ~( ALIGN_HIDDEN - 1 ) );
77
 	region->end = ( ( end + ALIGN_HIDDEN - 1 ) & ~( ALIGN_HIDDEN - 1 ) );
82
 	region->end = ( ( end + ALIGN_HIDDEN - 1 ) & ~( ALIGN_HIDDEN - 1 ) );
78
 
83
 
79
-	DBG ( "Hiding region %d [%lx,%lx)\n",
80
-	      region_id, region->start, region->end );
81
-}
82
-
83
-/**
84
- * Hide Etherboot text
85
- *
86
- */
87
-static void hide_text ( void ) {
88
-
89
-	/* The linker defines these symbols for us */
90
-	extern char _text[];
91
-	extern char _end[];
92
-
93
-	hide_region ( TEXT, virt_to_phys ( _text ), virt_to_phys ( _end ) );
84
+	DBG ( "Hiding region [%llx,%llx)\n", region->start, region->end );
94
 }
85
 }
95
 
86
 
96
 /**
87
 /**
102
 	 * hide_region(), because we don't want this rounded to the
93
 	 * hide_region(), because we don't want this rounded to the
103
 	 * nearest page boundary.
94
 	 * nearest page boundary.
104
 	 */
95
 	 */
105
-	hidden_regions[BASEMEM].start = ( get_fbms() * 1024 );
96
+	hidemem_base.start = ( get_fbms() * 1024 );
97
+}
98
+
99
+/**
100
+ * Hide umalloc() region
101
+ *
102
+ */
103
+void hide_umalloc ( physaddr_t start, physaddr_t end ) {
104
+	assert ( end <= virt_to_phys ( _text ) );
105
+	hide_region ( &hidemem_umalloc, start, end );
106
+}
107
+
108
+/**
109
+ * Hide .text and .data
110
+ *
111
+ */
112
+void hide_text ( void ) {
113
+	hide_region ( &hidemem_text, virt_to_phys ( _text ),
114
+		      virt_to_phys ( _end ) );
106
 }
115
 }
107
 
116
 
108
 /**
117
 /**
114
 static void hide_etherboot ( void ) {
123
 static void hide_etherboot ( void ) {
115
 
124
 
116
 	/* Initialise the hidden regions */
125
 	/* Initialise the hidden regions */
117
-	hide_text();
118
 	hide_basemem();
126
 	hide_basemem();
127
+	hide_umalloc ( virt_to_phys ( _text ), virt_to_phys ( _text ) );
128
+	hide_text();
119
 
129
 
120
 	/* Hook INT 15 */
130
 	/* Hook INT 15 */
121
 	hook_bios_interrupt ( 0x15, ( unsigned int ) int15,
131
 	hook_bios_interrupt ( 0x15, ( unsigned int ) int15,

+ 0
- 1
src/arch/i386/scripts/i386.lds View File

82
 	__data16 = .;
82
 	__data16 = .;
83
 	*(.data16)
83
 	*(.data16)
84
 	*(.data16.*)
84
 	*(.data16.*)
85
-	*(SORT(.tbl.data16.*))	/* Various tables.  See include/tables.h */
86
 	_edata16_progbits = .;
85
 	_edata16_progbits = .;
87
     }
86
     }
88
     .bss16 : AT ( _data16_load_offset + __bss16 ) {
87
     .bss16 : AT ( _data16_load_offset + __bss16 ) {

+ 2
- 10
src/include/gpxe/hidemem.h View File

8
  *
8
  *
9
  */
9
  */
10
 
10
 
11
-/**
12
- * Unique IDs for hidden regions
13
- */
14
-enum hidemem_region_id {
15
-	TEXT = 0,
16
-	BASEMEM,
17
-	EXTMEM,
18
-};
11
+#include <stdint.h>
19
 
12
 
20
-extern void hide_region ( unsigned int region_id, physaddr_t start,
21
-			  physaddr_t end );
13
+extern void hide_umalloc ( physaddr_t start, physaddr_t end );
22
 
14
 
23
 #endif /* _GPXE_HIDEMEM_H */
15
 #endif /* _GPXE_HIDEMEM_H */

Loading…
Cancel
Save