File tree Expand file tree Collapse file tree 2 files changed +32
-8
lines changed Expand file tree Collapse file tree 2 files changed +32
-8
lines changed Original file line number Diff line number Diff line change 7
7
text PT_LOAD ;
8
8
}
9
9
10
+ /* Loaders like to put stuff in low memory (< 1M), so we don't use it. */
11
+ ram_min = 1M;
12
+ ram_max = 2M;
13
+ /* Our stack grows down from ram_max. TODO : Add a guard for stack overflows. */
14
+ stack_size = 64K;
15
+
16
+ /* Pagetable locations loaded by Firecracker/cloud-hypervisor */
17
+ pml4t = 0x9000;
18
+ pml3t = 0xa000;
19
+
10
20
SECTIONS
11
21
{
12
- . = 1M ;
13
- _start_of_file = . ;
14
-
15
22
/* Mapping in the program headers makes it easier to mmap the whole file. */
16
- . += SIZEOF_HEADERS ;
23
+ . = ram_min;
24
+ . += SIZEOF_HEADERS ;
17
25
18
26
.rodata : { *(.rodata .rodata.*) } :rodata
19
27
.data : { *(.data .data.*) *(.bss .bss.*) } :data
20
28
.text : { *(.text .text.*) } :text
21
29
22
- _end_of_file = . ;
30
+ firmware_ram_size = . - ram_min;
31
+
32
+ /* Memory for 64 GiB identity mapping, keep synced with ADDRESS_SPACE_GIB */
33
+ identity_mapped_gbs = 64;
34
+ . = ALIGN (4K);
35
+ pml2t = .;
36
+ . += 4K * identity_mapped_gbs;
37
+
38
+ ASSERT ((. <= ram_max - stack_size), "firmware size too big for RAM region")
23
39
24
40
/* Match edk2's GccBase.lds DISCARD section */
25
41
/DISCARD/ : {
Original file line number Diff line number Diff line change @@ -65,14 +65,22 @@ fn enable_sse2() {
65
65
/// Setup page tables to provide an identity mapping over the full 4GiB range
66
66
fn setup_pagetables ( ) {
67
67
const ADDRESS_SPACE_GIB : u64 = 64 ;
68
- let pte = mem:: MemoryRegion :: new ( 0xb000 , 512 * ADDRESS_SPACE_GIB * 8 ) ;
68
+ type Page = [ u64 ; 512 ] ;
69
+
70
+ extern "C" {
71
+ static pml3t: Page ;
72
+ static pml2t: [ Page ; ADDRESS_SPACE_GIB as usize ] ;
73
+ }
74
+
75
+ let pte = mem:: MemoryRegion :: from_slice ( unsafe { & pml2t } ) ;
69
76
for i in 0 ..( 512 * ADDRESS_SPACE_GIB ) {
70
77
pte. io_write_u64 ( i * 8 , ( i << 21 ) + 0x83u64 )
71
78
}
72
79
73
- let pde = mem:: MemoryRegion :: new ( 0xa000 , 4096 ) ;
80
+ let pml2t_addr = unsafe { pml2t. as_ptr ( ) } as usize as u64 ;
81
+ let pde = mem:: MemoryRegion :: from_slice ( unsafe { & pml3t } ) ;
74
82
for i in 0 ..ADDRESS_SPACE_GIB {
75
- pde. io_write_u64 ( i * 8 , ( 0xb000u64 + ( 0x1000u64 * i) ) | 0x03 ) ;
83
+ pde. io_write_u64 ( i * 8 , ( pml2t_addr + ( 0x1000u64 * i) ) | 0x03 ) ;
76
84
}
77
85
78
86
log ! ( "Page tables setup" ) ;
You can’t perform that action at this time.
0 commit comments