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
48
49
50
51
52
53
54
use ALLOC;
use core::ptr;
pub unsafe fn bss_init() {
extern "C" {
static mut BSS_START: usize;
static BSS_END: usize;
}
let bss_start = &mut BSS_START as *mut usize;
let bss_end = &BSS_END as *const usize;
let count = (bss_end as usize - bss_start as usize) >> 2;
ptr::write_bytes(bss_start, 0, count);
}
pub unsafe fn data_init() {
extern "C" {
static mut DATA_START: usize;
static DATA_END: usize;
static DATA_CONST: usize;
}
let data_start = &mut DATA_START as *mut usize;
let data_end = &DATA_END as *const usize;
let data_const = &DATA_CONST as *const usize;
let count = (data_end as usize - data_start as usize) >> 2;
ptr::copy_nonoverlapping(data_const, data_start, count);
}
pub unsafe fn heap_init() {
extern "C" {
static HEAP_START: usize;
static HEAP_END: usize;
}
let heap_start = &HEAP_START as *const usize;
let heap_end = &HEAP_END as *const usize;
let count = heap_end as usize - heap_start as usize;
ALLOC.lock().init(heap_start as usize, count);
}