Skip to content

Commit 6cfc6c7

Browse files
committed
Make support for u-boot
1 parent 51fb773 commit 6cfc6c7

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

riscv-rt/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ panic-halt = "0.2.0"
2323
s-mode = ["riscv-rt-macros/s-mode"]
2424
single-hart = []
2525
v-trap = ["riscv-rt-macros/v-trap"]
26+
u-boot = ["riscv-rt-macros/u-boot"]

riscv-rt/macros/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ syn = { version = "2.0", features = ["extra-traits", "full"] }
2323
[features]
2424
s-mode = []
2525
v-trap = []
26+
u-boot = []

riscv-rt/macros/src/lib.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
5353
let f = parse_macro_input!(input as ItemFn);
5454

5555
// check the function arguments
56+
#[cfg(not(feature = "u-boot"))]
5657
if f.sig.inputs.len() > 3 {
5758
return parse::Error::new(
5859
f.sig.inputs.last().unwrap().span(),
@@ -61,6 +62,17 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
6162
.to_compile_error()
6263
.into();
6364
}
65+
#[cfg(feature = "u-boot")]
66+
if f.sig.inputs.len() != 2 {
67+
return parse::Error::new(
68+
f.sig.inputs.last().unwrap().span(),
69+
"`#[entry]` function must have exactly two arguments",
70+
)
71+
.to_compile_error()
72+
.into();
73+
}
74+
75+
#[cfg(not(feature = "u-boot"))]
6476
for arg in &f.sig.inputs {
6577
match arg {
6678
FnArg::Receiver(_) => {
@@ -77,6 +89,40 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
7789
}
7890
}
7991
}
92+
#[cfg(feature = "u-boot")]
93+
{
94+
// We have checked that there are two arguments above.
95+
let (a1, a2) = (&f.sig.inputs[0], &f.sig.inputs[1]);
96+
97+
match a1 {
98+
FnArg::Receiver(_) => {
99+
return parse::Error::new(a1.span(), "invalid argument")
100+
.to_compile_error()
101+
.into();
102+
}
103+
FnArg::Typed(t) => {
104+
if !is_simple_type(&t.ty, "c_int") {
105+
return parse::Error::new(t.ty.span(), "argument type must be c_int")
106+
.to_compile_error()
107+
.into();
108+
}
109+
}
110+
}
111+
match a2 {
112+
FnArg::Receiver(_) => {
113+
return parse::Error::new(a2.span(), "invalid argument")
114+
.to_compile_error()
115+
.into();
116+
}
117+
FnArg::Typed(t) => {
118+
if !is_simple_type(&t.ty, "usize") {
119+
return parse::Error::new(t.ty.span(), "argument type must be usize")
120+
.to_compile_error()
121+
.into();
122+
}
123+
}
124+
}
125+
}
80126

81127
// check the function signature
82128
let valid_signature = f.sig.constness.is_none()

riscv-rt/src/asm.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ cfg_global_asm!(
125125
);
126126

127127
// STORE A0..A2 IN THE STACK, AS THEY WILL BE NEEDED LATER BY main
128+
#[cfg(not(feature = "u-boot"))]
128129
cfg_global_asm!(
129130
#[cfg(riscv32)]
130131
"addi sp, sp, -4 * 3
@@ -213,12 +214,12 @@ riscv_rt_macros::loop_global_asm!(" fmv.w.x f{}, x0", 32);
213214
// SET UP INTERRUPTS, RESTORE a0..a2, AND JUMP TO MAIN RUST FUNCTION
214215
cfg_global_asm!(
215216
"call _setup_interrupts",
216-
#[cfg(riscv32)]
217+
#[cfg(all(riscv32, not(feature = "u-boot")))]
217218
"lw a0, 4 * 0(sp)
218219
lw a1, 4 * 1(sp)
219220
lw a2, 4 * 2(sp)
220221
addi sp, sp, 4 * 3",
221-
#[cfg(riscv64)]
222+
#[cfg(all(riscv64, not(feature = "u-boot")))]
222223
"ld a0, 8 * 0(sp)
223224
ld a1, 8 * 1(sp)
224225
ld a2, 8 * 2(sp)

0 commit comments

Comments
 (0)