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

Subversion Repositories openrisc

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/* =================================================================
2
 *
3
 *      loader_memory.c
4
 *
5
 *      Routines to read a library from memory.
6
 *
7
 * =================================================================
8
 * ####ECOSGPLCOPYRIGHTBEGIN####
9
 * -------------------------------------------
10
 * This file is part of eCos, the Embedded Configurable Operating
11
 * System.
12
 * Copyright (C) 2006, 2008 Free Software Foundation, Inc.
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):    Gernot Zankl zankl@decomsys.com
46
 *  Contributors:
47
 *  Date:         2006-11-21
48
 *  Purpose:
49
 *  Description:
50
 *
51
 * ####DESCRIPTIONEND####
52
 *
53
 * =================================================================
54
 */
55
 
56
#include <cyg/infra/diag.h>     // For diagnostic printing.
57
#include <cyg/infra/cyg_ass.h>  // CYG_ASSERT
58
 
59
#include <stdio.h>
60
#include <stdlib.h>
61
 
62
#include <pkgconf/objloader.h>
63
#include <cyg/objloader/elf.h>
64
#include <cyg/objloader/objelf.h>
65
#include <cyg/objloader/loader_memory.h>
66
 
67
typedef struct
68
{
69
    CYG_ADDRWORD nBufferBase;
70
    cyg_uint32   nOffset;
71
} ObjLoader_MemInfoType;
72
 
73
static size_t
74
cyg_ldr_memory_read(PELF_OBJECT p, size_t s, size_t n, void *mem)
75
{
76
    ObjLoader_MemInfoType * const pMemInfo = (ObjLoader_MemInfoType *)p->ptr;
77
 
78
    cyg_uint8 * const pSource =
79
        (cyg_uint8 *)pMemInfo->nBufferBase + pMemInfo->nOffset;
80
 
81
    memcpy(mem, (void*)pSource, s*n);
82
    return n;
83
}
84
 
85
static cyg_int32
86
cyg_ldr_memory_seek(PELF_OBJECT p, cyg_uint32 offs)
87
{
88
    ObjLoader_MemInfoType * const pMemInfo = (ObjLoader_MemInfoType *)p->ptr;
89
    pMemInfo->nOffset = offs;
90
    return 0;
91
}
92
 
93
static cyg_int32
94
cyg_ldr_memory_close(PELF_OBJECT p)
95
{
96
    return 0;
97
}
98
 
99
PELF_OBJECT
100
cyg_ldr_open_library_memory(CYG_ADDRWORD ptr)
101
{
102
    PELF_OBJECT  e_obj;
103
    ObjLoader_MemInfoType * pMemInfo;
104
 
105
    if (ptr == 0)
106
    {
107
        cyg_ldr_last_error = "ERROR INVALID POINTER";
108
        return (void*)0;
109
    }
110
 
111
    // Create a file object to keep track of this library.
112
    e_obj = (PELF_OBJECT)malloc(sizeof(ELF_OBJECT));
113
    CYG_ASSERT(e_obj != 0, "Cannot malloc() e_obj");
114
    if (e_obj == 0)
115
    {
116
        cyg_ldr_last_error = "ERROR IN MALLOC";
117
        return (void*)0;
118
    }
119
    memset(e_obj, 0, sizeof(ELF_OBJECT));
120
 
121
    pMemInfo = (ObjLoader_MemInfoType *)malloc(sizeof(ObjLoader_MemInfoType));
122
    CYG_ASSERT(pMemInfo != 0, "Cannot malloc() pMemInfo");
123
    if (pMemInfo == 0)
124
    {
125
        cyg_ldr_last_error = "ERROR IN MALLOC";
126
        return (void*)0;
127
    }
128
 
129
    pMemInfo->nBufferBase = ptr;
130
    pMemInfo->nOffset = 0;
131
 
132
    e_obj->ptr   = (CYG_ADDRWORD)pMemInfo;
133
    e_obj->mode  = CYG_LDR_MODE_MEMORY;
134
 
135
    // Handlers for the file system open.
136
    e_obj->read  = cyg_ldr_memory_read;
137
    e_obj->seek  = cyg_ldr_memory_seek;
138
    e_obj->close = cyg_ldr_memory_close;
139
    return e_obj;
140
}
141
 
142
void
143
cyg_ldr_close_library_memory(PELF_OBJECT p)
144
{
145
    free((ObjLoader_MemInfoType *) p->ptr);
146
}
147
 

powered by: WebSVN 2.1.0

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