diff --git a/src/host/README b/src/host/README index 7538ee6..e59433c 100644 --- a/src/host/README +++ b/src/host/README @@ -1,11 +1,8 @@ -The omx_sample.c Linux side test works with sysbios-rpmsg's test_omx.c +The omx*.c Linux side samples work with the sysbios-rpmsg test_omx.c. +The rpmsg_proto*.c samples work with either the test_omx ping tasks, or ping.c. -Copy these files to Linux kernel tree: /tools/: -- omx_packet.h -- omx_sample.c -- omx_benchmark.c -- build_samples +Copy these host/* files to Linux kernel tree: /tools/ From /tools type "build_samples" to build. -Copy omx_sample to target. +Copy binaries to target. diff --git a/src/host/build_samples b/src/host/build_samples old mode 100755 new mode 100644 index 2b0efec..22809c6 --- a/src/host/build_samples +++ b/src/host/build_samples @@ -3,5 +3,7 @@ arm-none-linux-gnueabi-gcc test_rpmsg_omx.c -o test_rpmsg_omx -lpthread arm-none-linux-gnueabi-gcc omx_sample.c -o omx_sample -lpthread arm-none-linux-gnueabi-gcc omx_benchmark.c -o omx_benchmark -lrt +arm-none-linux-gnueabi-gcc rpmsg_proto.c -o rpmsg_proto +arm-none-linux-gnueabi-gcc rpmsg_proto_bench.c -o rpmsg_proto_bench -lrt #cp -p omx_sample omx_benchmark /data/exports/gp/omap4_angstrom_rfs/virtio diff --git a/src/host/rpmsg_proto.c b/src/host/rpmsg_proto.c new file mode 100644 index 0000000..80628dc --- /dev/null +++ b/src/host/rpmsg_proto.c @@ -0,0 +1,120 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../include/net/rpmsg.h" + +#define M3_CORE0 (0) + +int main(void) +{ + int sock, sock2, err; + struct sockaddr_rpmsg src_addr, dst_addr; + socklen_t len; + const char *msg = "Hello there!"; + char buf[512]; + + /* create an RPMSG socket */ + sock = socket(AF_RPMSG, SOCK_SEQPACKET, 0); + if (sock < 0) { + printf("socket failed: %s (%d)\n", strerror(errno), errno); + return -1; + } + + /* connect to remote service */ + memset(&dst_addr, 0, sizeof(dst_addr)); + dst_addr.family = AF_RPMSG; + dst_addr.vproc_id = M3_CORE0; + dst_addr.addr = 51; + + printf("Connecting to address 0x%x on processor %d\n", + dst_addr.addr, dst_addr.vproc_id); + + len = sizeof(struct sockaddr_rpmsg); + err = connect(sock, (struct sockaddr *)&dst_addr, len); + if (err < 0) { + printf("connect failed: %s (%d)\n", strerror(errno), errno); + return -1; + } + + /* let's see what local address did we get */ + err = getsockname(sock, (struct sockaddr *)&src_addr, &len); + if (err < 0) { + printf("getpeername failed: %s (%d)\n", strerror(errno), errno); + return -1; + } + + printf("Our address: socket family: %d, proc id = %d, addr = %d\n", + src_addr.family, src_addr.vproc_id, src_addr.addr); + + printf("Sending \"%s\"\n", msg); + err = send(sock, msg, strlen(msg) + 1, 0); + if (err < 0) { + printf("sendto failed: %s (%d)\n", strerror(errno), errno); + return -1; + } + + memset(&src_addr, 0, sizeof(src_addr)); + + len = sizeof(src_addr); + + err = recvfrom(sock, buf, sizeof(buf), 0, + (struct sockaddr *)&src_addr, &len); + if (err < 0) { + printf("recvfrom failed: %s (%d)\n", strerror(errno), errno); + return -1; + } + if (len != sizeof(src_addr)) { + printf("recvfrom: got bad addr len (%d)\n", len); + return -1; + } + + printf("Received a msg from address 0x%x on processor %d\n", + src_addr.addr, src_addr.vproc_id); + printf("Message content: \"%s\".\n", buf); + + + close(sock); + + /* create another RPMSG socket */ + sock2 = socket(AF_RPMSG, SOCK_SEQPACKET, 0); + if (sock2 < 0) { + printf("socket failed: %s (%d)\n", strerror(errno), errno); + return -1; + } + + /* bind a local addr */ + memset(&src_addr, 0, sizeof(src_addr)); + src_addr.family = AF_RPMSG; + src_addr.vproc_id = M3_CORE0; + src_addr.addr = 99; + + + printf("Exposing address %d to processor %d\n", + src_addr.addr, src_addr.vproc_id); + + len = sizeof(struct sockaddr_rpmsg); + err = bind(sock2, (struct sockaddr *)&src_addr, len); + if (err < 0) { + printf("bind failed: %s (%d)\n", strerror(errno), errno); + return -1; + } + + /* let's see what local address did we bind */ + err = getsockname(sock2, (struct sockaddr *)&src_addr, &len); + if (err < 0) { + printf("getpeername failed: %s (%d)\n", strerror(errno), errno); + return -1; + } + + printf("Our address: socket family: %d, proc id = %d, addr = %d\n", + src_addr.family, src_addr.vproc_id, src_addr.addr); + + return 0; +} diff --git a/src/host/rpmsg_proto_bench.c b/src/host/rpmsg_proto_bench.c new file mode 100644 index 0000000..dff51ae --- /dev/null +++ b/src/host/rpmsg_proto_bench.c @@ -0,0 +1,124 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../include/net/rpmsg.h" + +#define M3_CORE0 (0) + +#define NUMLOOPS 1000 + +long diff(struct timespec start, struct timespec end) +{ + long usecs; + + struct timespec temp; + if ((end.tv_nsec-start.tv_nsec)<0) { + temp.tv_sec = end.tv_sec-start.tv_sec-1; + temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec; + } else { + temp.tv_sec = end.tv_sec-start.tv_sec; + temp.tv_nsec = end.tv_nsec-start.tv_nsec; + } + usecs = temp.tv_sec * 1000 + temp.tv_nsec / 1000; + return usecs; +} + +int main(void) +{ + int sock, err; + struct sockaddr_rpmsg src_addr, dst_addr; + socklen_t len; + const char *msg = "Hello there!"; + char buf[512]; + struct timespec start,end; + long elapsed=0,delta; + int i; + + /* create an RPMSG socket */ + sock = socket(AF_RPMSG, SOCK_SEQPACKET, 0); + if (sock < 0) { + printf("socket failed: %s (%d)\n", strerror(errno), errno); + return -1; + } + + /* connect to remote service */ + memset(&dst_addr, 0, sizeof(dst_addr)); + dst_addr.family = AF_RPMSG; + dst_addr.vproc_id = M3_CORE0; + dst_addr.addr = 51; // use 51 for ping_tasks; + //dst_addr.addr = 61; // use 61 for messageQ transport; + + printf("Connecting to address 0x%x on processor %d\n", + dst_addr.addr, dst_addr.vproc_id); + + len = sizeof(struct sockaddr_rpmsg); + err = connect(sock, (struct sockaddr *)&dst_addr, len); + if (err < 0) { + printf("connect failed: %s (%d)\n", strerror(errno), errno); + return -1; + } + + /* let's see what local address did we get */ + err = getsockname(sock, (struct sockaddr *)&src_addr, &len); + if (err < 0) { + printf("getpeername failed: %s (%d)\n", strerror(errno), errno); + return -1; + } + + printf("Our address: socket family: %d, proc id = %d, addr = %d\n", + src_addr.family, src_addr.vproc_id, src_addr.addr); + + printf("Sending \"%s\"\n", msg); + + for (i = 0; i < NUMLOOPS; i++) { + //clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); + clock_gettime(CLOCK_REALTIME, &start); + + err = send(sock, msg, strlen(msg) + 1, 0); + if (err < 0) { + printf("sendto failed: %s (%d)\n", strerror(errno), errno); + return -1; + } + + memset(&src_addr, 0, sizeof(src_addr)); + + len = sizeof(src_addr); + + // printf("Awaiting a response...\n"); + err = recvfrom(sock, buf, sizeof(buf), 0, + (struct sockaddr *)&src_addr, &len); + if (err < 0) { + printf("recvfrom failed: %s (%d)\n", strerror(errno), errno); + return -1; + } + if (len != sizeof(src_addr)) { + printf("recvfrom: got bad addr len (%d)\n", len); + return -1; + } + + //clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); + clock_gettime(CLOCK_REALTIME, &end); + delta = diff(start,end); + elapsed += delta; + + /* + printf ("Message time: %ld usecs\n", delta); + printf("Received a msg from address 0x%x on processor %d\n", + src_addr.addr, src_addr.vproc_id); + printf("Message content: \"%s\".\n", buf); + */ + } + printf ("Avg time: %ld usecs over %d iterations\n", elapsed / i, i); + + close(sock); + + return 0; +} diff --git a/src/ti/ipc/rpmsg/MessageQCopy.c b/src/ti/ipc/rpmsg/MessageQCopy.c index 71784f2..c8ee953 100644 --- a/src/ti/ipc/rpmsg/MessageQCopy.c +++ b/src/ti/ipc/rpmsg/MessageQCopy.c @@ -78,6 +78,8 @@ typedef struct MessageQCopy_Object { UInt32 queueId; /* Unique id (procId | queueIndex) */ Semaphore_Handle semHandle; /* I/O Completion */ + MessageQCopy_callback cb; /* MessageQ Callback */ + UArg arg; /* Callback argument */ List_Handle queue; /* Queue of pending messages */ Bool unblocked; /* Use with signal to unblock _receive() */ } MessageQCopy_Object; @@ -156,7 +158,7 @@ static Void MessageQCopy_swiFxn(UArg arg0, UArg arg1) "to: 0x%x, dataLen: %d", (IArg)msg->srcAddr, (IArg)msg->dstAddr, (IArg)msg->dataLen); - /* Pass to desitination queue (which is on this proc): */ + /* Pass to desitination queue (on this proc), or callback: */ MessageQCopy_send(dstProc, msg->dstAddr, msg->srcAddr, (Ptr)msg->payload, msg->dataLen); @@ -284,10 +286,13 @@ Void MessageQCopy_finalize() #undef FXNN /* - * ======== MessageQCopy_create ======== + * ======== MessageQCopy_createEx ======== */ #define FXNN "MessageQCopy_create" -MessageQCopy_Handle MessageQCopy_create(UInt32 reserved, UInt32 * endpoint) +MessageQCopy_Handle MessageQCopy_createEx(UInt32 reserved, + MessageQCopy_callback cb, + UArg arg, + UInt32 * endpoint) { MessageQCopy_Object *obj = NULL; Bool found = FALSE; @@ -295,8 +300,8 @@ MessageQCopy_Handle MessageQCopy_create(UInt32 reserved, UInt32 * endpoint) UInt16 queueIndex = 0; IArg key; - Log_print2(Diags_ENTRY, "--> "FXNN": (reserved=%d, endpoint=0x%x)", - (IArg)reserved, (IArg)endpoint); + Log_print3(Diags_ENTRY, "--> "FXNN": (reserved=%d, cb=0x%x, endpoint=0x%x)", + (IArg)reserved, (IArg)cb, (IArg)endpoint); Assert_isTrue((curInit > 0) , NULL); @@ -322,11 +327,18 @@ MessageQCopy_Handle MessageQCopy_create(UInt32 reserved, UInt32 * endpoint) if (found) { obj = Memory_alloc(NULL, sizeof(MessageQCopy_Object), 0, NULL); if (obj != NULL) { - /* Allocate a semaphore to signal when messages received: */ - obj->semHandle = Semaphore_create(0, NULL, NULL); + if (cb) { + /* Store callback and it's arg instead of semaphore: */ + obj->cb = cb; + obj->arg= arg; + } + else { + /* Allocate a semaphore to signal when messages received: */ + obj->semHandle = Semaphore_create(0, NULL, NULL); - /* Create our queue of to be received messages: */ - obj->queue = List_create(NULL, NULL); + /* Create our queue of to be received messages: */ + obj->queue = List_create(NULL, NULL); + } /* Store our endpoint, and object: */ obj->queueId = queueIndex; @@ -365,14 +377,20 @@ Int MessageQCopy_delete(MessageQCopy_Handle *handlePtr) if (handlePtr && (obj = (MessageQCopy_Object *)(*handlePtr))) { - Semaphore_delete(&(obj->semHandle)); - - /* Free/discard all queued message buffers: */ - while ((payload = (Queue_elem *)List_get(obj->queue)) != NULL) { - HeapBuf_free(module.heap, (Ptr)payload, MSGBUFFERSIZE); + if (obj->cb) { + obj->cb = NULL; + obj->arg= NULL; } + else { + Semaphore_delete(&(obj->semHandle)); + + /* Free/discard all queued message buffers: */ + while ((payload = (Queue_elem *)List_get(obj->queue)) != NULL) { + HeapBuf_free(module.heap, (Ptr)payload, MSGBUFFERSIZE); + } - List_delete(&(obj->queue)); + List_delete(&(obj->queue)); + } /* Null out our slot: */ key = GateSwi_enter(module.gateSwi); @@ -410,6 +428,8 @@ Int MessageQCopy_recv(MessageQCopy_Handle handle, Ptr data, UInt16 *len, (IArg)len, (IArg)rplyEndpt, (IArg)timeout); Assert_isTrue((curInit > 0) , NULL); + /* A callback was set: client should not be calling this fxn! */ + Assert_isTrue((!obj->cb), NULL); /* Check vring for pending messages before we block: */ Swi_post(transport.swiHandle); @@ -499,8 +519,6 @@ Int MessageQCopy_send(UInt16 dstProc, } } else { - /* Put on a Message queue on this processor: */ - /* Protect from MessageQCopy_delete */ key = GateSwi_enter(module.gateSwi); obj = module.msgqObjects[dstEndpt]; @@ -513,26 +531,36 @@ Int MessageQCopy_send(UInt16 dstProc, return status; } - /* Allocate a buffer to copy the payload: */ - size = len + sizeof(Queue_elem); + /* If callback registered, call it: */ + if (obj->cb) { + Log_print2(Diags_INFO, FXNN": calling callback with data len: " + "%d, from: %d\n", len, srcEndpt); + obj->cb(obj, obj->arg, data, len, srcEndpt); + } + else { + /* else, put on a Message queue on this processor: */ - /* HeapBuf_alloc() is non-blocking, so needs protection: */ - key = GateSwi_enter(module.gateSwi); - payload = (Queue_elem *)HeapBuf_alloc(module.heap, size, 0, NULL); - GateSwi_leave(module.gateSwi, key); + /* Allocate a buffer to copy the payload: */ + size = len + sizeof(Queue_elem); - if (payload != NULL) { - memcpy(payload->data, data, len); - payload->len = len; - payload->src = srcEndpt; + /* HeapBuf_alloc() is non-blocking, so needs protection: */ + key = GateSwi_enter(module.gateSwi); + payload = (Queue_elem *)HeapBuf_alloc(module.heap, size, 0, NULL); + GateSwi_leave(module.gateSwi, key); - /* Put on the endpoint's queue and signal: */ - List_put(obj->queue, (List_Elem *)payload); - Semaphore_post(obj->semHandle); - } - else { - status = MessageQCopy_E_MEMORY; - Log_print0(Diags_STATUS, FXNN": HeapBuf_alloc failed!"); + if (payload != NULL) { + memcpy(payload->data, data, len); + payload->len = len; + payload->src = srcEndpt; + + /* Put on the endpoint's queue and signal: */ + List_put(obj->queue, (List_Elem *)payload); + Semaphore_post(obj->semHandle); + } + else { + status = MessageQCopy_E_MEMORY; + Log_print0(Diags_STATUS, FXNN": HeapBuf_alloc failed!"); + } } } @@ -551,6 +579,8 @@ Void MessageQCopy_unblock(MessageQCopy_Handle handle) Log_print1(Diags_ENTRY, "--> "FXNN": (handle=0x%x)", (IArg)handle); + Assert_isTrue((!obj->cb), NULL); + /* Set instance to 'unblocked' state, and post */ obj->unblocked = TRUE; Semaphore_post(obj->semHandle); diff --git a/src/ti/ipc/rpmsg/MessageQCopy.h b/src/ti/ipc/rpmsg/MessageQCopy.h index 3ca3301..9750aae 100644 --- a/src/ti/ipc/rpmsg/MessageQCopy.h +++ b/src/ti/ipc/rpmsg/MessageQCopy.h @@ -141,6 +141,10 @@ extern "C" { */ typedef struct MessageQCopy_Object *MessageQCopy_Handle; + +typedef Void (*MessageQCopy_callback)(MessageQCopy_Handle, UArg, Ptr, + UInt16, UInt32); + /* ============================================================================= * MessageQCopy Functions: * ============================================================================= @@ -181,8 +185,34 @@ Void MessageQCopy_finalize(); * - reserved endpoint already taken; * - could not allocate object */ -MessageQCopy_Handle MessageQCopy_create(UInt32 reserved, UInt32 * endpoint); +#define MessageQCopy_create(reserved, endpoint)\ + MessageQCopy_createEx(reserved, NULL, NULL, endpoint) +/*! + * @brief Create a MessageQ instance for receiving, with callback. + * + * This is an extension of MessageQCopy_create(), with the option of passing + * a callback function and its argument to be called when a message is + * received. + * + * @param[in] reserved If value is MessageQCopy_ASSIGN_ANY, then + * any Endpoint can be assigned; otherwise, value is + * a reserved Endpoint ID, which must be less than + * or equal to MessageQCopy_MAX_RESERVED_ENDPOINT. + * @param[in] callback If non-NULL, on received data, this callback is + * called instead of posting the internal semaphore. + * @param[in] arg Argument for the callback. + * @param[out] endpoint Endpoint ID for this side of the connection. + * + * + * @return MessageQ Handle, or NULL if: + * - reserved endpoint already taken; + * - could not allocate object + */ +MessageQCopy_Handle MessageQCopy_createEx(UInt32 reserved, + MessageQCopy_callback callback, + UArg arg, + UInt32 * endpoint); /*! * @brief Receives a message from a message queue * diff --git a/src/ti/ipc/tests/package.bld b/src/ti/ipc/tests/package.bld new file mode 100644 index 0000000..f93a757 --- /dev/null +++ b/src/ti/ipc/tests/package.bld @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * ======== package.bld ======== + * + */ + +var testBld = xdc.loadCapsule("ti/sdo/ipc/build/test.bld"); +var commonBld = xdc.loadCapsule("ti/sdo/ipc/build/common.bld"); + +/* + * Export everything necessary to build this package with (almost) no + * generated files. This also exports subdirectories like 'golden' + * and 'docs'. + */ +Pkg.attrs.exportAll = true; + +/* + * ======== testArray ======== + * See ti/bios/build/test.bld. Only the test name is required. + * + * Example: + * var testArray = [ + * {name: Test1}, + * {name: Test2, sources: ["Test"], config: "Test", refOutput: "Test", timeout: "15", buildTargets: ["C64", "C28_large"]} + * ]; + */ + +var testArray = [ + {name: 'ping', buildPlatforms: ["ti.platform.omap4430.core0"]}, +]; + +arguments = ["profile=debug platform=all"]; + +testBld.buildTests(testArray, arguments); diff --git a/src/ti/ipc/tests/package.xdc b/src/ti/ipc/tests/package.xdc new file mode 100644 index 0000000..cc03678 --- /dev/null +++ b/src/ti/ipc/tests/package.xdc @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * ======== package.xdc ======== + * + */ + +/*! + * ======== ti.ipc.tests ======== + * Currently not shipping these modules + */ + +package ti.ipc.tests [1,0,0,0] { +} diff --git a/src/ti/ipc/tests/package.xs b/src/ti/ipc/tests/package.xs new file mode 100644 index 0000000..ca2dd06 --- /dev/null +++ b/src/ti/ipc/tests/package.xs @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * ======== package.xs ======== + */ + +/* + * ======== close ======== + */ +function close() +{ +} diff --git a/src/ti/ipc/tests/ping.c b/src/ti/ipc/tests/ping.c new file mode 100644 index 0000000..7cdb7d4 --- /dev/null +++ b/src/ti/ipc/tests/ping.c @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * ======== ping.c ======== + * + * Works with the rpmsg_proto* Linux samples over the rpmsg-proto socket. + * rpmsg_proto* samples are in the host/ directory of this tree. + */ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +typedef UInt32 u32; +#include + +static UInt16 dstProc; +static MessageQCopy_Handle handle = NULL; +static UInt32 myEndpoint = 0; +static UInt32 counter = 0; + +/* Send me a zero length data payload to tear down the MesssageQCopy object: */ +static Void pingCallbackFxn(MessageQCopy_Handle h, UArg arg, Ptr data, + UInt16 len, UInt32 src) +{ + Char buffer[128]; + + memcpy(buffer, data, len); + buffer[len] = '\0'; + System_printf("%d: Received data: %s, len:%d\n", counter++, buffer, len); + + /* Send data back to remote endpoint: */ + MessageQCopy_send(dstProc, src, myEndpoint, (Ptr)buffer, len); +} + +Void pingTaskFxn(UArg arg0, UArg arg1) +{ + System_printf("ping_task at port %d: Entered...\n", arg0); + + /* Create the messageQ for receiving, and register callback: */ + handle = MessageQCopy_createEx(arg0, pingCallbackFxn, NULL, &myEndpoint); + if (!handle) { + System_abort("MessageQCopy_createEx failed\n"); + } + + /* Announce we are here: */ + NameMap_register("rpmsg-proto", arg0); + + /* Note: we don't get a chance to teardown with MessageQCopy_destroy() */ +} + +Int main(Int argc, char* argv[]) +{ + + System_printf("%s starting..\n", MultiProc_getName(MultiProc_self())); + + System_printf("%d resources at 0x%x\n", resources.num, resources); + + /* Plug vring interrupts, and spin until host handshake complete. */ + VirtQueue_startup(0); + + dstProc = MultiProc_getId("HOST"); + MessageQCopy_init(dstProc); + + BIOS_start(); + + return (0); +} diff --git a/src/ti/ipc/tests/ping.cfg b/src/ti/ipc/tests/ping.cfg new file mode 100644 index 0000000..84d386a --- /dev/null +++ b/src/ti/ipc/tests/ping.cfg @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +/* + * The SysMin used here vs StdMin, as trace buffer address is required for + * Linux trace debug driver, plus provides better performance. + */ +var System = xdc.useModule('xdc.runtime.System'); +var SysMin = xdc.useModule('xdc.runtime.SysMin'); +System.SupportProxy = SysMin; +SysMin.bufSize = 0x8000; + +/* Modules used in the virtqueue/MessageQCopy/ServiceMgr libraries: */ +var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore'); +var BIOS = xdc.useModule('ti.sysbios.BIOS'); +BIOS.heapSize = 0x20000; + +/* Reduces code size, by only pulling in modules explicitly referenced: */ +BIOS.libType = BIOS.LibType_Custom; + +xdc.loadPackage('ti.ipc.rpmsg'); +xdc.loadPackage('ti.srvmgr'); /* for NameMap */ + + +/* Modules used in Power Management */ +xdc.loadPackage('ti.pm'); +var Power = xdc.useModule('ti.sysbios.family.arm.ducati.omap4430.Power'); +Power.loadSegment = "PM_DATA"; + +/* Idle function that periodically flushes the unicache */ +var Idle = xdc.useModule('ti.sysbios.knl.Idle'); +Idle.addFunc('&VirtQueue_cacheWb'); +/* IpcPower idle function must be at the end */ +Idle.addFunc('&IpcPower_idle'); + +var HeapBuf = xdc.useModule('ti.sysbios.heaps.HeapBuf'); +var List = xdc.useModule('ti.sdo.utils.List'); + +xdc.useModule('ti.sysbios.xdcruntime.GateThreadSupport'); +var GateSwi = xdc.useModule('ti.sysbios.gates.GateSwi'); + +var Task = xdc.useModule('ti.sysbios.knl.Task'); +var params = new Task.Params; +params.instance.name = "ping"; +params.arg0= 51; +Program.global.tsk1 = Task.create('&pingTaskFxn', params); +Task.deleteTerminatedTasks = true; + +var Assert = xdc.useModule('xdc.runtime.Assert'); +var Defaults = xdc.useModule('xdc.runtime.Defaults'); +var Diags = xdc.useModule('xdc.runtime.Diags'); +var LoggerSys = xdc.useModule('xdc.runtime.LoggerSys'); +var LoggerSysParams = new LoggerSys.Params(); + +/* Enable Logger: */ +Defaults.common$.logger = LoggerSys.create(LoggerSysParams); + +/* Enable runtime Diags_setMask() for non-XDC spec'd modules: */ +var Text = xdc.useModule('xdc.runtime.Text'); +Text.isLoaded = true; +var Registry = xdc.useModule('xdc.runtime.Registry'); +Registry.common$.diags_ENTRY = Diags.RUNTIME_OFF; +Registry.common$.diags_EXIT = Diags.RUNTIME_OFF; +Registry.common$.diags_INFO = Diags.RUNTIME_OFF; +Registry.common$.diags_LIFECYCLE = Diags.RUNTIME_OFF; +Registry.common$.diags_STATUS = Diags.RUNTIME_OFF; +Diags.setMaskEnabled = true; + +var Main = xdc.useModule('xdc.runtime.Main'); +Main.common$.diags_ASSERT = Diags.ALWAYS_ON; +Main.common$.diags_INTERNAL = Diags.ALWAYS_ON; + +var Hwi = xdc.useModule('ti.sysbios.family.arm.m3.Hwi'); +Hwi.enableException = true; + + +xdc.includeFile("ti/configs/omap4430/DucatiCore0.cfg"); +xdc.includeFile("ti/configs/omap4430/DucatiAmmu.cfg"); + diff --git a/src/ti/pm/IpcPower.c b/src/ti/pm/IpcPower.c index d7d7082..ec6827b 100644 --- a/src/ti/pm/IpcPower.c +++ b/src/ti/pm/IpcPower.c @@ -140,7 +140,9 @@ Void IpcPower_suspend() */ Void IpcPower_idle() { - REG32(M3_SCR_REG) |= 1 << DEEPSLEEP_BIT; +// TODO enable DEEPSLEEP bit only once we are using external GPT for OS tick, +// otherwise the M3 can fall asleep and never wake up +// REG32(M3_SCR_REG) |= 1 << DEEPSLEEP_BIT; REG32(WUGEN_MEVT1) |= WUGEN_INT_MASK; asm(" wfi"); } diff --git a/src/utils/Makefile b/src/utils/Makefile deleted file mode 100644 index e8afbbc..0000000 --- a/src/utils/Makefile +++ /dev/null @@ -1,66 +0,0 @@ -# -# Copyright (c) 2011, Texas Instruments Incorporated -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of Texas Instruments Incorporated nor the names of -# its contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# - -all: readrprc wrints genbase ducati-m3.bin - -ducati-m3.bin: ../ti/examples/srvmgr/ti_platform_omap4430_core0/debug/test_omx_sysm3.xem3 ../ti/examples/srvmgr/ti_platform_omap4430_core1/debug/test_omx_appm3.xem3 wrints genbase - # - # ensure that ducati's core0 program is listed before ducati's core1 - # program, the Linux FW loader expects such. - # - ./genrprc --t0=SysMin_Module_State_0_outbuf__A ../ti/examples/srvmgr/ti_platform_omap4430_core0/debug/test_omx_sysm3.xem3 --t1=SysMin_Module_State_0_outbuf__A ../ti/examples/srvmgr/ti_platform_omap4430_core1/debug/test_omx_appm3.xem3 $@ - -CFLAGS = -Wall -m32 -RPRCOBJ = readrprc.o -WRNTOBJ = wrints.o - -readrprc: $(RPRCOBJ) - gcc $(CFLAGS) -o $@ $(RPRCOBJ) - -readrprc.o: readrprc.c - gcc $(CFLAGS) -c -o $@ $< - -wrints: $(WRNTOBJ) - gcc $(CFLAGS) -o $@ $(WRNTOBJ) - -wrints.o: wrints.c - gcc $(CFLAGS) -c -o $@ $< - -genbase: elfload/genbase - cp $^ . - -elfload/genbase: - cd elfload; make - -clean: - @rm -f genbase readrprc wrints *.o ducati-m3.bin - cd elfload; make clean diff --git a/src/utils/README b/src/utils/README deleted file mode 100644 index f7ef5e0..0000000 --- a/src/utils/README +++ /dev/null @@ -1,7 +0,0 @@ -This directory is experimental, and not built into the ducati-m3.bin coming -from gollum releases. - -The BIOS image built from this directory is Version 2, and incompatible with -remotproc loaders which load only BIOS image Version 1. - -See src/ti/resources/rsc_table.h.mmap for corresponding .resource_table format. diff --git a/src/utils/elfload/ArrayList.c b/src/utils/elfload/ArrayList.c deleted file mode 100644 index 8d6990e..0000000 --- a/src/utils/elfload/ArrayList.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* ArrayList.c */ -/* */ -/* Array_List is a C implementation of a C++ vector class. */ -/* */ -/* This class emulates a resizable array along the lines of a C++ */ -/* vector or Java ArrayList class in C, and uses the convention */ -/* of passing a pointer to the current "object" as the first */ -/* argument. */ -/* */ -/* Usage is defined as follows: */ -/* */ -/* Array_List obj; */ -/* AL_initialize(&obj, sizeof(type_name)); */ -/* */ -/* ... */ -/* */ -/* type_name *ptr = (type_name*)(obj.buf); */ -/* for(i=0; i -#include -#include -#include "ArrayList.h" -#include "dload_api.h" - -/*****************************************************************************/ -/* AL_INITIALIZE() - Initialize a newly created Array_List object. */ -/*****************************************************************************/ -void AL_initialize(Array_List* obj, int32_t type_size, int32_t num_elem) -{ - if (num_elem == 0) num_elem = 1; - obj->buf = DLIF_malloc(type_size * num_elem); - obj->type_size = type_size; - obj->size = 0; - obj->buffer_size = num_elem; -} - -/*****************************************************************************/ -/* AL_APPEND() - Append an element to the end of an Array_List. */ -/*****************************************************************************/ -void AL_append(Array_List* obj, void* to_append) -{ - /*-----------------------------------------------------------------------*/ - /* If there is already space in the specified buffer for the new data, */ - /* just append it to the end of the data that is already in the buffer. */ - /*-----------------------------------------------------------------------*/ - if (obj->size < obj->buffer_size) - memcpy(((uint8_t*)obj->buf) + obj->type_size * ((obj->size)++), - to_append, obj->type_size); - - /*------------------------------------------------------------------------*/ - /* Grow the buffer if we need more space to add the new data to it. */ - /*------------------------------------------------------------------------*/ - else - { - void* old_buffer = obj->buf; - obj->buffer_size *= 2; - obj->buf = DLIF_malloc(obj->buffer_size*obj->type_size); - if(obj->buf) { - memcpy(obj->buf,old_buffer,obj->size*obj->type_size); - memcpy(((uint8_t*)obj->buf) + obj->type_size *((obj->size)++), - to_append, obj->type_size); - } - DLIF_free(old_buffer); - } -} - -/*****************************************************************************/ -/* AL_SIZE() - Get the number of elements in an Array_List. */ -/*****************************************************************************/ -int32_t AL_size(Array_List* obj) -{ - return obj->size; -} - -/*****************************************************************************/ -/* AL_DESTROY() - Free up memory associated with an Array_List that is no */ -/* longer in use. */ -/*****************************************************************************/ -void AL_destroy(Array_List* obj) -{ - DLIF_free(obj->buf); -} diff --git a/src/utils/elfload/Makefile b/src/utils/elfload/Makefile deleted file mode 100644 index 4a8b1ce..0000000 --- a/src/utils/elfload/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -# -# Copyright (c) 2011, Texas Instruments Incorporated -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of Texas Instruments Incorporated nor the names of -# its contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# - -CFLAGS = -Wall -m32 -I./include -DARM_TARGET -DC60_TARGET -g - -SRC = arm_dynamic.c arm_reloc.c ArrayList.c c60_dynamic.c c60_reloc.c dload.c dload_endian.c dlw_client.c dlw_debug.c dlw_dsbt.c dlw_trgmem.c elf32.c genbase.c symtab.c -OBJ = arm_dynamic.o arm_reloc.o ArrayList.o c60_dynamic.o c60_reloc.o dload.o dload_endian.o dlw_client.o dlw_debug.o dlw_dsbt.o dlw_trgmem.o elf32.o genbase.o symtab.o - -genbase: $(OBJ) - gcc $(CFLAGS) -o $@ $(OBJ) - -clean: - @rm -f genbase $(OBJ) diff --git a/src/utils/elfload/arm_dynamic.c b/src/utils/elfload/arm_dynamic.c deleted file mode 100644 index d94b616..0000000 --- a/src/utils/elfload/arm_dynamic.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* arm_dynamic.c */ -/* */ -/* ARM specific dynamic loader functionality. */ -/*****************************************************************************/ - -#ifdef ARM_TARGET - -#include "arm_elf32.h" -#include "dload.h" - -/*****************************************************************************/ -/* process_arm_dynamic_tag() */ -/* */ -/* Process ARM specific dynamic tags */ -/*****************************************************************************/ -BOOL DLDYN_arm_process_dynamic_tag(DLIMP_Dynamic_Module* dyn_module, int i) -{ - switch (dyn_module->dyntab[i].d_tag) - { - case DT_ARM_SYMTABSZ: - { - dyn_module->symnum = dyn_module->dyntab[i].d_un.d_val; -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Found symbol table size: %d\n", - dyn_module->symnum); -#endif - return TRUE; - } - } - - return FALSE; -} - -/*****************************************************************************/ -/* DLDYN_arm_relocate_dynamic_tag_info() */ -/* */ -/* Update any target specific dynamic tag values that are associated with */ -/* a section address. Return TRUE if the tag value is successfully */ -/* updated or if the tag is not associated with a section address, and */ -/* FALSE if we can't find the sectoin associated with the tag or if the */ -/* tag type is not recognized. */ -/* */ -/*****************************************************************************/ -BOOL DLDYN_arm_relocate_dynamic_tag_info(DLIMP_Dynamic_Module *dyn_module, - int32_t i) -{ - switch (dyn_module->dyntab[i].d_tag) - { - /*-------------------------------------------------------------------*/ - /* These tags do not point to sections. */ - /*-------------------------------------------------------------------*/ - case DT_ARM_RESERVED1: - case DT_ARM_SYMTABSZ: - case DT_ARM_PREEMPTMAP: - case DT_ARM_RESERVED2: - return TRUE; - } - - DLIF_error(DLET_MISC, "Invalid dynamic tag encountered, %d\n", - (int)dyn_module->dyntab[i].d_tag); - return FALSE; -} - -/*****************************************************************************/ -/* arm_process_eiosabi() */ -/* */ -/* Process the EI_OSABI value. Verify that the OSABI is supported and set */ -/* any variables which depend on the OSABI. */ -/*****************************************************************************/ -BOOL DLDYN_arm_process_eiosabi(DLIMP_Dynamic_Module* dyn_module) -{ - /*-----------------------------------------------------------------------*/ - /* For ARM, the EI_OSABI value must not be set. The only ARM specific */ - /* value is ELFOSABI_ARM_AEABI is for objects which contain symbol */ - /* versioning, which we do not support for Baremetal ABI. */ - /*-----------------------------------------------------------------------*/ - if (dyn_module->fhdr.e_ident[EI_OSABI] != ELFOSABI_NONE) - return FALSE; - - return TRUE; -} - -#endif /* ARM_TARGET */ diff --git a/src/utils/elfload/arm_reloc.c b/src/utils/elfload/arm_reloc.c deleted file mode 100644 index 3800da7..0000000 --- a/src/utils/elfload/arm_reloc.c +++ /dev/null @@ -1,2052 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/******************************************************************************/ -/* arm_reloc.c */ -/* */ -/* Process ARM-specific dynamic relocations for core dynamic loader. */ -/******************************************************************************/ - -#include -#include -#include "relocate.h" -#include "dload_api.h" -#include "util.h" -#include "dload_endian.h" -#include "symtab.h" -#include "arm_elf32.h" - -#define EXTRACT(field, lsb_offset, field_size) \ - ( (field >> lsb_offset) & ((1U << field_size) - 1) ) -#define OPND_S(symval) (symval & ~0x1) -#define OPND_T(symval) (symval & 0x1) -#define IS_BLX(field) ((EXTRACT(field, 24, 8) & ~0x1) == 0xFA) -#define SIGN_EXTEND(field, field_size) (field |= -(field & (1<<(field_size-1)))) - -/*****************************************************************************/ -/* Enumeration to represent the relocation container size. */ -/* */ -/* ARM_RELOC - one 32 bit relocation field */ -/* THUMB32_RELOC - two 16 bit relocation fields */ -/* THUMB16_RELOC - one 16 bit relocation field */ -/* ARM8_RELOC - one 8 bit relocation field */ -/*****************************************************************************/ -typedef enum -{ - ARM_RELOC, - THUMB32_RELOC, - THUMB16_RELOC, - ARM8_RELOC -}ARM_RELOC_SIZE; - -/*****************************************************************************/ -/* OBJ_IS_BE8() - Returns TRUE if the object file contains BE8 code. */ -/*****************************************************************************/ -static inline int obj_is_be8(struct Elf32_Ehdr* fhdr) -{ - return (fhdr->e_flags & EF_ARM_BE8); -} - -/*****************************************************************************/ -/* IS_DATA_RELOCATION() - Returns TRUE if the relocation pertains to data */ -/*****************************************************************************/ -static BOOL is_data_relocation(ARM_RELOC_TYPE r_type) -{ - switch (r_type) - { - case R_ARM_ABS32: - case R_ARM_ABS16: - case R_ARM_ABS8: - case R_ARM_PREL31: - case R_ARM_REL32: - case R_ARM_ABS32_NOI: - case R_ARM_REL32_NOI: - return TRUE; - default: - return FALSE; - } -} - -/*****************************************************************************/ -/* REL_SWAP_ENDIAN() - Return TRUE if we should change the endianness of a */ -/* relocation field. Due to BE-8 encoding, we cannot */ -/* simply rely on the wrong_endian member of elf_addrs. */ -/*****************************************************************************/ -static BOOL rel_swap_endian(DLIMP_Dynamic_Module* dyn_module, - ARM_RELOC_TYPE r_type) -{ - /*-----------------------------------------------------------------------*/ - /* LE -> BE8 - swap data relocations only */ - /*-----------------------------------------------------------------------*/ - if (dyn_module->wrong_endian && obj_is_be8(&dyn_module->fhdr) && - is_data_relocation(r_type)) - return TRUE; - /*-----------------------------------------------------------------------*/ - /* BE -> BE8 - swap instruction relocations */ - /*-----------------------------------------------------------------------*/ - else if (!dyn_module->wrong_endian && - obj_is_be8(&dyn_module->fhdr) && - !is_data_relocation(r_type)) - return TRUE; - /*-----------------------------------------------------------------------*/ - /* LE -> BE32, BE8-> LE, BE32 -> LE - swap all relocations */ - /*-----------------------------------------------------------------------*/ - else if (dyn_module->wrong_endian) - return TRUE; - - /*-----------------------------------------------------------------------*/ - /* BE32 -> BE32, LE -> LE, BE8 -> BE32 - swap nothing */ - /*-----------------------------------------------------------------------*/ - return FALSE; -} - -/*****************************************************************************/ -/* REL_CONCLUDES_GROUP() - Returns true if this relocation type concludes a */ -/* group relocation sequence */ -/*****************************************************************************/ -static BOOL rel_concludes_group(ARM_RELOC_TYPE r_type) -{ - switch (r_type) - { - case R_ARM_ALU_PC_G0: - case R_ARM_ALU_PC_G1: - case R_ARM_ALU_PC_G2: - case R_ARM_LDC_PC_G0: - case R_ARM_LDC_PC_G1: - case R_ARM_LDC_PC_G2: - case R_ARM_LDR_PC_G0: - case R_ARM_LDR_PC_G1: - case R_ARM_LDR_PC_G2: - case R_ARM_LDRS_PC_G0: - case R_ARM_LDRS_PC_G1: - case R_ARM_LDRS_PC_G2: - return TRUE; - default: - return FALSE; - } -} - -/*****************************************************************************/ -/* REL_GROUP_NUM() - Returns group number of this relocation type. */ -/*****************************************************************************/ -static int rel_group_num(ARM_RELOC_TYPE r_type) -{ - switch (r_type) - { - case R_ARM_ALU_PC_G0: - case R_ARM_ALU_PC_G0_NC: - case R_ARM_LDC_PC_G0: - case R_ARM_LDR_PC_G0: - case R_ARM_LDRS_PC_G0: - return 0; - - case R_ARM_ALU_PC_G1: - case R_ARM_ALU_PC_G1_NC: - case R_ARM_LDC_PC_G1: - case R_ARM_LDR_PC_G1: - case R_ARM_LDRS_PC_G1: - return 1; - - case R_ARM_ALU_PC_G2: - case R_ARM_LDC_PC_G2: - case R_ARM_LDR_PC_G2: - case R_ARM_LDRS_PC_G2: - return 2; - - default: - return 0; - } -} - -/*****************************************************************************/ -/* REL_ALU_MASK_OFFSET() - Calculate the offset of an 8-bit mask for an */ -/* ALU immediate value. */ -/*****************************************************************************/ -static uint32_t rel_alu_mask_offset(int32_t residual, int bit_align) -{ - uint32_t mask_offset; - - for (mask_offset = 31; mask_offset > 7; mask_offset--) - if (residual & (0x1 << mask_offset)) break; - mask_offset -= 7; - - if (bit_align == 0) bit_align = 1; - - if ((mask_offset & bit_align) != 0) - mask_offset += (bit_align - (mask_offset % bit_align)); - - return mask_offset; -} - -/*****************************************************************************/ -/* REL_MASK_FOR_GROUP() - Mask off the appropriate bits from reloc_val, */ -/* depending on the group relocation type. */ -/* See Section 4.6.1.4 Group relocations in AAELF */ -/* for more details. */ -/*****************************************************************************/ -static void rel_mask_for_group(ARM_RELOC_TYPE r_type, int32_t* reloc_val) -{ - int32_t curr_residual = *reloc_val; - int num_alu_groups = rel_group_num(r_type) + 1; - int n; - if (rel_concludes_group(r_type)) num_alu_groups--; - - for (n = 0; n < num_alu_groups; n++) - { - uint32_t mask_offset = rel_alu_mask_offset(curr_residual, 2); - uint32_t cres_mask = 0xFF << mask_offset; - - *reloc_val = curr_residual & cres_mask; - - curr_residual = curr_residual & ~cres_mask; - } - - if (rel_concludes_group(r_type)) *reloc_val = curr_residual; - -} - -/*****************************************************************************/ -/* GET_RELOC_SIZE() - Return the container size for this relocation type. */ -/*****************************************************************************/ -static ARM_RELOC_SIZE get_reloc_size(ARM_RELOC_TYPE r_type) -{ - switch (r_type) - { - case R_ARM_THM_ABS5: - case R_ARM_THM_PC8: - case R_ARM_THM_JUMP6: - case R_ARM_THM_JUMP11: - case R_ARM_THM_JUMP8: - return THUMB16_RELOC; - - case R_ARM_THM_CALL: - case R_ARM_THM_JUMP24: - case R_ARM_THM_MOVW_ABS_NC: - case R_ARM_THM_MOVT_ABS: - case R_ARM_THM_MOVW_PREL_NC: - case R_ARM_THM_MOVT_PREL: - case R_ARM_THM_JUMP19: - case R_ARM_THM_ALU_PREL_11_0: - case R_ARM_THM_PC12: - case R_ARM_THM_MOVW_BREL_NC: - case R_ARM_THM_MOVT_BREL: - case R_ARM_THM_MOVW_BREL: - return THUMB32_RELOC; - - case R_ARM_ABS8: - return ARM8_RELOC; - - default: - return ARM_RELOC; - } -} - -/*****************************************************************************/ -/* REL_CHANGE_ENDIAN() - Changes the endianess of the relocation field */ -/* located at address. The size of the field depends */ -/* on the relocation type. */ -/*****************************************************************************/ -static void rel_change_endian(ARM_RELOC_TYPE r_type, uint8_t* address) -{ - ARM_RELOC_SIZE reloc_size = get_reloc_size(r_type); - - switch (reloc_size) - { - case ARM_RELOC: - { - DLIMP_change_endian32((int32_t*)address); - break; - } - - case THUMB32_RELOC: - { - int16_t* ins1_ptr = (int16_t*)address; - DLIMP_change_endian16(ins1_ptr); - DLIMP_change_endian16(ins1_ptr + 1); - break; - } - - case THUMB16_RELOC: - { - DLIMP_change_endian16((int16_t*)address); - break; - } - - default: - break; - } -} - -/*****************************************************************************/ -/* WRITE_RELOC_R() - Write a relocation value to address rel_field_ptr. */ -/* It is assumed that all values have been properly packed */ -/* and masked. */ -/*****************************************************************************/ -static void write_reloc_r(uint8_t* rel_field_ptr, - ARM_RELOC_TYPE r_type, int32_t reloc_val, - uint32_t symval) -{ -#if LOADER_DEBUG - /*-----------------------------------------------------------------------*/ - /* Print some details about the relocation we are about to process. */ - /*-----------------------------------------------------------------------*/ - if(debugging_on) - { - DLIF_trace("RWRT: rel_field_ptr: 0x%x\n", (uint32_t)rel_field_ptr); - DLIF_trace("RWRT: result: 0x%x\n", reloc_val); - } -#endif - - - /*-----------------------------------------------------------------------*/ - /* Given the relocation type, carry out relocation into a 4 byte packet */ - /* within the buffered segment. */ - /*-----------------------------------------------------------------------*/ - switch(r_type) - { - case R_ARM_ABS32: - case R_ARM_REL32: - case R_ARM_REL32_NOI: - case R_ARM_ABS32_NOI: - { - *((uint32_t*)rel_field_ptr) = reloc_val; - break; - } - - case R_ARM_PREL31: - { - *((uint32_t*)rel_field_ptr) |= reloc_val; - break; - } - - case R_ARM_PC24: - case R_ARM_CALL: - case R_ARM_PLT32: - { - /*---------------------------------------------------------------*/ - /* ARM BL/BLX */ - /* reloc_val has already been packed down to 25 bits. If the */ - /* callee is a thumb function, we convert to a BLX. After */ - /* conversion, the field is packed down to 24 bits. */ - /*---------------------------------------------------------------*/ - uint32_t rel_field = *((uint32_t*)rel_field_ptr); - - /*---------------------------------------------------------------*/ - /* Check to see if callee is a thumb function. If so convert to */ - /* BLX */ - /*---------------------------------------------------------------*/ - if (OPND_T(symval)) - rel_field |= 0xF0000000; - - /*---------------------------------------------------------------*/ - /* Clear imm24 bits. This must be done for both BL and BLX */ - /*---------------------------------------------------------------*/ - rel_field &= ~0xFFFFFF; - - if (IS_BLX(rel_field)) - { - uint8_t Hval = reloc_val & 0x1; - /*-----------------------------------------------------------*/ - /* For BLX clear bit 24 (the H bit) */ - /*-----------------------------------------------------------*/ - rel_field &= ~0x01000000; - rel_field |= Hval << 24; - } - - /*---------------------------------------------------------------*/ - /* Pack reloc_val down to 24 bits. */ - /*---------------------------------------------------------------*/ - rel_field |= (reloc_val >> 1); - *((uint32_t*)rel_field_ptr) = rel_field; - break; - } - - case R_ARM_JUMP24: - { - *((uint32_t*)rel_field_ptr) &= ~0xFFFFFF; - *((uint32_t*)rel_field_ptr) |= reloc_val; - break; - } - - case R_ARM_THM_CALL: - case R_ARM_THM_JUMP24: - { - /*---------------------------------------------------------------*/ - /* THUMB B.W/BL/BLX */ - /*---------------------------------------------------------------*/ - uint16_t* rel_field_16_ptr = (uint16_t*) rel_field_ptr; - - uint8_t Sval; - uint8_t J1; - uint8_t J2; - uint16_t imm10; - uint16_t imm11; - - /*---------------------------------------------------------------*/ - /* If callee is a thumb function, convert BL to BLX */ - /*---------------------------------------------------------------*/ - if (!OPND_T(symval) && r_type == R_ARM_THM_CALL) - { - if (reloc_val & 0x1) reloc_val++; - *(rel_field_16_ptr + 1) &= 0xEFFF; - } - - /*---------------------------------------------------------------*/ - /* reloc_val = S:I1:I2:imm10:imm11 */ - /*---------------------------------------------------------------*/ - Sval = (reloc_val >> 23) & 0x1; - J1 = ((reloc_val >> 22) ^ (!Sval)) & 0x1; - J2 = ((reloc_val >> 21) ^ (!Sval)) & 0x1; - imm10 = (reloc_val >> 11) & 0x3FF; - imm11 = reloc_val & 0x7FF; - - *rel_field_16_ptr &= 0xF800; - *rel_field_16_ptr |= (Sval << 10); - *rel_field_16_ptr |= imm10; - - rel_field_16_ptr++; - *rel_field_16_ptr &= 0xD000; - - *rel_field_16_ptr |= (J1 << 13); - *rel_field_16_ptr |= (J2 << 11); - *rel_field_16_ptr |= imm11; - - break; - } - case R_ARM_THM_JUMP19: - { - /*---------------------------------------------------------------*/ - /* THUMB B.W */ - /* reloc_val = S:J2:J1:imm6:imm11:'0' */ - /*---------------------------------------------------------------*/ - uint16_t* rel_field_16_ptr = (uint16_t*) rel_field_ptr; - uint8_t S; - uint8_t J2; - uint8_t J1; - uint8_t imm6; - uint16_t imm11; - - S = (reloc_val >> 19) & 0x1; - J2 = (reloc_val >> 18) & 0x1; - J1 = (reloc_val >> 17) & 0x1; - imm6 = (reloc_val >> 11) & 0x3F; - imm11 = (reloc_val ) & 0x7FF; - - /*---------------------------------------------------------------*/ - /* Clear S and imm6 fields in first part of instruction */ - /*---------------------------------------------------------------*/ - *rel_field_16_ptr &= 0xFBC0; - *rel_field_16_ptr |= (S << 10); - *rel_field_16_ptr |= imm6; - - rel_field_16_ptr++; - - *rel_field_16_ptr &= 0xD800; - *rel_field_16_ptr |= (J2 << 13); - *rel_field_16_ptr |= (J1 << 11); - *rel_field_16_ptr |= imm11; - break; - } - case R_ARM_THM_JUMP11: - { - /*---------------------------------------------------------------*/ - /* THUMB B (unconditional) */ - /*---------------------------------------------------------------*/ - *((uint16_t*)rel_field_ptr) &= ~0x7FF; - *((uint16_t*)rel_field_ptr) |= reloc_val; - break; - } - - case R_ARM_THM_JUMP8: - { - /*---------------------------------------------------------------*/ - /* THUMB B */ - /*---------------------------------------------------------------*/ - *((uint16_t*)rel_field_ptr) &= ~0xFF; - *((uint16_t*)rel_field_ptr) |= reloc_val; - break; - } - - case R_ARM_THM_ABS5: - { - /*---------------------------------------------------------------*/ - /* THUMB LDR , [(,#imm}] */ - /*---------------------------------------------------------------*/ - *((uint16_t*)rel_field_ptr) &= 0xF83F; - *((uint16_t*)rel_field_ptr) |= (reloc_val << 6); - break; - } - - case R_ARM_THM_PC8: - { - /*---------------------------------------------------------------*/ - /* THUMB LDR ,[SP{,#imm}] */ - /*---------------------------------------------------------------*/ - *((uint16_t*)rel_field_ptr) &= 0xFF00; - *((uint16_t*)rel_field_ptr) |= reloc_val; - break; - } - - case R_ARM_THM_JUMP6: - { - /*---------------------------------------------------------------*/ - /* THUMB CBZ,CBNZ */ - /* reloc_field = Ival:imm5 */ - /*---------------------------------------------------------------*/ - uint8_t Ival; - uint8_t imm5; - - Ival = (reloc_val >> 5) & 0x1; - imm5 = (reloc_val & 0x1F); - *((uint16_t*)rel_field_ptr) &= 0xFD07; - *((uint16_t*)rel_field_ptr) |= (Ival << 9); - *((uint16_t*)rel_field_ptr) |= (imm5 << 3); - break; - } - - case R_ARM_ABS16: - { - /*---------------------------------------------------------------*/ - /* 16 bit data relocation */ - /*---------------------------------------------------------------*/ - *((uint16_t*)rel_field_ptr) = reloc_val; - break; - } - - case R_ARM_ABS8: - { - /*---------------------------------------------------------------*/ - /* 8 bit data relocation */ - /*---------------------------------------------------------------*/ - *((uint8_t*)rel_field_ptr) = reloc_val; - break; - } - - case R_ARM_MOVW_ABS_NC: - case R_ARM_MOVT_ABS: - case R_ARM_MOVW_PREL_NC: - case R_ARM_MOVT_PREL: - { - /*---------------------------------------------------------------*/ - /* MOVW/MOVT */ - /*---------------------------------------------------------------*/ - uint8_t imm4 = reloc_val >> 12; - uint16_t imm12 = reloc_val & 0xFFF; - *((uint32_t*)rel_field_ptr) &= 0xFFF0F000; - *((uint32_t*)rel_field_ptr) |= imm12; - *((uint32_t*)rel_field_ptr) |= (imm4 << 16); - break; - } - - case R_ARM_THM_MOVW_ABS_NC: - case R_ARM_THM_MOVT_ABS: - case R_ARM_THM_MOVW_PREL_NC: - case R_ARM_THM_MOVT_PREL: - { - /*----------------------------------------------------------------*/ - /* THUMB2 MOVW/MOVT */ - /*----------------------------------------------------------------*/ - uint16_t* rel_field_16_ptr = (uint16_t*) rel_field_ptr; - - uint8_t imm4 = (reloc_val >> 12); - uint8_t i = (reloc_val >> 11) & 0x1; - uint8_t imm3 = (reloc_val >> 8 ) & 0x7; - uint8_t imm8 = (reloc_val ) & 0xFF; - - *rel_field_16_ptr &= 0xFBF0; - *rel_field_16_ptr |= i << 10; - *rel_field_16_ptr |= imm4; - - rel_field_16_ptr++; - - *rel_field_16_ptr &= 0x8F00; - *rel_field_16_ptr |= imm3 << 12; - *rel_field_16_ptr |= imm8; - - break; - } - - case R_ARM_ABS12: - { - /*----------------------------------------------------------------*/ - /* LDR immediate */ - /* */ - /* We need to know the sign of the relocated value, so we wait to */ - /* to mask off any bits until now. */ - /*----------------------------------------------------------------*/ - uint8_t S = !((reloc_val >> 31) & 0x1); - reloc_val = abs(reloc_val) & 0xFFF; - - *((uint32_t*)rel_field_ptr) &= 0xFF7FF000; - *((uint32_t*)rel_field_ptr) |= reloc_val; - *((uint32_t*)rel_field_ptr) |= (S << 23); - break; - } - - case R_ARM_THM_PC12: - { - /*----------------------------------------------------------------*/ - /* LDR<,B,SB,H,SH> Rd, [PC, #imm] (literal) */ - /* */ - /* We need to know the sign of the relocated value, so we wait to */ - /* to mask off any bits until now. */ - /*----------------------------------------------------------------*/ - uint16_t* rel_field_16_ptr = (uint16_t*) rel_field_ptr; - uint8_t U = (reloc_val < 0) ? 0 : 1; - reloc_val = abs(reloc_val) & 0xFFF; - - *rel_field_16_ptr &= 0xFF7F; - *rel_field_16_ptr |= U << 7; - - rel_field_16_ptr++; - - *rel_field_16_ptr &= 0xF000; - *rel_field_16_ptr |= reloc_val; - - break; - } - - /*--------------------------------------------------------------------*/ - /* ARM GROUP RELOCATIONS. See Section 4.6.1.4 in AAELF for more info */ - /* */ - /* For these relocations, the reloc_val is calculated by */ - /* rel_mask_for_group(). We cannot check for overflow until after */ - /* this has been called, so overflow checking has been delayed until */ - /* now. */ - /*--------------------------------------------------------------------*/ - - case R_ARM_ALU_PC_G0_NC: - case R_ARM_ALU_PC_G0: - case R_ARM_ALU_PC_G1_NC: - case R_ARM_ALU_PC_G2: - { - /*----------------------------------------------------------------*/ - /* ARM ALU (ADD/SUB) */ - /*----------------------------------------------------------------*/ - uint32_t *rel_field_32_ptr = (uint32_t*) rel_field_ptr; - uint32_t mask_offset; - uint8_t Rval = 0; - uint8_t Ival = 0; - - *rel_field_32_ptr &= 0xFF3FF000; - - /******************************************************************/ - /* Change the instruction to ADD or SUB, depending on the sign */ - /******************************************************************/ - if ((int32_t)reloc_val >= 0) - *rel_field_32_ptr |= 0x1 << 23; - else - *rel_field_32_ptr |= 0x1 << 22; - - reloc_val = abs(reloc_val); - rel_mask_for_group(r_type, &reloc_val); - - mask_offset = rel_alu_mask_offset(reloc_val, 2); - - Rval = 32 - mask_offset; - Ival = (reloc_val >> mask_offset) & 0xFF; - - if (reloc_val & ~(0xFF << mask_offset)) - DLIF_error(DLET_RELOC, "relocation overflow\n"); - - *rel_field_32_ptr |= ((Rval >> 1) & 0xF) << 8; - *rel_field_32_ptr |= (Ival & 0xFF); - } - break; - - case R_ARM_LDR_PC_G0: - case R_ARM_LDR_PC_G1: - case R_ARM_LDR_PC_G2: - { - /*----------------------------------------------------------------*/ - /* ARM LDR/STR/LDRB/STRB */ - /*----------------------------------------------------------------*/ - uint8_t Uval = (reloc_val < 0) ? 0 : 1; - uint32_t Lval = 0; - - reloc_val = abs(reloc_val); - - rel_mask_for_group(r_type, &reloc_val); - - if (abs(reloc_val) >= 0x1000) - DLIF_error(DLET_RELOC, "relocation overflow!\n"); - - Lval = reloc_val & 0xFFF; - - *((uint32_t*) rel_field_ptr) &= 0xFF7FF000; - *((uint32_t*) rel_field_ptr) |= Uval << 23; - *((uint32_t*) rel_field_ptr) |= Lval; - } - break; - - case R_ARM_LDRS_PC_G0: - case R_ARM_LDRS_PC_G1: - case R_ARM_LDRS_PC_G2: - { - /*----------------------------------------------------------------*/ - /* ARM LDRD/STRD/LDRH/STRH/LDRSH/LDRSB */ - /*----------------------------------------------------------------*/ - uint8_t Uval = (reloc_val < 0) ? 0 : 1; - uint8_t Hval; - uint8_t Lval; - - reloc_val = abs(reloc_val); - - rel_mask_for_group(r_type, &reloc_val); - - if (abs(reloc_val) >= 0x100) - DLIF_error(DLET_RELOC, "relocation overflow!\n"); - - Hval = (reloc_val >> 4) & 0xF; - Lval = (reloc_val ) & 0xF; - - *((uint32_t*) rel_field_ptr) &= 0xFF7FF0F0; - *((uint32_t*) rel_field_ptr) |= (Uval << 23); - *((uint32_t*) rel_field_ptr) |= (Hval << 8); - *((uint32_t*) rel_field_ptr) |= Lval; - } - break; - - case R_ARM_LDC_PC_G0: - case R_ARM_LDC_PC_G1: - case R_ARM_LDC_PC_G2: - { - /*----------------------------------------------------------------*/ - /* ARM LDC/STC */ - /*----------------------------------------------------------------*/ - uint8_t Uval = (reloc_val < 0) ? 0 : 1; - uint8_t Lval; - - reloc_val = abs(reloc_val); - - rel_mask_for_group(r_type, &reloc_val); - - if (abs(reloc_val) >= 0x1000) - DLIF_error(DLET_RELOC, "relocation overflow!\n"); - - Lval = reloc_val & 0xFF; - - *((uint32_t*) rel_field_ptr) &= 0xFF7FFF00; - *((uint32_t*) rel_field_ptr) |= (Uval << 23); - *((uint32_t*) rel_field_ptr) |= Lval; - } - break; - - /*--------------------------------------------------------------------*/ - /* THUMB2 ALU RELOCATION. This is a big block of code, most of which */ - /* was taken from the linker. The problem is that there are a lot of */ - /* special formats. */ - /*--------------------------------------------------------------------*/ - case R_ARM_THM_ALU_PREL_11_0: - { - /*----------------------------------------------------------------*/ - /* THUMB2 ADR.W */ - /* */ - /* Encode the immediate value as specified in section 4.2 of the */ - /* Thumb2 supplement: "Immediate constants in data-processing */ - /* instructions" */ - /*----------------------------------------------------------------*/ - uint16_t* rel_field_16_ptr = (uint16_t*) rel_field_ptr; - uint16_t imm12; - uint8_t bits_7_0, bits_15_8, bits_23_16, bits_31_24, Ival, - imm3, imm8; - - /*----------------------------------------------------------------*/ - /* Convert to ADD/SUB depending on the sign. */ - /* Clear out the 'i' bit while clearing the ADD/SUB bits */ - /* If SUB, set bits 7 and 5 to 1, else should be 0 */ - /*----------------------------------------------------------------*/ - *rel_field_16_ptr &= 0xFB5F; - if (reloc_val < 0) - *rel_field_16_ptr |= 0x00A0; - - reloc_val = abs(reloc_val); - - /*----------------------------------------------------------------*/ - /* Extract out bits after we take the absolute value. */ - /*----------------------------------------------------------------*/ - bits_7_0 = (reloc_val) & 0xFF; - bits_15_8 = (reloc_val >> 8) & 0xFF; - bits_23_16 = (reloc_val >> 16) & 0xFF; - bits_31_24 = (reloc_val >> 24) & 0xFF; - - /*----------------------------------------------------------------*/ - /* Does the value match the pattern 0x00XY00XY? */ - /*----------------------------------------------------------------*/ - if (bits_23_16 == bits_7_0 && bits_31_24 == 0 && bits_15_8 == 0) - imm12 = (0x1 << 8) | bits_7_0; - - /*----------------------------------------------------------------*/ - /* Does the value match the pattern 0xXY00XY00? */ - /*----------------------------------------------------------------*/ - else if (bits_31_24 == bits_15_8 && bits_23_16 == 0 && bits_7_0 == 0) - imm12 = (0x2 << 8) | bits_7_0; - - /*-----------------------------------------------------------------*/ - /* Does the value match the pattern 0xXYXYXYXY? */ - /*-----------------------------------------------------------------*/ - else if (bits_31_24 == bits_23_16 && bits_31_24 == bits_15_8 && - bits_31_24 == bits_7_0) - imm12 = (0x3 << 8) | bits_7_0; - - /*-----------------------------------------------------------------*/ - /* Finally, check to see if we can encode this immediate as an */ - /* 8-bit shifted value. */ - /*-----------------------------------------------------------------*/ - else if (reloc_val >= 0 && reloc_val <= 255) - imm12 = reloc_val; - else - { - /*-------------------------------------------------------------*/ - /* Calculate the mask for this immediate, then find the */ - /* appropriate rotate and 8-bit immediate value */ - /* (Rval and Sval). */ - /*-------------------------------------------------------------*/ - uint32_t mask_offset = rel_alu_mask_offset( - (uint32_t)reloc_val, 1); - uint8_t Rval = 32 - mask_offset; - uint8_t Sval = (reloc_val >> mask_offset) & 0x7F; - - imm12 = (Rval << 7) | Sval; - - /*-------------------------------------------------------------*/ - /* If overflow occurred, then finding an 8-bit shiftable value */ - /* failed. */ - /*-------------------------------------------------------------*/ - if (reloc_val & ~(0xFF << mask_offset)) - DLIF_error(DLET_RELOC, "relocation overflow!\n"); - } - - Ival = (imm12 >> 11) & 0x1; - imm3 = (imm12 >> 8) & 0x7; - imm8 = (imm12) & 0xFF; - - *rel_field_16_ptr |= Ival << 10; - rel_field_16_ptr++; - *rel_field_16_ptr |= imm3 << 12; - *rel_field_16_ptr |= imm8; - break; - } - - default: - DLIF_error(DLET_RELOC, - "write_reloc_r called with invalid relocation type\n"); - } - -} - -/*****************************************************************************/ -/* PACK_RESULT() - Pack the result of a relocation calculation for storage */ -/* in the relocation field. */ -/*****************************************************************************/ -static int32_t pack_result(int32_t unpacked_result, int r_type) -{ - switch (r_type) - { - case R_ARM_ABS32: - case R_ARM_REL32: - case R_ARM_ABS16: - case R_ARM_ABS8: - case R_ARM_PREL31: - case R_ARM_MOVW_ABS_NC: - case R_ARM_MOVW_PREL_NC: - case R_ARM_THM_MOVW_ABS_NC: - case R_ARM_THM_MOVW_PREL_NC: - case R_ARM_ABS32_NOI: - case R_ARM_REL32_NOI: - case R_ARM_ABS12: - case R_ARM_ALU_PC_G0_NC: - case R_ARM_ALU_PC_G0: - case R_ARM_ALU_PC_G1_NC: - case R_ARM_ALU_PC_G1: - case R_ARM_ALU_PC_G2: - case R_ARM_LDR_PC_G0: - case R_ARM_LDR_PC_G1: - case R_ARM_LDR_PC_G2: - case R_ARM_LDRS_PC_G0: - case R_ARM_LDRS_PC_G1: - case R_ARM_LDRS_PC_G2: - case R_ARM_LDC_PC_G0: - case R_ARM_LDC_PC_G1: - case R_ARM_LDC_PC_G2: - case R_ARM_THM_PC12: - case R_ARM_THM_ALU_PREL_11_0: - return unpacked_result; - - case R_ARM_PC24: - case R_ARM_CALL: - case R_ARM_PLT32: - case R_ARM_THM_CALL: - case R_ARM_THM_JUMP24: - case R_ARM_THM_JUMP11: - case R_ARM_THM_JUMP8: - case R_ARM_THM_JUMP6: - case R_ARM_THM_JUMP19: - return unpacked_result >> 1; - - case R_ARM_JUMP24: - case R_ARM_THM_ABS5: - case R_ARM_THM_PC8: - return unpacked_result >> 2; - - case R_ARM_MOVT_ABS: - case R_ARM_MOVT_PREL: - case R_ARM_THM_MOVT_ABS: - case R_ARM_THM_MOVT_PREL: - return unpacked_result >> 16; - - default: - DLIF_error(DLET_RELOC, - "pack_result called with invalid relocation type!\n"); - return 0; - } - -} - -/*****************************************************************************/ -/* MASK_RESULT() - Mask the result of a relocation calculation so that it */ -/* fits the size of the relocation type's field. */ -/*****************************************************************************/ -static int32_t mask_result(int32_t unmasked_result, int r_type) -{ - switch (r_type) - { - case R_ARM_ABS8: - case R_ARM_THM_JUMP8: - case R_ARM_THM_PC8: - return unmasked_result & 0xFF; - - case R_ARM_ABS16: - case R_ARM_MOVW_ABS_NC: - case R_ARM_MOVT_ABS: - case R_ARM_MOVW_PREL_NC: - case R_ARM_MOVT_PREL: - case R_ARM_THM_MOVW_ABS_NC: - case R_ARM_THM_MOVT_ABS: - case R_ARM_THM_MOVW_PREL_NC: - case R_ARM_THM_MOVT_PREL: - return unmasked_result & 0xFFFF; - - case R_ARM_ABS32: - case R_ARM_REL32: - case R_ARM_ABS32_NOI: - case R_ARM_REL32_NOI: - case R_ARM_ABS12: - case R_ARM_ALU_PC_G0_NC: - case R_ARM_ALU_PC_G0: - case R_ARM_ALU_PC_G1_NC: - case R_ARM_ALU_PC_G1: - case R_ARM_ALU_PC_G2: - case R_ARM_LDR_PC_G0: - case R_ARM_LDR_PC_G1: - case R_ARM_LDR_PC_G2: - case R_ARM_LDRS_PC_G0: - case R_ARM_LDRS_PC_G1: - case R_ARM_LDRS_PC_G2: - case R_ARM_LDC_PC_G0: - case R_ARM_LDC_PC_G1: - case R_ARM_LDC_PC_G2: - case R_ARM_THM_PC12: - case R_ARM_THM_ALU_PREL_11_0: - return unmasked_result; - - case R_ARM_PREL31: - return unmasked_result & 0x7FFFFFFF; - - case R_ARM_CALL: - case R_ARM_PC24: - case R_ARM_THM_CALL: - case R_ARM_THM_JUMP24: - return unmasked_result & 0x01FFFFFF; - - case R_ARM_JUMP24: - return unmasked_result & 0x00FFFFFF; - - case R_ARM_THM_JUMP11: - return unmasked_result & 0x7FF; - - case R_ARM_THM_ABS5: - return unmasked_result & 0x1F; - - case R_ARM_THM_JUMP6: - return unmasked_result & 0x3F; - - case R_ARM_THM_JUMP19: - return unmasked_result & 0xFFFFF; - - default: - DLIF_error(DLET_RELOC, - "mask_result invalid relocation type!\n"); - return 0; - } - -} - - -/*****************************************************************************/ -/* OVERFLOW() - Check relocation value against the range associated with a */ -/* given relocation type field size and signedness. */ -/*****************************************************************************/ -static BOOL rel_overflow(ARM_RELOC_TYPE r_type, int32_t reloc_value) -{ - switch(r_type) - { - uint32_t sbits; - case R_ARM_JUMP24: - case R_ARM_CALL: - case R_ARM_PC24: - { - sbits = reloc_value >> 25; - return (sbits != 0 && sbits != -1UL); - } - case R_ARM_THM_CALL: - case R_ARM_THM_JUMP24: - { - sbits = reloc_value >> 24; - return (sbits != 0 && sbits != -1UL); - } - case R_ARM_THM_JUMP19: - { - sbits = reloc_value >> 20; - return (sbits != 0 && sbits != -1UL); - } - case R_ARM_ABS12: - case R_ARM_THM_PC12: - { - return abs(reloc_value) >= 0x1000; - } - case R_ARM_PREL31: - { - sbits = reloc_value >> 30; - return (sbits != 0 && sbits != -1UL); - } - - case R_ARM_ABS16: - { - return ((reloc_value > 65535) || - (reloc_value < -32768)); - } - case R_ARM_ABS8: - { - return ((reloc_value > 255) || - (reloc_value < -128)); - } - - default: - return FALSE; - } -} - -/*****************************************************************************/ -/* RELOC_DO() - Process a single relocation entry. */ -/*****************************************************************************/ -static void reloc_do(ARM_RELOC_TYPE r_type, uint8_t* address, - uint32_t addend, uint32_t symval, uint32_t pc, - uint32_t base_pointer) -{ - int32_t reloc_value = 0; - -#if LOADER_DEBUG || LOADER_PROFILE - /*-----------------------------------------------------------------------*/ - /* In debug mode, keep a count of the number of relocations processed. */ - /* In profile mode, start the clock on a given relocation. */ - /*-----------------------------------------------------------------------*/ - int start_time; - if (debugging_on || profiling_on) - { - DLREL_relocations++; - if (profiling_on) start_time = clock(); - } -#endif - - /*-----------------------------------------------------------------------*/ - /* Calculate the relocation value according to the rules associated with */ - /* the given relocation type. */ - /*-----------------------------------------------------------------------*/ - switch(r_type) - { - case R_ARM_NONE: - reloc_value = addend; - break; - - /*-------------------------------------------------------------------*/ - /* S + A */ - /*-------------------------------------------------------------------*/ - case R_ARM_ABS16: - case R_ARM_ABS12: - case R_ARM_THM_ABS5: - case R_ARM_ABS8: - case R_ARM_MOVT_ABS: - case R_ARM_THM_MOVT_ABS: - case R_ARM_ABS32_NOI: - case R_ARM_PLT32_ABS: - reloc_value = OPND_S(symval) + addend; - break; - - /*-------------------------------------------------------------------*/ - /* (S + A) | T */ - /*-------------------------------------------------------------------*/ - case R_ARM_ABS32: - case R_ARM_MOVW_ABS_NC: - case R_ARM_THM_MOVW_ABS_NC: - reloc_value = (OPND_S(symval) + addend) | OPND_T(symval); - break; - - /*-------------------------------------------------------------------*/ - /* (S + A) - P */ - /*-------------------------------------------------------------------*/ - case R_ARM_LDR_PC_G0: - case R_ARM_LDR_PC_G1: - case R_ARM_LDR_PC_G2: - case R_ARM_MOVT_PREL: - case R_ARM_THM_MOVT_PREL: - case R_ARM_REL32_NOI: - case R_ARM_THM_JUMP6: - case R_ARM_THM_JUMP11: - case R_ARM_THM_JUMP8: - case R_ARM_LDRS_PC_G0: - case R_ARM_LDRS_PC_G1: - case R_ARM_LDRS_PC_G2: - case R_ARM_LDC_PC_G0: - case R_ARM_LDC_PC_G1: - case R_ARM_LDC_PC_G2: - reloc_value = (OPND_S(symval) + addend) - pc; - break; - - /*-------------------------------------------------------------------*/ - /* (S + A) - Pa */ - /*-------------------------------------------------------------------*/ - case R_ARM_THM_PC8: - case R_ARM_THM_PC12: - reloc_value = (OPND_S(symval) + addend) - (pc & 0xFFFFFFFC); - break; - - /*-------------------------------------------------------------------*/ - /* ((S + A) | T) - P */ - /*-------------------------------------------------------------------*/ - case R_ARM_REL32: - case R_ARM_PC24: - case R_ARM_THM_CALL: - case R_ARM_PLT32: - case R_ARM_CALL: - case R_ARM_JUMP24: - case R_ARM_THM_JUMP24: - case R_ARM_PREL31: - case R_ARM_MOVW_PREL_NC: - case R_ARM_THM_MOVW_PREL_NC: - case R_ARM_THM_JUMP19: - case R_ARM_THM_ALU_PREL_11_0: - case R_ARM_ALU_PC_G0_NC: - case R_ARM_ALU_PC_G0: - case R_ARM_ALU_PC_G1_NC: - case R_ARM_ALU_PC_G1: - case R_ARM_ALU_PC_G2: - reloc_value = ((OPND_S(symval) + addend) | OPND_T(symval)) - pc; - break; - - /*--------------------------------------------------------------------*/ - /* Unrecognized relocation type. */ - /*--------------------------------------------------------------------*/ - default: - DLIF_error(DLET_RELOC,"invalid relocation type!\n"); - break; - - } - - if (rel_overflow(r_type, reloc_value)) - DLIF_error(DLET_RELOC, "relocation overflow!\n"); - - /*-----------------------------------------------------------------------*/ - /* Move relocation value to appropriate offset for relocation field's */ - /* location. */ - /*-----------------------------------------------------------------------*/ - reloc_value = pack_result(reloc_value, r_type); - - /*-----------------------------------------------------------------------*/ - /* Mask packed result to the size of the relocation field. */ - /*-----------------------------------------------------------------------*/ - reloc_value = mask_result(reloc_value, r_type); - - /*-----------------------------------------------------------------------*/ - /* Write the relocated 4-byte packet back to the segment buffer. */ - /*-----------------------------------------------------------------------*/ - write_reloc_r(address, r_type, reloc_value, symval); - -#if LOADER_DEBUG || LOADER_PROFILE - /*-----------------------------------------------------------------------*/ - /* In profile mode, add elapsed time for this relocation to total time */ - /* spent doing relocations. */ - /*-----------------------------------------------------------------------*/ - if (profiling_on) - DLREL_total_reloc_time += (clock() - start_time); - if (debugging_on) - DLIF_trace("reloc_value = 0x%x\n", reloc_value); -#endif -} - -/*****************************************************************************/ -/* REL_UNPACK_ADDEND() - Unpacks the addend from the relocation field */ -/*****************************************************************************/ -static void rel_unpack_addend(ARM_RELOC_TYPE r_type, - uint8_t* address, - uint32_t* addend) -{ - switch (r_type) - { - case R_ARM_ABS32: - case R_ARM_REL32: - case R_ARM_ABS32_NOI: - case R_ARM_REL32_NOI: - { - DLIF_trace("rel_unpack_addend %d\n", __LINE__); - *addend = *((uint32_t*)address); - DLIF_trace("rel_unpack_addend %d\n", __LINE__); - } - break; - - case R_ARM_ABS16: - { - *addend = *((uint16_t*)address); - *addend = SIGN_EXTEND(*addend, 16); - } - break; - - case R_ARM_ABS8: - { - *addend = *address; - *addend = SIGN_EXTEND(*addend, 8); - } - break; - - case R_ARM_CALL: - case R_ARM_PC24: - case R_ARM_PLT32: - case R_ARM_JUMP24: - { - uint32_t rel_field = *((uint32_t*)address); - uint32_t imm24; - uint8_t Hval; - if (IS_BLX(rel_field)) - Hval = EXTRACT(rel_field, 24, 1); - else - Hval = 0x0; - - imm24 = EXTRACT(rel_field, 0, 24); - *addend = (((imm24 << 1) + Hval) << 1); - SIGN_EXTEND(*addend, 26); - } - break; - - case R_ARM_THM_JUMP11: - { - *addend = EXTRACT(*((uint16_t*)address), 0, 11); - *addend = *addend << 1; - SIGN_EXTEND(*addend, 12); - break; - } - - case R_ARM_THM_JUMP8: - { - *addend = EXTRACT(*((uint16_t*)address), 0, 8); - *addend = *addend << 1; - SIGN_EXTEND(*addend, 9); - break; - } - - case R_ARM_THM_CALL: - case R_ARM_THM_JUMP24: - { - uint16_t* rel_field_ptr = (uint16_t *) address; - - uint8_t Sval; - uint16_t imm10; - uint8_t I1; - uint8_t I2; - uint16_t imm11; - - Sval = EXTRACT(*rel_field_ptr, 10, 1); - imm10 = EXTRACT(*rel_field_ptr, 0, 10); - rel_field_ptr++; - I1 = !(EXTRACT(*rel_field_ptr, 13, 1) ^ Sval); - I2 = !(EXTRACT(*rel_field_ptr, 11, 1) ^ Sval); - imm11 = EXTRACT(*rel_field_ptr, 0, 11); - - *addend = (Sval << 23) | (I1 << 22) | (I2 << 21) | - (imm10 << 11) | imm11; - *addend = *addend << 1; - SIGN_EXTEND(*addend, 25); - break; - } - - case R_ARM_THM_JUMP19: - { - uint16_t* rel_field_ptr = (uint16_t *) address; - - uint8_t Sval; - uint8_t imm6; - uint8_t J1; - uint8_t J2; - uint16_t imm11; - - Sval = EXTRACT(*rel_field_ptr, 10, 1); - imm6 = EXTRACT(*rel_field_ptr, 0, 6); - rel_field_ptr++; - J1 = EXTRACT(*rel_field_ptr, 13, 1); - J2 = EXTRACT(*rel_field_ptr, 11, 1); - imm11 = EXTRACT(*rel_field_ptr, 0, 11); - - *addend = (Sval << 19) | (J2 << 18) | (J1 << 17) | - (imm6 << 11) | imm11; - *addend = *addend << 1; - SIGN_EXTEND(*addend, 21); - } - break; - - case R_ARM_LDR_PC_G0: - case R_ARM_LDR_PC_G1: - case R_ARM_LDR_PC_G2: - case R_ARM_ABS12: - { - uint8_t Uval; - uint16_t imm12; - - uint32_t* rel_field_ptr = (uint32_t*) address; - - Uval = EXTRACT(*rel_field_ptr, 23, 1); - imm12 = EXTRACT(*rel_field_ptr, 0, 12); - - *addend = (Uval == 1) ? imm12 : -((int32_t)(imm12)); - } - break; - - case R_ARM_THM_PC12: - { - uint8_t Uval; - uint16_t imm12; - uint16_t* rel_field_ptr = (uint16_t*) address; - - Uval = EXTRACT(*rel_field_ptr, 7, 1); - rel_field_ptr++; - imm12 = EXTRACT(*rel_field_ptr, 0, 12); - - *addend = (Uval == 1) ? imm12 : -((int32_t)imm12); - break; - } - - case R_ARM_LDRS_PC_G0: - case R_ARM_LDRS_PC_G1: - case R_ARM_LDRS_PC_G2: - { - uint8_t Uval; - uint8_t imm4H; - uint8_t imm4L; - uint32_t* rel_field_ptr = (uint32_t*) address; - - Uval = EXTRACT(*rel_field_ptr, 23, 1); - imm4H = EXTRACT(*rel_field_ptr, 8, 4); - imm4L = EXTRACT(*rel_field_ptr, 0, 4); - - *addend = (imm4H << 4) | imm4L; - if (Uval == 0) *addend = -(*addend); - } - break; - - case R_ARM_LDC_PC_G0: - case R_ARM_LDC_PC_G1: - case R_ARM_LDC_PC_G2: - { - uint8_t Uval; - uint16_t imm8; - uint32_t* rel_field_ptr = (uint32_t*) address; - - Uval = EXTRACT(*rel_field_ptr, 23, 1); - imm8 = EXTRACT(*rel_field_ptr, 0, 8); - - *addend = (Uval == 1) ? imm8 : -((int32_t)imm8); - } - break; - - case R_ARM_ALU_PC_G0_NC: - case R_ARM_ALU_PC_G0: - case R_ARM_ALU_PC_G1_NC: - case R_ARM_ALU_PC_G1: - case R_ARM_ALU_PC_G2: - { - uint8_t Rval; - uint8_t Ival; - uint32_t rel_field = *((uint32_t*)address); - - Rval = EXTRACT(rel_field, 8, 4); - Ival = EXTRACT(rel_field, 0, 8); - - *addend = (Ival >> Rval) | (Ival << (32 - Rval)); - - if (EXTRACT(rel_field, 22, 2) == 1) - *addend = -(*addend); - } - break; - - case R_ARM_MOVW_ABS_NC: - case R_ARM_MOVT_ABS: - case R_ARM_MOVW_PREL_NC: - case R_ARM_MOVT_PREL: - { - uint8_t Ival; - uint16_t Jval; - uint32_t rel_field = *((uint32_t*)address); - Ival = EXTRACT(rel_field, 16, 4); - Jval = EXTRACT(rel_field, 0, 12); - - *addend = (Ival << 12) | Jval; - SIGN_EXTEND(*addend, 16); - } - break; - - case R_ARM_THM_MOVW_ABS_NC: - case R_ARM_THM_MOVT_ABS: - case R_ARM_THM_MOVW_PREL_NC: - case R_ARM_THM_MOVT_PREL: - { - uint8_t Ival; - uint8_t Jval; - uint8_t Kval; - uint8_t Lval; - - uint16_t* rel_field_ptr = (uint16_t*)address; - uint16_t rel_field = *rel_field_ptr; - - Ival = EXTRACT(rel_field, 0, 4); - Jval = EXTRACT(rel_field, 10, 1); - - rel_field = *(rel_field_ptr + 1); - Kval = EXTRACT(rel_field, 12, 3); - Lval = EXTRACT(rel_field, 0, 8); - - *addend = (Ival << 12) | (Jval << 11) | (Kval << 8) | Lval; - SIGN_EXTEND(*addend, 16); - } - break; - - case R_ARM_THM_ALU_PREL_11_0: - { - uint8_t Ival; - uint8_t Jval; - uint8_t Kval; - uint16_t imm12; - uint16_t* rel_field_ptr = (uint16_t*)address; - uint16_t rel_field = *rel_field_ptr; - uint8_t bits_11_10; - - Ival = EXTRACT(rel_field, 12, 3); - - rel_field = *(rel_field_ptr + 1); - Jval = EXTRACT(rel_field, 12, 3); - Kval = EXTRACT(rel_field, 0 , 8); - - imm12 = (Ival << 11) | (Jval << 8) | Kval; - - /*---------------------------------------------------------------*/ - /* Now that we've unpacked the immediate value, we need to */ - /* decode it according to section 4.2 in the Thumb2 supplement: */ - /* "Immediate constants in data-processing instructions" */ - /*---------------------------------------------------------------*/ - bits_11_10 = (imm12 >> 10) & 0x3; - - if (bits_11_10 == 0x0) - { - uint8_t bits_9_8 = (imm12 >> 8) & 0x3; - uint8_t bits_7_0 = (imm12) & 0xFF; - - switch (bits_9_8) - { - case 0x0: *addend = bits_7_0; - break; - case 0x1: *addend = (bits_7_0 << 16) | (bits_7_0); - break; - case 0x2: *addend = (bits_7_0 << 24) | (bits_7_0 << 8); - break; - case 0x3: *addend= (bits_7_0 << 24) | (bits_7_0 << 16) | - (bits_7_0 << 8) | (bits_7_0); - break; - } - } - else - { - uint8_t bits_6_0 = (imm12) & 0x7F; - uint8_t bits_11_7 = (imm12 >> 7) & 0x1F; - - uint8_t byte = 0x80 | bits_6_0; - *addend = (byte >> bits_11_7) | (byte << (32 - bits_11_7)); - } - - rel_field = *rel_field_ptr; - - if (EXTRACT(rel_field, 7, 1) == 1 && - EXTRACT(rel_field, 5, 1) == 1) - *addend = -(*addend); - } - break; - - case R_ARM_THM_JUMP6: - { - uint8_t Ival; - uint8_t Jval; - - uint16_t rel_field = *((uint16_t*)address); - - Ival = EXTRACT(rel_field, 9, 1); - Jval = EXTRACT(rel_field, 3, 5); - - *addend = ((Ival << 5) | Jval) << 1; - *addend = ((*addend + 4) & 0x7F) - 4; - - } - break; - - case R_ARM_THM_ABS5: - { - uint16_t rel_field = *((uint16_t*)address); - *addend = EXTRACT(rel_field, 6, 5); - *addend = *addend << 2; - break; - } - - case R_ARM_THM_PC8: - { - uint16_t rel_field = *((uint16_t*)address); - *addend = EXTRACT(rel_field, 0, 8); - *addend = *addend << 2; - *addend = ((*addend + 4) & 0x3FF) - 4; - - break; - } - - case R_ARM_PREL31: - { - uint32_t rel_field = *((uint32_t*)address); - *addend = EXTRACT(rel_field, 0, 31); - SIGN_EXTEND(*addend, 31); - break; - } - - default: - DLIF_error(DLET_RELOC, - "ERROR: Cannot unpack addend for relocation type %d\n", - r_type); - } -} - -/*****************************************************************************/ -/* PROCESS_REL_TABLE() - Process REL type relocation table. */ -/*****************************************************************************/ -static BOOL process_rel_table(DLOAD_HANDLE handle, - DLIMP_Loaded_Segment* seg, - struct Elf32_Rel* rel_table, - uint32_t relnum, - int32_t *start_rid, - DLIMP_Dynamic_Module* dyn_module) -{ - Elf32_Addr seg_start_addr = seg->input_vaddr; - Elf32_Addr seg_end_addr = seg_start_addr + seg->phdr.p_memsz; - BOOL found = FALSE; - int32_t rid = *start_rid; - - if (rid >= relnum) rid = 0; - - for ( ; rid < relnum; rid++) - { - /*---------------------------------------------------------------*/ - /* If the relocation offset falls within the segment, process it */ - /*---------------------------------------------------------------*/ - if (rel_table[rid].r_offset >= seg_start_addr && - rel_table[rid].r_offset < seg_end_addr) - { - Elf32_Addr r_symval; - ARM_RELOC_TYPE r_type = ELF32_R_TYPE(rel_table[rid].r_info); - int32_t r_symid = ELF32_R_SYM(rel_table[rid].r_info); - uint8_t* reloc_address; - uint32_t pc; - uint32_t addend; - BOOL change_endian; - - found = TRUE; - - /*---------------------------------------------------------*/ - /* If symbol definition is not found don't do the */ - /* relocation. An error is generated by the lookup */ - /* function. */ - /*---------------------------------------------------------*/ - if (!DLSYM_canonical_lookup(handle, r_symid, dyn_module, &r_symval)) - continue; - - reloc_address = - (((uint8_t*)(seg->phdr.p_vaddr) + seg->reloc_offset) + - rel_table[rid].r_offset - seg->input_vaddr); - pc = (uint32_t) reloc_address; - change_endian = rel_swap_endian(dyn_module, r_type); - if (change_endian) - rel_change_endian(r_type, reloc_address); - - rel_unpack_addend(ELF32_R_TYPE(rel_table[rid].r_info), - reloc_address, - &addend); - -#if LOADER_DEBUG || LOADER_PROFILE - if (debugging_on) - { - char *r_symname = (char*) dyn_module->symtab[r_symid].st_name; - DLIF_trace("r_type=%d, " - "pc=0x%x, " - "addend=0x%x, " - "symnm=%s, " - "symval=0x%x\n", - r_type, - pc, - addend, - r_symname, - r_symval); - } -#endif - /*----------------------------------------------------------*/ - /* Perform actual relocation. This is a really wide */ - /* function interface and could do with some encapsulation. */ - /*----------------------------------------------------------*/ - reloc_do(r_type, - reloc_address, - addend, - r_symval, - pc, - 0 /* static base, not yet supported */); - - - if (change_endian) - rel_change_endian(r_type, reloc_address); - - } - else if (found) - break; - } - - *start_rid = rid; - return found; -} - -static BOOL process_rela_table(DLOAD_HANDLE handle, - DLIMP_Loaded_Segment* seg, - struct Elf32_Rela* rela_table, - uint32_t relanum, - int32_t* start_rid, - DLIMP_Dynamic_Module* dyn_module) -{ - Elf32_Addr seg_start_addr = seg->input_vaddr; - Elf32_Addr seg_end_addr = seg_start_addr + seg->phdr.p_memsz; - BOOL found = FALSE; - int32_t rid = *start_rid; - - if (rid >= relanum) rid = 0; - - for ( ; rid < relanum; rid++) - { - /*---------------------------------------------------------------*/ - /* If the relocation offset falls within the segment, process it */ - /*---------------------------------------------------------------*/ - if (rela_table[rid].r_offset >= seg_start_addr && - rela_table[rid].r_offset < seg_end_addr) - { - Elf32_Addr r_symval; - ARM_RELOC_TYPE r_type = ELF32_R_TYPE(rela_table[rid].r_info); - int32_t r_symid = ELF32_R_SYM(rela_table[rid].r_info); - uint8_t* reloc_address; - uint32_t pc; - uint32_t addend; - BOOL change_endian; - - found = TRUE; - - /*---------------------------------------------------------*/ - /* If symbol definition is not found don't do the */ - /* relocation. An error is generated by the lookup */ - /* function. */ - /*---------------------------------------------------------*/ - if (!DLSYM_canonical_lookup(handle, r_symid, dyn_module, &r_symval)) - continue; - - reloc_address = (((uint8_t*)(seg->phdr.p_vaddr) + seg->reloc_offset) + - rela_table[rid].r_offset - seg->input_vaddr); - pc = (uint32_t) reloc_address; - addend = rela_table[rid].r_addend; - - change_endian = rel_swap_endian(dyn_module, r_type); - if (change_endian) - rel_change_endian(r_type, reloc_address); - -#if LOADER_DEBUG || LOADER_PROFILE - if (debugging_on) - { - char *r_symname = (char*) dyn_module->symtab[r_symid].st_name; - DLIF_trace("r_type=%d, " - "pc=0x%x, " - "addend=0x%x, " - "symnm=%s, " - "symval=0x%x\n", - r_type, - pc, - addend, - r_symname, - r_symval); - } -#endif - - /*----------------------------------------------------------*/ - /* Perform actual relocation. This is a really wide */ - /* function interface and could do with some encapsulation. */ - /*----------------------------------------------------------*/ - - reloc_do(ELF32_R_TYPE(rela_table[rid].r_info), - reloc_address, - addend, - r_symval, - pc, - 0); - - - if (change_endian) - rel_change_endian(r_type, reloc_address); - } - else if (found) - break; - } - - *start_rid = rid; - return found; -} - -/*****************************************************************************/ -/* READ_REL_TABLE() - */ -/* */ -/* Read in a REL type relocation table. This function allocates host */ -/* memory for the table. */ -/*****************************************************************************/ -static void read_rel_table(struct Elf32_Rel** rel_table, - int32_t table_offset, - uint32_t relnum, uint32_t relent, - LOADER_FILE_DESC* elf_file, - BOOL wrong_endian) -{ - int i; - *rel_table = (struct Elf32_Rel*) DLIF_malloc(relnum*relent); - if (NULL == *rel_table) { - DLIF_error(DLET_MEMORY,"Failed to Allocate read_rel_table\n"); - return; - } - DLIF_fseek(elf_file, table_offset, LOADER_SEEK_SET); - DLIF_fread(*rel_table, relnum, relent, elf_file); - - if (wrong_endian) - for (i=0; iloaded_module->loaded_segments.buf); - int seg_size = dyn_module->loaded_module->loaded_segments.size; - int32_t rel_rid = 0; - int32_t rela_rid = 0; - int s; - - for (s=0; sr_offset : - ((struct Elf32_Rela*) plt_reloc_table)->r_offset; - DLIMP_Loaded_Segment* seg = - (DLIMP_Loaded_Segment*)(dyn_module->loaded_module->loaded_segments.buf); - int seg_size = dyn_module->loaded_module->loaded_segments.size; - int32_t plt_rid = 0; - int s; - - /*-----------------------------------------------------------------------*/ - /* For each segment s, check if the relocation falls within s. If so, */ - /* then all other relocations are guaranteed to fall with s. Process */ - /* all relocations and then return. */ - /*-----------------------------------------------------------------------*/ - - for (s=0; s= seg_start_addr && - r_offset < seg_end_addr) - { - if (reltype == DT_REL) - process_rel_table(handle, (seg + s), - (struct Elf32_Rel*) plt_reloc_table, - pltnum, &plt_rid, - dyn_module); - else - process_rela_table(handle, (seg + s), - (struct Elf32_Rela*) plt_reloc_table, - pltnum, &plt_rid, - dyn_module); - - break; - } - } -} - -/*****************************************************************************/ -/* RELOCATE() - Perform RELA and REL type relocations for given ELF object */ -/* file that we are in the process of loading and relocating. */ -/*****************************************************************************/ -void DLREL_relocate(DLOAD_HANDLE handle, - LOADER_FILE_DESC* elf_file, - DLIMP_Dynamic_Module* dyn_module) - -{ - struct Elf32_Dyn* dyn_nugget = dyn_module->dyntab; - struct Elf32_Rela* rela_table = NULL; - struct Elf32_Rel* rel_table = NULL; - void* plt_table = NULL; - - /*-----------------------------------------------------------------------*/ - /* Read the size of the relocation table (DT_RELASZ) and the size per */ - /* relocation (DT_RELAENT) from the dynamic segment. */ - /*-----------------------------------------------------------------------*/ - uint32_t relasz = DLIMP_get_first_dyntag(DT_RELASZ, dyn_nugget); - uint32_t relaent = DLIMP_get_first_dyntag(DT_RELAENT, dyn_nugget); - uint32_t relanum = 0; - - /*-----------------------------------------------------------------------*/ - /* Read the size of the relocation table (DT_RELSZ) and the size per */ - /* relocation (DT_RELENT) from the dynamic segment. */ - /*-----------------------------------------------------------------------*/ - uint32_t relsz = DLIMP_get_first_dyntag(DT_RELSZ, dyn_nugget); - uint32_t relent = DLIMP_get_first_dyntag(DT_RELENT, dyn_nugget); - uint32_t relnum = 0; - - /*-----------------------------------------------------------------------*/ - /* Read the size of the relocation table (DT_PLTRELSZ) and the type of */ - /* of the PLTGOT relocation table (DT_PLTREL): one of DT_REL or DT_RELA */ - /*-----------------------------------------------------------------------*/ - uint32_t pltrelsz = DLIMP_get_first_dyntag(DT_PLTRELSZ, dyn_nugget); - int pltreltype = DLIMP_get_first_dyntag(DT_PLTREL, dyn_nugget); - uint32_t pltnum = 0; - - /*-----------------------------------------------------------------------*/ - /* Read the PLTGOT relocation table from the file */ - /* The PLTGOT table is a subsection at the end of either the DT_REL or */ - /* DT_RELA table. The size of the table it belongs to DT_REL(A)SZ */ - /* includes the size of the PLTGOT table. So it must be adjusted so that*/ - /* the GOT relocation tables only contain actual GOT relocations. */ - /*-----------------------------------------------------------------------*/ - if (pltrelsz != INT_MAX) - { - if (pltreltype == DT_REL) - { - pltnum = pltrelsz/relent; - relsz -= pltrelsz; - read_rel_table(((struct Elf32_Rel**) &plt_table), - DLIMP_get_first_dyntag(DT_JMPREL, dyn_nugget), - pltnum, relent, elf_file, - dyn_module->wrong_endian); - } - else if (pltreltype == DT_RELA) - { - pltnum = pltrelsz/relaent; - relasz -= pltrelsz; - read_rela_table(((struct Elf32_Rela**) &plt_table), - DLIMP_get_first_dyntag(DT_JMPREL, dyn_nugget), - pltnum, relaent, elf_file, - dyn_module->wrong_endian); - } - else - { - DLIF_error(DLET_RELOC, - "DT_PLTREL is invalid: must be either %d or %d\n", - DT_REL, DT_RELA); - } - } - - /*-----------------------------------------------------------------------*/ - /* Read the DT_RELA GOT relocation table from the file */ - /*-----------------------------------------------------------------------*/ - if (relasz != INT_MAX) - { - relanum = relasz/relaent; - read_rela_table(&rela_table, - DLIMP_get_first_dyntag(DT_RELA, dyn_nugget), - relanum, relaent, elf_file, dyn_module->wrong_endian); - } - - /*-----------------------------------------------------------------------*/ - /* Read the DT_REL GOT relocation table from the file */ - /*-----------------------------------------------------------------------*/ - if (relsz != INT_MAX) - { - relnum = relsz/relent; - read_rel_table(&rel_table, DLIMP_get_first_dyntag(DT_REL, dyn_nugget), - relnum, relent, elf_file, dyn_module->wrong_endian); - } - - /*------------------------------------------------------------------------*/ - /* Process the PLTGOT relocations */ - /*------------------------------------------------------------------------*/ - if (plt_table) - process_pltgot_relocs(handle, plt_table, pltreltype, pltnum, dyn_module); - - /*-----------------------------------------------------------------------*/ - /* Process the GOT relocations */ - /*-----------------------------------------------------------------------*/ - if (rel_table || rela_table) - process_got_relocs(handle, rel_table, relnum, rela_table, relanum, - dyn_module); - - /*------------------------------------------------------------------------*/ - /* Free memory used for ELF relocation table copies. */ - /*------------------------------------------------------------------------*/ - if (rela_table) DLIF_free(rela_table); - if (rel_table) DLIF_free(rel_table); - if (plt_table) DLIF_free(plt_table); -} - -/*****************************************************************************/ -/* UNIT TESTING INTERFACE. */ -/*****************************************************************************/ -#if UNIT_TEST -void unit_arm_reloc_do(ARM_RELOC_TYPE r_type, - uint8_t* address_space, - uint32_t addend, uint32_t symval, uint32_t pc, - uint32_t static_base, int wrong_endian) -{ - reloc_do(r_type, address_space, addend, symval, pc, static_base); -} - -void unit_arm_rel_unpack_addend(ARM_RELOC_TYPE r_type, - uint8_t* address, - uint32_t* addend) -{ - rel_unpack_addend(r_type, address, addend); -} - -BOOL unit_arm_rel_overflow(ARM_RELOC_TYPE r_type, int32_t reloc_value) -{ - return rel_overflow(r_type, reloc_value); -} - -void unit_arm_rel_mask_for_group(ARM_RELOC_TYPE r_type, int32_t* reloc_val) -{ - rel_mask_for_group(r_type, reloc_val); -} -#endif diff --git a/src/utils/elfload/c60_dynamic.c b/src/utils/elfload/c60_dynamic.c deleted file mode 100644 index d66e5a3..0000000 --- a/src/utils/elfload/c60_dynamic.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - * c60_dynamic.c - * - * C6x-specific dynamic loader functionality - * - * Copyright (C) 2009 Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef C60_TARGET -#include "c60_elf32.h" -#if defined (__KERNEL__) -#include -#else -#include -#include -#endif -#include "dload_api.h" -#include "dload.h" - -/*****************************************************************************/ -/* c60_process_dynamic_tag() */ -/* */ -/* Process C6x specific dynamic tags. */ -/*****************************************************************************/ -BOOL DLDYN_c60_process_dynamic_tag(DLIMP_Dynamic_Module* dyn_module, int i) -{ - switch (dyn_module->dyntab[i].d_tag) - { - /*------------------------------------------------------------------*/ - /* DT_C6000_GSYM_OFFSET: Dynamic symbol table is partitioned into */ - /* local and global symbols. This tag has the */ - /* offset into the dynamic symbol table where */ - /* the global symbol table starts. */ - /*------------------------------------------------------------------*/ - case DT_C6000_GSYM_OFFSET: - dyn_module->gsymtab_offset = dyn_module->dyntab[i].d_un.d_val; -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Found global symbol table: %d\n", - dyn_module->gsymtab_offset); -#endif - return TRUE; - - /*------------------------------------------------------------------*/ - /* DT_C6000_GSTR_OFFSET: Contains the offset into the dynamic */ - /* string table where the global symbol names */ - /* start. */ - /*------------------------------------------------------------------*/ - case DT_C6000_GSTR_OFFSET: - dyn_module->gstrtab_offset = dyn_module->dyntab[i].d_un.d_val; -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Found global string table: %d\n", - dyn_module->gstrtab_offset); -#endif - return TRUE; - - /*------------------------------------------------------------------*/ - /* DT_C6000_DSBT_BASE: Contains address of DSBT in executable or */ - /* shared object. */ - /* We store the tag's location in the dynamic */ - /* module object so that we can update it */ - /* easily after the sections have been */ - /* allocated (tag value is relocated). */ - /*------------------------------------------------------------------*/ - case DT_C6000_DSBT_BASE: - dyn_module->dsbt_base_tagidx = i; - return TRUE; - - /*------------------------------------------------------------------*/ - /* DT_C6000_DSBT_INDEX: Contains specific request for a DSBT */ - /* index. If this object module doesn't get */ - /* the index it requested, then the load will */ - /* fail (object module has already assumed */ - /* that it got the DSBT index it asks for; */ - /* references to the DSBT index will not have */ - /* relocation entries associated with them). */ - /*------------------------------------------------------------------*/ - case DT_C6000_DSBT_INDEX: - dyn_module->dsbt_index = dyn_module->dyntab[i].d_un.d_val; - return TRUE; - - /*------------------------------------------------------------------*/ - /* DT_C6000_DSBT_SIZE: Contains the size of the DSBT allocated for */ - /* this object module. It must be big enough */ - /* to hold the content of the master DSBT. */ - /*------------------------------------------------------------------*/ - case DT_C6000_DSBT_SIZE: - dyn_module->dsbt_size = dyn_module->dyntab[i].d_un.d_val; - return TRUE; - - } - - return FALSE; -} - -/*****************************************************************************/ -/* DLDYN_c60_relocate_dynamic_tag_info() */ -/* */ -/* Update any target specific dynamic tag values that are associated with */ -/* a section address. Return TRUE if the tag value is successfully */ -/* updated or if the tag is not associated with a section address, and */ -/* FALSE if we can't find the sectoin associated with the tag or if the */ -/* tag type is not recognized. */ -/* */ -/*****************************************************************************/ -BOOL DLDYN_c60_relocate_dynamic_tag_info(DLIMP_Dynamic_Module *dyn_module, - int32_t i) -{ - switch (dyn_module->dyntab[i].d_tag) - { - /*---------------------------------------------------------------------*/ - /* These tags do not point to sections. */ - /*---------------------------------------------------------------------*/ - case DT_C6000_GSYM_OFFSET: - case DT_C6000_GSTR_OFFSET: - case DT_C6000_DSBT_INDEX: - case DT_C6000_DSBT_SIZE: - return TRUE; - - /*---------------------------------------------------------------------*/ - /* DT_C6000_DSBT_BASE: This tag value provides the virtual address of */ - /* the .dsbt section. We will go find the program */ - /* header entry associated with the DSBT section */ - /* and update this tag with the section's run */ - /* address. */ - /*---------------------------------------------------------------------*/ - case DT_C6000_DSBT_BASE: - return DLIMP_update_dyntag_section_address(dyn_module, i); - } - - DLIF_error(DLET_MISC, "Invalid dynamic tag encountered, %d\n", - (int)dyn_module->dyntab[i].d_tag); - return FALSE; -} - -/*****************************************************************************/ -/* c60_process_eiosabi() */ -/* */ -/* Process the EI_OSABI value. Verify that the OSABI is supported and set */ -/* any variables which depend on the OSABI. */ -/*****************************************************************************/ -BOOL DLDYN_c60_process_eiosabi(DLIMP_Dynamic_Module* dyn_module) -{ - uint8_t osabi = dyn_module->fhdr.e_ident[EI_OSABI]; - - if (dyn_module->relocatable) - { - /*-------------------------------------------------------------------*/ - /* ELFOSABI_C6000_ELFABI - C6x Baremetal ABI */ - /*-------------------------------------------------------------------*/ - if (osabi == ELFOSABI_C6000_ELFABI) - return TRUE; - -#if 0 - /*-------------------------------------------------------------------*/ - /* ELFOSABI_C6000_LINUX - C6x Linux ABI */ - /* presently unsupported */ - /*-------------------------------------------------------------------*/ - if (osabi == ELFOSABI_C6000_LINUX) - return TRUE; -#endif - } - else - { - /*-------------------------------------------------------------------*/ - /* Static executables should have an OSABI of NONE. */ - /*-------------------------------------------------------------------*/ - if (osabi == ELFOSABI_NONE) - return TRUE; - } - - return FALSE; -} - -#endif diff --git a/src/utils/elfload/c60_reloc.c b/src/utils/elfload/c60_reloc.c deleted file mode 100644 index 52d8b0b..0000000 --- a/src/utils/elfload/c60_reloc.c +++ /dev/null @@ -1,1094 +0,0 @@ -/* - * c60_reloc.c - * - * Process C6x-specific dynamic relocations for core dynamic loader. - * - * Copyright (C) 2009 Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#if defined (__KERNEL__) -#include -#else -#include -#endif -#include -#include -#include -#include -#include "relocate.h" -#include "c60_elf32.h" -#include "dload_api.h" -#include "util.h" -#include "dload_endian.h" -#include "symtab.h" - -#define MASK(n,s) (((1 << n) - 1) << s) - -/*---------------------------------------------------------------------------*/ -/* C6x Relocations Supported */ -/* */ -/* See the C6000 ELF ABI Specification for more details. */ -/* */ -/* R_C6000_ABS32 | .field X,32 */ -/* R_C6000_ABS16 | .field X,16 */ -/* R_C6000_ABS8 | .field X,8 */ -/* R_C6000_PCR_S21 | B foo */ -/* CALLP foo, B3 */ -/* R_C6000_PCR_S12 | BNOP foo */ -/* R_C6000_PCR_S10 | BPOS foo, A10 */ -/* BDEC foo, A1 */ -/* R_C6000_PCR_S7 | ADDKPC foo, B3, 4 */ -/* R_C6000_ABS_S16 | MVK sym, A0 */ -/* R_C6000_ABS_L16 | MVKL sym, A0 */ -/* MVKLH sym, A0 */ -/* R_C6000_ABS_H16 | MVKH sym, A0 */ -/* R_C6000_SBR_U15_B | LDB *+B14(sym), A1 */ -/* ADDAB B14, sym, A1 */ -/* R_C6000_SBR_U15_H | LDH *+B14(sym), A1 */ -/* ADDAH B14, sym, A1 */ -/* R_C6000_SBR_U15_W | LDW *+B14(sym), A1 */ -/* ADDAW B14, sym, A1 */ -/* R_C6000_SBR_S16 | MVK sym-$bss, A0 */ -/* R_C6000_SBR_L16_B | MVKL (sym-$bss), A0 */ -/* R_C6000_SBR_L16_H | MVKL (sym-$bss)/2,A0 */ -/* R_C6000_SBR_L16_W | MVKL (sym-$bss)/4,A0 */ -/* R_C6000_SBR_H16_B | MVKH (sym-$bss), A0 */ -/* R_C6000_SBR_H16_H | MVKH (sym-$bss)/2,A0 */ -/* R_C6000_SBR_H16_W | MVKH (sym-$bss)/4,A0 */ -/* R_C6000_SBR_GOT_U15_W | LDW *+B14[GOT(sym)],A0 */ -/* R_C6000_SBR_GOT_L16_W | MVKL $DPR_GOT(sym), A0 */ -/* R_C6000_SBR_GOT_H16_W | MVKH $DPR_GOT(sym), A0 */ -/* R_C6000_DSBT_INDEX | LDW *+B14[$DSBT_index()], DP */ -/* */ -/*---------------------------------------------------------------------------*/ - -/*****************************************************************************/ -/* WRITE_RELOC_R() - Perform a relocation into a buffered segment. */ -/*****************************************************************************/ -static void write_reloc_r(uint8_t* buffered_segment, - uint32_t segment_offset, - int r_type, uint32_t r) -{ - uint32_t* rel_field_ptr = (uint32_t*)(buffered_segment + segment_offset); - -#if LOADER_DEBUG - /*------------------------------------------------------------------------*/ - /* Print some details about the relocation we are about to process. */ - /*------------------------------------------------------------------------*/ - if(debugging_on) - { - DLIF_trace("RWRT: segment_offset: %d\n", segment_offset); - DLIF_trace("RWRT: buffered_segment: 0x%x\n", buffered_segment); - DLIF_trace("RWRT: rel_field_ptr: 0x%x\n", rel_field_ptr); - DLIF_trace("RWRT: result: 0x%x\n", r); - } -#endif - - - /*------------------------------------------------------------------------*/ - /* Given the relocation type, carry out relocation into a 4 byte packet */ - /* within the buffered segment. */ - /*------------------------------------------------------------------------*/ - switch(r_type) - { - case R_C6000_ABS32: - *rel_field_ptr = r; - break; - case R_C6000_PREL31: - *rel_field_ptr = (*rel_field_ptr & ~MASK(30,0)) | r; - break; - case R_C6000_ABS16: - *((uint16_t*)(buffered_segment + segment_offset)) = r; - break; - case R_C6000_ABS8: - *((uint8_t*)(buffered_segment + segment_offset)) = r; - break; - case R_C6000_PCR_S21: - *rel_field_ptr = (*rel_field_ptr & ~MASK(21,7)) | (r << 7); - break; - case R_C6000_PCR_S12: - *rel_field_ptr = (*rel_field_ptr & ~MASK(12,16)) | (r << 16); - break; - case R_C6000_PCR_S10: - *rel_field_ptr = (*rel_field_ptr & ~MASK(10,13)) | (r << 13); - break; - case R_C6000_PCR_S7: - *rel_field_ptr = (*rel_field_ptr & ~MASK(7,16)) | (r << 16); - break; - - case R_C6000_ABS_S16: - *rel_field_ptr = (*rel_field_ptr & ~MASK(16,7)) | (r << 7); - break; - case R_C6000_ABS_L16: - *rel_field_ptr = (*rel_field_ptr & ~MASK(16,7)) | (r << 7); - break; - case R_C6000_ABS_H16: - *rel_field_ptr = (*rel_field_ptr & ~MASK(16,7)) | (r << 7); - break; - - case R_C6000_SBR_U15_B: - *rel_field_ptr = (*rel_field_ptr & ~MASK(15,8)) | (r << 8); - break; - case R_C6000_SBR_U15_H: - *rel_field_ptr = (*rel_field_ptr & ~MASK(15,8)) | (r << 8); - break; - case R_C6000_SBR_U15_W: - case R_C6000_DSBT_INDEX: - *rel_field_ptr = (*rel_field_ptr & ~MASK(15,8)) | (r << 8); - break; - - case R_C6000_SBR_S16: - case R_C6000_SBR_L16_B: - case R_C6000_SBR_L16_H: - case R_C6000_SBR_L16_W: - case R_C6000_SBR_H16_B: - case R_C6000_SBR_H16_H: - case R_C6000_SBR_H16_W: - *rel_field_ptr = (*rel_field_ptr & ~MASK(16,7)) | (r << 7); - break; - - /*---------------------------------------------------------------------*/ - /* Linux "import-as-own" copy relocations are not yet supported. */ - /*---------------------------------------------------------------------*/ - case R_C6000_COPY: - - default: - DLIF_error(DLET_RELOC, - "write_reloc_r called with invalid relocation type!\n"); - } - -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("reloc_field 0x%x\n", *rel_field_ptr); -#endif -} - -/*****************************************************************************/ -/* PACK_RESULT() - Pack the result of a relocation calculation for storage */ -/* in the relocation field. */ -/*****************************************************************************/ -static int32_t pack_result(int32_t unpacked_result, int r_type) -{ - switch(r_type) - { - case R_C6000_ABS32: - case R_C6000_ABS16: - case R_C6000_ABS8: - case R_C6000_ABS_S16: - case R_C6000_ABS_L16: - case R_C6000_SBR_U15_B: - case R_C6000_SBR_S16: - case R_C6000_SBR_L16_B: - return unpacked_result; - - case R_C6000_SBR_U15_H: - case R_C6000_SBR_L16_H: - case R_C6000_PREL31: - return unpacked_result >> 1; - - case R_C6000_PCR_S21: - case R_C6000_PCR_S12: - case R_C6000_PCR_S10: - case R_C6000_PCR_S7: - case R_C6000_SBR_U15_W: - case R_C6000_SBR_L16_W: - case R_C6000_DSBT_INDEX: - return unpacked_result >> 2; - - case R_C6000_ABS_H16: - case R_C6000_SBR_H16_B: - return unpacked_result >> 16; - - case R_C6000_SBR_H16_H: - return unpacked_result >> 17; - - case R_C6000_SBR_H16_W: - return unpacked_result >> 18; - - /*---------------------------------------------------------------------*/ - /* Linux "import-as-own" copy relocations are not yet supported. */ - /*---------------------------------------------------------------------*/ - case R_C6000_COPY: - - default: - DLIF_error(DLET_RELOC, - "pack_result called with invalid relocation type!\n"); - return 0; - } -} - -/*****************************************************************************/ -/* MASK_RESULT() - Mask the result of a relocation calculation so that it */ -/* fits the size of the relocation type's field. */ -/*****************************************************************************/ -static int32_t mask_result(int32_t unmasked_result, int r_type) -{ - switch(r_type) - { - case R_C6000_ABS8: - return unmasked_result & 0xFF; - - case R_C6000_ABS32: - return unmasked_result; - - case R_C6000_ABS16: - case R_C6000_ABS_S16: - case R_C6000_ABS_L16: - case R_C6000_ABS_H16: - case R_C6000_SBR_S16: - case R_C6000_SBR_L16_B: - case R_C6000_SBR_L16_H: - case R_C6000_SBR_L16_W: - case R_C6000_SBR_H16_B: - case R_C6000_SBR_H16_H: - case R_C6000_SBR_H16_W: - return unmasked_result & 0xFFFF; - - case R_C6000_PCR_S21: - return unmasked_result & 0x1FFFFF; - - case R_C6000_PCR_S12: - return unmasked_result & 0xFFF; - - case R_C6000_PCR_S10: - return unmasked_result & 0x3FF; - - case R_C6000_PCR_S7: - return unmasked_result & 0x7F; - - case R_C6000_SBR_U15_B: - case R_C6000_SBR_U15_H: - case R_C6000_SBR_U15_W: - case R_C6000_DSBT_INDEX: - return unmasked_result & 0x7FFF; - - case R_C6000_PREL31: - return unmasked_result & 0x7FFFFFFF; - - /*---------------------------------------------------------------------*/ - /* Linux "import-as-own" copy relocations are not yet supported. */ - /*---------------------------------------------------------------------*/ - case R_C6000_COPY: - - default: - DLIF_error(DLET_RELOC, - "mask_result called with invalid relocation type!\n"); - return 0; - } -} - -/*****************************************************************************/ -/* REL_OVERFLOW() */ -/* */ -/* Check relocation value against the range associated with a given */ -/* relocation type field size and signedness. */ -/* */ -/*****************************************************************************/ -static BOOL rel_overflow(C60_RELOC_TYPE r_type, int32_t reloc_value) -{ - /*------------------------------------------------------------------------*/ - /* Select appropriate range check based on relocation type. */ - /*------------------------------------------------------------------------*/ - switch(r_type) - { - case R_C6000_ABS16: return ((reloc_value > 65535) || - (reloc_value < -32768)); - case R_C6000_ABS8: return ((reloc_value > 255) || - (reloc_value < -128)); - case R_C6000_PCR_S21: return ((reloc_value >= 0x400000) || - (reloc_value < -0x400000)); - case R_C6000_PCR_S12: return ((reloc_value >= 0x2000) || - (reloc_value < -0x2000)); - case R_C6000_PCR_S10: return ((reloc_value >= 0x800) || - (reloc_value < -0x800)); - case R_C6000_PCR_S7: return ((reloc_value >= 0x100) || - (reloc_value < -0x100)); - case R_C6000_SBR_S16: - case R_C6000_ABS_S16: return ((reloc_value >= 0x8000) || - (reloc_value < -0x8000)); - case R_C6000_SBR_U15_B: return (((uint32_t)reloc_value) >= 0x8000); - case R_C6000_SBR_U15_H: return (((uint32_t)reloc_value) >= 0xFFFF); - case R_C6000_DSBT_INDEX: - case R_C6000_SBR_U15_W: return (((uint32_t)reloc_value) >= 0x1FFFD); - - - /*---------------------------------------------------------------------*/ - /* Some relocation types suppress overflow checking at link-time. */ - /*---------------------------------------------------------------------*/ - case R_C6000_ABS_L16: - case R_C6000_ABS_H16: - case R_C6000_SBR_L16_B: - case R_C6000_SBR_L16_H: - case R_C6000_SBR_L16_W: - case R_C6000_SBR_H16_B: - case R_C6000_SBR_H16_H: - case R_C6000_SBR_H16_W: - return 0; - - /*---------------------------------------------------------------------*/ - /* 32-bit relocation field values are not checked for overflow. */ - /*---------------------------------------------------------------------*/ - case R_C6000_ABS32: - case R_C6000_PREL31: - return 0; - - /*----------------------------------------------------------------------*/ - /* If relocation type did not appear in the above cases, then we didn't */ - /* expect to see it. */ - /*----------------------------------------------------------------------*/ - default: - DLIF_error(DLET_RELOC, - "rel_overflow called with invalid relocation type!\n"); - return 1; - } -} - -/*****************************************************************************/ -/* RELOC_DO() - Process a single relocation entry. */ -/*****************************************************************************/ -static void reloc_do(C60_RELOC_TYPE r_type, - uint8_t *segment_address, - uint32_t addend, - uint32_t symval, - uint32_t spc, - int wrong_endian, - uint32_t base_pointer, - int32_t dsbt_index) -{ - int32_t reloc_value = 0; - -#if LOADER_DEBUG && LOADER_PROFILE - /*------------------------------------------------------------------------*/ - /* In debug mode, keep a count of the number of relocations processed. */ - /* In profile mode, start the clock on a given relocation. */ - /*------------------------------------------------------------------------*/ - int start_time; - if (debugging_on || profiling_on) - { - DLREL_relocations++; - if (profiling_on) start_time = clock(); - } -#endif - - /*------------------------------------------------------------------------*/ - /* Calculate the relocation value according to the rules associated with */ - /* the given relocation type. */ - /*------------------------------------------------------------------------*/ - switch(r_type) - { - /*---------------------------------------------------------------------*/ - /* Straight-Up Address relocations (address references). */ - /*---------------------------------------------------------------------*/ - case R_C6000_ABS32: - case R_C6000_ABS16: - case R_C6000_ABS8: - case R_C6000_ABS_S16: - case R_C6000_ABS_L16: - case R_C6000_ABS_H16: - reloc_value = symval + addend; - break; - - /*---------------------------------------------------------------------*/ - /* PC-Relative relocations (calls and branches). */ - /*---------------------------------------------------------------------*/ - case R_C6000_PCR_S21: - case R_C6000_PCR_S12: - case R_C6000_PCR_S10: - case R_C6000_PCR_S7: - { - /*------------------------------------------------------------------*/ - /* Add SPC to segment address to get the PC. Mask for exec-packet */ - /* boundary. */ - /*------------------------------------------------------------------*/ - int32_t opnd_p = (spc + (int32_t)segment_address) & 0xffffffe0; - reloc_value = symval + addend - opnd_p; - break; - } - - /*---------------------------------------------------------------------*/ - /* "Place"-relative relocations (TDEH). */ - /*---------------------------------------------------------------------*/ - /* These relocations occur in data and refer to a label that occurs */ - /* at some signed 32-bit offset from the place where the relocation */ - /* occurs. */ - /*---------------------------------------------------------------------*/ - case R_C6000_PREL31: - { - /*------------------------------------------------------------------*/ - /* Compute location of relocation entry and subtract it from the */ - /* address of the location being referenced (it is computed very */ - /* much like a PC-relative relocation, but it occurs in data and */ - /* is called a "place"-relative relocation). */ - /*------------------------------------------------------------------*/ - /* If this is an Elf32_Rel type relocation, then addend is assumed */ - /* to have been scaled when it was unpacked (field << 1). */ - /*------------------------------------------------------------------*/ - /* For Elf32_Rela type relocations the addend is assumed to be a */ - /* signed 32-bit integer value. */ - /*------------------------------------------------------------------*/ - /* Offset is not fetch-packet relative; doesn't need to be masked. */ - /*------------------------------------------------------------------*/ - int32_t opnd_p = (spc + (int32_t)segment_address); - reloc_value = symval + addend - opnd_p; - break; - } - - /*---------------------------------------------------------------------*/ - /* Static-Base Relative relocations (near-DP). */ - /*---------------------------------------------------------------------*/ - case R_C6000_SBR_U15_B: - case R_C6000_SBR_U15_H: - case R_C6000_SBR_U15_W: - case R_C6000_SBR_S16: - case R_C6000_SBR_L16_B: - case R_C6000_SBR_L16_H: - case R_C6000_SBR_L16_W: - case R_C6000_SBR_H16_B: - case R_C6000_SBR_H16_H: - case R_C6000_SBR_H16_W: - reloc_value = symval + addend - base_pointer; - break; - - /*---------------------------------------------------------------------*/ - /* R_C6000_DSBT_INDEX - uses value assigned by the dynamic loader to */ - /* be the DSBT index for this module as a scaled offset when */ - /* referencing the DSBT. The DSBT base address is in symval and the */ - /* static base is in base_pointer. DP-relative offset to slot in */ - /* DSBT is the offset of the DSBT relative to the DP plus the */ - /* scaled DSBT index into the DSBT. */ - /*---------------------------------------------------------------------*/ - case R_C6000_DSBT_INDEX: - reloc_value = ((symval + addend) - base_pointer) + (dsbt_index << 2); - break; - - /*---------------------------------------------------------------------*/ - /* Linux "import-as-own" copy relocation: after DSO initialization, */ - /* copy the named object from the DSO into the executable's BSS */ - /*---------------------------------------------------------------------*/ - /* Linux "import-as-own" copy relocations are not yet supported. */ - /*---------------------------------------------------------------------*/ - case R_C6000_COPY: - - /*---------------------------------------------------------------------*/ - /* Unrecognized relocation type. */ - /*---------------------------------------------------------------------*/ - default: - DLIF_error(DLET_RELOC, - "reloc_do called with invalid relocation type!\n"); - break; - } - - /*------------------------------------------------------------------------*/ - /* Overflow checking. Is relocation value out of range for the size and */ - /* type of the current relocation? */ - /*------------------------------------------------------------------------*/ - if (rel_overflow(r_type, reloc_value)) - DLIF_error(DLET_RELOC, "relocation overflow!\n"); - - /*------------------------------------------------------------------------*/ - /* Move relocation value to appropriate offset for relocation field's */ - /* location. */ - /*------------------------------------------------------------------------*/ - reloc_value = pack_result(reloc_value, r_type); - - /*------------------------------------------------------------------------*/ - /* Mask packed result to the size of the relocation field. */ - /*------------------------------------------------------------------------*/ - reloc_value = mask_result(reloc_value, r_type); - - /*------------------------------------------------------------------------*/ - /* If necessary, Swap endianness of data at relocation address. */ - /*------------------------------------------------------------------------*/ - if (wrong_endian) - DLIMP_change_endian32((int32_t*)(segment_address + spc)); - - /*------------------------------------------------------------------------*/ - /* Write the relocated 4-byte packet back to the segment buffer. */ - /*------------------------------------------------------------------------*/ - write_reloc_r(segment_address, spc, r_type, reloc_value); - - /*------------------------------------------------------------------------*/ - /* Change endianness of segment address back to original. */ - /*------------------------------------------------------------------------*/ - if (wrong_endian) - DLIMP_change_endian32((int32_t*)(segment_address + spc)); - -#if LOADER_DEBUG && LOADER_PROFILE - /*------------------------------------------------------------------------*/ - /* In profile mode, add elapsed time for this relocation to total time */ - /* spent doing relocations. */ - /*------------------------------------------------------------------------*/ - if (profiling_on) - DLREL_total_reloc_time += (clock() - start_time); - if (debugging_on) - DLIF_trace("reloc_value = 0x%x\n", reloc_value); -#endif - -} - -/*****************************************************************************/ -/* REL_UNPACK_ADDEND() */ -/* */ -/* Unpack addend value from the relocation field. */ -/* */ -/*****************************************************************************/ -static void rel_unpack_addend(C60_RELOC_TYPE r_type, - uint8_t *address, - uint32_t *addend) -{ - /*------------------------------------------------------------------------*/ - /* C6000 does not support Elf32_Rel type relocations in the dynamic */ - /* loader core. We will emit an internal error and abort until this */ - /* support is added. I abort here because this is necessarily a target- */ - /* specific part of the relocation infrastructure. */ - /*------------------------------------------------------------------------*/ - *addend = 0; - - DLIF_error(DLET_RELOC, - "Internal Error: unpacking addend values from the relocation " - "field is not supported in the C6000 dynamic loader at this " - "time; aborting\n"); -#if !defined (__KERNEL__) - exit(1); -#endif -} - -/*****************************************************************************/ -/* REL_SWAP_ENDIAN() */ -/* */ -/* Return TRUE if we should change the endianness of a relocation field. */ -/* */ -/*****************************************************************************/ -static BOOL rel_swap_endian(DLIMP_Dynamic_Module *dyn_module, - C60_RELOC_TYPE r_type) -{ - if (dyn_module->wrong_endian) return TRUE; - - return FALSE; -} - -/*****************************************************************************/ -/* REL_CHANGE_ENDIAN() */ -/* */ -/* Change the endianness of the relocation field at the specified address */ -/* in the segment's data. */ -/* */ -/*****************************************************************************/ -static void rel_change_endian(C60_RELOC_TYPE r_type, uint8_t *address) -{ - /*------------------------------------------------------------------------*/ - /* On C6000, all instructions are 32-bits wide. */ - /*------------------------------------------------------------------------*/ - DLIMP_change_endian32((int32_t *)address); -} - -/*****************************************************************************/ -/* READ_REL_TABLE() */ -/* */ -/* Read in an Elf32_Rel type relocation table. This function allocates */ -/* host memory for the table. */ -/* */ -/*****************************************************************************/ -static void read_rel_table(struct Elf32_Rel **rel_table, - int32_t table_offset, - uint32_t relnum, uint32_t relent, - LOADER_FILE_DESC *fd, BOOL wrong_endian) -{ - *rel_table = (struct Elf32_Rel *)DLIF_malloc(relnum * relent); - if (NULL == *rel_table) { - DLIF_error(DLET_MEMORY, "Failed to Allocate read_rel_table\n"); - return; - } - DLIF_fseek(fd, table_offset, LOADER_SEEK_SET); - DLIF_fread(*rel_table, relnum, relent, fd); - - if (wrong_endian) - { - int i; - for (i = 0; i < relnum; i++) - DLIMP_change_rel_endian(*rel_table + i); - } -} - -/*****************************************************************************/ -/* PROCESS_REL_TABLE() */ -/* */ -/* Process table of Elf32_Rel type relocations. */ -/* */ -/*****************************************************************************/ -static void process_rel_table(DLOAD_HANDLE handle, DLIMP_Loaded_Segment* seg, - struct Elf32_Rel *rel_table, - uint32_t relnum, - int32_t *start_relidx, - uint32_t ti_static_base, - DLIMP_Dynamic_Module* dyn_module) -{ - Elf32_Addr seg_start_addr = seg->input_vaddr; - Elf32_Addr seg_end_addr = seg_start_addr + seg->phdr.p_memsz; - BOOL found = FALSE; - int32_t relidx = *start_relidx; - - /*------------------------------------------------------------------------*/ - /* If the given start reloc index is out of range, then start from the */ - /* beginning of the given table. */ - /*------------------------------------------------------------------------*/ - if (relidx >= relnum) relidx = 0; - - /*------------------------------------------------------------------------*/ - /* Spin through Elf32_Rel type relocation table. */ - /*------------------------------------------------------------------------*/ - for ( ; relidx < relnum; relidx++) - { - /*---------------------------------------------------------------------*/ - /* If the relocation offset falls within the segment, process it. */ - /*---------------------------------------------------------------------*/ - if (rel_table[relidx].r_offset >= seg_start_addr && - rel_table[relidx].r_offset < seg_end_addr) - { - Elf32_Addr r_symval = 0; - C60_RELOC_TYPE r_type = - (C60_RELOC_TYPE)ELF32_R_TYPE(rel_table[relidx].r_info); - int32_t r_symid = ELF32_R_SYM(rel_table[relidx].r_info); - - uint8_t *reloc_address = NULL; - uint32_t pc = 0; - uint32_t addend = 0; - - BOOL change_endian = FALSE; - - found = TRUE; - - /*------------------------------------------------------------------*/ - /* If symbol definition is not found, don't do the relocation. */ - /* An error is generated by the lookup function. */ - /*------------------------------------------------------------------*/ - if (!DLSYM_canonical_lookup(handle, r_symid, dyn_module, &r_symval)) - continue; - - /*------------------------------------------------------------------*/ - /* Addend value is stored in the relocation field. */ - /* We'll need to unpack it from the data for the segment that is */ - /* currently being relocated. */ - /*------------------------------------------------------------------*/ - reloc_address = - (((uint8_t *)(seg->phdr.p_vaddr) + seg->reloc_offset) + - rel_table[relidx].r_offset - seg->input_vaddr); - pc = (uint32_t)reloc_address; - - change_endian = rel_swap_endian(dyn_module, r_type); - if (change_endian) - rel_change_endian(r_type, reloc_address); - - rel_unpack_addend( - (C60_RELOC_TYPE)ELF32_R_TYPE(rel_table[relidx].r_info), - reloc_address, &addend); - - /*------------------------------------------------------------------*/ - /* Perform actual relocation. This is a really wide function */ - /* interface and could do with some encapsulation. */ - /*------------------------------------------------------------------*/ - reloc_do(r_type, - reloc_address, - addend, - r_symval, - pc, - dyn_module->wrong_endian, - ti_static_base, - dyn_module->dsbt_index); - - } - - else if (found) - break; - } -} - -/*****************************************************************************/ -/* READ_RELA_TABLE() */ -/* */ -/* Read in an Elf32_Rela type relocation table. This function allocates */ -/* host memory for the table. */ -/* */ -/*****************************************************************************/ -static void read_rela_table(struct Elf32_Rela **rela_table, - int32_t table_offset, - uint32_t relanum, uint32_t relaent, - LOADER_FILE_DESC *fd, BOOL wrong_endian) -{ - *rela_table = (struct Elf32_Rela *)DLIF_malloc(relanum * relaent); - if (NULL == *rela_table) { - DLIF_error(DLET_MEMORY, "Failed to Allocate read_rela_table\n"); - return; - } - DLIF_fseek(fd, table_offset, LOADER_SEEK_SET); - DLIF_fread(*rela_table, relanum, relaent, fd); - - if (wrong_endian) - { - int i; - for (i = 0; i < relanum; i++) - DLIMP_change_rela_endian(*rela_table + i); - } -} - -/*****************************************************************************/ -/* PROCESS_RELA_TABLE() */ -/* */ -/* Process a table of Elf32_Rela type relocations. */ -/* */ -/*****************************************************************************/ -static void process_rela_table(DLOAD_HANDLE handle, DLIMP_Loaded_Segment *seg, - struct Elf32_Rela *rela_table, - uint32_t relanum, - int32_t *start_relidx, - uint32_t ti_static_base, - DLIMP_Dynamic_Module *dyn_module) -{ - Elf32_Addr seg_start_addr = seg->input_vaddr; - Elf32_Addr seg_end_addr = seg_start_addr + seg->phdr.p_memsz; - BOOL found = FALSE; - int32_t relidx = *start_relidx; - - /*-----------------------------------------------------------------------*/ - /* If the given start reloc index is out of range, then start from */ - /* the beginning of the given table. */ - /*-----------------------------------------------------------------------*/ - if (relidx > relanum) relidx = 0; - - /*-----------------------------------------------------------------------*/ - /* Spin through RELA relocation table. */ - /*-----------------------------------------------------------------------*/ - for ( ; relidx < relanum; relidx++) - { - /*-------------------------------------------------------------------*/ - /* If the relocation offset falls within the segment, process it. */ - /*-------------------------------------------------------------------*/ - if (rela_table[relidx].r_offset >= seg_start_addr && - rela_table[relidx].r_offset < seg_end_addr) - { - Elf32_Addr r_symval; - C60_RELOC_TYPE r_type = - (C60_RELOC_TYPE)ELF32_R_TYPE(rela_table[relidx].r_info); - int32_t r_symid = ELF32_R_SYM(rela_table[relidx].r_info); - - found = TRUE; - - /*---------------------------------------------------------------*/ - /* If symbol definition is not found, don't do the relocation. */ - /* An error is generated by the lookup function. */ - /*---------------------------------------------------------------*/ - if (!DLSYM_canonical_lookup(handle, r_symid, dyn_module, &r_symval)) - continue; - - /*---------------------------------------------------------------*/ - /* Perform actual relocation. This is a really wide function */ - /* interface and could do with some encapsulation. */ - /*---------------------------------------------------------------*/ - reloc_do(r_type, - (uint8_t*)(seg->phdr.p_vaddr) + seg->reloc_offset, - rela_table[relidx].r_addend, - r_symval, - rela_table[relidx].r_offset - seg->input_vaddr, - dyn_module->wrong_endian, - ti_static_base, - dyn_module->dsbt_index); - } - - else if (found) - break; - } -} - -/*****************************************************************************/ -/* PROCESS_GOT_RELOCS() */ -/* */ -/* Process all GOT relocations. It is possible to have both Elf32_Rel */ -/* and Elf32_Rela type relocations in the same file, so we handle tham */ -/* both. */ -/* */ -/*****************************************************************************/ -static void process_got_relocs(DLOAD_HANDLE handle, - struct Elf32_Rel* rel_table, uint32_t relnum, - struct Elf32_Rela* rela_table, uint32_t relanum, - DLIMP_Dynamic_Module* dyn_module) -{ - DLIMP_Loaded_Segment *seg = - (DLIMP_Loaded_Segment*)(dyn_module->loaded_module->loaded_segments.buf); - uint32_t num_segs = dyn_module->loaded_module->loaded_segments.size; - int32_t rel_relidx = 0; - int32_t rela_relidx = 0; - uint32_t seg_idx = 0; - uint32_t ti_static_base = 0; - - /*------------------------------------------------------------------------*/ - /* Get the value of the static base (__TI_STATIC_BASE) which will be */ - /* passed into the relocation table processing functions. */ - /*------------------------------------------------------------------------*/ - if (!DLSYM_lookup_local_symtab("__TI_STATIC_BASE", dyn_module->symtab, - dyn_module->symnum, &ti_static_base)) - DLIF_error(DLET_RELOC, "Could not resolve value of __TI_STATIC_BASE\n"); - - /*------------------------------------------------------------------------*/ - /* Process relocations segment by segment. */ - /*------------------------------------------------------------------------*/ - for (seg_idx = 0; seg_idx < num_segs; seg_idx++) - { - /*---------------------------------------------------------------------*/ - /* Relocations should not occur in uninitialized segments. */ - /*---------------------------------------------------------------------*/ - if (!seg[seg_idx].phdr.p_filesz) continue; - - if (rela_table) - process_rela_table(handle, (seg + seg_idx), - rela_table, relanum, &rela_relidx, - ti_static_base, dyn_module); - - if (rel_table) - process_rel_table(handle, (seg + seg_idx), - rel_table, relnum, &rel_relidx, - ti_static_base, dyn_module); - } -} - -/*****************************************************************************/ -/* PROCESS_PLTGOT_RELOCS() */ -/* */ -/* Process all PLTGOT relocation entries. The PLTGOT relocation table */ -/* can be either Elf32_Rel or Elf32_Rela type. All PLTGOT relocations */ -/* ar guaranteed to belong to the same segment. */ -/* */ -/*****************************************************************************/ -static void process_pltgot_relocs(DLOAD_HANDLE handle, void* plt_reloc_table, - int reltype, - uint32_t pltnum, - DLIMP_Dynamic_Module* dyn_module) -{ - Elf32_Addr r_offset = (reltype == DT_REL) ? - ((struct Elf32_Rel *)plt_reloc_table)->r_offset : - ((struct Elf32_Rela *)plt_reloc_table)->r_offset; - - DLIMP_Loaded_Segment* seg = - (DLIMP_Loaded_Segment*)(dyn_module->loaded_module->loaded_segments.buf); - - uint32_t num_segs = dyn_module->loaded_module->loaded_segments.size; - int32_t plt_relidx = 0; - uint32_t seg_idx = 0; - uint32_t ti_static_base = 0; - - /*------------------------------------------------------------------------*/ - /* Get the value of the static base (__TI_STATIC_BASE) which will be */ - /* passed into the relocation table processing functions. */ - /*------------------------------------------------------------------------*/ - if (!DLSYM_lookup_local_symtab("__TI_STATIC_BASE", dyn_module->symtab, - dyn_module->symnum, &ti_static_base)) - DLIF_error(DLET_RELOC, "Could not resolve value of __TI_STATIC_BASE\n"); - - /*------------------------------------------------------------------------*/ - /* For each segment s, check if the relocation falls within s. If so, */ - /* then all other relocations are guaranteed to fall with s. Process */ - /* all relocations and then return. */ - /*------------------------------------------------------------------------*/ - for (seg_idx = 0; seg_idx < num_segs; seg_idx++) - { - Elf32_Addr seg_start_addr = seg[seg_idx].input_vaddr; - Elf32_Addr seg_end_addr = seg_start_addr + seg[seg_idx].phdr.p_memsz; - - /*---------------------------------------------------------------------*/ - /* Relocations should not occur in uninitialized segments. */ - /*---------------------------------------------------------------------*/ - if(!seg[seg_idx].phdr.p_filesz) continue; - - if (r_offset >= seg_start_addr && - r_offset < seg_end_addr) - { - if (reltype == DT_REL) - process_rel_table(handle, (seg + seg_idx), - (struct Elf32_Rel *)plt_reloc_table, - pltnum, &plt_relidx, - ti_static_base, dyn_module); - else - process_rela_table(handle, (seg + seg_idx), - (struct Elf32_Rela *)plt_reloc_table, - pltnum, &plt_relidx, - ti_static_base, dyn_module); - - break; - } - } -} - -/*****************************************************************************/ -/* RELOCATE() - Perform RELA and REL type relocations for given ELF object */ -/* file that we are in the process of loading and relocating. */ -/*****************************************************************************/ -void DLREL_relocate_c60(DLOAD_HANDLE handle, LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module) -{ - struct Elf32_Dyn *dyn_nugget = dyn_module->dyntab; - struct Elf32_Rela *rela_table = NULL; - struct Elf32_Rel *rel_table = NULL; - void *plt_table = NULL; - - /*------------------------------------------------------------------------*/ - /* Read the size of the relocation table (DT_RELASZ) and the size per */ - /* relocation (DT_RELAENT) from the dynamic segment. */ - /*------------------------------------------------------------------------*/ - uint32_t relasz = DLIMP_get_first_dyntag(DT_RELASZ, dyn_nugget); - uint32_t relaent = DLIMP_get_first_dyntag(DT_RELAENT, dyn_nugget); - uint32_t relanum = 0; - - /*------------------------------------------------------------------------*/ - /* Read the size of the relocation table (DT_RELSZ) and the size per */ - /* relocation (DT_RELENT) from the dynamic segment. */ - /*------------------------------------------------------------------------*/ - uint32_t relsz = DLIMP_get_first_dyntag(DT_RELSZ, dyn_nugget); - uint32_t relent = DLIMP_get_first_dyntag(DT_RELENT, dyn_nugget); - uint32_t relnum = 0; - - /*------------------------------------------------------------------------*/ - /* Read the size of the relocation table (DT_PLTRELSZ) and the type of */ - /* of the PLTGOT relocation table (DT_PLTREL): one of DT_REL or DT_RELA */ - /*------------------------------------------------------------------------*/ - uint32_t pltrelsz = DLIMP_get_first_dyntag(DT_PLTRELSZ, dyn_nugget); - int pltreltyp = DLIMP_get_first_dyntag(DT_PLTREL, dyn_nugget); - uint32_t pltnum = 0; - - /*------------------------------------------------------------------------*/ - /* Find/record DSBT index associated with this module. */ - /*------------------------------------------------------------------------*/ - if (is_dsbt_module(dyn_module) && - (dyn_module->dsbt_index == DSBT_INDEX_INVALID)) - dyn_module->dsbt_index = - DLIF_get_dsbt_index(dyn_module->loaded_module->file_handle); - - /*------------------------------------------------------------------------*/ - /* Read the PLTGOT relocation table from the file */ - /* The PLTGOT table is a subsection at the end of either the DT_REL or */ - /* DT_RELA table. The size of the table it belongs to DT_REL(A)SZ */ - /* includes the size of the PLTGOT table. So it must be adjusted so that */ - /* the GOT relocation tables only contain actual GOT relocations. */ - /*------------------------------------------------------------------------*/ - if (pltrelsz != INT_MAX) - { - if (pltreltyp == DT_REL) - { - pltnum = pltrelsz/relent; - relsz -= pltrelsz; - read_rel_table(((struct Elf32_Rel**) &plt_table), - DLIMP_get_first_dyntag(DT_JMPREL, dyn_nugget), - pltnum, relent, fd, dyn_module->wrong_endian); - } - - else if (pltreltyp == DT_RELA) - { - pltnum = pltrelsz/relaent; - relasz -= pltrelsz; - read_rela_table(((struct Elf32_Rela**) &plt_table), - DLIMP_get_first_dyntag(DT_JMPREL, dyn_nugget), - pltnum, relaent, fd, dyn_module->wrong_endian); - } - - else - { - DLIF_error(DLET_RELOC, - "DT_PLTREL is invalid: must be either %d or %d\n", - DT_REL, DT_RELA); - } - } - - /*------------------------------------------------------------------------*/ - /* Read the DT_RELA GOT relocation table from the file */ - /*------------------------------------------------------------------------*/ - if (relasz != INT_MAX) - { - relanum = relasz/relaent; - read_rela_table(&rela_table, DLIMP_get_first_dyntag(DT_RELA, dyn_nugget), - relanum, relaent, fd, dyn_module->wrong_endian); - } - - /*------------------------------------------------------------------------*/ - /* Read the DT_REL GOT relocation table from the file */ - /*------------------------------------------------------------------------*/ - if (relsz != INT_MAX) - { - relnum = relsz/relent; - read_rel_table(&rel_table, DLIMP_get_first_dyntag(DT_REL, dyn_nugget), - relnum, relent, fd, dyn_module->wrong_endian); - } - - /*------------------------------------------------------------------------*/ - /* Process the PLTGOT relocations */ - /*------------------------------------------------------------------------*/ - if (plt_table) - process_pltgot_relocs(handle, plt_table, pltreltyp, pltnum, dyn_module); - - /*------------------------------------------------------------------------*/ - /* Process the GOT relocations */ - /*------------------------------------------------------------------------*/ - if (rel_table || rela_table) - process_got_relocs(handle, rel_table, relnum, rela_table, relanum, dyn_module); - - /*-------------------------------------------------------------------------*/ - /* Free memory used for ELF relocation table copies. */ - /*-------------------------------------------------------------------------*/ - if (rela_table) DLIF_free(rela_table); - if (rel_table) DLIF_free(rel_table); - if (plt_table) DLIF_free(plt_table); -} - -/*****************************************************************************/ -/* UNIT TESTING INTERFACE */ -/*****************************************************************************/ -#ifdef UNIT_TEST -void unit_c60_reloc_do(C60_RELOC_TYPE r_type, - uint8_t *address_space, - uint32_t addend, uint32_t symval, uint32_t pc, - uint32_t static_base, int wrong_endian, - int32_t dsbt_index) -{ - reloc_do(r_type, address_space, addend, symval, pc, FALSE, static_base, dsbt_index); -} - -#if 0 /* RELA TYPE RELOCATIONS HAVE ADDEND IN RELOCATION ENTRY */ -void unit_c60_rel_unpack_addend(C60_RELOC_TYPE r_type, - uint8_t* address, - uint32_t* addend) -{ - rel_unpack_addend(r_type, address, addend); -} -#endif - -BOOL unit_c60_rel_overflow(C60_RELOC_TYPE r_type, int32_t reloc_value) -{ - return rel_overflow(r_type, reloc_value); -} -#endif diff --git a/src/utils/elfload/dload.c b/src/utils/elfload/dload.c deleted file mode 100644 index 3adbb1b..0000000 --- a/src/utils/elfload/dload.c +++ /dev/null @@ -1,3254 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* dload.c */ -/* */ -/* Core Dynamic Loader reference implementation. */ -/* */ -/* This implementation of the core dynamic loader is platform independent, */ -/* but it is object file format dependent. In particular, this */ -/* implementation supports ELF object file format. */ -/*****************************************************************************/ - -#include -#include -#include -#include -#include -#include - -#include "ArrayList.h" -#include "Queue.h" - -#include "symtab.h" -#include "dload_endian.h" -#include "elf32.h" -#include "dload.h" -#include "relocate.h" -#include "dload_api.h" - -#ifdef ARM_TARGET -#include "arm_dynamic.h" -#endif - -#ifdef C60_TARGET -#include "c60_dynamic.h" -#endif - -/*---------------------------------------------------------------------------*/ -/* Contains objects (type DLIMP_Loaded_Module) that the system has loaded */ -/* into target memory. */ -/*---------------------------------------------------------------------------*/ -TYPE_QUEUE_IMPLEMENTATION(DLIMP_Loaded_Module*, loaded_module_ptr) - -/*---------------------------------------------------------------------------*/ -/* Global flag to control debug output. */ -/*---------------------------------------------------------------------------*/ -#if LOADER_DEBUG -Bool debugging_on = 1; -#endif - - -/*---------------------------------------------------------------------------*/ -/* Global flag to enable profiling. */ -/*---------------------------------------------------------------------------*/ -#if LOADER_DEBUG || LOADER_PROFILE -Bool profiling_on = 0; -#endif - -#if LOADER_DEBUG || LOADER_PROFILE -int DLREL_relocations; -time_t DLREL_total_reloc_time; -#endif - - -/*---------------------------------------------------------------------------*/ -/* Dependency Graph Queue - FIFO queue of dynamic modules that are loaded */ -/* when client asks to load a dynamic executable or library. Note that */ -/* dependents that have already been loaded with another module will not */ -/* appear on this queue. */ -/*---------------------------------------------------------------------------*/ -TYPE_STACK_IMPLEMENTATION(DLIMP_Dynamic_Module*, dynamic_module_ptr) - -/*---------------------------------------------------------------------------*/ -/* Support for profiling performance of dynamic loader core. */ -/*---------------------------------------------------------------------------*/ -#if LOADER_PROFILE || LOADER_DEBUG -static clock_t cycle0 = 0; -static clock_t cycle_end = 0; -#define profile_start_clock() (cycle0 = clock()) -#define profile_stop_clock() (cycle_end = clock()) -#define profile_cycle_count() (cycle_end - cycle0) -#endif - -/*---------------------------------------------------------------------------*/ -/* DLOAD_create() */ -/* */ -/* Create an instance of the dynamic loader core. */ -/* */ -/* client_handle: Private client token to be returned during select DLIF */ -/* function calls. */ -/* */ -/* returns: an opaque DLOAD core loader handle, identifying this instance.*/ -/* */ -/*---------------------------------------------------------------------------*/ -DLOAD_HANDLE DLOAD_create(void * client_handle) -{ - LOADER_OBJECT * pLoaderObject; - - pLoaderObject = DLIF_malloc(sizeof(LOADER_OBJECT)); - - /* Fill out the Loader Object: */ - if (pLoaderObject != NULL) { - /*-------------------------------------------------------------------*/ - /* Set up initial objects_loading queue. */ - /*-------------------------------------------------------------------*/ - AL_initialize(&(pLoaderObject->DLIMP_module_dependency_list), - sizeof (const char*), 1); - - /* Initialize Loaded Module Ptr Queue */ - loaded_module_ptr_initialize_queue(&pLoaderObject->DLIMP_loaded_objects); - - /* Initialize Dynamic Module Ptr Stack */ - dynamic_module_ptr_initialize_stack(&pLoaderObject->DLIMP_dependency_stack); - - pLoaderObject->file_handle = 1; - - pLoaderObject->DLOAD_TARGET_MACHINE = DLOAD_DEFAULT_TARGET_MACHINE; - - /* Store client token, so it can be handed back during DLIF calls */ - pLoaderObject->client_handle = client_handle; - } - - return((DLOAD_HANDLE)pLoaderObject); -} - -/*---------------------------------------------------------------------------*/ -/* DLOAD_destroy() */ -/* */ -/* Remove an instance of the dynamic loader core, and free all resources */ -/* allocated during DLOAD_create(). */ -/* */ -/* client_handle: Private client token to be returned during select DLIF */ -/* function calls. */ -/* Preconditions: 1) handle must be valid. */ -/* 2) Loader instance must be in "UNLOADED" state. */ -/* */ -/*---------------------------------------------------------------------------*/ -void DLOAD_destroy(DLOAD_HANDLE handle) -{ - LOADER_OBJECT * pLoaderObject; - - pLoaderObject = (LOADER_OBJECT *)handle; - - AL_destroy(&(pLoaderObject->DLIMP_module_dependency_list)); - - /* Free the instance object */ - DLIF_free (pLoaderObject); -} - -/*****************************************************************************/ -/* DLIMP_get_first_dyntag() */ -/* */ -/* Return value for first tag entry in the given dynamic table whose */ -/* tag type matches the given key. */ -/* */ -/*****************************************************************************/ -uint32_t DLIMP_get_first_dyntag(int tag, struct Elf32_Dyn* dyn_table) -{ - /*-----------------------------------------------------------------------*/ - /* Spin through dynamic segment looking for a specific dynamic tag. */ - /* Return the value associated with the tag, if the tag is found. */ - /*-----------------------------------------------------------------------*/ - struct Elf32_Dyn *dtp = dyn_table; - while (dtp->d_tag != DT_NULL) - { - if (dtp->d_tag == tag) return dtp->d_un.d_val; - else dtp++; - } - - /*-----------------------------------------------------------------------*/ - /* Tag wasn't found, return a known bogus value for the tag. */ - /*-----------------------------------------------------------------------*/ - return INT_MAX; -} - -/*****************************************************************************/ -/* dload_and_allocate_dependencies() */ -/* */ -/* If not already loaded, load each dependent file identified in the */ -/* dynamic segment with a DT_NEEDED tag. Dependent files are listed in */ -/* order and should be loaded in the same order that they appear in the */ -/* dynamic segment. */ -/* */ -/*****************************************************************************/ -static BOOL dload_and_allocate_dependencies(DLOAD_HANDLE handle, - DLIMP_Dynamic_Module *dyn_module) -{ - /*-----------------------------------------------------------------------*/ - /* Spin through each dynamic tag entry in the dynamic segment. */ - /*-----------------------------------------------------------------------*/ - struct Elf32_Dyn* dyn_nugget = dyn_module->dyntab; - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Starting dload_and_allocate_dependencies() for %s ...\n", - dyn_module->name); -#endif - - while(dyn_nugget->d_tag != DT_NULL) - { - /*-------------------------------------------------------------------*/ - /* For each DT_NEEDED dynamic tag that we find in the dynamic */ - /* segment, load the dependent file identified by the so_name value */ - /* attached to the DT_NEEDED dynamic tag. */ - /*-------------------------------------------------------------------*/ - if (dyn_nugget->d_tag == DT_NEEDED) - { - loaded_module_ptr_Queue_Node* ptr; - -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Found DT_NEEDED: %s\n", - dyn_module->strtab+dyn_nugget->d_un.d_val); -#endif - - /*---------------------------------------------------------------*/ - /* Find out if the file named by the DT_NEEDED tag has already */ - /* been loaded. If it has, then we only have to bump the use */ - /* count of the named dependent file. */ - /*---------------------------------------------------------------*/ - for (ptr = pHandle->DLIMP_loaded_objects.front_ptr; ptr != NULL; - ptr = ptr->next_ptr) - { - if (!strcmp(ptr->value->name, - dyn_module->strtab + dyn_nugget->d_un.d_val)) - { - ptr->value->use_count++; - AL_append(&(dyn_module->loaded_module->dependencies), - &(ptr->value->file_handle)); - break; - } - } - - /*---------------------------------------------------------------*/ - /* If the named dependent file has not been loaded, then we ask */ - /* the client to invoke a load of the dependent file on our */ - /* behalf. */ - /*---------------------------------------------------------------*/ - if (ptr == NULL) - { - int32_t dependent_handle = DLIF_load_dependent( - pHandle->client_handle, - dyn_module->strtab + - dyn_nugget->d_un.d_val); - AL_append(&(dyn_module->loaded_module->dependencies), - &dependent_handle); - if (dependent_handle == 0) return FALSE; - } - } - - dyn_nugget++; - } - -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Finished dload_and_allocate_dependencies() for %s\n", - dyn_module->name); -#endif - - return TRUE; -} - -/*****************************************************************************/ -/* load_object() */ -/* */ -/* Finish the process of loading an object file. */ -/* */ -/*****************************************************************************/ -static int load_object(LOADER_FILE_DESC *fd, DLIMP_Dynamic_Module *dyn_module) -{ - /*-----------------------------------------------------------------------*/ - /* With the dynamic loader already running on the target, we are able to */ - /* relocate directly into target memory, so there is nothing more to be */ - /* done (at least in the bare-metal dynamic linking ABI model). */ - /*-----------------------------------------------------------------------*/ - return 1; -} - -/*****************************************************************************/ -/* initialize_loaded_module() */ -/* */ -/* Initialize DLIMP_Loaded_Module internal data object associated with a */ -/* dynamic module. This function will also set up a queue of */ -/* DLIMP_Loaded_Segment(s) associated with the loaded module. */ -/* This function is called as we are getting ready to actually load the */ -/* object file contents into target memory. Each segment will get a */ -/* target memory request that it can use to ask the client for target */ -/* memory space. This function will also assign a file handle to the */ -/* loaded module. */ -/* */ -/*---------------------------------------------------------------------------*/ -/* */ -/* In applications that use the DSBT model, this function will also need to */ -/* negotiate the module's DSBT index with the client. */ -/* */ -/*****************************************************************************/ -static void initialize_loaded_module(DLOAD_HANDLE handle, - DLIMP_Dynamic_Module *dyn_module) -{ - int i; - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - - /*-----------------------------------------------------------------------*/ - /* Allocate a DLIMP_Loaded_Module data structure for the specified ELF */ - /* file and assign a file handle for it (bumping the file handle counter */ - /* as we go). */ - /*-----------------------------------------------------------------------*/ - DLIMP_Loaded_Module *loaded_module = - dyn_module->loaded_module = DLIF_malloc(sizeof(DLIMP_Loaded_Module)); - - if(loaded_module == NULL) { -#if LOADER_DEBUG || LOADER_PROFILE - if(debugging_on) - DLIF_error(DLET_MISC, "Error allocating memory %d...\n",__LINE__); -#endif - exit(1); - } -#if LOADER_DEBUG || LOADER_PROFILE - /*-----------------------------------------------------------------------*/ - /* Start clock on initialization of loaded module object. */ - /*-----------------------------------------------------------------------*/ - if (debugging_on || profiling_on) - { - DLIF_trace("Starting initialize_loaded_module() ...\n"); - if (profiling_on) profile_start_clock(); - } -#endif - - loaded_module->name = DLIF_malloc(strlen(dyn_module->name) + 1); - if (NULL == loaded_module->name) { - DLIF_error(DLET_MISC, "Error allocating memory %d...\n",__LINE__); - exit(1); - } - strcpy(loaded_module->name, dyn_module->name); - - loaded_module->file_handle = pHandle->file_handle++; - loaded_module->direct_dependent_only = dyn_module->direct_dependent_only; - loaded_module->use_count = 1; - - /*-----------------------------------------------------------------------*/ - /* In case we wrapped around the file handle, return error. */ - /*-----------------------------------------------------------------------*/ - if (pHandle->file_handle == 0) - DLIF_error(DLET_MISC, "DLOAD File handle overflowed.\n"); - - /*-----------------------------------------------------------------------*/ - /* Initially the loaded module does not have access to its global */ - /* symbols. These need to be copied from the dynamic module (see call */ - /* to DLSYM_copy_globals() below). */ - /* */ - /* THESE INITIALIZATIONS SHOULD BE MOVED TO AN INIT ROUTINE FOR THE */ - /* LOADED MODULE */ - /*-----------------------------------------------------------------------*/ - loaded_module->gsymtab = NULL; - loaded_module->gstrtab = NULL; - loaded_module->gsymnum = loaded_module->gstrsz = 0; - - /*-----------------------------------------------------------------------*/ - /* Initialize the Array_List of dependencies. */ - /*-----------------------------------------------------------------------*/ - AL_initialize(&(loaded_module->dependencies), sizeof(int), 1); - - if (dyn_module->symtab) - DLSYM_copy_globals(dyn_module); - - /*-----------------------------------------------------------------------*/ - /* Initialize the module loaded segments Array_List. */ - /*-----------------------------------------------------------------------*/ - AL_initialize(&(loaded_module->loaded_segments), - sizeof(DLIMP_Loaded_Segment), dyn_module->phnum); - - /*-----------------------------------------------------------------------*/ - /* Spin thru segment headers and process each load segment encountered. */ - /*-----------------------------------------------------------------------*/ - for (i = 0; i < dyn_module->phnum; i++) - if (dyn_module->phdr[i].p_type == PT_LOAD) - { - /*---------------------------------------------------------------*/ - /* Note that this is parallel to and does not supplant the ELF */ - /* phdr tables. */ - /*---------------------------------------------------------------*/ - DLIMP_Loaded_Segment seg; - seg.obj_desc = DLIF_malloc(sizeof(struct DLOAD_MEMORY_SEGMENT)); - seg.phdr.p_vaddr = dyn_module->phdr[i].p_vaddr; - seg.phdr.p_offset = dyn_module->phdr[i].p_offset; - seg.modified = 0; - if(seg.obj_desc) { - seg.obj_desc->target_page = 0; /*not used*/ - seg.phdr.p_filesz = seg.obj_desc->objsz_in_bytes - = dyn_module->phdr[i].p_filesz; - seg.phdr.p_memsz = seg.obj_desc->memsz_in_bytes - = dyn_module->phdr[i].p_memsz; - } - seg.phdr.p_align = dyn_module->phdr[i].p_align; - seg.phdr.p_flags = dyn_module->phdr[i].p_flags; - seg.input_vaddr = 0; - seg.phdr.p_paddr = 0; - seg.phdr.p_type = PT_LOAD; - seg.reloc_offset = 0; - AL_append(&(loaded_module->loaded_segments), &seg); -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("%s:seg.phdr.p_vaddr 0x%x\n",__func__, - seg.phdr.p_vaddr); -#endif - } - - /*-----------------------------------------------------------------------*/ - /* Initialize the DSO termination information for this module. */ - /* It will be copied over from the enclosing dyn_module object when */ - /* placement is completed and dyn_module's local copy of the dynamic */ - /* table is updated. */ - /*-----------------------------------------------------------------------*/ - loaded_module->fini_array = (Elf32_Addr)NULL; - loaded_module->fini_arraysz = 0; - loaded_module->fini = (Elf32_Addr) NULL; - -#if LOADER_DEBUG || LOADER_PROFILE - if (debugging_on || profiling_on) - { - DLIF_trace("Finished initialize_loaded_module()\n"); - if (profiling_on) - { - profile_stop_clock(); - DLIF_trace("Took %d cycles.\n", (int32_t)profile_cycle_count()); - } - } -#endif - -} - -/*****************************************************************************/ -/* load_static_segment() */ -/* */ -/* The core dynamic loader requires that a statically linked executable */ -/* be placed in target memory at the location that was determined during */ -/* the static link that created the executable. Failure to get the */ -/* required target memory where the static executable is to be loaded */ -/* will cause the dynamic loader to emit an error and abort the load. */ -/* */ -/*****************************************************************************/ -static BOOL load_static_segment(DLOAD_HANDLE handle, LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module) -{ - int i; - DLIMP_Loaded_Segment* seg = (DLIMP_Loaded_Segment*) - (dyn_module->loaded_module->loaded_segments.buf); - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - -#if LOADER_DEBUG - if (debugging_on) { - DLIF_trace("dynmodule is 0x%x\n",(UInt32) dyn_module); - DLIF_trace("loaded_module is 0x%x\n",(UInt32)dyn_module->loaded_module); - DLIF_trace("loaded_segments is 0x%x\n", - (UInt32)&dyn_module->loaded_module->loaded_segments); - DLIF_trace("seg is 0x%x\n", - (UInt32)dyn_module->loaded_module->loaded_segments.buf); - } -#endif - - /*-----------------------------------------------------------------------*/ - /* For each segment in the loaded module, build up a target memory */ - /* request for the segment, get rights to target memory where we want */ - /* to load the segment from the client, then get the client to write the */ - /* segment contents out to target memory to the appropriate address. */ - /*-----------------------------------------------------------------------*/ - - for (i = 0; i < dyn_module->loaded_module->loaded_segments.size; i++) - { - struct DLOAD_MEMORY_REQUEST targ_req; - seg[i].obj_desc->target_page = 0; - targ_req.flags = 0; - - /*-------------------------------------------------------------------*/ - /* This is a static executable. DLIF_allocate should give us the */ - /* address we ask for or fail. */ - /*-------------------------------------------------------------------*/ - if (seg[i].phdr.p_flags & PF_X) targ_req.flags |= DLOAD_SF_executable; - - targ_req.align = seg[i].phdr.p_align; - seg[i].obj_desc->target_address = (TARGET_ADDRESS)seg[i].phdr.p_vaddr; - targ_req.flags &= ~DLOAD_SF_relocatable; - targ_req.fp = fd; - targ_req.segment = seg[i].obj_desc; - targ_req.offset = seg[i].phdr.p_offset; - targ_req.flip_endian = dyn_module->wrong_endian; -#if LOADER_DEBUG - if (debugging_on) { - DLIF_trace("============================================\n"); - DLIF_trace("targ_req.align %d\n", targ_req.align); - DLIF_trace("targ_req.segment 0x%x\n", (UInt32) targ_req.segment); - DLIF_trace("targ_req.offset 0x%x\n", targ_req.offset); - DLIF_trace("targ_req.flags 0x%x\n", targ_req.flags); - } -#endif - /*-------------------------------------------------------------------*/ - /* Ask the client side of the dynamic loader to allocate target */ - /* memory for this segment to be loaded into. */ - /*-------------------------------------------------------------------*/ - if (!DLIF_allocate(pHandle->client_handle, &targ_req)) return FALSE; - - /*-------------------------------------------------------------------*/ - /* If there is any initialized data in the segment, we'll first write*/ - /* it into a host writable buffer (DLIF_copy()) and then flush it to */ - /* target memory. */ - /*-------------------------------------------------------------------*/ - if (seg[i].phdr.p_filesz) - { - DLIF_copy(pHandle->client_handle, &targ_req); - DLIF_write(pHandle->client_handle, &targ_req); - } - } - - return TRUE; -} - -/*****************************************************************************/ -/* relocate_target_dynamic_tag_info() */ -/* */ -/* Update a target specific dynamic tag value that happens to be a */ -/* virtual address of a section. Returns TRUE if the tag was updated or */ -/* is not a virtual address and FALSE if it was not successfully updated */ -/* or was not recognized. */ -/*****************************************************************************/ -static BOOL relocate_target_dynamic_tag_info(DLIMP_Dynamic_Module *dyn_module, - int i) -{ -#ifdef ARM_TARGET - if (is_arm_module(&dyn_module->fhdr)) - return DLDYN_arm_relocate_dynamic_tag_info(dyn_module, i); -#endif - -#ifdef C60_TARGET - if (is_c60_module(&dyn_module->fhdr)) - return DLDYN_c60_relocate_dynamic_tag_info(dyn_module, i); -#endif - - return FALSE; -} - -/*****************************************************************************/ -/* DLIMP_update_dyntag_section_address() */ -/* */ -/* Given the index of a dynamic tag which we happen to know points to a */ -/* section address, find the program header table entry associated with */ -/* the specified address and update the tag value with the real address */ -/* of the section. */ -/* */ -/*****************************************************************************/ -BOOL DLIMP_update_dyntag_section_address(DLIMP_Dynamic_Module *dyn_module, - int32_t i) -{ - int j; - DLIMP_Loaded_Segment *seg = (DLIMP_Loaded_Segment *) - (dyn_module->loaded_module->loaded_segments.buf); - for (j = 0; j < dyn_module->loaded_module->loaded_segments.size; j++) - { - if ((dyn_module->dyntab[i].d_un.d_ptr >= seg[j].input_vaddr) && - (dyn_module->dyntab[i].d_un.d_ptr < - (seg[j].input_vaddr + seg[j].phdr.p_memsz))) - { - dyn_module->dyntab[i].d_un.d_ptr += - (seg[j].phdr.p_vaddr - seg[j].input_vaddr); - return TRUE; - } - } - - return FALSE; -} - -/*****************************************************************************/ -/* relocate_dynamic_tag_info() */ -/* */ -/* Once segment allocation has been completed, we'll need to go through */ -/* the dynamic table and update any tag values that happen to be virtual */ -/* addresses of segments (DT_C6000_DSBT_BASE, for example). */ -/* */ -/*****************************************************************************/ -static BOOL relocate_dynamic_tag_info(LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module) -{ - /*-----------------------------------------------------------------------*/ - /* Spin through dynamic table loking for tags that have a value which is */ - /* the virtual address of a section. After the sections are allocated, */ - /* we'll need to update these values with the new address of the section.*/ - /*-----------------------------------------------------------------------*/ - int i; - for (i = 0; dyn_module->dyntab[i].d_tag != DT_NULL; i++) - { - switch (dyn_module->dyntab[i].d_tag) - { - /*---------------------------------------------------------------*/ - /* Only tag values that are virtual addresses will be affected. */ - /*---------------------------------------------------------------*/ - case DT_NEEDED: - case DT_PLTRELSZ: - case DT_HASH: - case DT_STRTAB: - case DT_SYMTAB: - case DT_RELA: - case DT_RELASZ: - case DT_RELAENT: - case DT_STRSZ: - case DT_SYMENT: - case DT_SONAME: - case DT_RPATH: - case DT_SYMBOLIC: - case DT_REL: - case DT_RELSZ: - case DT_RELENT: - case DT_PLTREL: - case DT_DEBUG: - case DT_TEXTREL: - case DT_BIND_NOW: - case DT_INIT_ARRAYSZ: - case DT_RUNPATH: - case DT_FLAGS: - case DT_PREINIT_ARRAYSZ: - continue; - - /*---------------------------------------------------------------*/ - /* NOTE!!! */ - /* case DT_ENCODING: -- tag type has same "id" as */ - /* DT_PREINIT_ARRAY */ - /*---------------------------------------------------------------*/ - - /*---------------------------------------------------------------*/ - /* This is a generic dynamic tag whose value is a virtual address*/ - /* of a section. It needs to be relocated to the section's actual*/ - /* address in target memory. */ - /*---------------------------------------------------------------*/ - case DT_PREINIT_ARRAY: - case DT_INIT: - case DT_INIT_ARRAY: - if (!DLIMP_update_dyntag_section_address(dyn_module, i)) - return FALSE; - - continue; - - /*---------------------------------------------------------------*/ - /* Once we have resolved the actual address of termination */ - /* function sections, we need to copy their addresses over to */ - /* the loaded module object (dyn_module will be deleted before */ - /* we get to unloading the module). */ - /*---------------------------------------------------------------*/ - case DT_FINI_ARRAY: - case DT_FINI: - if (!DLIMP_update_dyntag_section_address(dyn_module, i)) - return FALSE; - - if (dyn_module->dyntab[i].d_tag == DT_FINI) - dyn_module->loaded_module->fini = - dyn_module->dyntab[i].d_un.d_ptr; - else - dyn_module->loaded_module->fini_array = - dyn_module->dyntab[i].d_un.d_ptr; - - continue; - - case DT_FINI_ARRAYSZ: - dyn_module->loaded_module->fini_arraysz = - dyn_module->dyntab[i].d_un.d_val; - continue; - - /*---------------------------------------------------------------*/ - /* Is this a virtual address??? */ - /*---------------------------------------------------------------*/ - case DT_JMPREL: /* is this a virtual address??? */ - continue; - - /*---------------------------------------------------------------*/ - /* The remaining dynamic tag types should be target specific. If */ - /* something generic slips through to here, then the handler for */ - /* relocating target specific dynamic tags should fail. */ - /*---------------------------------------------------------------*/ - default: - if (!relocate_target_dynamic_tag_info(dyn_module, i)) - return FALSE; - } - } - - /*-----------------------------------------------------------------------*/ - /* We've gotten through all of the dynamic table without incident. */ - /* All dynamic tag values that were virtual section addresses should have*/ - /* been updated with the final address of the section that they point to.*/ - /*-----------------------------------------------------------------------*/ - return TRUE; -} - -/*****************************************************************************/ -/* allocate_dynamic_segments_and relocate_symbols() */ -/* */ -/* Allocate target memory for each segment in this module, getting a */ -/* host-accessible space to copy the content of each segment into. Then */ -/* update the symbol table and program header table to reflect the new */ -/* target address for each segment. Processing of the dynamic relocation */ -/* entries will wait until all dependent files have been loaded and */ -/* allocated into target memory. */ -/* */ -/*---------------------------------------------------------------------------*/ -/* */ -/* The relocation entries in the ELF file do not handle the necessary */ -/* adjustments to the memory addresses in the program header or symbol */ -/* tables. These must be done manually. */ -/* */ -/* This is harder for us than for most dynamic loaders, because we have to */ -/* work in environments without virtual memory and thus where the offsets */ -/* between segments in memory may be different than they were in the file. */ -/* So, even though a dynamic loader usually only has to adjust all the */ -/* segments by a single fixed offset, we need to offset the symbols and */ -/* program header addresses segment by segment. This job is done by the */ -/* function below. */ -/* */ -/*****************************************************************************/ -static BOOL allocate_dynamic_segments_and_relocate_symbols - (DLOAD_HANDLE handle, - LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module) -{ - int i,j; - DLIMP_Loaded_Segment* seg = (DLIMP_Loaded_Segment*) - (dyn_module->loaded_module->loaded_segments.buf); - struct Elf32_Ehdr *fhdr = &(dyn_module->fhdr); - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - -#if LOADER_DEBUG || LOADER_PROFILE - if (debugging_on || profiling_on) - { - DLIF_trace("Dynamic executable found.\n" - "Starting allocate_dynamic_segments_and_relocate_symbols() ...\n"); - if (profiling_on) profile_start_clock(); - } -#endif - - /*-----------------------------------------------------------------------*/ - /* Spin through the list of loaded segments from the current module. */ - /*-----------------------------------------------------------------------*/ - for (i = 0; i < dyn_module->loaded_module->loaded_segments.size; i++) - { - /*-------------------------------------------------------------------*/ - /* Allocate target memory for segment via client-provided target */ - /* memory API. */ - /*-------------------------------------------------------------------*/ - int32_t addr_offset; - struct DLOAD_MEMORY_REQUEST targ_req; - seg[i].obj_desc->target_page = 0; - targ_req.flags = 0; - if (seg[i].phdr.p_flags & PF_X) targ_req.flags |= DLOAD_SF_executable; - targ_req.align = 0x20; - seg[i].obj_desc->target_address = (TARGET_ADDRESS)seg[i].phdr.p_vaddr; - targ_req.flags |= DLOAD_SF_relocatable; - - targ_req.fp = fd; - targ_req.segment = seg[i].obj_desc; - targ_req.offset = seg[i].phdr.p_offset; - targ_req.flip_endian = dyn_module->wrong_endian; - -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Segment %d flags 0x%x\n", i, targ_req.flags); -#endif - if (!DLIF_allocate(pHandle->client_handle, &targ_req)) - { - DLIF_error(DLET_MEMORY, "DLIF allocation failure.\n"); - return FALSE; - } - - /*-------------------------------------------------------------------*/ - /* Calculate the offset we need to adjust segment header and symbol */ - /* table addresses. */ - /*-------------------------------------------------------------------*/ - addr_offset = (int32_t)(seg[i].obj_desc->target_address) - - (int32_t)(seg[i].phdr.p_vaddr); - -#if LOADER_DEBUG - if (debugging_on) - { - DLIF_trace("Segment %d (at 0x%x, 0x%x bytes) relocated to 0x%x\n", - i, - (int32_t)(seg[i].phdr.p_vaddr), - (int32_t)(seg[i].phdr.p_memsz), - (int32_t)(seg[i].obj_desc->target_address)); - DLIF_trace( "Addr Offset is 0x%x\n", addr_offset); - } -#endif - - /*-------------------------------------------------------------------*/ - /* Update program entry point if needed. Need to replace to deal */ - /* with full ELF initialization routine. */ - /*-------------------------------------------------------------------*/ - if (dyn_module->relocate_entry_point && - fhdr->e_entry >= (Elf32_Addr)(seg[i].phdr.p_vaddr) && - fhdr->e_entry < (Elf32_Addr)((uint8_t*)(seg[i].phdr.p_vaddr) + - (uint32_t)(seg[i].phdr.p_memsz))) - { -#if LOADER_DEBUG - if (debugging_on) - { - DLIF_trace("Entry point 0x%x relocated to 0x%x\n", - fhdr->e_entry, fhdr->e_entry + addr_offset); - } -#endif - fhdr->e_entry += addr_offset; - - /*---------------------------------------------------------------*/ - /* Mark the entry point as being relocated so we will not do it */ - /* again. */ - /*---------------------------------------------------------------*/ - dyn_module->relocate_entry_point = FALSE; - } - - /*-------------------------------------------------------------------*/ - /* Fix program header entries in segment and Elf32_Phdr structs. */ - /*-------------------------------------------------------------------*/ - for (j = 0; j < fhdr->e_phnum; j++) - if (dyn_module->phdr[j].p_vaddr == (Elf32_Addr)seg[i].phdr.p_vaddr) - { - dyn_module->phdr[j].p_vaddr += addr_offset; - dyn_module->phdr[i].p_paddr += addr_offset; - break; - } - - seg[i].input_vaddr = (Elf32_Addr)(seg[i].phdr.p_vaddr); - seg[i].phdr.p_vaddr += addr_offset; - - /*-------------------------------------------------------------------*/ - /* Great, now the hard part: fix offsets in symbols. It would be */ - /* nice if there were an easier way to deal with this. */ - /*-------------------------------------------------------------------*/ - { - struct Elf32_Sym *gsymtab = - ((struct Elf32_Sym*)(dyn_module->loaded_module->gsymtab)); - Elf32_Addr segment_start = (Elf32_Addr)seg[i].phdr.p_vaddr; - Elf32_Addr segment_end = (Elf32_Addr)seg[i].phdr.p_vaddr + - seg[i].phdr.p_memsz; - Elf32_Word global_index = dyn_module->symnum - - dyn_module->loaded_module->gsymnum; - - for (j = 0; j < dyn_module->symnum; j++) - { - /*-----------------------------------------------------------*/ - /* Get the relocated symbol value. */ - /*-----------------------------------------------------------*/ - Elf32_Addr symval_adj = dyn_module->symtab[j].st_value + - addr_offset; - - /*-----------------------------------------------------------*/ - /* If the symbol is defined in this segment, update the */ - /* symbol value and mark the symbol so that we don't */ - /* relocate it again. */ - /*-----------------------------------------------------------*/ - if (symval_adj >= segment_start && symval_adj < segment_end && - dyn_module->symtab[j].st_shndx != INT16_MAX) - { - dyn_module->symtab[j].st_value = symval_adj; - - /*-------------------------------------------------------*/ - /* The module symbol table only has the global symbols. */ - /*-------------------------------------------------------*/ - if (j >= global_index) - gsymtab[j-global_index].st_value = symval_adj; - - /*-------------------------------------------------------*/ - /* Mark the symbol as relocated. */ - /*-------------------------------------------------------*/ - dyn_module->symtab[j].st_shndx = INT16_MAX; - } - } - } - } - - /*-----------------------------------------------------------------------*/ - /* Update dynamic tag information. Some dynamic tags have values which */ - /* are virtual addresses of sections. These values need to be updated */ - /* once segment allocation is completed and the new segment addresses are*/ - /* known. */ - /*-----------------------------------------------------------------------*/ - /* We should only traverse through the dynamic table once because we want*/ - /* to avoid the possibility of updating the same tag multiple times (an */ - /* error, if it happens). */ - /*-----------------------------------------------------------------------*/ - if (!relocate_dynamic_tag_info(fd, dyn_module)) - { - DLIF_error(DLET_MISC, "Failed dynamic table update.\n"); - return FALSE; - } - -#if LOADER_DEBUG || LOADER_PROFILE - if (debugging_on || profiling_on) - { - DLIF_trace("allocate_dynamic_segments_and_relocate_symbols() Done\n"); - if (profiling_on) - { - profile_stop_clock(); - DLIF_trace("Took %d cycles.\n", (int)profile_cycle_count()); - } - } -#endif - - return TRUE; -} - -/*****************************************************************************/ -/* delete_DLIMP_Loaded_Module() */ -/* */ -/* Free host memory associated with a DLIMP_Loaded_Module data structure */ -/* and all of the DLIMP_Loaded_Segment objects that are associated with */ -/* it. */ -/* */ -/*****************************************************************************/ -static void delete_DLIMP_Loaded_Module(DLOAD_HANDLE handle, - DLIMP_Loaded_Module **pplm) -{ - DLIMP_Loaded_Module *loaded_module = *pplm; - DLIMP_Loaded_Segment *segments = (DLIMP_Loaded_Segment*) - (loaded_module->loaded_segments.buf); - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - - /*-----------------------------------------------------------------------*/ - /* Spin through the segments attached to this loaded module, freeing up */ - /* any target memory that was allocated by the client for the segment. */ - /*-----------------------------------------------------------------------*/ - int i; - for (i = 0; i < loaded_module->loaded_segments.size; i++) - { - if (!DLIF_release(pHandle->client_handle, segments[i].obj_desc)) - DLIF_error(DLET_MISC, "Failed call to DLIF_release!\n");; - DLIF_free(segments[i].obj_desc); - } - - /*-----------------------------------------------------------------------*/ - /* Hacky way of indicating that the base image is no longer available. */ - /* WHHHHAAAAAAATTT!?!?!?!?!?! */ - /*-----------------------------------------------------------------------*/ - if (loaded_module->file_handle == DLIMP_application_handle) - DLIMP_application_handle = 0; - - /*-----------------------------------------------------------------------*/ - /* Free host heap memory that was allocated for the internal loaded */ - /* module data structure members. */ - /*-----------------------------------------------------------------------*/ - if (loaded_module->name) DLIF_free(loaded_module->name); - if (loaded_module->gsymtab) DLIF_free(loaded_module->gsymtab); - loaded_module->gsymnum = 0; - if (loaded_module->gstrtab) DLIF_free(loaded_module->gstrtab); - loaded_module->gstrsz = 0; - AL_destroy(&(loaded_module->loaded_segments)); - AL_destroy(&(loaded_module->dependencies)); - - /*-----------------------------------------------------------------------*/ - /* Finally, free the host memory for the loaded module object, then NULL */ - /* the pointer that was passed in. */ - /*-----------------------------------------------------------------------*/ - DLIF_free(loaded_module); - *pplm = NULL; -} - -/*****************************************************************************/ -/* new_DLIMP_Dynamic_Module() */ -/* */ -/* Allocate a dynamic module data structure from host memory and */ -/* initialize its members to their default values. */ -/* */ -/*****************************************************************************/ -static DLIMP_Dynamic_Module *new_DLIMP_Dynamic_Module(LOADER_FILE_DESC *fd) -{ - /*-----------------------------------------------------------------------*/ - /* Allocate space for dynamic module data structure from host memory. */ - /*-----------------------------------------------------------------------*/ - DLIMP_Dynamic_Module *dyn_module = - (DLIMP_Dynamic_Module *)DLIF_malloc(sizeof(DLIMP_Dynamic_Module)); - - if (!dyn_module) - return NULL; - - /*-----------------------------------------------------------------------*/ - /* Initialize data members of the new dynamic module data structure. */ - /*-----------------------------------------------------------------------*/ - dyn_module->name = NULL; - dyn_module->fd = fd; - dyn_module->phdr = NULL; - dyn_module->phnum = 0; - dyn_module->strtab = NULL; - dyn_module->strsz = 0; - dyn_module->dyntab = NULL; - dyn_module->symtab = NULL; - dyn_module->symnum = 0; - dyn_module->gsymtab_offset = 0; - dyn_module->gstrtab_offset = 0; - dyn_module->c_args = NULL; - dyn_module->argc = 0; - dyn_module->argv = NULL; - dyn_module->loaded_module = NULL; - dyn_module->wrong_endian = 0; - dyn_module->direct_dependent_only = TRUE; - dyn_module->relocatable = FALSE; - dyn_module->relocate_entry_point = TRUE; - - dyn_module->dsbt_size = 0; - dyn_module->dsbt_index = DSBT_INDEX_INVALID; - dyn_module->dsbt_base_tagidx = -1; - - dyn_module->preinit_array_idx = -1; - dyn_module->preinit_arraysz = 0; - dyn_module->init_idx = -1; - dyn_module->init_array_idx = -1; - dyn_module->init_arraysz = 0; - - return dyn_module; -} - -/*****************************************************************************/ -/* detach_loaded_module() */ -/* */ -/* Detach loaded module data structure from given dynamic module. When */ -/* an object file has been successfully loaded, the loader core will */ -/* detach the loaded module data structure from the dynamic module data */ -/* structure because the loaded module must continue to persist until is */ -/* is actually unloaded from target memory. If there is a problem with */ -/* the load, then the host memory associated with the loaded module will */ -/* be released as part of the destruction of the dynamic module. */ -/* */ -/*****************************************************************************/ -static DLIMP_Loaded_Module *detach_loaded_module(DLIMP_Dynamic_Module *dyn_module) -{ - if (dyn_module && dyn_module->loaded_module) - { - DLIMP_Loaded_Module *loaded_module = dyn_module->loaded_module; - dyn_module->loaded_module = NULL; - return loaded_module; - } - - return NULL; -} -/*****************************************************************************/ -/* delete_DLIMP_Dynamic_Module() */ -/* */ -/* Remove local copies of the string table, symbol table, program header */ -/* table, and dynamic table. */ -/* */ -/*****************************************************************************/ -static void delete_DLIMP_Dynamic_Module(DLOAD_HANDLE handle, - DLIMP_Dynamic_Module **ppdm) -{ - DLIMP_Dynamic_Module *dyn_module = NULL; - - if (!ppdm || (*ppdm == NULL)) - { - DLIF_error(DLET_MISC, - "Internal Error: invalid argument to dynamic module " - "destructor function; aborting loader\n"); - exit(1); - } - - dyn_module = *ppdm; - if (dyn_module->name) DLIF_free(dyn_module->name); - if (dyn_module->strtab) DLIF_free(dyn_module->strtab); - if (dyn_module->symtab) DLIF_free(dyn_module->symtab); - if (dyn_module->phdr) DLIF_free(dyn_module->phdr); - if (dyn_module->dyntab) DLIF_free(dyn_module->dyntab); - - /*-----------------------------------------------------------------------*/ - /* If we left the loaded module attached to the dynamic module, then */ - /* something must have gone wrong with the load. Remove the loaded */ - /* module from the queue of loaded modules, if it is there. Then free */ - /* the host memory allocated to the loaded module and its segments. */ - /*-----------------------------------------------------------------------*/ - if (dyn_module->loaded_module != NULL) - delete_DLIMP_Loaded_Module(handle, &(dyn_module->loaded_module)); - - /*-----------------------------------------------------------------------*/ - /* Finally, free the host memory for this dynamic module object and NULL */ - /* the pointer to the object. */ - /*-----------------------------------------------------------------------*/ - DLIF_free(dyn_module); - *ppdm = NULL; -} - -/*****************************************************************************/ -/* file_header_magic_number_is_valid() */ -/* */ -/* Given an object file header, check the magic number to ensure that it */ -/* is an object file format that we recognize. This implementation of */ -/* the dynamic loader core will handle ELF object file format. */ -/* */ -/*****************************************************************************/ -static BOOL file_header_magic_number_is_valid(struct Elf32_Ehdr* header) -{ - /*-----------------------------------------------------------------------*/ - /* Check for correct ELF magic numbers in file header. */ - /*-----------------------------------------------------------------------*/ - if (!header->e_ident[EI_MAG0] == ELFMAG0 || - !header->e_ident[EI_MAG1] == ELFMAG1 || - !header->e_ident[EI_MAG2] == ELFMAG2 || - !header->e_ident[EI_MAG3] == ELFMAG3) - { - DLIF_error(DLET_FILE, "Invalid ELF magic number.\n"); - return FALSE; - } - - return TRUE; -} - -/*****************************************************************************/ -/* file_header_machine_is_valid() */ -/* */ -/* Check if the machine specified in the file header is supported by the */ -/* loader. If the loader was compiled with support for all targets, */ -/* the machine will be initially set to EM_NONE. Once a module has been */ -/* loaded, all remaining modules must have the same machine value. */ -/*****************************************************************************/ -static BOOL file_header_machine_is_valid(DLOAD_HANDLE handle, Elf32_Half e_machine) -{ - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - - if (pHandle->DLOAD_TARGET_MACHINE == EM_NONE) - pHandle->DLOAD_TARGET_MACHINE = e_machine; - - if (e_machine != pHandle->DLOAD_TARGET_MACHINE) - return FALSE; - - return TRUE; -} - -/*****************************************************************************/ -/* is_valid_elf_object_file() */ -/* */ -/* Check file size against anticipated end location of string table, */ -/* symbol table, program header tables, etc. If we anything untoward, */ -/* then we declare that the ELF file is corrupt and the load is aborted. */ -/* */ -/*****************************************************************************/ -static BOOL is_valid_elf_object_file(LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module) -{ - uint32_t fsz; - int i; - - /*-----------------------------------------------------------------------*/ - /* Get file size. */ - /*-----------------------------------------------------------------------*/ - DLIF_fseek(fd, 0, LOADER_SEEK_END); - fsz = DLIF_ftell(fd); - - /*-----------------------------------------------------------------------*/ - /* Check for invalid table sizes (string table, symbol table, and */ - /* program header tables). */ - /*-----------------------------------------------------------------------*/ - if (!((dyn_module->strsz < fsz) && - (dyn_module->symnum < fsz) && - (dyn_module->phnum * sizeof(struct Elf32_Phdr)) < fsz)) - { - DLIF_error(DLET_FILE, "Invalid ELF table bounds.\n"); - return FALSE; - } - - /*-----------------------------------------------------------------------*/ - /* Check for null so_name string in file with dynamic information. */ - /*-----------------------------------------------------------------------*/ - if (dyn_module->dyntab && !strcmp(dyn_module->name, "")) - { - DLIF_error(DLET_MISC, "Dynamic file lacks SO_NAME identifier.\n"); - return FALSE; - } - - /*-----------------------------------------------------------------------*/ - /* Check for invalid program header information. */ - /*-----------------------------------------------------------------------*/ - for (i = 0; i < dyn_module->phnum; i++) - { - struct Elf32_Phdr* phdr = dyn_module->phdr + i; - - /*-------------------------------------------------------------------*/ - /* Sanity check for relative sizes of filesz and memsz. */ - /*-------------------------------------------------------------------*/ - if (!(phdr->p_type != PT_LOAD || phdr->p_filesz <= phdr->p_memsz)) - { - DLIF_error(DLET_MISC, - "Invalid file or memory size for segment %d.\n", i); - return FALSE; - } - - /*-------------------------------------------------------------------*/ - /* Check that segment file offset doesn't go off the end of the file.*/ - /*-------------------------------------------------------------------*/ - if (!(phdr->p_offset + phdr->p_filesz < fsz)) - { - DLIF_error(DLET_FILE, - "File location of segment %d is past the end of file.\n", i); - return FALSE; - } - } - - /*-----------------------------------------------------------------------*/ - /* Check that a ET_DYN-type file is relocatable. */ - /*-----------------------------------------------------------------------*/ - if (dyn_module->fhdr.e_type == ET_DYN && !dyn_module->symtab) return FALSE; - - /*-----------------------------------------------------------------------*/ - /* All checks passed. */ - /*-----------------------------------------------------------------------*/ - return TRUE; -} - -/*****************************************************************************/ -/* process_eiosabi() */ -/* */ -/* Check the EI_OSABI field to validate it and set any parameters based on */ -/* it. */ -/*****************************************************************************/ -static BOOL process_eiosabi(DLIMP_Dynamic_Module* dyn_module) -{ -#if ARM_TARGET - if (is_arm_module(&dyn_module->fhdr)) - return DLDYN_arm_process_eiosabi(dyn_module); -#endif - -#if C60_TARGET - if (is_c60_module(&dyn_module->fhdr)) - return DLDYN_c60_process_eiosabi(dyn_module); -#endif - - return FALSE; -} -/*****************************************************************************/ -/* dload_file_header() */ -/* */ -/* Read ELF file header. Store critical information in the provided */ -/* DLIMP_Dynamic_Module record. Check file header for validity. */ -/* */ -/*****************************************************************************/ -static BOOL dload_file_header(DLOAD_HANDLE handle, LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module) -{ - /*-----------------------------------------------------------------------*/ - /* Read ELF file header from given input file. */ - /*-----------------------------------------------------------------------*/ - DLIF_fread(&(dyn_module->fhdr), sizeof(struct Elf32_Ehdr), 1, fd); - - /*-----------------------------------------------------------------------*/ - /* Determine target vs. host endian-ness. Does header data need to be */ - /* byte swapped? */ - /*-----------------------------------------------------------------------*/ - dyn_module->wrong_endian = - (dyn_module->fhdr.e_ident[EI_DATA] != DLIMP_get_endian()); - - /*-----------------------------------------------------------------------*/ - /* Swap file header structures, if needed. */ - /*-----------------------------------------------------------------------*/ - if (dyn_module->wrong_endian) - DLIMP_change_ehdr_endian(&(dyn_module->fhdr)); - -#if LOADER_DEBUG - if (debugging_on) { - /*-------------------------------------------------------------------*/ - /* Write out magic ELF information for debug purposes. */ - /*-------------------------------------------------------------------*/ - DLIF_trace("ELF: %c%c%c\n", dyn_module->fhdr.e_ident[1], - dyn_module->fhdr.e_ident[2], - dyn_module->fhdr.e_ident[3]); - DLIF_trace("ELF file header entry point: %x\n", - dyn_module->fhdr.e_entry); - } -#endif - - /*-----------------------------------------------------------------------*/ - /* Verify magic numbers in ELF file header. */ - /*-----------------------------------------------------------------------*/ - if (!file_header_magic_number_is_valid(&(dyn_module->fhdr))) - { - DLIF_error(DLET_FILE, "Invalid ELF file header magic number.\n"); - return FALSE; - } - - if (!file_header_machine_is_valid(handle, dyn_module->fhdr.e_machine)) - { - DLIF_error(DLET_FILE, "Invalid ELF file target machine.\n"); - DLIF_trace("dyn_module->fhdr.e_machine = 0x%x\n", - dyn_module->fhdr.e_machine); - return FALSE; - } - - /*-----------------------------------------------------------------------*/ - /* Verify file is an executable or dynamic shared object or library. */ - /*-----------------------------------------------------------------------*/ - if ((dyn_module->fhdr.e_type != ET_EXEC) && - (dyn_module->fhdr.e_type != ET_DYN)) - { - DLIF_error(DLET_FILE, "Invalid ELF file type.\n"); - return FALSE; - } - -#if LOADER_DEBUG || LOADER_PROFILE - /*-----------------------------------------------------------------------*/ - /* Stop profiling clock when file header information has finished */ - /* loading. Re-start clock on initialization of symbol table, and */ - /* dynamic table pointers. */ - /*-----------------------------------------------------------------------*/ - if (debugging_on || profiling_on) - { - DLIF_trace("done.\n"); - if (profiling_on) - { - profile_stop_clock(); - DLIF_trace("Took %d cycles.\n", (int)profile_cycle_count()); - profile_start_clock(); - } - } -#endif - - return TRUE; -} - -/*****************************************************************************/ -/* dload_program_header_table() */ -/* */ -/* Make a local copy of the ELF object file's program header table in the */ -/* dynamic module data structure. */ -/* */ -/*****************************************************************************/ -static void dload_program_header_table(LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module) -{ - /*-----------------------------------------------------------------------*/ - /* Read the program header tables from the object file. */ - /*-----------------------------------------------------------------------*/ - struct Elf32_Ehdr *fhdr = &(dyn_module->fhdr); - dyn_module->phdr = (struct Elf32_Phdr*) - (DLIF_malloc(fhdr->e_phnum * fhdr->e_phentsize)); - DLIF_fseek(fd, fhdr->e_phoff, LOADER_SEEK_SET); - if(dyn_module->phdr) { - DLIF_fread(dyn_module->phdr, fhdr->e_phentsize, fhdr->e_phnum,fd); - dyn_module->phnum = fhdr->e_phnum; - - /*-------------------------------------------------------------------*/ - /* Byte swap the program header tables if the target endian-ness is */ - /* not the same as the host endian-ness. */ - /*-------------------------------------------------------------------*/ - if (dyn_module->wrong_endian) - { - int i; - for (i = 0; i < dyn_module->phnum; i++) - DLIMP_change_phdr_endian(dyn_module->phdr + i); - } - } -} - -/*****************************************************************************/ -/* dload_headers() */ -/* */ -/* Read ELF object file header and program header table information into */ -/* the given dynamic module data structure. If the object file contains */ -/* dynamic information, read in the dynamic tags, dynamic symbol table, */ -/* and global string table. Check to make sure that we are not already */ -/* in the process of loading the module (circular dependencies), then */ -/* perform some level of sanity checking on the content of the file to */ -/* provide some assurance that the file is not corrupted. */ -/* */ -/*****************************************************************************/ -static BOOL dload_headers(DLOAD_HANDLE handle, LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module) -{ -#if LOADER_DEBUG || LOADER_PROFILE - /*-----------------------------------------------------------------------*/ - /* More progress information. Start timing if profiling is enabled. */ - /*-----------------------------------------------------------------------*/ - if (debugging_on || profiling_on) - { - DLIF_trace("\nReading file headers ...\n"); - if (profiling_on) profile_start_clock(); - } -#endif - - /*-----------------------------------------------------------------------*/ - /* Read file header information and check vs. expected ELF object file */ - /* header content. */ - /*-----------------------------------------------------------------------*/ - if (!dload_file_header(handle, fd, dyn_module)) - return FALSE; - - /*-----------------------------------------------------------------------*/ - /* Read program header table information into the dynamic module object. */ - /*-----------------------------------------------------------------------*/ - dload_program_header_table(fd, dyn_module); - - return TRUE; -} - -/*****************************************************************************/ -/* find_dynamic_segment() */ -/* */ -/* Find the dynamic segment in the given ELF object file, if there is */ -/* one. If the segment is found, then the segment ID output parameter */ -/* is set to the index of the dynamic segment in the program header */ -/* table. If the dynamic segment is not found, the dynamic module's */ -/* relocatable flag is set to FALSE, and return FALSE. */ -/* */ -/*****************************************************************************/ -static BOOL find_dynamic_segment(DLIMP_Dynamic_Module *dyn_module, - Elf32_Word *dyn_seg_idx) -{ - int i; - - /*-----------------------------------------------------------------------*/ - /* We should have a valid dynamic module pointer and somewhere to put the*/ - /* dynamic segment id, if we find one. If either of these are missing, */ - /* we should get an internal error and abort the loader. */ - /*-----------------------------------------------------------------------*/ - if ((dyn_module == NULL) || (dyn_seg_idx == NULL)) - { - DLIF_error(DLET_MISC, "Internal error: find_dynamic_segment() needs " - "non-NULL arguments.\n"); - exit(1); - } - - /*-----------------------------------------------------------------------*/ - /* Spin through segment program headers to find the dynamic segment. */ - /*-----------------------------------------------------------------------*/ - dyn_module->relocatable = TRUE; - for (i = 0; i < dyn_module->phnum; i++) - if (dyn_module->phdr[i].p_type == PT_DYNAMIC) - { *dyn_seg_idx = i; return TRUE; } - - /*-----------------------------------------------------------------------*/ - /* No dynamic segment found, mark the object module as not relocatable */ - /* and warn the user. */ - /*-----------------------------------------------------------------------*/ - dyn_module->relocatable = FALSE; -#if LOADER_DEBUG - DLIF_warning(DLWT_MISC, "'%s' does not have a dynamic segment; assuming " - "that it is a static executable and it cannot " - "be relocated.\n", dyn_module->name); -#endif - return FALSE; -} - -/*****************************************************************************/ -/* copy_dynamic_table() */ -/* */ -/* Make a local copy of the dynamic table read from the dynamic segment */ -/* in the ELF object file. */ -/* */ -/*****************************************************************************/ -static void copy_dynamic_table(LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module, - Elf32_Word dyn_seg_idx) -{ - /*-----------------------------------------------------------------------*/ - /* Allocate space for the dynamic table from host memory and read its */ - /* content from the ELF object file. */ - /*-----------------------------------------------------------------------*/ - Elf32_Word num_elem; - dyn_module->dyntab = DLIF_malloc(dyn_module->phdr[dyn_seg_idx].p_filesz); - num_elem = - dyn_module->phdr[dyn_seg_idx].p_filesz / sizeof(struct Elf32_Dyn); - DLIF_fseek(fd, dyn_module->phdr[dyn_seg_idx].p_offset, LOADER_SEEK_SET); - if(dyn_module->dyntab) { - DLIF_fread(dyn_module->dyntab, sizeof(struct Elf32_Dyn), num_elem, fd); - - /*-------------------------------------------------------------------*/ - /* If necessary, byte swap each entry in the dynamic table. */ - /*-------------------------------------------------------------------*/ - if (dyn_module->wrong_endian) - { - int i; - for (i = 0; i < num_elem; i++) - DLIMP_change_dynent_endian(&dyn_module->dyntab[i]); - } - } -} - -/*****************************************************************************/ -/* process_target_dynamic_tag() */ -/* */ -/* Process a target specific dynamic tag entry. Returns TRUE if the tag */ -/* was handled and FALSE if it was not recognized. */ -/*****************************************************************************/ -static BOOL process_target_dynamic_tag(DLIMP_Dynamic_Module* dyn_module, int i) -{ -#ifdef ARM_TARGET - if (is_arm_module(&dyn_module->fhdr)) - return DLDYN_arm_process_dynamic_tag(dyn_module, i); -#endif - -#ifdef C60_TARGET - if (is_c60_module(&dyn_module->fhdr)) - return DLDYN_c60_process_dynamic_tag(dyn_module, i); -#endif - - return FALSE; -} - -/*****************************************************************************/ -/* process_dynamic_table() */ -/* */ -/* Process dynamic tag entries from the dynamic table. At the conclusion */ -/* of this function, we should have made a copy of the global symbols */ -/* and the global symbol names. */ -/* */ -/*****************************************************************************/ -static BOOL process_dynamic_table(LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module) -{ - int i; - BOOL soname_found = FALSE; - Elf32_Addr soname_offset = 0; - Elf32_Addr strtab_offset = 0; - Elf32_Addr hash_offset = 0; - Elf32_Addr symtab_offset = 0; - - /*-----------------------------------------------------------------------*/ - /* Iterate over the dynamic table in order to process dynamic tags. */ - /* See ELF TIS Specification for details on the meaning of each dynamic */ - /* tag. The C6000 ELF ABI Specification provides more details about the */ - /* TI specific C6000 ELF ABI tags. */ - /*-----------------------------------------------------------------------*/ - for (i = 0; dyn_module->dyntab[i].d_tag != DT_NULL; i++) - { - switch(dyn_module->dyntab[i].d_tag) - { - /*---------------------------------------------------------------*/ - /* DT_SONAME: Contains name of dynamic object, used for */ - /* dependency comparisons. Its value is an offset */ - /* from the start of the string table. We need to */ - /* copy the string at this offset into dmodule->name. */ - /*------------------------------------------------------------- -*/ - case DT_SONAME: -#if LOADER_DEBUG - if (debugging_on) DLIF_trace("Found SO_NAME.\n"); -#endif - /*-----------------------------------------------------------*/ - /* We store the offset of the so_name in the dynamic string */ - /* table so that it doesn't matter which dynamic tag we see */ - /* first (DT_SONAME actually is generated before DT_STRTAB). */ - /*-----------------------------------------------------------*/ - soname_found = TRUE; - soname_offset = dyn_module->dyntab[i].d_un.d_ptr; - break; - - /*---------------------------------------------------------------*/ - /* DT_STRSZ: Contains the size of the string table. */ - /*---------------------------------------------------------------*/ - case DT_STRSZ: - dyn_module->strsz = dyn_module->dyntab[i].d_un.d_val; - -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Found string table Size: 0x%x\n", - dyn_module->strsz); -#endif - break; - - /*---------------------------------------------------------------*/ - /* DT_STRTAB: Contains the file offset of the string table. The */ - /* tag directly after this is guaranteed to be */ - /* DT_STRSZ, containing the string table size. We */ - /* need to allocate memory for the string table and */ - /* copy it from the file. */ - /*---------------------------------------------------------------*/ - case DT_STRTAB: - strtab_offset = dyn_module->dyntab[i].d_un.d_ptr; -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Found string table: 0x%x\n", strtab_offset); -#endif - break; - - /*---------------------------------------------------------------*/ - /* DT_HASH: Contains the file offset of the symbol hash table. */ - /*---------------------------------------------------------------*/ - case DT_HASH: - hash_offset = dyn_module->dyntab[i].d_un.d_ptr; -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Found symbol hash table: 0x%x\n", hash_offset); -#endif - break; - - /*---------------------------------------------------------------*/ - /* DT_SYMTAB: Contains the file offset of the symbol table. */ - /*---------------------------------------------------------------*/ - case DT_SYMTAB: - symtab_offset = dyn_module->dyntab[i].d_un.d_ptr; -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Found symbol table: 0x%x\n", symtab_offset); -#endif - break; - - /*---------------------------------------------------------------*/ - /* DSO Initialization / Termination Model Dynamic Tags */ - /*---------------------------------------------------------------*/ - /* For initialization tags, we store indices and array sizes in */ - /* the dyn_module. Termination works a little different, the */ - /* indices into the local copy of the dynamic table are stored */ - /* in dyn_module, but the DT_FINI_ARRAYSZ value is recorded with */ - /* the loaded module. */ - /*---------------------------------------------------------------*/ - /* After placement is done, the DT_FINI and DT_FINI_ARRAY values */ - /* need to be copied from the local dynamic table into the */ - /* loaded module object. */ - /*---------------------------------------------------------------*/ - case DT_PREINIT_ARRAY: - dyn_module->preinit_array_idx = i; - break; - - case DT_PREINIT_ARRAYSZ: - dyn_module->preinit_arraysz = dyn_module->dyntab[i].d_un.d_val; - break; - - case DT_INIT: - dyn_module->init_idx = i; - break; - - case DT_INIT_ARRAY: - dyn_module->init_array_idx = i; - break; - - case DT_INIT_ARRAYSZ: - dyn_module->init_arraysz = dyn_module->dyntab[i].d_un.d_val; - break; - - /*---------------------------------------------------------------*/ - /* This information will be copied over to the loaded module */ - /* object after placement has been completed and the information */ - /* in the dynamic table has been relocated. */ - /*---------------------------------------------------------------*/ - case DT_FINI_ARRAY: - case DT_FINI_ARRAYSZ: - case DT_FINI: - break; - - /*---------------------------------------------------------------*/ - /* Unrecognized tag, may not be illegal, but is not explicitly */ - /* handled by this function. Should it be? */ - /*---------------------------------------------------------------*/ - default: - { - if (!process_target_dynamic_tag(dyn_module, i)) - { -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Unrecognized dynamic tag: 0x%X\n", - dyn_module->dyntab[i].d_tag); -#endif - } - - break; - } - - } - } - - /*-----------------------------------------------------------------------*/ - /* If string table offset and size were found, read string table in from */ - /* the ELF object file. */ - /*-----------------------------------------------------------------------*/ - if (strtab_offset && dyn_module->strsz) - { - DLIF_fseek(fd, strtab_offset, LOADER_SEEK_SET); - dyn_module->strtab = DLIF_malloc(dyn_module->strsz); - if(dyn_module->strtab) - DLIF_fread(dyn_module->strtab, sizeof(uint8_t), dyn_module->strsz, - fd); - else - return FALSE; - } - else - { - DLIF_warning(DLWT_MISC, - "Mandatory dynamic tag DT_STRTAB/DT_STRSZ not found!\n"); - return FALSE; - } - - - /*-----------------------------------------------------------------------*/ - /* If symbol hash table is found read-in the hash table. */ - /*-----------------------------------------------------------------------*/ - if (hash_offset) - { - /*-------------------------------------------------------------------*/ - /* Hash table has the following format. nchain equals the number of */ - /* entries in the symbol table (symnum) */ - /* */ - /* +----------------------------+ */ - /* | nbucket | */ - /* +----------------------------+ */ - /* | nchain | */ - /* +----------------------------+ */ - /* | bucket[0] | */ - /* | ... | */ - /* | bucket[nbucket-1] | */ - /* +----------------------------+ */ - /* | chain[0] | */ - /* | ... | */ - /* | chain[nchain-1] | */ - /* +----------------------------+ */ - /*-------------------------------------------------------------------*/ - Elf32_Word hash_nbucket; - Elf32_Word hash_nchain; - - /*-------------------------------------------------------------------*/ - /* Seek to the hash offset and read first two words into nbucket and */ - /* symnum. */ - /*-------------------------------------------------------------------*/ - DLIF_fseek(fd, hash_offset, LOADER_SEEK_SET); - DLIF_fread(&(hash_nbucket), sizeof(Elf32_Word), 1, fd); - DLIF_fread(&(hash_nchain), sizeof(Elf32_Word), 1, fd); - if (dyn_module->wrong_endian) - { - DLIMP_change_endian32((int32_t*)(&(hash_nbucket))); - DLIMP_change_endian32((int32_t*)(&(hash_nchain))); - } - - /*-------------------------------------------------------------------*/ - /* The number of entires in the dynamic symbol table is not encoded */ - /* anywhere in the elf file. However, the nchain is guaranteed to be */ - /* the same as the number of symbols. Use nchain to set the symnum. */ - /*-------------------------------------------------------------------*/ - dyn_module->symnum = hash_nchain; -#if LOADER_DEBUG - if (debugging_on) DLIF_trace("symnum=%d\n", hash_nchain); -#endif - } - else - { - DLIF_warning(DLWT_MISC, - "Mandatory dynamic tag DT_HASH is not found!\n"); - return FALSE; - } - - /*-----------------------------------------------------------------------*/ - /* Read dynamic symbol table. */ - /*-----------------------------------------------------------------------*/ - if (symtab_offset) - { - int j = 0; - DLIF_fseek(fd, symtab_offset, LOADER_SEEK_SET); - dyn_module->symtab = - DLIF_malloc(dyn_module->symnum * sizeof(struct Elf32_Sym)); - if(dyn_module->symtab == NULL) - return FALSE; - DLIF_fread(dyn_module->symtab, sizeof(struct Elf32_Sym), - dyn_module->symnum, fd); - if (dyn_module->wrong_endian) - { - for (j = 0; j < dyn_module->symnum; j++) - DLIMP_change_sym_endian(dyn_module->symtab + j); - } - - /*-------------------------------------------------------------------*/ - /* The st_name field of an Elf32_Sym entity is an offset into the */ - /* string table. Convert it into a pointer to the string. */ - /*-------------------------------------------------------------------*/ - if (strtab_offset) - for (j = 0; j < dyn_module->symnum; j++) { - dyn_module->symtab[j].st_name += - (Elf32_Word) dyn_module->strtab; -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Name of dynamic entry: %s\n", - dyn_module->symtab[j].st_name); -#endif - } - } - else - { - DLIF_warning(DLWT_MISC, - "Mandatory dynamic tag DT_SYMTAB is not found!\n"); - return FALSE; - } - - /*-----------------------------------------------------------------------*/ - /* Read the SONAME. */ - /*-----------------------------------------------------------------------*/ - if (!soname_found) - { - DLIF_warning(DLWT_MISC, "Dynamic tag DT_SONAME is not found!\n"); - dyn_module->name = DLIF_malloc(sizeof(char)); - if(dyn_module->name) - *dyn_module->name = '\0'; - else - return FALSE; - } - else - { - dyn_module->name = - DLIF_malloc(strlen(dyn_module->strtab + soname_offset) + 1); - if(dyn_module->name) { - strcpy(dyn_module->name, dyn_module->strtab + soname_offset); -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Name of dynamic object: %s\n", dyn_module->name); -#endif - } - else { - DLIF_error(DLET_MISC, "Error allocating memory %d.\n",__LINE__); - return FALSE; - } - } - - return TRUE; -} - - -/*****************************************************************************/ -/* dload_dynamic_information() */ -/* */ -/* Given a dynamic module with a dynamic segment which is located via */ -/* given dynamic segment index, make a local copy of the dynamic table */ -/* in the dynamic module object, then process the dynamic tag entries in */ -/* the table. */ -/* */ -/*****************************************************************************/ -static BOOL dload_dynamic_information(LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module, - Elf32_Word dyn_seg_idx) -{ - /*-----------------------------------------------------------------------*/ - /* Read a copy of the dynamic table into the dynamic module object. */ - /*-----------------------------------------------------------------------*/ - copy_dynamic_table(fd, dyn_module, dyn_seg_idx); - - /*-----------------------------------------------------------------------*/ - /* Process dynamic entries in the dynamic table. If any problems are */ - /* encountered, the loader should emit an error or warning and return */ - /* FALSE here. */ - /*-----------------------------------------------------------------------*/ - return process_dynamic_table(fd, dyn_module); -} - -/*****************************************************************************/ -/* check_circular_dependency() */ -/* */ -/* Determine whether a dynamic module is already in the process of being */ -/* loaded before we try to start loading it again. If it is already */ -/* being loaded, then the dynamic loader has detected a circular */ -/* dependency. An error will be emitted and the load will be aborted. */ -/* */ -/*****************************************************************************/ -static BOOL check_circular_dependency(DLOAD_HANDLE handle, - const char *dyn_mod_name) -{ - /*-----------------------------------------------------------------------*/ - /* Check the name of the given dependency module to be loaded against */ - /* the list of modules that are currently in the process of being */ - /* loaded. Report an error if any circular dependencies are detected. */ - /*-----------------------------------------------------------------------*/ - int i; - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - - for (i = 0; i < pHandle->DLIMP_module_dependency_list.size; i++) - if (!strcmp(dyn_mod_name, - ((char**)(pHandle->DLIMP_module_dependency_list.buf))[i])) - { - DLIF_error(DLET_MISC, - "Circular dependency detected, '%s' is already in the " - "process of loading.\n", dyn_mod_name); - return FALSE; - } - - return TRUE; -} - -/*****************************************************************************/ -/* dload_dynamic_segment() */ -/* */ -/* Find the dynamic segment in the given ELF module, if there is one. */ -/* If there is a dynamic segment, then make a local copy of the dynamic */ -/* table in the dynamic module object provided, then process the dynamic */ -/* tag entries in the table. */ -/* */ -/* If there is no dynamic segment, then we return success from this */ -/* function, marking the dynamic module as "not relocatable". */ -/* */ -/*****************************************************************************/ -static BOOL dload_dynamic_segment(DLOAD_HANDLE handle, - LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module) -{ - /*-----------------------------------------------------------------------*/ - /* If we don't find dynamic segment, the relocatable flag will have been */ - /* set to false to indicate that the module is a static executable. We */ - /* still return TRUE from this function so that we can proceed with */ - /* static loading. */ - /*-----------------------------------------------------------------------*/ - Elf32_Word dyn_seg_idx = 0; - if (!find_dynamic_segment(dyn_module, &dyn_seg_idx)) - return TRUE; - - /*-----------------------------------------------------------------------*/ - /* Process the OSABI now, after we know if the module is relocatable. */ - /*-----------------------------------------------------------------------*/ - if (!process_eiosabi(dyn_module)) - { - DLIF_error(DLET_FILE, "Unsupported EI_OSABI value.\n"); - return FALSE; - } - - /*-----------------------------------------------------------------------*/ - /* Read the dynamic table from the ELF file, then process the dynamic */ - /* tags in the table. */ - /*-----------------------------------------------------------------------*/ - if (!dload_dynamic_information(fd, dyn_module, dyn_seg_idx)) - return FALSE; - - /*-----------------------------------------------------------------------*/ - /* Check to make sure that this module is not already being loaded. If */ - /* is, then it will cause a circular dependency to be introduced. */ - /* Loader should detect circular dependencies and emit an error. */ - /*-----------------------------------------------------------------------*/ - if (!check_circular_dependency(handle, dyn_module->name)) - return FALSE; - - return TRUE; -} - -/*****************************************************************************/ -/* COPY_SEGMENTS() - */ -/* */ -/* Copy all segments into host memory. */ -/*****************************************************************************/ -static void copy_segments(DLOAD_HANDLE handle, LOADER_FILE_DESC* fp, - DLIMP_Dynamic_Module* dyn_module, int* data) -{ - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - DLIMP_Loaded_Segment* seg = - (DLIMP_Loaded_Segment*)(dyn_module->loaded_module->loaded_segments.buf); - int s, seg_size = dyn_module->loaded_module->loaded_segments.size; - void **va = DLIF_malloc(seg_size * sizeof(void*)); - - if (!va) { - DLIF_error(DLET_MISC, "Failed to allocate va in copy_segments.\n"); - return; - } - else - *data = (int)va; - - for (s=0; sclient_handle, &targ_req); - - va[s] = targ_req.host_address; - - /*-------------------------------------------------------------------*/ - /* Calculate offset for relocations. */ - /*-------------------------------------------------------------------*/ - seg[s].reloc_offset = (int32_t)(targ_req.host_address) - - (int32_t)(seg[s].obj_desc->target_address); - } -} - -/*****************************************************************************/ -/* WRITE_SEGMENTS() - */ -/* */ -/* Write all segments to target memory. */ -/*****************************************************************************/ -static void write_segments(DLOAD_HANDLE handle, LOADER_FILE_DESC* fp, - DLIMP_Dynamic_Module* dyn_module, int* data) -{ - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - DLIMP_Loaded_Segment* seg = - (DLIMP_Loaded_Segment*)(dyn_module->loaded_module->loaded_segments.buf); - int s, seg_size = dyn_module->loaded_module->loaded_segments.size; - void **va = (void *)*data; - - if (!va) { - DLIF_error(DLET_MISC, "Invalid host virtual address array passed into" - "write_segments.\n"); - return; - } - - for (s=0; sclient_handle, &targ_req); - } - - DLIF_free(va); -} - -/*****************************************************************************/ -/* DLOAD_initialize() */ -/* */ -/* Construct and initialize data structures internal to the dynamic */ -/* loader core. */ -/* */ -/*---------------------------------------------------------------------------*/ -/* */ -/* This implementation of DLOAD_initialize() will set up the list of */ -/* dependency modules maintained by the loader core. This list contains */ -/* the names of the files that the loader is in the process of loading. */ -/* The list is used to keep track of what objects are waiting on their */ -/* dependents to be loaded so thath circular dependencies can be detected */ -/* and reported by the core loader. */ -/* */ -/*****************************************************************************/ -void DLOAD_initialize(DLOAD_HANDLE handle) -{ - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - - /*-----------------------------------------------------------------------*/ - /* Set up initial objects_loading queue. */ - /*-----------------------------------------------------------------------*/ - AL_initialize(&pHandle->DLIMP_module_dependency_list, - sizeof (const char*), 1); -} - - -/*****************************************************************************/ -/* DLOAD_finalize() */ -/* */ -/* Destroy and finalize data structures internal to the dynamic */ -/* loader core. */ -/* */ -/*---------------------------------------------------------------------------*/ -/* */ -/* This implementation of DLOAD_finalize() will destroy the list of */ -/* dependency modules maintained by the loader core that is created */ -/* during DLOAD_initialize(). */ -/* */ -/*****************************************************************************/ -void DLOAD_finalize(DLOAD_HANDLE handle) -{ - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - - /*-----------------------------------------------------------------------*/ - /* Destroy initial objects_loading queue. */ - /*-----------------------------------------------------------------------*/ - AL_destroy(&pHandle->DLIMP_module_dependency_list); -} - - -/*****************************************************************************/ -/* dload_static_executable() */ -/* */ -/* Account for target memory allocated to static executable and wrap up */ -/* loading. No relocation is necessary. */ -/* */ -/*****************************************************************************/ -static int32_t dload_static_executable(DLOAD_HANDLE handle, - LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module) -{ - int32_t local_file_handle = 0; - -#if LOADER_DEBUG - if (debugging_on) DLIF_trace("Starting dload_static_executable() ...\n"); -#endif - - /*-----------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ - /* Set entry point for static executable and attempt to allocate target */ - /* memory for the static executable. */ - /*-----------------------------------------------------------------------*/ - dyn_module->loaded_module->entry_point = dyn_module->fhdr.e_entry; - if (load_static_segment(handle, fd, dyn_module) && - load_object(fd, dyn_module)) - { - /*-------------------------------------------------------------------*/ - /* If successful, we'll want to detach the loaded module object from */ - /* the dynamic module object that created it. Take note of the file */ - /* handle. */ - /*-------------------------------------------------------------------*/ - DLIMP_Loaded_Module *loaded_module = detach_loaded_module(dyn_module); - if (loaded_module) - local_file_handle = loaded_module->file_handle; - else { - DLIF_error(DLET_MISC, "Failed to detach module.\n"); - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - return local_file_handle; - } - } - - /*-----------------------------------------------------------------------*/ - /* Static load failed. Flag an error. */ - /*-----------------------------------------------------------------------*/ - else - { - DLIF_trace("%s:%d EMEMORY\n",__func__,__LINE__); - DLIF_error(DLET_MEMORY, - "Failed to allocate target memory for static executable.\n"); - } - - /*-----------------------------------------------------------------------*/ - /* Destruct dynamic module object. */ - /*-----------------------------------------------------------------------*/ - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - -#if LOADER_DEBUG - if (debugging_on) DLIF_trace("Finished dload_static_executable()\n"); -#endif - - return local_file_handle; -} - -/*****************************************************************************/ -/* process_dynamic_module_relocations() */ -/* */ -/* Make a host-accessible copy of all of the segments, process all */ -/* relocation entries associated with the given module within that */ -/* space, then write the updated segment buffers back out to target */ -/* memory. */ -/* */ -/*****************************************************************************/ -static void process_dynamic_module_relocations(DLOAD_HANDLE handle, - LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module) -{ - int data = 0; - -#if LOADER_DEBUG || LOADER_PROFILE - if(debugging_on || profiling_on) - { - DLIF_trace("Running relocate()...\n"); - if (profiling_on) profile_start_clock(); - } -#endif - - /*-----------------------------------------------------------------------*/ - /* Copy segments from file to host memory */ - /*-----------------------------------------------------------------------*/ - copy_segments(handle, fd, dyn_module, &data); - - /*------------------------------------------------------------------------*/ - /* Process dynamic relocations. */ - /*------------------------------------------------------------------------*/ -#if ARM_TARGET - if (is_arm_module(&dyn_module->fhdr)) - DLREL_relocate(handle, fd, dyn_module); -#endif - -#if C60_TARGET - if (is_c60_module(&dyn_module->fhdr)) - DLREL_relocate_c60(handle, fd, dyn_module); -#endif - - /*-----------------------------------------------------------------------*/ - /* Write segments from host memory to target memory */ - /*-----------------------------------------------------------------------*/ - write_segments(handle, fd, dyn_module, &data); - -#if LOADER_DEBUG || LOADER_PROFILE - /*-----------------------------------------------------------------------*/ - /* Report timing and progress information for relocation step. */ - /*-----------------------------------------------------------------------*/ - if (debugging_on || profiling_on) - { - if (profiling_on) - { - profile_stop_clock(); - DLIF_trace("Took %d cycles.\n", (int)profile_cycle_count()); - DLIF_trace("Total reloc time: %d\n", (int)DLREL_total_reloc_time); - DLIF_trace("Time per relocation: %d\n", - (DLREL_relocations ? - (int)(DLREL_total_reloc_time / DLREL_relocations) : 0)); - } - - DLIF_trace("Number of relocations: %d\n", DLREL_relocations); - DLIF_trace("\nAbout to run load_object()..."); - DLREL_total_reloc_time = DLREL_relocations = 0; - if (profiling_on) profile_start_clock(); - } -#endif -} - -/*****************************************************************************/ -/* execute_module_pre_initialization() */ -/* */ -/* Given a dynamic module object, execute any pre-initialization */ -/* functions for the specified dynamic executable module. Such functions */ -/* must be provided by the user and their addresses written to the */ -/* .preinit_array section. These functions should be executed in the */ -/* order that they are specified in the array before the initialization */ -/* process for this dynamic executable module begins. */ -/* */ -/*---------------------------------------------------------------------------*/ -/* */ -/* Note that dynamic shared objects (libraries) should not have a */ -/* .preinit_array (should be caught during static link-time if the user */ -/* attempts to link a .preinit_array section into a shared object. */ -/* */ -/*****************************************************************************/ -static void execute_module_pre_initialization(DLOAD_HANDLE handle, DLIMP_Dynamic_Module *dyn_module) -{ - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - - /*-----------------------------------------------------------------------*/ - /* Check for presence of DT_PREINIT_ARRAY and DT_PREINIT_ARRAYSZ */ - /* dynamic tags associated with this module. The dyn_module object will */ - /* hold the relevant indices into the local copy of the dynamic table. */ - /* The value of the DT_INIT_ARRAY tag will have been updated after */ - /* placement of the module was completed. */ - /*-----------------------------------------------------------------------*/ - if (dyn_module->preinit_arraysz != 0) - { - /*-------------------------------------------------------------------*/ - /* Retrieve the address of the .preinit_array section from the value */ - /* of the DT_PREINIT_ARRAY tag. */ - /*-------------------------------------------------------------------*/ - TARGET_ADDRESS preinit_array_loc = (TARGET_ADDRESS) - (dyn_module->dyntab[dyn_module->preinit_array_idx].d_un.d_ptr); - - /*-------------------------------------------------------------------*/ - /* Now make a loader-accessible copy of the .preinit_array section. */ - /*-------------------------------------------------------------------*/ - int32_t i; - int32_t num_preinit_fcns = - dyn_module->preinit_arraysz/sizeof(TARGET_ADDRESS); - TARGET_ADDRESS *preinit_array_buf = (TARGET_ADDRESS *) - DLIF_malloc(dyn_module->preinit_arraysz); - if(preinit_array_buf) { - DLIF_read(pHandle->client_handle, preinit_array_buf, 1, - dyn_module->preinit_arraysz, - (TARGET_ADDRESS)preinit_array_loc); - - /*---------------------------------------------------------------*/ - /* Call each function whose address occupies an entry in the */ - /* array in the order that it appears in the array. The sizeof */ - /* the array is provided by the preinit_arraysz field in the */ - /* dynamic module (copied earlier when the dynamic table was */ - /* read in). We need to divide the sizeof value down to get the */ - /* number of actual entries in the array. */ - /*---------------------------------------------------------------*/ - for (i = 0; i < num_preinit_fcns; i++) - DLIF_execute(pHandle->client_handle, - (TARGET_ADDRESS)(preinit_array_buf[i])); - - DLIF_free(preinit_array_buf); - } - } -} - -/*****************************************************************************/ -/* execute_module_initialization() */ -/* */ -/* Given a dynamic module object, execute initialization function(s) for */ -/* all global and static data objects that are defined in the module */ -/* which require construction. The user may also provide a custom */ -/* iniitialization function that needs to be executed before the compiler */ -/* generated static initialization functions are executed. */ -/* */ -/*****************************************************************************/ -static void execute_module_initialization(DLOAD_HANDLE handle, - DLIMP_Dynamic_Module *dyn_module) -{ - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - - /*-----------------------------------------------------------------------*/ - /* Check for presence of a DT_INIT dynamic tag associated with this */ - /* module. The dynamic module will hold the index into the local copy of */ - /* the dynamic table. This entry in the dynamic table will have been */ - /* updated after placement of the module is completed. */ - /*-----------------------------------------------------------------------*/ - if (dyn_module->init_idx != -1) - { - /*-------------------------------------------------------------------*/ - /* Retrieve the address of the initialization function from the */ - /* value of the DT_INIT tag, and get the client to execute the */ - /* function. */ - /*-------------------------------------------------------------------*/ - TARGET_ADDRESS init_fcn = (TARGET_ADDRESS) - (dyn_module->dyntab[dyn_module->init_idx].d_un.d_ptr); - DLIF_execute(pHandle->client_handle, init_fcn); - } - - /*-----------------------------------------------------------------------*/ - /* Check for presence of a DT_INIT_ARRAY and DT_INIT_ARRAYSZ dynamic */ - /* tags associated with this module. The dyn_module object will hold the */ - /* relevant indices into the local copy of the dynamic table. The value */ - /* of the DT_INIT_ARRAY tag will have been updated after placement of */ - /* the module was completed. */ - /*-----------------------------------------------------------------------*/ - if (dyn_module->init_arraysz != 0) - { - /*-------------------------------------------------------------------*/ - /* Retrieve the address of the .init_array section from the value of */ - /* DT_INIT_ARRAY tag. */ - /*-------------------------------------------------------------------*/ - TARGET_ADDRESS init_array_loc = (TARGET_ADDRESS) - (dyn_module->dyntab[dyn_module->init_array_idx].d_un.d_ptr); - - /*-------------------------------------------------------------------*/ - /* Now make a loader-accessible copy of the .init_array section. */ - /*-------------------------------------------------------------------*/ - int32_t i; - int32_t num_init_fcns = dyn_module->init_arraysz/sizeof(TARGET_ADDRESS); - TARGET_ADDRESS *init_array_buf = (TARGET_ADDRESS *) - DLIF_malloc(dyn_module->init_arraysz); - if(init_array_buf) { - DLIF_read(pHandle->client_handle, init_array_buf, 1, - dyn_module->init_arraysz, (TARGET_ADDRESS)init_array_loc); - - /*---------------------------------------------------------------*/ - /* Call each function whose address occupies an entry in the */ - /* array in the order that they appear in the array. The size of */ - /* the array is provided by the init_arraysz field in the */ - /* dynamic module (copied earlier when the dynamic table was */ - /* read in). */ - /*---------------------------------------------------------------*/ - for (i = 0; i < num_init_fcns; i++) - DLIF_execute(pHandle->client_handle, - (TARGET_ADDRESS)(init_array_buf[i])); - - DLIF_free(init_array_buf); - } - } -} - -/*****************************************************************************/ -/* relocate_dependency_graph_modules() */ -/* */ -/* For each dynamic module on the dependency stack, process dynamic */ -/* relocation entries then perform initialization for all global and */ -/* static objects that are defined in tha given module. The stack is */ -/* emptied from the top (LIFO). Each dynamic module object is popped */ -/* off the top of the stack, the module gets relocated, its global and */ -/* static objects that need to be constructed will be constructed, and */ -/* then, after detaching the loaded module object from its dynamic */ -/* module, the dynamic module object is destructed. */ -/* */ -/*****************************************************************************/ -static int32_t relocate_dependency_graph_modules(DLOAD_HANDLE handle, - LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module) -{ - /*-----------------------------------------------------------------------*/ - /* Processing of relocations will only be triggered when this function */ - /* is called from the top-level object module (at the bottom of the */ - /* dependency graph stack). */ - /*-----------------------------------------------------------------------*/ - int32_t local_file_handle = dyn_module->loaded_module->file_handle; - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - dynamic_module_ptr_Stack_Node *ptr = - pHandle->DLIMP_dependency_stack.bottom_ptr; - if (ptr && (ptr->value != dyn_module)) {return local_file_handle;} - - /*-----------------------------------------------------------------------*/ - /* Assign DSBT indices. */ - /*-----------------------------------------------------------------------*/ - DLIF_assign_dsbt_indices(); - - /*-----------------------------------------------------------------------*/ - /* Update the content of all DSBTs for any module that uses the DSBT */ - /* model. */ - /*-----------------------------------------------------------------------*/ - DLIF_update_all_dsbts(); - - /*-----------------------------------------------------------------------*/ - /* Ok, we are ready to process relocations. The relocation tables */ - /* associated with dependent files will be processed first. Consume */ - /* dynamic module objects from the dependency graph stack from dependents*/ - /* to the root of the dependency graph. */ - /*-----------------------------------------------------------------------*/ - while (pHandle->DLIMP_dependency_stack.size > 0) - { - DLIMP_Dynamic_Module *dyn_mod_ptr = - dynamic_module_ptr_pop(&pHandle->DLIMP_dependency_stack); - - /*-------------------------------------------------------------------*/ - /* Process dynamic relocations associated with this module. */ - /*-------------------------------------------------------------------*/ - process_dynamic_module_relocations(handle, dyn_mod_ptr->fd, - dyn_mod_ptr); - - /*------------------------------------------------------------------ */ - /* __c_args__ points to the beginning of the .args section, if there */ - /* is one. Record this pointer in the ELF file internal data object.*/ - /*-------------------------------------------------------------------*/ - DLSYM_lookup_local_symtab("__c_args__", dyn_mod_ptr->symtab, - dyn_mod_ptr->symnum, - (Elf32_Addr *)&dyn_mod_ptr->c_args); - - /*-------------------------------------------------------------------*/ - /* Pick up entry point address from ELF file header. */ - /* We currently only support a single entry point into the ELF */ - /* file. To support Braveheart notion of nodes, with multiple */ - /* entry points, we'll need to get the list of entry points */ - /* associated with a node, then add capability to the "execute" */ - /* command to select the entry point that we want to start */ - /* executing from. */ - /*-------------------------------------------------------------------*/ - dyn_mod_ptr->loaded_module->entry_point = dyn_mod_ptr->fhdr.e_entry; - - /*-------------------------------------------------------------------*/ - /* Copy command-line arguments into args section and deal with DSBT */ - /* issues (copy DSBT to its run location). */ - /*-------------------------------------------------------------------*/ - load_object(dyn_mod_ptr->fd, dyn_mod_ptr); - - /*-------------------------------------------------------------------*/ - /* Perform initialization, if needed, for this module. */ - /*-------------------------------------------------------------------*/ - execute_module_initialization(handle, dyn_mod_ptr); - - /*-------------------------------------------------------------------*/ - /* Free all dependent file pointers. */ - /*-------------------------------------------------------------------*/ - if (dyn_mod_ptr->fd != fd) - { - DLIF_fclose(dyn_mod_ptr->fd); - dyn_mod_ptr->fd = NULL; - } - - /*-------------------------------------------------------------------*/ - /* Detach loaded module object from the dynamic module object that */ - /* created it, then throw away the dynamic module object. */ - /*-------------------------------------------------------------------*/ - detach_loaded_module(dyn_mod_ptr); - delete_DLIMP_Dynamic_Module(handle, &dyn_mod_ptr); - } - return local_file_handle; -} - -/*****************************************************************************/ -/* DLOAD_load() */ -/* */ -/* Dynamically load the specified file and return a file handle for the */ -/* loaded file. If the load fails, this function will return a value of */ -/* zero (0) for the file handle. */ -/* */ -/* The core loader must have read access to the file pointed to by fd. */ -/* */ -/*****************************************************************************/ -int32_t DLOAD_load(DLOAD_HANDLE handle, LOADER_FILE_DESC *fd, int argc, - char** argv) -{ - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - DLIMP_Dynamic_Module *dyn_module = new_DLIMP_Dynamic_Module(fd); - - if (!dyn_module) - return 0; - -#if LOADER_DEBUG - /*-----------------------------------------------------------------------*/ - /* Spit out some loader progress information when we begin loading an */ - /* object. */ - /*-----------------------------------------------------------------------*/ - if (debugging_on) DLIF_trace("Loading file...\n"); -#endif - - /*-----------------------------------------------------------------------*/ - /* If no access to a program was provided, there is nothing to do. */ - /*-----------------------------------------------------------------------*/ - if (!fd) - { - DLIF_error(DLET_FILE, "Missing file specification.\n"); - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - return 0; - } - - /*-----------------------------------------------------------------------*/ - /* Read file headers and dynamic information into dynamic module. */ - /*-----------------------------------------------------------------------*/ - if (!dload_headers(handle, fd, dyn_module)) { - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - return 0; - } - - /*-----------------------------------------------------------------------*/ - /* Find the dynamic segment, if there is one, and read dynamic */ - /* information from the ELF object file into the dynamic module data */ - /* structure associated with this file. */ - /*-----------------------------------------------------------------------*/ - if (!dload_dynamic_segment(handle, fd, dyn_module)) { - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - return 0; - } - - /*-----------------------------------------------------------------------*/ - /* ??? We currently don't have a way of finding the .args section. So */ - /* we are hard-wiring the address of the .args section. The proposed */ - /* solution for this problem is to invent a special segment type or */ - /* dynamic tag(s) that identify the location and size of the .args */ - /* section for the dynamic loader. */ - /*-----------------------------------------------------------------------*/ - /*HACK ---> */dyn_module->c_args = (uint8_t*)(0x02204000); /* <--- HACK*/ - - /*-----------------------------------------------------------------------*/ - /* Record argc and argv pointers with the dynamic module record. */ - /*-----------------------------------------------------------------------*/ - dyn_module->argc = argc; - dyn_module->argv = argv; - if (dyn_module->name == NULL) { - dyn_module->name = DLIF_malloc(sizeof(char)); - if(dyn_module->name) - *dyn_module->name = '\0'; - else { - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - return 0; - } - } - - /*-----------------------------------------------------------------------*/ - /* Perform sanity checking on the read-in ELF file. */ - /*-----------------------------------------------------------------------*/ - if (!is_valid_elf_object_file(fd, dyn_module)) - { - DLIF_error(DLET_FILE, "Attempt to load invalid ELF file, '%s'.\n", - dyn_module->name); - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - return 0; - } - -#if LOADER_DEBUG || LOADER_PROFILE - /*-----------------------------------------------------------------------*/ - /* Stop clock on initialization of ELF file information. Start clock on */ - /* initialization of ELF module. */ - /*-----------------------------------------------------------------------*/ - if (debugging_on || profiling_on) - { - DLIF_trace("Finished dload_dynamic_segment.\n"); - if (profiling_on) - { - profile_stop_clock(); - DLIF_trace("Took %d cycles.\n", (int)profile_cycle_count()); - } - } -#endif - - /*-----------------------------------------------------------------------*/ - /* Initialize internal ELF module and segment structures. Sets */ - /* loaded_module in *dyn_module. This also deals with assigning a file */ - /* handle and bumping file handle counter. */ - /*-----------------------------------------------------------------------*/ - initialize_loaded_module(handle, dyn_module); - - /*-----------------------------------------------------------------------*/ - /* Append Module structure to loaded object list. */ - /*-----------------------------------------------------------------------*/ - loaded_module_ptr_enqueue(&pHandle->DLIMP_loaded_objects, - dyn_module->loaded_module); - - /*-----------------------------------------------------------------------*/ - /* Support static loading as special case. */ - /*-----------------------------------------------------------------------*/ - if (!dyn_module->relocatable) - return dload_static_executable(handle, fd, dyn_module); - - /*-----------------------------------------------------------------------*/ - /* Get space & address for segments, and offset symbols and program */ - /* header table to reflect the relocated address. Also offset the */ - /* addresses in the internal Segment structures used by the Module */ - /* structure. Note that this step needs to be performed prior and in */ - /* addition to the relocation entry processing. */ - /*-----------------------------------------------------------------------*/ - if (!allocate_dynamic_segments_and_relocate_symbols(handle, fd, dyn_module)) { - loaded_module_ptr_remove(&pHandle->DLIMP_loaded_objects, - dyn_module->loaded_module); - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - return 0; - } - /*-----------------------------------------------------------------------*/ - /* Execute any user defined pre-initialization functions that may be */ - /* associated with a dynamic executable module. */ - /*-----------------------------------------------------------------------*/ - if (dyn_module->fhdr.e_type == ET_EXEC) - execute_module_pre_initialization(handle, dyn_module); - - /*-----------------------------------------------------------------------*/ - /* Append current ELF file to list of objects currently loading. */ - /* This is used to detect circular dependencies while we are processing */ - /* the dependents of this file. */ - /*-----------------------------------------------------------------------*/ - AL_append(&pHandle->DLIMP_module_dependency_list, &dyn_module->name); - - /*-----------------------------------------------------------------------*/ - /* Push this dynamic module object onto the dependency stack. */ - /* All of the modules on the stack will get relocated after all of the */ - /* dependent files have been loaded and allocated. */ - /*-----------------------------------------------------------------------*/ - dynamic_module_ptr_push(&pHandle->DLIMP_dependency_stack, dyn_module); - - /*-----------------------------------------------------------------------*/ - /* If this object file uses the DSBT model, then register a DSBT index */ - /* request with the client's DSBT support management. */ - /*-----------------------------------------------------------------------*/ - if (is_dsbt_module(dyn_module) && - !DLIF_register_dsbt_index_request(handle, - dyn_module->name, - dyn_module->loaded_module->file_handle, - dyn_module->dsbt_index)) { - dynamic_module_ptr_pop(&pHandle->DLIMP_dependency_stack); - loaded_module_ptr_remove(&pHandle->DLIMP_loaded_objects, - dyn_module->loaded_module); - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - return 0; - } - - /*-----------------------------------------------------------------------*/ - /* Load this ELF file's dependents (all files on its DT_NEEDED list). */ - /* Do not process relocation entries for anyone in the dependency graph */ - /* until all modules in the graph are loaded and allocated. */ - /*-----------------------------------------------------------------------*/ - if (!dload_and_allocate_dependencies(handle, dyn_module)) { - dynamic_module_ptr_pop(&pHandle->DLIMP_dependency_stack); - loaded_module_ptr_remove(&pHandle->DLIMP_loaded_objects, - dyn_module->loaded_module); - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - return 0; - } - - /*-----------------------------------------------------------------------*/ - /* Remove the current ELF file from the list of files that are in the */ - /* process of loading. */ - /*-----------------------------------------------------------------------*/ - pHandle->DLIMP_module_dependency_list.size--; - - /*-----------------------------------------------------------------------*/ - /* __c_args__ points to the beginning of the .args section, if there is */ - /* one. Record this pointer in the ELF file internal data object. */ - /*-----------------------------------------------------------------------*/ - DLSYM_lookup_local_symtab("__c_args__", dyn_module->symtab, - dyn_module->symnum, - (Elf32_Addr *)&dyn_module->c_args); - - - return relocate_dependency_graph_modules(handle, fd, dyn_module); -} - -BOOL DLOAD_get_entry_names_info(DLOAD_HANDLE handle, - uint32_t file_handle, - int32_t *entry_pt_cnt, - int32_t *entry_pt_max_name_len) -{ - /*-----------------------------------------------------------------------*/ - /* Spin through list of loaded files until we find the file handle we */ - /* are looking for. Then build a list of entry points from that file's */ - /* symbol table. */ - /*-----------------------------------------------------------------------*/ - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - loaded_module_ptr_Queue_Node* ptr; - for (ptr = pHandle->DLIMP_loaded_objects.front_ptr; - ptr != NULL; - ptr = ptr->next_ptr) - { - if (ptr->value->file_handle == file_handle) - { - DLIMP_Loaded_Module *module = ptr->value; - struct Elf32_Sym *symtab; - int i; - - /*---------------------------------------------------------------*/ - /* Any symbol in our file's symbol table is considered a valid */ - /* entry point. */ - /*---------------------------------------------------------------*/ - symtab = (struct Elf32_Sym*)module->gsymtab; - *entry_pt_cnt = module->gsymnum; - *entry_pt_max_name_len = 0; - for (i = 0; i < module->gsymnum; i++) - { - const char *sym_name = (const char *)symtab[i].st_name; - - if ((strlen(sym_name) + 1) > *entry_pt_max_name_len) - *entry_pt_max_name_len = strlen(sym_name) + 1; - } - - return TRUE; - } - } - - /*-----------------------------------------------------------------------*/ - /* We didn't find the file we were looking for, return false. */ - /*-----------------------------------------------------------------------*/ - return FALSE; -} - -/*****************************************************************************/ -/* DLOAD_get_entry_names() */ -/* */ -/* Build a list of entry point names for a loaded object. Currently, */ -/* any global symbol in the module is considered a valid entry point */ -/* regardless of whether it is defined in code or associated with a */ -/* data object. We would need to process the content of the symbol */ -/* table entry or its debug information to determine whether it is a */ -/* valid entry point or not. */ -/* */ -/*****************************************************************************/ -BOOL DLOAD_get_entry_names(DLOAD_HANDLE handle, - uint32_t file_handle, - int32_t *entry_pt_cnt, - char ***entry_pt_names) -{ - /*-----------------------------------------------------------------------*/ - /* Spin through list of loaded files until we find the file handle we */ - /* are looking for. Then build a list of entry points from that file's */ - /* symbol table. */ - /*-----------------------------------------------------------------------*/ - char **names; - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - loaded_module_ptr_Queue_Node* ptr; - for (ptr = pHandle->DLIMP_loaded_objects.front_ptr; - ptr != NULL; - ptr = ptr->next_ptr) - { - if (ptr->value->file_handle == file_handle) - { - DLIMP_Loaded_Module *module = ptr->value; - struct Elf32_Sym *symtab; - int i; - - /*---------------------------------------------------------------*/ - /* Any symbol in our file's symbol table is considered a valid */ - /* entry point. */ - /*---------------------------------------------------------------*/ - symtab = (struct Elf32_Sym*)module->gsymtab; - if (*entry_pt_cnt < module->gsymnum) { - DLIF_error(DLET_MEMORY, "There are %d entry points, " - "only %d spaces provided.\n", - module->gsymnum,*entry_pt_cnt); - return FALSE; - } - - names = *entry_pt_names; - for (i = 0; i < module->gsymnum; i++) - { - const char *sym_name = (const char *)symtab[i].st_name; - strcpy(names[i],sym_name); - } - - return TRUE; - } - } - - /*-----------------------------------------------------------------------*/ - /* We didn't find the file we were looking for, return false. */ - /*-----------------------------------------------------------------------*/ - return FALSE; -} - -/*****************************************************************************/ -/* DLOAD_get_entry_point() */ -/* */ -/* Given a file handle, return the entry point associated with that */ -/* module in the *sym_val output parameter. */ -/* */ -/*****************************************************************************/ -BOOL DLOAD_get_entry_point(DLOAD_HANDLE handle, uint32_t file_handle, - TARGET_ADDRESS *sym_val) -{ - /*-----------------------------------------------------------------------*/ - /* Spin through list of loaded files until we find the file handle we */ - /* are looking for. Then return the entry point address associated with */ - /* that module. */ - /*-----------------------------------------------------------------------*/ - loaded_module_ptr_Queue_Node* ptr; - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - for (ptr = pHandle->DLIMP_loaded_objects.front_ptr; - ptr != NULL; - ptr = ptr->next_ptr) - if (ptr->value->file_handle == file_handle) - { - *sym_val = (TARGET_ADDRESS)(ptr->value->entry_point); - return TRUE; - } - - /*-----------------------------------------------------------------------*/ - /* We didn't find the file we were looking for, return false. */ - /*-----------------------------------------------------------------------*/ - return FALSE; -} - -/*****************************************************************************/ -/* DLOAD_query_symbol() */ -/* */ -/* Query the value of a global symbol from a specific file. The value */ -/* result will be written to *sym_val. The function returns TRUE if the */ -/* symbol was found, and FALSE if it wasn't. */ -/* */ -/*****************************************************************************/ -BOOL DLOAD_query_symbol(DLOAD_HANDLE handle, - uint32_t file_handle, - const char *sym_name, - TARGET_ADDRESS *sym_val) -{ - /*-----------------------------------------------------------------------*/ - /* Spin through list of loaded files until we find the file handle we */ - /* are looking for. Then return the value (target address) associated */ - /* with the symbol we are looking for in that file. */ - /*-----------------------------------------------------------------------*/ - loaded_module_ptr_Queue_Node* ptr; - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - for (ptr = pHandle->DLIMP_loaded_objects.front_ptr; - ptr != NULL; - ptr = ptr->next_ptr) - { - if (ptr->value->file_handle == file_handle) - { - DLIMP_Loaded_Module *module = ptr->value; - struct Elf32_Sym *symtab; - int i; - - /*---------------------------------------------------------------*/ - /* Search through the symbol table by name. */ - /*---------------------------------------------------------------*/ - symtab = (struct Elf32_Sym*)module->gsymtab; - for(i=0; i < module->gsymnum; i++) - { - if (!strcmp(sym_name, (const char *)symtab[i].st_name)) - { - *sym_val = (TARGET_ADDRESS) symtab[i].st_value; - return TRUE; - } - } - } - } - - /*-----------------------------------------------------------------------*/ - /* We didn't find the file we were looking for, return false. */ - /*-----------------------------------------------------------------------*/ - return FALSE; -} - - - -/*****************************************************************************/ -/* unlink_loaded_module() */ -/* */ -/* Unlink a loaded module data object from the list of loaded objects, */ -/* returning a pointer to the object so that it can be deconstructed. */ -/* */ -/*****************************************************************************/ -static DLIMP_Loaded_Module *unlink_loaded_module(DLOAD_HANDLE handle, - loaded_module_ptr_Queue_Node *back_ptr, - loaded_module_ptr_Queue_Node *lm_node) -{ - DLIMP_Loaded_Module *loaded_module = lm_node->value; - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - loaded_module_ptr_remove(&pHandle->DLIMP_loaded_objects, lm_node->value); - return loaded_module; -} - -/*****************************************************************************/ -/* execute_module_termination() */ -/* */ -/* Execute termination functions associated with this loaded module. */ -/* Termination functions are called in the reverse order as their */ -/* corresponding initialization functions. */ -/* */ -/*****************************************************************************/ -static void execute_module_termination(DLOAD_HANDLE handle, - DLIMP_Loaded_Module *loaded_module) -{ - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - - /*-----------------------------------------------------------------------*/ - /* If a DT_FINI_ARRAY dynamic tag was encountered for this module, spin */ - /* through the array in reverse order, calling each function address */ - /* stored in the array. */ - /*-----------------------------------------------------------------------*/ - if (loaded_module->fini_arraysz != 0) - { - /*-------------------------------------------------------------------*/ - /* Now make a loader-accessible copy of the .fini_array section. */ - /*-------------------------------------------------------------------*/ - int32_t i; - int32_t num_fini_fcns = - loaded_module->fini_arraysz/sizeof(TARGET_ADDRESS); - TARGET_ADDRESS *fini_array_buf = (TARGET_ADDRESS *) - DLIF_malloc(loaded_module->fini_arraysz); - if(fini_array_buf) { - DLIF_read(pHandle->client_handle, fini_array_buf, 1, - loaded_module->fini_arraysz, - (TARGET_ADDRESS)loaded_module->fini_array); - - /*---------------------------------------------------------------*/ - /* Now spin through the array in reverse order, executing each */ - /* termination function whose address occupies an entry in the */ - /* array. */ - /*---------------------------------------------------------------*/ - for (i = num_fini_fcns - 1; i >= 0; i--) - DLIF_execute(pHandle->client_handle, - (TARGET_ADDRESS)(fini_array_buf[i])); - - DLIF_free(fini_array_buf); - } - } - - /*-----------------------------------------------------------------------*/ - /* If a DT_FINI dynamic tag was encountered for this module, call the */ - /* function indicated by the tag's value to complete the termination */ - /* process for this module. */ - /*-----------------------------------------------------------------------*/ - if (loaded_module->fini != (Elf32_Addr)NULL) - DLIF_execute(pHandle->client_handle, - (TARGET_ADDRESS)loaded_module->fini); -} - -/*****************************************************************************/ -/* remove_loaded_module() */ -/* */ -/* Find and unlink a loaded module data object from the list of loaded */ -/* objects, then call its destructor to free the host memory associated */ -/* with the loaded module and all of its loaded segments. */ -/* */ -/*****************************************************************************/ -static void remove_loaded_module(DLOAD_HANDLE handle, - loaded_module_ptr_Queue_Node *lm_node) -{ - DLIMP_Loaded_Module *lm_object = NULL; - loaded_module_ptr_Queue_Node *back_ptr = NULL; - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - - if (lm_node != pHandle->DLIMP_loaded_objects.front_ptr) - for (back_ptr = pHandle->DLIMP_loaded_objects.front_ptr; - back_ptr->next_ptr != lm_node; - back_ptr = back_ptr->next_ptr); - - lm_object = unlink_loaded_module(handle, back_ptr, lm_node); - - delete_DLIMP_Loaded_Module(handle, &lm_object); -} - -/*****************************************************************************/ -/* DLOAD_unload() */ -/* */ -/* Unload specified module (identified by its file handle) from target */ -/* memory. Free up any target memory that was allocated for the module's */ -/* segments and also any host heap memory that was allocated for the */ -/* internal module and segment data structures. */ -/* */ -/* Return TRUE if program entry is actually destroyed. This is a way of */ -/* communicating to the client when it needs to actually remove debug */ -/* information associated with this module (so that client does not have */ -/* to maintain a use count that mirrors the program entry). */ -/* */ -/*****************************************************************************/ -BOOL DLOAD_unload(DLOAD_HANDLE handle, uint32_t file_handle) -{ - loaded_module_ptr_Queue_Node* lm_node; - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - - for (lm_node = pHandle->DLIMP_loaded_objects.front_ptr; lm_node != NULL; - lm_node = lm_node->next_ptr) - { - if (lm_node->value->file_handle == file_handle) - { - --lm_node->value->use_count; - if (lm_node->value->use_count == 0) - { - DLIMP_Loaded_Module *loaded_module = - (DLIMP_Loaded_Module *)lm_node->value; - int j; - int *dep_file_handles; - - /*-----------------------------------------------------------*/ - /* Termination functions need to be executed in the reverse */ - /* order as the corresponding initialization functions, so */ - /* before we go unload this module's dependents, we need to */ - /* perform the user/global/static termination functions */ - /* associated with this module. */ - /*-----------------------------------------------------------*/ - execute_module_termination(handle, loaded_module); - - /*-----------------------------------------------------------*/ - /* Unload dependent modules via the client. Client needs to */ - /* know when a dependent gets unloaded so that it can update */ - /* debug information. */ - /*-----------------------------------------------------------*/ - dep_file_handles = (int*)(loaded_module->dependencies.buf); - for (j = 0; j < loaded_module->dependencies.size; j++) { - DLIF_unload_dependent(pHandle->client_handle, - dep_file_handles[j]); - } - - /*-----------------------------------------------------------*/ - /* Find the predecessor node of the value we're deleting, */ - /* because its next_ptr will need to be updated. */ - /* */ - /* We can't keep a back pointer around because */ - /* DLIF_unload_dependent() might free that node, making our */ - /* pointer invalid. Turn the Queue template into a doubly */ - /* linked list if this overhead becomes a problem. */ - /*-----------------------------------------------------------*/ - remove_loaded_module(handle, lm_node); - - /*-----------------------------------------------------------*/ - /* If all loaded objects have been unloaded (including the */ - /* base image), then reset the machine to the default target */ - /* machine. This only has an effect when multiple targets */ - /* are supported, in which case the machine is set to */ - /* EM_NONE. */ - /*-----------------------------------------------------------*/ - if (pHandle->DLIMP_loaded_objects.front_ptr == NULL) - { - pHandle->DLOAD_TARGET_MACHINE = DLOAD_DEFAULT_TARGET_MACHINE; - } - - return TRUE; - } - } - } - - return FALSE; -} - -/*****************************************************************************/ -/* DLOAD_load_symbols() */ -/* */ -/* Load the symbols from the given file and make symbols available for */ -/* global symbol linkage. */ -/* */ -/*****************************************************************************/ -int32_t DLOAD_load_symbols(DLOAD_HANDLE handle, LOADER_FILE_DESC *fd) -{ - DLIMP_Dynamic_Module *dyn_module = NULL; - DLIMP_Loaded_Module *loaded_module = NULL; - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - - /*-----------------------------------------------------------------------*/ - /* If no access to a program was provided, there is nothing to do. */ - /*-----------------------------------------------------------------------*/ - if (!fd) - { - DLIF_error(DLET_FILE, "Missing file specification.\n"); - return 0; - } - - dyn_module = new_DLIMP_Dynamic_Module(fd); - - /*-----------------------------------------------------------------------*/ - /* Ensure we have a valid dynamic module object from the constructor. */ - /*-----------------------------------------------------------------------*/ - if (!dyn_module) - return 0; - - /*-----------------------------------------------------------------------*/ - /* Record argc and argv pointers with the dynamic module record. */ - /*-----------------------------------------------------------------------*/ - dyn_module->argc = 0; - dyn_module->argv = NULL; - - /*-----------------------------------------------------------------------*/ - /* Read file headers and dynamic information into dynamic module. */ - /*-----------------------------------------------------------------------*/ - if (!dload_headers(handle, fd, dyn_module)) { - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - return 0; - } - - /*-----------------------------------------------------------------------*/ - /* Find the dynamic segment, if there is one, and read dynamic */ - /* information from the ELF object file into the dynamic module data */ - /* structure associated with this file. */ - /*-----------------------------------------------------------------------*/ - if (!dload_dynamic_segment(handle, fd, dyn_module)) { - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - return 0; - } - - /*-----------------------------------------------------------------------*/ - /* Perform sanity checking on the read-in ELF file. */ - /*-----------------------------------------------------------------------*/ - if (!is_valid_elf_object_file(fd, dyn_module)) - { - DLIF_error(DLET_FILE, "Attempt to load invalid ELF file, '%s'.\n", - dyn_module->name); - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - return 0; - } - - /*-----------------------------------------------------------------------*/ - /* Initialize internal ELF module and segment structures. Sets */ - /* loaded_module in *dyn_module. This also deals with assigning a file */ - /* handle and bumping file handle counter. */ - /*-----------------------------------------------------------------------*/ - initialize_loaded_module(handle, dyn_module); - - /*-----------------------------------------------------------------------*/ - /* Add this module to the loaded module queue. */ - /* Detach the loaded module object from the dynamic module thath created */ - /* it. Ownership of the host memory allocated for the loaded module */ - /* object now belongs to the DLIMP_loaded_objects list. */ - /*-----------------------------------------------------------------------*/ - loaded_module_ptr_enqueue(&pHandle->DLIMP_loaded_objects, - dyn_module->loaded_module); - - /*-----------------------------------------------------------------------*/ - /* Register a DSBT index request for this module and update its own copy */ - /* of the DSBT with the contents of the client's master DSBT. */ - /*-----------------------------------------------------------------------*/ - if (is_dsbt_module(dyn_module)) - { - dynamic_module_ptr_push(&pHandle->DLIMP_dependency_stack, dyn_module); - DLIF_register_dsbt_index_request(handle, - dyn_module->name, - dyn_module->loaded_module->file_handle, - dyn_module->dsbt_index); - DLIF_assign_dsbt_indices(); - DLIF_update_all_dsbts(); - dynamic_module_ptr_pop(&pHandle->DLIMP_dependency_stack); - } - - /*-----------------------------------------------------------------------*/ - /* Ownership of the host memory allocated for the loaded module object */ - /* is transferred to the DLIMP_loaded_objects list. Free up the host */ - /* memory for the dynamic module that created the loaded module object. */ - /* Just call the destructor function for DLIMP_Dynamic_Module. */ - /*-----------------------------------------------------------------------*/ - loaded_module = detach_loaded_module(dyn_module); - if(loaded_module == NULL) - { - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - return 0; - } - delete_DLIMP_Dynamic_Module(handle, &dyn_module); - - /*-----------------------------------------------------------------------*/ - /* Return a file handle so that the client can match this file to an ID. */ - /*-----------------------------------------------------------------------*/ - return loaded_module->file_handle; -} - -/*****************************************************************************/ -/* DSBT Support Functions */ -/*****************************************************************************/ - -/*****************************************************************************/ -/* DLOAD_get_dsbt_size() */ -/* */ -/* Find the amount of space allocated for the specified module's DSBT. */ -/* It must be big enough to hold a copy of the master DSBT or the client */ -/* will flag an error. Those modules whose DSBT size is zero are assumed */ -/* to not be using the DSBT model. */ -/* */ -/*****************************************************************************/ -uint32_t DLOAD_get_dsbt_size(DLOAD_HANDLE handle, int32_t file_handle) -{ - dynamic_module_ptr_Stack_Node *ptr; - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - for (ptr = pHandle->DLIMP_dependency_stack.top_ptr; - ptr != NULL; - ptr = ptr->next_ptr) - { - DLIMP_Dynamic_Module *dmp = ptr->value; - if (dmp->loaded_module->file_handle == file_handle) - return dmp->dsbt_size; - } - - return 0; -} - -/*****************************************************************************/ -/* DLOAD_get_static_base() */ -/* */ -/* Look up static base symbol associated with the specified module. */ -/* */ -/*****************************************************************************/ -BOOL DLOAD_get_static_base(DLOAD_HANDLE handle, int32_t file_handle, - TARGET_ADDRESS *static_base) -{ - dynamic_module_ptr_Stack_Node *ptr; - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - for (ptr = pHandle->DLIMP_dependency_stack.top_ptr; - ptr != NULL; - ptr = ptr->next_ptr) - { - DLIMP_Dynamic_Module *dmp = ptr->value; - if (dmp->loaded_module->file_handle == file_handle) - { - BOOL stat = DLSYM_lookup_local_symtab("__TI_STATIC_BASE", - dmp->symtab, dmp->symnum, - (Elf32_Addr *)static_base); - return stat; - } - } - - return FALSE; -} - -/*****************************************************************************/ -/* DLOAD_get_dsbt_base() */ -/* */ -/* Look up address of DSBT for the specified module. */ -/* */ -/*****************************************************************************/ -BOOL DLOAD_get_dsbt_base(DLOAD_HANDLE handle, int32_t file_handle, - TARGET_ADDRESS *dsbt_base) -{ - dynamic_module_ptr_Stack_Node *ptr; - LOADER_OBJECT *pHandle = (LOADER_OBJECT *)handle; - for (ptr = pHandle->DLIMP_dependency_stack.top_ptr; - ptr != NULL; - ptr = ptr->next_ptr) - { - DLIMP_Dynamic_Module *dmp = ptr->value; - if (dmp->loaded_module->file_handle == file_handle) - { - *dsbt_base = - (TARGET_ADDRESS)dmp->dyntab[dmp->dsbt_base_tagidx].d_un.d_ptr; - return TRUE; - } - } - - return FALSE; -} diff --git a/src/utils/elfload/dload_endian.c b/src/utils/elfload/dload_endian.c deleted file mode 100644 index 1b01553..0000000 --- a/src/utils/elfload/dload_endian.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* dload_endian.c */ -/* */ -/* Simple helper functions to assist core loader with endian-ness issues */ -/* when the host endian-ness may be opposite the endian-ness of the target. */ -/*****************************************************************************/ -#include "dload_endian.h" - -/*****************************************************************************/ -/* DLIMP_GET_ENDIAN() - Determine endianness of the host. Uses ELF */ -/* endianness constants. */ -/*****************************************************************************/ -int DLIMP_get_endian() -{ - int32_t x = 0x1; - - if (*((int16_t*)(&x))) return ELFDATA2LSB; - - return ELFDATA2MSB; -} - -/*****************************************************************************/ -/* DLIMP_CHANGE_ENDIAN32() - Swap endianness of a 32-bit integer. */ -/*****************************************************************************/ -void DLIMP_change_endian32(int32_t* to_change) -{ - int32_t temp = 0; - temp += (*to_change & 0x000000FF) << 24; - temp += (*to_change & 0x0000FF00) << 8; - temp += (*to_change & 0x00FF0000) >> 8; - temp += (*to_change & 0xFF000000) >> 24; - *to_change = temp; -} - -/*****************************************************************************/ -/* DLIMP_CHANGE_ENDIAN16() - Swap endianness of a 16-bit integer. */ -/*****************************************************************************/ -void DLIMP_change_endian16(int16_t* to_change) -{ - int16_t temp = 0; - temp += (*to_change & 0x00FF) << 8; - temp += (*to_change & 0xFF00) >> 8; - *to_change = temp; -} - -/*****************************************************************************/ -/* DLIMP_CHANGE_EHDR_ENDIAN() - Swap endianness of an ELF file header. */ -/*****************************************************************************/ -void DLIMP_change_ehdr_endian(struct Elf32_Ehdr* ehdr) -{ - DLIMP_change_endian16((int16_t*)(&ehdr->e_type)); - DLIMP_change_endian16((int16_t*)(&ehdr->e_machine)); - DLIMP_change_endian32((int32_t*)(&ehdr->e_version)); - DLIMP_change_endian32((int32_t*)(&ehdr->e_entry)); - DLIMP_change_endian32((int32_t*)(&ehdr->e_phoff)); - DLIMP_change_endian32((int32_t*)(&ehdr->e_shoff)); - DLIMP_change_endian32((int32_t*)(&ehdr->e_flags)); - DLIMP_change_endian16((int16_t*)(&ehdr->e_ehsize)); - DLIMP_change_endian16((int16_t*)(&ehdr->e_phentsize)); - DLIMP_change_endian16((int16_t*)(&ehdr->e_phnum)); - DLIMP_change_endian16((int16_t*)(&ehdr->e_shentsize)); - DLIMP_change_endian16((int16_t*)(&ehdr->e_shnum)); - DLIMP_change_endian16((int16_t*)(&ehdr->e_shstrndx)); -} - -/*****************************************************************************/ -/* DLIMP_CHANGE_PHDR_ENDIAN() - Swap endianness of an ELF program header. */ -/*****************************************************************************/ -void DLIMP_change_phdr_endian(struct Elf32_Phdr* phdr) -{ - DLIMP_change_endian32((int32_t*)(&phdr->p_type)); - DLIMP_change_endian32((int32_t*)(&phdr->p_offset)); - DLIMP_change_endian32((int32_t*)(&phdr->p_vaddr)); - DLIMP_change_endian32((int32_t*)(&phdr->p_paddr)); - DLIMP_change_endian32((int32_t*)(&phdr->p_filesz)); - DLIMP_change_endian32((int32_t*)(&phdr->p_memsz)); - DLIMP_change_endian32((int32_t*)(&phdr->p_flags)); - DLIMP_change_endian32((int32_t*)(&phdr->p_align)); -} - -/*****************************************************************************/ -/* DLIMP_CHANGE_DYNENT_ENDIAN() - Swap endianness of a dynamic table entry. */ -/*****************************************************************************/ -void DLIMP_change_dynent_endian(struct Elf32_Dyn* dyn) -{ - DLIMP_change_endian32((int32_t*)(&dyn->d_tag)); - DLIMP_change_endian32((int32_t*)(&dyn->d_un.d_val)); -} - -/*****************************************************************************/ -/* DLIMP_CHANGE_SYM_ENDIAN() - Swap endianness of an ELF symbol table entry. */ -/*****************************************************************************/ -void DLIMP_change_sym_endian(struct Elf32_Sym* sym) -{ - DLIMP_change_endian32((int32_t*)(&sym->st_name)); - DLIMP_change_endian32((int32_t*)(&sym->st_value)); - DLIMP_change_endian32((int32_t*)(&sym->st_size)); - DLIMP_change_endian16((int16_t*)(&sym->st_shndx)); -} - -/*****************************************************************************/ -/* DLIMP_CHANGE_RELA_ENDIAN() - Swap endianness of a RELA-type relocation. */ -/*****************************************************************************/ -void DLIMP_change_rela_endian(struct Elf32_Rela* ra) -{ - DLIMP_change_endian32((int32_t*)(&ra->r_offset)); - DLIMP_change_endian32((int32_t*)(&ra->r_info)); - DLIMP_change_endian32((int32_t*)(&ra->r_addend)); -} - -/*****************************************************************************/ -/* DLIMP_CHANGE_REL_ENDIAN() - Swap endianness of a REL-type relocation. */ -/*****************************************************************************/ -void DLIMP_change_rel_endian(struct Elf32_Rel* r) -{ - DLIMP_change_endian32((int32_t*)(&r->r_offset)); - DLIMP_change_endian32((int32_t*)(&r->r_info)); -} diff --git a/src/utils/elfload/dlw_client.c b/src/utils/elfload/dlw_client.c deleted file mode 100644 index 14240bc..0000000 --- a/src/utils/elfload/dlw_client.c +++ /dev/null @@ -1,526 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2011, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* dlw_client.c */ -/* */ -/* DLW implementation of client functions required by dynamic loader API. */ -/* Please see list of client-required API functions in dload_api.h. */ -/* */ -/* DLW is expected to run on the DSP. It uses C6x RTS functions for file */ -/* I/O and memory management (both host and target memory). */ -/* */ -/* A loader that runs on a GPP for the purposes of loading C6x code onto a */ -/* DSP will likely need to re-write all of the functions contained in this */ -/* module. */ -/* */ -/*****************************************************************************/ - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "../rprcfmt.h" - -extern FILE * out_file; -extern unsigned int tag_addr[]; -extern char *tag_name[]; -extern int num_tags; - -/* - * insert data at the beginning of an open, existing file - * note that file needs to be opened with "w+b" - */ -static int finsert(unsigned char * newData, int numBytes, FILE * fp) -{ - struct stat statBuf; - off_t size; - char * data; - int n; - - /* get size of current data in file and alloc buffer to hold it */ - fseek(fp, 0, SEEK_SET); - fstat(fileno(fp), &statBuf); - size = statBuf.st_size; - - data = malloc(size); - fread(data, 1, size, fp); - - /* back to the beginning of file */ - fseek(fp, 0, SEEK_SET); - - /* write the new data */ - n = fwrite(newData, 1, numBytes, fp); - if (!n || ferror(fp)) { - perror("first fwrite: "); - } - - /* write the original data */ - n = fwrite(data, 1, size, fp); - if (!n || ferror(fp)) { - perror("second fwrite: "); - } - - fseek(fp, 0, SEEK_END); - - free(data); - - return size + numBytes; -} - -static void patchup_resources(struct rproc_fw_resource *res, - unsigned int res_size) -{ - int i; - struct rproc_fw_resource *res_end; - - printf("resource size: %d\n", sizeof(struct rproc_fw_resource)); - - res_end = (struct rproc_fw_resource *)((unsigned int)res + res_size); - - while (res < res_end) { - printf("resource: %d, da: %llx, pa: %llx, len: 0x%x, name: %s\n", - res->type, res->da, res->pa, res->len, res->name); - switch (res->type) { - case RSC_TRACE: - printf("found TRACE resource, looking for corresponding tag...\n"); - - for (i = 0; i < num_tags; i++) { - if (!strncmp(tag_name[i], "trace", 5)) { - if (res->da == atoi(&tag_name[i][5])) { - printf("...found tag %s\n", tag_name[i]); - printf("patching address 0x%x\n", tag_addr[i]); - res->da = tag_addr[i]; - break; - } - } - } - - if (i == num_tags) { - printf("...no tag found, ignoring resource\n"); - } - break; - - case RSC_BOOTADDR: - printf("found ENTRYPOINT resource, looking for corresponding tag...\n"); - - for (i = 0; i < num_tags; i++) { - if (!strncmp(tag_name[i], "entry", 5)) { - if (res->da == atoi(&tag_name[i][5])) { - printf("...found tag %s\n", tag_name[i]); - printf("patching address 0x%x\n", tag_addr[i]); - res->da = tag_addr[i]; - break; - } - } - } - - if (i == num_tags) { - printf("...no tag found, ignoring resource\n"); - } - break; - - case RSC_CARVEOUT: - case RSC_DEVMEM: - case RSC_IRQ: - case RSC_DEVICE: - printf("found M/I/D/S resource, nothing to do\n"); - break; - - default: - fprintf(stderr, "unknown resource type %d\n", res->type); - break; - } - res++; - } -} - -/*---------------------------------------------------------------------------*/ -/* Target Memory Access / Write Services */ -/* */ -/* The client side's target memory allocator infrastructure communicates */ -/* with the core loader through the DLOAD_MEMORY_REQUEST and */ -/* DLOAD_MEMORY_SEGMENT data structures defined above. To complete the */ -/* loading of an object segment, the segment may need to be relocated */ -/* before it is actually written to target memory in the space that was */ -/* allocated for it by DLIF_allocate(). */ -/* */ -/* The client side of the dynamic loader provides two functions to help */ -/* complete the process of loading an object segment, DLIF_copy() and */ -/* DLIF_write(). */ -/* */ -/* These functions help to make the core loader truly independent of */ -/* whether it is running on the host or target architecture and how the */ -/* client provides for reading/writing from/to target memory. */ -/* */ -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/* DLIF_copy() */ -/* */ -/* Copy segment data from the object file described in the 'fp' and */ -/* 'offset' of the DLOAD_MEMORY_REQUEST into host accessible memory so */ -/* that it can relocated or otherwise manipulated by the core loader. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLIF_copy(void* client_handle, struct DLOAD_MEMORY_REQUEST* targ_req) -{ - struct DLOAD_MEMORY_SEGMENT* obj_desc = targ_req->segment; - FILE * f = targ_req->fp; - unsigned int dst_addr = 0; - struct rproc_fw_section * fwsect; - void * buf; - void * fwbuf; - unsigned int buf_size; - unsigned int fwbuf_size; - unsigned int type; - int i; - - if (obj_desc->objsz_in_bytes == 0) { - printf("skipping empty section at %p\n", obj_desc->target_address); - return TRUE; - } - - dst_addr = (unsigned int)obj_desc->target_address; - - /* insure all sections are word-multiples for easier loading */ - buf_size = (obj_desc->objsz_in_bytes + 3) & ~0x3; - fwbuf_size = buf_size + 16; - fwbuf = calloc(4, fwbuf_size / 4); - buf = fwbuf + 16; - fseek(f, targ_req->offset, SEEK_SET); - fread(buf, obj_desc->objsz_in_bytes, 1, f); - - type = FW_DATA; // default - for (i = 0; i < num_tags; i++) { - type = FW_DATA; // default - if (dst_addr == tag_addr[i]) { - printf(" matched destination addr w/ specified tag addr\n"); - if (!strcmp(tag_name[i], "restab")) { - printf(" found 'restab' section\n"); - type = FW_RESOURCE; - patchup_resources((struct rproc_fw_resource *)buf, buf_size); - break; - } - else if (!strcmp(tag_name[i], "text")) { - printf(" found 'text' section\n"); - type = FW_TEXT; - break; - } - else if (!strcmp(tag_name[i], "data")) { - printf(" found 'data' section\n"); - type = FW_DATA; - break; - } - } - } - - fwsect = (struct rproc_fw_section *)fwbuf; - - fwsect->type = type; - fwsect->da = dst_addr; - fwsect->len = buf_size; - if (type == FW_RESOURCE) { - finsert(fwbuf, fwbuf_size, out_file); - } - else { - fwrite(fwbuf, 1, fwbuf_size, out_file); - } - - free(fwbuf); - - return 1; -} - -/*---------------------------------------------------------------------------*/ -/* File I/O */ -/* */ -/* The client side of the dynamic loader must provide basic file I/O */ -/* capabilities so that the core loader has random access into any */ -/* object file that it is asked to load. */ -/* */ -/* The client side of the dynamic loader must provide a definition of */ -/* the LOADER_FILE_DESC in dload_filedefs.h. This allows the core loader */ -/* to be independent of how the client accesses raw data in an object */ -/* file. */ -/* */ -/*---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------*/ -/* DLIF_fseek() */ -/* */ -/* Seek to a position in a file (accessed via 'stream') based on the */ -/* values for offset and origin. */ -/* */ -/*---------------------------------------------------------------------------*/ -int DLIF_fseek(LOADER_FILE_DESC *stream, int32_t offset, int origin) -{ - return fseek(stream, offset, origin); -} - -/*---------------------------------------------------------------------------*/ -/* DLIF_ftell() */ -/* */ -/* Return the current file position in the file identified in the */ -/* LOADER_FILE_DESC pointed to by 'stream'. */ -/* */ -/*---------------------------------------------------------------------------*/ -int32_t DLIF_ftell(LOADER_FILE_DESC *stream) -{ - return ftell(stream); -} - -/*---------------------------------------------------------------------------*/ -/* DLIF_fread() */ -/* */ -/* Read 'size' * 'nmemb' bytes of data from the file identified in the */ -/* LOADER_FILE_DESC object pointed to by 'stream', and write that data */ -/* into the memory accessed via 'ptr'. */ -/* */ -/*---------------------------------------------------------------------------*/ -size_t DLIF_fread(void *ptr, size_t size, size_t nmemb, - LOADER_FILE_DESC *stream) -{ - return fread(ptr, size, nmemb, stream); -} - -/*---------------------------------------------------------------------------*/ -/* DLIF_fclose() */ -/* */ -/* Close a file that was opened on behalf of the core loader. Ownership */ -/* of the file pointer in question belongs to the core loader, but the */ -/* client has exclusive access to the file system. */ -/* */ -/*---------------------------------------------------------------------------*/ -int DLIF_fclose(LOADER_FILE_DESC *fd) -{ - return fclose(fd); -} - -/*---------------------------------------------------------------------------*/ -/* Host Memory Management */ -/* */ -/* Allocate and free host memory as needed for the dynamic loader's */ -/* internal data structures. If the dynamic loader resides on the */ -/* target architecture, then this memory is allocated from a target */ -/* memory heap that must be managed separately from memory that is */ -/* allocated for a dynamically loaded object file. */ -/* */ -/*---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------*/ -/* DLIF_malloc() */ -/* */ -/* Allocate 'size' bytes of memory space that is usable as scratch space */ -/* (appropriate for the loader's internal data structures) by the dynamic */ -/* loader. */ -/* */ -/*---------------------------------------------------------------------------*/ -void* DLIF_malloc(size_t size) -{ - return malloc(size); -} - -/*---------------------------------------------------------------------------*/ -/* DLIF_free() */ -/* */ -/* Free memory space that was previously allocated by DLIF_malloc(). */ -/* */ -/*---------------------------------------------------------------------------*/ -void DLIF_free(void* ptr) -{ - free(ptr); -} - -/*****************************************************************************/ -/* DLIF_LOAD_DEPENDENT() - Perform whatever maintenance is needed in the */ -/* client when loading of a dependent file is initiated by the core */ -/* loader. Open the dependent file on behalf of the core loader, */ -/* then invoke the core loader to get it into target memory. The core */ -/* loader assumes ownership of the dependent file pointer and must ask */ -/* the client to close the file when it is no longer needed. */ -/* */ -/* If debug support is needed under the Braveheart model, then create */ -/* a host version of the debug module record for this object. This */ -/* version will get updated each time we allocate target memory for a */ -/* segment that belongs to this module. When the load returns, the */ -/* client will allocate memory for the debug module from target memory */ -/* and write the host version of the debug module into target memory */ -/* at the appropriate location. After this takes place the new debug */ -/* module needs to be added to the debug module list. The client will */ -/* need to update the tail of the DLModules list to link the new debug */ -/* module onto the end of the list. */ -/* */ -/*****************************************************************************/ -int DLIF_load_dependent(void* client_handle, const char* so_name) -{ - printf("%s: unexpected call\n", __func__); - return 0; -} - -/*****************************************************************************/ -/* DLIF_UNLOAD_DEPENDENT() - Perform whatever maintenance is needed in the */ -/* client when unloading of a dependent file is initiated by the core */ -/* loader. Invoke the DLOAD_unload() function to get the core loader */ -/* to release any target memory that is associated with the dependent */ -/* file's segments. */ -/*****************************************************************************/ -void DLIF_unload_dependent(void* client_handle, uint32_t file_handle) -{ - printf("%s: unexpected call\n", __func__); -} - - -/*****************************************************************************/ -/* DLIF_WARNING() - Write out a warning message from the core loader. */ -/*****************************************************************************/ -void DLIF_warning(LOADER_WARNING_TYPE wtype, const char *fmt, ...) -{ - va_list ap; - va_start(ap,fmt); - printf("<< D L O A D >> WARNING: "); - vprintf(fmt,ap); - va_end(ap); -} - -/*****************************************************************************/ -/* DLIF_ERROR() - Write out an error message from the core loader. */ -/*****************************************************************************/ -void DLIF_error(LOADER_ERROR_TYPE etype, const char *fmt, ...) -{ - va_list ap; - va_start(ap,fmt); - printf("<< D L O A D >> ERROR: "); - vprintf(fmt,ap); - va_end(ap); -} - -/*****************************************************************************/ -/* DLIF_trace() - Write out a trace from the core loader. */ -/*****************************************************************************/ -void DLIF_trace(const char *fmt, ...) -{ - va_list ap; - va_start(ap,fmt); - vprintf(fmt,ap); - va_end(ap); -} - -/*---------------------------------------------------------------------------*/ -/* DLIF_allocate() */ -/* */ -/* Given a DLOAD_MEMORY_REQUEST created by the core loader, allocate */ -/* target memory to fulfill the request using the target memory */ -/* management infrastrucutre on the client side of the dynamic loader. */ -/* The contents of the DLOAD_MEMORY_REQUEST will be updated per the */ -/* details of a successful allocation. The allocated page and address */ -/* can be found in the DLOAD_MEMORY_SEGMENT attached to the request. */ -/* The boolean return value reflects whether the allocation was */ -/* successful or not. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLIF_allocate(void * client_handle, struct DLOAD_MEMORY_REQUEST *req) -{ -// printf("%s: %p, %p\n", __func__, client_handle, req); - - return 1; -} - -/*---------------------------------------------------------------------------*/ -/* DLIF_release() */ -/* */ -/* Given a DLOAD_MEMORY_SEGMENT description, free the target memory */ -/* associated with the segment using the target memory management */ -/* infrastructure on the client side of the dynamic loader. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLIF_release(void* client_handle, struct DLOAD_MEMORY_SEGMENT* ptr) -{ - printf("%s: %p, %p\n", __func__, client_handle, ptr); - - return 1; -} - -/*---------------------------------------------------------------------------*/ -/* DLIF_write() */ -/* */ -/* Once the segment data described in the DLOAD_MEMORY_REQUEST is ready */ -/* (relocated, if needed), write the segment contents to the target */ -/* memory identified in the DLOAD_MEMORY_SEGMENT attached to the request. */ -/* */ -/* After the segment contents have been written to target memory, the */ -/* core loader should discard the DLOAD_MEMORY_REQUEST object, but retain */ -/* the DLOAD_MEMORY_SEGMENT object so that the target memory associated */ -/* with the segment can be releases when the segment is unloaded. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLIF_write(void* client_handle, struct DLOAD_MEMORY_REQUEST* req) -{ -// printf("%s: %p, %p\n", __func__, client_handle, req); - - return 1; -} - -/*---------------------------------------------------------------------------*/ -/* DLIF_read() */ -/* */ -/* Given a host accessible buffer, read content of indicated target */ -/* memory address into the buffer. */ -/*---------------------------------------------------------------------------*/ -BOOL DLIF_read(void* client_handle, void *ptr, size_t size, size_t nmemb, - TARGET_ADDRESS src) -{ - printf("%s: %p, %p, %d, %d, %p\n", __func__, client_handle, ptr, size, nmemb, src); - - return 1; -} - -/*---------------------------------------------------------------------------*/ -/* DLIF_execute() */ -/* */ -/* Start execution on the target architecture from given 'exec_addr'. */ -/* If the dynamic loader is running on the target architecture, this can */ -/* be effected as a simple function call. */ -/* */ -/*---------------------------------------------------------------------------*/ -int32_t DLIF_execute(void* client_handle, TARGET_ADDRESS exec_addr) -{ - printf("%s: %p, %p\n", __func__, client_handle, exec_addr); - - return 1; -} diff --git a/src/utils/elfload/dlw_debug.c b/src/utils/elfload/dlw_debug.c deleted file mode 100644 index 39bb9ea..0000000 --- a/src/utils/elfload/dlw_debug.c +++ /dev/null @@ -1,433 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* dlw_debug.c */ -/* */ -/* This source file contains the implementation of the DLL debug support. */ -/* The client side of the ELF dynamic loader will write to target memory a */ -/* list of module debug records containing the final addresses of all */ -/* segments that were loaded to target memory by the dynamic loader. */ -/* */ -/*****************************************************************************/ -#include -#include -#include -#include -#include -#include "dload4430.h" -#include "ArrayList.h" -#include "symtab.h" -#include "dload_api.h" -#include "util.h" -#include "dlw_debug.h" -#include "dlw_trgmem.h" - -/*****************************************************************************/ -/* dl_debug */ -/* */ -/* Define a LIFO linked list "class" of DL_Module_Debug_Record pointers. */ -/*****************************************************************************/ -TYPE_STACK_IMPLEMENTATION(DL_Host_Module_Debug*, dl_debug) - -/*****************************************************************************/ -/* mirror_debug_ptr */ -/* */ -/* Define a linked list "class" of DL_Host_Module_Debug pointers. */ -/*****************************************************************************/ -TYPE_QUEUE_IMPLEMENTATION(DL_Host_Module_Debug*, mirror_debug_ptr) - -/*---------------------------------------------------------------------------*/ -/* Global flag to control debug output. */ -/*---------------------------------------------------------------------------*/ -#if LOADER_DEBUG -extern Bool debugging_on; -#endif - -/*---------------------------------------------------------------------------*/ -/* Global flag to enable profiling. */ -/*---------------------------------------------------------------------------*/ -#if LOADER_DEBUG || LOADER_PROFILE -extern Bool profiling_on; -#endif - -/*****************************************************************************/ -/* DLDBG_ADD_HOST_RECORD() - Construct a host version of a debug record */ -/* that is to be associated with the specified module. The debug */ -/* record is placed on the top of the "context stack" while the module */ -/* is being loaded so that debug information about the location of the */ -/* module segments can be added during the load. */ -/*****************************************************************************/ -void DLDBG_add_host_record(void* client_handle, const char *module_name) -{ - DLoad4430_Object *clientObj = (DLoad4430_Object *)client_handle; - - /*-----------------------------------------------------------------------*/ - /* Allocate a new DL_Host_Module_Debug record from host memory. */ - /*-----------------------------------------------------------------------*/ - DL_Host_Module_Debug *host_dbg = - (DL_Host_Module_Debug *)DLIF_malloc(sizeof(DL_Host_Module_Debug)); - if(!host_dbg) { -#if LOADER_DEBUG - if(debugging_on) - DLIF_error(DLET_MISC,"malloc failed at %d\n", __LINE__); -#endif - exit(1); - } - - /*-----------------------------------------------------------------------*/ - /* Set up initial values. Make a copy of the module name; everything */ - /* else is NULL. */ - /*-----------------------------------------------------------------------*/ - host_dbg->module_name = (char *)DLIF_malloc(strlen(module_name) + 1); - if(host_dbg->module_name) { - strncpy(host_dbg->module_name, module_name, strlen(module_name)); - host_dbg->module_name[strlen(module_name)] = '\0'; - } - host_dbg->num_segments = 0; - host_dbg->segment_list_head = - host_dbg->segment_list_tail = NULL; - - /*-----------------------------------------------------------------------*/ - /* Push the new host version of the debug record onto the context stack. */ - /* This module is now currently being loaded. When its segments are */ - /* allocated and written into target memory, the debug record at the top */ - /* of the context stack will get updated with new segment information. */ - /*-----------------------------------------------------------------------*/ - dl_debug_push(&clientObj->dl_debug_stk, host_dbg); -} - -/*****************************************************************************/ -/* DLDBG_ADD_TARGET_RECORD() - Host version of the debug record on the top */ -/* of the context stack is now complete and the module associated has */ -/* been successfully loaded. It is now time to create a target version */ -/* of the debug record based on the host version. Allocate space for */ -/* the target record and write the information from the host version of */ -/* record into the target memory. The host will retain a mirror copy */ -/* of the target debug record list so that it can update pointers in */ -/* the list when debug records are added to or removed from the list. */ -/*****************************************************************************/ -void DLDBG_add_target_record(void* client_handle, int handle) -{ - int i; - DLoad4430_Object *clientObj = (DLoad4430_Object *)client_handle; - DL_Host_Module_Debug *host_dbg = dl_debug_pop(&clientObj->dl_debug_stk); - struct DLOAD_MEMORY_REQUEST targ_req; - struct DLOAD_MEMORY_SEGMENT obj_desc; - DL_Host_Segment *host_seg = NULL; - DL_Target_Module_Debug *targ_dbg = NULL; - char *targ_module_name = NULL; - - /*-----------------------------------------------------------------------*/ - /* Assign handle after loading has been completed. */ - /*-----------------------------------------------------------------------*/ - host_dbg->handle = handle; - - /*-----------------------------------------------------------------------*/ - /* Figure out how much target memory we need to hold all of the debug */ - /* record information for the module that just finished loading and its */ - /* segments. */ - /*-----------------------------------------------------------------------*/ - obj_desc.memsz_in_bytes = sizeof(DL_Target_Module_Debug) + - (sizeof(DL_Target_Segment) * (host_dbg->num_segments - 1)) + - (strlen(host_dbg->module_name) + 1); - - /*-----------------------------------------------------------------------*/ - /* Build up request for target memory in a local data object. */ - /*-----------------------------------------------------------------------*/ - targ_req.fp = NULL; - targ_req.align = 4; - targ_req.flags = DLOAD_SF_relocatable; - - /*-----------------------------------------------------------------------*/ - /* Request the target memory for the new debug record. */ - /*-----------------------------------------------------------------------*/ - if (!DLTMM_malloc(client_handle, &targ_req, &obj_desc)) - { - DLIF_error(DLET_MEMORY, - "Failed to allocate target memory for debug record.\n"); - exit(1); - } - - /*------------------------------------------------------------------------*/ - /* Write content of host version of the debug record into the target */ - /* version of the debug record in target memory. */ - /*------------------------------------------------------------------------*/ - targ_dbg = (DL_Target_Module_Debug *)obj_desc.target_address; - targ_dbg->tool_version = INIT_VERSION; - targ_dbg->verification_word = VERIFICATION; - targ_dbg->num_segments = host_dbg->num_segments; - - for (host_seg = host_dbg->segment_list_head, i = 0; - host_seg; host_seg = host_seg->next_segment, i++) - { - targ_dbg->segments[i].load_address = host_seg->load_address; - targ_dbg->segments[i].run_address = host_seg->run_address; - } - - if (i != host_dbg->num_segments) - { - DLIF_error(DLET_MISC, "Debug record segment list mismatch.\n"); - exit(1); - } - - targ_module_name = ((char *)obj_desc.target_address + - sizeof(DL_Target_Module_Debug) + - (sizeof(DL_Target_Segment) * - (host_dbg->num_segments - 1))); - - memcpy(targ_module_name, host_dbg->module_name, - strlen(host_dbg->module_name) + 1); - - /*-----------------------------------------------------------------------*/ - /* The host will hold onto access info for all target debug records so */ - /* the debug record list can be properly managed when adding or removing */ - /* debug records to/from the list. */ - /*-----------------------------------------------------------------------*/ - host_dbg->target_address = obj_desc.target_address; - host_dbg->next_module_ptr = (uint32_t)NULL; - host_dbg->next_module_size = 0; - - /*-----------------------------------------------------------------------*/ - /* Link the new target debug record into the module debug list. This */ - /* means updating the debug record currently at the end of the list to */ - /* point at and give the size of the new debug record. */ - /*-----------------------------------------------------------------------*/ - if (clientObj->mirror_debug_list.size == 0) - { - DL_Debug_List_Header *dbg_hdr = (DL_Debug_List_Header *)clientObj->DLModules_loc; - dbg_hdr->first_module_ptr = (uint32_t)(obj_desc.target_address); - dbg_hdr->first_module_size = obj_desc.memsz_in_bytes; - } - else - { - DL_Host_Module_Debug *tail_host_dbg = clientObj->mirror_debug_list.back_ptr->value; - DL_Target_Module_Debug *tail_targ_dbg = tail_host_dbg->target_address; - - tail_targ_dbg->next_module_ptr = - tail_host_dbg->next_module_ptr = (uint32_t)(obj_desc.target_address); - tail_targ_dbg->next_module_size = - tail_host_dbg->next_module_size = obj_desc.memsz_in_bytes; - } - - mirror_debug_ptr_enqueue(&clientObj->mirror_debug_list, host_dbg); - -#if LOADER_DEBUG - if (debugging_on) DLDBG_dump_mirror_debug_list(client_handle); -#endif -} - -/*****************************************************************************/ -/* DLDBG_RM_TARGET_RECORD() - Find the host version of the module debug */ -/* record on the mirror DLL debug list so that we can then find the */ -/* target version of the module debug record. We'll unlink the target */ -/* version of the record from the DLL debug list, free the target */ -/* memory associated with the debug record, then finally, free the */ -/* host version of the module debug record. */ -/*****************************************************************************/ -void DLDBG_rm_target_record(void* client_handle, int handle) -{ - DLoad4430_Object *clientObj = (DLoad4430_Object *)client_handle; - mirror_debug_ptr_Queue_Node *prev_itr = NULL; - mirror_debug_ptr_Queue_Node *itr = clientObj->mirror_debug_list.front_ptr; - DL_Host_Module_Debug *prev_host_dbg = NULL; - DL_Host_Module_Debug *host_dbg = itr->value; - - /*-----------------------------------------------------------------------*/ - /* Base Image is assumed to have handle ID == 1, it won't be on the */ - /* DLL Debug list, so don't bother looking for it. */ - /*-----------------------------------------------------------------------*/ - if (handle <= 1) return; - - /*-----------------------------------------------------------------------*/ - /* Find host version of the module debug record using the module handle. */ - /*-----------------------------------------------------------------------*/ - for (; itr; itr = itr->next_ptr) - { - host_dbg = itr->value; - if (host_dbg->handle == handle) break; - prev_itr = itr; - } - - if (!itr) - { - DLIF_trace("Couldn't find handle %d on debug list\n", handle); - return; - } - - /*-----------------------------------------------------------------------*/ - /* Unlink the target version of the module debug record from the DLL */ - /* debug list in target memory. */ - /*-----------------------------------------------------------------------*/ - /* The debug record to be removed may be in the middle or at the end of */ - /* the DLL debug list, or ... */ - /*-----------------------------------------------------------------------*/ - if (prev_itr) - { - DL_Target_Module_Debug *prev_targ_dbg = NULL; - - prev_host_dbg = prev_itr->value; - prev_targ_dbg = (DL_Target_Module_Debug *)prev_host_dbg->target_address; - - prev_host_dbg->next_module_ptr = - prev_targ_dbg->next_module_ptr = host_dbg->next_module_ptr; - prev_host_dbg->next_module_size = - prev_targ_dbg->next_module_size = host_dbg->next_module_size; - } - - /*-----------------------------------------------------------------------*/ - /* The debug record could be at the front of the DLL debug list. If so, */ - /* then we'll need to update the content of the list header object. */ - /*-----------------------------------------------------------------------*/ - else - { - DL_Debug_List_Header *dbg_hdr = (DL_Debug_List_Header *)clientObj->DLModules_loc; - dbg_hdr->first_module_ptr = host_dbg->next_module_ptr; - dbg_hdr->first_module_size = host_dbg->next_module_size; - } - - /*-----------------------------------------------------------------------*/ - /* Free target memory associated with the target version of the module */ - /* debug record. */ - /*-----------------------------------------------------------------------*/ - DLTMM_free(client_handle, (char *)host_dbg->target_address); - - /*-----------------------------------------------------------------------*/ - /* Find and remove the host version of the module debug record from the */ - /* mirror version of the DLL debug list, then free the host memory */ - /* associated with the object. */ - /*-----------------------------------------------------------------------*/ - mirror_debug_ptr_remove(&clientObj->mirror_debug_list, host_dbg); - -#if LOADER_DEBUG - if (debugging_on) DLDBG_dump_mirror_debug_list(client_handle); -#endif -} - -/*****************************************************************************/ -/* DLDBG_ADD_SEGMENT_RECORD() - Add a new segment record for the debug */ -/* record for the module at the top of the context stack. */ -/*****************************************************************************/ -void DLDBG_add_segment_record(void* client_handle, struct DLOAD_MEMORY_SEGMENT *obj_desc) -{ - DLoad4430_Object *clientObj = (DLoad4430_Object *)client_handle; - - /*-----------------------------------------------------------------------*/ - /* Get access to the module debug record at the top of the context stack.*/ - /*-----------------------------------------------------------------------*/ - DL_Host_Module_Debug *host_dbg = clientObj->dl_debug_stk.top_ptr->value; - - /*-----------------------------------------------------------------------*/ - /* Allocate host memory for a new segment debug record. */ - /*-----------------------------------------------------------------------*/ - DL_Host_Segment *host_seg = - (DL_Host_Segment *)DLIF_malloc(sizeof(DL_Host_Segment)); - if(!host_seg) { -#if LOADER_DEBUG - if(debugging_on) - DLIF_error(DLET_MISC,"malloc failed at %d\n", __LINE__); -#endif - exit(1); - } - - /*-----------------------------------------------------------------------*/ - /* Fill load and run address fields of new segment debug record. */ - /*-----------------------------------------------------------------------*/ - host_seg->load_address = - host_seg->run_address = (uint32_t)obj_desc->target_address; - host_seg->next_segment = NULL; - - /*-----------------------------------------------------------------------*/ - /* Add the new segment debug record to the end of the segment list that */ - /* is attached to the module debug record. */ - /*-----------------------------------------------------------------------*/ - if (host_dbg->num_segments == 0) - { - host_dbg->segment_list_head = - host_dbg->segment_list_tail = host_seg; - } - else - { - host_dbg->segment_list_tail->next_segment = host_seg; - host_dbg->segment_list_tail = host_seg; - } - - host_dbg->num_segments++; -} - -/*****************************************************************************/ -/* DLDBG_DUMP_MIRROR_DEBUG_LIST() - Write out contents of mirror debug list */ -/* so that we can debug what is being written to target memory on */ -/* behalf of the DLL View support. */ -/*****************************************************************************/ -void DLDBG_dump_mirror_debug_list(void* client_handle) -{ - DLoad4430_Object *clientObj = (DLoad4430_Object *)client_handle; - mirror_debug_ptr_Queue_Node *itr = clientObj->mirror_debug_list.front_ptr; - - DL_Debug_List_Header *dbg_hdr = (DL_Debug_List_Header *)clientObj->DLModules_loc; - DLIF_trace("DLL View Debug List Header at 0x%lx\n", (unsigned long)dbg_hdr); - DLIF_trace(" first module debug record at: 0x%lx\n", - (unsigned long)dbg_hdr->first_module_ptr); - DLIF_trace(" first module debug record size: %d\n", - (int)dbg_hdr->first_module_size); - - while (itr) - { - int i; - DL_Host_Module_Debug *host_dbg = itr->value; - DL_Host_Segment *host_seg = NULL; - - DLIF_trace("Module Debug Record for %s at 0x%lx\n", - host_dbg->module_name, - (unsigned long)host_dbg->target_address); - DLIF_trace(" next module debug record at: 0x%lx\n", - (unsigned long)host_dbg->next_module_ptr); - DLIF_trace(" next module debug record size: %d\n", - (int)host_dbg->next_module_size); - - DLIF_trace(" handle for %s is %d\n", host_dbg->module_name, - host_dbg->handle); - DLIF_trace(" segment list for %s:\n", host_dbg->module_name); - for (i = 0, host_seg = host_dbg->segment_list_head; - host_seg; i++, host_seg = host_seg->next_segment) - { - DLIF_trace(" segment [%d] load address: 0x%lx\n", - i, (unsigned long)host_seg->load_address); - DLIF_trace(" segment [%d] run address: 0x%lx\n", - i, (unsigned long)host_seg->run_address); - } - - itr = itr->next_ptr; - } -} diff --git a/src/utils/elfload/dlw_dsbt.c b/src/utils/elfload/dlw_dsbt.c deleted file mode 100644 index 61e1ca5..0000000 --- a/src/utils/elfload/dlw_dsbt.c +++ /dev/null @@ -1,565 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* dlw_dsbt.c */ -/* */ -/* Implementation of client functions required by dynamic loader API */ -/* to support the Dynamic Static Base Table (DSBT) model. */ -/* Please see list of client-required API functions in dload_api.h. */ -/* */ -/*****************************************************************************/ -#include "Queue.h" -#include "ArrayList.h" -#include "dload_api.h" -#include -#include -#include -#include "dlw_dsbt.h" - -/*****************************************************************************/ -/* DSBT_index_request_queue - This is a holding area for DSBT index requests */ -/* while allocation and relocation of symbols is in progress for the top- */ -/* level module and all of its dependents. Items will be pulled off the */ -/* queue when we are ready to make actual DSBT index assignments in */ -/* DLIF_assign_dsbt_indices(). */ -/*****************************************************************************/ -TYPE_QUEUE_IMPLEMENTATION(DSBT_Index_Request*, dsbt_index_request_ptr) -dsbt_index_request_ptr_Queue DSBT_index_request_queue; - -/*****************************************************************************/ -/* DSBT_Master - This is the master copy of the DSBT created by the client */ -/* after all object modules have been allocated and their symbols have */ -/* been relocated. */ -/*****************************************************************************/ -static int32_t DSBT_first_avail_index = 0; -Array_List DSBT_master; - -#if LOADER_DEBUG -static void dump_master_dsbt(void); -#endif - -/*****************************************************************************/ -/* DLIF_register_dsbt_index_request() */ -/* */ -/* Register a request for a DSBT index from a dynamic executable or a */ -/* dynamic library. An executable must make a specific request for the */ -/* 0th slot in the DSBT. Dynamic libraries can make a specific index */ -/* request or have the client assign an index on its behalf when the */ -/* allocation and relocation of symbols is completed for a top-level */ -/* load (load invoked by client's "load" command, for example). */ -/* */ -/* If a specific request is made for an index that has already been */ -/* assigned or specifically requested by an earlier request, then an */ -/* error will be emitted and the loader core should fail the load. */ -/* */ -/* The information provided with the request will include the requesting */ -/* module's so_name and file handle, along with the index requested and */ -/* the index assigned. */ -/* */ -/*---------------------------------------------------------------------------*/ -/* */ -/* It is assumed that AL_initialize has been called to set up the initial */ -/* state of the client's model of the DSBT master. */ -/* */ -/*****************************************************************************/ -BOOL DLIF_register_dsbt_index_request(DLOAD_HANDLE handle, - const char *requestor_name, - int32_t requestor_file_handle, - int32_t requested_dsbt_index) -{ - DSBT_Index_Request *new_request = NULL; - - /*-----------------------------------------------------------------------*/ - /* If requesting a specific DSBT index, check existing list of DSBT index*/ - /* requests to see if we've already seen a request for the specified */ - /* DSBT index or if a request has already been received on behalf of the */ - /* specified file. Both cases constitute an error and will abort the */ - /* load. */ - /*-----------------------------------------------------------------------*/ - if (requested_dsbt_index != DSBT_INDEX_INVALID) - { - dsbt_index_request_ptr_Queue_Node *ptr; - - /*-------------------------------------------------------------------*/ - /* If the client's master DSBT model already has content, then check */ - /* to see if the requested DSBT index is available in the master */ - /* DSBT. */ - /*-------------------------------------------------------------------*/ - if (AL_size(&DSBT_master) > requested_dsbt_index) - { - DSBT_Entry *client_dsbt = (DSBT_Entry *)(DSBT_master.buf); - if (client_dsbt[requested_dsbt_index].index_request != NULL) - { - DLIF_error(DLET_MISC, - "%s is requesting a DSBT index, %d, that is already " - "being used by an active module, %s", - requestor_name, requested_dsbt_index, - client_dsbt[requested_dsbt_index].index_request->name); - return FALSE; - } - } - - for (ptr = DSBT_index_request_queue.front_ptr; - ptr != NULL; ptr = ptr->next_ptr) - { - DSBT_Index_Request *existing_request = ptr->value; - - /*---------------------------------------------------------------*/ - /* Have we seen a request for this file already? That would be a */ - /* problem (likely internal). */ - /*---------------------------------------------------------------*/ - if (requestor_file_handle == existing_request->file_handle) - { - DLIF_error(DLET_MISC, - "A DSBT index has already been requested on behalf " - "of %s; cannot make a second DSBT index request for " - "the same module", existing_request->name); - return FALSE; - } - - /*---------------------------------------------------------------*/ - /* Have we seen a specific request for this DSBT index already? */ - /* Report a conflict among specific requests in the same load. */ - /*---------------------------------------------------------------*/ - if (requested_dsbt_index == existing_request->requested_index) - { - DLIF_error(DLET_MISC, - "Requested DSBT index, %d, requested by %s has " - "already been requested by %s; load aborted", - requested_dsbt_index, - requestor_name, - existing_request->name); - return FALSE; - } - } - } - - /*-----------------------------------------------------------------------*/ - /* If specified module is requesting a specific DSBT index that hasn't */ - /* been encountered yet, or if it is making a general DSBT index request */ - /* (to be assigned by the client when the current top-level load is */ - /* sucessfully completed), make a DSBT index request entry for the */ - /* current module and add it to the DSBT_Index_Request_List. */ - /*-----------------------------------------------------------------------*/ - new_request = (DSBT_Index_Request *)DLIF_malloc(sizeof(DSBT_Index_Request)); - if (NULL == new_request) { - DLIF_error(DLET_MISC, - "Could not allocate memory for DSBT index request"); - return FALSE; - } - new_request->name = (char *)DLIF_malloc(strlen(requestor_name) + 1); - if (NULL == new_request->name) { - DLIF_free(new_request); - DLIF_error(DLET_MISC, - "Could not allocate memory for DSBT index request name"); - return FALSE; - } - strcpy(new_request->name, requestor_name); - new_request->file_handle = requestor_file_handle; - - new_request->dsbt_size = DLOAD_get_dsbt_size(handle, requestor_file_handle); - if (!DLOAD_get_dsbt_base(handle, requestor_file_handle, &new_request->dsbt_base)) - { - DLIF_error(DLET_MISC, - "Could not resolve DSBT base value for %s", - requestor_name); - DLIF_free(new_request->name); - new_request->name = NULL; - DLIF_free(new_request); - new_request = NULL; - return FALSE; - } - - if (!DLOAD_get_static_base(handle, requestor_file_handle, &new_request->static_base)) - { - DLIF_error(DLET_MISC, - "Could not resolve static base value for %s", - requestor_name); - DLIF_free(new_request->name); - new_request->name = NULL; - DLIF_free(new_request); - new_request = NULL; - return FALSE; - } - - new_request->requested_index = requested_dsbt_index; - new_request->assigned_index = DSBT_INDEX_INVALID; - - dsbt_index_request_ptr_enqueue(&DSBT_index_request_queue, new_request); - - return TRUE; -} - -/*****************************************************************************/ -/* new_DSBT_Entry() */ -/* */ -/* Construct a DSBT_Entry data structure and initialize it with specified */ -/* DSBT_Index_Request pointer. */ -/* */ -/*****************************************************************************/ -static void add_dsbt_entry(DSBT_Index_Request *request) -{ - DSBT_Entry new_entry; - new_entry.index_request = request; - AL_append(&DSBT_master, &new_entry); -} - -/*****************************************************************************/ -/* assign_dsbt_entry() */ -/* */ -/* Assign an entry in the client's model of the DSBT master to the */ -/* given DSBT index request. If the DSBT master needs to grow in order */ -/* to accommodate the request, then it will do so. */ -/* */ -/*****************************************************************************/ -static void assign_dsbt_entry(DSBT_Index_Request *request) -{ - DSBT_Entry *client_dsbt = NULL; - - /*-----------------------------------------------------------------------*/ - /* For a specific DSBT index request, assign the specified slot in the */ - /* DSBT master to the given request. If we need to, we will grow the */ - /* master DSBT to a size that can accommodate the specific request. */ - /*-----------------------------------------------------------------------*/ - if (request->requested_index != DSBT_INDEX_INVALID) - { - while (AL_size(&DSBT_master) <= request->requested_index) - add_dsbt_entry(NULL); - - client_dsbt = (DSBT_Entry *)(DSBT_master.buf); - client_dsbt[request->requested_index].index_request = request; - request->assigned_index = request->assigned_index; - } - - /*-----------------------------------------------------------------------*/ - /* For a general DSBT index request, find the first available slot in the*/ - /* master DSBT and assign it to the request, or grow the master DSBT and */ - /* assign the new slot to the request. */ - /*-----------------------------------------------------------------------*/ - else - { - int i; - client_dsbt = (DSBT_Entry *)(DSBT_master.buf); - for (i = DSBT_first_avail_index; i < AL_size(&DSBT_master); i++) - { - if (client_dsbt[i].index_request == NULL) - { - client_dsbt[i].index_request = request; - break; - } - - DSBT_first_avail_index++; - } - - if (i == AL_size(&DSBT_master)) - add_dsbt_entry(request); - - request->assigned_index = i; - } -} - -/*****************************************************************************/ -/* DLIF_assign_dsbt_indices() */ -/* */ -/* When the core loader completes allocation of the top-level object */ -/* being loaded and the allocation for all dependent files, this function */ -/* is called to bind objects that have just been allocated to their DSBT */ -/* index (as determined by the client). We will first honor any specific */ -/* index requests that have been made. Then remaining DSBT entries will */ -/* be assigned in the order that they were encountered during the load */ -/* to each available slot in the master DSBT. */ -/* */ -/*---------------------------------------------------------------------------*/ -/* */ -/* It is assumed that AL_initialize has been called to set up the initial */ -/* state of the client's model of the DSBT master. */ -/* */ -/* Error conditions should have been detected during registration of each */ -/* DSBT index request. I don't think there are any error/warning */ -/* situations that need to be handled within this function. */ -/* */ -/*****************************************************************************/ -void DLIF_assign_dsbt_indices(void) -{ - /*-----------------------------------------------------------------------*/ - /* Spin through DSBT index request queue, processing any specific DSBT */ - /* index requests. If we need to grow the DSBT master model to handle a */ - /* request, then do so. */ - /*-----------------------------------------------------------------------*/ - dsbt_index_request_ptr_Queue_Node *ptr = DSBT_index_request_queue.front_ptr; - dsbt_index_request_ptr_Queue_Node *next_ptr = NULL; - DSBT_Index_Request *curr_req = NULL; - - for (; ptr != NULL; ptr = next_ptr) - { - curr_req = ptr->value; - next_ptr = ptr->next_ptr; - - if (curr_req->requested_index == DSBT_INDEX_INVALID) continue; - - assign_dsbt_entry(curr_req); - dsbt_index_request_ptr_remove(&DSBT_index_request_queue, curr_req); - } - - /*-----------------------------------------------------------------------*/ - /* Spin through what remains of the DSBT index request queue to process */ - /* all general DSBT index requests. This time we can dequeue entries */ - /* off the index request queue as we proceed. */ - /*-----------------------------------------------------------------------*/ - curr_req = dsbt_index_request_ptr_dequeue(&DSBT_index_request_queue); - while (curr_req != NULL) - { - assign_dsbt_entry(curr_req); - curr_req = dsbt_index_request_ptr_dequeue(&DSBT_index_request_queue); - } - -#if LOADER_DEBUG - if (debugging_on) - { - DLIF_trace("After completed assignment of DSBT indices ...\n"); - dump_master_dsbt(); - } -#endif -} - -/*****************************************************************************/ -/* DLIF_get_dsbt_index() */ -/* */ -/* Find specified file handle among the list of DSBT request entries. */ -/* Then return the DSBT index that has been assigned to that file */ -/* handle. Emit an error if the file handle is not found among the list */ -/* of DSBT request entries or if a DSBT assignment has not been made */ -/* for the specified file yet. */ -/* */ -/*****************************************************************************/ -int32_t DLIF_get_dsbt_index(int32_t file_handle) -{ - /*-----------------------------------------------------------------------*/ - /* Find specified file handle among client's model of the DSBT master. */ - /*-----------------------------------------------------------------------*/ - int32_t i; - DSBT_Entry *client_dsbt = (DSBT_Entry *)(DSBT_master.buf); - for (i = 0; i < AL_size(&DSBT_master); i++) - { - DSBT_Index_Request *curr_req = client_dsbt[i].index_request; - - if (curr_req == NULL) continue; - - if (curr_req->file_handle == file_handle) - return curr_req->assigned_index; - } - - /*-----------------------------------------------------------------------*/ - /* Otherwise, we either did not find the specified file handle, or a */ - /* valid DSBT index has not yet been assigned to the file handle. */ - /*-----------------------------------------------------------------------*/ - return DSBT_INDEX_INVALID; -} - -/*****************************************************************************/ -/* DLIF_update_all_dsbts() */ -/* */ -/* Update all DSBTs for the application and all libraries that use the */ -/* DSBT model. Each DSBT index request entry was provided with the */ -/* address and size of the DSBT contained in the loaded application. */ -/* The client simply needs to copy the content of its master copy of the */ -/* DSBT to each module's own DSBT. The client will check the size of */ -/* each module's DSBT to see if it is big enough to hold the master copy */ -/* of the DSBT before actually copying the master to the module's DSBT. */ -/* An error will be emitted if a module's allocated DSBT is not big */ -/* enough to hold the master DSBT. */ -/* */ -/*****************************************************************************/ -BOOL DLIF_update_all_dsbts() -{ - /*-----------------------------------------------------------------------*/ - /* Spin through the client's master copy of the DSBT. For each entry in */ - /* the table: */ - /* */ - /* 1. Check the DSBT size for the module that is associated with the */ - /* current slot in the DSBT to see if its DSBT size is large enough*/ - /* to hold a copy of the master DSBT. */ - /* */ - /* 2. Query the core loader for the static base value associated with */ - /* the module that has been assigned to the current index in the */ - /* DSBT. This static base value is recorded in the client's DSBT */ - /* model. */ - /* */ - /* 3. Query the core loader for the DSBT base value associated with */ - /* the module that has been assigned to the current index in the */ - /* master DSBT. We should only look this value up once while the */ - /* file is still open and its dynamic module object is still */ - /* available. */ - /* */ - /*-----------------------------------------------------------------------*/ - int32_t i; - int32_t master_dsbt_size = AL_size(&DSBT_master); - DSBT_Entry *client_dsbt = (DSBT_Entry *)(DSBT_master.buf); - DSBT_Index_Request *curr_req = NULL; - -#if LOADER_DEBUG - if (debugging_on) - { - DLIF_trace("Starting DLIF_update_all_dsbts() ... \n"); - DLIF_trace("Size of master DSBT is %d\n", master_dsbt_size); - dump_master_dsbt(); - } -#endif - - /*-----------------------------------------------------------------------*/ - /* Spin through the master DSBT model and fill in details about the DSBT */ - /* base and the static base associated with each module that has been */ - /* assigned a slot in the master DSBT. */ - /*-----------------------------------------------------------------------*/ - for (i = 0; i < master_dsbt_size; i++) - { - curr_req = client_dsbt[i].index_request; - - /*-------------------------------------------------------------------*/ - /* We only need to worry about filling in details for slots that have*/ - /* actually been assigned to an object module (if this slot doesn't */ - /* have a DSBT index request record associated with it, then it is */ - /* "available"). */ - /*-------------------------------------------------------------------*/ - if (curr_req != NULL) - { - /*---------------------------------------------------------------*/ - /* If the DSBT size has not been filled in for the module that */ - /* is assigned to this slot, look it up in the local symbol */ - /* table of the module. We have to do this while the dynamic */ - /* module object for the module is still open (it has a copy of */ - /* the local symbol table). */ - /*---------------------------------------------------------------*/ - uint32_t curr_dsbt_size = curr_req->dsbt_size; - if (curr_dsbt_size < master_dsbt_size) - { - DLIF_error(DLET_MISC, - "DSBT allocated for %s is not large enough to hold " - "entire DSBT", curr_req->name); - return FALSE; - } - } - } - - /*-----------------------------------------------------------------------*/ - /* Now write a copy of the DSBT for each module that uses the DSBT model.*/ - /* We need to find the DSBT base for each module represented in the */ - /* master DSBT, then we can write the content of the master DSBT to each */ - /* DSBT base location. */ - /*-----------------------------------------------------------------------*/ - for (i = 0; i < master_dsbt_size; i++) - { - curr_req = client_dsbt[i].index_request; - - /*-------------------------------------------------------------------*/ - /* Write content of master DSBT to location of module's DSBT. */ - /*-------------------------------------------------------------------*/ - if (curr_req != NULL) - { - int j; -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("Writing master DSBT to 0x%08lx for module: %s\n", - curr_req->dsbt_base, curr_req->name); -#endif - - for (j = 0; j < master_dsbt_size; j++) - { - DSBT_Index_Request *j_req = client_dsbt[j].index_request; - - if (j_req != NULL) - *((TARGET_ADDRESS *)(curr_req->dsbt_base) + j) = - (j_req != NULL) ? j_req->static_base : 0; - } - } - } - -#if LOADER_DEBUG - if (debugging_on) dump_master_dsbt(); -#endif - - return TRUE; -} - -/*****************************************************************************/ -/* dump_master_dsbt() */ -/*****************************************************************************/ -#if LOADER_DEBUG -static void dump_master_dsbt(void) -{ - int i; - DSBT_Entry *client_dsbt = (DSBT_Entry *)(DSBT_master.buf); - DLIF_trace("Dumping master DSBT ...\n"); - for (i = 0; i < AL_size(&DSBT_master); i++) - { - DSBT_Index_Request *i_req = client_dsbt[i].index_request; - if (i_req != NULL) - { - DLIF_trace(" slot %d has dsbt_base: 0x%08lx; static base: 0x%08lx;\n" - " index request from: %s\n", - i, i_req->dsbt_base, i_req->static_base, i_req->name); - } - else - { - DLIF_trace(" slot %d is AVAILABLE\n", i); - } - } -} -#endif - -/*****************************************************************************/ -/* DSBT_release_entry() */ -/* */ -/* Once a file is unloaded from the target, make its DSBT entry in the */ -/* master DSBT available to objects that may be subsequently loaded. If */ -/* we don't find the file handle among the master DSBT, then we assume */ -/* that the file does not use the DSBT model. */ -/* */ -/*****************************************************************************/ -void DSBT_release_entry(int32_t file_handle) -{ - int32_t i; - DSBT_Entry *client_dsbt = (DSBT_Entry *)(DSBT_master.buf); - for (i = 0; i < AL_size(&DSBT_master); i++) - { - DSBT_Index_Request *curr_req = client_dsbt[i].index_request; - - if (curr_req && (curr_req->file_handle == file_handle)) - { - client_dsbt[i].index_request = NULL; - if (i < DSBT_first_avail_index) DSBT_first_avail_index = i; - DLIF_free(curr_req); - } - } -} diff --git a/src/utils/elfload/dlw_trgmem.c b/src/utils/elfload/dlw_trgmem.c deleted file mode 100644 index 27ea63d..0000000 --- a/src/utils/elfload/dlw_trgmem.c +++ /dev/null @@ -1,561 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* dlw_trgmem.c */ -/* */ -/* This source file contains the implementation of the client side's target */ -/* memory allocator. The RIDL version of the dynamic loader will manage */ -/* target memory from a massive data object called "trg_mem_pool". This */ -/* memory manager is derived from the RTS version of malloc()/free(). */ -/* */ -/*---------------------------------------------------------------------------*/ -/* */ -/* This module contains the functions which implement the dynamic memory */ -/* management routines. The following assumptions/rules apply: */ -/* */ -/* 1) Packets are allocated from host memory so they have no impact on */ -/* the target memory heap. */ -/* 2) The size of the heap is assumed to be 0x02000000, the size of the */ -/* .blob section in the ELF dynamic loader executable file. */ -/* 3) The heap can be reset at any time by calling trg_minit() */ -/* */ -/*---------------------------------------------------------------------------*/ -/* These functions constitute the target memory manager interface with the */ -/* rest of the dynamic loader: */ -/* */ -/* DLTMM_malloc() : Allocate a chunk of target memory per request. */ -/* DLTMM_free() : Release target memory allocated to specified address. */ -/* DLTMM_fwrite() : Write content of target memory to dump file. */ -/* DLTMM_fread() : Read core file into target memory area. */ -/* */ -/*---------------------------------------------------------------------------*/ -/* These functions manage the target memory packet list and help the */ -/* interface functions carry out a target memory allocation: */ -/* */ -/* trg_minit() : Initialize target memory packet list. */ -/* trg_align() : Find next address within packet that is aligned. */ -/* trg_free_pkt() : Free a used packet and merge it with free neighbors. */ -/* trg_alloc_pkt() : Allocate chunk of free packet and slit packet into */ -/* used and available pieces. */ -/* trg_malloc() : Serve DLTMM_malloc(), set actual request size to */ -/* multiple of MIN_BLOCK and find a free packet to */ -/* allocate from. */ -/* */ -/*****************************************************************************/ -#include "ArrayList.h" -#include "dload_api.h" -#include "dload4430.h" -#include -#include -#include -#include "dlw_trgmem.h" - -/*---------------------------------------------------------------------------*/ -/* Function declarations */ -/*---------------------------------------------------------------------------*/ -static void trg_minit(void* client_handle, uint32_t dyn_seg, - uint32_t size); -static void trg_mdeinit(void* client_handle); -static uint32_t trg_align(uint32_t orig_addr, int alignment); -static void trg_free_pkt(void* client_handle, TRG_PACKET *); -static uint32_t trg_alloc_pkt(TRG_PACKET *, size_t, int, uint32_t); -static BOOL trg_malloc(void* client_handle, uint32_t *req_addr, - size_t size, int alignment); - -/*****************************************************************************/ -/* TRG_MINIT() - Initialize target memory management data structures. */ -/* Set up initial free list. */ -/*****************************************************************************/ -static void trg_minit(void* client_handle, uint32_t dyn_seg, uint32_t size) -{ - DLoad4430_Object *clientObj = (DLoad4430_Object *)client_handle; - - clientObj->trg_mem_head = (TRG_PACKET *)DLIF_malloc(sizeof(TRG_PACKET)); - if (clientObj->trg_mem_head) { - clientObj->trg_mem_head->packet_addr = dyn_seg; - clientObj->trg_mem_head->packet_size = size; - clientObj->trg_mem_head->prev_packet = NULL; - clientObj->trg_mem_head->next_packet = NULL; - clientObj->trg_mem_head->used_packet = FALSE; - } -} - -/*****************************************************************************/ -/* TRG_MDEINIT() - De-Initialize target memory management data structures. */ -/* Free up initial free list. */ -/*****************************************************************************/ -static void trg_mdeinit(void* client_handle) -{ - DLoad4430_Object *clientObj = (DLoad4430_Object *)client_handle; - - DLIF_free(clientObj->trg_mem_head); -} - -/*****************************************************************************/ -/* TRG_ALIGN() - If given origin address is aligned, return it. Otherwise, */ -/* find next aligned address and return it. */ -/*****************************************************************************/ -static uint32_t trg_align(uint32_t orig_addr, int alignment) -{ - if (alignment <= 1) return orig_addr; - return ((orig_addr + (alignment - 1)) & ~(alignment - 1)); -} - -/*****************************************************************************/ -/* TRG_FREE_PKT() - Move packet from used state to free state and merge it */ -/* with any free neighbors on the target memory packet list. */ -/*****************************************************************************/ -static void trg_free_pkt(void* client_handle, TRG_PACKET *ptr) -{ - DLoad4430_Object *clientObj = (DLoad4430_Object *)client_handle; - - if (ptr) - { - TRG_PACKET *prev_pkt = ptr->prev_packet; - TRG_PACKET *next_pkt = ptr->next_packet; - - if (prev_pkt && !prev_pkt->used_packet) - { - ptr->packet_addr = prev_pkt->packet_addr; - ptr->packet_size += prev_pkt->packet_size; - ptr->prev_packet = prev_pkt->prev_packet; - if (prev_pkt->prev_packet) - prev_pkt->prev_packet->next_packet = ptr; - DLIF_free(prev_pkt); - } - - if (next_pkt && !next_pkt->used_packet) - { - ptr->packet_size += next_pkt->packet_size; - ptr->next_packet = next_pkt->next_packet; - if (next_pkt->next_packet) - next_pkt->next_packet->prev_packet = ptr; - DLIF_free(next_pkt); - } - - if (!ptr->prev_packet) clientObj->trg_mem_head = ptr; - - ptr->used_packet = FALSE; - } -} - -/*****************************************************************************/ -/* TRG_ALLOC_PKT() - Allocate size bytes into given free packet at next */ -/* aligned address in the packet. Split packet into used and free */ -/* pieces, updating the target memory list along the way. */ -/*****************************************************************************/ -static uint32_t trg_alloc_pkt(TRG_PACKET *ptr, size_t size, int alignment, - uint32_t req_addr) -{ - uint32_t align_addr; - uint32_t align_pad; - - /*-----------------------------------------------------------------------*/ - /* Split given packet into used and unused pieces. */ - /*-----------------------------------------------------------------------*/ - TRG_PACKET *used_pkt = ptr; - size_t orig_sz = 0; - TRG_PACKET *free_pkt = NULL; - - /*-----------------------------------------------------------------------*/ - /* If the requested address is not equal to the packet address, we need */ - /* to break the packet in two by inserting a free packet before the */ - /* the used packet. This assumes that the requested address has already */ - /* been verified to lie within the packet. */ - /*-----------------------------------------------------------------------*/ - if (req_addr > used_pkt->packet_addr) - { - free_pkt = (TRG_PACKET *)DLIF_malloc(sizeof(TRG_PACKET)); - if(!free_pkt) { - return 0; - } - free_pkt->next_packet = used_pkt; - free_pkt->prev_packet = used_pkt->prev_packet; - used_pkt->prev_packet = free_pkt; - - free_pkt->packet_size = req_addr - used_pkt->packet_addr; - free_pkt->packet_addr = used_pkt->packet_addr; - free_pkt->used_packet = FALSE; - - used_pkt->packet_addr = req_addr; - } - - /*-----------------------------------------------------------------------*/ - /* Compute aligned address within given free packet where we want to */ - /* allocate. Any alignment padding at the front will become a separate */ - /* free packet on the target memory list. */ - /*-----------------------------------------------------------------------*/ - align_addr = trg_align(used_pkt->packet_addr, alignment); - align_pad = align_addr - used_pkt->packet_addr; - - /*-----------------------------------------------------------------------*/ - /* If there is any padding at the front of the packet, then we'll build */ - /* a new packet to represent our allocated space. */ - /*-----------------------------------------------------------------------*/ - if (align_pad) - { - /*-------------------------------------------------------------------*/ - /* If free_pkt is NULL, then we did not split ptr into two packets. */ - /* If this is the case we need to allocate a new packet for the */ - /* padding. If we did split ptr into two packets, just merge the */ - /* padding into the free packet. */ - /*-------------------------------------------------------------------*/ - if (!free_pkt) - { - free_pkt = (TRG_PACKET *)DLIF_malloc(sizeof(TRG_PACKET)); - if(!free_pkt) { - return 0; - } - free_pkt->next_packet = used_pkt; - free_pkt->prev_packet = used_pkt->prev_packet; - used_pkt->prev_packet = free_pkt; - free_pkt->packet_addr = used_pkt->packet_addr; - free_pkt->packet_size = 0; - } - - free_pkt->packet_size += align_pad; - used_pkt->packet_size -= align_pad; - used_pkt->packet_addr = align_addr; - - } - - /*-----------------------------------------------------------------------*/ - /* Preserve original size of used packet so that we can compute size of */ - /* unused space when we split the used packet. Then set size of used */ - /* packet. */ - /*-----------------------------------------------------------------------*/ - orig_sz = used_pkt->packet_size; - used_pkt->packet_size = size; - used_pkt->used_packet = TRUE; - - /*-----------------------------------------------------------------------*/ - /* If there is unused space at the end of our allocated packet, then */ - /* we'll build up a new packet to represent this free space and at it */ - /* into the target memory list. */ - /*-----------------------------------------------------------------------*/ - if (orig_sz > size) - { - free_pkt = (TRG_PACKET *)DLIF_malloc(sizeof(TRG_PACKET)); - if(!free_pkt) { - return 0; - } - free_pkt->next_packet = used_pkt->next_packet; - free_pkt->prev_packet = used_pkt; - used_pkt->next_packet = free_pkt; - - free_pkt->packet_size = orig_sz - size; - - free_pkt->packet_addr = used_pkt->packet_addr + size; - - free_pkt->used_packet = FALSE; - } - - return (used_pkt->packet_addr); -} - -/*****************************************************************************/ -/* TRG_MALLOC() - Allocate target memory from the free list (which manages */ -/* available target memory in .blob section). The free list keeps */ -/* track of available and used target memory. */ -/*****************************************************************************/ -static BOOL trg_malloc(void* client_handle, uint32_t *req_addr, size_t size, - int alignment) -{ - DLoad4430_Object *clientObj = (DLoad4430_Object *)client_handle; - - TRG_PACKET *current = NULL; - TRG_PACKET *best_fit = NULL; - - if (size <= 0) return FALSE; - - /*-----------------------------------------------------------------------*/ - /* If we did not get a request for a specific target address from the */ - /* client, then find the best fit available packet, incorporating any */ - /* alignment constraints imposed by the client. */ - /*-----------------------------------------------------------------------*/ - if (*req_addr == (uint32_t)-1) - { - /*-------------------------------------------------------------------*/ - /* Find best free packet on the target memory list. */ - /*-------------------------------------------------------------------*/ - for (current = clientObj->trg_mem_head; - current; - current = current->next_packet) - { - /*---------------------------------------------------------------*/ - /* Account for alignment constraint on current packet. */ - /*---------------------------------------------------------------*/ - uint32_t align_addr = trg_align(current->packet_addr, alignment); - uint32_t align_pad = align_addr - current->packet_addr; - - /*---------------------------------------------------------------*/ - /* Skip over any packets that are already allocated. */ - /*---------------------------------------------------------------*/ - if (current->used_packet) continue; - - /*---------------------------------------------------------------*/ - /* Best fit will be smallest free packet that is >= size. */ - /*---------------------------------------------------------------*/ - if ((current->packet_size > align_pad) && - ((current->packet_size - align_pad) >= size)) - { - if (best_fit && (current->packet_size >= best_fit->packet_size)) - continue; - best_fit = current; - } - } - - if (!best_fit) return FALSE; - - *req_addr = trg_alloc_pkt(best_fit, size, alignment, - best_fit->packet_addr); - - return TRUE; - } - - /*-----------------------------------------------------------------------*/ - /* Otherwise, we do have a request for a specific target address from the*/ - /* client. So we need to find the free packet that contains that target */ - /* address. */ - /*-----------------------------------------------------------------------*/ - else - { - /*-------------------------------------------------------------------*/ - /* Find the free packet that contains the requested address. */ - /*-------------------------------------------------------------------*/ - for (current = clientObj->trg_mem_head; - current; - current = current->next_packet) - { - /*---------------------------------------------------------------*/ - /* If we have a requested address, we must make sure that the */ - /* requested address falls on an alignment boundary, if it does */ - /* not report an error. */ - /* --------------------------------------------------------------*/ - uint32_t align_addr = trg_align(*req_addr, alignment); - if (align_addr != *req_addr) - { - DLIF_error(DLET_TRGMEM, "requested address is not aligned\n"); - return FALSE; - } - - /*---------------------------------------------------------------*/ - /* Does the requested address fall inside the packet? */ - /*---------------------------------------------------------------*/ - if (*req_addr < current->packet_addr || - ((current->packet_addr + current->packet_size) <= *req_addr)) - continue; - - /*---------------------------------------------------------------*/ - /* Is the current packet big enough for the request? */ - /*---------------------------------------------------------------*/ - if ((current->packet_size) >= size) - { - uint32_t alloc_addr = trg_alloc_pkt(current, size, alignment, - *req_addr); - if (alloc_addr != *req_addr) - { - DLIF_error(DLET_TRGMEM, "Problem with trg_alloc_pkt\n"); - exit(1); - } - - return TRUE; - } - - break; - } - } - - return FALSE; -} - -/*****************************************************************************/ -/* DLTMM_INIT() - Externally accessible interface to initialize the target */ -/* memory allocator. */ -/*****************************************************************************/ -BOOL DLTMM_init(void* client_handle, uint32_t dynMemAddr, uint32_t size) -{ - DLoad4430_Object *clientObj = (DLoad4430_Object *)client_handle; - - if (dynMemAddr == 0) - return FALSE; - - if (!clientObj->trg_minit) - { - trg_minit(client_handle, dynMemAddr, size); - clientObj->trg_minit = TRUE; - } - - return TRUE; -} - -/*****************************************************************************/ -/* DLTMM_DEINIT() - Externally accessible interface to de-initialize the */ -/* target memory allocator. */ -/*****************************************************************************/ -BOOL DLTMM_deinit(void* client_handle) -{ - DLoad4430_Object *clientObj = (DLoad4430_Object *)client_handle; - - if (clientObj->trg_minit) - { - trg_mdeinit(client_handle); - clientObj->trg_minit = FALSE; - } - - return TRUE; -} - -/*****************************************************************************/ -/* DLTMM_MALLOC() - Externally accessible interface into target memory */ -/* allocator. This function will use the core target memory manager */ -/* to find available space per requested and update target memory list */ -/* to reflect new status of used and free target memory. */ -/*****************************************************************************/ -BOOL DLTMM_malloc(void* client_handle, - struct DLOAD_MEMORY_REQUEST *targ_req, - struct DLOAD_MEMORY_SEGMENT *obj_desc) -{ - /*-----------------------------------------------------------------------*/ - /* Set up alignment constraint and request for specific address, if */ - /* there is one. */ - /*-----------------------------------------------------------------------*/ - int alignment = (targ_req->align) ? targ_req->align : 1; - uint32_t req_addr = (targ_req->flags & DLOAD_SF_relocatable) ? - (uint32_t)-1 : (uint32_t)obj_desc->target_address; - - /*-----------------------------------------------------------------------*/ - /* Ask for free space from the target memory allocator. */ - /*-----------------------------------------------------------------------*/ - if (trg_malloc(client_handle, - &req_addr, - obj_desc->memsz_in_bytes, - alignment)) - { - obj_desc->target_address = targ_req->host_address = (void *)req_addr; - return TRUE; - } - - /*-----------------------------------------------------------------------*/ - /* Something went wrong. Target memory allocation failed. */ - /*-----------------------------------------------------------------------*/ - return FALSE; -} - -/*****************************************************************************/ -/* DLTMM_FREE() - Find packet in target memory list associated with given */ -/* target address and change its state from used to free. */ -/*****************************************************************************/ -void DLTMM_free(void* client_handle, TARGET_ADDRESS ptr) -{ - DLoad4430_Object *clientObj = (DLoad4430_Object *)client_handle; - - uint32_t pkt_addr = (uint32_t)ptr; - TRG_PACKET *prev = NULL; - TRG_PACKET *current = NULL; - - /*-----------------------------------------------------------------------*/ - /* Find free packet on the target memory list that contains the specified*/ - /* address that we are trying to free. */ - /*-----------------------------------------------------------------------*/ - for (current = clientObj->trg_mem_head; - current; - current = current->next_packet) - { - /*-------------------------------------------------------------------*/ - /* Skip over any packets that are already free. */ - /*-------------------------------------------------------------------*/ - if (!current->used_packet) continue; - - /*-------------------------------------------------------------------*/ - /* Find used packet associated with given address. */ - /*-------------------------------------------------------------------*/ - if (current->packet_addr <= pkt_addr) prev = current; - else break; - } - - if (prev) trg_free_pkt(client_handle, prev); - - else - { - DLIF_error(DLET_TRGMEM, - "Did not find free packet associated with given target " - "address, 0x%lx\n", pkt_addr); - exit(1); - } -} - -/*****************************************************************************/ -/* DLTMM_FWRITE_TRG_MEM() - Write content of target memory area to a file. */ -/*****************************************************************************/ -void DLTMM_fwrite_trg_mem(FILE *fp) -{ - /*if (fp) fwrite(trg_mem_pool, trg_mem_pool_sz, 1, fp);*/ -} - -/*****************************************************************************/ -/* DLTMM_FREAD_TRG_MEM() - Read file content into target memory area. */ -/*****************************************************************************/ -void DLTMM_fread_trg_mem(FILE *fp) -{ - /*if (fp) fread(trg_mem_pool, trg_mem_pool_sz, 1, fp);*/ -} - -/*****************************************************************************/ -/* DLTMM_DUMP_TRG_MEM() - Dump the contents of target memory into a file. */ -/*****************************************************************************/ -void DLTMM_dump_trg_mem(uint32_t offset, uint32_t nbytes, - FILE* fp) -{ -#if 0 - uint8_t* ptr = trg_mem_pool + offset; - - if (!fp) - { - DLIF_error(DLET_TRGMEM, "NULL file pointer given to dump_trgmem\n"); - return; - } - - /*-----------------------------------------------------------------------*/ - /* Make sure the request is in range. */ - /*-----------------------------------------------------------------------*/ - if ((ptr + nbytes) > (trg_mem_pool + trg_mem_pool_sz )) - { - DLIF_error(DLET_TRGMEM, "Invalid range given to dump_trgmem\n"); - return; - } - - fwrite(ptr, 1, nbytes, fp); -#endif -} diff --git a/src/utils/elfload/elf32.c b/src/utils/elfload/elf32.c deleted file mode 100644 index 158fa34..0000000 --- a/src/utils/elfload/elf32.c +++ /dev/null @@ -1,655 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* elf32.c */ -/* */ -/* Basic Data Structures for 32-Bit ELF Object Format Files */ -/* */ -/* The data structures in this file come primarily from this specification: */ -/* */ -/* Tool Interface Standard (TIS) */ -/* Executable and Linking Format (ELF) Specification */ -/* Version 1.2 */ -/* */ -/* TIS Committee */ -/* May 1995 */ -/* */ -/* Additions and enhancements from this specification are also included: */ -/* */ -/* System V Application Binary Interface */ -/* DRAFT 17 */ -/* December 2003 */ -/* */ -/* http://sco.com/developers/gabi/2003-12-17/contents.html */ -/* */ -/* This is a C implementation of the data base objects that are commonly */ -/* used in the source for TI development tools that support ELF. */ -/*****************************************************************************/ -/* PLEASE NOTE!! Other TI tools use a C++ implementation in the ELF04 */ -/* source module. Changes to that module need to be duplicated here and */ -/* vice versa at least until the ELF04 module implementation is made C safe. */ -/*****************************************************************************/ -#include "elf32.h" - -/*---------------------------------------------------------------------------*/ -/* Dynamic Tag Database */ -/*---------------------------------------------------------------------------*/ - -const struct EDYN_TAG EDYN_TAG_DB[] = -{ - /* EDYN_TAG_NULL */ - { - /* d_tag_name */ "DT_NULL", - /* d_tag_value */ DT_NULL, - /* d_untype */ EDYN_UNTYPE_IGNORED, - /* d_exec_req */ EDYN_TAGREQ_MANDATORY, - /* d_shared_req */ EDYN_TAGREQ_MANDATORY - }, - - /* EDYN_TAG_NEEDED */ - { - /* d_tag_name */ "DT_NEEDED", - /* d_tag_value */ DT_NEEDED, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_PLTRELSZ */ - { - /* d_tag_name */ "DT_PLTRELSZ", - /* d_tag_value */ DT_PLTRELSZ, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_PLTGOT */ - { - /* d_tag_name */ "DT_PLTGOT", - /* d_tag_value */ DT_PLTGOT, - /* d_untype */ EDYN_UNTYPE_PTR, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_HASH */ - { - /* d_tag_name */ "DT_HASH", - /* d_tag_value */ DT_HASH, - /* d_untype */ EDYN_UNTYPE_PTR, - /* d_exec_req */ EDYN_TAGREQ_MANDATORY, - /* d_shared_req */ EDYN_TAGREQ_MANDATORY - }, - - /* EDYN_TAG_STRTAB */ - { - /* d_tag_name */ "DT_STRTAB", - /* d_tag_value */ DT_STRTAB, - /* d_untype */ EDYN_UNTYPE_PTR, - /* d_exec_req */ EDYN_TAGREQ_MANDATORY, - /* d_shared_req */ EDYN_TAGREQ_MANDATORY - }, - - /* EDYN_TAG_SYMTAB */ - { - /* d_tag_name */ "DT_SYMTAB", - /* d_tag_value */ DT_SYMTAB, - /* d_untype */ EDYN_UNTYPE_PTR, - /* d_exec_req */ EDYN_TAGREQ_MANDATORY, - /* d_shared_req */ EDYN_TAGREQ_MANDATORY - }, - - /* EDYN_TAG_RELA */ - { - /* d_tag_name */ "DT_RELA", - /* d_tag_value */ DT_RELA, - /* d_untype */ EDYN_UNTYPE_PTR, - /* d_exec_req */ EDYN_TAGREQ_MANDATORY, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_RELASZ */ - { - /* d_tag_name */ "DT_RELASZ", - /* d_tag_value */ DT_RELASZ, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_MANDATORY, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_RELAENT */ - { - /* d_tag_name */ "DT_RELAENT", - /* d_tag_value */ DT_RELAENT, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_MANDATORY, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_STRSZ */ - { - /* d_tag_name */ "DT_STRSZ", - /* d_tag_value */ DT_STRSZ, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_MANDATORY, - /* d_shared_req */ EDYN_TAGREQ_MANDATORY - }, - - /* EDYN_TAG_SYMENT */ - { - /* d_tag_name */ "DT_SYMENT", - /* d_tag_value */ DT_SYMENT, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_MANDATORY, - /* d_shared_req */ EDYN_TAGREQ_MANDATORY - }, - - /* EDYN_TAG_INIT */ - { - /* d_tag_name */ "DT_INIT", - /* d_tag_value */ DT_INIT, - /* d_untype */ EDYN_UNTYPE_PTR, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_FINI */ - { - /* d_tag_name */ "DT_FINI", - /* d_tag_value */ DT_FINI, - /* d_untype */ EDYN_UNTYPE_PTR, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_SONAME */ - { - /* d_tag_name */ "DT_SONAME", - /* d_tag_value */ DT_SONAME, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_IGNORED, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_RPATH */ - { - /* d_tag_name */ "DT_RPATH", - /* d_tag_value */ DT_RPATH, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_IGNORED - }, - - /* EDYN_TAG_SYMBOLIC */ - { - /* d_tag_name */ "DT_SYMBOLIC", - /* d_tag_value */ DT_SYMBOLIC, - /* d_untype */ EDYN_UNTYPE_IGNORED, - /* d_exec_req */ EDYN_TAGREQ_IGNORED, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_REL */ - { - /* d_tag_name */ "DT_REL", - /* d_tag_value */ DT_REL, - /* d_untype */ EDYN_UNTYPE_PTR, - /* d_exec_req */ EDYN_TAGREQ_MANDATORY, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_RELSZ */ - { - /* d_tag_name */ "DT_RELSZ", - /* d_tag_value */ DT_RELSZ, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_MANDATORY, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_RELENT */ - { - /* d_tag_name */ "DT_RELENT", - /* d_tag_value */ DT_RELENT, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_MANDATORY, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_PLTREL */ - { - /* d_tag_name */ "DT_PLTREL", - /* d_tag_value */ DT_PLTREL, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_DEBUG */ - { - /* d_tag_name */ "DT_DEBUG", - /* d_tag_value */ DT_DEBUG, - /* d_untype */ EDYN_UNTYPE_PTR, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_IGNORED - }, - - /* EDYN_TAG_TEXTREL */ - { - /* d_tag_name */ "DT_TEXTREL", - /* d_tag_value */ DT_TEXTREL, - /* d_untype */ EDYN_UNTYPE_IGNORED, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_JMPREL */ - { - /* d_tag_name */ "DT_JMPREL", - /* d_tag_value */ DT_JMPREL, - /* d_untype */ EDYN_UNTYPE_PTR, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_BIND_NOW */ - { - /* d_tag_name */ "DT_BIND_NOW", - /* d_tag_value */ DT_BIND_NOW, - /* d_untype */ EDYN_UNTYPE_IGNORED, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_INIT_ARRAY */ - { - /* d_tag_name */ "DT_INIT_ARRAY", - /* d_tag_value */ DT_INIT_ARRAY, - /* d_untype */ EDYN_UNTYPE_PTR, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_FINI_ARRAY */ - { - /* d_tag_name */ "DT_FINI_ARRAY", - /* d_tag_value */ DT_FINI_ARRAY, - /* d_untype */ EDYN_UNTYPE_PTR, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_INIT_ARRAYSZ */ - { - /* d_tag_name */ "DT_INIT_ARRAYSZ", - /* d_tag_value */ DT_INIT_ARRAYSZ, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_FINI_ARRAYSZ */ - { - /* d_tag_name */ "DT_FINI_ARRAYSZ", - /* d_tag_value */ DT_FINI_ARRAYSZ, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_RUNPATH */ - { - /* d_tag_name */ "DT_RUNPATH", - /* d_tag_value */ DT_RUNPATH, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_FLAGS */ - { - /* d_tag_name */ "DT_FLAGS", - /* d_tag_value */ DT_FLAGS, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_OPTIONAL - }, - - /* EDYN_TAG_ENCODING */ - { - /* d_tag_name */ "DT_ENCODING", - /* d_tag_value */ DT_ENCODING, - /* d_untype */ EDYN_UNTYPE_UNSPECIFIED, - /* d_exec_req */ EDYN_TAGREQ_UNSPECIFIED, - /* d_shared_req */ EDYN_TAGREQ_UNSPECIFIED - }, - - /* EDYN_TAG_PREINIT_ARRAY */ - { - /* d_tag_name */ "DT_PREINIT_ARRAY", - /* d_tag_value */ DT_PREINIT_ARRAY, - /* d_untype */ EDYN_UNTYPE_PTR, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_IGNORED - }, - - /* EDYN_TAG_PREINIT_ARRAYSZ */ - { - /* d_tag_name */ "DT_PREINIT_ARRAYSZ", - /* d_tag_value */ DT_PREINIT_ARRAYSZ, - /* d_untype */ EDYN_UNTYPE_VAL, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_IGNORED - }, - - /* Terminate array with an id of -1 */ - { - /* d_tag_name */ "", - /* d_tag_value */ -1, - /* d_untype */ EDYN_UNTYPE_UNSPECIFIED, - /* d_exec_req */ EDYN_TAGREQ_OPTIONAL, - /* d_shared_req */ EDYN_TAGREQ_IGNORED - } -}; - -/*---------------------------------------------------------------------------*/ -/* Special Section Database */ -/*---------------------------------------------------------------------------*/ -const struct ESCN ESCN_DB[] = -{ - /* .bss */ - { - /* name */ ESCN_BSS_name, - /* sh_type */ SHT_NOBITS, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC + SHF_WRITE - }, - - /* .comment */ - { - /* name */ ESCN_COMMENT_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ 0 - }, - - /* .data */ - { - /* name */ ESCN_DATA_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC + SHF_WRITE - }, - - /* .data1 */ - { - /* name */ ESCN_DATA1_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC + SHF_WRITE - }, - - /* .debug */ - { - /* name */ ESCN_DEBUG_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ 0 - }, - - /* .dynamic */ - { - /* name */ ESCN_DYNAMIC_name, - /* sh_type */ SHT_DYNAMIC, - /* sh_entsize */ sizeof(struct Elf32_Dyn), - /* sh_flags */ SHF_ALLOC - }, - - /* .dynstr */ - { - /* name */ ESCN_DYNSTR_name, - /* sh_type */ SHT_STRTAB, - /* sh_entsize */ sizeof(char), - /* sh_flags */ SHF_ALLOC + SHF_STRINGS - }, - - /* .dynsym */ - { - /* name */ ESCN_DYNSYM_name, - /* sh_type */ SHT_DYNSYM, - /* sh_entsize */ sizeof(struct Elf32_Sym), - /* sh_flags */ SHF_ALLOC - }, - - /* .fini */ - { - /* name */ ESCN_FINI_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC + SHF_EXECINSTR - }, - - /* .fini_array */ - { - /* name */ ESCN_FINI_ARRAY_name, - /* sh_type */ SHT_FINI_ARRAY, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC + SHF_WRITE - }, - - /* .got */ - { - /* name */ ESCN_GOT_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ 0 - }, - - /* .hash */ - { - /* name */ ESCN_HASH_name, - /* sh_type */ SHT_HASH, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC - }, - - /* .init */ - { - /* name */ ESCN_INIT_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC + SHF_EXECINSTR - }, - - /* .init_array */ - { - /* name */ ESCN_INIT_ARRAY_name, - /* sh_type */ SHT_INIT_ARRAY, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC + SHF_WRITE - }, - - /* .interp */ - { - /* name */ ESCN_INTERP_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ 0 - }, - - /* .line */ - { - /* name */ ESCN_LINE_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ 0 - }, - - /* .note */ - { - /* name */ ESCN_NOTE_name, - /* sh_type */ SHT_NOTE, - /* sh_entsize */ 0, - /* sh_flags */ 0 - }, - - /* .plt */ - { - /* name */ ESCN_PLT_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ 0 - }, - - /* .preinit_array */ - { - /* name */ ESCN_PREINIT_ARRAY_name, - /* sh_type */ SHT_PREINIT_ARRAY, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC + SHF_WRITE - }, - - /* .rel */ - { - /* name */ ESCN_REL_name, - /* sh_type */ SHT_REL, - /* sh_entsize */ sizeof(struct Elf32_Rel), - /* sh_flags */ 0 - }, - - /* .rela */ - { - /* name */ ESCN_RELA_name, - /* sh_type */ SHT_RELA, - /* sh_entsize */ sizeof(struct Elf32_Rela), - /* sh_flags */ 0 - }, - - /* .rodata */ - { - /* name */ ESCN_RODATA_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC - }, - - /* .rodata1 */ - { - /* name */ ESCN_RODATA1_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC - }, - - /* .shstrtab */ - { - /* name */ ESCN_SHSTRTAB_name, - /* sh_type */ SHT_STRTAB, - /* sh_entsize */ sizeof(char), - /* sh_flags */ SHF_STRINGS - }, - - /* .strtab */ - { - /* name */ ESCN_STRTAB_name, - /* sh_type */ SHT_STRTAB, - /* sh_entsize */ sizeof(char), - /* sh_flags */ SHF_STRINGS - }, - - /* .symtab */ - { - /* name */ ESCN_SYMTAB_name, - /* sh_type */ SHT_SYMTAB, - /* sh_entsize */ sizeof(struct Elf32_Sym), - /* sh_flags */ 0 - }, - - /* .symtab_shndx */ - { - /* name */ ESCN_SYMTAB_SHNDX_name, - /* sh_type */ SHT_SYMTAB_SHNDX, - /* sh_entsize */ sizeof(Elf32_Word), - /* sh_flags */ 0 - }, - - /* .tbss */ - { - /* name */ ESCN_TBSS_name, - /* sh_type */ SHT_NOBITS, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC + SHF_WRITE + SHF_TLS - }, - - /* .tdata */ - { - /* name */ ESCN_TDATA_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC + SHF_WRITE + SHF_TLS - }, - - /* .tdata1 */ - { - /* name */ ESCN_TDATA1_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC + SHF_WRITE + SHF_TLS - }, - - /* .text */ - { - /* name */ ESCN_TEXT_name, - /* sh_type */ SHT_PROGBITS, - /* sh_entsize */ 0, - /* sh_flags */ SHF_ALLOC + SHF_EXECINSTR - }, -#if 0 - /* .build.attributes */ - { - /* name */ ESCN_ATTRIBUTES_name, - /* sh_type */ SHT_ATTRIBUTES, - /* sh_entsize */ 0, - /* sh_flags */ 0 - }, -#endif - /* Terminate array with a NULL name field */ - { - /* name */ (const char*)0, - /* sh_type */ 0, - /* sh_entsize */ 0, - /* sh_flags */ 0 - } -}; diff --git a/src/utils/elfload/genbase.c b/src/utils/elfload/genbase.c deleted file mode 100644 index c791d00..0000000 --- a/src/utils/elfload/genbase.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2011, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -#include - - -/* global for simple access in dlw_client.c */ -FILE * out_file; - -#define MAXTAGS 128 -unsigned int tag_addr[MAXTAGS]; -char *tag_name[MAXTAGS]; -int num_tags; - -int main(int argc, char * argv[]) -{ - DLOAD_HANDLE loader; - FILE * in_file; - int i, j, k; - - if (argc < 3) { - fprintf(stderr, "Usage: %s input-file output-file\n", argv[0]); - exit(1); - } - - if ((in_file = fopen(argv[1], "rb")) == NULL) { - fprintf(stderr, "%s: could not open file %s for reading\n", argv[0], - argv[1]); - exit(2); - } - - if ((out_file = fopen(argv[2], "w+b")) == NULL) { - fprintf(stderr, "%s: could not open file %s for writing\n", argv[0], - argv[2]); - exit(3); - } - - num_tags = 0; - - for (j = 0, i = 3; i < argc; i++, j++) { - num_tags++; - k = 0; - tag_name[j] = argv[i]; - while (argv[i][k] != ':') { - k++; - } - argv[i][k] = '\0'; - tag_addr[j] = strtoll(&argv[i][k+1], NULL, 16); - printf("found tag %d: name '%s' addr 0x%x\n", j, tag_name[j], - tag_addr[j]); - } - - loader = DLOAD_create(NULL); - DLOAD_load(loader, in_file, 0, NULL); - DLOAD_destroy(loader); - - fclose(out_file); - fclose(in_file); - - return 0; -} diff --git a/src/utils/elfload/include/ArrayList.h b/src/utils/elfload/include/ArrayList.h deleted file mode 100644 index 215e699..0000000 --- a/src/utils/elfload/include/ArrayList.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/**********************************************************************/ -/* ArrayList.h */ -/* */ -/* This implementation of ArrayList is a replacement for the C++ */ -/* vector class in C. */ -/* */ -/* This class emulates a resizable array along the lines of a C++ */ -/* vector or Java ArrayList class in C, and uses the convention */ -/* of passing a pointer to the current "object" as the first */ -/* argument. */ -/* */ -/* Usage is defined as follows: */ -/* */ -/* Array_List obj; */ -/* AL_initialize(&obj, sizeof(type_name)); */ -/* */ -/* ... */ -/* */ -/* type_name *ptr = (type_name*)(obj.buf); */ -/* for(i=0; i - -/**********************************************************************/ -/* Array_List - structure type specification. */ -/**********************************************************************/ -typedef struct -{ - void *buf; - int32_t type_size; - int32_t size; - int32_t buffer_size; -} Array_List; - -/*--------------------------------------------------------------------*/ -/* Array_List Member Functions: */ -/* */ -/* AL_initialize() - Initialize a newly created Array_List object. */ -/* AL_append() - Append an element to the end of an Array_List. */ -/* AL_size() - Get number of elements in an Array_List. */ -/* AL_destroy() - Free memory associated with an Array_List that is */ -/* no longer in use. */ -/*--------------------------------------------------------------------*/ -void AL_initialize(Array_List* obj, int32_t type_size, int32_t num_elem); -void AL_append(Array_List* obj, void* to_append); -int32_t AL_size(Array_List* obj); -void AL_destroy(Array_List* obj); - -#endif diff --git a/src/utils/elfload/include/Queue.h b/src/utils/elfload/include/Queue.h deleted file mode 100644 index 5e70742..0000000 --- a/src/utils/elfload/include/Queue.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* Queue.h */ -/* */ -/* Interface to Linked List */ -/* */ -/* This is an implementation of a type-independent linked list class for C. */ -/* It's basically a template class, but uses macros instead so that it can */ -/* be compiled with a C-only compiler. */ -/* */ -/* To define a linked list class: */ -/* #include "Queue.h" */ -/* TYPE_QUEUE_DEFINITION(object_type,Class_Identifier) */ -/* */ -/* In a separate C file: */ -/* #include "Queue.h" */ -/* TYPE_QUEUE_DEFINITION(object_type,Class_Identifier) */ -/* TYPE_QUEUE_IMPLEMENTATION(object_type,Class_Identifier */ -/* */ -/* Now, to create a list: */ -/* Class_Identifier_Queue name; */ -/* Get it initialized to zero everywhere somehow, maybe like this: */ -/* Class_Identifier_initialize_queue(&name); */ -/* */ -/* To add to the list: */ -/* Class_Identifier_enqueue(&name, object); */ -/* */ -/* To iterate over the list: */ -/* Class_Identifier_Queue_Node* it = name.front; */ -/* while(it) { do_something_to_(it->value); it=it->next; } */ -/* */ -/* To delete from the list: */ -/* If it's the first node: */ -/* Class_Identifier_dequeue(&name); */ -/* If it's not: */ -/* predecessor_node->next_ptr = deleted_node->next_ptr; */ -/* name.size--; */ -/*****************************************************************************/ -#ifndef QUEUE_H -#define QUEUE_H - -#include -#include "dload_api.h" - -/*****************************************************************************/ -/* TYPE_QUEUE_DEFINITION() - Define structure specifications for a linked */ -/* list of t_name objects. */ -/*****************************************************************************/ -#define TYPE_QUEUE_DEFINITION(t, t_name) \ -struct t_name##_Queue_Node_ \ -{ \ - t value; \ - struct t_name##_Queue_Node_* next_ptr; \ -}; \ -typedef struct t_name##_Queue_Node_ t_name##_Queue_Node; \ - \ -typedef struct \ -{ \ - t_name##_Queue_Node* front_ptr; \ - t_name##_Queue_Node* back_ptr; \ - int32_t size; \ -} t_name##_Queue; \ - \ -extern void t_name##_initialize_queue(t_name##_Queue* queue); \ -extern void t_name##_enqueue(t_name##_Queue* queue, t to_enqueue); \ -extern t t_name##_dequeue(t_name##_Queue* queue); \ -extern void t_name##_remove(t_name##_Queue* queue, t to_remove); - - -/*****************************************************************************/ -/* TYPE_QUEUE_IMPLEMENTATION() - Define member functions of new linked list */ -/* "class" of t_name objects. */ -/* */ -/* _initialize_queue() - clears the queue */ -/* _enqueue() - adds a type object to the end of the queue */ -/* _dequeue() - remove a type object from the front of the queue */ -/* and provide access to it to the caller */ -/* _remove() - find and remove a type object from the queue */ -/*****************************************************************************/ -#define TYPE_QUEUE_IMPLEMENTATION(t, t_name) \ -void t_name##_initialize_queue (t_name##_Queue* queue) \ -{ \ - queue->front_ptr = queue->back_ptr = NULL; \ - queue->size = 0; \ -} \ -void t_name##_enqueue(t_name##_Queue* queue, t to_enqueue) \ -{ \ - queue->size++; \ - \ - if(!queue->back_ptr) \ - queue->back_ptr = queue->front_ptr = \ - (t_name##_Queue_Node*) \ - (DLIF_malloc(sizeof(t_name##_Queue_Node))); \ - else \ - { \ - queue->back_ptr->next_ptr = \ - (t_name##_Queue_Node*)(DLIF_malloc( \ - sizeof(t_name##_Queue_Node))); \ - queue->back_ptr = queue->back_ptr->next_ptr; \ - } \ - \ - if (NULL != queue->back_ptr) { \ - queue->back_ptr->value = to_enqueue; \ - queue->back_ptr->next_ptr = NULL; \ - } \ -} \ - \ -t t_name##_dequeue(t_name##_Queue* queue) \ -{ \ - t to_ret; \ - t_name##_Queue_Node* next_ptr = NULL; \ - \ - if (!queue->size) return ((t)(NULL)); \ - \ - next_ptr = queue->front_ptr->next_ptr; \ - queue->size--; \ - to_ret = queue->front_ptr->value; \ - DLIF_free((void*)(queue->front_ptr)); \ - \ - if(!queue->size) \ - queue->front_ptr = queue->back_ptr = NULL; \ - else \ - queue->front_ptr = next_ptr; \ - \ - return to_ret; \ -} \ - \ -void t_name##_remove(t_name##_Queue* queue, t to_remove) \ -{ \ - t_name##_Queue_Node* prev_ptr = NULL; \ - t_name##_Queue_Node* curr_ptr = queue->front_ptr; \ - t_name##_Queue_Node* next_ptr = NULL; \ - \ - for (; curr_ptr; curr_ptr = next_ptr) \ - { \ - next_ptr = curr_ptr->next_ptr; \ - if (curr_ptr->value == to_remove) break; \ - prev_ptr = curr_ptr; \ - } \ - \ - if (curr_ptr) \ - { \ - if (prev_ptr) prev_ptr->next_ptr = next_ptr; \ - queue->size--; \ - DLIF_free((void*)(curr_ptr)); \ - } \ - \ - if (!queue->size) \ - queue->front_ptr = queue->back_ptr = NULL; \ - else \ - { \ - if (!prev_ptr) queue->front_ptr = next_ptr; \ - if (!next_ptr) queue->back_ptr = prev_ptr; \ - } \ -} - - -#endif diff --git a/src/utils/elfload/include/Stack.h b/src/utils/elfload/include/Stack.h deleted file mode 100644 index b2ced25..0000000 --- a/src/utils/elfload/include/Stack.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* Stack.h */ -/* */ -/* Interface to Stack */ -/* */ -/* This is an implementation of a type-independent stack implemented as */ -/* a signly linked list class for C. It's basically a template class, but */ -/* uses macros instead so that it can be compiled with a C-only compiler. */ -/* */ -/* To define a Stack class: */ -/* #include "Stack.h" */ -/* TYPE_STACK_DEFINITION(object_type,Class_Identifier) */ -/* */ -/* In a separate C file: */ -/* #include "Stack.h" */ -/* TYPE_STACK_DEFINITION(object_type,Class_Identifier) */ -/* TYPE_STACK_IMPLEMENTATION(object_type,Class_Identifier */ -/* */ -/* Now, to create a stack: */ -/* struct Class_Identifier_Stack name; */ -/* Get it initialized to zero everywhere somehow, maybe like this: */ -/* initialize_stack_Class_Identifier(&name); */ -/* */ -/* To add to the stack: */ -/* push_Class_Identifier(&name, object); */ -/* */ -/* To access the top of the stack: */ -/* Class_Identifier_Stack_Node* tos = name.top_ptr; */ -/* do_something_to_(tos->value); */ -/* */ -/* To delete from the stack: */ -/* if (name.size > 0) pop_Class_Identifier(&name); */ -/* */ -/*****************************************************************************/ -#ifndef STACK_H -#define STACK_H - -#include -#include "dload_api.h" - -/*****************************************************************************/ -/* TYPE_STACK_DEFINITION() - Define structure specifications for a last-in, */ -/* first-out linked list of t_name objects. */ -/*****************************************************************************/ -#define TYPE_STACK_DEFINITION(t, t_name) \ -struct t_name##_Stack_Node_ \ -{ \ - t value; \ - struct t_name##_Stack_Node_* next_ptr; \ -}; \ -typedef struct t_name##_Stack_Node_ t_name##_Stack_Node; \ - \ -typedef struct \ -{ \ - t_name##_Stack_Node* top_ptr; \ - t_name##_Stack_Node* bottom_ptr; \ - int size; \ -} t_name##_Stack; \ - \ -extern void t_name##_initialize_stack(t_name##_Stack* stack); \ -extern void t_name##_push(t_name##_Stack* stack, t to_push); \ -extern t t_name##_pop(t_name##_Stack* stack); - -/*****************************************************************************/ -/* TYPE_STACK_IMPLEMENTATION() - Define member functions of new LIFO linked */ -/* list "class" of t_name objects. */ -/* */ -/* _initialize_stack() - clears the stack */ -/* _push() - pushes a type object to the top of the stack */ -/* _pop() - pop a type object from the top of the stack */ -/* and provide access to it to the caller */ -/*****************************************************************************/ -#define TYPE_STACK_IMPLEMENTATION(t, t_name) \ -void t_name##_initialize_stack (t_name##_Stack* stack) \ -{ \ - stack->top_ptr = stack->bottom_ptr = NULL; \ - stack->size = 0; \ -} \ -void t_name##_push(t_name##_Stack* stack, t to_push) \ -{ \ - stack->size++; \ - \ - if(!stack->top_ptr) \ - { \ - stack->bottom_ptr = stack->top_ptr = \ - (t_name##_Stack_Node*)(DLIF_malloc(sizeof(t_name##_Stack_Node))); \ - if (NULL == stack->top_ptr) \ - return; \ - stack->top_ptr->next_ptr = NULL; \ - } \ - else \ - { \ - t_name##_Stack_Node* next_ptr = stack->top_ptr; \ - stack->top_ptr = \ - (t_name##_Stack_Node*)(DLIF_malloc(sizeof(t_name##_Stack_Node))); \ - if (NULL == stack->top_ptr) \ - return; \ - stack->top_ptr->next_ptr = next_ptr; \ - } \ - \ - stack->top_ptr->value = to_push; \ -} \ - \ -t t_name##_pop(t_name##_Stack* stack) \ -{ \ - t to_ret; \ - t_name##_Stack_Node* next_ptr = stack->top_ptr->next_ptr; \ - \ - stack->size--; \ - to_ret = stack->top_ptr->value; \ - DLIF_free((void*)(stack->top_ptr)); \ - \ - if(!stack->size) \ - stack->top_ptr = stack->bottom_ptr = NULL; \ - else \ - stack->top_ptr = next_ptr; \ - \ - return to_ret; \ -} - -#endif diff --git a/src/utils/elfload/include/Std.h b/src/utils/elfload/include/Std.h deleted file mode 100644 index c5ca784..0000000 --- a/src/utils/elfload/include/Std.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/** ============================================================================ - * @file Std.h - * - * @brief This will have definitions of standard data types for - * platform abstraction. - * - * ============================================================================ - */ - -#if !defined(STD_H) -#define STD_H - -#ifdef SYSLINK_BUILDOS_LINUX -#include -#endif -#include -#include - -#if defined (__cplusplus) -extern "C" { -#endif - -typedef char Char; -typedef unsigned char UChar; -typedef short Short; -typedef unsigned short UShort; -typedef int Int; -typedef unsigned int UInt; -typedef long Long; -typedef unsigned long ULong; -typedef float Float; -typedef double Double; -typedef long double LDouble; -typedef void Void; - - -typedef bool Bool; -typedef void * Ptr; /* data pointer */ -typedef void * Handle; /* data pointer */ -typedef char * String; /* null terminated string */ - - -typedef int * IArg; -typedef unsigned int * UArg; -typedef char Int8; -typedef short Int16; -typedef int Int32; - -typedef unsigned char UInt8; -typedef unsigned short UInt16; -typedef unsigned int UInt32; -typedef unsigned int SizeT; -typedef unsigned char Bits8; -typedef unsigned short Bits16; -typedef UInt32 Bits32; - -/* taken from bridge */ -typedef void *PVOID; /* p */ -typedef PVOID HANDLE; /* h */ - -#define TRUE 1 -#define FALSE 0 -#define FAIL -1 -//#define NULL '\0' - -#if defined (__cplusplus) -} -#endif - -#endif diff --git a/src/utils/elfload/include/arm_dynamic.h b/src/utils/elfload/include/arm_dynamic.h deleted file mode 100644 index be14217..0000000 --- a/src/utils/elfload/include/arm_dynamic.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* arm_dynamic.h */ -/* */ -/* Interface into ARM specific dynamic loader functionality. */ -/*****************************************************************************/ -#ifndef DLOAD_ARM_H -#define DLOAD_ARM_H - -#include "dload.h" - -BOOL DLDYN_arm_process_dynamic_tag(DLIMP_Dynamic_Module* dyn_module, int i); -BOOL DLDYN_arm_relocate_dynamic_tag_info(DLIMP_Dynamic_Module *dyn_module, - int32_t i); -BOOL DLDYN_arm_process_eiosabi(DLIMP_Dynamic_Module* dyn_module); - -#endif diff --git a/src/utils/elfload/include/arm_elf32.h b/src/utils/elfload/include/arm_elf32.h deleted file mode 100644 index da2890b..0000000 --- a/src/utils/elfload/include/arm_elf32.h +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* arm_elf32.h */ -/* */ -/* ARM-Specific Data Structures for 32-bit ELF Object Files. */ -/* */ -/* The data structures in this file come primarily from this specification: */ -/* */ -/* ELF for the ARM Architecture (AAELF) */ -/* Document Number: ARM IHI 0044C, current through ABI release 2.07 */ -/* Date of Issue : 10th October, 2008 */ -/*****************************************************************************/ -#ifndef ARM_ELF32_H -#define ARM_ELF32_H - -#include "elf32.h" - -/*---------------------------------------------------------------------------*/ -/* ARM-specific e_flags */ -/*---------------------------------------------------------------------------*/ -enum -{ - EF_ARM_EABIMASK = 0xFF000000, - EF_ARM_BE8 = 0x00800000 -}; - -/*---------------------------------------------------------------------------*/ -/* ARM-specific EI_OSABI values */ -/*---------------------------------------------------------------------------*/ -enum -{ - ELFOSABI_ARM_AEABI = 64 /* ARM AEABI with symbol versioning */ -}; - -/*---------------------------------------------------------------------------*/ -/* ARM-specific section types */ -/*---------------------------------------------------------------------------*/ -enum -{ - SHT_ARM_EXIDX = 0x70000001, - SHT_ARM_PREEMPTMAP = 0x70000002, - SHT_ARM_ATTRIBUTES = 0x70000003, - SHT_ARM_DEBUGOVERLAY = 0x70000004, - SHT_ARM_OVERLAYSECTION = 0x70000005 -}; - -/*---------------------------------------------------------------------------*/ -/* ARM-specific segment types */ -/*---------------------------------------------------------------------------*/ -enum -{ - PT_ARM_ARCHEXT = 0x70000000, - PT_ARM_EXIDX = 0x70000001 -}; - -/*---------------------------------------------------------------------------*/ -/* Common architecture compatibility information */ -/*---------------------------------------------------------------------------*/ -enum -{ - PT_ARM_ARCHEXT_FMTMSK =0xFF000000, - PT_ARM_ARCHEXT_PROFMASK = 0x00FF0000, - PT_ARM_ARCHEXT_ARCHMSK = 0x000000FF -}; - -/*---------------------------------------------------------------------------*/ -/* Architecture compatibility formats */ -/*---------------------------------------------------------------------------*/ -enum -{ - PT_ARM_ARCHEXT_FMT_OS = 0x0 -}; - -/*---------------------------------------------------------------------------*/ -/* Architecture profile compatibility */ -/*---------------------------------------------------------------------------*/ -enum -{ - PT_ARM_ARCHEXT_PROF_NONE = 0x0, - PT_ARM_ARCHEXT_PROF_ARM = 0x00410000, - PT_ARM_ARCHEXT_PROF_RT = 0x00520000, - PT_ARM_ARCHEXT_PROF_MC = 0x004D0000 -}; - -/*---------------------------------------------------------------------------*/ -/* Architecture compatibility */ -/*---------------------------------------------------------------------------*/ -enum -{ - PT_ARM_ARCHEXT_ARCH_UNKN = 0x0, - PT_ARM_ARCHEXT_ARCHv4 = 0x1, - PT_ARM_ARCHEXT_ARCHv4T = 0x2, - PT_ARM_ARCHEXT_ARCHv5T = 0x3, - PT_ARM_ARCHEXT_ARCHv5TE = 0x4, - PT_ARM_ARCHEXT_ARCHv5TEJ = 0x5, - PT_ARM_ARCHEXT_ARCHv6 = 0x6, - PT_ARM_ARCHEXT_ARCHv6KZ = 0x7, - PT_ARM_ARCHEXT_ARCHv6T2 = 0x8, - PT_ARM_ARCHEXT_ARCHv6K = 0x9, - PT_ARM_ARCHEXT_ARCHv7 = 0xA -}; - - -/*---------------------------------------------------------------------------*/ -/* ARM-specific dynamic array tags */ -/*---------------------------------------------------------------------------*/ -enum -{ - DT_ARM_RESERVED1 = 0x70000000, - DT_ARM_SYMTABSZ = 0x70000001, - DT_ARM_PREEMPTMAP = 0x70000002, - DT_ARM_RESERVED2 = 0x70000003 -}; - -/*---------------------------------------------------------------------------*/ -/* ARM Relocation Types */ -/*---------------------------------------------------------------------------*/ -typedef enum -{ - R_ARM_NONE = 0, - R_ARM_PC24 = 1, - R_ARM_ABS32 = 2, - R_ARM_REL32 = 3, - R_ARM_LDR_PC_G0 = 4, - R_ARM_ABS16 = 5, - R_ARM_ABS12 = 6, - R_ARM_THM_ABS5 = 7, - R_ARM_ABS8 = 8, - R_ARM_SBREL32 = 9, - R_ARM_THM_CALL = 10, - R_ARM_THM_PC8 = 11, - R_ARM_BREL_ADJ = 12, - R_ARM_SWI24 = 13, - R_ARM_THM_SWI8 = 14, - R_ARM_XPC25 = 15, - R_ARM_THM_XPC22 = 16, - R_ARM_TLS_DTPMOD32 = 17, - R_ARM_TLS_DTPOFF32 = 18, - R_ARM_TLS_TPOFF32 = 19, - R_ARM_COPY = 20, - R_ARM_GLOB_DAT = 21, - R_ARM_JUMP_SLOT = 22, - R_ARM_RELATIVE = 23, - R_ARM_GOTOFF32 = 24, - R_ARM_BASE_PREL = 25, - R_ARM_GOT_BREL = 26, - R_ARM_PLT32 = 27, - R_ARM_CALL = 28, - R_ARM_JUMP24 = 29, - R_ARM_THM_JUMP24 = 30, - R_ARM_BASE_ABS = 31, - R_ARM_ALU_PCREL_7_0 = 32, - R_ARM_ALU_PCREL_15_8 = 33, - R_ARM_ALU_PCREL_23_15 = 34, - R_ARM_LDR_SBREL_11_0_NC = 35, - R_ARM_ALU_SBREL_19_12_NC = 36, - R_ARM_ALU_SBREL_27_20_CK = 37, - R_ARM_TARGET1 = 38, - R_ARM_SBREL31 = 39, - R_ARM_V4BX = 40, - R_ARM_TARGET2 = 41, - R_ARM_PREL31 = 42, - R_ARM_MOVW_ABS_NC = 43, - R_ARM_MOVT_ABS = 44, - R_ARM_MOVW_PREL_NC = 45, - R_ARM_MOVT_PREL = 46, - R_ARM_THM_MOVW_ABS_NC = 47, - R_ARM_THM_MOVT_ABS = 48, - R_ARM_THM_MOVW_PREL_NC = 49, - R_ARM_THM_MOVT_PREL = 50, - R_ARM_THM_JUMP19 = 51, - R_ARM_THM_JUMP6 = 52, - R_ARM_THM_ALU_PREL_11_0 = 53, - R_ARM_THM_PC12 = 54, - R_ARM_ABS32_NOI = 55, - R_ARM_REL32_NOI = 56, - R_ARM_ALU_PC_G0_NC = 57, - R_ARM_ALU_PC_G0 = 58, - R_ARM_ALU_PC_G1_NC = 59, - R_ARM_ALU_PC_G1 = 60, - R_ARM_ALU_PC_G2 = 61, - R_ARM_LDR_PC_G1 = 62, - R_ARM_LDR_PC_G2 = 63, - R_ARM_LDRS_PC_G0 = 64, - R_ARM_LDRS_PC_G1 = 65, - R_ARM_LDRS_PC_G2 = 66, - R_ARM_LDC_PC_G0 = 67, - R_ARM_LDC_PC_G1 = 68, - R_ARM_LDC_PC_G2 = 69, - R_ARM_ALU_SB_G0_NC = 70, - R_ARM_ALU_SB_G0 = 71, - R_ARM_ALU_SB_G1_NC = 72, - R_ARM_ALU_SB_G1 = 73, - R_ARM_ALU_SB_G2 = 74, - R_ARM_LDR_SB_G0 = 75, - R_ARM_LDR_SB_G1 = 76, - R_ARM_LDR_SB_G2 = 77, - R_ARM_LDRS_SB_G0 = 78, - R_ARM_LDRS_SB_G1 = 79, - R_ARM_LDRS_SB_G2 = 80, - R_ARM_LDC_SB_G0 = 81, - R_ARM_LDC_SB_G1 = 82, - R_ARM_LDC_SB_G2 = 83, - R_ARM_MOVW_BREL_NC = 84, - R_ARM_MOVT_BREL = 85, - R_ARM_MOVW_BREL = 86, - R_ARM_THM_MOVW_BREL_NC = 87, - R_ARM_THM_MOVT_BREL = 88, - R_ARM_THM_MOVW_BREL = 89, - R_ARM_PLT32_ABS = 94, - R_ARM_GOT_ABS = 95, - R_ARM_GOT_PREL = 96, - R_ARM_GOT_BREL12 = 97, - R_ARM_GOTOFF12 = 98, - R_ARM_GOTRELAX = 99, - R_ARM_GNU_VTENTRY = 100, - R_ARM_GNU_VTINHERIT = 101, - R_ARM_THM_JUMP11 = 102, - R_ARM_THM_JUMP8 = 103, - R_ARM_TLS_GD32 = 104, - R_ARM_TLS_LDM32 = 105, - R_ARM_TLS_LDO32 = 106, - R_ARM_TLS_IE32 = 107, - R_ARM_TLS_LE32 = 108, - R_ARM_TLS_LDO12 = 109, - R_ARM_TLS_LE12 = 110, - R_ARM_TLS_IE12GP = 111, - R_ARM_PRIVATE_0 = 112, - R_ARM_PRIVATE_1 = 113, - R_ARM_PRIVATE_2 = 114, - R_ARM_PRIVATE_3 = 115, - R_ARM_PRIVATE_4 = 116, - R_ARM_PRIVATE_5 = 117, - R_ARM_PRIVATE_6 = 118, - R_ARM_PRIVATE_7 = 119, - R_ARM_PRIVATE_8 = 120, - R_ARM_PRIVATE_9 = 121, - R_ARM_PRIVATE_10 = 122, - R_ARM_PRIVATE_11 = 123, - R_ARM_PRIVATE_12 = 124, - R_ARM_PRIVATE_13 = 125, - R_ARM_PRIVATE_14 = 126, - R_ARM_PRIVATE_15 = 127, - R_ARM_ME_TOO = 128, - R_ARM_THM_TLS_DESCSEQ16 = 129, - R_ARM_THM_TLS_DESCSEQ32 = 130 -}ARM_RELOC_TYPE; - -#endif /* ARM_ELF32_H */ diff --git a/src/utils/elfload/include/c60_dynamic.h b/src/utils/elfload/include/c60_dynamic.h deleted file mode 100644 index fe068ff..0000000 --- a/src/utils/elfload/include/c60_dynamic.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * c60_dynamic.h - * - * Interface into C6x-specific dynamic loader functionality - * - * Copyright (C) 2009 Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef DLOAD_C60_H -#define DLOAD_C60_H - -#include "dload.h" - -BOOL DLDYN_c60_process_dynamic_tag(DLIMP_Dynamic_Module* dyn_module, int i); -BOOL DLDYN_c60_process_eiosabi(DLIMP_Dynamic_Module* dyn_module); -BOOL DLDYN_c60_relocate_dynamic_tag_info(DLIMP_Dynamic_Module *dyn_module, - int32_t i); - -#endif diff --git a/src/utils/elfload/include/c60_elf32.h b/src/utils/elfload/include/c60_elf32.h deleted file mode 100644 index 62f7175..0000000 --- a/src/utils/elfload/include/c60_elf32.h +++ /dev/null @@ -1,159 +0,0 @@ -/* - * c60_elf32.h - * - * C6x-specific data structures for 32-bit ELF object format files. - * - * Copyright (C) 2009 Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef C60_ELF32_H -#define C60_ELF32_H - -#include "elf32.h" - -/*---------------------------------------------------------------------------*/ -/* C6x specific EI_OSABI values */ -/*---------------------------------------------------------------------------*/ -enum -{ - ELFOSABI_C6000_ELFABI = 64, /* C6X Baremetal OSABI */ - ELFOSABI_C6000_LINUX = 65 /* C6X Linux OSABI */ -}; - -/*---------------------------------------------------------------------------*/ -/* File Header Flags (value of "e_flags") */ -/*---------------------------------------------------------------------------*/ -enum -{ - EF_C6000_REL = 0x01 /* Contains static relocations. A ET_EXEC or */ - /* ET_DYN file w/ this flag set can be */ - /* treated as ET_REL during static linking. */ -}; - -/*---------------------------------------------------------------------------*/ -/* Segment Types (value of "p_type") */ -/*---------------------------------------------------------------------------*/ -enum -{ - PT_C6000_PHATTRS = 0x70000000 /* Extended Program Header Attributes*/ -}; - -/*---------------------------------------------------------------------------*/ -/* C6x specific section types */ -/*---------------------------------------------------------------------------*/ -enum -{ - - /*------------------------------------------------------------------------*/ - /* Section types defined by the C6x ELFABI. */ - /* Note: ABI defined section type should be named SHT_C6000_xxx */ - /*------------------------------------------------------------------------*/ - SHT_C6000_UNWIND = 0x70000001, /* Exception Index Table */ - SHT_C6000_PREEMPTMAP = 0x70000002, /* Pre-emption Map */ - - SHT_C6000_ATTRIBUTES = 0x70000003, /* Obj File Compatability Attributes */ - - /*------------------------------------------------------------------------*/ - /* The following section types are not part of C6x ABI. As per the ABI, */ - /* the processor specific values not defined in the ABI are reserved for */ - /* future use. Here we reserve the range 0x7F000000 through 0x7FFFFFFFF */ - /* for the TI specific processor section types. */ - /* Note: TI specific section type should be named SHT_TI_xxx */ - /*------------------------------------------------------------------------*/ - SHT_TI_ICODE = 0x7F000000, /* ICODE representation */ - SHT_TI_XREF = 0x7F000001, /* Symbol cross reference */ - SHT_TI_HANDLER = 0x7F000002, /* Handler function table */ - SHT_TI_INITINFO = 0x7F000003, /* Info for C auto-init of variables */ - SHT_TI_PHATTRS = 0x7F000004 /* Extended Program Header Attributes*/ -}; - -/*****************************************************************************/ -/* C6x-Specific Dynamic Array Tags (C6x ELF ABI Section ??? - AEGUPD) */ -/* NOTE: */ -/* As per GABI a tag whose value is even number indicates a dynamic tag */ -/* that uses d_ptr. Odd number indicates the use of d_val or doesn't use */ -/* neither d_val nor d_ptr. */ -/*****************************************************************************/ -enum -{ - /*------------------------------------------------------------------------*/ - /* OSABI specific tags: */ - /* From 0x6000000D thru 0x6FFFF000 */ - /*------------------------------------------------------------------------*/ - DT_C6000_GSYM_OFFSET = 0x6000000D, /* d_val -- OSABI Specific -- */ - DT_C6000_GSTR_OFFSET = 0x6000000F, /* d_val -- OSABI Specific -- */ - - /*------------------------------------------------------------------------*/ - /* Processor specific tags: */ - /* From 0x70000000 thru 0x7FFFFFFF */ - /*------------------------------------------------------------------------*/ - DT_C6000_DSBT_BASE = 0x70000000, /* d_ptr -- Platform Specific -- */ - DT_C6000_DSBT_SIZE = 0x70000001, /* d_val -- Platform Specific -- */ - DT_C6000_PREEMPTMAP = 0x70000002, /* d_ptr -- Platform Specific -- */ - DT_C6000_DSBT_INDEX = 0x70000003 /* d_val -- Platform Specific -- */ -}; - -/*---------------------------------------------------------------------------*/ -/* C6x Dynamic Relocation Types */ -/*---------------------------------------------------------------------------*/ -typedef enum -{ - R_C6000_NONE = 0, - R_C6000_ABS32 = 1, - R_C6000_ABS16 = 2, - R_C6000_ABS8 = 3, - R_C6000_PCR_S21 = 4, - R_C6000_PCR_S12 = 5, - R_C6000_PCR_S10 = 6, - R_C6000_PCR_S7 = 7, - R_C6000_ABS_S16 = 8, - R_C6000_ABS_L16 = 9, - R_C6000_ABS_H16 = 10, - R_C6000_SBR_U15_B = 11, - R_C6000_SBR_U15_H = 12, - R_C6000_SBR_U15_W = 13, - R_C6000_SBR_S16 = 14, - R_C6000_SBR_L16_B = 15, - R_C6000_SBR_L16_H = 16, - R_C6000_SBR_L16_W = 17, - R_C6000_SBR_H16_B = 18, - R_C6000_SBR_H16_H = 19, - R_C6000_SBR_H16_W = 20, - R_C6000_SBR_GOT_U15_W = 21, - R_C6000_SBR_GOT_L16_W = 22, - R_C6000_SBR_GOT_H16_W = 23, - R_C6000_DSBT_INDEX = 24, - R_C6000_PREL31 = 25, - R_C6000_COPY = 26 -}C60_RELOC_TYPE; - -#endif /* C60_ELF32_H */ diff --git a/src/utils/elfload/include/dload.h b/src/utils/elfload/include/dload.h deleted file mode 100644 index 8cea14a..0000000 --- a/src/utils/elfload/include/dload.h +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* dload.h */ -/* */ -/* Define internal data structures used by core dynamic loader. */ -/*****************************************************************************/ -#ifndef DLOAD_H -#define DLOAD_H - -#include "ArrayList.h" -#include "Queue.h" -#include "Stack.h" -#include "elf32.h" -#include "dload_api.h" -#include "util.h" -#include "Std.h" - - -/*---------------------------------------------------------------------------*/ -/* DLIMP_Loaded_Segment */ -/* */ -/* This structure represents a segment loaded on memory. */ -/* */ -/* This data structure should be created using host memory when a module */ -/* is being loaded into target memory. The data structure should persist */ -/* as long as the module stays resident in target memory. It should be */ -/* removed when the last use of the module is unloaded from the target. */ -/*---------------------------------------------------------------------------*/ -typedef struct -{ - struct Elf32_Phdr phdr; - Elf32_Addr input_vaddr; /* original segment load addr */ - BOOL modified; - int32_t reloc_offset; /* used by load_program */ - struct DLOAD_MEMORY_SEGMENT *obj_desc; -} DLIMP_Loaded_Segment; - -/*---------------------------------------------------------------------------*/ -/* DLIMP_Loaded_Module */ -/* */ -/* This structure contains all the information the dynamic loader needs */ -/* to retain after loading an object file's segments into target memory. */ -/* The data structure is created while the object file is being loaded, */ -/* and should persist until the last use of the module is unloaded from */ -/* target memory. */ -/* */ -/* The information contained here is used by the dynamic loader to */ -/* perform dynamic symbol resolution, to track the use count, and to */ -/* finally deallocate the module's segments when the module is unloaded. */ -/*---------------------------------------------------------------------------*/ -typedef struct -{ - char *name; /* Local copy of so_name */ - int32_t file_handle; - int32_t use_count; - Elf32_Addr entry_point; /* Entry point address into module */ - struct Elf32_Sym *gsymtab; /* Module's global symbol table */ - Elf32_Word gsymnum; /* # global symbols */ - char *gstrtab; /* Module's global symbol names */ - Elf32_Word gstrsz; /* Size of global string table */ - Array_List loaded_segments; /* List of DLIMP_Loaded_Segment(s) */ - Array_List dependencies; /* List of dependent file handles */ - BOOL direct_dependent_only; - - Elf32_Addr fini; /* .fini function/section address */ - Elf32_Addr fini_array; /* .fini_array term fcn ary addr */ - int32_t fini_arraysz; /* sizeof .fini_array */ - -} DLIMP_Loaded_Module; - -/*---------------------------------------------------------------------------*/ -/* DLIMP_loaded_objects */ -/* */ -/* A list of loaded module objects (DLIMP_Loaded_Module *) that the */ -/* loader has placed into target memory. */ -/*---------------------------------------------------------------------------*/ -TYPE_QUEUE_DEFINITION(DLIMP_Loaded_Module*, loaded_module_ptr) - -/*---------------------------------------------------------------------------*/ -/* DLIMP_Dynamic_Module */ -/* */ -/* This structure represents a dynamic module to be loaded by the dynamic */ -/* loader. It contains all the information necessary to load and relocate */ -/* the module. It actually contains most of the headers, dynamic info, */ -/* dynamic symbol table, string table etc. */ -/* */ -/* This structure is allocated in host memory while an ELF object file is */ -/* being loaded and will be destructed after the file has been */ -/* successfully loaded. To simplify loading and relocation of the object */ -/* file's segments, this data structure maintains a link to the loaded */ -/* module. This link is severed when the load is successfully completed. */ -/* The loaded module data structure will persist until the module is */ -/* actually unloaded from target memory, but this data structure will be */ -/* freed. */ -/* */ -/* If the load of the object file is not successful for any reason, then */ -/* the loaded module will not be detached from the dynamic module. In */ -/* such case, the destructor for the dynamic module will assume */ -/* responsibility for freeing any host memory associated with the loaded */ -/* module and its segments. */ -/*---------------------------------------------------------------------------*/ -typedef struct -{ - char *name; /* Local copy of so_name */ - LOADER_FILE_DESC *fd; /* Access to ELF object file */ - struct Elf32_Ehdr fhdr; /* ELF Object File Header */ - struct Elf32_Phdr *phdr; /* ELF Program Header Table */ - Elf32_Word phnum; /* # entries in program header table */ - char* strtab; /* String Table */ - Elf32_Word strsz; /* String Table size in bytes */ - struct Elf32_Dyn *dyntab; /* Elf Dynamic Table (.dynamic scn) */ - /* This contains a list of dynamic */ - /* tags which is terminated by a NULL */ - /* record. */ - struct Elf32_Sym *symtab; /* Elf Dynamic Symbol Table */ - Elf32_Word symnum; /* # symbols in dynamic symbol table */ - Elf32_Word gsymtab_offset;/* Offset into symbol table where */ - /* global symbols start. */ - Elf32_Word gstrtab_offset;/* Offset into string table where */ - /* global symbol names start. */ - - uint8_t *c_args; - int32_t argc; - char **argv; - DLIMP_Loaded_Module *loaded_module; - int32_t wrong_endian; - BOOL direct_dependent_only; - BOOL relocatable; /* TRUE if module can be relocated */ - /* at load-time. FALSE if module is */ - /* a static executable. */ - BOOL relocate_entry_point; /* TRUE if the entry point has */ - /* not been relocated */ - - int32_t dsbt_index; /* DSBT index requested/assigned */ - uint32_t dsbt_size; /* DSBT size for this module */ - int32_t dsbt_base_tagidx;/* Location of DSBT base dyn tag */ - - int32_t preinit_array_idx; /* DT_PREINIT_ARRAY dyn tag loc */ - int32_t preinit_arraysz; /* sizeof pre-init array */ - int32_t init_idx; /* DT_INIT dynamic tag location */ - int32_t init_array_idx; /* DT_INIT_ARRAY dyn tag location */ - int32_t init_arraysz; /* sizeof init array */ - -} DLIMP_Dynamic_Module; - -/*---------------------------------------------------------------------------*/ -/* DLIMP_dependency_stack */ -/* */ -/* A LIFO stack of dynamic module objects (DLIMP_Dynamic_Module *) that */ -/* is retained while dependent files are being loaded and allocated. It */ -/* is used to guide which dynamic modules need to be relocated after all */ -/* items in the dependency graph have been allocated. The stack is only */ -/* used when the client asks the core loader to load a dynamic executable */ -/* or library. When relocation is completed, this stack should be empty. */ -/*---------------------------------------------------------------------------*/ -TYPE_STACK_DEFINITION(DLIMP_Dynamic_Module*, dynamic_module_ptr) - -/*---------------------------------------------------------------------------*/ -/* Private Loader Object instance. */ -/*---------------------------------------------------------------------------*/ -typedef struct -{ - /*-----------------------------------------------------------------------*/ - /* Contains filenames (type const char*) the system is in the process of */ - /* loading. Used to detect cycles in incorrectly compiled ELF binaries. */ - /*-----------------------------------------------------------------------*/ - Array_List DLIMP_module_dependency_list; - - /*-----------------------------------------------------------------------*/ - /* Contains objects (type DLIMP_Loaded_Module) that the system has loaded*/ - /* into target memory. */ - /*-----------------------------------------------------------------------*/ - loaded_module_ptr_Queue DLIMP_loaded_objects; - - /*-----------------------------------------------------------------------*/ - /* Dependency Graph Queue - FIFO queue of dynamic modules that are loaded*/ - /* when client asks to load a dynamic executable or library. Note that */ - /* dependents that have already been loaded with another module will not */ - /* appear on this queue. */ - /*-----------------------------------------------------------------------*/ - dynamic_module_ptr_Stack DLIMP_dependency_stack; - - /*-----------------------------------------------------------------------*/ - /* Counter for generating unique IDs for file handles. */ - /* NOTE: File handle is assigned sequencially but is never reclaimed */ - /* when the modules are unloaded. It is conceivable that a loader*/ - /* running for a long time and loading and unloading modules */ - /* could wrap-around. The loader generates error in this case. */ - /*-----------------------------------------------------------------------*/ - int32_t file_handle; - - /*-----------------------------------------------------------------------*/ - /* Identify target supported by this implementation of the core loader. */ - /*-----------------------------------------------------------------------*/ - int DLOAD_TARGET_MACHINE; - - /*-----------------------------------------------------------------------*/ - /* Client token, passed in via DLOAD_create() */ - /*-----------------------------------------------------------------------*/ - void * client_handle; -} LOADER_OBJECT; - - -/*****************************************************************************/ -/* is_DSBT_module() */ -/* */ -/* return true if the module uses DSBT model */ -/*****************************************************************************/ -static inline BOOL is_dsbt_module(DLIMP_Dynamic_Module *dyn_module) -{ - return (dyn_module->dsbt_size != 0); -} - -/*****************************************************************************/ -/* is_arm_module() */ -/* */ -/* return true if the module being processed is for ARM */ -/*****************************************************************************/ -static inline BOOL is_arm_module(struct Elf32_Ehdr* fhdr) -{ - return fhdr->e_machine == EM_ARM; -} - -/*****************************************************************************/ -/* is_c60_module() */ -/* */ -/* return true if the module being processed is for C60 */ -/*****************************************************************************/ -static inline BOOL is_c60_module(struct Elf32_Ehdr* fhdr) -{ - return fhdr->e_machine == EM_TI_C6000; -} - -/*---------------------------------------------------------------------------*/ -/* Identifies the current supported target. This is reset by the default */ -/* value when all loaded objects have been unloaded. */ -/*---------------------------------------------------------------------------*/ -extern int DLOAD_TARGET_MACHINE; - -uint32_t DLIMP_get_first_dyntag(int tag, struct Elf32_Dyn* dyn_table); -/*---------------------------------------------------------------------------*/ -/* Identify target which is supported by the core loader. If set to EM_NONE */ -/* the target will be determined by the first loaded module. */ -/*---------------------------------------------------------------------------*/ -#if defined(ARM_TARGET) && defined(C60_TARGET) -#define DLOAD_DEFAULT_TARGET_MACHINE (EM_NONE) -#elif defined(ARM_TARGET) -#define DLOAD_DEFAULT_TARGET_MACHINE (EM_ARM) -#elif defined(C60_TARGET) -#define DLOAD_DEFAULT_TARGET_MACHINE (EM_TI_C6000) -#else -#error "ARM_TARGET and/or C60_TARGET must be defined" -#endif - -/* ============================================================================= - * APIs - * ============================================================================= - */ - -/*---------------------------------------------------------------------------*/ -/* DLIMP_update_dyntag_section_address() */ -/* */ -/* Given the index of a dynamic tag which we happen to know points to a */ -/* section address, find the program header table entry associated with */ -/* the specified address and update the tag value with the real address */ -/* of the section. */ -/* */ -/*---------------------------------------------------------------------------*/ -extern BOOL DLIMP_update_dyntag_section_address( - DLIMP_Dynamic_Module *dyn_module, - int32_t i); - -/*---------------------------------------------------------------------------*/ -/* Global flags to help manage internal debug and profiling efforts. */ -/*---------------------------------------------------------------------------*/ -#ifndef __TI_COMPILER_VERSION__ -#define LOADER_DEBUG 1 -#else -#define LOADER_DEBUG 0 -#endif - -#undef LOADER_DEBUG -#define LOADER_DEBUG 0 -#define LOADER_PROFILE 0 - -#if LOADER_DEBUG -extern Bool debugging_on; -#endif - -#if LOADER_DEBUG || LOADER_PROFILE -extern Bool profiling_on; -#endif - -#endif diff --git a/src/utils/elfload/include/dload4430.h b/src/utils/elfload/include/dload4430.h deleted file mode 100644 index 5a03e06..0000000 --- a/src/utils/elfload/include/dload4430.h +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* dload4430.h */ -/* */ -/* Define internal data structures used by core dynamic loader. */ -/*****************************************************************************/ -#ifndef DLOAD4430_H -#define DLOAD4430_H - -#include "ArrayList.h" -#include "Queue.h" -#include "Stack.h" -#include "elf32.h" -#include "dload_api.h" -#include "dlw_debug.h" -#include "dlw_trgmem.h" -#include "util.h" -#include "Std.h" - -/*! - * @def DLOAD_MODULEID - * @brief Module ID for DLoad. - */ -#define DLOAD_MODULEID (UInt16) 0xfade - -/* ============================================================================= - * All success and failure codes for the module - * ============================================================================= - */ - -/*! - * @def DLOAD_STATUSCODEBASE - * @brief Error code base for DLoad. - */ -#define DLOAD_STATUSCODEBASE (DLOAD_MODULEID << 12u) - -/*! - * @def DLOAD_MAKE_FAILURE - * @brief Macro to make failure code. - */ -#define DLOAD_MAKE_FAILURE(x) ((Int)( 0x80000000 \ - | (DLOAD_STATUSCODEBASE + (x)))) - -/*! - * @def DLOAD_MAKE_SUCCESS - * @brief Macro to make success code. - */ -#define DLOAD_MAKE_SUCCESS(x) (DLOAD_STATUSCODEBASE + (x)) - -/*! - * @def DLOAD_E_INVALIDARG - * @brief Argument passed to a function is invalid. - */ -#define DLOAD_E_INVALIDARG DLOAD_MAKE_FAILURE(1) - -/*! - * @def DLOAD_E_MEMORY - * @brief Memory allocation failed. - */ -#define DLOAD_E_MEMORY DLOAD_MAKE_FAILURE(2) - -/*! - * @def DLOAD_E_FAIL - * @brief Generic failure. - */ -#define DLOAD_E_FAIL DLOAD_MAKE_FAILURE(3) - -/*! - * @def DLOAD_E_INVALIDSTATE - * @brief Module is in invalid state. - */ -#define DLOAD_E_INVALIDSTATE DLOAD_MAKE_FAILURE(4) - -/*! - * @def DLOAD_E_HANDLE - * @brief Invalid object handle specified - */ -#define DLOAD_E_HANDLE DLOAD_MAKE_FAILURE(5) - -/*! - * @def DLOAD_E_OSFAILURE - * @brief Failure in an OS-specific operation. - */ -#define DLOAD_E_OSFAILURE DLOAD_MAKE_FAILURE(6) - -/*! - * @def DLOAD_E_ACCESSDENIED - * @brief The operation is not permitted in this process. - */ -#define DLOAD_E_ACCESSDENIED DLOAD_MAKE_FAILURE(7) - -/*! - * @def DLOAD_E_TRANSLATE - * @brief An address translation error occurred. - */ -#define DLOAD_E_TRANSLATE DLOAD_MAKE_FAILURE(8) - -/*! - * @def DLOAD_SUCCESS - * @brief Operation successful. - */ -#define DLOAD_SUCCESS DLOAD_MAKE_SUCCESS(0) - -/*! - * @def DLOAD_S_ALREADYSETUP - * @brief The DLoad module has already been setup in this process. - */ -#define DLOAD_S_ALREADYSETUP DLOAD_MAKE_SUCCESS(1) - -/*! - * @def DLOAD_S_OPENHANDLE - * @brief Other DLoad clients have still setup the DLoad module. - */ -#define DLOAD_S_SETUP DLOAD_MAKE_SUCCESS(2) - -/*! - * @def DLOAD_S_OPENHANDLE - * @brief Other DLoad handles are still open in this process. - */ -#define DLOAD_S_OPENHANDLE DLOAD_MAKE_SUCCESS(3) - -/*! - * @def DLOAD_S_ALREADYEXISTS - * @brief The DLoad instance has already been created/opened in this process - */ -#define DLOAD_S_ALREADYEXISTS DLOAD_MAKE_SUCCESS(4) - -/*! - * @brief DLoad instance object - */ -typedef struct DLoad4430_Object_tag { - UInt32 openRefCount; - /*!< Reference count for number of times open/close were called in this - process. */ - Bool created; - /*!< Indicates whether the object was created in this process. */ - UInt16 procId; - /*!< Processor ID */ - - UInt32 fileId; - /*!< Baseimage fileId */ - - void * dynLoadMem; - UInt32 dynLoadMemSize; - /*!< Baseimage DynLoad Mem Section */ - TRG_PACKET *trg_mem_head; - BOOL trg_minit; - - BOOL DLL_debug; - /*!< Flag to indicate if DLL_debug is supported. */ - TARGET_ADDRESS DLModules_loc; - /*!< Address on the target of the DLModules. */ - mirror_debug_ptr_Queue mirror_debug_list; - dl_debug_Stack dl_debug_stk; - - DLOAD_HANDLE loaderHandle; - /*!< Handle to loader-instance specific info used by dyn loader lib. */ -} DLoad4430_Object; - - -/*! - * @brief Defines DLoad object handle - */ -typedef struct DLoad4430_Object * DLoad4430_Handle; - -/*! - * @brief Module configuration structure. - */ -typedef struct DLoad_Config { - UInt32 reserved; - /*!< Reserved value. */ -} DLoad_Config; - - -typedef enum { - DLOAD_MPU = 0, - DLOAD_TESLA = 1, - DLOAD_SYSM3 = 2, - DLOAD_APPM3 = 3, - DLOAD_END = 4 -} DLoad_ProcId; - -#define DLOAD_INVALIDFILEID = 0xFFFFFFFF; - -/*! - * @brief Configuration parameters specific to the slave ProcMgr instance. - */ -typedef struct DLoad_Params_tag { - UInt32 reserved; - /*!< Reserved value. */ -} DLoad_Params ; - - -/* ============================================================================= - * APIs - * ============================================================================= - */ - -/* Function to get the default configuration for the DLoad module. */ -Void DLoad4430_getConfig (DLoad_Config * cfg); - -/* Function to setup the DLoad module. */ -Int DLoad4430_setup (DLoad_Config * cfg); - -/* Function to destroy the DLoad module. */ -Int DLoad4430_destroy (Void); - -/* Function to create the DLoad instance. */ -DLoad4430_Handle DLoad4430_create (UInt16 procId, const DLoad_Params * params); - -/* Function to delete the DLoad instance. */ -Int DLoad4430_delete (DLoad4430_Handle * handlePtr); - -/* Function to load a file to the specified instance. */ -Int -DLoad4430_load (DLoad4430_Handle handle, - String imagePath, - UInt32 argc, - String * argv, - UInt32 * entry_point, - UInt32 * fileId); - -/* Function to unload a file from the specified instance. */ -Int -DLoad4430_unload (DLoad4430_Handle handle, UInt32 fileId); - -/* Function to get the information needed to call getEntryNames. */ -Int -DLoad4430_getEntryNamesInfo (DLoad4430_Handle handle, - UInt32 fileId, - Int32 * entry_pt_cnt, - Int32 * entry_pt_max_name_len); - -/* Function to get the entry names for a specified instance and file. */ -Int -DLoad4430_getEntryNames (DLoad4430_Handle handle, - UInt32 fileId, - Int32 * entry_pt_cnt, - Char *** entry_pt_names); - -/* Function to get the symbol address of a specified symbol. */ -Int -DLoad4430_getSymbolAddress (DLoad4430_Handle handle, - UInt32 fileId, - String symbolName, - UInt32 * symValue); - - -#endif diff --git a/src/utils/elfload/include/dload_api.h b/src/utils/elfload/include/dload_api.h deleted file mode 100644 index 661592e..0000000 --- a/src/utils/elfload/include/dload_api.h +++ /dev/null @@ -1,657 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* dload_api.h */ -/* */ -/* Dynamic Loader API Specification. */ -/* */ -/* Client-side of API is assumed to be platform dependent, but object file */ -/* format independent. */ -/* */ -/* Core Loader side of API is assumed to be platform independent, but */ -/* object file format dependent and target dependent. */ -/*****************************************************************************/ -#ifndef DLOAD_API_H -#define DLOAD_API_H - -#include -#include -#include "util.h" - - - - -/*****************************************************************************/ -/* Specification of Loader File Descriptor. If client side of the loader */ -/* supports virtual memory, this may need to be updated to facilitate the */ -/* use of mmap(). */ -/*****************************************************************************/ -typedef FILE LOADER_FILE_DESC; - -static const int LOADER_SEEK_SET = SEEK_SET; -static const int LOADER_SEEK_CUR = SEEK_CUR; -static const int LOADER_SEEK_END = SEEK_END; - -/*****************************************************************************/ -/* TARGET_ADDRESS - type suitable for storing target memory address values. */ -/*****************************************************************************/ -typedef void* TARGET_ADDRESS; - -/*****************************************************************************/ -/* DLOAD_HANDLE - defines the DLoad object handle. */ -/*****************************************************************************/ -typedef void * DLOAD_HANDLE; - -/*****************************************************************************/ -/* Core Loader Provided API Functions (Core Loader Entry Points) */ -/*****************************************************************************/ - -/*---------------------------------------------------------------------------*/ -/* DLOAD_create() */ -/* */ -/* Create an instance of the dynamic loader, passing a handle to the */ -/* client-specific handle for this instance. */ -/* */ -/*---------------------------------------------------------------------------*/ -DLOAD_HANDLE DLOAD_create(void * client_handle); - -/*---------------------------------------------------------------------------*/ -/* DLOAD_destroy() */ -/* */ -/* Destroy the specified dynamic loader instance. */ -/* */ -/*---------------------------------------------------------------------------*/ -void DLOAD_destroy(DLOAD_HANDLE handle); - -/*---------------------------------------------------------------------------*/ -/* DLOAD_initialize() */ -/* */ -/* Construct and initialize data structures internal to the dynamic */ -/* loader core. */ -/* */ -/*---------------------------------------------------------------------------*/ -void DLOAD_initialize(DLOAD_HANDLE handle); - -/*---------------------------------------------------------------------------*/ -/* DLOAD_finalize() */ -/* */ -/* Destroy and finalize data structures internal to the dynamic */ -/* loader core. */ -/* */ -/*---------------------------------------------------------------------------*/ -void DLOAD_finalize(DLOAD_HANDLE handle); - -/*---------------------------------------------------------------------------*/ -/* DLOAD_load_symbols() */ -/* */ -/* Load externally visible symbols from the specified file so that they */ -/* can be linked against when another object file is subsequntly loaded. */ -/* External symbols will be made available for global symbol linkage. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLOAD_load_symbols(DLOAD_HANDLE handle, LOADER_FILE_DESC* fp); - -/*---------------------------------------------------------------------------*/ -/* DLOAD_load() */ -/* */ -/* Dynamically load the specified file and return a file handle for the */ -/* loaded file. If the load fails, this function will return a value */ -/* zero (0). */ -/* */ -/* The core loader must have read access to the file pointed by fp. */ -/* */ -/*---------------------------------------------------------------------------*/ -int DLOAD_load(DLOAD_HANDLE handle, LOADER_FILE_DESC* fp, int argc, - char** argv); - -/*---------------------------------------------------------------------------*/ -/* DLOAD_unload() */ -/* */ -/* Given a file handle ID, unload all object segments associated with */ -/* the identified file and any of its dependents that are not still in */ -/* use. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLOAD_unload(DLOAD_HANDLE handle, uint32_t pseudopid); - -/*---------------------------------------------------------------------------*/ -/* DLOAD_get_entry_names_info() */ -/* */ -/* Given a file handle, get the information needed to create an array of */ -/* sufficient size to call DLOAD_get_entry_names. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLOAD_get_entry_names_info(DLOAD_HANDLE handle, - uint32_t file_handle, - int32_t *entry_pt_cnt, - int32_t *entry_pt_max_name_len); - -/*---------------------------------------------------------------------------*/ -/* DLOAD_get_entry_names() */ -/* */ -/* Given a file handle, build a list of entry point names that are */ -/* available in the specified file. This can be used when querying */ -/* the list of global functions available in a shared library. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLOAD_get_entry_names(DLOAD_HANDLE handle, uint32_t file_handle, - int32_t* entry_pt_cnt, char*** entry_pt_names); - -/*---------------------------------------------------------------------------*/ -/* DLOAD_query_symbol() */ -/* */ -/* Query the value of a symbol that is defined by an object file that */ -/* has previously been loaded. Boolean return value will be false if */ -/* the symbol is not found. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLOAD_query_symbol(DLOAD_HANDLE handle, uint32_t file_handle, - const char *sym_name, TARGET_ADDRESS *sym_val); - -/*---------------------------------------------------------------------------*/ -/* DLOAD_get_entry_point() */ -/* */ -/* Given a file handle, return the entry point target address associated */ -/* with that object file. The entry point address value is written to */ -/* *sym_val. The return value of the function indicates whether the */ -/* file with the specified handle was found or not. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLOAD_get_entry_point(DLOAD_HANDLE handle, uint32_t file_handle, - TARGET_ADDRESS *sym_val); - -/*****************************************************************************/ -/* Client Provided API Functions */ -/*****************************************************************************/ - -/*---------------------------------------------------------------------------*/ -/* File I/O */ -/* */ -/* The client side of the dynamic loader must provide basic file I/O */ -/* capabilities so that the core loader has random access into any */ -/* object file that it is asked to load. */ -/* */ -/* The client side of the dynamic loader must provide a definition of */ -/* the LOADER_FILE_DESC in dload_filedefs.h. This allows the core loader */ -/* to be independent of how the client accesses raw data in an object */ -/* file. */ -/* */ -/*---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------*/ -/* DLIF_fseek() */ -/* */ -/* Seek to a position in a file (accessed via 'stream') based on the */ -/* values for offset and origin. */ -/* */ -/*---------------------------------------------------------------------------*/ -int DLIF_fseek(LOADER_FILE_DESC *stream, int32_t offset, int origin); - -/*---------------------------------------------------------------------------*/ -/* DLIF_ftell() */ -/* */ -/* Return the current file position in the file identified in the */ -/* LOADER_FILE_DESC pointed to by 'stream'. */ -/* */ -/*---------------------------------------------------------------------------*/ -int32_t DLIF_ftell(LOADER_FILE_DESC *stream); - -/*---------------------------------------------------------------------------*/ -/* DLIF_fread() */ -/* */ -/* Read 'size' * 'nmemb' bytes of data from the file identified in the */ -/* LOADER_FILE_DESC object pointed to by 'stream', and write that data */ -/* into the memory accessed via 'ptr'. */ -/* */ -/*---------------------------------------------------------------------------*/ -size_t DLIF_fread(void *ptr, size_t size, size_t nmemb, - LOADER_FILE_DESC *stream); - -/*---------------------------------------------------------------------------*/ -/* DLIF_fclose() */ -/* */ -/* Close a file that was opened on behalf of the core loader. Ownership */ -/* of the file pointer in question belongs to the core loader, but the */ -/* client has exclusive access to the file system. */ -/* */ -/*---------------------------------------------------------------------------*/ -int DLIF_fclose(LOADER_FILE_DESC *fd); - -/*---------------------------------------------------------------------------*/ -/* Host Memory Management */ -/* */ -/* Allocate and free host memory as needed for the dynamic loader's */ -/* internal data structures. If the dynamic loader resides on the */ -/* target architecture, then this memory is allocated from a target */ -/* memory heap that must be managed separately from memory that is */ -/* allocated for a dynamically loaded object file. */ -/* */ -/*---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------*/ -/* DLIF_malloc() */ -/* */ -/* Allocate 'size' bytes of memory space that is usable as scratch space */ -/* (appropriate for the loader's internal data structures) by the dynamic */ -/* loader. */ -/* */ -/*---------------------------------------------------------------------------*/ -void* DLIF_malloc(size_t size); - -/*---------------------------------------------------------------------------*/ -/* DLIF_free() */ -/* */ -/* Free memory space that was previously allocated by DLIF_malloc(). */ -/* */ -/*---------------------------------------------------------------------------*/ -void DLIF_free(void* ptr); - -/*---------------------------------------------------------------------------*/ -/* Target Memory Allocator Interface */ -/* */ -/* The client side of the dynamic loader must create and maintain an */ -/* infrastructure to manage target memory. The client must keep track */ -/* of what target memory is associated with each object segment, */ -/* allocating target memory for newly loaded objects and release target */ -/* memory that is associated with objects that are being unloaded from */ -/* the target architecture. */ -/* */ -/* The two client-supplied functions, DLIF_allocate() and DLIF_release(), */ -/* are used by the core loader to interface into the client side's */ -/* target memory allocator infrastructure. */ -/* */ -/*---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------*/ -/* DLOAD_SEGMENT_FLAGS - segment characteristics. */ -/*---------------------------------------------------------------------------*/ -typedef uint32_t DLOAD_SEGMENT_FLAGS; -static const int DLOAD_SF_executable = 0x1; /* Memory must be executable */ -static const int DLOAD_SF_relocatable = 0x2; /* Segment must be relocatable */ - -/*---------------------------------------------------------------------------*/ -/* DLOAD_MEMORY_SEGMENT - Define structure to represent placement and size */ -/* details of a segment to be loaded. */ -/*---------------------------------------------------------------------------*/ -struct DLOAD_MEMORY_SEGMENT -{ - uint32_t target_page; /* requested/returned memory page */ - TARGET_ADDRESS target_address; /* requested/returned address */ - uint32_t objsz_in_bytes; /* size of init'd part of segment */ - uint32_t memsz_in_bytes; /* size of memory block for segment */ - DLOAD_SEGMENT_FLAGS flags; /* allocation request flags */ -}; - -/*---------------------------------------------------------------------------*/ -/* DLOAD_MEMORY_REQUEST - Define structure to represent a target memory */ -/* request made by the core loader on behalf of a segment that the */ -/* loader needs to relocate and write into target memory. */ -/*---------------------------------------------------------------------------*/ -struct DLOAD_MEMORY_REQUEST -{ - LOADER_FILE_DESC *fp; /* file being loaded */ - struct DLOAD_MEMORY_SEGMENT *segment; /* obj for req/ret alloc */ - void *host_address; /* ret hst ptr from DLIF_copy()*/ - BOOL is_loaded; /* returned as true if segment */ - /* is already in target memory */ - uint32_t offset; /* file offset of segment's */ - /* raw data */ - uint32_t flip_endian; /* endianness of trg opp host */ - DLOAD_SEGMENT_FLAGS flags; /* allocation request flags */ - uint32_t align; /* align of trg memory block */ -}; - -#if 0 -/*---------------------------------------------------------------------------*/ -/* DLIF_mapTable() */ -/* */ -/* Map the memory regions for the specified client handle. This should */ -/* be called before loading or unloading a file. */ -/* */ -/*---------------------------------------------------------------------------*/ -void DLIF_mapTable(void* client_handle); - -/*---------------------------------------------------------------------------*/ -/* DLIF_unMapTable() */ -/* */ -/* Un-Map the memory regions for the specified client handle. */ -/* */ -/*---------------------------------------------------------------------------*/ -void DLIF_unMapTable(void* client_handle); -#endif - -/*---------------------------------------------------------------------------*/ -/* DLIF_initMem() */ -/* */ -/* Initialize the dynamic loader memory segment for this client handle. */ -/* The parameter dynMemAddr should contain the address of the start of */ -/* the dynamic loader region and size should contain its size. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLIF_initMem(void* client_handle, uint32_t dynMemAddr, uint32_t size); - -/*---------------------------------------------------------------------------*/ -/* DLIF_deinitMem() */ -/* */ -/* De-initialize the dynamic loader memory segment for this client */ -/* handle. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLIF_deinitMem(void* client_handle); - -/*---------------------------------------------------------------------------*/ -/* DLIF_allocate() */ -/* */ -/* Given a DLOAD_MEMORY_REQUEST created by the core loader, allocate */ -/* target memory to fulfill the request using the target memory */ -/* management infrastrucutre on the client side of the dynamic loader. */ -/* The contents of the DLOAD_MEMORY_REQUEST will be updated per the */ -/* details of a successful allocation. The allocated page and address */ -/* can be found in the DLOAD_MEMORY_SEGMENT attached to the request. */ -/* The boolean return value reflects whether the allocation was */ -/* successful or not. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLIF_allocate(void * client_handle, struct DLOAD_MEMORY_REQUEST *req); - -/*---------------------------------------------------------------------------*/ -/* DLIF_release() */ -/* */ -/* Given a DLOAD_MEMORY_SEGMENT description, free the target memory */ -/* associated with the segment using the target memory management */ -/* infrastructure on the client side of the dynamic loader. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLIF_release(void* client_handle, struct DLOAD_MEMORY_SEGMENT* ptr); - -/*---------------------------------------------------------------------------*/ -/* Target Memory Access / Write Services */ -/* */ -/* The client side's target memory allocator infrastructure communicates */ -/* with the core loader through the DLOAD_MEMORY_REQUEST and */ -/* DLOAD_MEMORY_SEGMENT data structures defined above. To complete the */ -/* loading of an object segment, the segment may need to be relocated */ -/* before it is actually written to target memory in the space that was */ -/* allocated for it by DLIF_allocate(). */ -/* */ -/* The client side of the dynamic loader provides two functions to help */ -/* complete the process of loading an object segment, DLIF_copy() and */ -/* DLIF_write(). */ -/* */ -/* These functions help to make the core loader truly independent of */ -/* whether it is running on the host or target architecture and how the */ -/* client provides for reading/writing from/to target memory. */ -/* */ -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/* DLIF_copy() */ -/* */ -/* Copy segment data from the object file described in the 'fp' and */ -/* 'offset' of the DLOAD_MEMORY_REQUEST into host accessible memory so */ -/* that it can relocated or otherwise manipulated by the core loader. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLIF_copy(void* client_handle, struct DLOAD_MEMORY_REQUEST* req); - -/*---------------------------------------------------------------------------*/ -/* DLIF_write() */ -/* */ -/* Once the segment data described in the DLOAD_MEMORY_REQUEST is ready */ -/* (relocated, if needed), write the segment contents to the target */ -/* memory identified in the DLOAD_MEMORY_SEGMENT attached to the request. */ -/* */ -/* After the segment contents have been written to target memory, the */ -/* core loader should discard the DLOAD_MEMORY_REQUEST object, but retain */ -/* the DLOAD_MEMORY_SEGMENT object so that the target memory associated */ -/* with the segment can be releases when the segment is unloaded. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLIF_write(void* client_handle, struct DLOAD_MEMORY_REQUEST* req); - -/*---------------------------------------------------------------------------*/ -/* DLIF_read() */ -/* */ -/* Given a host accessible buffer, read content of indicated target */ -/* memory address into the buffer. */ -/*---------------------------------------------------------------------------*/ -BOOL DLIF_read(void* client_handle, void *ptr, size_t size, size_t nmemb, - TARGET_ADDRESS src); - -/*---------------------------------------------------------------------------*/ -/* DLIF_execute() */ -/* */ -/* Start execution on the target architecture from given 'exec_addr'. */ -/* If the dynamic loader is running on the target architecture, this can */ -/* be effected as a simple function call. */ -/* */ -/*---------------------------------------------------------------------------*/ -int32_t DLIF_execute(void* client_handle, TARGET_ADDRESS exec_addr); - -/*---------------------------------------------------------------------------*/ -/* Loading and Unloading of Dependent Files */ -/* */ -/* The dynamic loader core loader must coordinate loading and unloading */ -/* dependent object files with the client side of the dynamic loader. */ -/* This allows the client to keep its bookkeeping information up to date */ -/* with what is currently loaded on the target architecture. */ -/* */ -/* For instance, the client may need to interact with a file system or */ -/* registry. The client may also need to update debug information in */ -/* synch with the loading and unloading of shared objects. */ -/* */ -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/* DLIF_load_dependent() */ -/* */ -/* Ask client to find and open a dependent file identified by the */ -/* 'so_name' parameter, then, if necessary, initiate a DLOAD_load() */ -/* call to actually load the shared object onto the target. A */ -/* successful load will return a file handle ID that the client can */ -/* associate with the newly loaded file. */ -/* */ -/*---------------------------------------------------------------------------*/ -int DLIF_load_dependent(void* client_handle, const char* so_name); - -/*---------------------------------------------------------------------------*/ -/* DLIF_unload_dependent() */ -/* */ -/* Ask client to unload a dependent file identified by the 'file_handle' */ -/* parameter. Initiate a call to DLOAD_unload() to actually free up */ -/* the target memory that was occupied by the object file. */ -/* */ -/*---------------------------------------------------------------------------*/ -void DLIF_unload_dependent(void* client_handle, uint32_t file_handle); - -/*---------------------------------------------------------------------------*/ -/* Error/Warning Registration Functions */ -/* */ -/* The client will maintain an error/warning log. This will allow the */ -/* core loader to register errors and warnings in the load during a */ -/* given dynamic load. The client is required to check the log after */ -/* each load attempt to report any problems. */ -/* */ -/*---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------*/ -/* Loader Warning Types */ -/*---------------------------------------------------------------------------*/ -typedef enum { - DLWT_MISC = 0, /* Miscellaneous warning */ - DLWT_FILE /* Warning missing/invalid file information */ -} LOADER_WARNING_TYPE; - -/*---------------------------------------------------------------------------*/ -/* DLIF_warning() */ -/* */ -/* Log a warning message with the client's error/warning handling */ -/* infrastructure. */ -/* */ -/*---------------------------------------------------------------------------*/ -void DLIF_warning(LOADER_WARNING_TYPE wtype, const char *fmt, ...); - -/*---------------------------------------------------------------------------*/ -/* Loader Error Types */ -/*---------------------------------------------------------------------------*/ -typedef enum { - DLET_MISC = 0, /* Miscellaneous error */ - DLET_FILE, /* Error reading/processing file */ - DLET_SYMBOL, /* Symbol resolution error */ - DLET_RELOC, /* Relocation error */ - DLET_MEMORY, /* Host memory allocation/free error */ - DLET_TRGMEM, /* Target memory allocation/free error */ - DLET_DEBUG /* Shared object or DLL debug error */ -} LOADER_ERROR_TYPE; - -/*---------------------------------------------------------------------------*/ -/* DLIF_error() */ -/* */ -/* Log an error message with the client's error/warning handling */ -/* infrastructure. */ -/* */ -/*---------------------------------------------------------------------------*/ -void DLIF_error(LOADER_ERROR_TYPE etype, const char *fmt, ...); - -/*---------------------------------------------------------------------------*/ -/* DLIF_trace() */ -/* */ -/* Log a message with the client's trace handling infrastructure. */ -/* */ -/*---------------------------------------------------------------------------*/ -void DLIF_trace(const char *fmt, ...); - -/*---------------------------------------------------------------------------*/ -/* Dynamic Static Base Table (DSBT) Support Functions */ -/*---------------------------------------------------------------------------*/ -#define DSBT_INDEX_INVALID -1 -#define DSBT_DSBT_BASE_INVALID 0 -#define DSBT_STATIC_BASE_INVALID 0 - -/*****************************************************************************/ -/* Core Loader Side of DSBT Support */ -/*****************************************************************************/ - -/*---------------------------------------------------------------------------*/ -/* DLOAD_get_dsbt_size() */ -/* */ -/* Query the size of the DSBT associated with a specified file. The */ -/* client will check the size of a module's DSBT before it writes a copy */ -/* of the master DSBT to the module's DSBT. If the module's DSBT is not */ -/* big enough, an error will be emitted and the load will fail. */ -/* */ -/*---------------------------------------------------------------------------*/ -uint32_t DLOAD_get_dsbt_size(DLOAD_HANDLE handle, int32_t file_handle); - -/*---------------------------------------------------------------------------*/ -/* DLOAD_get_dsbt_base() */ -/* */ -/* Find DSBT address for specified file. The client will query for this */ -/* address after allocation and symbol relocation has been completed. */ -/* The client will write a copy of the master DSBT to the returned DSBT */ -/* address if the module's DSBT size is big enough. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLOAD_get_dsbt_base(DLOAD_HANDLE handle, int32_t file_handle, - TARGET_ADDRESS *dsbt_base); - -/*---------------------------------------------------------------------------*/ -/* DLOAD_get_static_base() */ -/* */ -/* Find static base for a specified file. The client will query for this */ -/* address after allocation and symbol relocation has been completed. */ -/* The client will use the returned static base value to fill the slot */ -/* in the master DSBT that is associated with this module. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLOAD_get_static_base(DLOAD_HANDLE handle, int32_t file_handle, - TARGET_ADDRESS *static_base); - - -/*****************************************************************************/ -/* Client Side of DSBT Support */ -/*****************************************************************************/ - -/*---------------------------------------------------------------------------*/ -/* DLIF_register_dsbt_index_request() */ -/* */ -/* Register a request for a DSBT index with the client. A module can */ -/* make a specific DSBT index request or it can allow the client to */ -/* assign a DSBT index on its behalf (requested_dsbt_index == -1). The */ -/* client implementation of this function must check that a specific DSBT */ -/* index request does not conflict with a previous specific DSBT index */ -/* request. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLIF_register_dsbt_index_request(DLOAD_HANDLE handle, - const char * requestor_name, - int32_t requestor_file_handle, - int32_t requested_dsbt_index); - -/*---------------------------------------------------------------------------*/ -/* DLIF_assign_dsbt_indices() */ -/* */ -/* Bind each module that registered a request for a DSBT index to a */ -/* specific slot in the DSBT. Specific requests for DSBT indices will be */ -/* honored first. Any general requests that remain will be assigned to */ -/* the first available slot in the DSBT. */ -/* */ -/*---------------------------------------------------------------------------*/ -void DLIF_assign_dsbt_indices(void); - -/*---------------------------------------------------------------------------*/ -/* DLIF_get_dsbt_index() */ -/* */ -/* Given a module that uses the DSBT model, return the identity of the */ -/* DSBT slot that was assigned to it by the client. This function can */ -/* only be called after the client has assigned DSBT indices to all */ -/* loaded object modules that use the DSBT model. The implementation of */ -/* this function will check that a proper DSBT index has been assigned to */ -/* the specified module and an invalid index (-1) if there is a problem. */ -/* */ -/*---------------------------------------------------------------------------*/ -int32_t DLIF_get_dsbt_index(int32_t file_handle); - -/*---------------------------------------------------------------------------*/ -/* DLIF_update_all_dsbts() */ -/* */ -/* Populate the client's model of the master DSBT with the static base */ -/* for each assigned slot in the DSBT, then write a copy of the master */ -/* DSBT to each module's DSBT location. The implementation of this */ -/* function must check the size of each module's DSBT to make sure that */ -/* it is large enough to hold a copy of the master DSBT. The function */ -/* will return FALSE if there is a problem. */ -/* */ -/*---------------------------------------------------------------------------*/ -BOOL DLIF_update_all_dsbts(void); - -#endif diff --git a/src/utils/elfload/include/dload_endian.h b/src/utils/elfload/include/dload_endian.h deleted file mode 100644 index c1c9cd9..0000000 --- a/src/utils/elfload/include/dload_endian.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* dload_endian.h */ -/* */ -/* Specification of functions used to assist loader with endian-ness issues. */ -/*****************************************************************************/ -#ifndef DLOAD_ENDIAN_H -#define DLOAD_ENDIAN_H - -#include "elf32.h" - -/*---------------------------------------------------------------------------*/ -/* Prototypes for ELF file object reader endianness swap routines. */ -/*---------------------------------------------------------------------------*/ - -int DLIMP_get_endian(); -void DLIMP_change_endian32(int32_t* to_change); -void DLIMP_change_endian16(int16_t* to_change); -void DLIMP_change_ehdr_endian(struct Elf32_Ehdr* to_change); -void DLIMP_change_phdr_endian(struct Elf32_Phdr* to_change); -void DLIMP_change_dynent_endian(struct Elf32_Dyn* to_change); -void DLIMP_change_sym_endian(struct Elf32_Sym* to_change); -void DLIMP_change_rela_endian(struct Elf32_Rela* to_change); -void DLIMP_change_rel_endian(struct Elf32_Rel* to_change); - -#endif diff --git a/src/utils/elfload/include/dlw_debug.h b/src/utils/elfload/include/dlw_debug.h deleted file mode 100644 index d170f4f..0000000 --- a/src/utils/elfload/include/dlw_debug.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* dlw_debug.h */ -/* */ -/* Define internal data structures used by DLW client side for DLL debug. */ -/*****************************************************************************/ -#ifndef DLW_DEBUG_H -#define DLW_DEBUG_H - -#include "dload_api.h" -#include "Queue.h" -#include "Stack.h" - -/*---------------------------------------------------------------------------*/ -/* DLL Debug Support */ -/* */ -/* A host copy of the DLL View debug support data structure that will be */ -/* written into target memory to assist the debugger with mapping symbol */ -/* definitions to their dynamically loaded location in target memory. */ -/*---------------------------------------------------------------------------*/ -#define INIT_VERSION 2 -#define VERIFICATION 0x79 - -/*---------------------------------------------------------------------------*/ -/* DL_Debug_List_Header - Address of this structure in target memory is */ -/* recorded in DLModules symbol. Provides directions to first */ -/* DL_Module_Record in the list. */ -/*---------------------------------------------------------------------------*/ -typedef struct { - uint32_t first_module_ptr; - uint16_t first_module_size; - uint16_t update_flag; -} DL_Debug_List_Header; - -/*---------------------------------------------------------------------------*/ -/* DL_Segment - Debug information recorded about each segment in a module. */ -/*---------------------------------------------------------------------------*/ -typedef struct { - uint32_t load_address; - uint32_t run_address; -} DL_Target_Segment; - -typedef struct _DL_Host_Segment { - uint32_t load_address; - uint32_t run_address; - struct _DL_Host_Segment *next_segment; -} DL_Host_Segment; - -/*---------------------------------------------------------------------------*/ -/* DL_Module_Debug_Record - Debug information about each module that has */ -/* been loaded. */ -/*---------------------------------------------------------------------------*/ -/* We have a host version of the debug record which is built up while the */ -/* module is being loaded, and a target version of the debug record which */ -/* is built after the load has completed and we know all of the information */ -/* that needs to be written to target memory for this module. */ -/*---------------------------------------------------------------------------*/ -typedef struct { - int handle; - char *module_name; - TARGET_ADDRESS target_address; - uint32_t next_module_ptr; - uint16_t next_module_size; - int num_segments; - DL_Host_Segment *segment_list_head; - DL_Host_Segment *segment_list_tail; -} DL_Host_Module_Debug; - -typedef struct { - uint32_t next_module_ptr; - uint16_t next_module_size; - uint16_t tool_version; - uint16_t verification_word; - uint16_t num_segments; - uint32_t timestamp; - DL_Target_Segment segments[1]; -} DL_Target_Module_Debug; - -/*---------------------------------------------------------------------------*/ -/* DLL Debug Support - context stack of module records. We need to maintain */ -/* a stack of modules while creating the DLL module record list for */ -/* debug support. While we are building up a module record for one */ -/* module, the loader may be asked to load dependent modules. Note */ -/* that we cannot emit a module record to target memory until loading */ -/* of the module has been completed (need to know how many segments */ -/* are in the module before we can allocate target memory for the */ -/* module record). */ -/*---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------*/ -/* dl_debug */ -/* */ -/* Define a LIFO linked list "class" of DL_Module_Debug_Record pointers. */ -/*---------------------------------------------------------------------------*/ -TYPE_STACK_DEFINITION(DL_Host_Module_Debug*, dl_debug) - -/*---------------------------------------------------------------------------*/ -/* mirror_debug_ptr */ -/* */ -/* Define a linked list "class" of DL_Host_Module_Debug pointers. */ -/*---------------------------------------------------------------------------*/ -TYPE_QUEUE_DEFINITION(DL_Host_Module_Debug*, mirror_debug_ptr) - -/*---------------------------------------------------------------------------*/ -/* Management functions for DLL debug support data structures. */ -/*---------------------------------------------------------------------------*/ -extern void DLDBG_add_host_record(void* client_handle, - const char *module_name); -extern void DLDBG_add_target_record(void* client_handle, - int handle); -extern void DLDBG_rm_target_record(void* client_handle, - int handle); -extern void DLDBG_add_segment_record(void* client_handle, - struct DLOAD_MEMORY_SEGMENT *obj_desc); -extern void DLDBG_dump_mirror_debug_list(void* client_handle); -#endif diff --git a/src/utils/elfload/include/dlw_dsbt.h b/src/utils/elfload/include/dlw_dsbt.h deleted file mode 100644 index 616565d..0000000 --- a/src/utils/elfload/include/dlw_dsbt.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* dlw_dsbt.h */ -/* */ -/* Define internal data structures used by RIDL client side for */ -/* Dynamic Static Base Table (DSBT) support. */ -/*****************************************************************************/ -#ifndef DLW_DSBT_H -#define DLW_DSBT_H - -#include "Queue.h" -#include "dload_api.h" - -/*---------------------------------------------------------------------------*/ -/* DSBT_Index_Request - Representation of a request for a DSBT index on */ -/* behalf of an executable or library. This data structure will reserve */ -/* space for the specified module in the client's model of the master */ -/* DSBT. */ -/*---------------------------------------------------------------------------*/ -typedef struct { - char *name; - int32_t file_handle; - uint32_t dsbt_size; - TARGET_ADDRESS dsbt_base; - TARGET_ADDRESS static_base; - int32_t requested_index; - int32_t assigned_index; -} DSBT_Index_Request; - -/*---------------------------------------------------------------------------*/ -/* DSBT_Entry - Representation of one slot in the client's model of the */ -/* master DSBT. The model is built up when DSBT indices are assigned. */ -/* The content of the master DSBT is propagated to each module who uses */ -/* the DSBT model. */ -/*---------------------------------------------------------------------------*/ -typedef struct { - DSBT_Index_Request *index_request; -} DSBT_Entry; - -/*---------------------------------------------------------------------------*/ -/* DSBT_index_request_queue - This is a holding area for DSBT index requests */ -/* while allocation and relocation of symbols is in progress for the top- */ -/* level module and all of its dependents. Items will be pulled off the */ -/* queue when we are ready to make actual DSBT index assignmments. */ -/*---------------------------------------------------------------------------*/ -TYPE_QUEUE_DEFINITION(DSBT_Index_Request*, dsbt_index_request_ptr) -extern dsbt_index_request_ptr_Queue DSBT_index_request_queue; - -/*---------------------------------------------------------------------------*/ -/* DSBT_master - client's model of DSBT master. Vector of DSBT_Entry ptrs. */ -/*---------------------------------------------------------------------------*/ -extern Array_List DSBT_master; - -/*---------------------------------------------------------------------------*/ -/* DSBT_release_entry() */ -/* */ -/* Release an entry in the client's model of the master DSBT. This */ -/* happens when a module is unloaded from the target. The slot will */ -/* remain a part of the DSBT, but it will become available to other */ -/* objects that are subsequently loaded. */ -/*---------------------------------------------------------------------------*/ -extern void DSBT_release_entry(int32_t file_handle); - -#endif diff --git a/src/utils/elfload/include/dlw_trgmem.h b/src/utils/elfload/include/dlw_trgmem.h deleted file mode 100644 index b241276..0000000 --- a/src/utils/elfload/include/dlw_trgmem.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* dlw_trgmem.h */ -/* */ -/* Define internal data structures used by RIDL client side for target */ -/* memory management. */ -/*****************************************************************************/ -#ifndef DLW_TRGMEM_H -#define DLW_TRGMEM_H - -#include "dload_api.h" - -/*---------------------------------------------------------------------------*/ -/* MIN_BLOCK is the minimum size of a packet. */ -/*---------------------------------------------------------------------------*/ -#define MIN_BLOCK 4 - -/*---------------------------------------------------------------------------*/ -/* TRG_PACKET is the template for a data packet. Packet size contains the */ -/* number of bytes allocated for the user. Packets are always allocated */ -/* memory in MIN_BLOCK byte chunks. The list is ordered by packet address */ -/* which refers to the target address associated with the first byte of the */ -/* packet. The list itself is allocated out of host memory and is a doubly */ -/* linked list to help with easy splitting and merging of elements. */ -/*---------------------------------------------------------------------------*/ -typedef struct _trg_packet -{ - /* Need to change this to TARGET_ADDRESS packet_addr */ - uint32_t packet_addr; /* target address of packet */ - uint32_t packet_size; /* number of bytes in this packet */ - struct _trg_packet *prev_packet; /* prev packet in trg mem list */ - struct _trg_packet *next_packet; /* next packet in trg mem list */ - BOOL used_packet; /* has packet been allocated? */ -} TRG_PACKET; - -/*---------------------------------------------------------------------------*/ -/* Interface into client's target memory manager. */ -/*---------------------------------------------------------------------------*/ -extern BOOL DLTMM_init(void* client_handle, uint32_t dynMemAddr, uint32_t size); -extern BOOL DLTMM_deinit(void* client_handle); -extern BOOL DLTMM_malloc(void* client_handle, - struct DLOAD_MEMORY_REQUEST *targ_req, - struct DLOAD_MEMORY_SEGMENT *obj_desc); -extern void DLTMM_free(void* client_handle, TARGET_ADDRESS ptr); - -extern void DLTMM_fwrite_trg_mem(FILE *fp); -extern void DLTMM_fread_trg_mem(FILE *fp); -extern void DLTMM_dump_trg_mem(uint32_t offset, uint32_t nbytes, - FILE* fp); - -#endif /* DLW_TRGMEM_H */ diff --git a/src/utils/elfload/include/elf32.h b/src/utils/elfload/include/elf32.h deleted file mode 100644 index 5b0301f..0000000 --- a/src/utils/elfload/include/elf32.h +++ /dev/null @@ -1,756 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* elf32.h */ -/* */ -/* Basic Data Structures for 32-bit ELF Object Format Files */ -/* */ -/* The data structures in this file come primarily from this specification: */ -/* */ -/* Tool Interface Standard (TIS) */ -/* Executable and Linking Format (ELF) Specification */ -/* Version 1.2 */ -/* */ -/* TIS Committee */ -/* May 1995 */ -/* */ -/* Additions and enhancements from this specification are also included: */ -/* */ -/* System V Application Binary Interface */ -/* DRAFT 17 */ -/* December 2003 */ -/* */ -/* http://sco.com/developers/gabi/2003-12-17/contents.html */ -/* */ -/*****************************************************************************/ -#ifndef ELF32_H -#define ELF32_H - -#include - -/*---------------------------------------------------------------------------*/ -/* 32-Bit Data Types (Figure 1-2, page 1-2) */ -/*---------------------------------------------------------------------------*/ -typedef uint32_t Elf32_Addr; -typedef uint16_t Elf32_Half; -typedef uint32_t Elf32_Off; -typedef int32_t Elf32_Sword; -typedef uint32_t Elf32_Word; - - -/*****************************************************************************/ -/* ELF Header */ -/* PP. 1-4 */ -/*****************************************************************************/ - -/*---------------------------------------------------------------------------*/ -/* ELF Identification Indexes (indexes into Elf32_Ehdr.e_ident[] below) */ -/*---------------------------------------------------------------------------*/ -enum -{ - EI_MAG0 = 0, /* File identification */ - EI_MAG1 = 1, /* File identification */ - EI_MAG2 = 2, /* File identification */ - EI_MAG3 = 3, /* File identification */ - EI_CLASS = 4, /* File class */ - EI_DATA = 5, /* Data encoding */ - EI_VERSION = 6, /* File version */ - EI_OSABI = 7, /* Operating system / ABI */ - EI_ABIVERSION = 8, /* ABI version */ - EI_PAD = 9, /* Start of padding bytes */ - EI_NIDENT = 16 /* Size of Elf32_Ehdr.e_ident[] */ -}; - - -/*---------------------------------------------------------------------------*/ -/* ELF Header Data Structure */ -/*---------------------------------------------------------------------------*/ -struct Elf32_Ehdr -{ - uint8_t e_ident[EI_NIDENT]; /* ELF Magic Number */ - Elf32_Half e_type; /* Object File Type */ - Elf32_Half e_machine; /* Target Processor */ - Elf32_Word e_version; /* Object File Version */ - Elf32_Addr e_entry; /* Entry Point */ - Elf32_Off e_phoff; /* Program Header Table Offset */ - Elf32_Off e_shoff; /* Section Header Table Offset */ - Elf32_Word e_flags; /* Processor-Specific Flags */ - Elf32_Half e_ehsize; /* Size of ELF header */ - Elf32_Half e_phentsize; /* Size of a Program Header */ - Elf32_Half e_phnum; /* # Entries in Program Header Table */ - Elf32_Half e_shentsize; /* Size of a Section Header */ - Elf32_Half e_shnum; /* # Entries in Section Header Table */ - Elf32_Half e_shstrndx; /* Section Name String Table Section */ -}; - - -/*---------------------------------------------------------------------------*/ -/* Object File Types (value of "e_type") */ -/*---------------------------------------------------------------------------*/ -enum -{ - ET_NONE = 0, /* No file type */ - ET_REL = 1, /* Relocatable file */ - ET_EXEC = 2, /* Executable file */ - ET_DYN = 3, /* Shared object file */ - ET_CORE = 4, /* Core file */ - ET_LOOS = 0xfe00, /* First OS-specific value */ - ET_HIPS = 0xfeff, /* Last OS-specific value */ - ET_LOPROC = 0xff00, /* First processor-specific value */ - ET_HIPROC = 0xffff /* Last processor-specific value */ -}; - - -/*---------------------------------------------------------------------------*/ -/* Target Processors (value of "e_machine") */ -/*---------------------------------------------------------------------------*/ -enum -{ - EM_NONE = 0, /* No machine */ - EM_M32 = 1, /* AT&T WE 32100 */ - EM_SPARC = 2, /* SPARC */ - EM_386 = 3, /* Intel 80386 */ - EM_68K = 4, /* Motorola 68000 */ - EM_88K = 5, /* Motorola 88000 */ - EM_860 = 7, /* Intel 80860 */ - EM_MIPS = 8, /* MIPS I Architecture */ - EM_S370 = 9, /* IBM System/370 Processor */ - EM_MIPS_RS3_LE = 10, /* MIPS RS3000 Little-endian */ - EM_PARISC = 15, /* Hewlett-Packard PA-RISC */ - EM_VPP500 = 17, /* Fujitsu VPP500 */ - EM_SPARC32PLUS = 18, /* Enhanced instruction set SPARC */ - EM_960 = 19, /* Intel 80960 */ - EM_PPC = 20, /* PowerPC */ - EM_PPC64 = 21, /* 64-bit PowerPC */ - EM_S390 = 22, /* IBM System/390 Processor */ - EM_V800 = 36, /* NEC V800 */ - EM_FR20 = 37, /* Fujitsu FR20 */ - EM_RH32 = 38, /* TRW RH-32 */ - EM_RCE = 39, /* Motorola RCE */ - EM_ARM = 40, /* Advanced RISC Machines ARM */ - EM_ALPHA = 41, /* Digital Alpha */ - EM_SH = 42, /* Hitachi SH */ - EM_SPARCV9 = 43, /* SPARC Version 9 */ - EM_TRICORE = 44, /* Siemens TriCore embedded processor */ - EM_ARC = 45, /* "Argonaut RISC Core, Argonaut Technologies Inc. */ - EM_H8_300 = 46, /* Hitachi H8/300 */ - EM_H8_300H = 47, /* Hitachi H8/300H */ - EM_H8S = 48, /* Hitachi H8S */ - EM_H8_500 = 49, /* Hitachi H8/500 */ - EM_IA_64 = 50, /* Intel IA-64 processor architecture */ - EM_MIPS_X = 51, /* Stanford MIPS-X */ - EM_COLDFIRE = 52, /* Motorola ColdFire */ - EM_68HC12 = 53, /* Motorola M68HC12 */ - EM_MMA = 54, /* Fujitsu MMA Multimedia Accelerator */ - EM_PCP = 55, /* Siemens PCP */ - EM_NCPU = 56, /* Sony nCPU embedded RISC processor */ - EM_NDR1 = 57, /* Denso NDR1 microprocessor */ - EM_STARCORE = 58, /* Motorola Star*Core processor */ - EM_ME16 = 59, /* Toyota ME16 processor */ - EM_ST100 = 60, /* STMicroelectronics ST100 processor */ - EM_TINYJ = 61, /* Advanced Logic Corp. TinyJ embedded processor f */ - EM_X86_64 = 62, /* AMD x86-64 architecture */ - EM_PDSP = 63, /* Sony DSP Processor */ - EM_PDP10 = 64, /* Digital Equipment Corp. PDP-10 */ - EM_PDP11 = 65, /* Digital Equipment Corp. PDP-11 */ - EM_FX66 = 66, /* Siemens FX66 microcontroller */ - EM_ST9PLUS = 67, /* STMicroelectronics ST9+ 8/16 bit microcontrolle */ - EM_ST7 = 68, /* STMicroelectronics ST7 8-bit microcontroller */ - EM_68HC16 = 69, /* Motorola MC68HC16 Microcontroller */ - EM_68HC11 = 70, /* Motorola MC68HC11 Microcontroller */ - EM_68HC08 = 71, /* Motorola MC68HC08 Microcontroller */ - EM_68HC05 = 72, /* Motorola MC68HC05 Microcontroller */ - EM_SVX = 73, /* Silicon Graphics SVx */ - EM_ST19 = 74, /* STMicroelectronics ST19 8-bit microcontroller */ - EM_VAX = 75, /* Digital VAX */ - EM_CRIS = 76, /* Axis Communications 32-bit embedded processor */ - EM_JAVELIN = 77, /* Infineon Technologies 32-bit embedded processor */ - EM_FIREPATH = 78, /* Element 14 64-bit DSP Processor */ - EM_ZSP = 79, /* LSI Logic 16-bit DSP Processor */ - EM_MMIX = 80, /* Donald Knuth's educational 64-bit processor */ - EM_HUANY = 81, /* Harvard University machine-independent object f */ - EM_PRISM = 82, /* SiTera Prism */ - EM_AVR = 83, /* Atmel AVR 8-bit microcontroller */ - EM_FR30 = 84, /* Fujitsu FR30 */ - EM_D10V = 85, /* Mitsubishi D10V */ - EM_D30V = 86, /* Mitsubishi D30V */ - EM_V850 = 87, /* NEC v850 */ - EM_M32R = 88, /* Mitsubishi M32R */ - EM_MN10300 = 89, /* Matsushita MN10300 */ - EM_MN10200 = 90, /* Matsushita MN10200 */ - EM_PJ = 91, /* picoJava */ - EM_OPENRISC = 92, /* OpenRISC 32-bit embedded processor */ - EM_ARC_A5 = 93, /* ARC Cores Tangent-A5 */ - EM_XTENSA = 94, /* Tensilica Xtensa Architecture */ - EM_VIDEOCORE = 95, /* Alphamosaic VideoCore processor */ - EM_TMM_GPP = 96, /* Thompson Multimedia General Purpose Processor */ - EM_NS32K = 97, /* National Semiconductor 32000 series */ - EM_TPC = 98, /* Tenor Network TPC processor */ - EM_SNP1K = 99, /* Trebia SNP 1000 processor */ - EM_ST200 = 100, /* STMicroelectronics (www.st.com) ST200 microcont */ - EM_IP2K = 101, /* Ubicom IP2xxx microcontroller family */ - EM_MAX = 102, /* MAX Processor */ - EM_CR = 103, /* National Semiconductor CompactRISC microprocess */ - EM_F2MC16 = 104, /* Fujitsu F2MC16 */ - EM_MSP430 = 105, /* Texas Instruments embedded microcontroller msp4 */ - EM_BLACKFIN = 106, /* Analog Devices Blackfin (DSP) processor */ - EM_SE_C33 = 107, /* S1C33 Family of Seiko Epson processors */ - EM_SEP = 108, /* Sharp embedded microprocessor */ - EM_ARCA = 109, /* Arca RISC Microprocessor */ - EM_UNICORE = 110, /* Microprocessor series from PKU-Unity Ltd. and M */ - - /*------------------------------------------------------------------------*/ - /* ELF Magic Numbers Reserved For Texas Instruments */ - /* */ - /* The magic numbers 140-159 were reserved through SCO to be included */ - /* in the official ELF specification. Please see Don Darling */ - /* regarding any changes or allocation of the numbers below. */ - /* */ - /* When we allocate a number for use, SCO needs to be notified so they */ - /* can update the ELF specification accordingly. */ - /*------------------------------------------------------------------------*/ - EM_TI_C6000 = 140, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED02 = 141, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED03 = 142, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED04 = 143, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED05 = 144, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED06 = 145, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED07 = 146, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED08 = 147, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED09 = 148, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED10 = 149, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED11 = 150, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED12 = 151, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED13 = 152, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED14 = 153, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED15 = 154, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED16 = 155, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED17 = 156, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED18 = 157, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED19 = 158, /* Reserved for Texas Instruments; unused */ - EM_TI_UNUSED20 = 159 /* Reserved for Texas Instruments; unused */ -}; - - -/*---------------------------------------------------------------------------*/ -/* Object File Version (value of "e_version") */ -/*---------------------------------------------------------------------------*/ -enum -{ - EV_NONE = 0, /* Invalid version */ - EV_CURRENT = 1 /* Current version */ -}; - - -/*****************************************************************************/ -/* ELF Identification */ -/* PP. 1-6 */ -/*****************************************************************************/ - -/*---------------------------------------------------------------------------*/ -/* Identification Values for ELF Files */ -/*---------------------------------------------------------------------------*/ - -/* EI_MAG0 to EI_MAG3 */ -enum -{ - ELFMAG0 = 0x7f, /* e_ident[EI_MAG0] */ - ELFMAG1 = 'E', /* e_ident[EI_MAG1] */ - ELFMAG2 = 'L', /* e_ident[EI_MAG2] */ - ELFMAG3 = 'F' /* e_ident[EI_MAG3] */ -}; - -/* EI_CLASS */ -enum -{ - ELFCLASSNONE = 0, /* Invalid class */ - ELFCLASS32 = 1, /* 32-bit objects */ - ELFCLASS64 = 2 /* 64-bit objects */ -}; - -/* EI_DATA */ -enum -{ - ELFDATANONE = 0, /* Invalid data encoding */ - ELFDATA2LSB = 1, /* Little-endian data */ - ELFDATA2MSB = 2 /* Big-endian data */ -}; - -/* EI_OSABI */ -enum -{ - ELFOSABI_NONE = 0, /* No extensions or unspecified */ - ELFOSABI_HPUX = 1, /* Hewlett-Packard HP-UX */ - ELFOSABI_NETBSD = 2, /* NetBSD */ - ELFOSABI_LINUX = 3, /* Linux */ - ELFOSABI_SOLARIS = 6, /* Sun Solaris */ - ELFOSABI_AIX = 7, /* AIX */ - ELFOSABI_IRIX = 8, /* IRIX */ - ELFOSABI_FREEBSD = 9, /* FreeBSD */ - ELFOSABI_TRU64 = 10, /* Compaq TRU64 UNIX */ - ELFOSABI_MODESTO = 11, /* Novell Modesto */ - ELFOSABI_OPENBSD = 12, /* Open BSD */ - ELFOSABI_OPENVMS = 13, /* Open VMS */ - ELFOSABI_NSK = 14, /* Hewlett-Packard Non-Stop Kernel */ - ELFOSABI_AROS = 15 /* Amiga Research OS */ -}; - -/*****************************************************************************/ -/* Program Header */ -/* PP. 2-2 */ -/*****************************************************************************/ - -/*---------------------------------------------------------------------------*/ -/* Program Header Data Structure */ -/*---------------------------------------------------------------------------*/ -struct Elf32_Phdr -{ - Elf32_Word p_type; /* Segment type */ - Elf32_Off p_offset; /* Segment file offset */ - Elf32_Addr p_vaddr; /* Segment virtual address */ - Elf32_Addr p_paddr; /* Segment physical address */ - Elf32_Word p_filesz; /* Segment file image size */ - Elf32_Word p_memsz; /* Segment memory image size */ - Elf32_Word p_flags; /* Segment flags */ - Elf32_Word p_align; /* Segment alignment */ -}; - -/*---------------------------------------------------------------------------*/ -/* Segment Types (value of "p_type") */ -/*---------------------------------------------------------------------------*/ -enum -{ - PT_NULL = 0, /* Unused table entry */ - PT_LOAD = 1, /* Loadable segment */ - PT_DYNAMIC = 2, /* Dynamic linking information */ - PT_INTERP = 3, /* Interpreter path string location */ - PT_NOTE = 4, /* Location and size of auxiliary information */ - PT_SHLIB = 5, /* Shared library information */ - PT_PHDR = 6, /* Location and size of program header table */ - PT_TLS = 7, /* Specifies the Thread-Local Storage template */ - PT_LOOS = 0x60000000, /* First OS-specific value */ - PT_HIOS = 0x6fffffff, /* Last OS-specific value */ - PT_LOPROC = 0x70000000, /* First processor-specific value */ - PT_HIPROC = 0x7fffffff /* Last processor-specific value */ -}; - -/*---------------------------------------------------------------------------*/ -/* Segment Permissions (value of "p_flags") */ -/*---------------------------------------------------------------------------*/ -enum -{ - PF_X = 0x1, /* Execute */ - PF_W = 0x2, /* Write */ - PF_R = 0x4, /* Read */ - PF_MASKOS = 0x0ff00000, /* OS-specific mask */ - PF_MASKPROC = 0xf0000000 /* Processor-specific mask */ -}; - -/*****************************************************************************/ -/* Sections */ -/* PP. 1-9 */ -/*****************************************************************************/ - -/*---------------------------------------------------------------------------*/ -/* Section Header Data Structure */ -/*---------------------------------------------------------------------------*/ -struct Elf32_Shdr -{ - Elf32_Word sh_name; /* Section name (offset into string section) */ - Elf32_Word sh_type; /* Section type */ - Elf32_Word sh_flags; /* Section flags */ - Elf32_Addr sh_addr; /* Address in memory image */ - Elf32_Off sh_offset; /* File offset of section data */ - Elf32_Word sh_size; /* Size of the section in bytes */ - Elf32_Word sh_link; /* Link to the section header table */ - Elf32_Word sh_info; /* Extra information depending on section type */ - Elf32_Word sh_addralign; /* Address alignment constraints */ - Elf32_Word sh_entsize; /* Size of fixed-size entries in section */ -}; - -/*---------------------------------------------------------------------------*/ -/* Special Section Indexes */ -/*---------------------------------------------------------------------------*/ -enum -{ - SHN_UNDEF = 0, /* Referenced by undefined values */ - SHN_LORESERVE = 0xff00, /* First reserved index */ - SHN_LOPROC = 0xff00, /* First processor-specific index */ - SHN_HIPROC = 0xff1f, /* Last processor-specific index */ - SHN_LOOS = 0xff20, /* First OS-specific index */ - SHN_HIOS = 0xff3f, /* Last OS-specific index */ - SHN_ABS = 0xfff1, /* Referenced by absolute values */ - SHN_COMMON = 0xfff2, /* Referenced by common values */ - SHN_XINDEX = 0xffff, /* Indirect index reference (escape value) */ - SHN_HIRESERVE = 0xffff /* Last reserved index */ -}; - -/*---------------------------------------------------------------------------*/ -/* Section Types (value of "sh_type") */ -/*---------------------------------------------------------------------------*/ -enum -{ - SHT_NULL = 0, /* Inactive section */ - SHT_PROGBITS = 1, /* Application-specific information */ - SHT_SYMTAB = 2, /* Symbol table */ - SHT_STRTAB = 3, /* String table */ - SHT_RELA = 4, /* Relocation entries (explicit addends) */ - SHT_HASH = 5, /* Symbol hash table */ - SHT_DYNAMIC = 6, /* Dynamic linking information */ - SHT_NOTE = 7, /* Miscellaneous information */ - SHT_NOBITS = 8, /* Contains no data in file */ - SHT_REL = 9, /* Relocation entries (no expl. addends) */ - SHT_SHLIB = 10, /* Shared library */ - SHT_DYNSYM = 11, /* Dynamic symbol table */ - SHT_INIT_ARRAY = 14, /* Pointers to initialization functions */ - SHT_FINI_ARRAY = 15, /* Pointers to termination functions */ - SHT_PREINIT_ARRAY = 16, /* Pointers to pre-init functions */ - SHT_GROUP = 17, /* Section group */ - SHT_SYMTAB_SHNDX = 18, /* Section indexes for SHN_XINDEX refs. */ - SHT_LOOS = 0x60000000, /* First OS-specific type */ - SHT_HIOS = 0x6fffffff, /* Last OS-specific type */ - SHT_LOPROC = 0x70000000, /* First processor-specific type */ - SHT_HIPROC = 0x7fffffff, /* Last processor-specific type */ - SHT_LOUSER = 0x80000000, /* First application-specific type */ - SHT_HIUSER = 0xffffffff /* Last application-specific type */ -}; - -/*---------------------------------------------------------------------------*/ -/* Section Attribute Flags (value of "sh_flags") */ -/*---------------------------------------------------------------------------*/ -enum -{ - SHF_WRITE = 0x1, /* Writable during process execution */ - SHF_ALLOC = 0x2, /* Loaded into processor memory */ - SHF_EXECINSTR = 0x4, /* Contains executable instructions */ - SHF_MERGE = 0x10, /* Can be merged */ - SHF_STRINGS = 0x20, /* Contains null-terminated strings */ - SHF_INFO_LINK = 0x40, /* sh_info contains a section index */ - SHF_LINK_ORDER = 0x80, /* Maintain section ordering */ - SHF_OS_NONCONFORMING = 0x100, /* OS-specific processing required */ - SHF_GROUP = 0x200, /* Member of a section group */ - SHF_TLS = 0x400, /* Contains Thread-Local Storage */ - SHF_MASKOS = 0x0ff00000, /* Mask of OS-specific flags */ - SHF_MASKPROC = 0xf0000000 /* Mask for processor-specific flags */ -}; - -/*---------------------------------------------------------------------------*/ -/* Section Group Flags */ -/*---------------------------------------------------------------------------*/ -enum -{ - GRP_COMDAT = 0x1, /* Common data; only one is kept by linker */ - GRP_MASKOS = 0x0ff00000, /* Mask for OS-specific group flags */ - GRP_MASKPROC = 0xf0000000 /* Mask for processor-specific group flags */ -}; - - -/*****************************************************************************/ -/* Symbol Table */ -/* PP. 1-18 */ -/*****************************************************************************/ - -/*---------------------------------------------------------------------------*/ -/* Symbol Table Entry Data Structure */ -/*---------------------------------------------------------------------------*/ -struct Elf32_Sym -{ - Elf32_Word st_name; /* String table offset for symbol name */ - Elf32_Addr st_value; /* Symbol value */ - Elf32_Word st_size; /* Symbol size */ - uint8_t st_info; /* Symbol type and binding */ - uint8_t st_other; /* Symbol visibility */ - Elf32_Half st_shndx; /* Symbol type / defining section */ -}; - -/*---------------------------------------------------------------------------*/ -/* Undefined Symbol Index */ -/*---------------------------------------------------------------------------*/ -enum -{ - STN_UNDEF = 0 /* First symbol table entry is always undefined */ -}; - -/*---------------------------------------------------------------------------*/ -/* Symbol Binding and Type Utility Functions. */ -/*---------------------------------------------------------------------------*/ -static inline uint8_t ELF32_ST_BIND(uint8_t i) { return (i >> 4); } -static inline uint8_t ELF32_ST_TYPE(uint8_t i) { return (i & 0xf); } -static inline uint8_t ELF32_ST_INFO(uint8_t b, uint8_t t) - { return ((b << 4) + (t & 0xf)); } -static inline uint8_t ELF32_ST_VISIBILITY(uint8_t o) { return (o & 0x3); } - - -/*---------------------------------------------------------------------------*/ -/* Symbol Binding (value returned by ELF32_ST_BIND()) */ -/*---------------------------------------------------------------------------*/ -enum -{ - STB_LOCAL = 0, /* Symbol does not have external linkage */ - STB_GLOBAL = 1, /* Symbol has external linkage */ - STB_WEAK = 2, /* Symbol has weak external linkage */ - STB_LOOS = 10, /* First OS-specific binding */ - STB_HIOS = 12, /* Last OS-specific binding */ - STB_LOPROC = 13, /* First processor-specific binding */ - STB_HIPROC = 15 /* Last processor-specific binding */ -}; - -/*---------------------------------------------------------------------------*/ -/* Symbol Types (value returned by ELF32_ST_TYPE()) */ -/*---------------------------------------------------------------------------*/ -enum -{ - STT_NOTYPE = 0, /* Unspecified type */ - STT_OBJECT = 1, /* Associated with a data object */ - STT_FUNC = 2, /* Associated with executable code */ - STT_SECTION = 3, /* Associated with a section */ - STT_FILE = 4, /* Associated with a source file */ - STT_COMMON = 5, /* Labels an uninitialized common block */ - STT_TLS = 6, /* Specifies a thread-local storage entity */ - STT_LOOS = 10, /* First OS-specific type */ - STT_HIOS = 12, /* Last OS-specific type */ - STT_LOPROC = 13, /* First processor-specific type */ - STT_HIPROC = 15 /* Last processor-specific type */ -}; - -/*---------------------------------------------------------------------------*/ -/* Symbol Visibility (value returned by ELF32_ST_VISIBILITY()) */ -/*---------------------------------------------------------------------------*/ -enum -{ - STV_DEFAULT = 0, /* Visibility specified by binding type */ - STV_INTERNAL = 1, /* Like STV_HIDDEN, with processor-specific semantics */ - STV_HIDDEN = 2, /* Not visible to other components */ - STV_PROTECTED = 3 /* Visible in other components but not preemptable */ -}; - -/*****************************************************************************/ -/* Relocation */ -/* PP. 1-22 */ -/*****************************************************************************/ - -/*---------------------------------------------------------------------------*/ -/* Relocation Entries Data Structures */ -/*---------------------------------------------------------------------------*/ -struct Elf32_Rel -{ - Elf32_Addr r_offset; /* Offset of the relocatable value in the section */ - Elf32_Word r_info; /* Symbol table index and relocation type */ -}; - -struct Elf32_Rela -{ - Elf32_Addr r_offset; /* Offset of the relocatable value in the section */ - Elf32_Word r_info; /* Symbol table index and relocation type */ - Elf32_Sword r_addend; /* Constant addend used to compute new value */ -}; - -/*---------------------------------------------------------------------------*/ -/* Relocation Symbol and Type Utility Functions. */ -/*---------------------------------------------------------------------------*/ -static inline uint32_t ELF32_R_SYM(uint32_t i) { return (i >> 8); } -static inline uint8_t ELF32_R_TYPE(uint32_t i) { return (i & 0xFF); } -static inline uint32_t ELF32_R_INFO(uint32_t s, uint8_t t) - { return ((s << 8) + t); } - - -/*****************************************************************************/ -/* Dynamic Section */ -/* PP. 2-8 */ -/*****************************************************************************/ -struct Elf32_Dyn -{ - Elf32_Sword d_tag; - union - { - Elf32_Word d_val; - Elf32_Addr d_ptr; - } d_un; -}; - -/* Name Value d_un Executable Shared Obj. */ -/* ---- ----- ---- ---------- ----------- */ -enum -{ - DT_NULL = 0, /* ignored mandatory mandatory */ - DT_NEEDED = 1, /* d_val optional optional */ - DT_PLTRELSZ = 2, /* d_val optional optional */ - DT_PLTGOT = 3, /* d_ptr optional optional */ - DT_HASH = 4, /* d_ptr mandatory mandatory */ - DT_STRTAB = 5, /* d_ptr mandatory mandatory */ - DT_SYMTAB = 6, /* d_ptr mandatory mandatory */ - DT_RELA = 7, /* d_ptr mandatory optional */ - DT_RELASZ = 8, /* d_val mandatory optional */ - DT_RELAENT = 9, /* d_val mandatory optional */ - DT_STRSZ = 10, /* d_val mandatory mandatory */ - DT_SYMENT = 11, /* d_val mandatory mandatory */ - DT_INIT = 12, /* d_ptr optional optional */ - DT_FINI = 13, /* d_ptr optional optional */ - DT_SONAME = 14, /* d_val ignored optional */ - DT_RPATH = 15, /* d_val optional ignored */ - DT_SYMBOLIC = 16, /* ignored ignored optional */ - DT_REL = 17, /* d_ptr mandatory optional */ - DT_RELSZ = 18, /* d_val mandatory optional */ - DT_RELENT = 19, /* d_val mandatory optional */ - DT_PLTREL = 20, /* d_val optional optional */ - DT_DEBUG = 21, /* d_ptr optional ignored */ - DT_TEXTREL = 22, /* ignored optional optional */ - DT_JMPREL = 23, /* d_ptr optional optional */ - DT_BIND_NOW = 24, /* ignored optional optional */ - DT_INIT_ARRAY = 25, /* d_ptr optional optional */ - DT_FINI_ARRAY = 26, /* d_ptr optional optional */ - DT_INIT_ARRAYSZ = 27, /* d_val optional optional */ - DT_FINI_ARRAYSZ = 28, /* d_val optional optional */ - DT_RUNPATH = 29, /* d_val optional optional */ - DT_FLAGS = 30, /* d_val optional optional */ - DT_ENCODING = 32, /* unspecified unspecified unspecified */ - DT_PREINIT_ARRAY = 32, /* d_ptr optional ignored */ - DT_PREINIT_ARRAYSZ = 33, /* d_val optional ignored */ - DT_LOOS = 0x60000000, /* unspecified unspecified unspecified */ - DT_HIOS = 0x6ffff000, /* unspecified unspecified unspecified */ - DT_LOPROC = 0x70000000, /* unspecified unspecified unspecified */ - DT_HIPROC = 0x7fffffff /* unspecified unspecified unspecified */ -}; - - -/*---------------------------------------------------------------------------*/ -/* DT_FLAGS values. */ -/*---------------------------------------------------------------------------*/ -enum -{ - DF_ORIGIN = 0x01, /* loaded object may reference $ORIGIN subst. string */ - DF_SYMBOLIC = 0x02, /* changes dynamic linker symbol resolution */ - DF_TEXTREL = 0x04, /* do not allow relocation of non-writable segments */ - DF_BIND_NOW = 0x08, /* don't use lazy binding */ - DF_STATIC_TLS = 0x10, /* do not load this file dynamically */ - DF_DIRECT_DEPENDENT = 0x20, /* limit global sym lookup to dependent list */ - DF_WORLD = 0x40 /* Linux style global sym lookup, breadth-first */ -}; - - -/*---------------------------------------------------------------------------*/ -/* Dynamic Tag Database. */ -/*---------------------------------------------------------------------------*/ - -/* Specifiers for which d_un union member to use */ - -enum -{ - EDYN_UNTYPE_IGNORED, - EDYN_UNTYPE_VAL, - EDYN_UNTYPE_PTR, - EDYN_UNTYPE_UNSPECIFIED -}; - - -/* Specifiers for executable/shared object file requirements */ - -enum -{ - EDYN_TAGREQ_IGNORED, - EDYN_TAGREQ_MANDATORY, - EDYN_TAGREQ_OPTIONAL, - EDYN_TAGREQ_UNSPECIFIED -}; - - -/* Data structure for one dynamic tag database entry */ - -struct EDYN_TAG -{ - const char* d_tag_name; /* tag name string */ - Elf32_Sword d_tag_value; /* DT_* tag value */ - Elf32_Word d_untype; /* which d_un union member to use */ - Elf32_Word d_exec_req; /* requirement for executable files */ - Elf32_Word d_shared_req; /* requirement for shared object files */ -}; - -extern const struct EDYN_TAG EDYN_TAG_DB[]; - -/*****************************************************************************/ -/* Special Section Database */ -/*****************************************************************************/ - -/*---------------------------------------------------------------------------*/ -/* Special Section Names */ -/*---------------------------------------------------------------------------*/ -#define ESCN_BSS_name ".bss" -#define ESCN_COMMENT_name ".comment" -#define ESCN_DATA1_name ".data1" -#define ESCN_DATA_name ".data" -#define ESCN_DEBUG_name ".debug" -#define ESCN_DYNAMIC_name ".dynamic" -#define ESCN_DYNSTR_name ".dynstr" -#define ESCN_DYNSYM_name ".dynsym" -#define ESCN_FINI_ARRAY_name ".fini_array" -#define ESCN_FINI_name ".fini" -#define ESCN_GOT_name ".got" -#define ESCN_HASH_name ".hash" -#define ESCN_INIT_ARRAY_name ".init_array" -#define ESCN_INIT_name ".init" -#define ESCN_INTERP_name ".interp" -#define ESCN_LINE_name ".line" -#define ESCN_NOTE_name ".note" -#define ESCN_PLT_name ".plt" -#define ESCN_PREINIT_ARRAY_name ".preinit_array" -#define ESCN_RELA_name ".rela" -#define ESCN_REL_name ".rel" -#define ESCN_RODATA1_name ".rodata1" -#define ESCN_RODATA_name ".rodata" -#define ESCN_SHSTRTAB_name ".shstrtab" -#define ESCN_STRTAB_name ".strtab" -#define ESCN_SYMTAB_SHNDX_name ".symtab_shndx" -#define ESCN_SYMTAB_name ".symtab" -#define ESCN_TBSS_name ".tbss" -#define ESCN_TDATA1_name ".tdata1" -#define ESCN_TDATA_name ".tdata" -#define ESCN_TEXT_name ".text" -#define ESCN_ATTRIBUTES_name "__TI_build_attributes" -#define ESCN_ICODE_name "__TI_ICODE" -#define ESCN_XREF_name "__TI_XREF" - -/*---------------------------------------------------------------------------*/ -/* Special Section Information Data Structure. */ -/*---------------------------------------------------------------------------*/ -struct ESCN -{ - const char *name; - Elf32_Word sh_type; - Elf32_Word sh_entsize; - Elf32_Word sh_flags; -}; - -extern const struct ESCN ESCN_DB[]; - -#endif /* ELF32_H */ diff --git a/src/utils/elfload/include/relocate.h b/src/utils/elfload/include/relocate.h deleted file mode 100644 index 21ef73f..0000000 --- a/src/utils/elfload/include/relocate.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* relocate.h */ -/* */ -/* Declare names and IDs of all C6x relocation types supported in the */ -/* dynamic loader. Note that this list must be kept in synch with the */ -/* C6x relocation engine files in the other object development tools. */ -/*****************************************************************************/ -#ifndef RELOCATE_H -#define RELOCATE_H - -#include -#include "elf32.h" -#include "dload.h" -#include "dload_api.h" - -/*---------------------------------------------------------------------------*/ -/* Declare some globals that are used for internal debugging and profiling. */ -/*---------------------------------------------------------------------------*/ -#if LOADER_DEBUG || LOADER_PROFILE -#include -extern int DLREL_relocations; -extern time_t DLREL_total_reloc_time; -#endif - - -/*---------------------------------------------------------------------------*/ -/* Landing point for core loader's relocation processor. */ -/*---------------------------------------------------------------------------*/ -void DLREL_relocate(DLOAD_HANDLE handle, LOADER_FILE_DESC *elf_file, - DLIMP_Dynamic_Module *dyn_module); - -void DLREL_relocate_c60(DLOAD_HANDLE handle, LOADER_FILE_DESC *fd, - DLIMP_Dynamic_Module *dyn_module); - -#endif diff --git a/src/utils/elfload/include/std_linux.h b/src/utils/elfload/include/std_linux.h deleted file mode 100644 index 131e95d..0000000 --- a/src/utils/elfload/include/std_linux.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/** ============================================================================ - * @file std_linux.h - * - * @brief TODO - * - * ============================================================================ - */ - -#if !defined(STD_LINUX_H) -#define STD_LINUX_H - -#include - - -#endif /* if !defined(STD_LINUX_H) */ diff --git a/src/utils/elfload/include/symtab.h b/src/utils/elfload/include/symtab.h deleted file mode 100644 index b419479..0000000 --- a/src/utils/elfload/include/symtab.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* symtab.h */ -/* */ -/* Specification of functions used by the core loader to create, maintain, */ -/* and destroy internal symbol tables. */ -/*****************************************************************************/ -#ifndef SYMTAB_H -#define SYMTAB_H - -#include "ArrayList.h" -#include "dload.h" - -/*****************************************************************************/ -/* This is the top-level application file handle. It should only be needed */ -/* under the Linux and DSBT models. */ -/*****************************************************************************/ -extern int32_t DLIMP_application_handle; - -/*---------------------------------------------------------------------------*/ -/* Core Loader Symbol Table Management Functions */ -/*---------------------------------------------------------------------------*/ -BOOL DLSYM_canonical_lookup(DLOAD_HANDLE handle, - int32_t sym_index, - DLIMP_Dynamic_Module *dyn_module, - Elf32_Addr *sym_value); - -BOOL DLSYM_global_lookup(DLOAD_HANDLE handle, - const char *sym_name, - DLIMP_Loaded_Module *pentry, - Elf32_Addr *sym_value); - -BOOL DLSYM_lookup_local_symtab(const char *sym_name, - struct Elf32_Sym *symtab, - Elf32_Word symnum, - Elf32_Addr *sym_value); - -void DLSYM_copy_globals(DLIMP_Dynamic_Module *dyn_module); - -BOOL DLSYM_lookup_global_symtab(const char *sym_name, struct Elf32_Sym *symtab, - Elf32_Word symnum, Elf32_Addr *sym_value); - -#endif diff --git a/src/utils/elfload/include/util.h b/src/utils/elfload/include/util.h deleted file mode 100644 index 7acca35..0000000 --- a/src/utils/elfload/include/util.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* util.h */ -/* */ -/* Definition of some useful string comparison routines (not */ -/* not provided on all platforms) and a few generic macros. */ -/* */ -/*****************************************************************************/ -#ifndef UTIL_H -#define UTIL_H - -#include - - -/*****************************************************************************/ -/* Define MIN and MAX macros. */ -/*****************************************************************************/ -#define MIN(x,y) (((x) > (y)) ? (y) : (x)) -#define MAX(x,y) (((x) >= (y)) ? (x) : (y)) - -/*****************************************************************************/ -/* C implementation of 'bool' type. */ -/*****************************************************************************/ -typedef int BOOL; -#define TRUE 1 -#define FALSE 0 - -#endif diff --git a/src/utils/elfload/symtab.c b/src/utils/elfload/symtab.c deleted file mode 100644 index 890dc27..0000000 --- a/src/utils/elfload/symtab.c +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Syslink-IPC for TI OMAP Processors - * - * Copyright (c) 2008-2010, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*****************************************************************************/ -/* symtab.c */ -/* */ -/* Symbol table creation, maintenance, and management. This module also */ -/* contains implementations of local and global symbol table lookup */ -/* algorithms, as appropriate for the platform that we are running on */ -/* (assumed to be Braveheart or Linux, indicated by direct_dependent_only */ -/* flag in a given Module). */ -/*****************************************************************************/ -#include "elf32.h" -#include "ArrayList.h" - -/*---------------------------------------------------------------------------*/ -/* Set up a Queue of Int32 type data objects. */ -/*---------------------------------------------------------------------------*/ -#include "Queue.h" -TYPE_QUEUE_DEFINITION(int32_t, Int32) -TYPE_QUEUE_IMPLEMENTATION(int32_t, Int32) - -#include "symtab.h" -#include "dload_api.h" -#include -#include -#include - -/*---------------------------------------------------------------------------*/ -/* Holds the handle of the ET_EXEC-type mmodule loaded, if any. */ -/*---------------------------------------------------------------------------*/ -int32_t DLIMP_application_handle = 0; - -/*****************************************************************************/ -/* DLSYM_COPY_GLOBALS() - Copy global symbols from the dynamic module's */ -/* symbol table to the loader's global symbol table. */ -/*****************************************************************************/ -void DLSYM_copy_globals(DLIMP_Dynamic_Module *dyn_module) -{ - Elf32_Word i, global_index, global_symnum; - DLIMP_Loaded_Module *module = dyn_module->loaded_module; - -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("DLSYM_copy_globals:\n"); -#endif - - /*-----------------------------------------------------------------------*/ - /* The dynamic symbol table is sorted so that the local symbols come */ - /* before the global symbols. gsymtab_offset points to the address where */ - /* the first global symbol starts. Only the global symbols need to be */ - /* copied into the persistent info. */ - /*-----------------------------------------------------------------------*/ - global_index = dyn_module->gsymtab_offset / sizeof(struct Elf32_Sym); - global_symnum = dyn_module->symnum - global_index; - - /*-----------------------------------------------------------------------*/ - /* Create space for the new global symbol table. */ - /*-----------------------------------------------------------------------*/ - - if (module->gsymtab) - DLIF_free(module->gsymtab); - module->gsymtab = DLIF_malloc(sizeof(struct Elf32_Sym) * global_symnum); - module->gsymnum = global_symnum; - - if (module->gsymtab) - memcpy(module->gsymtab, - &dyn_module->symtab[global_index], - sizeof(struct Elf32_Sym) * global_symnum); - - /*-----------------------------------------------------------------------*/ - /* Copy the string table part that contains the global symbol names. */ - /*-----------------------------------------------------------------------*/ - if (module->gstrtab) - DLIF_free(module->gstrtab); - - module->gstrsz = dyn_module->strsz - dyn_module->gstrtab_offset; - module->gstrtab = DLIF_malloc(module->gstrsz); - - if (module->gstrtab) - memcpy(module->gstrtab, - dyn_module->strtab + dyn_module->gstrtab_offset, - module->gstrsz); - - /*-----------------------------------------------------------------------*/ - /* Update the symbol names of the global symbol entries to point to */ - /* the symbol names in the string table. */ - /* NOTE: Note that we don't set the offset into the string table. We */ - /* instead set the full address so that the st_name field can be accessed*/ - /* as char *. */ - /*-----------------------------------------------------------------------*/ - for (i = 0; i < global_symnum; i++) - { - - Elf32_Word old_offset = dyn_module->symtab[i + global_index].st_name - - (Elf32_Addr) dyn_module->strtab; - Elf32_Word new_offset = old_offset - dyn_module->gstrtab_offset; - if(module->gsymtab) { - struct Elf32_Sym *sym = &((struct Elf32_Sym*)(module->gsymtab))[i]; - sym->st_name = new_offset + (Elf32_Addr)module->gstrtab; - } -#if LOADER_DEBUG - if (debugging_on) DLIF_trace("Copying symbol: %s\n", (char *) - dyn_module->symtab[i + global_index].st_name); -#endif - } -} - -/*****************************************************************************/ -/* BREADTH_FIRST_LOOKUP() - Perform a breadth-first search of the Module */ -/* dependency graph to find specified symbol name (sym_name). */ -/*****************************************************************************/ -static BOOL breadth_first_lookup(DLOAD_HANDLE phandle, - const char* sym_name, - int handle, - Elf32_Addr *sym_value) -{ - /*-----------------------------------------------------------------------*/ - /* We start this function by putting the specified file handle on the */ - /* file_handle_queue. */ - /*-----------------------------------------------------------------------*/ - Int32_Queue file_handle_queue; - Int32_initialize_queue(&file_handle_queue); - Int32_enqueue(&file_handle_queue, handle); - LOADER_OBJECT *dHandle = (LOADER_OBJECT *)phandle; - - /*-----------------------------------------------------------------------*/ - /* While the queue is not empty, keep looking for the symbol. */ - /*-----------------------------------------------------------------------*/ - while(file_handle_queue.size) - { - int i; - - /*-------------------------------------------------------------------*/ - /* Set up a pointer to front of the list of loaded files so that we */ - /* can be sure that dependent files will be searched in load order. */ - /*-------------------------------------------------------------------*/ - loaded_module_ptr_Queue_Node* mod_node = - dHandle->DLIMP_loaded_objects.front_ptr; - int* dependencies = (int*)(mod_node->value->dependencies.buf); - - /*-------------------------------------------------------------------*/ - /* Pluck off the file handle at the front of the file_handle_queue. */ - /* We will search this file next. */ - /*-------------------------------------------------------------------*/ - handle = Int32_dequeue(&file_handle_queue); - - /*-------------------------------------------------------------------*/ - /* Locate the Module associated with the current file handle. */ - /*-------------------------------------------------------------------*/ - while (mod_node->value->file_handle != handle) mod_node++; - - /*-------------------------------------------------------------------*/ - /* Search the symbol table of the current file handle's Module. */ - /* If the symbol was found, then we're finished. */ - /*-------------------------------------------------------------------*/ - if (DLSYM_lookup_global_symtab(sym_name, - mod_node->value->gsymtab, - mod_node->value->gsymnum, - sym_value)) - return TRUE; - - /*-------------------------------------------------------------------*/ - /* If our symbol was not in the current Module, then add this */ - /* Module's dependents to the end of the file_handle_queue. */ - /*-------------------------------------------------------------------*/ - for (i = 0; i < mod_node->value->dependencies.size; i++) - Int32_enqueue(&file_handle_queue, dependencies[i]); - } - - /*------------------------------------------------------------------------*/ - /* We didn't find our symbol; return FALSE. */ - /*------------------------------------------------------------------------*/ - return FALSE; -} - -/*****************************************************************************/ -/* DLSYM_global_lookup() - Search the global symbol table to find the */ -/* definition of the given symbol name. */ -/*****************************************************************************/ -BOOL DLSYM_global_lookup(DLOAD_HANDLE handle, - const char *sym_name, - DLIMP_Loaded_Module *loaded_module, - Elf32_Addr *sym_value) -{ - int i = 0; - loaded_module_ptr_Queue_Node* node; - LOADER_OBJECT *dHandle = (LOADER_OBJECT *)handle; - -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("DLSYM_global_lookup: %s\n", sym_name); -#endif - - /*-----------------------------------------------------------------------*/ - /* We will choose a different lookup algorithm based on what kind of */ - /* platform we are supporting. In the Braveheart case, the global symbol*/ - /* lookup algorithm searches the base image first, followed by the */ - /* explicit children of the specified Module. */ - /*-----------------------------------------------------------------------*/ - if (loaded_module->direct_dependent_only) - { - int* child_handle = (int*)(loaded_module->dependencies.buf); - - /*-------------------------------------------------------------------*/ - /* Spin through list of this Module's dependencies (anything on its */ - /* DT_NEEDED list), searching through each dependent's symbol table */ - /* to find the symbol we are after. */ - /*-------------------------------------------------------------------*/ - for (i = 0; i < loaded_module->dependencies.size; i++) - { - for (node = dHandle->DLIMP_loaded_objects.front_ptr; - node->value->file_handle != child_handle[i]; - node=node->next_ptr); - - /*---------------------------------------------------------------*/ - /* Return true if we find the symbol. */ - /*---------------------------------------------------------------*/ - if (DLSYM_lookup_global_symtab(sym_name, - node->value->gsymtab, - node->value->gsymnum, - sym_value)) - return TRUE; - } - } - - /*-----------------------------------------------------------------------*/ - /* In the LINUX model, we will use a breadth-first global symbol lookup */ - /* algorithm. First, the application's global symbol table is searched, */ - /* followed by its children, followed by their children, and so on. */ - /* It is up to the client of this module to set the application handle. */ - /*-----------------------------------------------------------------------*/ - else - { - if (breadth_first_lookup(handle, sym_name, DLIMP_application_handle, - sym_value)) - return TRUE; - } - - /*-----------------------------------------------------------------------*/ - /* If we got this far, then symbol was not found. */ - /*-----------------------------------------------------------------------*/ - DLIF_error(DLET_SYMBOL, "Could not resolve symbol %s!\n", sym_name); - - return FALSE; -} - -/*****************************************************************************/ -/* DLSYM_lookup_symtab() - Lookup the symbol name in the given symbol table. */ -/* Symbol must have specified binding. Return the */ -/* value in sym_value and return TRUE if the lookup */ -/* succeeds. */ -/*****************************************************************************/ -static BOOL DLSYM_lookup_symtab(const char *sym_name, struct Elf32_Sym *symtab, - Elf32_Word symnum, Elf32_Addr *sym_value, - BOOL require_local_binding) -{ - Elf32_Addr sym_idx; - for (sym_idx = 0; sym_idx < symnum; sym_idx++) - { -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("DLSYM_lookup_symtab %s\n", - (char *)symtab[sym_idx].st_name); -#endif - - if ((symtab[sym_idx].st_shndx != SHN_UNDEF) && - ((require_local_binding && - (ELF32_ST_BIND(symtab[sym_idx].st_info) == STB_LOCAL)) || - (!require_local_binding && - (ELF32_ST_BIND(symtab[sym_idx].st_info) != STB_LOCAL))) && - !strcmp(sym_name,(char*)(symtab[sym_idx].st_name))) - { - if (sym_value) *sym_value = symtab[sym_idx].st_value; - return TRUE; - - } - } - if (sym_value) *sym_value = 0; - return FALSE; -} - -/*****************************************************************************/ -/* DLSYM_lookup_global_symtab() - Lookup the symbol name in the given symbol */ -/* table. Symbol must have global binding. */ -/* Return the value in sym_value and return */ -/* TRUE if the lookup succeeds. */ -/*****************************************************************************/ -BOOL DLSYM_lookup_global_symtab(const char *sym_name, struct Elf32_Sym *symtab, - Elf32_Word symnum, Elf32_Addr *sym_value) -{ - return DLSYM_lookup_symtab(sym_name, symtab, symnum, sym_value, FALSE); -} - -/*****************************************************************************/ -/* DLSYM_lookup_local_symtab() - Lookup the symbol name in the given symbol */ -/* table. Symbol must have local binding. */ -/* Return the value in sym_value and return */ -/* TRUE if the lookup succeeds. */ -/*****************************************************************************/ -BOOL DLSYM_lookup_local_symtab(const char *sym_name, struct Elf32_Sym *symtab, - Elf32_Word symnum, Elf32_Addr *sym_value) -{ - return DLSYM_lookup_symtab(sym_name, symtab, symnum, sym_value, TRUE); -} - -/*****************************************************************************/ -/* CANONICAL_SYMBOL_LOOKUP() - Find the symbol definition. Look up the local */ -/* symbol table to find the symbol. If it is a */ -/* definition and cannot be pre-empted, return */ -/* it. Otherwise, do a look up in the global */ -/* symbol table that contains the symbol tables */ -/* from all the necessary modules. */ -/*****************************************************************************/ -BOOL DLSYM_canonical_lookup(DLOAD_HANDLE handle, - int sym_index, - DLIMP_Dynamic_Module *dyn_module, - Elf32_Addr *sym_value) -{ - /*-----------------------------------------------------------------------*/ - /* Lookup the symbol table to get the symbol characteristics. */ - /*-----------------------------------------------------------------------*/ - struct Elf32_Sym *sym = &dyn_module->symtab[sym_index]; - int32_t st_bind = ELF32_ST_BIND(sym->st_info); - int32_t st_vis = ELF32_ST_VISIBILITY(sym->st_other); - BOOL is_def = (sym->st_shndx != SHN_UNDEF && - (sym->st_shndx < SHN_LORESERVE || - sym->st_shndx == SHN_XINDEX)); - const char *sym_name = (char *)sym->st_name; - -#if LOADER_DEBUG - if (debugging_on) - DLIF_trace("DLSYM_canonical_lookup: %d, %s\n", sym_index, sym_name); -#endif - - /*-----------------------------------------------------------------------*/ - /* Local symbols and symbol definitions that cannot be pre-empted */ - /* are resolved by the definition in the same module. */ - /*-----------------------------------------------------------------------*/ - if (st_bind == STB_LOCAL || st_vis != STV_DEFAULT) - { - /*-------------------------------------------------------------------*/ - /* If it is a local symbol or non-local that cannot be preempted, */ - /* the definition should be found in the same module. If we don't */ - /* find the definition it is an error. */ - /*-------------------------------------------------------------------*/ - if (!is_def) - { - DLIF_error(DLET_SYMBOL, - "Local/non-imported symbol %s definition is not found " - "in module %s!\n", sym_name, dyn_module->name); - return FALSE; - } - else - { - if (sym_value) *sym_value = sym->st_value; - return TRUE; - } - } - /*-----------------------------------------------------------------------*/ - /* Else we have either pre-emptable defintion or undef symbol. We need */ - /* to do global look up. */ - /*-----------------------------------------------------------------------*/ - else - { - return DLSYM_global_lookup(handle, sym_name, dyn_module->loaded_module, - sym_value); - } -} diff --git a/src/utils/genrprc b/src/utils/genrprc deleted file mode 100755 index 5895a1b..0000000 --- a/src/utils/genrprc +++ /dev/null @@ -1,264 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2011, Texas Instruments Incorporated -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of Texas Instruments Incorporated nor the names of -# its contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -#=============================================================================== -# -# Usage: genrprc [--e0=core0 entry point] [--e1=core1 entry point] -# [--t0=core0 trace buffer symbol] [--t1=core1 trace buffer symbol] -# core0_filename [core1_filename] output_filename -# -# Default values for: -# core0 entry point: "Entry point address:" field from output of -# 'readelf -h core0_filename' -# core1 entry point: "Entry point address:" field from output of -# 'readelf -h core1_filename' -# core0 trace buffer symbol: SysMin_Module_State_0_outbuf__A -# core1 trace buffer symbol: SysMin_Module_State_0_outbuf__A -# -#=============================================================================== - -usage=\ -"Usage: genrprc [--e0=core0 entry point] [--e1=core1 entry point] - [--t0=core0 trace buffer symbol] [--t1=core1 trace buffer symbol] - core0_filename [core1_filename] output_filename" - -PATH=$PATH:. - -tracename0=SysMin_Module_State_0_outbuf__A -tracename1=SysMin_Module_State_0_outbuf__A -entryname0= -entryname1= - -cmdline=`getopt -o "" --long e0:,e1:,t0:,t1: --name $0 -- "$@"` -err=$? -if [[ $err != 0 ]] -then - echo getopt returned $err - echo $usage - exit 1 -fi - -# set new positional parameters with all options placed before script args -eval set -- "$cmdline" -while true ; do - case "$1" in - --e0) entryname0=$2; shift 2;; - --e1) entryname1=$2; shift 2;; - --t0) tracename0=$2; shift 2;; - --t1) tracename1=$2; shift 2;; - --) shift; break;; - esac -done - -if [[ $# == 3 ]] -then - core0file=$1 - core1file=$2 - outfile=$3 - shift 3 - - traceaddr0=`nm $core0file | grep $tracename0 | cut -d ' ' -f 1` - traceaddr1=`nm $core1file | grep $tracename1 | cut -d ' ' -f 1` - if [[ $entryname0 == "" ]] - then - entryaddr0=`readelf -h $core0file | \ - grep "Entry point address" | awk '{printf($4)}'` - else - entryaddr0=`nm $core0file | \ - grep $entryname0 | awk '{printf($1)}'` - fi - if [[ $entryname1 == "" ]] - then - entryaddr1=`readelf -h $core1file | \ - grep "Entry point address" | awk '{printf($4)}'` - else - entryaddr1=`nm $core1file | \ - grep $entryname1 | awk '{printf($1)}'` - fi -else - if [[ $# == 2 ]] - then - core0file=$1 - outfile=$2 - shift 2 - - traceaddr0=`nm $core0file | grep $tracename0 | cut -d ' ' -f 1` - if [[ $entryname0 == "" ]] - then - entryaddr0=`readelf -h $core0file | \ - grep "Entry point address" | awk '{printf($4)}'` - else - entryaddr0=`nm $core0file | \ - grep $entryname0 | awk '{printf($1)}'` - fi - else - echo $usage - exit 1 - fi -fi - -if [[ $entryaddr0 == "" ]] -then - echo warning: null entry point for core 0 -fi -if [[ $entryaddr1 == "" ]] -then - echo warning: null entry point for core 1 -fi -if [[ $traceaddr0 == "" ]] -then - echo warning: null trace buffer address for core 0 -fi -if [[ $traceaddr1 == "" ]] -then - echo warning: null trace buffer address for core 1 -fi - -file_info=`file $outfile` -foo=`echo $file_info | grep executable` -# -# Make sure we don't overwrite executable. -# User might have mistakenly forgotten to specify output file name. -# -if [[ $foo != "" ]] -then - echo error: output file \'$outfile\' is of type \"executable\" but should be a data file - echo $usage - exit 1 -fi - -tmp=/tmp/genrprc-$$ - -echo mkheader $core0file $core1file $outfile -mkheader $core0file $core1file $outfile -if [[ $? != 0 ]] -then - echo mkheader failed - echo $usage - exit 1 -fi - -# -# genbase (invoked below) accepts any number of "key:value" tags on its -# command invocation. Today, the supported tags are: -# restab: -# trace[0-9]: -# entry[0-9]: -# where is an address in hexadecimal form w/ or w/o leading "0x", -# and the [0-9] field specifies a "core number". -# -# restab is the key name for the (possibly nonexistant) .resource_table -# linker section, and its value is the section's address. When genbase -# encounters a linker section whose address matches the restab value, it -# calls a special resource table processing function for that section. -# -# trace[0-9] is the key name for core 0's executable file's trace buffer, -# and its value is the trace buffer's address. When genbase encounters -# a resource (from the .resource_table table) of type TRACE it assigns -# that resource's "base" element to the value of key trace[0-9] (the 1st -# type TRACE resource gets the value of trace0, the 2nd type TRACE resource -# gets the value of trace1, etc.). -# -# entry[0-9] is the key name for core 0's executable file's entry point, -# and its value is the entry point's address. When genbase encounters -# a resource (from the .resource_table table) of type ENTRYPOINT it assigns -# that resource's "base" element to the value of key entry[0-9] (the 1st -# type ENTRYPOINT resource gets the value of entry0, the 2nd type ENTRYPOINT -# resource gets the value of entry1, etc.). -# - -if [[ $traceaddr0 == "" ]] -then - trace0= -else - trace0="trace0:$traceaddr0" -fi -if [[ $traceaddr1 == "" ]] -then - trace1= -else - trace1="trace1:$traceaddr1" -fi -if [[ $entryaddr0 == "" ]] -then - entry0= -else - entry0="entry0:$entryaddr0" -fi -if [[ $entryaddr1 == "" ]] -then - entry1= -else - entry1="entry1:$entryaddr1" -fi - - -if [[ -f $core0file ]] -then - resource_tab=`readelf -S $core0file | \ - awk '{if ($2==".resource_table") printf("%s", $4)}'` - if [[ $resource_tab == "" ]] - then - echo no .resource_tab section found in $core0file - echo genbase $core0file $tmp $* - genbase $core0file $tmp $* - else - echo genbase $core0file $tmp $* restab:$resource_tab \ - $trace0 $trace1 $entry0 $entry1 - genbase $core0file $tmp $* restab:$resource_tab \ - $trace0 $trace1 $entry0 $entry1 - fi - - cat $tmp >> $outfile - rm $tmp -fi - - -if [[ -f $core1file ]] -then - resource_tab=`readelf -S $core1file | \ - awk '{if ($2==".resource_table") printf("%s", $4)}'` - if [[ $resource_tab == "" ]] - then - echo no .resource_tab section found in $core1file - echo genbase $core1file $tmp $* - genbase $core1file $tmp $* - else - echo genbase $core1file $tmp $* restab:$resource_tab \ - $trace0 $trace1 $entry0 $entry1 - genbase $core1file $tmp $* restab:$resource_tab \ - $trace0 $trace1 $entry0 $entry1 - fi - - cat $tmp >> $outfile - rm $tmp -fi diff --git a/src/utils/mkheader b/src/utils/mkheader deleted file mode 100755 index 94e6a1b..0000000 --- a/src/utils/mkheader +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2011, Texas Instruments Incorporated -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of Texas Instruments Incorporated nor the names of -# its contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# - -if [[ $# == 3 ]] -then - corefile0=$1 - corefile1=$2 - outfile=$3 - shift 3 -else - if [[ $# == 2 ]] - then - corefile0=$1 - outfile=$2 - shift 2 - else - echo Usage: $0 core0 [core1] out >&2 - exit 1 - fi -fi - - -tmp=/tmp/singlebin-$$ -if [[ ! -f version.txt ]] -then - echo no version.txt file - exit 1 -fi - -version=`cat version.txt` -echo header version $version - -echo -n RPRC > $outfile -./wrints $version 1012 >> $outfile - -if [[ -f $corefile0 ]] -then - md5sum $corefile0 >> $outfile - stat -c "%s %z" $corefile0 >> $outfile - nm $corefile0 | grep SysMin_Module_State_0_outbuf__A | cut -d ' ' -f 1 >> $outfile -fi - -if [[ -f $corefile1 ]] -then - md5sum $corefile1 >> $outfile - stat -c "%s %z" $corefile1 >> $outfile - nm $corefile1 | grep SysMin_Module_State_0_outbuf__A | cut -d ' ' -f 1 >> $outfile -fi - -(( numbytesneeded = 1024 - $(stat -c "%s" $outfile) )) -dd if=/dev/zero of=$tmp bs=$numbytesneeded count=1 > /dev/null 2>&1 -cat $tmp >> $outfile -rm $tmp diff --git a/src/utils/readrprc.c b/src/utils/readrprc.c deleted file mode 100644 index f157f7c..0000000 --- a/src/utils/readrprc.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2011, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/* - * ======== dbg-loader.c ======== - */ - -#include -#include -#include -#include - -#include "rprcfmt.h" - -static int dump_image(void * data, int size); - -/* - * ======== main ======== - */ -int main(int argc, char * argv[]) -{ - FILE * fp; - struct stat st; - char * filename; - void * data; - int size; - int status; - - if (argc != 2) { - fprintf(stderr, "Usage: %s filename\n", argv[0]); - exit(1); - } - - filename = argv[1]; - if ((fp = fopen(filename, "rb")) == NULL) { - fprintf(stderr, "%s: could not open: %s\n", argv[0], filename); - exit(2); - } - - fstat(fileno(fp), &st); - size = st.st_size; - data = malloc(size); - fread(data, 1, size, fp); - fclose(fp); - - status = dump_image(data, size); - - free(data); - - return status; -} - -/* - * ======== dump_resources ======== - */ -static void dump_resources(struct rproc_fw_section * s) -{ - struct rproc_fw_resource * res = (struct rproc_fw_resource * )s->content; - int i; - - printf("resource table: %d\n", sizeof(struct rproc_fw_resource)); - for (i = 0; i < s->len / sizeof(struct rproc_fw_resource); i++) { - printf("resource: %d, da: 0x%8llx, pa: 0x%8llx, len: 0x%8x, name: %s\n", - res[i].type, res[i].da, res[i].pa, res[i].len, res[i].name); - } - printf("\n"); -} - -/* - * ======== dump_image ======== - */ -static int dump_image(void * data, int size) -{ - struct rproc_fw_header *hdr; - struct rproc_fw_section *s; - - hdr = (struct rproc_fw_header *)data; - - /* check that magic is what we expect */ - if (memcmp(hdr->magic, RPROC_FW_MAGIC, sizeof(hdr->magic))) { - fprintf(stderr, "invalid magic number: %.4s\n", hdr->magic); - return -1; - } - - /* baseimage information */ - printf("magic number %.4s\n", hdr->magic); - printf("header version %d\n", hdr->version); - printf("header size %d\n", hdr->header_len); - printf("header data\n%s\n", hdr->header); - - /* get the first section */ - s = (struct rproc_fw_section *)(hdr->header + hdr->header_len); - - while ((u8 *)s < (u8 *)(data + size)) { - printf("section: %d, address: 0x%8llx, size: 0x%8x\n", s->type, - s->da, s->len); - if (s->type == FW_RESOURCE) { - dump_resources(s); - } - - s = ((void *)s->content) + s->len; - } - - return 0; -} diff --git a/src/utils/readrprc.txt b/src/utils/readrprc.txt deleted file mode 100644 index db816fb..0000000 --- a/src/utils/readrprc.txt +++ /dev/null @@ -1,40 +0,0 @@ -utils.mmap> readrprc ducati-m3.bin -magic number RPRC -header version 2 -header size 1012 -header data -d727f7428de52c99f6defc76915c64dc ../ti/examples/srvmgr/ti_platform_omap4430_core0/debug/test_omx_sysm3.xem3 -3835810 2011-06-02 16:28:55.221623000 -0700 -80060000 -dc84021fdb027d761019ff1fafbb6aad ../ti/examples/srvmgr/ti_platform_omap4430_core1/debug/test_omx_appm3.xem3 -3829814 2011-06-02 16:29:19.299079000 -0700 -80160000 - -type: 1, address: 0x0, size: 0x3c -type: 2, address: 0x0, size: 0x3c -type: 2, address: 0x400, size: 0x140 -type: 2, address: 0x4000, size: 0x13428 -type: 0, address: 0x8006a000, size: 0x474 -resource table: 76 -type: 4, da: 0x80060000, pa: 0x0,len: 32768, name: 0 -type: 4, da: 0x80160000, pa: 0x0,len: 32768, name: 1 -type: 5, da: 0x106f1, pa: 0x0,len: 0, name: 0 -type: 5, da: 0x10c6c9, pa: 0x0,len: 0, name: 1 -type: 0, da: 0xa0000000, pa: 0x0,len: 1048576, name: IPU_MEM_IPC -type: 0, da: 0x0, pa: 0x0,len: 4194304, name: IPU_MEM_TEXT -type: 0, da: 0x80000000, pa: 0xb9800000,len: 100663296, name: IPU_MEM_DATA -type: 0, da: 0xaa000000, pa: 0x4a000000,len: 16777216, name: IPU_PERIPHERAL_L4CFG -type: 0, da: 0xa8000000, pa: 0x48000000,len: 16777216, name: IPU_PERIPHERAL_L4PER -type: 0, da: 0x60000000, pa: 0x60000000,len: 268435456, name: IPU_TILER_MODE_0_1 -type: 0, da: 0x70000000, pa: 0x70000000,len: 134217728, name: IPU_TILER_MODE_2 -type: 0, da: 0x78000000, pa: 0x78000000,len: 134217728, name: IPU_TILER_MODE_3 -type: 0, da: 0xba000000, pa: 0x5a000000,len: 16777216, name: IPU_IVAHD_CONFIG -type: 0, da: 0xbb000000, pa: 0x5b000000,len: 16777216, name: IPU_IVAHD_SL2 -type: 6, da: 0x0, pa: 0x0,len: 0, name: END - -type: 2, address: 0x8006bc54, size: 0x200 -type: 2, address: 0x0, size: 0x3c -type: 2, address: 0x800, size: 0x140 -type: 2, address: 0x100000, size: 0x133f0 -type: 2, address: 0x8016b7e0, size: 0x200 -utils.mmap> diff --git a/src/utils/rprcfmt.h b/src/utils/rprcfmt.h deleted file mode 100644 index 5dd0a51..0000000 --- a/src/utils/rprcfmt.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2011, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _RPROCFMT_H_ -#define _RPROCFMT_H_ - -typedef unsigned int u32; -typedef unsigned long long u64; -typedef unsigned char u8; -#define __packed __attribute__ ((packed)) - -/** - * The following enums and structures define the binary format of the images - * we load and run the remote processors with. - * - * The binary format is as follows: - * - * struct { - * char magic[4] = { 'R', 'P', 'R', 'C' }; - * u32 version; - * u32 header_len; - * char header[...] = { header_len bytes of unformatted, textual header }; - * struct sections { - * u32 type; - * u64 da; - * u32 len; - * u8 content[...] = { len bytes of binary data }; - * } [ no limit on number of sections ]; - * } __packed; - */ - -#define RPROC_FW_MAGIC "RPRC" - -enum rproc_fw_resource_type { - RSC_CARVEOUT = 0, - RSC_DEVMEM = 1, - RSC_TRACE = 2, - RSC_VRING = 3, - RSC_VIRTIO_HDR = 4, - RSC_VIRTIO_CFG = 5, -}; - -enum rproc_fw_section_type { - FW_RESOURCE = 0, - FW_TEXT = 1, - FW_DATA = 2, -}; - -struct rproc_fw_resource { - u32 type; - u32 id; - u64 da; - u64 pa; - u32 len; - u32 flags; - u8 reserved[16]; - u8 name[48]; -} __packed; - -struct rproc_fw_section { - u32 type; - u64 da; - u32 len; - char content[0]; -} __packed; - -struct rproc_fw_header { - char magic[4]; - u32 version; - u32 header_len; - char header[0]; -} __packed; - -#endif diff --git a/src/utils/version.txt b/src/utils/version.txt deleted file mode 100644 index 0cfbf08..0000000 --- a/src/utils/version.txt +++ /dev/null @@ -1 +0,0 @@ -2 diff --git a/src/utils/wrints.c b/src/utils/wrints.c deleted file mode 100644 index b085a1c..0000000 --- a/src/utils/wrints.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2011, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -int main(int argc, char * argv[]) -{ - int i; - unsigned int word; - - for (i = 1; i < argc; i++) { - word = strtoul(argv[i], NULL, 0); - fwrite(&word, 4, 1, stdout); - } - - return 0; -}