Skip to content

Commit 672b6eb

Browse files
committed
fmt code
1 parent edb6702 commit 672b6eb

File tree

3 files changed

+48
-51
lines changed

3 files changed

+48
-51
lines changed

.vscode/settings.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"rust-analyzer.cargo.target":
3-
// "aarch64-unknown-none",
4-
"x86_64-unknown-none",
2+
"rust-analyzer.cargo.target": "aarch64-unknown-none",
3+
// "x86_64-unknown-none",
54
"rust-analyzer.cargo.allTargets": false,
65
}

hello/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{fs, path::PathBuf};
22

33
fn main() {
44
println!("cargo::rustc-link-arg-tests=-Tlink.ld");
5-
// println!("cargo::rustc-link-arg-tests=-no-pie");
5+
println!("cargo::rustc-link-arg-tests=-no-pie");
66
println!("cargo::rustc-link-arg-tests=-znostart-stop-gc");
77

88
fs::copy("link.ld", out_dir().join("link.ld")).unwrap();

hello/src/lib.rs

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![no_std]
22
#![no_main]
3-
#![feature(naked_functions)]
43

54
use core::{
65
arch::naked_asm,
@@ -16,60 +15,56 @@ const FLAG_LE: usize = 0b0;
1615
const FLAG_PAGE_SIZE_4K: usize = 0b10;
1716
const FLAG_ANY_MEM: usize = 0b1000;
1817

19-
#[naked]
18+
#[unsafe(naked)]
2019
#[unsafe(no_mangle)]
2120
#[unsafe(link_section = ".text.head")]
2221
/// The entry point of the kernel.
2322
unsafe extern "C" fn _start() -> ! {
24-
unsafe {
25-
naked_asm!(
26-
// code0/code1
27-
"nop",
28-
"bl {entry}",
29-
// text_offset
30-
".quad 0",
31-
// image_size
32-
".quad _kernel_size",
33-
// flags
34-
".quad {flags}",
35-
// Reserved fields
36-
".quad 0",
37-
".quad 0",
38-
".quad 0",
39-
// magic - yes 0x644d5241 is the same as ASCII string "ARM\x64"
40-
".ascii \"ARM\\x64\"",
41-
// Another reserved field at the end of the header
42-
".byte 0, 0, 0, 0",
43-
flags = const FLAG_LE | FLAG_PAGE_SIZE_4K | FLAG_ANY_MEM,
44-
entry = sym primary_entry,
45-
)
46-
}
23+
naked_asm!(
24+
// code0/code1
25+
"nop",
26+
"bl {entry}",
27+
// text_offset
28+
".quad 0",
29+
// image_size
30+
".quad _kernel_size",
31+
// flags
32+
".quad {flags}",
33+
// Reserved fields
34+
".quad 0",
35+
".quad 0",
36+
".quad 0",
37+
// magic - yes 0x644d5241 is the same as ASCII string "ARM\x64"
38+
".ascii \"ARM\\x64\"",
39+
// Another reserved field at the end of the header
40+
".byte 0, 0, 0, 0",
41+
flags = const FLAG_LE | FLAG_PAGE_SIZE_4K | FLAG_ANY_MEM,
42+
entry = sym primary_entry,
43+
)
4744
}
4845

49-
#[naked]
46+
#[unsafe(naked)]
5047
#[unsafe(link_section = ".text.boot")]
5148
/// The entry point of the kernel.
5249
unsafe extern "C" fn primary_entry() -> ! {
53-
unsafe {
54-
naked_asm!(
55-
"ADR x11, .",
56-
"LDR x10, ={this_func}",
57-
"SUB x18, x10, x11", // x18 = va_offset
58-
"MOV x19, x0", // x19 = dtb_addr
59-
60-
// setup stack
61-
"LDR x1, =_stack_top",
62-
"SUB x1, x1, x18", // X1 == STACK_TOP
63-
"MOV sp, x1",
64-
65-
66-
"MOV x0, x18",
67-
"MOV x1, x19",
68-
"BL {entry}",
69-
this_func = sym primary_entry,
70-
entry = sym rust_entry,
71-
)
72-
}
50+
naked_asm!(
51+
"ADR x11, .",
52+
"LDR x10, ={this_func}",
53+
"SUB x18, x10, x11", // x18 = va_offset
54+
"MOV x19, x0", // x19 = dtb_addr
55+
56+
// setup stack
57+
"LDR x1, =_stack_top",
58+
"SUB x1, x1, x18", // X1 == STACK_TOP
59+
"MOV sp, x1",
60+
61+
62+
"MOV x0, x18",
63+
"MOV x1, x19",
64+
"BL {entry}",
65+
this_func = sym primary_entry,
66+
entry = sym rust_entry,
67+
)
7368
}
7469

7570
fn phys_to_virt(addr: usize) -> *mut u8 {
@@ -90,7 +85,10 @@ fn rust_entry(_text_va: usize, fdt: *mut u8) -> ! {
9085
let mut u = Uart::new_by_fdt_node(&node, phys_to_virt).unwrap();
9186
let _ = tx.write_str_blocking("found\n");
9287

93-
u.tx.take().unwrap().write_str_blocking("Hello, world!\n");
88+
u.tx.take()
89+
.unwrap()
90+
.write_str_blocking("Hello, world!\n")
91+
.unwrap();
9492

9593
let _ = tx.write_str_blocking("All tests passed!\n");
9694
}

0 commit comments

Comments
 (0)