nios2: convert copy_exception_trampoline to use dm cpu data

Convert copy_exception_trampoline() to use dm cpu data.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
diff --git a/arch/nios2/cpu/cpu.c b/arch/nios2/cpu/cpu.c
index e4217c8..ff0fa20 100644
--- a/arch/nios2/cpu/cpu.c
+++ b/arch/nios2/cpu/cpu.c
@@ -29,6 +29,27 @@
 	return 0;
 }
 
+/*
+ * COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
+ * exception address. Define CONFIG_ROM_STUBS to prevent
+ * the copy (e.g. exception in flash or in other
+ * softare/firmware component).
+ */
+#ifndef CONFIG_ROM_STUBS
+static void copy_exception_trampoline(void)
+{
+	extern int _except_start, _except_end;
+	void *except_target = (void *)gd->arch.exception_addr;
+
+	if (&_except_start != except_target) {
+		memcpy(except_target, &_except_start,
+		       &_except_end - &_except_start);
+		flush_cache(gd->arch.exception_addr,
+			    &_except_end - &_except_start);
+	}
+}
+#endif
+
 int arch_cpu_init_dm(void)
 {
 	struct udevice *dev;
@@ -41,6 +62,9 @@
 		return -ENODEV;
 
 	gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
+#ifndef CONFIG_ROM_STUBS
+	copy_exception_trampoline();
+#endif
 
 	return 0;
 }