Skip to content

Commit

Permalink
openrisc: Work around potential relocation issues
Browse files Browse the repository at this point in the history
When reset code is in flash, the jump instructions emitted by the
compiler are relative instead of absolute jumps.

A fix to the reset code to make correct jumps to the beginning of
code relocated to RAM have also been added.

Signed-off-by: Julius Baxter <[email protected]>
  • Loading branch information
juliusbaxter authored and wdenx committed Aug 9, 2012
1 parent eb0b43f commit 3874a37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 5 additions & 1 deletion arch/openrisc/cpu/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ extern void __reset(void);
int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
disable_interrupts();
__reset();
/* Code the jump to __reset here as the compiler is prone to
emitting a bad jump instruction if the function is in flash */
__asm__("l.movhi r1,hi(__reset); \
l.ori r1,r1,lo(__reset); \
l.jr r1");
/* not reached, __reset does not return */
return 0;
}
13 changes: 8 additions & 5 deletions arch/openrisc/cpu/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@

#define HANDLE_EXCEPTION \
l.addi r1, r1, -EXCEPTION_STACK_SIZE ;\
l.sw 0x00(r1), r2 ;\
l.sw 0x1c(r1), r9 ;\
l.jal _exception_handler ;\
l.movhi r2,hi(_exception_handler) ;\
l.ori r2,r2,lo(_exception_handler) ;\
l.jalr r2 ;\
l.nop ;\
l.lwz r9, 0x1c(r1) ;\
l.addi r1, r1, EXCEPTION_STACK_SIZE ;\
Expand Down Expand Up @@ -79,8 +82,9 @@ __reset:
l.bnf .L_relocvectors
l.addi r4,r4, 4
#endif

l.j _start
l.movhi r4,hi(_start)
l.ori r4,r4,lo(_start)
l.jr r4
l.nop

/* bus error */
Expand Down Expand Up @@ -262,8 +266,7 @@ _start:
.type _exception_handler,@function

_exception_handler:
/* Store state (r9 already saved)*/
l.sw 0x00(r1), r2
/* Store state (r2 and r9 already saved)*/
l.sw 0x04(r1), r3
l.sw 0x08(r1), r4
l.sw 0x0c(r1), r5
Expand Down

0 comments on commit 3874a37

Please sign in to comment.