Contiki 3.x
syscalls-int.h
1 /*
2  * Copyright (C) 2015, Intel Corporation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * 3. Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef CPU_X86_MM_SYSCALLS_INT_H_
32 #define CPU_X86_MM_SYSCALLS_INT_H_
33 
34 /** Software interrupt number for dispatching a system call */
35 #define PROT_DOMAINS_SYSCALL_DISPATCH_INT 100
36 /** Software interrupt number for returning from a system call */
37 #define PROT_DOMAINS_SYSRET_DISPATCH_INT 101
38 
39 #if !__ASSEMBLER__
40 
41 #include <stdint.h>
42 
43 extern dom_id_t cur_dom;
44 
45 #define SYSCALLS_STUB_EPILOGUE(nm) \
46  /* Load the system call identifier into EAX, as required by */ \
47  /* prot_domains_syscall_dispatcher: */ \
48  " mov $" EXP_STRINGIFY(_syscall_ent_##nm) ", %eax\n\t" \
49  /* Check whether the server protection domain is already active: */ \
50  " cmp %edx, cur_dom\n\t" \
51  /* If so, skip the system call dispatcher and directly invoke the */ \
52  /* system call body: */ \
53  " je _syscall_" #nm "\n\t" \
54  " int $" EXP_STRINGIFY(PROT_DOMAINS_SYSCALL_DISPATCH_INT) "\n\t"
55 
56 #define SYSCALLS_STUB(nm) \
57  SYSCALLS_ALLOC_ENTRYPOINT(nm); \
58  asm ( \
59  ".text\n\t" \
60  ".global " #nm "\n\t" \
61  #nm ":\n\t" \
62  /* First, load server protection domain ID into EDX, as required by */ \
63  /* prot_domains_syscall_dispatcher: */ \
64  /* Skip past return address on stack to obtain address of protection */ \
65  /* domain ID parameter: */ \
66  " mov 4(%esp), %edx\n\t" \
67  SYSCALLS_STUB_EPILOGUE(nm))
68 
69 #define SYSCALLS_STUB_SINGLETON(nm, dcd) \
70  SYSCALLS_ALLOC_ENTRYPOINT(nm); \
71  asm ( \
72  ".text\n\t" \
73  ".global " #nm "\n\t" \
74  #nm ":\n\t" \
75  /* First, load server protection domain ID into EDX, as required by */ \
76  /* prot_domains_syscall_dispatcher: */ \
77  " mov %" SEG_KERN "s:" #dcd ", %edx\n\t" \
78  SYSCALLS_STUB_EPILOGUE(nm))
79 
80 void syscalls_int_init(void);
81 
82 void prot_domains_sysret_stub(void);
83 
84 /* Inter-privilege level interrupt stack with no error code. */
85 typedef struct interrupt_stack {
86  uint32_t eip;
87  uint32_t cs;
88  uint32_t eflags;
89  uint32_t esp;
90  uint32_t ss;
91 } interrupt_stack_t;
92 
93 #if 0
94 /* Declaration only included for documentation purposes: */
95 /**
96  * \brief Switch to a different protection domain.
97  * \param from_id Origin protection domain.
98  * \param to_id Destination protection domain.
99  * \return Segment selector for kernel data access (only used for
100  * multi-segment implementations).
101  */
102 uint32_t prot_domains_switch(dom_id_t from_id,
103  dom_id_t to_id,
104  interrupt_stack_t *intr_stk);
105 #endif
106 
107 #endif
108 
109 #endif /* CPU_X86_MM_SYSCALLS_INT_H_ */