@@ -28,81 +28,8 @@ pub unsafe extern "C" fn _start() -> ! {
28
28
unsafe { reset ( ) } ;
29
29
}
30
30
31
- #[ unsafe( no_mangle) ]
32
- #[ unsafe( link_section = ".text.chainboot" ) ]
33
- pub unsafe extern "C" fn reset ( ) -> ! {
34
- use core:: {
35
- cell:: UnsafeCell ,
36
- sync:: { atomic, atomic:: Ordering } ,
37
- } ;
38
-
39
- // These are a problem, because they are not interpreted as constants here.
40
- // Subsequently, this code tries to read values from not-yet-existing data locations.
41
- unsafe extern "Rust" {
42
- // Boundaries of the .bss section, provided by the linker script
43
- static __BSS_START: UnsafeCell < ( ) > ;
44
- static __BSS_SIZE_U64S: UnsafeCell < ( ) > ;
45
- // Load address of the kernel binary
46
- static __binary_nonzero_lma: UnsafeCell < ( ) > ;
47
- // Address to relocate to and image size
48
- static __binary_nonzero_vma: UnsafeCell < ( ) > ;
49
- static __binary_nonzero_vma_end_exclusive: UnsafeCell < ( ) > ;
50
- // Stack top
51
- static __boot_core_stack_end_exclusive: UnsafeCell < ( ) > ;
52
- }
53
-
54
- // This tries to call memcpy() at a wrong linked address - the function is in relocated area!
55
-
56
- // Relocate the code.
57
- // Emulate
58
- // core::ptr::copy_nonoverlapping(
59
- // __binary_nonzero_lma.get() as *const u64,
60
- // __binary_nonzero_vma.get() as *mut u64,
61
- // __binary_nonzero_vma_end_exclusive.get() as usize - __binary_nonzero_vma.get() as usize,
62
- // );
63
- let binary_size = unsafe { __binary_nonzero_vma_end_exclusive. get ( ) } as usize
64
- - unsafe { __binary_nonzero_vma. get ( ) } as usize ;
65
- unsafe {
66
- local_memcpy (
67
- __binary_nonzero_vma. get ( ) as * mut u8 ,
68
- __binary_nonzero_lma. get ( ) as * const u8 ,
69
- binary_size,
70
- )
71
- } ;
72
-
73
- // This tries to call memset() at a wrong linked address - the function is in relocated area!
74
-
75
- // Zeroes the .bss section
76
- // Emulate
77
- // crate::stdmem::local_memset(__bss_start.get() as *mut u8, 0u8, __bss_size.get() as usize);
78
- let bss = unsafe {
79
- core:: slice:: from_raw_parts_mut (
80
- __BSS_START. get ( ) as * mut u64 ,
81
- __BSS_SIZE_U64S. get ( ) as usize ,
82
- )
83
- } ;
84
- for i in bss {
85
- * i = 0 ;
86
- }
87
-
88
- // Don't cross this line with loads and stores. The initializations
89
- // done above could be "invisible" to the compiler, because we write to the
90
- // same memory location that is used by statics after this point.
91
- // Additionally, we assume that no statics are accessed before this point.
92
- atomic:: compiler_fence ( Ordering :: SeqCst ) ;
93
-
94
- let max_kernel_size = unsafe { __binary_nonzero_vma. get ( ) } as u64
95
- - unsafe { __boot_core_stack_end_exclusive. get ( ) } as u64 ;
96
- unsafe { crate :: kernel_init ( max_kernel_size) }
31
+ unsafe extern "Rust" {
32
+ fn reset ( ) -> !;
97
33
}
98
34
99
- #[ inline( always) ]
100
- #[ unsafe( link_section = ".text.chainboot" ) ]
101
- unsafe fn local_memcpy ( mut dest : * mut u8 , mut src : * const u8 , n : usize ) {
102
- let dest_end = unsafe { dest. add ( n) } ;
103
- while dest < dest_end {
104
- unsafe { * dest = * src } ;
105
- dest = unsafe { dest. add ( 1 ) } ;
106
- src = unsafe { src. add ( 1 ) } ;
107
- }
108
- }
35
+ core:: arch:: global_asm!( include_str!( "boot.s" ) ) ;
0 commit comments