add pinctrl sample code
[firefly-linux-kernel-4.4.55.git] / arch / arm / libpie / relocate.S
1 /*
2  * arch/arm/libpie/relocate.S - Relocation updating for PIEs
3  *
4  * Copyright 2013 Texas Instruments, Inc.
5  *      Russ Dill <russ.dill@ti.com>
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms and conditions of the GNU General Public License,
9  * version 2, as published by the Free Software Foundation.
10  */
11
12 #include <linux/linkage.h>
13
14 /*
15  * Update relocations based on current pc
16  *
17  * On exit:
18  *  r4-r9 corrupted
19  */
20
21 ENTRY(__pie_relocate)
22         /* Calculate offset of our code compared to existing relocations */
23         ldr     r4, pie_relocate_address
24         adr     r5, __pie_relocate
25         subs    r6, r5, r4
26         moveq   pc, lr                  /* 0 offset, no need to do anything */
27
28         /* Base of PIE group */
29         ldr     r7, reloc_offset
30         sub     r5, r5, r7
31
32         /* Calculate address of tail */
33         ldr     r7, tail_offset
34         add     r7, r7, r5
35
36         /* First byte of tail is number of entries */
37         ldr     r8, [r7], #4
38         add     r8, r7, r8, lsl #2
39
40         /*
41          * r5 - current base address of PIE group
42          * r6 - fixup offset needed for relocs
43          * r7 - relocs start
44          * r8 - relocs end
45          */
46
47 1:
48         cmp     r7, r8
49         ldrne   r4, [r7], #4    /* Load next reloc offset */
50
51         addne   r4, r4, r5      /* Calculate address of reloc entry */
52         ldrne   r9, [r4]
53         addne   r9, r9, r6      /* Fixup reloc entry */
54         strne   r9, [r4]
55
56         bne     1b
57
58         mov     pc, lr
59 ENDPROC(__pie_relocate)
60
61 /*
62  * This ends up in the .rel.dyn section and can be used to read the current
63  * relocation offset
64  */
65 pie_relocate_address:
66         .long   __pie_relocate
67
68 /* Offset from PIE section start to reloc function */
69 .global reloc_offset
70 reloc_offset:
71         .space  4
72
73 /* Offset from PIE section start to tail */
74 .globl tail_offset
75 tail_offset:
76         .space  4