1 /*
2  * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3  *
4  * SPDX-License-Identifier: GPL-2.0-only
5  */
6 
7 #include <assert.h>
8 #include <arch/machine/registerset.h>
9 #include <machine/fpu.h>
10 #include <arch/object/structures.h>
11 
12 const register_t msgRegisters[] = {
13     R10, R8, R9, R15
14 };
15 compile_assert(
16     consistent_message_registers,
17     sizeof(msgRegisters) / sizeof(msgRegisters[0]) == n_msgRegisters
18 );
19 
20 const register_t frameRegisters[] = {
21     FaultIP, RSP, FLAGS, RAX, RBX, RCX, RDX, RSI, RDI, RBP,
22     R8, R9, R10, R11, R12, R13, R14, R15
23 };
24 compile_assert(
25     consistent_frame_registers,
26     sizeof(frameRegisters) / sizeof(frameRegisters[0]) == n_frameRegisters
27 );
28 
29 const register_t gpRegisters[] = {
30     FS_BASE, GS_BASE
31 };
32 compile_assert(
33     consistent_gp_registers,
34     sizeof(gpRegisters) / sizeof(gpRegisters[0]) == n_gpRegisters
35 );
36 
Mode_initContext(user_context_t * context)37 void Mode_initContext(user_context_t *context)
38 {
39     context->registers[RAX] = 0;
40     context->registers[RBX] = 0;
41     context->registers[RCX] = 0;
42     context->registers[RDX] = 0;
43     context->registers[RSI] = 0;
44     context->registers[RDI] = 0;
45     context->registers[RBP] = 0;
46     context->registers[R8]  = 0;
47     context->registers[R9]  = 0;
48     context->registers[R10] = 0;
49     context->registers[R11] = 0;
50     context->registers[R12] = 0;
51     context->registers[R13] = 0;
52     context->registers[R14] = 0;
53     context->registers[R15] = 0;
54     context->registers[RSP] = 0;
55 }
56 
Mode_sanitiseRegister(register_t reg,word_t v)57 word_t Mode_sanitiseRegister(register_t reg, word_t v)
58 {
59     if (reg == FaultIP || reg == NextIP || reg == FS_BASE || reg == GS_BASE) {
60         /* ensure instruction address is canonical */
61         if (v > 0x00007fffffffffff && v < 0xffff800000000000) {
62             /* no way to guess what the user wanted so give them zero */
63             v = 0;
64         }
65     }
66     return v;
67 }
68 
69 #ifdef CONFIG_KERNEL_MCS
getNBSendRecvDest(void)70 word_t getNBSendRecvDest(void)
71 {
72     return getRegister(NODE_STATE(ksCurThread), nbsendRecvDest);
73 }
74 #endif
75