lsw: JPN fix
[savezelda.git] / loader / loader.h
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
4
5 #ifndef _LOADER_H
6 #define _LOADER_H
7
8 #include <stddef.h>
9
10
11 // String functions.
12
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);
18
19
20 // Basic types.
21
22 typedef unsigned char u8;
23 typedef unsigned short int u16;
24 typedef unsigned int u32;
25 typedef unsigned long long int u64;
26
27 static inline u16 le16(const u8 *p)
28 {
29         return p[0] | (p[1] << 8);
30 }
31
32 static inline u32 le32(const u8 *p)
33 {
34         return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
35 }
36
37
38 // Basic I/O.
39
40 static inline u32 read32(u32 addr)
41 {
42         u32 x;
43
44         asm volatile("lwz %0,0(%1) ; sync" : "=r"(x) : "b"(0xc0000000 | addr));
45
46         return x;
47 }
48
49 static inline void write32(u32 addr, u32 x)
50 {
51         asm("stw %0,0(%1) ; eieio" : : "r"(x), "b"(0xc0000000 | addr));
52 }
53
54 static inline u16 read16(u32 addr)
55 {
56         u16 x;
57
58         asm volatile("lhz %0,0(%1) ; sync" : "=r"(x) : "b"(0xc0000000 | addr));
59
60         return x;
61 }
62
63 static inline void write16(u32 addr, u16 x)
64 {
65         asm("sth %0,0(%1) ; eieio" : : "r"(x), "b"(0xc0000000 | addr));
66 }
67
68
69 // Address mapping.
70
71 static inline u32 virt_to_phys(const void *p)
72 {
73         return (u32)p & 0x7fffffff;
74 }
75
76 static inline void *phys_to_virt(u32 x)
77 {
78         return (void *)(x | 0x80000000);
79 }
80
81
82 // Cache synchronisation.
83
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);
87
88
89 // Time.
90
91 void udelay(u32 us);
92
93
94 // Special purpose registers.
95
96 #define mtspr(n, x) do { asm("mtspr %1,%0" : : "r"(x), "i"(n)); } while (0)
97 #define mfspr(n) ({ \
98         u32 x; asm volatile("mfspr %0,%1" : "=r"(x) : "i"(n)); x; \
99 })
100
101
102 // Exceptions.
103
104 void exception_init(void);
105
106
107 // USB Gecko.
108
109 void usbgecko_init(void);
110 int usbgecko_checkgecko(void);
111 void usbgecko_console_putc(u8 c);
112
113 u8 usbgecko_flash_read8(u32 offset);
114 u32 usbgecko_flash_read32(u32 offset);
115
116
117 // Version string.
118
119 extern const char version[];
120
121
122 // Video.
123
124 void video_init(void);
125 void fb_putc(char);
126
127
128 // Console.
129
130 void console_init(void);
131 int printf(const char *fmt, ...);
132
133
134 // SD card.
135
136 int sd_init(void);
137 int sd_read_sector(u8 *data, u32 offset);
138 int sd_close(void);
139
140
141 // FAT.
142
143 int fat_init(void);
144 int fat_open(const char *name);
145 int fat_read(void *data, u32 len);
146
147
148 // ELF.
149
150 int valid_elf_image(void *addr);
151 void *load_elf_image(void *addr);
152
153
154 // IOS.
155
156 struct ioctlv {
157         void *data;
158         u32 len;
159 };
160
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);
168
169 void reset_ios(void);
170
171 #endif