-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.ld
51 lines (47 loc) · 1.65 KB
/
kernel.ld
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
/*
* kernel.ld -- 针对 kernel 格式所写的链接脚本
*
* 作者是 JamesM 先生,感谢他的慷慨和付出
*
* Original file taken from Bran's Kernel Development
* tutorials: http://www.osdever.net/bkerndev/index.php.
*
* 首先,我们声明了内核程序的入口地址是符号 "start"
* 这个脚本告诉 ld 程序 如何构造我们的内核映像文件。
* 然后,我们声明了第一个段 .text 段(代码段)以及它的起始地址 0x100000(1MB)。
* 接着是 已初始化数据段 .data 和 未初始化数据段 .bss 以及它们采用的4096的页对齐方式。
* Linux GCC 增加了额外的数据段 .rodata,这是一个只读的已初始化数据段,放置常量什么的。
* 简单起见,我们把和 .data 段放在一起好了。
*
* This script tells LD how to set up our kernel image.
* Firstly it tells LD that the start location of our binary should be the symbol 'start'.
* It then tells LD that the .text section (that's where all your code goes) should be first,
* and should start at 0x100000 (1MB).
* The .data (initialised static data) and the .bss (uninitialised static data) should be next,
* and each should be page-aligned (ALIGN(4096)).
* Linux GCC also adds in an extra data section: .rodata.
* This is for read-only initialised data, such as constants.
* For simplicity we simply bundle this in with the .data section.
*/
ENTRY(_start)
SECTIONS
{
. = 0x07e00;
.text :
{
*(.text)
. = ALIGN(4096);
}
.data :
{
*(.data)
*(.rodata)
. = ALIGN(4096);
}
.bss :
{
*(.bss)
. = ALIGN(4096);
}
/DISCARD/ : { *(.comment) *(.eh_frame) }
}