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