• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 
13 #pragma once
14 
15 /* Use -1 instead of 0 (NULL) since 0 is used as the ending mark of envp */
16 #define ENVP_NONE_PMOS (-1)
17 #define ENVP_NONE_CAPS (-1)
18 
19 /* ChCore custom auxiliary vector types */
20 #define AT_CHCORE_PMO_CNT      0xCC00
21 #define AT_CHCORE_PMO_MAP_ADDR 0xCC01
22 #define AT_CHCORE_CAP_CNT      0xCC02
23 #define AT_CHCORE_CAP_VAL      0xCC03
24 
25 /* Used for usys_fs_load_cpio */
26 /* wh_cpio */
27 #define FSM_CPIO     0
28 #define TMPFS_CPIO   1
29 #define RAMDISK_CPIO 2
30 /* op */
31 #define QUERY_SIZE 0
32 #define LOAD_CPIO  1
33 
34 /*
35  * Used as a token which is added at the beginnig of the path name
36  * during booting a system server. E.g., "kernel-server/fsm.srv"
37  *
38  * This is simply for preventing users unintentionally
39  * run system servers in Shell. That is meaningless.
40  */
41 #define KERNEL_SERVER "kernel-server"
42 
43 #define NO_AFF       (-1)
44 #define NO_ARG       (0)
45 #define PASSIVE_PRIO (-1)
46 
47 /* cache operations */
48 #define CACHE_CLEAN         1
49 #define CACHE_INVALIDATE    2
50 #define CACHE_CLEAN_AND_INV 3
51 #define SYNC_IDCACHE        4
52 
53 /* virtual memory rights */
54 #define VM_READ   (1 << 0)
55 #define VM_WRITE  (1 << 1)
56 #define VM_EXEC   (1 << 2)
57 #define VM_FORBID (0)
58 
59 /* PMO types */
60 #define PMO_ANONYM       0
61 #define PMO_DATA         1
62 #define PMO_FILE         2
63 #define PMO_SHM          3
64 #define PMO_DATA_NOCACHE 6
65 #define PMO_FORBID       10
66 
67 /* a thread's own cap_group */
68 #define SELF_CAP 0
69 
70 #define DEFAULT_PRIO 10
71 
72 
73 #if __SIZEOF_POINTER__ == 4
74 #define CHILD_THREAD_STACK_BASE (0x50800000UL)
75 #define CHILD_THREAD_STACK_SIZE (0x200000UL)
76 #else
77 #define CHILD_THREAD_STACK_BASE (0x500000800000UL)
78 #define CHILD_THREAD_STACK_SIZE (0x800000UL)
79 #endif
80 #define CHILD_THREAD_PRIO (DEFAULT_PRIO)
81 
82 #if __SIZEOF_POINTER__ == 4
83 #define MAIN_THREAD_STACK_BASE (0x50000000UL)
84 #define MAIN_THREAD_STACK_SIZE (0x200000UL)
85 #else
86 #define MAIN_THREAD_STACK_BASE (0x500000000000UL)
87 #define MAIN_THREAD_STACK_SIZE (0x800000UL)
88 #endif
89 #define MAIN_THREAD_PRIO (DEFAULT_PRIO)
90 
91 #define IPC_PER_SHM_SIZE (0x1000)
92 
93 #define ROUND_UP(x, n)   (((x) + (n)-1) & ~((n)-1))
94 #define ROUND_DOWN(x, n) ((x) & ~((n)-1))
95 
96 #define unused(x) ((void)(x))
97 
98 #ifndef PAGE_SIZE
99 #define PAGE_SIZE 0x1000
100 #endif
101 
102 /**
103  * read(2):
104  * On Linux, read() (and similar system calls) will transfer at most
105  * 0x7ffff000 (2,147,479,552) bytes, returning the number of bytes
106  * actually transferred.  (This is true on both 32-bit and 64-bit
107  * systems.)
108  */
109 #define READ_SIZE_MAX (0x7ffff000)
110 
111 /* Syscall numbers */
112 
113 /* Character */
114 #define CHCORE_SYS_putstr 0
115 #define CHCORE_SYS_getc   1
116 
117 #define CHCORE_SYS_tee_push_rdr_update_addr 5
118 #define CHCORE_SYS_debug_rdr_logitem        6
119 
120 /* PMO */
121 /* - single */
122 #define CHCORE_SYS_create_pmo        10
123 #define CHCORE_SYS_create_device_pmo 11
124 #define CHCORE_SYS_map_pmo           12
125 #define CHCORE_SYS_unmap_pmo         13
126 #define CHCORE_SYS_write_pmo         14
127 #define CHCORE_SYS_read_pmo          15
128 #ifdef CHCORE_OH_TEE
129 #define CHCORE_SYS_create_ns_pmo         16
130 #define CHCORE_SYS_destroy_ns_pmo        17
131 #define CHCORE_SYS_create_tee_shared_pmo 19
132 #define CHCORE_SYS_transfer_pmo_owner    20
133 #endif /* CHCORE_OH_TEE */
134 
135 /* - address translation */
136 #define CHCORE_SYS_get_phys_addr 31
137 
138 /* Capability */
139 #define CHCORE_SYS_revoke_cap    18
140 #define CHCORE_SYS_transfer_caps 62
141 
142 /* Multitask */
143 /* - create & exit */
144 #define CHCORE_SYS_create_cap_group 80
145 #define CHCORE_SYS_exit_group       81
146 #define CHCORE_SYS_create_thread    82
147 #define CHCORE_SYS_thread_exit      83
148 #ifdef CHCORE_OH_TEE
149 #define CHCORE_SYS_get_thread_id    84
150 #define CHCORE_SYS_terminate_thread 85
151 #endif /* CHCORE_OH_TEE */
152 #define CHCORE_SYS_kill_group 86
153 /* - recycle */
154 #define CHCORE_SYS_register_recycle     90
155 #define CHCORE_SYS_cap_group_recycle    91
156 #define CHCORE_SYS_ipc_close_connection 92
157 /* - schedule */
158 #define CHCORE_SYS_yield        100
159 #define CHCORE_SYS_set_affinity 101
160 #define CHCORE_SYS_get_affinity 102
161 #define CHCORE_SYS_set_prio     103
162 #define CHCORE_SYS_get_prio     104
163 
164 /* IPC */
165 /* - procedure call */
166 #define CHCORE_SYS_register_server         120
167 #define CHCORE_SYS_register_client         121
168 #define CHCORE_SYS_ipc_register_cb_return  122
169 #define CHCORE_SYS_ipc_call                123
170 #define CHCORE_SYS_ipc_return              124
171 #define CHCORE_SYS_ipc_exit_routine_return 125
172 /* - notification */
173 #define CHCORE_SYS_create_notifc 130
174 #define CHCORE_SYS_wait          131
175 #define CHCORE_SYS_notify        132
176 
177 #ifdef CHCORE_OH_TEE
178 /* - oh-tee-ipc */
179 #define CHCORE_SYS_tee_msg_create_msg_hdl 140
180 #define CHCORE_SYS_tee_msg_create_channel 141
181 #define CHCORE_SYS_tee_msg_stop_channel   142
182 
183 #define CHCORE_SYS_tee_msg_receive 143
184 #define CHCORE_SYS_tee_msg_call    144
185 #define CHCORE_SYS_tee_msg_reply   145
186 #define CHCORE_SYS_tee_msg_notify  146
187 #endif /* CHCORE_OH_TEE */
188 
189 /* Exception */
190 /* - irq */
191 #define CHCORE_SYS_irq_register      150
192 #define CHCORE_SYS_irq_wait          151
193 #define CHCORE_SYS_irq_ack           152
194 #define CHCORE_SYS_cache_config      158
195 #define CHCORE_SYS_disable_local_irq 159
196 #define CHCORE_SYS_enable_local_irq  160
197 #define CHCORE_SYS_disable_irqno     155
198 #define CHCORE_SYS_enable_irqno      156
199 #define CHCORE_SYS_irq_op            40
200 #define CHCORE_SYS_irq_stop          41
201 
202 /* - page fault */
203 #define CHCORE_SYS_user_fault_register 165
204 #define CHCORE_SYS_user_fault_map      166
205 
206 /* Hardware Access (Privileged Instruction) */
207 /* - cache */
208 #define CHCORE_SYS_cache_flush 180
209 /* - timer */
210 #define CHCORE_SYS_get_current_tick 185
211 
212 /* POSIX */
213 /* - time */
214 #define CHCORE_SYS_clock_gettime   200
215 #define CHCORE_SYS_clock_nanosleep 201
216 /* - memory */
217 #define CHCORE_SYS_handle_brk      210
218 #define CHCORE_SYS_handle_mprotect 213
219 
220 /* CPIO */
221 
222 #define CHCORE_SYS_fs_load_cpio 215
223 
224 /* Debug */
225 #define CHCORE_SYS_debug_log         220
226 #define CHCORE_SYS_top               221
227 #define CHCORE_SYS_get_free_mem_size 222
228 #define CHCORE_SYS_get_mem_usage_msg 223
229 
230 /* Performance Benchmark */
231 #define CHCORE_SYS_perf_start 230
232 #define CHCORE_SYS_perf_end   231
233 #define CHCORE_SYS_perf_null  232
234 
235 /* Get PCI devcie information. */
236 #define CHCORE_SYS_get_pci_device 233
237 
238 /* poweroff */
239 #define CHCORE_SYS_poweroff 234
240 
241 /* Virtualization */
242 #define CHCORE_SYS_virt_dispatch 240
243 
244 /* TrustZone */
245 #define CHCORE_SYS_tee_wait_switch_req 250
246 #define CHCORE_SYS_tee_switch_req      251
247 #define CHCORE_SYS_tee_create_ns_pmo   252
248 #define CHCORE_SYS_tee_pull_kernel_var 253
249