Skip to content

Commit

Permalink
core/util: branch-to-NULL assert for ELFv2 ABI
Browse files Browse the repository at this point in the history
The ELFv1 branch to NULL catcher puts a function descriptor at 0 which
points to a function that asserts. For ELFv2, put a trap at address 0.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[oliver: commit message prefix]
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
  • Loading branch information
npiggin authored and oohal committed Oct 2, 2019
1 parent 9ddc1a6 commit 216433a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions asm/head.S
Expand Up @@ -35,6 +35,8 @@
. = 0
.global __head
__head:
trap

/* This entry point is used when booting with a flat device-tree
* pointer in r3
*/
Expand Down
21 changes: 15 additions & 6 deletions core/init.c
Expand Up @@ -15,6 +15,7 @@
#include <opal.h>
#include <opal-msg.h>
#include <elf.h>
#include <elf-abi.h>
#include <io.h>
#include <cec.h>
#include <device.h>
Expand Down Expand Up @@ -757,13 +758,25 @@ static void __nomcount do_ctors(void)
(*call)();
}

#ifndef PPC64_ELF_ABI_v2
#ifdef ELF_ABI_v2
static void setup_branch_null_catcher(void)
{
asm volatile( \
".section .rodata" "\n\t" \
"3: .string \"branch to NULL\"" "\n\t" \
".previous" "\n\t" \
".section .trap_table,\"aw\"" "\n\t" \
".llong 0" "\n\t" \
".llong 3b" "\n\t" \
".previous" "\n\t" \
);
}
#else
static void branch_null(void)
{
assert(0);
}


static void setup_branch_null_catcher(void)
{
void (*bn)(void) = branch_null;
Expand All @@ -775,10 +788,6 @@ static void setup_branch_null_catcher(void)
*/
memcpy_null(0, bn, 16);
}
#else
static void setup_branch_null_catcher(void)
{
}
#endif

void copy_sreset_vector(void)
Expand Down

0 comments on commit 216433a

Please sign in to comment.