]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/blackfin/kernel/flat.c
Merge tag 'for-linus-20170825' of git://git.infradead.org/linux-mtd
[mirror_ubuntu-artful-kernel.git] / arch / blackfin / kernel / flat.c
CommitLineData
1394f032 1/*
96f1050d 2 * Copyright 2007 Analog Devices Inc.
1394f032 3 *
96f1050d 4 * Licensed under the GPL-2.
1394f032
BW
5 */
6
7#include <linux/module.h>
8#include <linux/sched.h>
589ee628 9#include <linux/mm_types.h>
1394f032
BW
10#include <linux/flat.h>
11
12#define FLAT_BFIN_RELOC_TYPE_16_BIT 0
13#define FLAT_BFIN_RELOC_TYPE_16H_BIT 1
14#define FLAT_BFIN_RELOC_TYPE_32_BIT 2
15
468138d7
AV
16unsigned long bfin_get_addr_from_rp(u32 *ptr,
17 u32 relval,
18 u32 flags,
19 u32 *persistent)
1394f032
BW
20{
21 unsigned short *usptr = (unsigned short *)ptr;
22 int type = (relval >> 26) & 7;
468138d7 23 u32 val;
1394f032
BW
24
25 switch (type) {
1f83b8f1
MF
26 case FLAT_BFIN_RELOC_TYPE_16_BIT:
27 case FLAT_BFIN_RELOC_TYPE_16H_BIT:
28 usptr = (unsigned short *)ptr;
29 pr_debug("*usptr = %x", get_unaligned(usptr));
30 val = get_unaligned(usptr);
31 val += *persistent;
32 break;
1394f032 33
1f83b8f1 34 case FLAT_BFIN_RELOC_TYPE_32_BIT:
cb0fbbf2 35 pr_debug("*ptr = %x", get_unaligned(ptr));
1f83b8f1
MF
36 val = get_unaligned(ptr);
37 break;
1394f032 38
1f83b8f1
MF
39 default:
40 pr_debug("BINFMT_FLAT: Unknown relocation type %x\n", type);
41 return 0;
1394f032
BW
42 }
43
44 /*
45 * Stack-relative relocs contain the offset into the stack, we
46 * have to add the stack's start address here and return 1 from
47 * flat_addr_absolute to prevent the normal address calculations
48 */
49 if (relval & (1 << 29))
50 return val + current->mm->context.end_brk;
51
52 if ((flags & FLAT_FLAG_GOTPIC) == 0)
53 val = htonl(val);
54 return val;
55}
56EXPORT_SYMBOL(bfin_get_addr_from_rp);
57
58/*
59 * Insert the address ADDR into the symbol reference at RP;
60 * RELVAL is the raw relocation-table entry from which RP is derived
61 */
468138d7 62void bfin_put_addr_at_rp(u32 *ptr, u32 addr, u32 relval)
1394f032
BW
63{
64 unsigned short *usptr = (unsigned short *)ptr;
65 int type = (relval >> 26) & 7;
66
67 switch (type) {
1f83b8f1
MF
68 case FLAT_BFIN_RELOC_TYPE_16_BIT:
69 put_unaligned(addr, usptr);
70 pr_debug("new value %x at %p", get_unaligned(usptr), usptr);
71 break;
1394f032 72
1f83b8f1
MF
73 case FLAT_BFIN_RELOC_TYPE_16H_BIT:
74 put_unaligned(addr >> 16, usptr);
75 pr_debug("new value %x", get_unaligned(usptr));
76 break;
1394f032 77
1f83b8f1
MF
78 case FLAT_BFIN_RELOC_TYPE_32_BIT:
79 put_unaligned(addr, ptr);
cb0fbbf2 80 pr_debug("new ptr =%x", get_unaligned(ptr));
1f83b8f1 81 break;
1394f032
BW
82 }
83}
84EXPORT_SYMBOL(bfin_put_addr_at_rp);