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 77 text PT_LOAD ;
88}
99
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+
1020SECTIONS
1121{
12- . = 1M ;
13- _start_of_file = . ;
14-
1522 /* Mapping in the program headers makes it easier to mmap the whole file. */
16- . += SIZEOF_HEADERS ;
23+ . = ram_min;
24+ . += SIZEOF_HEADERS ;
1725
1826 .rodata : { *(.rodata .rodata .*) } :rodata
1927 .data : { *(.data .data .*) *(.bss .bss .*) } :data
2028 .text : { *(.text .text .*) } :text
2129
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" )
2339
2440 /* Match edk2's GccBase.lds DISCARD section */
2541 /DISCARD/ : {
Original file line number Diff line number Diff line change @@ -65,14 +65,22 @@ fn enable_sse2() {
6565/// Setup page tables to provide an identity mapping over the full 4GiB range
6666fn setup_pagetables ( ) {
6767 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 } ) ;
6976 for i in 0 ..( 512 * ADDRESS_SPACE_GIB ) {
7077 pte. io_write_u64 ( i * 8 , ( i << 21 ) + 0x83u64 )
7178 }
7279
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 } ) ;
7482 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 ) ;
7684 }
7785
7886 log ! ( "Page tables setup" ) ;
You can’t perform that action at this time.
0 commit comments