|
| 1 | +/* |
| 2 | + * Copyright (c) 2013-2016, ARM Limited, All Rights Reserved |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | + * not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +#ifndef __UVISOR_API_SVC_EXPORTS_H__ |
| 18 | +#define __UVISOR_API_SVC_EXPORTS_H__ |
| 19 | + |
| 20 | +#include "api/inc/uvisor_exports.h" |
| 21 | +#include "api/inc/api.h" |
| 22 | +#include <stdint.h> |
| 23 | + |
| 24 | +/* An SVCall takes a 8bit immediate, which is used as follows: |
| 25 | + * |
| 26 | + * For fast APIs: |
| 27 | + * |
| 28 | + * 7 6 5 4 3 2 1 0 |
| 29 | + * .---.---.---.---.---.---.---.---. |
| 30 | + * | 1 | N | N | N | h | h | h | h | |
| 31 | + * '---'---'---'---'---'---'---'---' |
| 32 | + * | |_______| |___________| |
| 33 | + * | | | |
| 34 | + * | | | |
| 35 | + * | | | |
| 36 | + * | | (h) Handler index in the hardcoded table (max 16) |
| 37 | + * | | |
| 38 | + * | (N) Number of arguments to pass to the handler (max 4) |
| 39 | + * | |
| 40 | + * SVCall mode: Fast |
| 41 | + * |
| 42 | + * For slow APIs: |
| 43 | + * |
| 44 | + * 7 6 5 4 3 2 1 0 |
| 45 | + * .---.---.---.---.---.---.---.---. |
| 46 | + * | 0 | c | c | c | c | c | c | c | |
| 47 | + * '---'---'---'---'---'---'---'---' |
| 48 | + * | |_______________________| |
| 49 | + * | | |
| 50 | + * | | |
| 51 | + * | (c) Handler index in the custom table (max 128) |
| 52 | + * | |
| 53 | + * SVCall mode: Slow |
| 54 | + */ |
| 55 | + |
| 56 | +/* 1 bit of the SVCall imm8 field is used to determine the mode, fast/slow. */ |
| 57 | +#define UVISOR_SVC_MODE_FAST 1 |
| 58 | +#define UVISOR_SVC_MODE_SLOW 0 |
| 59 | +#define UVISOR_SVC_MODE_BIT 7 |
| 60 | +#define UVISOR_SVC_MODE_MASK ((uint8_t) (1 << UVISOR_SVC_MODE_BIT)) |
| 61 | +#define UVISOR_SVC_MODE(mode) ((uint8_t) (((mode) << UVISOR_SVC_MODE_BIT) & UVISOR_SVC_MODE_MASK)) |
| 62 | + |
| 63 | +/* 7 or 4 bits of the SVCall imm8 field are used to determine the table index, |
| 64 | + * depending on the mode, fast/slow. */ |
| 65 | +#define UVISOR_SVC_FAST_INDEX_MAX (1 << 4) |
| 66 | +#define UVISOR_SVC_SLOW_INDEX_MAX (1 << 7) |
| 67 | +#define UVISOR_SVC_FAST_INDEX_BIT 0 |
| 68 | +#define UVISOR_SVC_FAST_INDEX_MASK ((uint8_t) (0xF << UVISOR_SVC_FAST_INDEX_BIT)) |
| 69 | +#define UVISOR_SVC_SLOW_INDEX_BIT 0 |
| 70 | +#define UVISOR_SVC_SLOW_INDEX_MASK ((uint8_t) (0x7F << UVISOR_SVC_SLOW_INDEX_BIT)) |
| 71 | +#define UVISOR_SVC_FAST_INDEX(index) ((uint8_t) (((index) << UVISOR_SVC_FAST_INDEX_BIT) & UVISOR_SVC_FAST_INDEX_MASK)) |
| 72 | +#define UVISOR_SVC_SLOW_INDEX(index) ((uint8_t) (((index) << UVISOR_SVC_SLOW_INDEX_BIT) & UVISOR_SVC_SLOW_INDEX_MASK)) |
| 73 | + |
| 74 | +/* When the SVC mode is "fast", the imm8 field also contains a specification of |
| 75 | + * the call interface (number of arguments). |
| 76 | + * This is needed for context switches, since the stack manipulation routines |
| 77 | + * need to know how many arguments to copy from source to destination. */ |
| 78 | +#define UVISOR_SVC_FAST_NARGS_BIT 4 |
| 79 | +#define UVISOR_SVC_FAST_NARGS_MASK ((uint8_t) (0x7 << UVISOR_SVC_FAST_NARGS_BIT)) |
| 80 | +#define UVISOR_SVC_FAST_NARGS_SET(nargs) ((uint8_t) (((nargs) << UVISOR_SVC_FAST_NARGS_BIT) & UVISOR_SVC_FAST_NARGS_MASK)) |
| 81 | +#define UVISOR_SVC_FAST_NARGS_GET(svc_id) (((uint8_t) (svc_id) & UVISOR_SVC_FAST_NARGS_MASK) >> UVISOR_SVC_FAST_NARGS_BIT) |
| 82 | + |
| 83 | +/* Macros to build the SVCall imm8 field. |
| 84 | + * For slow APIs only the SVC handler index is needed. |
| 85 | + * For fast APIs the SVC handler index and the number of arguments are needed. */ |
| 86 | +#define UVISOR_SVC_CUSTOM_TABLE(index) ((uint8_t) (UVISOR_SVC_MODE(UVISOR_SVC_MODE_SLOW) | \ |
| 87 | + UVISOR_SVC_SLOW_INDEX(index))) |
| 88 | +#define UVISOR_SVC_FIXED_TABLE(index, nargs) ((uint8_t) (UVISOR_SVC_MODE(UVISOR_SVC_MODE_FAST) | \ |
| 89 | + UVISOR_SVC_FAST_INDEX(index) | \ |
| 90 | + UVISOR_SVC_FAST_NARGS_SET(nargs))) |
| 91 | + |
| 92 | +/* SVC immediate values for hardcoded table (call from unprivileged) */ |
| 93 | +#define UVISOR_SVC_ID_UNVIC_OUT UVISOR_SVC_FIXED_TABLE(0, 0) |
| 94 | +/* Deprecated: UVISOR_SVC_ID_CX_IN(nargs) UVISOR_SVC_FIXED_TABLE(1, nargs) */ |
| 95 | +/* Deprecated: UVISOR_SVC_ID_CX_OUT UVISOR_SVC_FIXED_TABLE(2, 0) */ |
| 96 | +#define UVISOR_SVC_ID_REGISTER_GATEWAY UVISOR_SVC_FIXED_TABLE(3, 0) |
| 97 | +#define UVISOR_SVC_ID_BOX_INIT_FIRST UVISOR_SVC_FIXED_TABLE(4, 0) |
| 98 | +#define UVISOR_SVC_ID_BOX_INIT_NEXT UVISOR_SVC_FIXED_TABLE(5, 0) |
| 99 | + |
| 100 | +/* SVC immediate values for hardcoded table (call from privileged) */ |
| 101 | +#define UVISOR_SVC_ID_UNVIC_IN UVISOR_SVC_FIXED_TABLE(0, 0) |
| 102 | + |
| 103 | +#endif /* __UVISOR_API_SVC_EXPORTS_H__ */ |
0 commit comments