summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/m32r/m32rsim/start/start.S
blob: 9b1138987232436c33f682da1bebc019fd8ca3b5 (plain) (blame)
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
55
56
57
/*
 *  From Newlib 1.16.0
 */

	.text
	.balign 4
	.global	_start
_start:

	seth	sp, #shigh(_stack)
	add3	sp, sp, #low(_stack)
	ldi	fp, #0

# Clear the BSS.  Do it in two parts for efficiency: longwords first
# for most of it, then the remaining 0 to 3 bytes.

	seth	r2, #shigh(__bss_start)
	add3	r2, r2, #low(__bss_start); R2 = start of BSS
	seth	r3, #shigh(_end)
	add3	r3, r3, #low(_end)	; R3 = end of BSS + 1

	sub	r3, r2		; R3 = BSS size in bytes
	mv	r4, r3
	srli	r4, #2		; R4 = BSS size in longwords (rounded down)
	ldi	r1, #0		; clear R1 for longword store
	addi	r2, #-4		; account for pre-inc store
	beqz	r4, .Lendloop1	; any more to go?
.Lloop1:
	st	r1, @+r2	; yep, zero out another longword
	addi	r4, #-1		; decrement count
	bnez	r4, .Lloop1	; go do some more
.Lendloop1:
	and3	r4, r3, #3	; get no. of remaining BSS bytes to clear
	addi	r2, #4		; account for pre-inc store
	beqz	r4, .Lendloop2	; any more to go?
.Lloop2:
	stb	r1, @r2		; yep, zero out another byte
	addi	r2, #1		; bump address
	addi	r4, #-1		; decrement count
	bnez	r4, .Lloop2	; go do some more
.Lendloop2:

# Run code in the .init section.
# This will queue the .fini section to be run with atexit.

	# bl	__init

# Call main, then exit.

	ldi	r1, #0           ; r1 = argv
	ldi	r0, #0           ; r0 = argc
	bl	boot_card

# If that fails just loop.

.Lexit:
	bra	.Lexit