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