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