File tree Expand file tree Collapse file tree 5 files changed +30
-10
lines changed
Expand file tree Collapse file tree 5 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -29,4 +29,16 @@ get_kernel_end:
2929 add x0, x0, :lo12:__kernel_end
3030 ret
3131
32+ .global get_bss_start
33+ get_bss_start:
34+ adrp x0, __bss_start
35+ add x0, x0, :lo12:__bss_start
36+ ret
37+
38+ .global get_bss_end
39+ get_bss_end:
40+ adrp x0, __bss_end
41+ add x0, x0, :lo12:__bss_end
42+ ret
43+
3244#endif
Original file line number Diff line number Diff line change @@ -65,15 +65,6 @@ el1_entry:
6565 ldr x1 , =_start
6666 mov sp , x1
6767
68- // clear bss
69- ldr x1 , =__bss_start
70- ldr w2 , =__bss_size
71- clear_bss_loop:
72- cbz w2 , jump_to_main
73- str xzr , [ x1 ], # 8 // stores a 64 - bit doubleword so __bss_end must be 8 - byte aligned
74- sub w2 , w2 , # 1
75- cbnz w2 , clear_bss_loop
76-
7768jump_to_main:
7869 // jump to Swift code , should not return
7970 bl Kernel_main
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ void delay(uint64_t);
66void halt ();
77uintptr_t get_kernel_start ();
88uintptr_t get_kernel_end ();
9+ uintptr_t get_bss_start ();
10+ uintptr_t get_bss_end ();
911#ifdef __aarch64__
1012uint32_t get_el ();
1113#endif
Original file line number Diff line number Diff line change @@ -4,9 +4,25 @@ private import AsmSupport
44 private import RaspberryPi
55#endif
66
7+ func zeroBSS( ) {
8+ let start = get_bss_start ( )
9+ let end = get_bss_end ( )
10+ let size = end - start
11+
12+ precondition ( start % 8 == 0 )
13+ precondition ( size % 8 == 0 )
14+
15+ // swift-format-ignore: NeverForceUnwrap
16+ let ptr = unsafe UnsafeMutableRawPointer( bitPattern: start) !
17+
18+ unsafe ptr. initializeMemory ( as: UInt64 . self, repeating: 0 , count: Int ( size >> 3 ) )
19+ }
20+
721@main
822struct Kernel {
923 static func main( ) {
24+ zeroBSS ( )
25+
1026 #if RASPI
1127 initUART ( )
1228
Original file line number Diff line number Diff line change @@ -24,4 +24,3 @@ SECTIONS {
2424 *(.swift_modhash *)
2525 }
2626}
27- __bss_size = (__bss_end - __bss_start) >> 3 ;
You can’t perform that action at this time.
0 commit comments