Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:54

0001 /*
0002  *  bootldr.h -- Include file for bootloader.
0003  */
0004 
0005 /*
0006  *  Copyright (C) 1998, 1999 Gabriel Paubert, paubert@iram.es
0007  *
0008  *  Modified to compile in RTEMS development environment
0009  *  by Eric Valette
0010  *
0011  *  Copyright (C) 1999 Eric Valette. valette@crf.canon.fr
0012  *
0013  *  The license and distribution terms for this file may be
0014  *  found in the file LICENSE in this distribution or at
0015  *  http://www.rtems.org/license/LICENSE.
0016  */
0017 
0018 #ifndef _PPC_BOOTLDR_H
0019 #define _PPC_BOOTLDR_H
0020 
0021 #ifndef ASM
0022 #include <stdint.h>
0023 #include <bsp/residual.h>
0024 #include <bsp/consoleIo.h>
0025 #include "pci.h"
0026 
0027 #define abs __builtin_abs
0028 
0029 #define PTE_REFD 0x100
0030 #define PTE_CHNG (0x80|PTE_REFD)    /* Modified implies referenced */
0031 #define PTE_WTHR 0x040
0032 #define PTE_CINH 0x020
0033 #define PTE_COHER 0x010
0034 #define PTE_GUAR 0x008
0035 #define PTE_RO   0x003
0036 #define PTE_RW   0x002
0037 
0038 #define PTE_RAM (PTE_CHNG|PTE_COHER|PTE_RW)
0039 #define PTE_ROM (PTE_REFD|PTE_RO)
0040 #define PTE_IO  (PTE_CHNG|PTE_CINH|PTE_GUAR|PTE_RW)
0041 
0042 typedef struct {}opaque;
0043 
0044 /* The context passed during MMU interrupts. */
0045 typedef struct _ctxt {
0046     u_long lr, ctr;
0047     u_int cr, xer;
0048     u_long nip, msr;
0049     u_long regs[32];
0050 } ctxt;
0051 
0052 /* The main structure which is pointed to permanently by r13. Things
0053  * are not separated very well between parts because it would cause
0054  * too much code bloat for such a simple program like the bootloader.
0055  * The code is designed to be compiled with the -m relocatable option and
0056  * tries to minimize the number of relocations/fixups and the number of
0057  * functions who have to access the .got2 sections (this increases the
0058  * size of the prologue in every function).
0059  */
0060 typedef struct _boot_data {
0061     RESIDUAL *residual;
0062     void *load_address;
0063         void *of_entry;
0064     void *r6, *r7, *r8, *r9, *r10;
0065     u_long cache_lsize;
0066     void *image;  /* Where to copy ourselves */
0067     void *stack;
0068     void *mover;  /* where to copy codemove to avoid overlays */
0069     u_long o_msr, o_hid0, o_r31;
0070     opaque * mm_private;
0071     const struct pci_bootloader_config_access_functions* pci_functions;
0072     opaque * pci_private;
0073     struct pci_dev * pci_devices;
0074     opaque * v86_private;
0075     char cmd_line[256];
0076 } boot_data;
0077 
0078 register boot_data *bd __asm__("r13");
0079 
0080 static inline int
0081 pcibios_read_config_byte(u_char bus, u_char dev_fn,
0082              u_char where, uint8_t *val) {
0083     return bd->pci_functions->read_config_byte(bus, dev_fn, where, val);
0084 }
0085 
0086 static inline int
0087 pcibios_read_config_word(u_char bus, u_char dev_fn,
0088              u_char where, uint16_t *val) {
0089     return bd->pci_functions->read_config_word(bus, dev_fn, where, val);
0090 }
0091 
0092 static inline int
0093 pcibios_read_config_dword(u_char bus, u_char dev_fn,
0094              u_char where, uint32_t *val) {
0095     return bd->pci_functions->read_config_dword(bus, dev_fn, where, val);
0096 }
0097 
0098 static inline int
0099 pcibios_write_config_byte(u_char bus, u_char dev_fn,
0100              u_char where, uint8_t val) {
0101     return bd->pci_functions->write_config_byte(bus, dev_fn, where, val);
0102 }
0103 
0104 static inline int
0105 pcibios_write_config_word(u_char bus, u_char dev_fn,
0106              u_char where, uint16_t val) {
0107     return bd->pci_functions->write_config_word(bus, dev_fn, where, val);
0108 }
0109 
0110 static inline int
0111 pcibios_write_config_dword(u_char bus, u_char dev_fn,
0112              u_char where, uint32_t val) {
0113     return bd->pci_functions->write_config_dword(bus, dev_fn, where, val);
0114 }
0115 
0116 static inline int
0117 pci_bootloader_read_config_byte(struct pci_dev *dev, u_char where, uint8_t *val) {
0118     return bd->pci_functions->read_config_byte(dev->bus->number,
0119                            dev->devfn,
0120                            where, val);
0121 }
0122 
0123 static inline int
0124 pci_bootloader_read_config_word(struct pci_dev *dev, u_char where, uint16_t *val) {
0125     return bd->pci_functions->read_config_word(dev->bus->number,
0126                            dev->devfn,
0127                            where, val);
0128 }
0129 
0130 static inline int
0131 pci_bootloader_read_config_dword(struct pci_dev *dev, u_char where, uint32_t *val) {
0132     return bd->pci_functions->read_config_dword(dev->bus->number,
0133                             dev->devfn,
0134                             where, val);
0135 }
0136 
0137 static inline int
0138 pci_bootloader_write_config_byte(struct pci_dev *dev, u_char where, uint8_t val) {
0139     return bd->pci_functions->write_config_byte(dev->bus->number,
0140                             dev->devfn,
0141                             where, val);
0142 }
0143 
0144 static inline int
0145 pci_bootloader_write_config_word(struct pci_dev *dev, u_char where, uint16_t val) {
0146     return bd->pci_functions->write_config_word(dev->bus->number,
0147                             dev->devfn,
0148                             where, val);
0149 }
0150 
0151 static inline int
0152 pci_bootloader_write_config_dword(struct pci_dev *dev, u_char where, uint32_t val) {
0153     return bd->pci_functions->write_config_dword(dev->bus->number,
0154                              dev->devfn,
0155                              where, val);
0156 }
0157 
0158 /* codemove is like memmove, but it also gets the cache line size
0159  * as 4th parameter to synchronize them. If this last parameter is
0160  * zero, it performs more or less like memmove. No copy is performed if
0161  * source and destination addresses are equal. However the caches
0162  * are synchronized. Note that the size is always rounded up to the
0163  * next mutiple of 4.
0164  */
0165 extern void * codemove(void *, const void *, size_t, unsigned long);
0166 
0167 /* The physical memory allocator allows to align memory by
0168  * powers of 2 given by the lower order bits of flags.
0169  * By default it allocates from higher addresses towrds lower ones,
0170  * setting PA_LOW reverses this behaviour.
0171  */
0172 
0173 #define palloc(size) __palloc(size,0)
0174 
0175 #define isa_io_base (bd->io_base)
0176 
0177 void * __palloc(u_long, int);
0178 void  pfree(void *);
0179 
0180 #define PA_LOW 0x100
0181 #define PA_PERM 0x200       /* Not freeable by pfree */
0182 #define PA_SUBALLOC 0x400   /* Allocate for suballocation by salloc */
0183 #define PA_ALIGN_MASK 0x1f
0184 
0185 void * valloc(u_long size);
0186 void vfree(void *);
0187 
0188 int vmap(void *, u_long, u_long);
0189 void vunmap(void *);
0190 
0191 void * salloc(u_long size);
0192 void sfree(void *);
0193 
0194 void pci_init(void);
0195 
0196 void * memset(void *p, int c, size_t n);
0197 
0198 void gunzip(void *, int, unsigned char *, int *);
0199 
0200 void print_all_maps(const char *);
0201 void print_hash_table(void);
0202 void MMUon(void);
0203 void MMUoff(void);
0204 void hang(const char *, u_long, ctxt *) __attribute__((noreturn));
0205 
0206 int init_v86(void);
0207 void cleanup_v86_mess(void);
0208 void em86_main(struct pci_dev *);
0209 int find_max_mem(struct pci_dev *);
0210 
0211 /*
0212  * Prototypes for calls from assembly and across files.
0213  */
0214 typedef struct _x86 x86;
0215 
0216 int em86_trap(x86 *p);
0217 void decompress_kernel(int kernel_size, void * zimage_start, int len,
0218                void * initrd_start, int initrd_len );
0219 void boot_udelay(uint32_t _microseconds);
0220 void setup_hw(void);
0221 void _handler(int vec, ctxt *p);
0222 int early_setup(u_long image_size);
0223 void mm_init(u_long image_size);
0224 #endif
0225 
0226 #ifdef ASM
0227 /* These definitions simplify the ugly declarations necessary for
0228  * GOT definitions.
0229  */
0230 
0231 #define GOT_ENTRY(NAME) .L_ ## NAME = . - .LCTOC1   ; .long NAME
0232 #define GOT(NAME) .L_ ## NAME (r30)
0233 
0234 #define START_GOT   \
0235     .section    ".got2","aw"; \
0236 .LCTOC1 = .+ 0x8000
0237 
0238 #define END_GOT \
0239     .text
0240 
0241 #define GET_GOT \
0242     bl      1f; \
0243     .text   2; \
0244 0:  .long   .LCTOC1-1f; \
0245     .text   ; \
0246 1:  mflr    r30; \
0247     lwz r0,0b-1b(r30); \
0248         add r30,r0,r30
0249 
0250 #define bd r13
0251 #define cache_lsize 32  /* Offset into bd area */
0252 #define image   36
0253 #define stack   40
0254 #define mover   44
0255 #define o_msr   48
0256 #define o_hid0  52
0257 #define o_r31   56
0258 /* Stack offsets for saved registers on exceptions */
0259 #define save_lr    8(r1)
0260 #define save_ctr  12(r1)
0261 #define save_cr   16(r1)
0262 #define save_xer  20(r1)
0263 #define save_nip  24(r1)
0264 #define save_msr  28(r1)
0265 #define save_r(n) 32+4*n(r1)
0266 #endif
0267 
0268 #endif