Skip to content

Instantly share code, notes, and snippets.

@pamaury
Created March 16, 2012 15:26
Show Gist options
  • Save pamaury/2050534 to your computer and use it in GitHub Desktop.
Save pamaury/2050534 to your computer and use it in GitHub Desktop.
Check if an address is readable in Rockbox
diff --git a/firmware/drivers/tuner/si4700.c b/firmware/drivers/tuner/si4700.c
index a5b004a..f3bac29 100644
--- a/firmware/drivers/tuner/si4700.c
+++ b/firmware/drivers/tuner/si4700.c
@@ -355,6 +355,7 @@ static void si4700_sleep(int snooze)
bool si4700_detect(void)
{
+ panicf("read: %d", safe_read8(0x40000000, NULL));
if (!tuner_present) {
tuner_power(true);
tuner_present = (si4700_read_reg(DEVICEID) == 0x1242);
diff --git a/firmware/target/arm/imx233/crt0.S b/firmware/target/arm/imx233/crt0.S
index 4ae083c..37f04c7 100644
--- a/firmware/target/arm/imx233/crt0.S
+++ b/firmware/target/arm/imx233/crt0.S
@@ -188,11 +188,6 @@ prefetch_abort_handler:
mov r1, #1
b UIE
-data_abort_handler:
- sub r0, lr, #8
- mov r1, #2
- b UIE
-
/* 256 words of IRQ stack */
.space 256*4
irq_stack:
diff --git a/firmware/target/arm/system-arm.c b/firmware/target/arm/system-arm.c
index c4692bb..a550056 100644
--- a/firmware/target/arm/system-arm.c
+++ b/firmware/target/arm/system-arm.c
@@ -36,6 +36,15 @@ static const char* const uiename[] = {
"SWI"
};
+void __attribute__((weak,naked)) data_abort_handler(void)
+{
+ asm volatile(
+ "sub r0, lr, #8 \r\n"
+ "mov r1, #2 \r\n"
+ "b UIE \r\n"
+ );
+}
+
/* Unexpected Interrupt or Exception handler. Currently only deals with
exceptions, but will deal with interrupts later.
*/
@@ -98,7 +107,7 @@ void NORETURN_ATTR UIE(unsigned int pc, unsigned int num)
if (!triggered)
{
triggered = true;
- backtrace(pc, __get_sp(), &line);
+ //backtrace(pc, __get_sp(), &line);
}
lcd_update();
diff --git a/lib/unwarminder/SOURCES b/lib/unwarminder/SOURCES
index 055e6d0..b060e29 100644
--- a/lib/unwarminder/SOURCES
+++ b/lib/unwarminder/SOURCES
@@ -5,3 +5,4 @@ unwarm.c
unwarminder.c
unwarmmem.c
unwarm_thumb.c
+safe_read.S
\ No newline at end of file
diff --git a/lib/unwarminder/backtrace.c b/lib/unwarminder/backtrace.c
index 4e16091..2cb50ee 100644
--- a/lib/unwarminder/backtrace.c
+++ b/lib/unwarminder/backtrace.c
@@ -23,6 +23,7 @@
***************************************************************************/
#include "backtrace.h"
+#include "symtable.h"
/***************************************************************************
* Prototypes
diff --git a/lib/unwarminder/safe_read.S b/lib/unwarminder/safe_read.S
new file mode 100644
index 0000000..520c767
--- /dev/null
+++ b/lib/unwarminder/safe_read.S
@@ -0,0 +1,75 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2012 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+.data
+was_aborted:
+ .word 0
+
+.section .text.safe_read8,"ax",%progbits
+.global safe_read8
+@ bool safe_read8(uint8_t *addr, uint8_t *value)
+safe_read8:
+ @ was_aborted = 0
+ ldr r2, =was_aborted
+ mov r3, #0
+ str r3, [r2]
+ @ r0=*addr
+safe_read8_faulty_addr:
+ ldrb r0, [r0]
+ @ if(was_aborted)
+ ldr r2, [r2]
+ cmp r2, #1
+ @ return false;
+ moveq r0, #0
+ bxeq lr
+ @ if(value != NULL)
+ cmp r1, #0
+ @ *value = r0
+ streqb r0, [r1]
+ @ return true;
+ mov r0, #1
+ bx lr
+
+.section .text.data_abort_handler,"ax",%progbits
+.global data_abort_handler
+data_abort_handler:
+ @ store minimal amount of registers
+ stmfd sp!, {r0-r1}
+ @ compute faulty address
+ sub r0, lr, #8
+ @ compare to safe_read8
+ ldr r1, =safe_read8_faulty_addr
+ cmp r0, r1
+ @ if equal, special treatment
+ beq 1f
+ @ otherwise just normally to UIE
+ mov r0, r1
+ mov r1, #2
+ b UIE
+1:
+ @ set was_aborted
+ ldr r1, =was_aborted
+ mov r0, #1
+ str r0, [r1]
+ @ restore registers
+ ldmfd sp!, {r0-r1}
+ @ restore mode and jump back to the *next* instruction
+ subs pc, lr, #-4
diff --git a/lib/unwarminder/safe_read.h b/lib/unwarminder/safe_read.h
new file mode 100644
index 0000000..0ad23e6
--- /dev/null
+++ b/lib/unwarminder/safe_read.h
@@ -0,0 +1,33 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2012 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef __SAFE_READ__
+#define __SAFE_READ__
+
+#include "system.h"
+
+/* Try to read an X-bit unsigned integer. If the address is not readable,
+ * returns false. Otherwise returns true and store the result in *value
+ * if value is not NULL */
+bool safe_read8(uint8_t *addr, uint8_t *value);
+bool safe_read16(uint16_t *addr, uint16_t *value);
+bool safe_read32(uint32_t *addr, uint32_t *value);
+
+#endif /* __SAFE_READ__ */
\ No newline at end of file
diff --git a/tools/configure b/tools/configure
index ffded7e..b6152cc 100755
--- a/tools/configure
+++ b/tools/configure
@@ -3695,6 +3695,11 @@ if test -n "$ccache"; then
CC="$ccache $CC"
fi
+if test "$arch" = "arm"; then
+ extradefines="$extradefines -DPOKE_FUNCTION_NAMES"
+ GCCOPTS="$GCCOPTS -mpoke-function-name"
+fi
+
if test "$ARG_ARM_THUMB" = "1"; then
extradefines="$extradefines -DUSE_THUMB"
CC="$toolsdir/thumb-cc.py $CC"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment