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