blob: 5d4bc416c2a5e065f4e0b42178f12998372daa0a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// Copyright (C) 2024 Clyne Sullivan <clyne@bitgloo.com>
//
// Distributed under the GNU GPL v3 or later. You should have received a copy of
// the GNU General Public License along with this program.
// If not, see <https://www.gnu.org/licenses/>.
const main = @import("main.zig");
extern const __data_flash: u32;
extern const __data: u32;
extern const __data_size: u32;
extern const __bss: u32;
extern const __bss_size: u32;
comptime {
asm (
\\.extern _start
\\.extern _tstack
\\
\\.section .vector_table
\\.global init_vector_table
\\init_vector_table:
\\ .word _tstack
\\ .word _start
\\ .skip 4 * 14
);
}
inline fn zero_bss() void {
const bss: [*]volatile u8 = @ptrFromInt(@intFromPtr(&__bss));
@memset(bss[0..@intFromPtr(&__bss_size)], 0);
}
inline fn copy_data() void {
const data_flash: [*]volatile u8 = @ptrFromInt(@intFromPtr(&__data_flash));
const data: [*]volatile u8 = @ptrFromInt(@intFromPtr(&__data));
const data_size = @intFromPtr(&__data_size);
@memcpy(data[0..data_size], data_flash[0..data_size]);
}
export fn _start() callconv(.C) noreturn {
zero_bss();
copy_data();
main.main();
while (true) {}
}
|