Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 22 | paddr_t layout_text_begin(void) |
| 23 | { |
| 24 | extern uint8_t text_begin[]; |
| 25 | return pa_init((uintpaddr_t)text_begin); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Get the address the .text section ends at. |
| 30 | */ |
| 31 | paddr_t layout_text_end(void) |
| 32 | { |
| 33 | extern uint8_t text_end[]; |
| 34 | return pa_init((uintpaddr_t)text_end); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Get the address the .rodata section begins at. |
| 39 | */ |
| 40 | paddr_t layout_rodata_begin(void) |
| 41 | { |
| 42 | extern uint8_t rodata_begin[]; |
| 43 | return pa_init((uintpaddr_t)rodata_begin); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Get the address the .rodata section ends at. |
| 48 | */ |
| 49 | paddr_t layout_rodata_end(void) |
| 50 | { |
| 51 | extern uint8_t rodata_end[]; |
| 52 | return pa_init((uintpaddr_t)rodata_end); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Get the address the .data section begins at. |
| 57 | */ |
| 58 | paddr_t layout_data_begin(void) |
| 59 | { |
| 60 | extern uint8_t data_begin[]; |
| 61 | return pa_init((uintpaddr_t)data_begin); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Get the address the .data section ends at. |
| 66 | */ |
| 67 | paddr_t layout_data_end(void) |
| 68 | { |
| 69 | extern uint8_t data_end[]; |
| 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[]; |
| 79 | return pa_init((uintpaddr_t)initrd_begin); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Get the address the .initrd section ends at. |
| 84 | */ |
| 85 | paddr_t layout_initrd_end(void) |
| 86 | { |
| 87 | extern uint8_t initrd_end[]; |
| 88 | return pa_init((uintpaddr_t)initrd_end); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Get the address the .fdt section begins at. |
| 93 | */ |
| 94 | paddr_t layout_fdt_begin(void) |
| 95 | { |
| 96 | extern uint8_t fdt_begin[]; |
| 97 | return pa_init((uintpaddr_t)fdt_begin); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Get the address the .fdt section ends at. |
| 102 | */ |
| 103 | paddr_t layout_fdt_end(void) |
| 104 | { |
| 105 | extern uint8_t fdt_end[]; |
| 106 | return pa_init((uintpaddr_t)fdt_end); |
| 107 | } |
| 108 | |
| 109 | /** |
Andrew Scull | fa90e23 | 2018-10-19 11:24:28 +0100 | [diff] [blame] | 110 | * Get the address the loaded image ends at. |
| 111 | */ |
| 112 | paddr_t layout_bin_end(void) |
| 113 | { |
| 114 | extern uint8_t bin_end[]; |
| 115 | return pa_init((uintpaddr_t)bin_end); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Get the address to load the primary VM at. |
| 120 | * |
| 121 | * This is placed just after the image. |
| 122 | */ |
| 123 | paddr_t layout_primary_begin(void) |
| 124 | { |
| 125 | /* TODO: This is a hack. We must read the alignment from the binary. */ |
| 126 | paddr_t bin_end = layout_bin_end(); |
| 127 | return pa_init((pa_addr(bin_end) + 0x80000 - 1) & ~(0x80000 - 1)); |
| 128 | } |