Andrew Scull | 1883487 | 2018-10-12 11:48:09 +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 | |
Andrew Scull | 5991ec9 | 2018-10-08 14:55:02 +0100 | [diff] [blame] | 17 | #pragma once |
| 18 | |
| 19 | #include "hf/addr.h" |
| 20 | |
| 21 | /** |
| 22 | * Get the address the .text section begins at. |
| 23 | */ |
| 24 | static inline paddr_t layout_text_begin(void) |
| 25 | { |
| 26 | extern uint8_t text_begin[]; |
| 27 | return pa_init((uintpaddr_t)text_begin); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Get the address the .text section ends at. |
| 32 | */ |
| 33 | static inline paddr_t layout_text_end(void) |
| 34 | { |
| 35 | extern uint8_t text_end[]; |
| 36 | return pa_init((uintpaddr_t)text_end); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get the address the .rodata section begins at. |
| 41 | */ |
| 42 | static inline paddr_t layout_rodata_begin(void) |
| 43 | { |
| 44 | extern uint8_t rodata_begin[]; |
| 45 | return pa_init((uintpaddr_t)rodata_begin); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get the address the .rodata section ends at. |
| 50 | */ |
| 51 | static inline paddr_t layout_rodata_end(void) |
| 52 | { |
| 53 | extern uint8_t rodata_end[]; |
| 54 | return pa_init((uintpaddr_t)rodata_end); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Get the address the .data section begins at. |
| 59 | */ |
| 60 | static inline paddr_t layout_data_begin(void) |
| 61 | { |
| 62 | extern uint8_t data_begin[]; |
| 63 | return pa_init((uintpaddr_t)data_begin); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Get the address the .data section ends at. |
| 68 | */ |
| 69 | static inline paddr_t layout_data_end(void) |
| 70 | { |
| 71 | extern uint8_t data_end[]; |
| 72 | return pa_init((uintpaddr_t)data_end); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Get the address the loaded image ends at. |
| 77 | */ |
| 78 | static inline paddr_t layout_bin_end(void) |
| 79 | { |
| 80 | extern uint8_t bin_end[]; |
| 81 | return pa_init((uintpaddr_t)bin_end); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Get the address to load the primary VM at. |
| 86 | * |
| 87 | * This is placed just after the image. |
| 88 | */ |
| 89 | static inline paddr_t layout_primary_begin(void) |
| 90 | { |
| 91 | /* TODO: This is a hack. We must read the alignment from the binary. */ |
| 92 | paddr_t bin_end = layout_bin_end(); |
| 93 | return pa_init((pa_addr(bin_end) + 0x80000 - 1) & ~(0x80000 - 1)); |
| 94 | } |