Skip to content

Commit 2accfc2

Browse files
committed
work
1 parent 2a01039 commit 2accfc2

File tree

3 files changed

+270
-160
lines changed

3 files changed

+270
-160
lines changed

initialize_memory.S

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,40 @@
44

55
;;; Does not handle the region pointer!
66
__initialize_memory:
7-
ldi r31, hi8(__data_load_start)
8-
ldi r30, lo8(__data_load_start) ; Z
97

10-
ldi r29, hi8(__data_load_end)
11-
ldi r28, lo8(__data_load_end) ; Y
8+
__initialize_memory_init_data:
9+
ldi r30, lo8(__data_load_start)
10+
ldi r31, hi8(__data_load_start) ; Z
11+
ldi r24, lo8(__data_end)
12+
ldi r25, hi8(__data_end)
13+
ldi r26, lo8(__data_start)
14+
ldi r27, hi8(__data_start) ; X
15+
rjmp __initialize_memory_init_data_check
1216

13-
ldi r27, hi8(__data_start)
14-
ldi r26, lo8(__data_start) ; X
17+
__initialize_memory_init_data_copy:
18+
lpm r18, Z+
19+
st X+, r18
1520

16-
sub r28, r30
17-
sbc r29, r31 ; Y now contains the length of bytes
18-
rjmp check
21+
__initialize_memory_init_data_check:
22+
cp r26, r24
23+
cpc r27, r25
24+
brne __initialize_memory_init_data_copy
1925

20-
entrypoint:
21-
lpm r0, Z+ ; Load from program memory, increment pointer
22-
st X+, r0 ; Store to RAM, increment pointer
26+
__initialize_memory_init_bss:
27+
ldi r24, lo8(__bss_end)
28+
ldi r25, hi8(__bss_end)
29+
ldi r26, lo8(__data_end) ; X
30+
ldi r27, hi8(__data_end)
31+
ldi r18, 0x00
32+
rjmp __initialize_memory_init_bss_check
2333

24-
subi r28, 1 ; Decrement the count
25-
sbci r29, 0
34+
__initialize_memory_init_bss_copy:
35+
st X+, r18
2636

27-
check:
28-
brne entrypoint ; Exit when all bytes copied
37+
__initialize_memory_init_bss_check:
38+
cp r26, r24
39+
cpc r27, r25
40+
brne __initialize_memory_init_bss_copy
41+
42+
__initialize_memory_finish:
2943
ret

linker-script

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
/* TODO: Verify memory addresses and lengths */
88
MEMORY {
9-
text (rx) : ORIGIN = 0x000000, LENGTH = 64K
10-
data (rw!x) : ORIGIN = 0x800100, LENGTH = 0xFFA0
9+
text (rx) : ORIGIN = 0x000000, LENGTH = 32K
10+
registers (rw!x) : ORIGIN = 0x800000, LENGTH = 256
11+
data (rw!x) : ORIGIN = 0x800100, LENGTH = 2K
1112
}
1213

1314
SECTIONS {
@@ -34,8 +35,10 @@ SECTIONS {
3435

3536
/* Data not initialized to a value */
3637
/* Even possible in Rust? */
38+
/* Yes: zero-initialized */
3739
.bss : AT(ADDR(.data) + SIZEOF(.data)) {
3840
__bss_start = .;
41+
/* Can we avoid actually copying this in? */
3942
* (.bss*);
4043
__bss_end = .;
4144
} >data

0 commit comments

Comments
 (0)