summaryrefslogtreecommitdiff
path: root/arch/microblaze/cpu
diff options
context:
space:
mode:
Diffstat (limited to 'arch/microblaze/cpu')
-rw-r--r--arch/microblaze/cpu/exception.c35
-rw-r--r--arch/microblaze/cpu/interrupts.c76
-rw-r--r--arch/microblaze/cpu/irq.S121
-rw-r--r--arch/microblaze/cpu/spl.c2
-rw-r--r--arch/microblaze/cpu/start.S126
-rw-r--r--arch/microblaze/cpu/u-boot-spl.lds6
-rw-r--r--arch/microblaze/cpu/u-boot.lds12
7 files changed, 254 insertions, 124 deletions
diff --git a/arch/microblaze/cpu/exception.c b/arch/microblaze/cpu/exception.c
index 227842f6a4..aa34f45bef 100644
--- a/arch/microblaze/cpu/exception.c
+++ b/arch/microblaze/cpu/exception.c
@@ -13,49 +13,52 @@ void _hw_exception_handler (void)
{
int address = 0;
int state = 0;
+
/* loading address of exception EAR */
- MFS (address, rear);
+ MFS(address, rear);
/* loading excetpion state register ESR */
- MFS (state, resr);
- printf ("Hardware exception at 0x%x address\n", address);
+ MFS(state, resr);
+ printf("Hardware exception at 0x%x address\n", address);
+ R17(address);
+ printf("Return address from exception 0x%x\n", address);
switch (state & 0x1f) { /* mask on exception cause */
case 0x1:
- puts ("Unaligned data access exception\n");
+ puts("Unaligned data access exception\n");
break;
case 0x2:
- puts ("Illegal op-code exception\n");
+ puts("Illegal op-code exception\n");
break;
case 0x3:
- puts ("Instruction bus error exception\n");
+ puts("Instruction bus error exception\n");
break;
case 0x4:
- puts ("Data bus error exception\n");
+ puts("Data bus error exception\n");
break;
case 0x5:
- puts ("Divide by zero exception\n");
+ puts("Divide by zero exception\n");
break;
#ifdef MICROBLAZE_V5
case 0x7:
puts("Priviledged or stack protection violation exception\n");
break;
case 0x1000:
- puts ("Exception in delay slot\n");
+ puts("Exception in delay slot\n");
break;
#endif
default:
- puts ("Undefined cause\n");
+ puts("Undefined cause\n");
break;
}
- printf ("Unaligned %sword access\n", ((state & 0x800) ? "" : "half"));
- printf ("Unaligned %s access\n", ((state & 0x400) ? "store" : "load"));
- printf ("Register R%x\n", (state & 0x3E) >> 5);
- hang ();
+ printf("Unaligned %sword access\n", ((state & 0x800) ? "" : "half"));
+ printf("Unaligned %s access\n", ((state & 0x400) ? "store" : "load"));
+ printf("Register R%x\n", (state & 0x3E) >> 5);
+ hang();
}
#ifdef CONFIG_SYS_USR_EXCEP
void _exception_handler (void)
{
- puts ("User vector_exception\n");
- hang ();
+ puts("User vector_exception\n");
+ hang();
}
#endif
diff --git a/arch/microblaze/cpu/interrupts.c b/arch/microblaze/cpu/interrupts.c
index 9364e2fa9c..b6d6610f2f 100644
--- a/arch/microblaze/cpu/interrupts.c
+++ b/arch/microblaze/cpu/interrupts.c
@@ -14,10 +14,9 @@
#include <asm/microblaze_intc.h>
#include <asm/asm.h>
-#undef DEBUG_INT
-
void enable_interrupts(void)
{
+ debug("Enable interrupts for the whole CPU\n");
MSRSET(0x2);
}
@@ -50,12 +49,11 @@ static void enable_one_interrupt(int irq)
offset <<= irq;
mask = intc->ier;
intc->ier = (mask | offset);
-#ifdef DEBUG_INT
- printf("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
- intc->ier);
- printf("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
- intc->iar, intc->mer);
-#endif
+
+ debug("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
+ intc->ier);
+ debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
+ intc->iar, intc->mer);
}
static void disable_one_interrupt(int irq)
@@ -66,12 +64,11 @@ static void disable_one_interrupt(int irq)
offset <<= irq;
mask = intc->ier;
intc->ier = (mask & ~offset);
-#ifdef DEBUG_INT
- printf("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
- intc->ier);
- printf("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
- intc->iar, intc->mer);
-#endif
+
+ debug("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
+ intc->ier);
+ debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
+ intc->iar, intc->mer);
}
int install_interrupt_handler(int irq, interrupt_handler_t *hdlr, void *arg)
@@ -88,12 +85,12 @@ int install_interrupt_handler(int irq, interrupt_handler_t *hdlr, void *arg)
act->handler = hdlr;
act->arg = arg;
act->count = 0;
- enable_one_interrupt (irq);
+ enable_one_interrupt(irq);
return 0;
}
/* Disable */
- act->handler = (interrupt_handler_t *) def_hdlr;
+ act->handler = (interrupt_handler_t *)def_hdlr;
act->arg = (void *)irq;
disable_one_interrupt(irq);
return 1;
@@ -107,18 +104,17 @@ static void intc_init(void)
intc->iar = 0xFFFFFFFF;
/* XIntc_Start - hw_interrupt enable and all interrupt enable */
intc->mer = 0x3;
-#ifdef DEBUG_INT
- printf("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
- intc->iar, intc->mer);
-#endif
+
+ debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
+ intc->iar, intc->mer);
}
-int interrupts_init(void)
+int interrupt_init(void)
{
int i;
#if defined(CONFIG_SYS_INTC_0_ADDR) && defined(CONFIG_SYS_INTC_0_NUM)
- intc = (microblaze_intc_t *) (CONFIG_SYS_INTC_0_ADDR);
+ intc = (microblaze_intc_t *)CONFIG_SYS_INTC_0_ADDR;
irq_no = CONFIG_SYS_INTC_0_NUM;
#endif
if (irq_no) {
@@ -130,7 +126,7 @@ int interrupts_init(void)
/* initialize irq list */
for (i = 0; i < irq_no; i++) {
- vecs[i].handler = (interrupt_handler_t *) def_hdlr;
+ vecs[i].handler = (interrupt_handler_t *)def_hdlr;
vecs[i].arg = (void *)i;
vecs[i].count = 0;
}
@@ -147,31 +143,29 @@ void interrupt_handler(void)
{
int irqs = intc->ivr; /* find active interrupt */
int mask = 1;
-#ifdef DEBUG_INT
int value;
- printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
- intc->iar, intc->mer);
- R14(value);
- printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
-#endif
struct irq_action *act = vecs + irqs;
-#ifdef DEBUG_INT
- printf
- ("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
- act->handler, act->count, act->arg);
+ debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
+ intc->iar, intc->mer);
+#ifdef DEBUG
+ R14(value);
#endif
- act->handler (act->arg);
+ debug("Interrupt handler on %x line, r14 %x\n", irqs, value);
+
+ debug("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
+ (u32)act->handler, act->count, (u32)act->arg);
+ act->handler(act->arg);
act->count++;
intc->iar = mask << irqs;
-#ifdef DEBUG_INT
- printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
- intc->ier, intc->iar, intc->mer);
+ debug("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
+ intc->ier, intc->iar, intc->mer);
+#ifdef DEBUG
R14(value);
- printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
#endif
+ debug("Interrupt handler on %x line, r14 %x\n", irqs, value);
}
#if defined(CONFIG_CMD_IRQ)
@@ -186,10 +180,10 @@ int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, const char *argv[])
"-----------------------------\n");
for (i = 0; i < irq_no; i++) {
- if (act->handler != (interrupt_handler_t *) def_hdlr) {
+ if (act->handler != (interrupt_handler_t *)def_hdlr) {
printf("%02d %08x %08x %d\n", i,
- (int)act->handler, (int)act->arg,
- act->count);
+ (int)act->handler, (int)act->arg,
+ act->count);
}
act++;
}
diff --git a/arch/microblaze/cpu/irq.S b/arch/microblaze/cpu/irq.S
index 24015898b0..5cfe1516bf 100644
--- a/arch/microblaze/cpu/irq.S
+++ b/arch/microblaze/cpu/irq.S
@@ -11,71 +11,70 @@
.text
.global _interrupt_handler
_interrupt_handler:
- swi r2, r1, -4
- swi r3, r1, -8
- swi r4, r1, -12
- swi r5, r1, -16
- swi r6, r1, -20
- swi r7, r1, -24
- swi r8, r1, -28
- swi r9, r1, -32
- swi r10, r1, -36
- swi r11, r1, -40
- swi r12, r1, -44
- swi r13, r1, -48
- swi r14, r1, -52
- swi r15, r1, -56
- swi r16, r1, -60
- swi r17, r1, -64
- swi r18, r1, -68
- swi r19, r1, -72
- swi r20, r1, -76
- swi r21, r1, -80
- swi r22, r1, -84
- swi r23, r1, -88
- swi r24, r1, -92
- swi r25, r1, -96
- swi r26, r1, -100
- swi r27, r1, -104
- swi r28, r1, -108
- swi r29, r1, -112
- swi r30, r1, -116
- swi r31, r1, -120
addik r1, r1, -124
+ swi r2, r1, 4
+ swi r3, r1, 8
+ swi r4, r1, 12
+ swi r5, r1, 16
+ swi r6, r1, 20
+ swi r7, r1, 24
+ swi r8, r1, 28
+ swi r9, r1, 32
+ swi r10, r1, 36
+ swi r11, r1, 40
+ swi r12, r1, 44
+ swi r13, r1, 48
+ swi r14, r1, 52
+ swi r15, r1, 56
+ swi r16, r1, 60
+ swi r17, r1, 64
+ swi r18, r1, 68
+ swi r19, r1, 72
+ swi r20, r1, 76
+ swi r21, r1, 80
+ swi r22, r1, 84
+ swi r23, r1, 88
+ swi r24, r1, 92
+ swi r25, r1, 96
+ swi r26, r1, 100
+ swi r27, r1, 104
+ swi r28, r1, 108
+ swi r29, r1, 112
+ swi r30, r1, 116
+ swi r31, r1, 120
brlid r15, interrupt_handler
nop
+ lwi r31, r1, 120
+ lwi r30, r1, 116
+ lwi r29, r1, 112
+ lwi r28, r1, 108
+ lwi r27, r1, 104
+ lwi r26, r1, 100
+ lwi r25, r1, 96
+ lwi r24, r1, 92
+ lwi r23, r1, 88
+ lwi r22, r1, 84
+ lwi r21, r1, 80
+ lwi r20, r1, 76
+ lwi r19, r1, 72
+ lwi r18, r1, 68
+ lwi r17, r1, 64
+ lwi r16, r1, 60
+ lwi r15, r1, 56
+ lwi r14, r1, 52
+ lwi r13, r1, 48
+ lwi r12, r1, 44
+ lwi r11, r1, 40
+ lwi r10, r1, 36
+ lwi r9, r1, 32
+ lwi r8, r1, 28
+ lwi r7, r1, 24
+ lwi r6, r1, 20
+ lwi r5, r1, 16
+ lwi r4, r1, 12
+ lwi r3, r1, 8
+ lwi r2, r1, 4
addik r1, r1, 124
- lwi r31, r1, -120
- lwi r30, r1, -116
- lwi r29, r1, -112
- lwi r28, r1, -108
- lwi r27, r1, -104
- lwi r26, r1, -100
- lwi r25, r1, -96
- lwi r24, r1, -92
- lwi r23, r1, -88
- lwi r22, r1, -84
- lwi r21, r1, -80
- lwi r20, r1, -76
- lwi r19, r1, -72
- lwi r18, r1, -68
- lwi r17, r1, -64
- lwi r16, r1, -60
- lwi r15, r1, -56
- lwi r14, r1, -52
- lwi r13, r1, -48
- lwi r12, r1, -44
- lwi r11, r1, -40
- lwi r10, r1, -36
- lwi r9, r1, -32
- lwi r8, r1, -28
- lwi r7, r1, -24
- lwi r6, r1, -20
- lwi r5, r1, -16
- lwi r4, r1, -12
- lwi r3, r1, -8
- lwi r2, r1, -4
-
rtid r14, 0
nop
.size _interrupt_handler,.-_interrupt_handler
diff --git a/arch/microblaze/cpu/spl.c b/arch/microblaze/cpu/spl.c
index 091226133e..2cc0a2da89 100644
--- a/arch/microblaze/cpu/spl.c
+++ b/arch/microblaze/cpu/spl.c
@@ -25,8 +25,6 @@ u32 spl_boot_device(void)
/* Board initialization after bss clearance */
void spl_board_init(void)
{
- gd = (gd_t *)CONFIG_SPL_STACK_ADDR;
-
/* enable console uart printing */
preloader_console_init();
}
diff --git a/arch/microblaze/cpu/start.S b/arch/microblaze/cpu/start.S
index 84c29e5409..953d3a15ee 100644
--- a/arch/microblaze/cpu/start.S
+++ b/arch/microblaze/cpu/start.S
@@ -30,7 +30,11 @@ _start:
mts rshr, r1
addi r1, r1, -4 /* Decrement SP to top of memory */
#else
+#if defined(CONFIG_SYS_MALLOC_F_LEN)
+ addi r1, r0, CONFIG_SYS_INIT_SP_OFFSET - CONFIG_SYS_MALLOC_F_LEN
+#else
addi r1, r0, CONFIG_SYS_INIT_SP_OFFSET
+#endif
mts rshr, r1
addi r1, r1, -4 /* Decrement SP to top of memory */
@@ -129,7 +133,7 @@ _start:
/* Flush cache before enable cache */
addik r5, r0, 0
addik r6, r0, XILINX_DCACHE_BYTE_SIZE
-flush: bralid r15, flush_cache
+ bralid r15, flush_cache
nop
/* enable instruction and data cache */
@@ -150,12 +154,28 @@ clear_bss:
bnei r6, 2b
3: /* jumping to board_init */
#ifndef CONFIG_SPL_BUILD
+ or r5, r0, r0 /* flags - empty */
+ addi r31, r0, _gd
+#if defined(CONFIG_SYS_MALLOC_F_LEN)
+ addi r6, r0, CONFIG_SYS_INIT_SP_OFFSET
+ swi r6, r31, GD_MALLOC_BASE
+#endif
brai board_init_f
#else
+ addi r31, r0, _gd
+#if defined(CONFIG_SYS_MALLOC_F_LEN)
+ addi r6, r0, CONFIG_SPL_STACK_ADDR
+ swi r6, r31, GD_MALLOC_BASE
+#endif
brai board_init_r
#endif
1: bri 1b
+ .section .bss
+.align 4
+_gd:
+ .space GENERATED_GBL_DATA_SIZE
+
#ifndef CONFIG_SPL_BUILD
/*
* Read 16bit little endian
@@ -189,4 +209,108 @@ out16: bslli r3, r6, 8
rtsd r15, 8
or r0, r0, r0
.end out16
+
+/*
+ * Relocate u-boot
+ */
+ .text
+ .global relocate_code
+ .ent relocate_code
+ .align 2
+relocate_code:
+ /*
+ * r5 - start_addr_sp
+ * r6 - new_gd
+ * r7 - reloc_addr
+ */
+ addi r1, r5, 0 /* Start to use new SP */
+ addi r31, r6, 0 /* Start to use new GD */
+
+ add r23, r0, r7 /* Move reloc addr to r23 */
+ /* Relocate text and data - r12 temp value */
+ addi r21, r0, _start
+ addi r22, r0, __end - 4 /* Include BSS too */
+
+ rsub r6, r21, r22
+ or r5, r0, r0
+1: lw r12, r21, r5 /* Load u-boot data */
+ sw r12, r23, r5 /* Write zero to loc */
+ cmp r12, r5, r6 /* Check if we have reach the end */
+ bneid r12, 1b
+ addi r5, r5, 4 /* Increment to next loc - relocate code */
+
+ /* R23 points to the base address. */
+ add r23, r0, r7 /* Move reloc addr to r23 */
+ addi r24, r0, CONFIG_SYS_TEXT_BASE /* Get reloc offset */
+ rsub r23, r24, r23 /* keep - this is already here gd->reloc_off */
+
+ addik r6, r0, 0x2 /* BIG/LITTLE endian offset */
+ lwi r7, r0, 0x28
+ swi r6, r0, 0x28 /* used first unused MB vector */
+ lbui r10, r0, 0x28 /* used first unused MB vector */
+ swi r7, r0, 0x28
+
+#ifdef CONFIG_SYS_USR_EXCEP
+ addik r6, r0, _exception_handler
+ addk r6, r6, r23 /* add offset */
+ sw r6, r1, r0
+ lhu r7, r1, r10
+ rsubi r8, r10, 0xa
+ sh r7, r0, r8
+ rsubi r8, r10, 0xe
+ sh r6, r0, r8
+#endif
+ addik r6, r0, _hw_exception_handler
+ addk r6, r6, r23 /* add offset */
+ sw r6, r1, r0
+ lhu r7, r1, r10
+ rsubi r8, r10, 0x22
+ sh r7, r0, r8
+ rsubi r8, r10, 0x26
+ sh r6, r0, r8
+
+ addik r6, r0, _interrupt_handler
+ addk r6, r6, r23 /* add offset */
+ sw r6, r1, r0
+ lhu r7, r1, r10
+ rsubi r8, r10, 0x12
+ sh r7, r0, r8
+ rsubi r8, r10, 0x16
+ sh r6, r0, r8
+
+ /* Check if GOT exist */
+ addik r21, r23, _got_start
+ addik r22, r23, _got_end
+ cmpu r12, r21, r22
+ beqi r12, 2f /* No GOT table - jump over */
+
+ /* Skip last 3 entries plus 1 because of loop boundary below */
+ addik r22, r22, -0x10
+
+ /* Relocate the GOT. */
+3: lw r12, r21, r0 /* Load entry */
+ addk r12, r12, r23 /* Add reloc offset */
+ sw r12, r21, r0 /* Save entry back */
+
+ cmpu r12, r21, r22 /* Check if this cross boundary */
+ bneid r12, 3b
+ addik r21. r21, 4
+
+ /* Update pointer to GOT */
+ mfs r20, rpc
+ addik r20, r20, _GLOBAL_OFFSET_TABLE_ + 8
+ addk r20, r20, r23
+
+ /* Flush caches to ensure consistency */
+ addik r5, r0, 0
+ addik r6, r0, XILINX_DCACHE_BYTE_SIZE
+ bralid r15, flush_cache
+ nop
+
+2: addi r5, r31, 0 /* gd is initialized in board_r.c */
+ addi r6, r0, CONFIG_SYS_TEXT_BASE
+ addi r12, r23, board_init_r
+ bra r12 /* Jump to relocated code */
+
+ .end relocate_code
#endif
diff --git a/arch/microblaze/cpu/u-boot-spl.lds b/arch/microblaze/cpu/u-boot-spl.lds
index 96353cd96c..c60336ca5c 100644
--- a/arch/microblaze/cpu/u-boot-spl.lds
+++ b/arch/microblaze/cpu/u-boot-spl.lds
@@ -37,6 +37,12 @@ SECTIONS
__data_end = .;
}
+ . = ALIGN(4);
+ .u_boot_list : {
+ KEEP(*(SORT(.u_boot_list*)));
+ }
+ __init_end = . ;
+
.bss ALIGN(0x4):
{
__bss_start = .;
diff --git a/arch/microblaze/cpu/u-boot.lds b/arch/microblaze/cpu/u-boot.lds
index fdad20753d..2502a0db2b 100644
--- a/arch/microblaze/cpu/u-boot.lds
+++ b/arch/microblaze/cpu/u-boot.lds
@@ -29,17 +29,23 @@ SECTIONS
.data ALIGN(0x4):
{
__data_start = .;
-#ifdef CONFIG_OF_EMBED
- dts/built-in.o (.data)
-#endif
*(.data)
__data_end = .;
}
+ .got ALIGN(4):
+ {
+ _got_start = .;
+ *(.got*)
+ . = ALIGN(4);
+ _got_end = .;
+ }
+
. = ALIGN(4);
.u_boot_list : {
KEEP(*(SORT(.u_boot_list*)));
}
+ __init_end = . ;
.bss ALIGN(0x4):
{