Skip to content

Commit ba9d943

Browse files
committed
Allow specifying addresses as TOML integers too
1 parent 4431c3b commit ba9d943

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

build.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fn main() {
99
#[cfg(feature = "binary")]
1010
mod binary {
1111
use quote::quote;
12+
use std::convert::TryInto;
1213

1314
pub fn main() {
1415
use llvm_tools_build as llvm_tools;
@@ -394,10 +395,23 @@ mod binary {
394395
if num % 0x1000 == 0 {
395396
Ok(AlignedAddress(num))
396397
} else {
397-
Err(serde::de::Error::custom(format!("address {:#x} is not page aligned", num)))
398+
Err(serde::de::Error::custom(format!(
399+
"address {:#x} is not page aligned",
400+
num
401+
)))
398402
}
399403
}
400404

405+
fn visit_i64<E>(self, num: i64) -> Result<Self::Value, E>
406+
where
407+
E: serde::de::Error,
408+
{
409+
let unsigned: u64 = num
410+
.try_into()
411+
.map_err(|_| serde::de::Error::custom(format!("address {} is negative", num)))?;
412+
self.visit_u64(unsigned)
413+
}
414+
401415
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
402416
where
403417
E: serde::de::Error,
@@ -411,7 +425,10 @@ mod binary {
411425
u64::from_str_radix(&value, 10)
412426
}
413427
.map_err(|_err| {
414-
serde::de::Error::custom(format!("string \"{}\" is not a valid memory address", value))
428+
serde::de::Error::custom(format!(
429+
"string \"{}\" is not a valid memory address",
430+
value
431+
))
415432
})?;
416433

417434
self.visit_u64(num)

tests/test_kernels/map_phys_mem/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ uart_16550 = "0.2.10"
1111

1212
[package.metadata.bootloader]
1313
map-physical-memory = true
14-
physical-memory-offset = "0x0000_4000_0000_0000"
14+
physical-memory-offset = 0x0000_4000_0000_0000

0 commit comments

Comments
 (0)