Skip to content

Commit 26b890f

Browse files
committed
Factor common userland and baremetal C functions
This allows add.c to run unmodified on both! For that to work, use int main on baremetal, and pass the return value to the final exit.
1 parent ecc2a21 commit 26b890f

26 files changed

+87
-52
lines changed

baremetal/add.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <common.h>
22

3-
void main(void) {
3+
int main(void) {
44
int i, j, k;
55
i = 1;
66
/* test-gdb-op1 */
@@ -9,5 +9,5 @@ void main(void) {
99
k = i + j;
1010
/* test-gdb-result */
1111
if (k != 3)
12-
assert_fail();
12+
common_assert_fail();
1313
}

baremetal/arch/aarch64/add.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ main:
77
/* test-gdb-result */
88
cmp x1, #3
99
beq 1f
10-
bl assert_fail
10+
bl common_assert_fail
1111
1:
1212
ret

baremetal/arch/aarch64/fadd.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ main:
1212
fmov d3, #4.0
1313
fcmp d2, d3
1414
beq 1f
15-
bl assert_fail
15+
bl common_assert_fail
1616
1:
1717

1818
/* Now in 32-bit. */
@@ -26,7 +26,7 @@ main:
2626
fmov s3, #4.0
2727
fcmp s2, s3
2828
beq 1f
29-
bl assert_fail
29+
bl common_assert_fail
3030
1:
3131

3232
/* Higher registers. */
@@ -40,6 +40,6 @@ main:
4040
/* test-gdb-d31 */
4141
fcmp d30, d31
4242
beq 1f
43-
bl assert_fail
43+
bl common_assert_fail
4444
1:
4545
ret

baremetal/arch/arm/add.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ main:
77
/* test-gdb-result */
88
cmp r1, #3
99
beq 1f
10-
bl assert_fail
10+
bl common_assert_fail
1111
1:
1212
bx lr

baremetal/exit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33

4-
void main(void) {
4+
int main(void) {
55
exit(0);
66
}
77

baremetal/interactive/assert_fail.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <common.h>
22

3-
void main(void) {
4-
assert_fail();
3+
int main(void) {
4+
common_assert_fail();
55
}
66

baremetal/interactive/exit1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33

4-
void main(void) {
4+
int main(void) {
55
exit(1);
66
}

baremetal/interactive/hello.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdio.h>
22

3-
void main(void) {
3+
int main(void) {
44
puts("hello");
5+
return 0;
56
}

baremetal/interactive/prompt.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33

4-
void main(void) {
4+
int main(void) {
55
char c;
66
char *ptr = NULL;
77
size_t alloc_size = 1;
@@ -19,4 +19,3 @@ void main(void) {
1919
}
2020
}
2121
}
22-

baremetal/interactive/return1.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int main(void) { return 1; }

0 commit comments

Comments
 (0)