/*
* tramp.c
*
* DSP-BIOS Bridge driver support functions for TI OMAP processors.
*
* Copyright (C) 2009 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "header.h"
#if TMS32060
#include "tramp_table_c6000.c"
#endif
#define MAX_RELOS_PER_PASS 4
/*
* Function: priv_tramp_sect_tgt_alloc
* Description: Allocate target memory for the trampoline section. The
* target mem size is easily obtained as the next available address.
*/
static int priv_tramp_sect_tgt_alloc(struct dload_state *dlthis)
{
int ret_val = 0;
struct ldr_section_info *sect_info;
/* Populate the trampoline loader section and allocate it on the
* target. The section name is ALWAYS the first string in the final
* string table for trampolines. The trampoline section is always
* 1 beyond the total number of allocated sections. */
sect_info = &dlthis->ldr_sections[dlthis->allocated_secn_count];
sect_info->name = dlthis->tramp.final_string_table;
sect_info->size = dlthis->tramp.tramp_sect_next_addr;
sect_info->context = 0;
sect_info->type =
(4 << 8) | DLOAD_TEXT | DS_ALLOCATE_MASK | DS_DOWNLOAD_MASK;
sect_info->page = 0;
sect_info->run_addr = 0;
sect_info->load_addr = 0;
ret_val = dlthis->myalloc->dload_allocate(dlthis->myalloc,
sect_info,
ds_alignment
(sect_info->type));
if (ret_val == 0)
dload_error(dlthis, "Failed to allocate target memory for"
" trampoline");
return ret_val;
}
/*
* Function: priv_h2a
* Description: Helper function to convert a hex value to its ASCII
* representation. Used for trampoline symbol name generation.
*/
static u8 priv_h2a(u8 value)
{
if (value > 0xF)
return 0xFF;
if (value <= 9)
value += 0x30;
else
value += 0x37;
return value;
}
/*
* Function: priv_tramp_sym_gen_name
* Description: Generate a trampoline symbol name (ASCII) using the value
* of the symbol. This places the new name into the user buffer.
* The name is fixed in length and of the form: __$dbTR__xxxxxxxx
* (where "xxxxxxxx" is the hex value).
*/
static void priv_tramp_sym_gen_name(u32 value, char *dst)
{
u32 i;
char *prefix = TRAMP_SYM_PREFIX;
char *dst_local = dst;
u8 tmp;
/* Clear out the destination, including the ending NULL */
for (i = 0; i < (TRAMP_SYM_PREFIX_LEN + TRAMP_SYM_HEX_ASCII_LEN); i++)
*(dst_local + i) = 0;
/* Copy the prefix to start */
for (i = 0; i < strlen(TRAMP_SYM_PREFIX); i++) {
*dst_local = *(prefix + i);
dst_local++;
}
/* Now convert the value passed in to a string equiv of the hex */
for (i = 0; i < sizeof(value); i++) {
#ifndef _BIG_ENDIAN
tmp = *(((u8 *) &value) + (sizeof(value) - 1) - i);
*dst_local = priv_h2a((tmp & 0xF0) >> 4);
dst_local++;
*dst_local = priv_h2a(tmp & 0x0F);
dst_local++;
#else
tmp = *(((u8 *) &value) + i);
*dst_local = priv_h2a((tmp & 0xF0) >> 4);
dst_local++;
*dst_local = priv_h2a(tmp & 0x0F);
dst_local++;
#endif
}
/* NULL terminate */
*dst_local = 0;
}
/*
* Function: priv_tramp_string_create
* Description: Create a new string specific to the trampoline loading and add
* it to the trampoline string list. This list contains the
* trampoline section name and trampoline point symbols.
*/
static struct tramp_string *priv_tramp_string_create(struct dload_state *dlthis,
u32