1 /*
2 * Copyright (c) 2015, Google Inc. All rights reserved
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24 #include <kernel/thread.h>
25 #include <lk/init.h>
26 #include <stdbool.h>
27 #include <stdio.h>
28
29 #define FPTEST_THREAD_COUNT (2)
30
31 void fptest_arch_init(uint64_t base_value);
32 int fptest_arch_check_state(uint64_t base_value);
33
fptest(void * arg)34 static int fptest(void* arg) {
35 int i = (uintptr_t)arg;
36 int corrupted_regs;
37
38 fptest_arch_init(i);
39 while (true) {
40 thread_sleep((1 + i) * 10 * 1000);
41 corrupted_regs = fptest_arch_check_state(i);
42 if (corrupted_regs) {
43 printf("%s(%d): bad register state detected, %d registers corrupted\n",
44 __func__, i, corrupted_regs);
45 } else {
46 printf("%s(%d): register state OK\n", __func__, i);
47 }
48 }
49 return 0;
50 }
51
fptest_init(uint level)52 static void fptest_init(uint level) {
53 int i;
54 int cpu = 0; /* test only on cpu for now */
55 char thread_name[32];
56 thread_t* thread;
57
58 for (i = 0; i < FPTEST_THREAD_COUNT; i++) {
59 snprintf(thread_name, sizeof(thread_name), "fptest-%d-%d", cpu, i);
60 thread = thread_create(thread_name, fptest, (void*)(uintptr_t)i,
61 DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
62 thread->pinned_cpu = cpu;
63 thread_resume(thread);
64 }
65 }
66
67 LK_INIT_HOOK(fptest, fptest_init, LK_INIT_LEVEL_APPS);
68