]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/services/objloader/v2_0/src/relocate_ppc.c
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / services / objloader / v2_0 / src / relocate_ppc.c
1 /* =================================================================
2  *
3  *      relocate_ppc.c
4  *
5  *      Relocation types for the PowerPC processor.
6  *
7  * ================================================================= 
8  * ####ECOSGPLCOPYRIGHTBEGIN####
9  * -------------------------------------------
10  * This file is part of eCos, the Embedded Configurable Operating
11  * System.
12  * Copyright (C) 2005 eCosCentric Ltd.
13  * 
14  * eCos is free software; you can redistribute it and/or modify it
15  * under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 or (at your option)
17  * any later version.
18  * 
19  * eCos is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22  * General Public License for more details.
23  * 
24  * You should have received a copy of the GNU General Public License
25  * along with eCos; if not, write to the Free Software Foundation,
26  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27  * 
28  * As a special exception, if other files instantiate templates or
29  * use macros or inline functions from this file, or you compile this
30  * file and link it with other works to produce a work based on this
31  * file, this file does not by itself cause the resulting work to be
32  * covered by the GNU General Public License. However the source code
33  * for this file must still be made available in accordance with
34  * section (3) of the GNU General Public License.
35  * 
36  * This exception does not invalidate any other reasons why a work
37  * based on this file might be covered by the GNU General Public
38  * License.
39  *
40  * -------------------------------------------
41  * ####ECOSGPLCOPYRIGHTEND####
42  * =================================================================
43  * #####DESCRIPTIONBEGIN####
44  * 
45  *  Author(s):    Anthony Tonizzo (atonizzo@gmail.com)
46  *  Date:         2005-05-13
47  *  Purpose:      
48  *  Description:  
49  *               
50  * ####DESCRIPTIONEND####
51  * 
52  * =================================================================
53  */
54
55 #include <cyg/infra/diag.h>     // For diagnostic printing.
56 #include <pkgconf/io_fileio.h>
57 #include <stdlib.h>
58 #include <stdio.h>
59 #include <string.h>
60
61 #include <cyg/hal/hal_cache.h>
62 #include <cyg/hal/hal_io.h>
63
64 #include <pkgconf/objloader.h>
65 #include <cyg/objloader/elf.h>
66 #include <cyg/objloader/objelf.h>
67
68 #ifdef CYGPKG_HAL_POWERPC
69 void
70 cyg_ldr_flush_cache(void)
71 {
72     HAL_DCACHE_SYNC();
73     HAL_ICACHE_SYNC();
74 }
75
76 // in:
77 // 
78 // sym_type  Type of relocation to apply,
79 // mem       Address in memory to modify (relocate).
80 // sym_value 
81 cyg_int32 
82 cyg_ldr_relocate(cyg_int32 sym_type, cyg_uint32 mem, cyg_int32 sym_value)
83 {
84     cyg_int32  rel_offset, i;
85
86     // PPC uses rela, so we have to add the addend.
87     switch(sym_type)
88     {
89     case R_PPC_ADDR16_HA:
90         HAL_WRITE_UINT16(mem, _ha_(sym_value));
91         return 0;
92     case R_PPC_ADDR16_HI:
93         HAL_WRITE_UINT16(mem, _hi_(sym_value));
94         return 0;
95     case R_PPC_ADDR16_LO:
96         HAL_WRITE_UINT16(mem, _lo_(sym_value));
97         return 0;
98     case R_PPC_REL24:
99         // Now it is time to seek the destination address of the call.
100         // We need to do something in case the user jumps more than 16MB.
101         rel_offset = (sym_value - mem) & 0x03FFFFFC; 
102         HAL_READ_UINT32(mem, i);
103         i &= 0xFC000003;
104         HAL_WRITE_UINT32(mem, rel_offset | i);
105         return 0;
106     case R_PPC_REL32:
107         HAL_WRITE_UINT32(mem, (sym_value - mem));
108         return 0;
109     case R_PPC_ADDR32:
110         HAL_WRITE_UINT32(mem, sym_value);
111         return 0;
112     default:
113         ELFDEBUG("FIXME: Unknown relocation value!!!\n");
114         return -1;
115     }
116 }
117 #endif // CYGPKG_HAL_POWERPC
118
119