Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Hafnium Authors. |
| 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style |
| 5 | * license that can be found in the LICENSE file or at |
| 6 | * https://opensource.org/licenses/BSD-3-Clause. |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <stdalign.h> |
| 10 | #include <stdint.h> |
| 11 | |
Andrew Walbran | 0fc4d41 | 2019-11-06 17:22:32 +0000 | [diff] [blame] | 12 | #include "hf/arch/vm/interrupts.h" |
| 13 | |
David Brazdil | 711fbe9 | 2019-08-06 13:39:58 +0100 | [diff] [blame] | 14 | #include "hf/mm.h" |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 15 | |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 16 | #include "hftest_common.h" |
Andrew Walbran | 1e7c774 | 2019-12-13 17:10:02 +0000 | [diff] [blame] | 17 | #include "test/hftest.h" |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 18 | |
| 19 | alignas(4096) uint8_t kstack[4096]; |
| 20 | |
| 21 | extern struct hftest_test hftest_begin[]; |
| 22 | extern struct hftest_test hftest_end[]; |
| 23 | |
David Brazdil | b856be6 | 2020-03-25 10:14:55 +0000 | [diff] [blame] | 24 | void kmain(const void *fdt_ptr) |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 25 | { |
David Brazdil | b856be6 | 2020-03-25 10:14:55 +0000 | [diff] [blame] | 26 | struct fdt fdt; |
| 27 | size_t fdt_len; |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 28 | |
David Brazdil | 711fbe9 | 2019-08-06 13:39:58 +0100 | [diff] [blame] | 29 | /* |
| 30 | * Initialize the stage-1 MMU and identity-map the entire address space. |
| 31 | */ |
| 32 | if ((VM_TOOLCHAIN == 1) && !hftest_mm_init()) { |
| 33 | HFTEST_LOG("Memory initialization failed."); |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 34 | goto out; |
David Brazdil | 711fbe9 | 2019-08-06 13:39:58 +0100 | [diff] [blame] | 35 | } |
| 36 | |
Andrew Walbran | 0fc4d41 | 2019-11-06 17:22:32 +0000 | [diff] [blame] | 37 | /* |
| 38 | * Install the exception handler with no IRQ callback for now, so that |
| 39 | * exceptions are logged. |
| 40 | */ |
Fuad Tabba | 3e9b022 | 2019-11-11 16:47:50 +0000 | [diff] [blame] | 41 | exception_setup(NULL, NULL); |
Andrew Walbran | 0fc4d41 | 2019-11-06 17:22:32 +0000 | [diff] [blame] | 42 | |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 43 | hftest_use_list(hftest_begin, hftest_end - hftest_begin); |
| 44 | |
David Brazdil | b856be6 | 2020-03-25 10:14:55 +0000 | [diff] [blame] | 45 | if (!fdt_size_from_header(fdt_ptr, &fdt_len) || |
| 46 | !fdt_init_from_ptr(&fdt, fdt_ptr, fdt_len)) { |
| 47 | HFTEST_LOG("Unable to init FDT."); |
| 48 | goto out; |
| 49 | } |
| 50 | |
J-Alves | 070a40d | 2021-01-21 14:35:12 +0000 | [diff] [blame] | 51 | hftest_command(&fdt); |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 52 | |
| 53 | out: |
| 54 | hftest_ctrl_finish(); |
Olivier Deprez | ea0e019 | 2022-06-03 08:47:52 +0200 | [diff] [blame] | 55 | hftest_ctrl_reboot(); |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 56 | } |