mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
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.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include <common.h>
|
||||
|
||||
void main(void) {
|
||||
int main(void) {
|
||||
int i, j, k;
|
||||
i = 1;
|
||||
/* test-gdb-op1 */
|
||||
@@ -9,5 +9,5 @@ void main(void) {
|
||||
k = i + j;
|
||||
/* test-gdb-result */
|
||||
if (k != 3)
|
||||
assert_fail();
|
||||
common_assert_fail();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ main:
|
||||
/* test-gdb-result */
|
||||
cmp x1, #3
|
||||
beq 1f
|
||||
bl assert_fail
|
||||
bl common_assert_fail
|
||||
1:
|
||||
ret
|
||||
|
||||
@@ -12,7 +12,7 @@ main:
|
||||
fmov d3, #4.0
|
||||
fcmp d2, d3
|
||||
beq 1f
|
||||
bl assert_fail
|
||||
bl common_assert_fail
|
||||
1:
|
||||
|
||||
/* Now in 32-bit. */
|
||||
@@ -26,7 +26,7 @@ main:
|
||||
fmov s3, #4.0
|
||||
fcmp s2, s3
|
||||
beq 1f
|
||||
bl assert_fail
|
||||
bl common_assert_fail
|
||||
1:
|
||||
|
||||
/* Higher registers. */
|
||||
@@ -40,6 +40,6 @@ main:
|
||||
/* test-gdb-d31 */
|
||||
fcmp d30, d31
|
||||
beq 1f
|
||||
bl assert_fail
|
||||
bl common_assert_fail
|
||||
1:
|
||||
ret
|
||||
|
||||
@@ -7,6 +7,6 @@ main:
|
||||
/* test-gdb-result */
|
||||
cmp r1, #3
|
||||
beq 1f
|
||||
bl assert_fail
|
||||
bl common_assert_fail
|
||||
1:
|
||||
bx lr
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void main(void) {
|
||||
int main(void) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <common.h>
|
||||
|
||||
void main(void) {
|
||||
assert_fail();
|
||||
int main(void) {
|
||||
common_assert_fail();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void main(void) {
|
||||
int main(void) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void main(void) {
|
||||
int main(void) {
|
||||
puts("hello");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void main(void) {
|
||||
int main(void) {
|
||||
char c;
|
||||
char *ptr = NULL;
|
||||
size_t alloc_size = 1;
|
||||
@@ -19,4 +19,3 @@ void main(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1
baremetal/interactive/return1.c
Normal file
1
baremetal/interactive/return1.c
Normal file
@@ -0,0 +1 @@
|
||||
int main(void) { return 1; }
|
||||
@@ -8,5 +8,4 @@ mystart:
|
||||
ldr x0, =stack_top
|
||||
mov sp, x0
|
||||
bl main
|
||||
mov x0, #0
|
||||
bl exit
|
||||
|
||||
@@ -2,5 +2,4 @@
|
||||
mystart:
|
||||
ldr sp, =stack_top
|
||||
bl main
|
||||
mov r0, #0
|
||||
bl exit
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
void assert_fail();
|
||||
#endif
|
||||
@@ -86,8 +86,3 @@ void _exit(int status) {
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void assert_fail() {
|
||||
puts("lkmc_test_fail");
|
||||
exit(1);
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
void main(void) {}
|
||||
int main(void) { return 0; }
|
||||
|
||||
Reference in New Issue
Block a user