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