2000-10-31 Philip Blundell <philb@gnu.org>
[binutils.git] / ld / testsuite / ld-empic / runtesti.s
blobefa195301fb49c3cc026cc67ff647aa8b7119a50
1 # Assembler initialization code for actual execution test.
3 # This code becomes the start of the execution test program. It is
4 # responsible for initializing the static data, invoking the C code,
5 # and returning the result. It is called as though it were a C
6 # function with an argument of the address of the data segment.
8 # We need to know the value of _ftext and _fdata at link time, but we
9 # have no way to actually get that at runtime. This is because when
10 # this code is compiled with -membedded-pic, the la instruction will
11 # be turned into an addiu $gp instruction. We work around this by
12 # storing the information in words in the .data section. We then load
13 # the values of these words *before* doing the runtime relocation.
14 .sdata
15 text_start:
16 .word _ftext
17 data_start:
18 .word _fdata
20 .globl start
21 .text
22 start:
23 # Grab some space on the stack, just as though we were a real
24 # function.
25 addiu $sp,$sp,-8
26 sw $31,0($sp)
28 # Save the $gp register, and set it up for our data section.
29 sw $gp,4($sp)
31 addu $gp,$4,0x8000 # macro
33 # The start of the data segment is in $4.
35 # Get the address of start into $5 in a position independent
36 # fashion.
37 .set noreorder
38 $LF1 = . + 8
39 bal $LF1
40 la $5,start-$LF1 # macro
41 .set reorder
42 addu $5,$5,$31
44 # Now get the address of _ftext into $6.
45 la $6,_ftext-start # macro
46 addu $6,$6,$5
48 # Get the value of _ftext used to link into $7.
49 lw $7,text_start # macro
51 # Get the value of _fdata used to link into $8.
52 lw $8,data_start # macro
54 # Get the address of __runtime_reloc_start into $9.
55 la $9,__runtime_reloc_start-start # macro
56 addu $9,$9,$5
58 # Get the address of __runtime_reloc_stop into $10.
59 la $10,__runtime_reloc_stop-start # macro
60 addu $10,$10,$5
62 # The words between $9 and $10 are the runtime initialization
63 # instructions. Step through and relocate them. First set
64 # $11 and $12 to the values to add to text and data sections,
65 # respectively.
66 subu $11,$6,$7
67 subu $12,$4,$8
69 1:
70 bge $9,$10,3f # macro
71 lw $13,0($9)
72 and $14,$13,0xfffffffe # macro
73 move $15,$11
74 beq $13,$14,2f
75 move $15,$12
76 2:
77 addu $14,$14,$4
78 lw $24,0($14)
79 addu $24,$24,$15
80 sw $24,0($14)
81 addiu $9,$9,4
82 b 1b
83 3:
85 # Now the statically initialized data has been relocated
86 # correctly, and we can call the C code which does the actual
87 # testing.
88 bal foo
90 # We return the value returned by the C code.
91 lw $31,0($sp)
92 lw $gp,4($sp)
93 addu $sp,$sp,8
94 j $31