File tree 2 files changed +23
-3
lines changed
2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 1
1
use std:: {
2
2
env,
3
+ fs:: File ,
4
+ io:: Write ,
3
5
path:: { Path , PathBuf } ,
4
6
process:: { self , Command } ,
5
7
} ;
@@ -123,6 +125,24 @@ fn main() {
123
125
process:: exit ( 1 ) ;
124
126
}
125
127
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
+
126
146
// pass link arguments to rustc
127
147
println ! ( "cargo:rustc-link-search=native={}" , out_dir. display( ) ) ;
128
148
println ! (
Original file line number Diff line number Diff line change @@ -22,9 +22,9 @@ use x86_64::structures::paging::{
22
22
use x86_64:: ux:: u9;
23
23
use x86_64:: { PhysAddr , VirtAddr } ;
24
24
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" ) ) ;
28
28
29
29
global_asm ! ( include_str!( "stage_1.s" ) ) ;
30
30
global_asm ! ( include_str!( "stage_2.s" ) ) ;
You can’t perform that action at this time.
0 commit comments