OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [services/] [objloader/] [current/] [src/] [relocate_arm.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/* =================================================================
2
 *
3
 *      relocate_arm.c
4
 *
5
 *      Relocation types for the ARM processor (Little Endian).
6
 *
7
 * =================================================================
8
 * ####ECOSGPLCOPYRIGHTBEGIN####
9
 * -------------------------------------------
10
 * This file is part of eCos, the Embedded Configurable Operating System.
11
 * Copyright (C) 2008, 2009 Free Software Foundation, Inc.
12
 *
13
 * eCos is free software; you can redistribute it and/or modify it
14
 * under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 or (at your option)
16
 * any later version.
17
 *
18
 * eCos is distributed in the hope that it will be useful, but
19
 * WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21
 * General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with eCos; if not, write to the Free Software Foundation,
25
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26
 *
27
 * As a special exception, if other files instantiate templates or
28
 * use macros or inline functions from this file, or you compile this
29
 * file and link it with other works to produce a work based on this
30
 * file, this file does not by itself cause the resulting work to be
31
 * covered by the GNU General Public License. However the source code
32
 * for this file must still be made available in accordance with
33
 * section (3) of the GNU General Public License.
34
 *
35
 * This exception does not invalidate any other reasons why a work
36
 * based on this file might be covered by the GNU General Public
37
 * License.
38
 *
39
 * -------------------------------------------
40
 * ####ECOSGPLCOPYRIGHTEND####
41
 * =================================================================
42
 * #####DESCRIPTIONBEGIN####
43
 *
44
 *  Author(s):    Anthony Tonizzo (atonizzo@gmail.com)
45
 *  Contributors: Sergei Gavrikov (sergei.gavrikov@gmail.com)
46
 *  Date:         2008-12-01
47
 *  Purpose:
48
 *  Description:
49
 *
50
 * ####DESCRIPTIONEND####
51
 *
52
 * =================================================================
53
 */
54
 
55
#include <cyg/infra/diag.h>     // For diagnostic printing.
56
#include <stdlib.h>
57
#include <stdio.h>
58
#include <string.h>
59
 
60
#include <cyg/hal/hal_cache.h>
61
#include <cyg/hal/hal_io.h>
62
 
63
#include <pkgconf/objloader.h>
64
#include <cyg/objloader/elf.h>
65
#include <cyg/objloader/objelf.h>
66
 
67
#ifdef CYGPKG_HAL_ARM
68
void
69
cyg_ldr_flush_cache(void)
70
{
71
    HAL_DCACHE_SYNC();
72
    HAL_ICACHE_SYNC();
73
}
74
 
75
#if CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL > 1
76
// Always 16 characters long, with blank padding is necessary, so
77
//  the printing is pretty. If the name is longer than 16, shorten it.
78
// We print the relocation symbols only is 
79
//  CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL is set to 2.
80
char *relocation_name[] =
81
{
82
    "", "R_ARM_PC24      ", "R_ARM_ABS32     ", "", "", "", "", "", "", "",
83
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
84
    "", "", "R_ARM_CALL      ", "R_ARM_JUMP24    ", "", "", "", "",
85
    "", "", "", "", "", "", "R_ARM_V4BX      "
86
};
87
#endif
88
 
89
// sym_type  Type of relocation to apply,
90
// mem       Address in memory to modify (relocate).
91
// sym_value The value of the symbol to use for the relocation.
92
// The proper relocation to apply (i.e. the proper use of mem and sym_value)
93
//  depend on the relocation to apply. The number and types of relocations
94
//  that must be supported by any given architecture is spelled in the ELF/EABI
95
//  guide for that architecture.
96
cyg_int32
97
cyg_ldr_relocate(cyg_int32 sym_type, cyg_uint32 mem, cyg_int32 sym_value)
98
{
99
    cyg_int32 offset;
100
    volatile cyg_uint32 *mem_addr = (cyg_uint32 *)mem;
101
 
102
    switch(sym_type)
103
    {
104
    case R_ARM_ABS32:
105
        offset = *mem_addr;
106
        *mem_addr = offset + sym_value;
107
        break;
108
    case R_ARM_PC24:
109
    case R_ARM_CALL:
110
    case R_ARM_JUMP24:
111
        offset = (*mem_addr & 0x00FFFFFF) << 2;
112
        if (offset & 0x02000000)
113
            offset -= 0x04000000;     // Sign extend.
114
        *mem_addr &= 0xff000000;      // Mask off the entire offset bits.
115
        offset = sym_value - mem + offset;  // This is the new offset.
116
        if ((offset & 0x03) || (offset >= (cyg_int32)0x04000000) ||
117
                                (offset <= (cyg_int32)0xFC000000))
118
            return -1;
119
        *mem_addr |= (offset >> 2) & 0x00FFFFFF;
120
        break;
121
    case R_ARM_V4BX:
122
        // For now only ARMv4T and later cores (with Thumb) are supported.
123
        break;
124
    default:
125
        CYG_ASSERT(0, ("FIXME: Unknown relocation value!!!\r\n"));
126
        return -1;
127
    }
128
    return 0;
129
}
130
 
131
#endif // CYGPKG_HAL_ARM
132
 
133
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.