-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathcommon_arch.h
More file actions
71 lines (63 loc) · 1.48 KB
/
Copy pathcommon_arch.h
File metadata and controls
71 lines (63 loc) · 1.48 KB
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
66
67
68
69
70
71
#ifndef COMMON_ARCH_H
#define COMMON_ARCH_H
.syntax unified
/* Assert that a register equals a constant.
* * reg: the register to check. Can be r0-r10, but not r11. r11 is overwritten.
* * const: the constant to compare to. Only works for literals or labels, not for registers.
* For register / register comparision, use ASSERT_EQ_REG.
*/
#define ASSERT_EQ(reg, const) \
ldr r11, =const; \
cmp reg, r11; \
ASSERT(beq); \
;
/* Assert that two arrays are the same. */
#define ASSERT_MEMCMP(s1, s2, n) \
MEMCMP(s1, s2, n); \
ASSERT_EQ(r0, 0); \
;
/* Store all callee saved registers, and LR in case we make further BL calls.
*
* Also save the input arguments r0-r3 on the stack, so we can access them later on,
* despite those registers being overwritten.
*/
#define ENTRY \
.text; \
.global asm_main; \
asm_main: \
stmdb sp!, {r0-r12, lr}; \
asm_main_after_prologue: \
;
/* Meant to be called at the end of ENTRY.*
*
* Branching to "fail" makes tests fail with exit status 1.
*
* If EXIT is reached, the program ends successfully.
*
* Restore LR and bx jump to it to return from asm_main.
*/
#define EXIT \
mov r0, 0; \
mov r1, 0; \
b pass; \
fail: \
ldr r1, [sp]; \
str r0, [r1]; \
mov r0, 1; \
pass: \
add sp, 16; \
ldmia sp!, {r4-r12, lr}; \
bx lr; \
;
/* Always fail. */
#define FAIL \
ldr r0, =__LINE__; \
b fail; \
;
#define MEMCMP(s1, s2, n) \
ldr r0, =s1; \
ldr r1, =s2; \
ldr r2, =n; \
bl memcmp; \
;
#endif