blob: 91b53b5022c5dba3d252735e9582f530e2a26eb5 [file] [log] [blame]
Andrew Walbranbc342d42019-02-05 16:56:02 +00001/*
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 Walbran0fc4d412019-11-06 17:22:32 +000020#include "hf/arch/vm/interrupts.h"
21
David Brazdil711fbe92019-08-06 13:39:58 +010022#include "hf/mm.h"
Andrew Walbranbc342d42019-02-05 16:56:02 +000023
Andrew Walbranbc342d42019-02-05 16:56:02 +000024#include "hftest_common.h"
Andrew Walbran1e7c7742019-12-13 17:10:02 +000025#include "test/hftest.h"
Andrew Walbranbc342d42019-02-05 16:56:02 +000026
27alignas(4096) uint8_t kstack[4096];
28
29extern struct hftest_test hftest_begin[];
30extern struct hftest_test hftest_end[];
31
32void kmain(const struct fdt_header *fdt)
33{
David Brazdil17e76652020-01-29 14:44:19 +000034 struct memiter command_line;
Andrew Walbranbc342d42019-02-05 16:56:02 +000035 struct memiter command;
36
David Brazdil711fbe92019-08-06 13:39:58 +010037 /*
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 Brazdil17e76652020-01-29 14:44:19 +000042 goto out;
David Brazdil711fbe92019-08-06 13:39:58 +010043 }
44
Andrew Walbran0fc4d412019-11-06 17:22:32 +000045 /*
46 * Install the exception handler with no IRQ callback for now, so that
47 * exceptions are logged.
48 */
Fuad Tabba3e9b0222019-11-11 16:47:50 +000049 exception_setup(NULL, NULL);
Andrew Walbran0fc4d412019-11-06 17:22:32 +000050
Andrew Walbranbc342d42019-02-05 16:56:02 +000051 hftest_use_list(hftest_begin, hftest_end - hftest_begin);
52
David Brazdil17e76652020-01-29 14:44:19 +000053 if (!hftest_ctrl_start(fdt, &command_line)) {
54 HFTEST_LOG("Unable to read the command line.");
55 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000056 }
57
David Brazdil17e76652020-01-29 14:44:19 +000058 if (!memiter_parse_str(&command_line, &command)) {
Andrew Walbranbc342d42019-02-05 16:56:02 +000059 HFTEST_LOG("Unable to parse command.");
David Brazdil17e76652020-01-29 14:44:19 +000060 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000061 }
62
63 if (memiter_iseq(&command, "json")) {
64 hftest_json();
David Brazdil17e76652020-01-29 14:44:19 +000065 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000066 }
67
68 if (memiter_iseq(&command, "run")) {
69 struct memiter suite_name;
70 struct memiter test_name;
71
David Brazdil17e76652020-01-29 14:44:19 +000072 if (!memiter_parse_str(&command_line, &suite_name)) {
Andrew Walbranbc342d42019-02-05 16:56:02 +000073 HFTEST_LOG("Unable to parse test suite.");
David Brazdil17e76652020-01-29 14:44:19 +000074 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000075 }
76
David Brazdil17e76652020-01-29 14:44:19 +000077 if (!memiter_parse_str(&command_line, &test_name)) {
Andrew Walbranbc342d42019-02-05 16:56:02 +000078 HFTEST_LOG("Unable to parse test.");
David Brazdil17e76652020-01-29 14:44:19 +000079 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000080 }
Andrew Walbranafabe852019-03-20 17:55:11 +000081 hftest_run(suite_name, test_name, fdt);
David Brazdil17e76652020-01-29 14:44:19 +000082 goto out;
Andrew Walbranbc342d42019-02-05 16:56:02 +000083 }
84
85 hftest_help();
David Brazdil17e76652020-01-29 14:44:19 +000086
87out:
88 hftest_ctrl_finish();
Andrew Walbranbc342d42019-02-05 16:56:02 +000089}