baremetal: allow arbitrary exit status with the magic string

test-baremetal: fix missing setting x0 return value

Examples were just returning on ret without setting x0, which led to
failures... those were not noticed because of how broken the testing system
was ;-)
This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-05-06 00:00:01 +00:00
parent ff8cbe9d7a
commit 26cab92bfc
20 changed files with 133 additions and 77 deletions

View File

@@ -1,12 +1,13 @@
.global main
main:
/* 1 + 2 == 3 */
mov x0, #1
mov x0, 1
/* test-gdb-op1 */
add x1, x0, #2
add x1, x0, 2
/* test-gdb-result */
cmp x1, #3
cmp x1, 3
beq 1f
bl lkmc_assert_fail
1:
mov x0, 0
ret

View File

@@ -1,5 +1,5 @@
/* Call a C function. */
.global main
main:
mov x0, #0
mov x0, 0
bl exit

View File

@@ -3,43 +3,45 @@
.global main
main:
/* 1.5 + 2.5 == 4.0 */
fmov d0, #1.5
fmov d0, 1.5
/* test-gdb-d0 */
fmov d1, #2.5
fmov d1, 2.5
/* test-gdb-d1 */
fadd d2, d0, d1
/* test-gdb-d2 */
fmov d3, #4.0
fmov d3, 4.0
fcmp d2, d3
beq 1f
bl lkmc_assert_fail
1:
/* Now in 32-bit. */
fmov s0, #1.5
fmov s0, 1.5
/* test-gdb-s0 */
fmov s1, #2.5
fmov s1, 2.5
/* test-gdb-s1 */
fadd s2, s0, s1
/* test-gdb-s2 */
fadd s2, s0, s1
fmov s3, #4.0
fmov s3, 4.0
fcmp s2, s3
beq 1f
bl lkmc_assert_fail
1:
/* Higher registers. */
fmov d28, #1.5
fmov d28, 1.5
/* test-gdb-d28 */
fmov d29, #2.5
fmov d29, 2.5
/* test-gdb-d29 */
fadd d30, d28, d29
/* test-gdb-d30 */
fmov d31, #4.0
fmov d31, 4.0
/* test-gdb-d31 */
fcmp d30, d31
beq 1f
bl lkmc_assert_fail
1:
mov x0, 0
ret

View File

@@ -3,7 +3,7 @@
.global main
main:
/* Reset spinlock. */
mov x0, #0
mov x0, 0
ldr x1, =spinlock
str x0, [x1]
@@ -66,6 +66,7 @@ spinlock_start:
wfe
cbz x0, spinlock_start
mov x0, 0
ret
spinlock:

View File

@@ -6,7 +6,7 @@ mystart:
movk x1, 2, lsl 16
ldr x2, =semihost_args
str x1, [x2, 0]
mov x0, #0
mov x0, 0
str x0, [x2, 8]
mov x1, x2
mov w0, 0x18

View File

@@ -4,26 +4,26 @@
*/
.global main
main:
mov x0, #1
mov x0, 1
/* test-gdb-x0 */
mov x1, #2
mov x1, 2
/* test-gdb-x1 */
mov x29, #1
mov x29, 1
/* test-gdb-x29 */
mov x30, #2
mov x30, 2
/* test-gdb-x30 */
fmov d0, #1.5
fmov d0, 1.5
/* test-gdb-d0 */
fmov d1, #2.5
fmov d1, 2.5
/* test-gdb-d1 */
fmov d30, #1.5
fmov d30, 1.5
/* test-gdb-d30 */
fmov d31, #2.5
fmov d31, 2.5
/* test-gdb-d31 */
/* Exit required since we messed up with x30 which is the lr. */
mov x0, #0
mov x0, 0
bl exit

View File

@@ -1,4 +1,5 @@
/* Return to ensure that the post main works. */
.global main
main:
mov x0, 0
ret

View File

@@ -16,6 +16,7 @@ main:
1:
/* Go home. */
mov x0, 0
ret
LKMC_GLOBAL(lkmc_vector_trap_handler)

View File

@@ -9,4 +9,5 @@ main:
beq 1f
bl lkmc_assert_fail
1:
mov r0, #0
bx lr

View File

@@ -32,6 +32,7 @@ spinlock_start:
wfe
cmp r0, #0
beq spinlock_start
mov r0, #0
bx lr
spinlock:
.skip 4

View File

@@ -5,4 +5,5 @@ main:
/* test-gdb-r0 */
mov r1, #2
/* test-gdb-r1 */
mov r0, #0
bx lr

View File

@@ -62,13 +62,23 @@ int _write(int file, char *ptr, int len) {
return len;
}
/* Only 0 is supported for now, arm semihosting cannot handle other values. */
void _exit(int status) {
if (status != 0) {
/* https://github.com/cirosantilli/linux-kernel-module-cheat#magic-failure-string */
printf("lkmc_exit_status_%d\n", status);
}
#if defined(GEM5)
LKMC_M5OPS_EXIT;
#else
#if defined(__arm__)
__asm__ __volatile__ ("mov r0, #0x18; ldr r1, =#0x20026; svc 0x00123456" : : : "r0", "r1");
__asm__ __volatile__ (
"mov r0, #0x18\n"
"ldr r1, =#0x20026\n"
"svc 0x00123456\n"
:
:
: "r0", "r1"
);
#elif defined(__aarch64__)
/* TODO actually use the exit value here, just for fun. */
__asm__ __volatile__ (

1
baremetal/return2.c Normal file
View File

@@ -0,0 +1 @@
int main(void) { return 2; }