File: kexec-elf-rel-sh.c

package info (click to toggle)
kexec-tools 1%3A2.0.29-2
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 3,040 kB
  • sloc: ansic: 29,720; sh: 3,553; asm: 2,625; cpp: 1,753; makefile: 964
file content (54 lines) | stat: -rw-r--r-- 1,344 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * kexec-elf-rel-sh.c - ELF relocations for SuperH
 * Copyright (C) 2008 Paul Mundt
 *
 * Based on the SHcompact module loader (arch/sh/kernel/module.c) in the
 * Linux kernel, which is written by:
 *
 *	Copyright (C) 2003 - 2008 Kaz Kojima & Paul Mundt
 *
 * This source code is licensed under the GNU General Public License,
 * Version 2.  See the file COPYING for more details.
 */
#include <stdio.h>
#include <elf.h>
#include "../../kexec.h"
#include "../../kexec-elf.h"

int machine_verify_elf_rel(struct mem_ehdr *ehdr)
{
	/* Intentionally don't bother with endianness validation, it's
	 * configurable */

	if (ehdr->ei_class != ELFCLASS32)
		return 0;
	if (ehdr->e_machine != EM_SH)
		return 0;

	return 1;
}

void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr),
	struct mem_sym *UNUSED(sym), unsigned long r_type, void *orig_loc,
	unsigned long UNUSED(address), unsigned long relocation)
{
	uint32_t *location = orig_loc;
	uint32_t value;

	switch (r_type) {
	case R_SH_DIR32:
		value = get_unaligned(location);
		value += relocation;
		put_unaligned(value, location);
		break;
	case R_SH_REL32:
		relocation = (relocation - (uint32_t)location);
		value = get_unaligned(location);
		value += relocation;
		put_unaligned(value, location);
		break;
	default:
	        die("Unknown rela relocation: %lu\n", r_type);
		break;
	}
}