blob: 5414fe4751d704f0abf2f3efe2cb7fe3e15f8ff8 [file] [log] [blame]
Andrew Scullfa90e232018-10-19 11:24:28 +01001/*
Andrew Walbran692b3252019-03-07 15:51:31 +00002 * Copyright 2018 The Hafnium Authors.
Andrew Scullfa90e232018-10-19 11:24:28 +01003 *
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
Andrew Scull8d9e1212019-04-05 13:52:55 +010019#include "hf/std.h"
Alfredo Mazzinghieb1997c2019-02-07 18:00:01 +000020
Andrew Scullfa90e232018-10-19 11:24:28 +010021/**
22 * Get the address the .text section begins at.
23 */
24paddr_t layout_text_begin(void)
25{
26 extern uint8_t text_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000027
Andrew Scullfa90e232018-10-19 11:24:28 +010028 return pa_init((uintpaddr_t)text_begin);
29}
30
31/**
32 * Get the address the .text section ends at.
33 */
34paddr_t layout_text_end(void)
35{
36 extern uint8_t text_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000037
Andrew Scullfa90e232018-10-19 11:24:28 +010038 return pa_init((uintpaddr_t)text_end);
39}
40
41/**
42 * Get the address the .rodata section begins at.
43 */
44paddr_t layout_rodata_begin(void)
45{
46 extern uint8_t rodata_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000047
Andrew Scullfa90e232018-10-19 11:24:28 +010048 return pa_init((uintpaddr_t)rodata_begin);
49}
50
51/**
52 * Get the address the .rodata section ends at.
53 */
54paddr_t layout_rodata_end(void)
55{
56 extern uint8_t rodata_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000057
Andrew Scullfa90e232018-10-19 11:24:28 +010058 return pa_init((uintpaddr_t)rodata_end);
59}
60
61/**
62 * Get the address the .data section begins at.
63 */
64paddr_t layout_data_begin(void)
65{
66 extern uint8_t data_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000067
Andrew Scullfa90e232018-10-19 11:24:28 +010068 return pa_init((uintpaddr_t)data_begin);
69}
70
71/**
72 * Get the address the .data section ends at.
73 */
74paddr_t layout_data_end(void)
75{
76 extern uint8_t data_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000077
Andrew Scullfa90e232018-10-19 11:24:28 +010078 return pa_init((uintpaddr_t)data_end);
79}
80
81/**
Andrew Scullb401ba32018-11-09 10:30:54 +000082 * Get the address the .initrd section begins at.
83 */
84paddr_t layout_initrd_begin(void)
85{
86 extern uint8_t initrd_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000087
Andrew Scullb401ba32018-11-09 10:30:54 +000088 return pa_init((uintpaddr_t)initrd_begin);
89}
90
91/**
92 * Get the address the .initrd section ends at.
93 */
94paddr_t layout_initrd_end(void)
95{
96 extern uint8_t initrd_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000097
Andrew Scullb401ba32018-11-09 10:30:54 +000098 return pa_init((uintpaddr_t)initrd_end);
99}
100
101/**
102 * Get the address the .fdt section begins at.
103 */
104paddr_t layout_fdt_begin(void)
105{
106 extern uint8_t fdt_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000107
Andrew Scullb401ba32018-11-09 10:30:54 +0000108 return pa_init((uintpaddr_t)fdt_begin);
109}
110
111/**
112 * Get the address the .fdt section ends at.
113 */
114paddr_t layout_fdt_end(void)
115{
116 extern uint8_t fdt_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000117
Andrew Scullb401ba32018-11-09 10:30:54 +0000118 return pa_init((uintpaddr_t)fdt_end);
119}
120
121/**
Andrew Scullfa90e232018-10-19 11:24:28 +0100122 * Get the address the loaded image ends at.
123 */
Andrew Scull0e6bf1a2019-04-10 15:02:54 +0100124paddr_t layout_image_end(void)
Andrew Scullfa90e232018-10-19 11:24:28 +0100125{
Andrew Scull0e6bf1a2019-04-10 15:02:54 +0100126 extern uint8_t image_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000127
Andrew Scull0e6bf1a2019-04-10 15:02:54 +0100128 return pa_init((uintpaddr_t)image_end);
Andrew Scullfa90e232018-10-19 11:24:28 +0100129}
130
131/**
132 * Get the address to load the primary VM at.
133 *
134 * This is placed just after the image.
135 */
136paddr_t layout_primary_begin(void)
137{
138 /* TODO: This is a hack. We must read the alignment from the binary. */
Andrew Scull0e6bf1a2019-04-10 15:02:54 +0100139 paddr_t image_end = layout_image_end();
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000140
Andrew Scull0e6bf1a2019-04-10 15:02:54 +0100141 return pa_init(align_up(pa_addr(image_end), 0x80000));
Andrew Scullfa90e232018-10-19 11:24:28 +0100142}