2 BootMii - a Free Software replacement for the Nintendo/BroadOn bootloader.
5 Copyright (C) 2008 Segher Boessenkool <segher@kernel.crashing.org>
7 # This code is licensed to you under the terms of the GNU GPL, version 2;
8 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
20 #define MEM2_BSS __attribute__ ((section (".bss.mem2")))
21 #define MEM2_DATA __attribute__ ((section (".data.mem2")))
22 #define MEM2_RODATA __attribute__ ((section (".rodata.mem2")))
23 #define ALIGNED(x) __attribute__((aligned(x)))
25 #define STACK_ALIGN(type, name, cnt, alignment) \
26 u8 _al__##name[((sizeof(type)*(cnt)) + (alignment) + \
27 (((sizeof(type)*(cnt))%(alignment)) > 0 ? ((alignment) - \
28 ((sizeof(type)*(cnt))%(alignment))) : 0))]; \
29 type *name = (type*)(((u32)(_al__##name)) + ((alignment) - (( \
30 (u32)(_al__##name))&((alignment)-1))))
34 static inline u32 read32(u32 addr)
38 asm volatile("lwz %0,0(%1) ; sync" : "=r"(x) : "b"(0xc0000000 | addr));
43 static inline void write32(u32 addr, u32 x)
45 asm("stw %0,0(%1) ; eieio" : : "r"(x), "b"(0xc0000000 | addr));
48 static inline void mask32(u32 addr, u32 clear, u32 set)
50 write32(addr, (read32(addr)&(~clear)) | set);
53 static inline u16 read16(u32 addr)
57 asm volatile("lhz %0,0(%1) ; sync" : "=r"(x) : "b"(0xc0000000 | addr));
62 static inline void write16(u32 addr, u16 x)
64 asm("sth %0,0(%1) ; eieio" : : "r"(x), "b"(0xc0000000 | addr));
70 static inline u32 virt_to_phys(const void *p)
72 return (u32)p & 0x7fffffff;
75 static inline void *phys_to_virt(u32 x)
77 return (void *)(x | 0x80000000);
81 // Cache synchronisation.
83 void sync_before_read(void *p, u32 len);
84 void sync_after_write(const void *p, u32 len);
85 void sync_before_exec(const void *p, u32 len);
94 // Special purpose registers.
96 #define mtspr(n, x) do { asm("mtspr %1,%0" : : "r"(x), "i"(n)); } while (0)
98 u32 x; asm volatile("mfspr %0,%1" : "=r"(x) : "i"(n)); x; \
104 void exception_init(void);
109 void gecko_init(void);
110 int printf(const char *fmt, ...);
113 // Debug: blink the tray led.
115 static inline void blink(void)
117 write32(0x0d8000c0, read32(0x0d8000c0) ^ 0x20);