aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/scripts/kernel.ld
blob: 064b8d7b8413ebfc19ae9a86bb6fdae43f6a3201 (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
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
ENTRY(_start)

/*****************************************************************************
 * Virtual and linear start addresses of the TeachOS kernel
 *****************************************************************************/
TEACHOS_PMA = 1M;
TEACHOS_VMA = 0xFFFFFFFF80000000;

PHDRS {
  boot_rodata PT_LOAD FLAGS(4);
  boot_text   PT_LOAD FLAGS(5);
  boot_data   PT_LOAD FLAGS(6);

  text   PT_LOAD FLAGS(5);
  data   PT_LOAD FLAGS(6);
  rodata PT_LOAD FLAGS(4);
}

SECTIONS
{
  /***************************************************************************
   * Load the bootstrap code into low memory. We need to be accessible in
   * 32-Bit mode, so we want to live down low, but we need to leave the 1MiB
   * hole open since some BIOS functionality resides below it.
   ***************************************************************************/
  . = TEACHOS_PMA;

  /***************************************************************************
   * We want to be able to be able to access all memory (physical and virtual)
   * during bootstrapping and operation. To achieve this, we define some
   * symbols at the beginning.
   ***************************************************************************/
  _start_physical = .;
  _start_virtual = . + TEACHOS_VMA;


  /***************************************************************************
   * The bootstrapping infratructure goes first. We first place the read-only
   * data, followed by our code, initialized mutable data, and finally our 
   * uninitialized mutable data.
   ***************************************************************************/
  .boot_rodata ALIGN(4K) : AT(ADDR (.boot_rodata))
  {
    KEEP(*(.boot_mbh))
    *(.boot_rodata)
  } :boot_rodata

  .boot_text ALIGN(4K) : AT(ADDR (.boot_text))
  {
    *(.boot_text)
  } :boot_text

  .boot_bss ALIGN(4K) : AT(ADDR (.boot_bss))
  {
    *(.boot_bss)
    *(.boot_stack)
  }

  .boot_data ALIGN(4K) : AT(ADDR (.boot_data))
  {
    *(.boot_data)
  } :boot_data

  /***************************************************************************
   * Now it is time to load the 64-bit kernel code. We
   * make sure to align the loaded data onto a page boundary.
   ***************************************************************************/
  . = ALIGN(4K);
  . += TEACHOS_VMA;

  .stl_text ALIGN(4K) : AT(ADDR (.stl_text) - TEACHOS_VMA)
  {
    *(.stl_text .stl_text*)
    KEEP(*libstdc++.a:*(.text .text.*))
  } :text

  .text ALIGN(4K) : AT(ADDR (.text) - TEACHOS_VMA)
  {
    *(.text .text.*)
  }

  .user_text ALIGN(4K) : AT(ADDR (.user_text) - TEACHOS_VMA)
  {
    *(.user_text .user_text.*)
  }

  .rodata ALIGN(4K) : AT (ADDR (.rodata) - TEACHOS_VMA)
  {
    *(.rodata)
    *(.rodata.*)
  } :rodata

  .ctors ALIGN(4K) : AT (ADDR (.ctors) - TEACHOS_VMA)
  {
    __ctors_start = .;
    KEEP(*(SORT(.ctors.*)))
    KEEP(*(.ctors))
    __ctors_end = .;
  } :data

  .init_array ALIGN(4K) : AT (ADDR (.init_array) - TEACHOS_VMA)
  {
    __init_array_start = .;
    KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*)))
    KEEP(*(.init_array))
    __init_array_end = .;
  }

  .bss ALIGN(4K) : AT (ADDR (.bss) - TEACHOS_VMA)
  {
    *(COMMON)
    *(.bss*)
  }

  .data ALIGN(4K) : AT (ADDR (.data) - TEACHOS_VMA)
  {
    *(.data*)
  }

  .user_data ALIGN(4K) : AT (ADDR (.user_data) - TEACHOS_VMA)
  {
    *(.user_data .user_data.*)
  }

  /***************************************************************************
   * In accordance with the symbol definitions at the start, we generate some
   * symbols to mark the end of our loaded image.
   ***************************************************************************/
  _end_virtual = .;
  _end_physical = _end_virtual - TEACHOS_VMA;

  /DISCARD/ : { *(.comment) }
}