Skip to content
Snippets Groups Projects
Commit 692fcdd8 authored by Alexander Graf's avatar Alexander Graf Committed by Tom Rini
Browse files

arm: Add return value argument to longjmp


The normal longjmp command allows for a caller to pass the return value
of the setjmp() invocation. This patch adds that semantic to the arm
implementation of it and adjusts the efi_loader call respectively.

Signed-off-by: default avatarAlexander Graf <agraf@suse.de>
Reviewed-by: default avatarSimon Glass <sjg@chromium.org>
parent d40dbfb7
No related branches found
No related tags found
No related merge requests found
...@@ -11,29 +11,26 @@ ...@@ -11,29 +11,26 @@
struct jmp_buf_data { struct jmp_buf_data {
ulong target; ulong target;
ulong regs[5]; ulong regs[5];
int ret;
}; };
typedef struct jmp_buf_data jmp_buf[1]; typedef struct jmp_buf_data jmp_buf[1];
static inline int setjmp(jmp_buf jmp) static inline int setjmp(jmp_buf jmp)
{ {
long r = 0; jmp->ret = 0;
#ifdef CONFIG_ARM64 #ifdef CONFIG_ARM64
asm volatile( asm volatile(
"adr x1, jmp_target\n" "adr x1, jmp_target\n"
"str x1, %1\n" "str x1, %0\n"
"stp x26, x27, %2\n" "stp x26, x27, %1\n"
"stp x28, x29, %3\n" "stp x28, x29, %2\n"
"mov x1, sp\n" "mov x1, sp\n"
"str x1, %4\n" "str x1, %3\n"
"b 2f\n"
"jmp_target: " "jmp_target: "
"mov %0, #1\n" : "=m" (jmp->target), "=m" (jmp->regs[0]),
"2:\n" "=m" (jmp->regs[2]), "=m" (jmp->regs[4])
: "+r" (r), "=m" (jmp->target),
"=m" (jmp->regs[0]), "=m" (jmp->regs[2]),
"=m" (jmp->regs[4])
: :
: "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
"x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
...@@ -49,26 +46,25 @@ static inline int setjmp(jmp_buf jmp) ...@@ -49,26 +46,25 @@ static inline int setjmp(jmp_buf jmp)
#else #else
"adr r0, jmp_target\n" "adr r0, jmp_target\n"
#endif #endif
"mov r1, %1\n" "mov r1, %0\n"
"mov r2, sp\n" "mov r2, sp\n"
"stm r1!, {r0, r2, r4, r5, r6, r7}\n" "stm r1!, {r0, r2, r4, r5, r6, r7}\n"
"b 2f\n"
".align 2\n" ".align 2\n"
"jmp_target: \n" "jmp_target: \n"
"mov %0, #1\n" :
"2:\n"
: "+l" (r)
: "l" (&jmp->target) : "l" (&jmp->target)
: "r0", "r1", "r2", "r3", /* "r4", "r5", "r6", "r7", */ : "r0", "r1", "r2", "r3", /* "r4", "r5", "r6", "r7", */
"r8", "r9", "r10", "r11", /* sp, */ "ip", "lr", "r8", "r9", "r10", "r11", /* sp, */ "ip", "lr",
"cc", "memory"); "cc", "memory");
#endif #endif
return r; return jmp->ret;
} }
static inline __noreturn void longjmp(jmp_buf jmp) static inline __noreturn void longjmp(jmp_buf jmp, int ret)
{ {
jmp->ret = ret;
#ifdef CONFIG_ARM64 #ifdef CONFIG_ARM64
asm volatile( asm volatile(
"ldr x0, %0\n" "ldr x0, %0\n"
......
...@@ -475,7 +475,7 @@ static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle, ...@@ -475,7 +475,7 @@ static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
exit_data_size, exit_data); exit_data_size, exit_data);
loaded_image_info->exit_status = exit_status; loaded_image_info->exit_status = exit_status;
longjmp(&loaded_image_info->exit_jmp); longjmp(&loaded_image_info->exit_jmp, 1);
panic("EFI application exited"); panic("EFI application exited");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment