File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 11use std:: {
22 env,
3+ fs:: File ,
4+ io:: Write ,
35 path:: { Path , PathBuf } ,
46 process:: { self , Command } ,
57} ;
@@ -123,6 +125,24 @@ fn main() {
123125 process:: exit ( 1 ) ;
124126 }
125127
128+ // create a file with the `PHYSICAL_MEMORY_OFFSET` constant
129+ let file_path = out_dir. join ( "physical_memory_offset.rs" ) ;
130+ let mut file = File :: create ( file_path) . expect ( "failed to create physical_memory_offset.rs" ) ;
131+ let physical_memory_offset = match option_env ! ( "BOOTLOADER_PHYSICAL_MEMORY_OFFSET" ) {
132+ None => 0o_177777_770_000_000_000_0000u64 ,
133+ Some ( s) => s. parse ( ) . expect (
134+ "The `BOOTLOADER_PHYSICAL_MEMORY_OFFSET` environment variable must be an integer." ,
135+ ) ,
136+ } ;
137+ file. write_all (
138+ format ! (
139+ "const PHYSICAL_MEMORY_OFFSET: u64 = {:#x};" ,
140+ physical_memory_offset
141+ )
142+ . as_bytes ( ) ,
143+ )
144+ . expect ( "write to physical_memory_offset.rs failed" ) ;
145+
126146 // pass link arguments to rustc
127147 println ! ( "cargo:rustc-link-search=native={}" , out_dir. display( ) ) ;
128148 println ! (
Original file line number Diff line number Diff line change @@ -22,9 +22,9 @@ use x86_64::structures::paging::{
2222use x86_64:: ux:: u9;
2323use x86_64:: { PhysAddr , VirtAddr } ;
2424
25- /// The offset into the virtual address space where the physical memory is mapped if
26- /// the `map_physical_memory` is activated.
27- const PHYSICAL_MEMORY_OFFSET : u64 = 0o_177777_770_000_000_000_0000 ;
25+ // The offset into the virtual address space where the physical memory is mapped if
26+ // the `map_physical_memory` is activated. Set by the build script .
27+ include ! ( concat! ( env! ( "OUT_DIR" ) , "/physical_memory_offset.rs" ) ) ;
2828
2929global_asm ! ( include_str!( "stage_1.s" ) ) ;
3030global_asm ! ( include_str!( "stage_2.s" ) ) ;
You can’t perform that action at this time.
0 commit comments