summaryrefslogtreecommitdiff
path: root/ldso/ldso/m68k/dl-startup.h
blob: 2c38102a3efb5477cd84014656582c776112a8e9 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* vi: set sw=4 ts=4: */
/*
 * Architecture specific code used by dl-startup.c
 * Copyright (C) 2005 by Erik Andersen <andersen@codepoet.org>
 */

__asm__ ("\
	.text\n\
	.globl _start\n\
	.type _start,@function\n\
_start:\n\
	move.l %sp, -(%sp)\n\
	jbsr _dl_start\n\
	addq.l #4, %sp\n\
	/* FALLTHRU */\n\
\n\
	.globl _dl_start_user\n\
.type _dl_start_user,@function\n\
_dl_start_user:\n\
	# Save the user entry point address in %a4.\n\
	move.l %d0, %a4\n\
	# See if we were run as a command with the executable file\n\
	# name as an extra leading argument.\n\
	move.l _dl_skip_args(%pc), %d0\n\
	# Pop the original argument count\n\
	move.l (%sp)+, %d1\n\
	# Subtract _dl_skip_args from it.\n\
	sub.l %d0, %d1\n\
	# Adjust the stack pointer to skip _dl_skip_args words.\n\
	lea (%sp, %d0*4), %sp\n\
	# Push back the modified argument count.\n\
	move.l %d1, -(%sp)\n\
	# Pass our finalizer function to the user in %a1.\n\
	lea _dl_fini(%pc), %a1\n\
	# Initialize %fp with the stack pointer.\n\
	move.l %sp, %fp\n\
	# Jump to the user's entry point.\n\
	jmp (%a4)\n\
	.size _dl_start_user, . - _dl_start_user\n\
	.previous");

/* Get a pointer to the argv array.  On many platforms this can be just
 * the address of the first argument, on other platforms we need to
 * do something a little more subtle here.  */
#define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long *) ARGS) + 1)

/* Handle relocation of the symbols in the dynamic loader. */
static __always_inline
void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr,
	unsigned long symbol_addr, unsigned long load_addr, Elf32_Sym *symtab)
{
	switch (ELF32_R_TYPE(rpnt->r_info))
	{
		case R_68K_8:
			*(char *) reloc_addr = symbol_addr + rpnt->r_addend;
			break;
		case R_68K_16:
			*(short *) reloc_addr = symbol_addr + rpnt->r_addend;
			break;
		case R_68K_32:
			*reloc_addr = symbol_addr + rpnt->r_addend;
			break;
		case R_68K_PC8:
			*(char *) reloc_addr = (symbol_addr + rpnt->r_addend
			                       - (unsigned int) reloc_addr);
			break;
		case R_68K_PC16:
			*(short *) reloc_addr = (symbol_addr + rpnt->r_addend
			                        - (unsigned int) reloc_addr);
			break;
		case R_68K_PC32:
			*reloc_addr = (symbol_addr + rpnt->r_addend
			              - (unsigned int) reloc_addr);
			break;
		case R_68K_GLOB_DAT:
		case R_68K_JMP_SLOT:
			*reloc_addr = symbol_addr;
			break;
		case R_68K_RELATIVE:
			*reloc_addr = ((unsigned int) load_addr +
			              (rpnt->r_addend ? : *reloc_addr));
			break;
		default:
			_dl_exit (1);
	}
}