Contiki 3.x
swseg-prot-domains.c
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 #include "gdt.h"
32 #include "helpers.h"
33 #include "multi-segment.h"
34 #include "prot-domains.h"
35 
36 /*---------------------------------------------------------------------------*/
37 void
38 prot_domains_reg(dom_client_data_t ATTR_KERN_ADDR_SPACE *dcd,
39  uintptr_t mmio, size_t mmio_sz,
40  uintptr_t meta, size_t meta_sz,
41  bool pio)
42 {
43  volatile dom_kern_data_t ATTR_KERN_ADDR_SPACE *dkd;
44  dom_id_t dom_id;
45 
46  KERN_READL(dom_id, dcd->dom_id);
47 
48  if(PROT_DOMAINS_ACTUAL_CNT <= dom_id) {
49  halt();
50  }
51 
52  dkd = prot_domains_kern_data + dom_id;
53 
54  prot_domains_reg_multi_seg(dkd, mmio, mmio_sz, meta, meta_sz);
55 
56  KERN_WRITEL(dkd->flags, pio ? PROT_DOMAINS_FLAG_PIO : 0);
57 }
58 /*---------------------------------------------------------------------------*/
59 static inline void __attribute__((always_inline))
60 prot_domains_switch(dom_id_t from_id, dom_id_t to_id,
61  interrupt_stack_t *intr_stk)
62 {
63  __asm__ __volatile__ (
64  "lldt %[_ldt_]\n\t"
65  "mov %[_meta_seg_], %%eax\n\t"
66  "lsl %%eax, %%ecx\n\t"
67  "jz 1f\n\t" /* ZF will only be set if the segment descriptor is valid. */
68  "xor %%eax, %%eax\n\t" /* Nullify metadata selector */
69  "1: mov %%eax, %%" SEG_META "s\n\t"
70  "mov %[_kern_seg_], %%eax\n\t"
71  "mov %%eax, %%" SEG_KERN "s\n\t"
72  :
73  : [_ldt_] "r" ((uint16_t)GDT_SEL_LDT(to_id)),
74  [_meta_seg_] "i" (LDT_SEL_META),
75  [_kern_seg_] "i" (LDT_SEL_KERN)
76  : "cc", "eax", "ecx"
77  );
78 }
79 /*---------------------------------------------------------------------------*/
80 
81 /* Enable inter-procedural optimization with procedures in the following file:
82  */
83 #include "syscalls-int.c"
#define __attribute__(nothing)
Define attribute to nothing since it isn't handled by IAR.
Definition: iar.h:194
Data associated with each protection domain that is owned by clients of that domain and used to ident...
Definition: prot-domains.h:247