From 9bb6050d40b9936beda5cb1cd15040f6c1b07179 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Wed, 18 Jan 2017 14:36:27 +0100 Subject: hwstub: rewrite exception catching Since we can catch exceptions like data aborts on read/write, it takes very little to also catch exceptions in calls. When extending this with the catching of illegal instructions, the call instruction now becomes much more robust and also for address and instruction probing. Since we can catch several types of exception, rename set_data_abort_jmp to set_exception_jmp. At the same time, simplify the logic in read/write request handlers. Also fix a bug in ARM jump code: it was using stmia r1, {..., pc} as if pc would get current pc + 8 but this is actually implementation defined on older ARMs (typically pc + 12) and deprecated on newer ARMs, so rewrite the code avoid that. The set_exception_jmp() function now also reports the exception type. Change-Id: Icd0dd52d2456b361b27c4776be09c3d13528ed93 --- utils/hwstub/stub/system.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'utils/hwstub/stub/system.h') diff --git a/utils/hwstub/stub/system.h b/utils/hwstub/stub/system.h index 09c86debfe..5de08cb40a 100644 --- a/utils/hwstub/stub/system.h +++ b/utils/hwstub/stub/system.h @@ -21,6 +21,7 @@ #ifndef __HWSTUB_SYSTEM__ #define __HWSTUB_SYSTEM__ +#ifdef ARM_ARCH #define IRQ_ENABLED 0x00 #define IRQ_DISABLED 0x80 #define IRQ_STATUS 0x80 @@ -56,6 +57,7 @@ #define enable_fiq() \ enable_interrupt(FIQ_STATUS) +#ifndef __ASSEMBLER__ static inline int set_interrupt_status(int status, int mask) { unsigned long cpsr; @@ -113,8 +115,21 @@ static inline int disable_interrupt_save(int mask) : "i"(mask)); return cpsr; } +#endif /* __ASSEMBLER__ */ +#endif /* ARM_ARCH */ -int set_data_abort_jmp(void); +/* Save the current context into a local buffer and return 0. + * When an exception occurs, typically read/write at invalid address or invalid + * instructions (the exact exceptions caught depend on the architecture), it will + * restore the context to what it was when the function was called except that + * it returns a nonzero value describing the error */ +#define EXCEPTION_NONE 0 /* no exception, returned on the first call */ +#define EXCEPTION_UNSP 1 /* some unspecified exception occured */ +#define EXCEPTION_ADDR 2 /* read/write at an invalid address */ +#define EXCEPTION_INSTR 3 /* invalid instruction */ + +#ifndef __ASSEMBLER__ +int set_exception_jmp(void); +#endif /* __ASSEMBLER__ */ #endif /* __HWSTUB_SYSTEM__ */ - -- cgit v1.2.3