Conrad Grobler | a824af6 | 2019-03-22 17:33:23 +0000 | [diff] [blame] | 1 | /* |
| 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 Grobler | 02ff6af | 2019-06-04 09:40:28 +0100 | [diff] [blame] | 24 | #include "../msr.h" |
Conrad Grobler | a824af6 | 2019-03-22 17:33:23 +0000 | [diff] [blame] | 25 | #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 | */ |
| 34 | TEST(floating_point, fp_fill) |
| 35 | { |
| 36 | const double first = 1.2; |
| 37 | const double second = -2.3; |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 38 | struct spci_value run_res; |
Conrad Grobler | a824af6 | 2019-03-22 17:33:23 +0000 | [diff] [blame] | 39 | struct mailbox_buffers mb = set_up_mailbox(); |
| 40 | |
| 41 | fill_fp_registers(first); |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame^] | 42 | SERVICE_SELECT(SERVICE_VM1, "fp_fill", mb.send); |
| 43 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 44 | EXPECT_EQ(run_res.func, SPCI_YIELD_32); |
Conrad Grobler | a824af6 | 2019-03-22 17:33:23 +0000 | [diff] [blame] | 45 | EXPECT_EQ(check_fp_register(first), true); |
| 46 | |
| 47 | fill_fp_registers(second); |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame^] | 48 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 49 | EXPECT_EQ(run_res.func, SPCI_YIELD_32); |
Conrad Grobler | a824af6 | 2019-03-22 17:33:23 +0000 | [diff] [blame] | 50 | EXPECT_EQ(check_fp_register(second), true); |
| 51 | } |
Conrad Grobler | 02ff6af | 2019-06-04 09:40:28 +0100 | [diff] [blame] | 52 | |
| 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 | */ |
| 57 | TEST(floating_point, fp_fpcr) |
| 58 | { |
| 59 | uintreg_t value = 0; |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 60 | struct spci_value run_res; |
Conrad Grobler | 02ff6af | 2019-06-04 09:40:28 +0100 | [diff] [blame] | 61 | struct mailbox_buffers mb = set_up_mailbox(); |
| 62 | |
| 63 | EXPECT_EQ(read_msr(fpcr), value); |
| 64 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame^] | 65 | SERVICE_SELECT(SERVICE_VM1, "fp_fpcr", mb.send); |
| 66 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 67 | EXPECT_EQ(run_res.func, SPCI_YIELD_32); |
Conrad Grobler | 02ff6af | 2019-06-04 09:40:28 +0100 | [diff] [blame] | 68 | EXPECT_EQ(read_msr(fpcr), value); |
| 69 | |
Fuad Tabba | 7bd1413 | 2019-11-07 14:18:52 +0000 | [diff] [blame^] | 70 | run_res = spci_run(SERVICE_VM1, 0); |
Andrew Walbran | 27faff3 | 2019-10-02 18:20:57 +0100 | [diff] [blame] | 71 | EXPECT_EQ(run_res.func, SPCI_YIELD_32); |
Conrad Grobler | 02ff6af | 2019-06-04 09:40:28 +0100 | [diff] [blame] | 72 | EXPECT_EQ(read_msr(fpcr), value); |
| 73 | } |