# Relocation patching for the C6000 EABI, checked by hand against SPRAB89
# Table 13-6. far_target resolves to 0x08000570.
#
#   0x08000040  R_C6000_PCR_S21  field [32,7,21] scaled by 4
#               (S - P) >> 2 = (0x08000570 - 0x08000040) >> 2 = 0x14c
#               word 0x00000010 -> 0x0000a610, since 0x14c << 7 = 0xa600
#   0x08000048  R_C6000_ABS_L16  field [32,7,16], low half  = 0x0570
#               word 0x00000028 -> 0x0002b828, since 0x570 << 7 = 0x2b800
#   0x0800004c  R_C6000_ABS_H16  field [32,7,16], high half = 0x0800
#               word 0x00000068 -> 0x00040068, since 0x800 << 7 = 0x40000
NAME=TMS320C6000 EABI relocation patching
FILE=bins/tms320/elf/c6x_reloc.eabi.elf
CMDS=<<EOF
e bin.relocs.apply=true
e scr.color=0
ir
s 0x08000040
p8 4
s 0x08000048
p8 8
EOF
EXPECT=<<EOF
     vaddr      paddr     target type            name          
---------------------------------------------------------------
0x08000040 0x00000040 0x08000570 R_C6000_PCR_S21 far_target
0x08000048 0x00000048 0x08000570 R_C6000_ABS_L16 far_target
0x0800004c 0x0000004c 0x08000570 R_C6000_ABS_H16 far_target
0x08000066 0x00000066 0x080001dd R_C6000_ABS32   .debug_abbrev
0x08000072 0x00000072 0x08000186 R_C6000_ABS32   .debug_line
0x080000e8 0x000000e8 0x080001ee R_C6000_ABS32   .debug_abbrev
0x080000f4 0x000000f4 0x080001a6 R_C6000_ABS32   .debug_line
0x080000f8 0x000000f8 0x08000040 R_C6000_ABS32   .text
0x080000fc 0x000000fc 0x08000040 R_C6000_ABS32   .text
0x08000179 0x00000179 0x08000040 R_C6000_ABS32   .text
0x0800017d 0x0000017d 0x08000040 R_C6000_ABS32   .text
0x080001cf 0x000001cf 0x08000040 R_C6000_ABS32   .text
0x0800021b 0x0000021b 0x080000e2 R_C6000_ABS32   .debug_info
0x08000225 0x00000225 0x08000040 R_C6000_ABS32   .text
0x0800023b 0x0000023b 0x080000e2 R_C6000_ABS32   .debug_info
10a60000
28b8020068000400
EOF
RUN

# Relocation patching for the C28x EABI. The field layouts are not fully given
# in SPRAC71C Table 11-6, so they were measured: assemble a reference to an
# external symbol, link it at a known address with lnk2000, and diff the
# section against the relocatable object. far_target resolves to 0x080001e0.
#
#   R_C28X_DP_HI16  whole word    = (S >> 6) & 0xffff = 0x0007
#   R_C28X_ABSLO6   word bits 5:0 = S & 0x3f          = 0x20
#   R_C28X_ABS8     word bits 7:0 = S & 0xff          = 0xe0
#   R_C28X_ABS16    whole word    = S & 0xffff        = 0x01e0
#   R_C28X_ABS22_BR w0 bits 5:0   = S >> 16           = 0x00
#                   w1            = S & 0xffff        = 0x01e0
#   R_C28X_PCREL16  w1            = S + A - P         = 0x0197
#   R_C28X_PCREL8   word bits 7:0 = S + A - P         = 0x94
NAME=TMS320C28x EABI relocation patching
FILE=bins/tms320/elf/c28x_reloc.eabi.elf
CMDS=<<EOF
e bin.relocs.apply=true
e scr.color=0
ir
s 0x08000036
p8 10
s 0x08000040
p8 14
EOF
EXPECT=<<EOF
     vaddr      paddr     target type            name                    
-------------------------------------------------------------------------
0x08000036 0x00000036 0x080001e0 R_C28X_DP_HI16  far_target
0x08000038 0x00000038 0x080001e0 R_C28X_ABSLO6   far_target
0x0800003a 0x0000003a 0x080001e0 R_C28X_ABS8     far_target
0x0800003e 0x0000003e 0x080001e0 R_C28X_ABS16    far_target
0x08000040 0x00000040 0x080001e0 R_C28X_ABS22_BR far_target
0x08000044 0x00000044 0x080001e0 R_C28X_ABS22_BR far_target
0x0800004a 0x0000004a 0x080001e0 R_C28X_PCREL16  far_target - 0x08000049
0x0800004c 0x0000004c 0x080001e0 R_C28X_PCREL8   far_target - 0x0800004c
07002092e09aa928e001
008fe0014076e001e0ff97019460
EOF
RUN
