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; |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 28 | struct memiter command_line; |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 29 | struct memiter command; |
| 30 | |
David Brazdil | 711fbe9 | 2019-08-06 13:39:58 +0100 | [diff] [blame] | 31 | /* |
| 32 | * Initialize the stage-1 MMU and identity-map the entire address space. |
| 33 | */ |
| 34 | if ((VM_TOOLCHAIN == 1) && !hftest_mm_init()) { |
| 35 | HFTEST_LOG("Memory initialization failed."); |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 36 | goto out; |
David Brazdil | 711fbe9 | 2019-08-06 13:39:58 +0100 | [diff] [blame] | 37 | } |
| 38 | |
Andrew Walbran | 0fc4d41 | 2019-11-06 17:22:32 +0000 | [diff] [blame] | 39 | /* |
| 40 | * Install the exception handler with no IRQ callback for now, so that |
| 41 | * exceptions are logged. |
| 42 | */ |
Fuad Tabba | 3e9b022 | 2019-11-11 16:47:50 +0000 | [diff] [blame] | 43 | exception_setup(NULL, NULL); |
Andrew Walbran | 0fc4d41 | 2019-11-06 17:22:32 +0000 | [diff] [blame] | 44 | |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 45 | hftest_use_list(hftest_begin, hftest_end - hftest_begin); |
| 46 | |
David Brazdil | b856be6 | 2020-03-25 10:14:55 +0000 | [diff] [blame] | 47 | if (!fdt_size_from_header(fdt_ptr, &fdt_len) || |
| 48 | !fdt_init_from_ptr(&fdt, fdt_ptr, fdt_len)) { |
| 49 | HFTEST_LOG("Unable to init FDT."); |
| 50 | goto out; |
| 51 | } |
| 52 | |
| 53 | if (!hftest_ctrl_start(&fdt, &command_line)) { |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 54 | HFTEST_LOG("Unable to read the command line."); |
| 55 | goto out; |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 56 | } |
| 57 | |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 58 | if (!memiter_parse_str(&command_line, &command)) { |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 59 | HFTEST_LOG("Unable to parse command."); |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 60 | goto out; |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 61 | } |
| 62 | |
David Brazdil | 88333cb | 2020-01-31 17:12:30 +0000 | [diff] [blame] | 63 | if (memiter_iseq(&command, "exit")) { |
| 64 | hftest_device_exit_test_environment(); |
| 65 | goto out; |
| 66 | } |
| 67 | |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 68 | if (memiter_iseq(&command, "json")) { |
| 69 | hftest_json(); |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 70 | goto out; |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | if (memiter_iseq(&command, "run")) { |
| 74 | struct memiter suite_name; |
| 75 | struct memiter test_name; |
| 76 | |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 77 | if (!memiter_parse_str(&command_line, &suite_name)) { |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 78 | HFTEST_LOG("Unable to parse test suite."); |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 79 | goto out; |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 80 | } |
| 81 | |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 82 | if (!memiter_parse_str(&command_line, &test_name)) { |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 83 | HFTEST_LOG("Unable to parse test."); |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 84 | goto out; |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 85 | } |
David Brazdil | b856be6 | 2020-03-25 10:14:55 +0000 | [diff] [blame] | 86 | hftest_run(suite_name, test_name, &fdt); |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 87 | goto out; |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | hftest_help(); |
David Brazdil | 17e7665 | 2020-01-29 14:44:19 +0000 | [diff] [blame] | 91 | |
| 92 | out: |
| 93 | hftest_ctrl_finish(); |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 94 | } |