1 // Copyright 2008-2009 Segher Boessenkool <segher@kernel.crashing.org>
2 // This code is licensed to you under the terms of the GNU GPL, version 2;
3 // see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
13 size_t strlen(const char *);
14 size_t strnlen(const char *, size_t);
15 void *memset(void *, int, size_t);
16 void *memcpy(void *, const void *, size_t);
17 int memcmp(const void *, const void *, size_t);
22 typedef unsigned char u8;
23 typedef unsigned short int u16;
24 typedef unsigned int u32;
25 typedef unsigned long long int u64;
27 static inline u16 le16(const u8 *p)
29 return p[0] | (p[1] << 8);
32 static inline u32 le32(const u8 *p)
34 return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
40 static inline u32 read32(u32 addr)
44 asm volatile("lwz %0,0(%1) ; sync" : "=r"(x) : "b"(0xc0000000 | addr));
49 static inline void write32(u32 addr, u32 x)
51 asm("stw %0,0(%1) ; eieio" : : "r"(x), "b"(0xc0000000 | addr));
54 static inline u16 read16(u32 addr)
58 asm volatile("lhz %0,0(%1) ; sync" : "=r"(x) : "b"(0xc0000000 | addr));
63 static inline void write16(u32 addr, u16 x)
65 asm("sth %0,0(%1) ; eieio" : : "r"(x), "b"(0xc0000000 | addr));
71 static inline u32 virt_to_phys(const void *p)
73 return (u32)p & 0x7fffffff;
76 static inline void *phys_to_virt(u32 x)
78 return (void *)(x | 0x80000000);
82 // Cache synchronisation.
84 void sync_before_read(void *p, u32 len);
85 void sync_after_write(const void *p, u32 len);
86 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 usbgecko_init(void);
110 int usbgecko_checkgecko(void);
111 void usbgecko_console_putc(u8 c);
113 u8 usbgecko_flash_read8(u32 offset);
114 u32 usbgecko_flash_read32(u32 offset);
119 extern const char version[];
124 void video_init(void);
130 void console_init(void);
131 int printf(const char *fmt, ...);
137 int sd_read_sector(u8 *data, u32 offset);
144 int fat_open(const char *name);
145 int fat_read(void *data, u32 len);
150 int valid_elf_image(void *addr);
151 void *load_elf_image(void *addr);
161 int ios_open(const char *filename, u32 mode);
162 int ios_close(int fd);
163 int ios_read(int fd, void *data, u32 len);
164 int ios_write(int fd, const void *data, u32 len);
165 int ios_seek(int fd, int where, int whence);
166 int ios_ioctl(int fd, u32 n, const void *in, u32 inlen, void *out, u32 outlen);
167 int ios_ioctlv(int fd, u32 n, u32 in_count, u32 out_count, struct ioctlv *vec);
169 void reset_ios(void);