(Long post but short question, I added all the information at the end of the post to save you time)
Questions:
The MSP430 TI compiler uses a function in it's initialization process called _auto_init_hold_wtd. This is stored in the .text section, and it's called from the .text:_isr section, specifically from the _c_int00_noargs_noexit function. These can be found in the autoinit.c and boot_special.c files.
I need to ensure that these functions work correctly after relocating them on the RAM. In order to do so, I need to perform the relocations using some compiler symbols. Unfortunately, when I create a relocatable file, all these symbols have a 0 (zero) value and my relocations don't work, thus, the initialization is not correctly executed.
I need to know (1) how many symbols there are, (2) what does each one mean and (3) where they are located (what they point to), so that I can find the best solution to give them the correct values, however, (4) if you can think of any workaround it could also help. Right now, I only know that they are used in functions run_binit, run_cinit and run_pinit functions, called from the _auto_init_hold_wtd function, and, that the symbols of run_cinit are located after an asm routine called __TI_ISR_TRAP from the isr_trap.asm file (it's basically a loop in case the main function finishes).
Information:
_auto_init_hold_wtd()
void AUTO_INIT_HOLD_WDT(void) { run_binit(); uint16_t initial_WDT = WDTCTL; WDTCTL = HOLD_WDT; run_cinit(); WDTCTL = RESTORE_WDT(initial_WDT); run_pinit(); }
I could not find run_binit function.
run_cinit()
/*------------------------------------------------------------------------*/ /* Process the compressed ELF cinit table. The format is as follows: */ /* |4-byte load addr|4-byte run addr| */ /* |4-byte load addr|4-byte run addr| */ /* */ /* Processing steps: */ /* 1. Read load and run address. */ /* 2. Read one byte at load address, say idx. */ /* 3. Get pointer to handler at handler_start[idx] */ /* 4. call handler(load_addr + 1, run_addr) */ /*------------------------------------------------------------------------*/ if (__TI_Handler_Table_Base != __TI_Handler_Table_Limit) { char *const *table_ptr = __TI_CINIT_Base; char *const *table_limit = __TI_CINIT_Limit; while (table_ptr != table_limit) { char const *load_addr = *table_ptr++; char *run_addr = *table_ptr++; char handler_idx = *load_addr++; handler_fn_t handler = __TI_Handler_Table_Base[handler_idx]; handler(load_addr, run_addr); } }
run_pinit()
#define PINIT_BASE __TI_INITARRAY_Base #define PINIT_LIMIT __TI_INITARRAY_Limit /*------------------------------------------------------------------------*/ /* Process Pinit table for ELF. */ /* The section is not NULL terminated, but can be accessed by pointers */ /* which point to the beginning and end of the section. */ /*------------------------------------------------------------------------*/ if (PINIT_BASE != PINIT_LIMIT) { int i = 0; while (&(PINIT_BASE[i]) != PINIT_LIMIT) PINIT_BASE[i++](); }
The symbols I need to perform the relocations, are in the functions above plus some more. Those are the ones I referred to in my questions. Here are some, and the values they had in a test program.
__TI_Handler_Table_Base 0x4448 __TI_Handler_Table_Limit 0x444C __TI_CINIT_Base 0x444C __TI_CINIT_Limit 0x4454 0x4448: 00B0 0001 4442 0000 0x4450: 2400 0000 FFFF FFFF
However, their value is 0 in the relocations.
Relocation section '.rel.text' at offset 0xa9f4 contains 33 entries: Offset Info Type Sym.Value Sym. Name 00000002 00055508 R_MSP430X_ABS20_E 0000015c WDTCTL 00000008 0005550a R_MSP430X_ABS20_E 0000015c WDTCTL 00000010 0005910b R_MSP430X_ABS20_A 00000000 __TI_Handler_Table_Base // cinit 00000014 0005920b R_MSP430X_ABS20_A 00000000 __TI_Handler_Table_Limit // cinit 0000001a 0005930b R_MSP430X_ABS20_A 00000000 __TI_CINIT_Base // cinit 0000001e 0005940b R_MSP430X_ABS20_A 00000000 __TI_CINIT_Limit // cinit 0000002a 00059108 R_MSP430X_ABS20_E 00000000 __TI_Handler_Table_Base // cinit 00000046 00055509 R_MSP430X_ABS20_E 0000015c WDTCTL 0000004c 0005950b R_MSP430X_ABS20_A 00000000 __TI_INITARRAY_Base // pinit 00000050 0005960b R_MSP430X_ABS20_A 00000000 __TI_INITARRAY_Limit // pinit 00000056 0005950b R_MSP430X_ABS20_A 00000000 __TI_INITARRAY_Base // pinit 00000062 0005960b R_MSP430X_ABS20_A 00000000 __TI_INITARRAY_Limit // pinit 000000ca 0005550f R_MSP430X_ABS16 0000015c WDTCTL 000000d0 00037d0f R_MSP430X_ABS16 00000225 PBDIR_H 000000d4 00035f0f R_MSP430X_ABS16 00000204 PADIR_L 000000da 0004370f R_MSP430X_ABS16 00000342 TA0CCTL0 000000e0 00043d0f R_MSP430X_ABS16 00000352 TA0CCR0 000000e6 0004360f R_MSP430X_ABS16 00000340 TA0CTL 000000ec 0004360f R_MSP430X_ABS16 00000340 TA0CTL 000000f0 0005580f R_MSP430X_ABS16 00000000 turn 0000010e 0005860c R_MSP430X_ABS20_A 00000008 _lock 00000112 00056509 R_MSP430X_ABS20_E 00000004 __TI_dtors_ptr 0000011c 0005650c R_MSP430X_ABS20_A 00000004 __TI_dtors_ptr 00000120 00056609 R_MSP430X_ABS20_E 00000000 __TI_cleanup_ptr 00000128 0005660c R_MSP430X_ABS20_A 00000000 __TI_cleanup_ptr 0000012c 0005870c R_MSP430X_ABS20_A 0000000c _unlock 00000130 0005630c R_MSP430X_ABS20_A 0000023e abort 0000018e 00059002 R_MSP430_ABS16 00000000 __c_args__ 000001ae 00055a0b R_MSP430X_ABS20_A 000000c6 main 00000222 00037a0f R_MSP430X_ABS16 00000223 PBOUT_H 0000022a 00037a0f R_MSP430X_ABS16 00000223 PBOUT_H 0000022e 0005860c R_MSP430X_ABS20_A 00000008 _lock 00000234 0005870c R_MSP430X_ABS20_A 0000000c _unlock
It can be seen that there are some symbols there with a 0 value, like __TI_cleanup_ptr or __TI_INITARRAY_Base. I need to somehow fix this and I think I think the proper questions to achieve it.
All help is appreciated, thank you.