blob: a92ec82f057ca163e719de1551514d1fe2a693ef [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 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/BSD-3-Clause.
Andrew Scullfa90e232018-10-19 11:24:28 +01007 */
8
9#include "hf/layout.h"
10
Andrew Scull8d9e1212019-04-05 13:52:55 +010011#include "hf/std.h"
Alfredo Mazzinghieb1997c2019-02-07 18:00:01 +000012
Andrew Scullfa90e232018-10-19 11:24:28 +010013/**
14 * Get the address the .text section begins at.
15 */
16paddr_t layout_text_begin(void)
17{
18 extern uint8_t text_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000019
Andrew Scullfa90e232018-10-19 11:24:28 +010020 return pa_init((uintpaddr_t)text_begin);
21}
22
23/**
24 * Get the address the .text section ends at.
25 */
26paddr_t layout_text_end(void)
27{
28 extern uint8_t text_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000029
Andrew Scullfa90e232018-10-19 11:24:28 +010030 return pa_init((uintpaddr_t)text_end);
31}
32
33/**
34 * Get the address the .rodata section begins at.
35 */
36paddr_t layout_rodata_begin(void)
37{
38 extern uint8_t rodata_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000039
Andrew Scullfa90e232018-10-19 11:24:28 +010040 return pa_init((uintpaddr_t)rodata_begin);
41}
42
43/**
44 * Get the address the .rodata section ends at.
45 */
46paddr_t layout_rodata_end(void)
47{
48 extern uint8_t rodata_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000049
Andrew Scullfa90e232018-10-19 11:24:28 +010050 return pa_init((uintpaddr_t)rodata_end);
51}
52
53/**
54 * Get the address the .data section begins at.
55 */
56paddr_t layout_data_begin(void)
57{
58 extern uint8_t data_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000059
Andrew Scullfa90e232018-10-19 11:24:28 +010060 return pa_init((uintpaddr_t)data_begin);
61}
62
63/**
64 * Get the address the .data section ends at.
65 */
66paddr_t layout_data_end(void)
67{
68 extern uint8_t data_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000069
Andrew Scullfa90e232018-10-19 11:24:28 +010070 return pa_init((uintpaddr_t)data_end);
71}
72
73/**
Andrew Scullb401ba32018-11-09 10:30:54 +000074 * Get the address the .initrd section begins at.
75 */
76paddr_t layout_initrd_begin(void)
77{
78 extern uint8_t initrd_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000079
Andrew Scullb401ba32018-11-09 10:30:54 +000080 return pa_init((uintpaddr_t)initrd_begin);
81}
82
83/**
84 * Get the address the .initrd section ends at.
85 */
86paddr_t layout_initrd_end(void)
87{
88 extern uint8_t initrd_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000089
Andrew Scullb401ba32018-11-09 10:30:54 +000090 return pa_init((uintpaddr_t)initrd_end);
91}
92
93/**
94 * Get the address the .fdt section begins at.
95 */
96paddr_t layout_fdt_begin(void)
97{
98 extern uint8_t fdt_begin[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +000099
Andrew Scullb401ba32018-11-09 10:30:54 +0000100 return pa_init((uintpaddr_t)fdt_begin);
101}
102
103/**
104 * Get the address the .fdt section ends at.
105 */
106paddr_t layout_fdt_end(void)
107{
108 extern uint8_t fdt_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000109
Andrew Scullb401ba32018-11-09 10:30:54 +0000110 return pa_init((uintpaddr_t)fdt_end);
111}
112
113/**
Andrew Scullfa90e232018-10-19 11:24:28 +0100114 * Get the address the loaded image ends at.
115 */
Andrew Scull0e6bf1a2019-04-10 15:02:54 +0100116paddr_t layout_image_end(void)
Andrew Scullfa90e232018-10-19 11:24:28 +0100117{
Andrew Scull0e6bf1a2019-04-10 15:02:54 +0100118 extern uint8_t image_end[];
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000119
Andrew Scull0e6bf1a2019-04-10 15:02:54 +0100120 return pa_init((uintpaddr_t)image_end);
Andrew Scullfa90e232018-10-19 11:24:28 +0100121}
122
123/**
124 * Get the address to load the primary VM at.
125 *
126 * This is placed just after the image.
127 */
128paddr_t layout_primary_begin(void)
129{
Andrew Scull0e6bf1a2019-04-10 15:02:54 +0100130 paddr_t image_end = layout_image_end();
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000131
Andrew Walbrana2e3d862019-04-16 17:19:31 +0100132 /*
133 * Linux usually expects to be loaded at offset 0x80000 into a 2MB
134 * aligned address.
135 * TODO: This is a hack, and isn't always correct. We should really read
136 * the alignment from the header of the binary, or have a bootloader
137 * within the VM do so.
138 */
Andrew Walbranf636b842020-01-10 11:46:12 +0000139 return pa_init(align_up(pa_addr(image_end), LINUX_ALIGNMENT) +
140 LINUX_OFFSET);
Andrew Scullfa90e232018-10-19 11:24:28 +0100141}