11#![ no_std]
22#![ no_main]
3- #![ feature( naked_functions) ]
43
54use core:: {
65 arch:: naked_asm,
@@ -16,60 +15,56 @@ const FLAG_LE: usize = 0b0;
1615const FLAG_PAGE_SIZE_4K : usize = 0b10 ;
1716const 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.
2322unsafe 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.
5249unsafe 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
7570fn 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