forked from lurk101/pshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cc_printf.S
65 lines (53 loc) · 1.68 KB
/
cc_printf.S
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
58
59
60
61
62
63
64
65
.syntax unified
.cpu cortex-m0plus
.thumb
.section .text.cc_printf
.global cc_printf
.type cc_printf,%function
.thumb_func
.extern __wrap_printf
// int cc_printf(void* stk, int wrds);
cc_printf:
// r4 parameter block
// r5 parameter block words
// r6 stack save
push {r4,r5,r6, lr} // save the top regs
mov r4, r0 // Set up the base and count regs
mov r5, r1
mov r6, sp // Save the stack pointer
// the final stack pointer needs to be 8 byte aligned
lsls r0, r5, #2 // if both on even boundary
mov r1, sp // or both on odd boundary
eors r0, R1 // then we don't need to adjust
lsls r0, #29
lsrs r0, #31
beq l0
sub sp, #4 // align the stack
l0: lsls r0, r5, #2 // make space for arguments
mov r1, sp
subs r1, r0
mov sp, r1
l1: mov r0, sp // copy args to the stack
mov r1, r4
mov r2, r5
l2: cmp r2, #0
beq l3
ldm r1!, {r3}
stm r0!, {r3}
subs r2, #1
b l2
l3: cmp r5, #0 // move up to the 1st 4 words
beq l4 // to r0, r1, r2, and r3
pop {r0}
cmp r5, #1
beq l4
pop {r1}
cmp r5, #2
beq l4
pop {r2}
cmp r5, #3
beq l4
pop {r3}
l4: bl __wrap_printf // call SDK's printf
mov sp, r6 // restore the stack and top regs
pop {r4,r5,r6,pc}