summaryrefslogtreecommitdiffstats
path: root/arch/x86/lib/barebox.lds.S
blob: 6cf6b10d1bb8027fbe6413e1a2cf2eada74411cd (plain) (blame)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *
 */

#undef i386
#include <asm-generic/barebox.lds.h>

OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(_start)

MEMORY
{
	mbr(rwx): ORIGIN = TEXT_BASE, LENGTH = 2 * SECTOR_SIZE
	barebox (rwx) : ORIGIN = TEXT_BASE + SECTOR_SIZE, LENGTH = (256 * 1024 * 1024)
}

SECTIONS
{
#ifdef CONFIG_X86_HDBOOT

	.ramlayout : {
		boot_stack = INDIRECT_AREA;
		indirect_area = INDIRECT_AREA;
	}
	/* describing the main boot sector */
	.bootsector : AT (0) {
		*(.boot_start)

		. = 0x00b;
		/*
		 * Maybe later on occupied by a "BIOS parameter block". So,
		 * keep it free from code.
		 * - BytesPerSector dw@0x000B
		 * - SectorsPerCluster db@0x000D
		 * - ReservedSectors dw@0x000E
		 * - FatCopies db@0x0010
		 * - RootDirEntries dw@0x0011
		 * - NumSectors dw@0x0013
		 * - MediaType db@0x0015
		 * - SectorsPerFAT dw@0x0016
		 * - SectorsPerTrack dw@0x0018
		 * - NumberOfHeads dw@0x001A
		 * - HiddenSectors dd@0x001C
		 * - SectorsBig dd@0x0020
		 */
		LONG(0);

		. = 0x024;
		*(.boot_code)
		*(.boot_data)

		/*
		 * embed one "Disk Address Packet Structure" into the boot sector
		 * This DAPS points to the 'indirect' sector to give the boot code
		 * an idea what and where to load. Its content must be adapted
		 * to the system it should run on, so, this structure must be
		 * located at a well known offset.
		 */
		. = PATCH_AREA;
		indirect_sector_lba = .;
		SHORT(0x0010);		/* size of this structure */
		SHORT(0x0001);		/* one sector */
		SHORT(indirect_area);	/* where to store: offset */
		SHORT(0x0000);		/* where to store: segment */
		/* the following values are filled by the installer */
		LONG(0x00000000);	/* LBA start lower */
		LONG(0x00000000);	/* LBA start upper */

		/* boot disk number used by upper layers */
		. = PATCH_AREA + PATCH_AREA_BOOT_DEV;
		boot_disk = .;
		BYTE(0x00);		/* boot disk number (provided by the BIOS)

		/* information about the persistent environment storage */
		. = PATCH_AREA + PATCH_AREA_PERS_START;
		pers_env_storage = .;
		LONG(0x00000000);	/* LBA start lower */
		LONG(0x00000000);	/* LBA start upper */

		. = PATCH_AREA + PATCH_AREA_PERS_SIZE;
		pers_env_size = .;
		SHORT(PATCH_AREA_PERS_SIZE_UNUSED);	/* size of this area in sectors */

		. = PATCH_AREA + PATCH_AREA_PERS_DRIVE;
		pers_env_drive = .;
		BYTE(0x00);		/* used drive */

		/* partition table area (fixed location) */
		. = OFFSET_OF_PARTITION_TABLE;
		/* create an empty one */
		LONG(0x00000000); LONG(0x00000000); LONG(0x00000000); LONG(0x00000000);
		LONG(0x00000000); LONG(0x00000000); LONG(0x00000000); LONG(0x00000000);
		LONG(0x00000000); LONG(0x00000000); LONG(0x00000000); LONG(0x00000000);
		LONG(0x00000000); LONG(0x00000000); LONG(0x00000000); LONG(0x00000000);

		/* boot sector signature */
		. = OFFSET_OF_SIGNATURE;
		BYTE(0x55);
		BYTE(0xAA);
		/* end of the first sector */

		/*
		 * The indirect sector starts here
		 */
		. = SECTOR_SIZE;
		BYTE(MARK_DAPS_INVALID);	/* mark the first entry invalid */
		BYTE(0x00);
		. = SECTOR_SIZE + 496;
		BYTE(MARK_DAPS_INVALID);	/* mark the last entry invalid */
		BYTE(0x00);
		. = SECTOR_SIZE + 508;
		LONG(0x00000000);	/* LBA start upper */
	} > mbr

	/* some real mode bootstrapping */
	.bootstrapping : AT ( LOADADDR(.bootsector) + SIZEOF(.bootsector) ) {
		*(.boot.head)
		*(.boot.text*)
		*(.boot.rodata*)
		*(.boot.data*)
		. = ALIGN(4);
	} > barebox
#endif

	/* the main barebox part (32 bit) */
	.text : AT ( LOADADDR(.bootstrapping) + SIZEOF(.bootstrapping) ) {
		/* do not align here! It may fails with the LOADADDR! */
		_stext = .;
		_text = .;
		*(.text_entry*)
		__bare_init_start = .;
		*(.text_bare_init*)
		__bare_init_end = .;
		*(.text*)
		. = ALIGN(4);
		*(.rodata*)
		. = ALIGN(4);
		_etext = .;			/* End of text and rodata section */
	} > barebox
	BAREBOX_BARE_INIT_SIZE

	_sdata = .;
	.data : AT ( LOADADDR(.text) + SIZEOF(.text) ) {
		*(.data*)
		. = ALIGN(4);
	} > barebox

	.got : AT ( LOADADDR(.data) + SIZEOF (.data) ) {
		*(.got*)
		. = ALIGN(4);
	} > barebox

	.barebox_cmd : AT ( LOADADDR(.got) + SIZEOF (.got) ) {
		__barebox_cmd_start = .;
		BAREBOX_CMDS
		__barebox_cmd_end = .;
		. = ALIGN(4);
	} > barebox

	.barebox_magicvars : AT ( LOADADDR(.barebox_cmd) + SIZEOF (.barebox_cmd) ) {
		__barebox_magicvar_start = .;
		BAREBOX_MAGICVARS
		__barebox_magicvar_end = .;
		. = ALIGN(4);
	} > barebox

	.barebox_initcalls : AT ( LOADADDR(.barebox_magicvars) + SIZEOF (.barebox_magicvars) ) {
		__barebox_initcalls_start = .;
		INITCALLS
		__barebox_initcalls_end = .;
		. = ALIGN(4);
	} > barebox

	.__usymtab : AT ( LOADADDR(.barebox_initcalls) + SIZEOF (.barebox_initcalls) ) {
		__usymtab_start = .;
		BAREBOX_SYMS
		__usymtab_end = .;
		. = ALIGN(4);
	} > barebox

	_edata = .;
	.bss : {
		__bss_start = .;
		*(.bss*);
		*( COMMON )
		__bss_stop = .;
		_end = .;
	} > barebox
}