1 | /* |
---|
2 | * bootldr.h -- Include file for bootloader. |
---|
3 | * |
---|
4 | * Copyright (C) 1998, 1999 Gabriel Paubert, paubert@iram.es |
---|
5 | * |
---|
6 | * Modified to compile in RTEMS development environment |
---|
7 | * by Eric Valette |
---|
8 | * |
---|
9 | * Copyright (C) 1999 Eric Valette. valette@crf.canon.fr |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in found in the file LICENSE in this distribution or at |
---|
13 | * http://www.OARcorp.com/rtems/license.html. |
---|
14 | * |
---|
15 | * $Id$ |
---|
16 | */ |
---|
17 | |
---|
18 | #ifndef _PPC_BOOTLDR_H |
---|
19 | #define _PPC_BOOTLDR_H |
---|
20 | |
---|
21 | #ifndef ASM |
---|
22 | #include <bsp/residual.h> |
---|
23 | #include <bsp/consoleIo.h> |
---|
24 | #include "pci.h" |
---|
25 | |
---|
26 | #define abs __builtin_abs |
---|
27 | |
---|
28 | #define PTE_REFD 0x100 |
---|
29 | #define PTE_CHNG (0x80|PTE_REFD) /* Modified implies referenced */ |
---|
30 | #define PTE_WTHR 0x040 |
---|
31 | #define PTE_CINH 0x020 |
---|
32 | #define PTE_COHER 0x010 |
---|
33 | #define PTE_GUAR 0x008 |
---|
34 | #define PTE_RO 0x003 |
---|
35 | #define PTE_RW 0x002 |
---|
36 | |
---|
37 | #define PTE_RAM (PTE_CHNG|PTE_COHER|PTE_RW) |
---|
38 | #define PTE_ROM (PTE_REFD|PTE_RO) |
---|
39 | #define PTE_IO (PTE_CHNG|PTE_CINH|PTE_GUAR|PTE_RW) |
---|
40 | |
---|
41 | typedef struct {}opaque; |
---|
42 | |
---|
43 | /* The context passed during MMU interrupts. */ |
---|
44 | typedef struct _ctxt { |
---|
45 | u_long lr, ctr; |
---|
46 | u_int cr, xer; |
---|
47 | u_long nip, msr; |
---|
48 | u_long regs[32]; |
---|
49 | } ctxt; |
---|
50 | |
---|
51 | /* The main structure which is pointed to permanently by r13. Things |
---|
52 | * are not separated very well between parts because it would cause |
---|
53 | * too much code bloat for such a simple program like the bootloader. |
---|
54 | * The code is designed to be compiled with the -m relocatable option and |
---|
55 | * tries to minimize the number of relocations/fixups and the number of |
---|
56 | * functions who have to access the .got2 sections (this increases the |
---|
57 | * size of the prologue in every function). |
---|
58 | */ |
---|
59 | typedef struct _boot_data { |
---|
60 | RESIDUAL *residual; |
---|
61 | void *load_address; |
---|
62 | void *of_entry; |
---|
63 | void *r6, *r7, *r8, *r9, *r10; |
---|
64 | u_long cache_lsize; |
---|
65 | void *image; /* Where to copy ourselves */ |
---|
66 | void *stack; |
---|
67 | void *mover; /* where to copy codemove to avoid overlays */ |
---|
68 | u_long o_msr, o_hid0, o_r31; |
---|
69 | opaque * mm_private; |
---|
70 | const struct pci_config_access_functions * pci_functions; |
---|
71 | opaque * pci_private; |
---|
72 | struct pci_dev * pci_devices; |
---|
73 | opaque * v86_private; |
---|
74 | char cmd_line[256]; |
---|
75 | } boot_data; |
---|
76 | |
---|
77 | register boot_data *bd __asm__("r13"); |
---|
78 | |
---|
79 | extern inline int |
---|
80 | pcibios_read_config_byte(u_char bus, u_char dev_fn, |
---|
81 | u_char where, u_char * val) { |
---|
82 | return bd->pci_functions->read_config_byte(bus, dev_fn, where, val); |
---|
83 | } |
---|
84 | |
---|
85 | extern inline int |
---|
86 | pcibios_read_config_word(u_char bus, u_char dev_fn, |
---|
87 | u_char where, u_short * val) { |
---|
88 | return bd->pci_functions->read_config_word(bus, dev_fn, where, val); |
---|
89 | } |
---|
90 | |
---|
91 | extern inline int |
---|
92 | pcibios_read_config_dword(u_char bus, u_char dev_fn, |
---|
93 | u_char where, u_int * val) { |
---|
94 | return bd->pci_functions->read_config_dword(bus, dev_fn, where, val); |
---|
95 | } |
---|
96 | |
---|
97 | extern inline int |
---|
98 | pcibios_write_config_byte(u_char bus, u_char dev_fn, |
---|
99 | u_char where, u_char val) { |
---|
100 | return bd->pci_functions->write_config_byte(bus, dev_fn, where, val); |
---|
101 | } |
---|
102 | |
---|
103 | extern inline int |
---|
104 | pcibios_write_config_word(u_char bus, u_char dev_fn, |
---|
105 | u_char where, u_short val) { |
---|
106 | return bd->pci_functions->write_config_word(bus, dev_fn, where, val); |
---|
107 | } |
---|
108 | |
---|
109 | extern inline int |
---|
110 | pcibios_write_config_dword(u_char bus, u_char dev_fn, |
---|
111 | u_char where, u_int val) { |
---|
112 | return bd->pci_functions->write_config_dword(bus, dev_fn, where, val); |
---|
113 | } |
---|
114 | |
---|
115 | extern inline int |
---|
116 | pci_read_config_byte(struct pci_dev *dev, u_char where, u_char * val) { |
---|
117 | return bd->pci_functions->read_config_byte(dev->bus->number, |
---|
118 | dev->devfn, |
---|
119 | where, val); |
---|
120 | } |
---|
121 | |
---|
122 | extern inline int |
---|
123 | pci_read_config_word(struct pci_dev *dev, u_char where, u_short * val) { |
---|
124 | return bd->pci_functions->read_config_word(dev->bus->number, |
---|
125 | dev->devfn, |
---|
126 | where, val); |
---|
127 | } |
---|
128 | |
---|
129 | extern inline int |
---|
130 | pci_read_config_dword(struct pci_dev *dev, u_char where, u_int * val) { |
---|
131 | return bd->pci_functions->read_config_dword(dev->bus->number, |
---|
132 | dev->devfn, |
---|
133 | where, val); |
---|
134 | } |
---|
135 | |
---|
136 | extern inline int |
---|
137 | pci_write_config_byte(struct pci_dev *dev, u_char where, u_char val) { |
---|
138 | return bd->pci_functions->write_config_byte(dev->bus->number, |
---|
139 | dev->devfn, |
---|
140 | where, val); |
---|
141 | } |
---|
142 | |
---|
143 | extern inline int |
---|
144 | pci_write_config_word(struct pci_dev *dev, u_char where, u_short val) { |
---|
145 | return bd->pci_functions->write_config_word(dev->bus->number, |
---|
146 | dev->devfn, |
---|
147 | where, val); |
---|
148 | } |
---|
149 | |
---|
150 | extern inline int |
---|
151 | pci_write_config_dword(struct pci_dev *dev, u_char where, u_int val) { |
---|
152 | return bd->pci_functions->write_config_dword(dev->bus->number, |
---|
153 | dev->devfn, |
---|
154 | where, val); |
---|
155 | } |
---|
156 | |
---|
157 | /* codemove is like memmove, but it also gets the cache line size |
---|
158 | * as 4th parameter to synchronize them. If this last parameter is |
---|
159 | * zero, it performs more or less like memmove. No copy is performed if |
---|
160 | * source and destination addresses are equal. However the caches |
---|
161 | * are synchronized. Note that the size is always rounded up to the |
---|
162 | * next mutiple of 4. |
---|
163 | */ |
---|
164 | extern void * codemove(void *, const void *, size_t, unsigned long); |
---|
165 | |
---|
166 | /* The physical memory allocator allows to align memory by |
---|
167 | * powers of 2 given by the lower order bits of flags. |
---|
168 | * By default it allocates from higher addresses towrds lower ones, |
---|
169 | * setting PA_LOW reverses this behaviour. |
---|
170 | */ |
---|
171 | |
---|
172 | #define palloc(size) __palloc(size,0) |
---|
173 | |
---|
174 | #define isa_io_base (bd->io_base) |
---|
175 | |
---|
176 | |
---|
177 | void * __palloc(u_long, int); |
---|
178 | void pfree(void *); |
---|
179 | |
---|
180 | #define PA_LOW 0x100 |
---|
181 | #define PA_PERM 0x200 /* Not freeable by pfree */ |
---|
182 | #define PA_SUBALLOC 0x400 /* Allocate for suballocation by salloc */ |
---|
183 | #define PA_ALIGN_MASK 0x1f |
---|
184 | |
---|
185 | void * valloc(u_long size); |
---|
186 | void vfree(void *); |
---|
187 | |
---|
188 | int vmap(void *, u_long, u_long); |
---|
189 | void vunmap(void *); |
---|
190 | |
---|
191 | void * salloc(u_long size); |
---|
192 | void sfree(void *); |
---|
193 | |
---|
194 | void pci_init(void); |
---|
195 | |
---|
196 | void * memset(void *p, int c, size_t n); |
---|
197 | |
---|
198 | void gunzip(void *, int, unsigned char *, int *); |
---|
199 | |
---|
200 | void print_all_maps(const char *); |
---|
201 | void print_hash_table(void); |
---|
202 | void MMUon(void); |
---|
203 | void MMUoff(void); |
---|
204 | void hang(const char *, u_long, ctxt *) __attribute__((noreturn)); |
---|
205 | |
---|
206 | int init_v86(void); |
---|
207 | void cleanup_v86_mess(void); |
---|
208 | void em86_main(struct pci_dev *); |
---|
209 | int find_max_mem(struct pci_dev *); |
---|
210 | |
---|
211 | #endif |
---|
212 | |
---|
213 | #ifdef ASM |
---|
214 | /* These definitions simplify the ugly declarations necessary for |
---|
215 | * GOT definitions. |
---|
216 | */ |
---|
217 | |
---|
218 | #define GOT_ENTRY(NAME) .L_ ## NAME = . - .LCTOC1 ; .long NAME |
---|
219 | #define GOT(NAME) .L_ ## NAME (r30) |
---|
220 | |
---|
221 | #define START_GOT \ |
---|
222 | .section ".got2","aw"; \ |
---|
223 | .LCTOC1 = .+ 0x8000 |
---|
224 | |
---|
225 | #define END_GOT \ |
---|
226 | .text |
---|
227 | |
---|
228 | #define GET_GOT \ |
---|
229 | bl 1f; \ |
---|
230 | .text 2; \ |
---|
231 | 0: .long .LCTOC1-1f; \ |
---|
232 | .text ; \ |
---|
233 | 1: mflr r30; \ |
---|
234 | lwz r0,0b-1b(r30); \ |
---|
235 | add r30,r0,r30 |
---|
236 | |
---|
237 | #define bd r13 |
---|
238 | #define cache_lsize 32 /* Offset into bd area */ |
---|
239 | #define image 36 |
---|
240 | #define stack 40 |
---|
241 | #define mover 44 |
---|
242 | #define o_msr 48 |
---|
243 | #define o_hid0 52 |
---|
244 | #define o_r31 56 |
---|
245 | /* Stack offsets for saved registers on exceptions */ |
---|
246 | #define save_lr 8(r1) |
---|
247 | #define save_ctr 12(r1) |
---|
248 | #define save_cr 16(r1) |
---|
249 | #define save_xer 20(r1) |
---|
250 | #define save_nip 24(r1) |
---|
251 | #define save_msr 28(r1) |
---|
252 | #define save_r(n) 32+4*n(r1) |
---|
253 | #endif |
---|
254 | |
---|
255 | #endif |
---|
256 | |
---|
257 | |
---|
258 | |
---|