]>
git.ipfire.org Git - people/ms/u-boot.git/blob - tools/updater/utils.c
2 #include <asm/processor.h>
4 #include <linux/ctype.h>
6 static __inline__
unsigned long
11 asm volatile("mfmsr %0" : "=r" (msr
) :);
15 static __inline__
void
16 set_msr(unsigned long msr
)
18 asm volatile("mtmsr %0" : : "r" (msr
));
21 static __inline__
unsigned long
26 asm volatile("mfdec %0" : "=r" (val
) :);
31 static __inline__
void
32 set_dec(unsigned long val
)
34 asm volatile("mtdec %0" : : "r" (val
));
39 enable_interrupts(void)
41 set_msr (get_msr() | MSR_EE
);
44 /* returns flag if MSR_EE was set before */
46 disable_interrupts(void)
51 set_msr (msr
& ~MSR_EE
);
52 return ((msr
& MSR_EE
) != 0);
60 void out8(u32 port
, u8 val
)
65 unsigned long in32(u32 port
)
70 unsigned long simple_strtoul(const char *cp
,char **endp
,unsigned int base
)
72 unsigned long result
= 0,value
;
76 if ((*cp
== 'x') && isxdigit(cp
[1])) {
87 while (isxdigit(*cp
) && (value
= isdigit(*cp
) ? *cp
-'0' : (islower(*cp
)
88 ? toupper(*cp
) : *cp
)-'A'+10) < base
) {
89 result
= result
*base
+ value
;
97 long simple_strtol(const char *cp
,char **endp
,unsigned int base
)
100 return -simple_strtoul(cp
+1,endp
,base
);
101 return simple_strtoul(cp
,endp
,base
);
105 soft_restart(unsigned long addr
)
107 /* SRR0 has system reset vector, SRR1 has default MSR value */
108 /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */
110 __asm__
__volatile__ ("mtspr 26, %0" :: "r" (addr
));
111 __asm__
__volatile__ ("li 4, (1 << 6)" ::: "r4");
112 __asm__
__volatile__ ("mtspr 27, 4");
113 __asm__
__volatile__ ("rfi");
115 while(1); /* not reached */
122 /* flush and disable I/D cache */
123 __asm__
__volatile__ ("mfspr 3, 1008" ::: "r3");
124 __asm__
__volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
125 __asm__
__volatile__ ("ori 4, 3, 0xc00" ::: "r4");
126 __asm__
__volatile__ ("andc 5, 3, 5" ::: "r5");
127 __asm__
__volatile__ ("sync");
128 __asm__
__volatile__ ("mtspr 1008, 4");
129 __asm__
__volatile__ ("isync");
130 __asm__
__volatile__ ("sync");
131 __asm__
__volatile__ ("mtspr 1008, 5");
132 __asm__
__volatile__ ("isync");
133 __asm__
__volatile__ ("sync");
135 #ifdef CONFIG_SYS_RESET_ADDRESS
136 addr
= CONFIG_SYS_RESET_ADDRESS
;
139 * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address,
140 * CONFIG_SYS_MONITOR_BASE - sizeof (ulong) is usually a valid
141 * address. Better pick an address known to be invalid on your
142 * system and assign it to CONFIG_SYS_RESET_ADDRESS.
144 addr
= CONFIG_SYS_MONITOR_BASE
- sizeof (ulong
);
147 while(1); /* not reached */