blob: 88656e41e03dba687c827a721c9e424d3ea64ae4 [file] [log] [blame]
Conrad Groblera824af62019-03-22 17:33:23 +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 "hf/arch/std.h"
18#include "hf/arch/vm/registers.h"
19
20#include "hf/spci.h"
21
22#include "vmapi/hf/call.h"
23
Conrad Grobler02ff6af2019-06-04 09:40:28 +010024#include "../msr.h"
Conrad Groblera824af62019-03-22 17:33:23 +000025#include "hftest.h"
26#include "primary_with_secondary.h"
27#include "util.h"
28
29/**
30 * Test that floating point registers are saved and restored by
31 * filling them with one value here and a different value in the
32 * service.
33 */
34TEST(floating_point, fp_fill)
35{
36 const double first = 1.2;
37 const double second = -2.3;
Andrew Walbran27faff32019-10-02 18:20:57 +010038 struct spci_value run_res;
Conrad Groblera824af62019-03-22 17:33:23 +000039 struct mailbox_buffers mb = set_up_mailbox();
40
41 fill_fp_registers(first);
Fuad Tabba7bd14132019-11-07 14:18:52 +000042 SERVICE_SELECT(SERVICE_VM1, "fp_fill", mb.send);
43 run_res = spci_run(SERVICE_VM1, 0);
Andrew Walbran27faff32019-10-02 18:20:57 +010044 EXPECT_EQ(run_res.func, SPCI_YIELD_32);
Conrad Groblera824af62019-03-22 17:33:23 +000045 EXPECT_EQ(check_fp_register(first), true);
46
47 fill_fp_registers(second);
Fuad Tabba7bd14132019-11-07 14:18:52 +000048 run_res = spci_run(SERVICE_VM1, 0);
Andrew Walbran27faff32019-10-02 18:20:57 +010049 EXPECT_EQ(run_res.func, SPCI_YIELD_32);
Conrad Groblera824af62019-03-22 17:33:23 +000050 EXPECT_EQ(check_fp_register(second), true);
51}
Conrad Grobler02ff6af2019-06-04 09:40:28 +010052
53/**
54 * Test that the floating point control register is restored correctly
55 * on full context switch when needed by changing it in the service.
56 */
57TEST(floating_point, fp_fpcr)
58{
59 uintreg_t value = 0;
Andrew Walbran27faff32019-10-02 18:20:57 +010060 struct spci_value run_res;
Conrad Grobler02ff6af2019-06-04 09:40:28 +010061 struct mailbox_buffers mb = set_up_mailbox();
62
63 EXPECT_EQ(read_msr(fpcr), value);
64
Fuad Tabba7bd14132019-11-07 14:18:52 +000065 SERVICE_SELECT(SERVICE_VM1, "fp_fpcr", mb.send);
66 run_res = spci_run(SERVICE_VM1, 0);
Andrew Walbran27faff32019-10-02 18:20:57 +010067 EXPECT_EQ(run_res.func, SPCI_YIELD_32);
Conrad Grobler02ff6af2019-06-04 09:40:28 +010068 EXPECT_EQ(read_msr(fpcr), value);
69
Fuad Tabba7bd14132019-11-07 14:18:52 +000070 run_res = spci_run(SERVICE_VM1, 0);
Andrew Walbran27faff32019-10-02 18:20:57 +010071 EXPECT_EQ(run_res.func, SPCI_YIELD_32);
Conrad Grobler02ff6af2019-06-04 09:40:28 +010072 EXPECT_EQ(read_msr(fpcr), value);
73}