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 | /** |
| 74 | * Get the address the loaded image ends at. |
| 75 | */ |
| 76 | paddr_t layout_bin_end(void) |
| 77 | { |
| 78 | extern uint8_t bin_end[]; |
| 79 | return pa_init((uintpaddr_t)bin_end); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Get the address to load the primary VM at. |
| 84 | * |
| 85 | * This is placed just after the image. |
| 86 | */ |
| 87 | paddr_t layout_primary_begin(void) |
| 88 | { |
| 89 | /* TODO: This is a hack. We must read the alignment from the binary. */ |
| 90 | paddr_t bin_end = layout_bin_end(); |
| 91 | return pa_init((pa_addr(bin_end) + 0x80000 - 1) & ~(0x80000 - 1)); |
| 92 | } |