paul@60 | 1 | /* |
paul@60 | 2 | * Payload initialisation functions. |
paul@60 | 3 | * |
paul@60 | 4 | * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk> |
paul@60 | 5 | * |
paul@60 | 6 | * This program is free software: you can redistribute it and/or modify |
paul@60 | 7 | * it under the terms of the GNU General Public License as published by |
paul@60 | 8 | * the Free Software Foundation, either version 3 of the License, or |
paul@60 | 9 | * (at your option) any later version. |
paul@60 | 10 | * |
paul@60 | 11 | * This program is distributed in the hope that it will be useful, |
paul@60 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@60 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@60 | 14 | * GNU General Public License for more details. |
paul@60 | 15 | * |
paul@60 | 16 | * You should have received a copy of the GNU General Public License |
paul@60 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@60 | 18 | */ |
paul@60 | 19 | |
paul@60 | 20 | #include <stdint.h> |
paul@60 | 21 | |
paul@66 | 22 | |
paul@66 | 23 | |
paul@67 | 24 | extern uint8_t _data_original[], _data[], _bss[]; |
paul@64 | 25 | |
paul@66 | 26 | /* These are defined using SIZEOF and their table entries contain actual values. |
paul@66 | 27 | The "address" provided by each entry is therefore the value! */ |
paul@64 | 28 | |
paul@66 | 29 | extern uint32_t _data_size, _bss_size; |
paul@64 | 30 | |
paul@60 | 31 | /* Relocate the .data section's contents to initialise mutable structures. */ |
paul@60 | 32 | |
paul@64 | 33 | void relocate_data(void) |
paul@60 | 34 | { |
paul@67 | 35 | uint8_t *original = _data_original, *current = _data, |
paul@64 | 36 | *limit = original + (uint32_t) &_data_size; |
paul@60 | 37 | |
paul@60 | 38 | /* Copy data from program memory to the relocated data area in RAM. */ |
paul@60 | 39 | |
paul@63 | 40 | while (original < limit) |
paul@63 | 41 | *current++ = *original++; |
paul@60 | 42 | } |
paul@66 | 43 | |
paul@66 | 44 | /* Clear the .bss section. */ |
paul@66 | 45 | |
paul@66 | 46 | void init_bss(void) |
paul@66 | 47 | { |
paul@67 | 48 | uint8_t *current = _bss, *limit = current + (uint32_t) &_bss_size; |
paul@66 | 49 | |
paul@66 | 50 | while (current < limit) |
paul@66 | 51 | *current++ = 0; |
paul@66 | 52 | } |