blob: 15dec5dad8d7db85da90fc53c2f8d529040b593d [file] [log] [blame]
Andrew Scullfa90e232018-10-19 11:24:28 +01001/*
2 * Copyright 2018 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "hf/layout.h"
18
19/**
20 * Get the address the .text section begins at.
21 */
22paddr_t layout_text_begin(void)
23{
24 extern uint8_t text_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000025
Andrew Scullfa90e232018-10-19 11:24:28 +010026 return pa_init((uintpaddr_t)text_begin);
27}
28
29/**
30 * Get the address the .text section ends at.
31 */
32paddr_t layout_text_end(void)
33{
34 extern uint8_t text_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000035
Andrew Scullfa90e232018-10-19 11:24:28 +010036 return pa_init((uintpaddr_t)text_end);
37}
38
39/**
40 * Get the address the .rodata section begins at.
41 */
42paddr_t layout_rodata_begin(void)
43{
44 extern uint8_t rodata_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000045
Andrew Scullfa90e232018-10-19 11:24:28 +010046 return pa_init((uintpaddr_t)rodata_begin);
47}
48
49/**
50 * Get the address the .rodata section ends at.
51 */
52paddr_t layout_rodata_end(void)
53{
54 extern uint8_t rodata_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000055
Andrew Scullfa90e232018-10-19 11:24:28 +010056 return pa_init((uintpaddr_t)rodata_end);
57}
58
59/**
60 * Get the address the .data section begins at.
61 */
62paddr_t layout_data_begin(void)
63{
64 extern uint8_t data_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000065
Andrew Scullfa90e232018-10-19 11:24:28 +010066 return pa_init((uintpaddr_t)data_begin);
67}
68
69/**
70 * Get the address the .data section ends at.
71 */
72paddr_t layout_data_end(void)
73{
74 extern uint8_t data_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000075
Andrew Scullfa90e232018-10-19 11:24:28 +010076 return pa_init((uintpaddr_t)data_end);
77}
78
79/**
Andrew Scullb401ba32018-11-09 10:30:54 +000080 * Get the address the .initrd section begins at.
81 */
82paddr_t layout_initrd_begin(void)
83{
84 extern uint8_t initrd_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000085
Andrew Scullb401ba32018-11-09 10:30:54 +000086 return pa_init((uintpaddr_t)initrd_begin);
87}
88
89/**
90 * Get the address the .initrd section ends at.
91 */
92paddr_t layout_initrd_end(void)
93{
94 extern uint8_t initrd_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000095
Andrew Scullb401ba32018-11-09 10:30:54 +000096 return pa_init((uintpaddr_t)initrd_end);
97}
98
99/**
100 * Get the address the .fdt section begins at.
101 */
102paddr_t layout_fdt_begin(void)
103{
104 extern uint8_t fdt_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000105
Andrew Scullb401ba32018-11-09 10:30:54 +0000106 return pa_init((uintpaddr_t)fdt_begin);
107}
108
109/**
110 * Get the address the .fdt section ends at.
111 */
112paddr_t layout_fdt_end(void)
113{
114 extern uint8_t fdt_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000115
Andrew Scullb401ba32018-11-09 10:30:54 +0000116 return pa_init((uintpaddr_t)fdt_end);
117}
118
119/**
Andrew Scullfa90e232018-10-19 11:24:28 +0100120 * Get the address the loaded image ends at.
121 */
122paddr_t layout_bin_end(void)
123{
124 extern uint8_t bin_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000125
Andrew Scullfa90e232018-10-19 11:24:28 +0100126 return pa_init((uintpaddr_t)bin_end);
127}
128
129/**
130 * Get the address to load the primary VM at.
131 *
132 * This is placed just after the image.
133 */
134paddr_t layout_primary_begin(void)
135{
136 /* TODO: This is a hack. We must read the alignment from the binary. */
137 paddr_t bin_end = layout_bin_end();
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000138
Andrew Scullfa90e232018-10-19 11:24:28 +0100139 return pa_init((pa_addr(bin_end) + 0x80000 - 1) & ~(0x80000 - 1));
140}