File: head.S

package info (click to toggle)
emile 0.10-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,716 kB
  • ctags: 2,737
  • sloc: ansic: 18,908; makefile: 726; asm: 622; sh: 2
file content (111 lines) | stat: -rw-r--r-- 1,800 bytes parent folder | download
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 *
 * (c) 2004, 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
 *
 */

	.chip 68000

.macro SysError
	.short 0xA9C9
.endm

.macro NewPtrClear
        .short 0xA31E
.endm

.equ	paramstring_length, 1024

/***************************************************************************
 *
 * second level arguments 
 *
 ***************************************************************************/

_start:			bra	setup
_signature:		.dc.b	'E','M','0','6'

/* EM06 */

_conf_size:		.dc.w	paramstring_length
_configuration:		.skip	paramstring_length, 0

	.align	4
setup:
	/* relocate C code, need to be compiled with -fpic */

	bsr	relocate

	/* initialize console, so we can debug ;-) */

	lea	_start(%pc), %a0
	move.l	%a0, -(%sp)
	bsr	console_init@PLTPC

	/* begin to work */

	lea	_start(%pc), %a0
	move.l	%a0, -(%sp)
	bsr	start@PLTPC

	/* We guess to never come here */
loop:
	bra	loop

relocate:
	/* Allocate BSS section */

	move.l	#__bss_size, %d0	/* size */
	/* Alloc and clear memory (needed by GCC 3) */
	NewPtrClear			/* result in %a0 */
	move.l	%a0, %d0
	bne	malloc_ok
	SysError
malloc_ok:
	move.l	%a0,%d3
	move.l	#__bss_start, %d0
	sub.l	%d0,%d3			/* %d3 is the offset to add for BSS */

	/* real address of GOT */

	lea	_GLOBAL_OFFSET_TABLE_-.-8,%a0
	lea	(%pc, %a0), %a0

	/* linked address of GOT */

	move.l	#_GLOBAL_OFFSET_TABLE_, %d0

	/* %d2 is the offset to add for all other sections */

	move.l	%a0,%d2
	sub.l	%d0,%d2

	/* relocate BSS section */

	move.l	#__got_size, %d0
	beq	exit_relocate

got_loop:
	move.l	(%a0), %d1

	cmp.l	#__bss_start.l, %d1
	blt	other_section
	cmp.l	#_end.l, %d1
	bgt	other_section

	/* symbol in section BSS */

	add.l	%d3, %d1
	bra	got_store

other_section:
	add.l	%d2, %d1

got_store:
	move.l	%d1, (%a0)+

	subq.l	#4, %d0
	bgt	got_loop

exit_relocate:
	rts