1 /*
2  * Copyright 2019 The Hafnium Authors.
3  *
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.
7  */
8 
9 #include <stdalign.h>
10 #include <stdint.h>
11 
12 #include "hf/arch/vm/interrupts.h"
13 
14 #include "hf/mm.h"
15 
16 #include "hftest_common.h"
17 #include "test/hftest.h"
18 
19 alignas(4096) uint8_t kstack[4096];
20 
21 extern struct hftest_test hftest_begin[];
22 extern struct hftest_test hftest_end[];
23 
kmain(const void * fdt_ptr)24 void kmain(const void *fdt_ptr)
25 {
26 	struct fdt fdt;
27 	size_t fdt_len;
28 
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.");
34 		goto out;
35 	}
36 
37 	/*
38 	 * Install the exception handler with no IRQ callback for now, so that
39 	 * exceptions are logged.
40 	 */
41 	exception_setup(NULL, NULL);
42 
43 	hftest_use_list(hftest_begin, hftest_end - hftest_begin);
44 
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 
51 	hftest_command(&fdt);
52 
53 out:
54 	hftest_ctrl_finish();
55 	hftest_ctrl_reboot();
56 }
57