Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 1 | /* |
Andrew Walbran | 692b325 | 2019-03-07 15:51:31 +0000 | [diff] [blame] | 2 | * Copyright 2018 The Hafnium Authors. |
Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 4 | * 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 Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "hf/layout.h" |
| 10 | |
Andrew Scull | 8d9e121 | 2019-04-05 13:52:55 +0100 | [diff] [blame] | 11 | #include "hf/std.h" |
Alfredo Mazzinghi | eb1997c | 2019-02-07 18:00:01 +0000 | [diff] [blame] | 12 | |
Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 13 | /** |
| 14 | * Get the address the .text section begins at. |
| 15 | */ |
| 16 | paddr_t layout_text_begin(void) |
| 17 | { |
| 18 | extern uint8_t text_begin[]; |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 19 | |
Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 20 | return pa_init((uintpaddr_t)text_begin); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Get the address the .text section ends at. |
| 25 | */ |
| 26 | paddr_t layout_text_end(void) |
| 27 | { |
| 28 | extern uint8_t text_end[]; |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 29 | |
Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 30 | return pa_init((uintpaddr_t)text_end); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Get the address the .rodata section begins at. |
| 35 | */ |
| 36 | paddr_t layout_rodata_begin(void) |
| 37 | { |
| 38 | extern uint8_t rodata_begin[]; |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 39 | |
Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 40 | return pa_init((uintpaddr_t)rodata_begin); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Get the address the .rodata section ends at. |
| 45 | */ |
| 46 | paddr_t layout_rodata_end(void) |
| 47 | { |
| 48 | extern uint8_t rodata_end[]; |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 49 | |
Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 50 | return pa_init((uintpaddr_t)rodata_end); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Get the address the .data section begins at. |
| 55 | */ |
| 56 | paddr_t layout_data_begin(void) |
| 57 | { |
| 58 | extern uint8_t data_begin[]; |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 59 | |
Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 60 | return pa_init((uintpaddr_t)data_begin); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Get the address the .data section ends at. |
| 65 | */ |
| 66 | paddr_t layout_data_end(void) |
| 67 | { |
| 68 | extern uint8_t data_end[]; |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 69 | |
Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 70 | return pa_init((uintpaddr_t)data_end); |
| 71 | } |
| 72 | |
| 73 | /** |
Andrew Scull | b401ba3 | 2018-11-09 10:30:54 +0000 | [diff] [blame] | 74 | * Get the address the .initrd section begins at. |
| 75 | */ |
| 76 | paddr_t layout_initrd_begin(void) |
| 77 | { |
| 78 | extern uint8_t initrd_begin[]; |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 79 | |
Andrew Scull | b401ba3 | 2018-11-09 10:30:54 +0000 | [diff] [blame] | 80 | return pa_init((uintpaddr_t)initrd_begin); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Get the address the .initrd section ends at. |
| 85 | */ |
| 86 | paddr_t layout_initrd_end(void) |
| 87 | { |
| 88 | extern uint8_t initrd_end[]; |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 89 | |
Andrew Scull | b401ba3 | 2018-11-09 10:30:54 +0000 | [diff] [blame] | 90 | return pa_init((uintpaddr_t)initrd_end); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Get the address the .fdt section begins at. |
| 95 | */ |
| 96 | paddr_t layout_fdt_begin(void) |
| 97 | { |
| 98 | extern uint8_t fdt_begin[]; |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 99 | |
Andrew Scull | b401ba3 | 2018-11-09 10:30:54 +0000 | [diff] [blame] | 100 | return pa_init((uintpaddr_t)fdt_begin); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Get the address the .fdt section ends at. |
| 105 | */ |
| 106 | paddr_t layout_fdt_end(void) |
| 107 | { |
| 108 | extern uint8_t fdt_end[]; |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 109 | |
Andrew Scull | b401ba3 | 2018-11-09 10:30:54 +0000 | [diff] [blame] | 110 | return pa_init((uintpaddr_t)fdt_end); |
| 111 | } |
| 112 | |
| 113 | /** |
Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 114 | * Get the address the loaded image ends at. |
| 115 | */ |
Andrew Scull | 0e6bf1a | 2019-04-10 15:02:54 +0100 | [diff] [blame] | 116 | paddr_t layout_image_end(void) |
Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 117 | { |
Andrew Scull | 0e6bf1a | 2019-04-10 15:02:54 +0100 | [diff] [blame] | 118 | extern uint8_t image_end[]; |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 119 | |
Andrew Scull | 0e6bf1a | 2019-04-10 15:02:54 +0100 | [diff] [blame] | 120 | return pa_init((uintpaddr_t)image_end); |
Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Get the address to load the primary VM at. |
| 125 | * |
| 126 | * This is placed just after the image. |
| 127 | */ |
| 128 | paddr_t layout_primary_begin(void) |
| 129 | { |
Andrew Scull | 0e6bf1a | 2019-04-10 15:02:54 +0100 | [diff] [blame] | 130 | paddr_t image_end = layout_image_end(); |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 131 | |
Andrew Walbran | a2e3d86 | 2019-04-16 17:19:31 +0100 | [diff] [blame] | 132 | /* |
| 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 Walbran | f636b84 | 2020-01-10 11:46:12 +0000 | [diff] [blame] | 139 | return pa_init(align_up(pa_addr(image_end), LINUX_ALIGNMENT) + |
| 140 | LINUX_OFFSET); |
Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 141 | } |