* Rename cle_upd_reloc to cle_write_reloc and changed first arg to

point to position to be updated.

* Factor cle.c into multiple files.
This commit is contained in:
bg- 2007-04-26 13:37:28 +00:00
parent cf14e47a0f
commit 9f106aa6fc
5 changed files with 251 additions and 149 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)$Id: cle.c,v 1.5 2007/04/26 12:52:52 bg- Exp $
* @(#)$Id: cle.c,v 1.6 2007/04/26 13:37:28 bg- Exp $
*/
/*
@ -38,8 +38,8 @@
#include "contiki.h"
#include "loader/cle.h"
#include "loader/elf32.h"
#include "loader/cle.h"
#include "loader/sym.h"
#define NDEBUG
@ -185,25 +185,6 @@ cle_read_info(struct cle_info *info,
return CLE_OK;
}
/*
* Update one reloc.
*
* Writing relocs is machine dependent and this function is MSP430
* specific!
*/
#ifdef __MSP430__
static inline int
cle_upd_reloc(unsigned char *segmem, struct elf32_rela *rela, cle_addr addr)
{
memcpy((char *)segmem + rela->r_offset, &addr, 2); /* Write reloc */
return CLE_OK;
}
#else
static int
cle_upd_reloc(unsigned char *segmem, struct elf32_rela *rela, cle_addr addr);
#endif
/*
* Relocate one segment that has been copied to the location pointed
* to by segmem.
@ -279,7 +260,7 @@ cle_relocate(struct cle_info *info,
addr += rela.r_addend;
ret = cle_upd_reloc(segmem, &rela, addr);
ret = cle_write_reloc(segmem + rela.r_offset, &rela, addr);
if(ret != CLE_OK) {
return ret;
}
@ -335,128 +316,3 @@ cle_lookup(struct cle_info *info,
}
return NULL;
}
#if defined(__AVR__) && defined(__GNUC__)
#define R_AVR_NONE 0
#define R_AVR_32 1
#define R_AVR_7_PCREL 2
#define R_AVR_13_PCREL 3
#define R_AVR_16 4
#define R_AVR_16_PM 5
#define R_AVR_LO8_LDI 6
#define R_AVR_HI8_LDI 7
#define R_AVR_HH8_LDI 8
#define R_AVR_LO8_LDI_NEG 9
#define R_AVR_HI8_LDI_NEG 10
#define R_AVR_HH8_LDI_NEG 11
#define R_AVR_LO8_LDI_PM 12
#define R_AVR_HI8_LDI_PM 13
#define R_AVR_HH8_LDI_PM 14
#define R_AVR_LO8_LDI_PM_NEG 15
#define R_AVR_HI8_LDI_PM_NEG 16
#define R_AVR_HH8_LDI_PM_NEG 17
#define R_AVR_CALL 18
static int
cle_upd_reloc(unsigned char *segmem, struct elf32_rela *rela, cle_addr addr)
{
unsigned char *instr = segmem + rela->r_offset;
unsigned char byte;
switch(ELF32_R_TYPE(rela->r_info)) {
default:
PRINTF("cle_upd_reloc: unsupported relocation type: %d\n",
ELF32_R_TYPE(rela->r_info));
return CLE_UNKNOWN_RELOC;
#if VERIFY_BEFORE_ENABLE
case R_AVR_7_PCREL: /* 2 */
/* Reloc in bits 0x03f8 (0000 00kk kkkk k000). */
byte = (addr - rela->r_offset - 2)/2;
instr[0] = (instr[0] & 0x07) | (byte << 3); /* 0xf8 */
instr[1] = (instr[1] & 0xfc) | (byte >> 5); /* 0x03 */
return CLE_OK;
case R_AVR_13_PCREL: /* 3 */
/* Reloc in bits 0x0fff (0000 kkkk kkkk kkkk). */
addr = (addr - rela->r_offset - 2)/2;
instr[0] = addr;
instr[1] = (instr[1] & 0xf0) | ((addr >> 8) & 0x0f);
return CLE_OK;
#endif
case R_AVR_CALL: /* 18 */
addr = addr >> 1;
instr[2] = addr;
instr[3] = addr >> 8;
return CLE_OK;
case R_AVR_16: /* 4 */
instr[0] = addr;
instr[1] = addr >> 8;
return CLE_OK;
case R_AVR_16_PM: /* 5 */
addr = addr >> 1;
instr[0] = addr;
instr[1] = addr >> 8;
return CLE_OK;
/*
* Remaining relocs all have immediate value in bits 0x0f0f.
*/
case R_AVR_LO8_LDI: /* 6 */
byte = addr;
break;
case R_AVR_HI8_LDI: /* 7 */
byte = addr >> 8;
break;
case R_AVR_HH8_LDI: /* 8 */
byte = addr >> 16;
break;
case R_AVR_LO8_LDI_NEG: /* 9 */
byte = (-addr);
break;
case R_AVR_HI8_LDI_NEG: /* 10 */
byte = (-addr) >> 8;
break;
case R_AVR_HH8_LDI_NEG: /* 11 */
byte = (-addr) >> 16;
break;
case R_AVR_LO8_LDI_PM: /* 12 */
byte = addr >> 1;
break;
case R_AVR_HI8_LDI_PM: /* 13 */
byte = addr >> 9;
break;
case R_AVR_HH8_LDI_PM: /* 14 */
byte = addr >> 17;
break;
case R_AVR_LO8_LDI_PM_NEG: /* 15 */
byte = (-addr) >> 1;
break;
case R_AVR_HI8_LDI_PM_NEG: /* 16 */
byte = (-addr) >> 9;
break;
case R_AVR_HH8_LDI_PM_NEG: /* 17 */
byte = (-addr) >> 17;
break;
}
/* Relocation in bits 0x0f0f (0000 kkkk 0000 kkkk). */
instr[0] = (instr[0] & 0xf0) | (byte & 0x0f);
instr[1] = (instr[1] & 0xf0) | (byte >> 4);
return CLE_OK;
}
#endif /* __AVR__ */