Contiki 3.x
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 "prot-domains.h"
32 
33 #include "gdt.h"
34 #include <stdio.h>
35 #include "interrupt.h"
36 #include <stdint.h>
37 #include <assert.h>
38 #include "syscalls.h"
39 #include "stacks.h"
40 
41 static dom_kern_data_t __attribute__((section(".kern_prot_dom_bss")))
42  ATTR_KERN_ADDR_SPACE PROT_DOMAINS_PDCS_NM(kern_dcd);
43 PROT_DOMAINS_ALLOC_IMPL(kern_dcd);
44 static dom_client_data_t ATTR_BSS_KERN kern_dcd;
45 static dom_kern_data_t __attribute__((section(".app_prot_dom_bss")))
46  ATTR_KERN_ADDR_SPACE PROT_DOMAINS_PDCS_NM(app_dcd);
47 PROT_DOMAINS_ALLOC_IMPL(app_dcd);
48 static dom_client_data_t ATTR_BSS_KERN app_dcd;
49 
50 /*---------------------------------------------------------------------------*/
51 void
52 prot_domains_init(void)
53 {
54  segment_desc_t desc;
55 
56  gdt_lookup(GDT_IDX_CODE_EXC, &desc);
57 #if X86_CONF_PROT_DOMAINS == X86_CONF_PROT_DOMAINS__SWSEG
58  /* The exception code segment needs to be readable so that the general
59  * protection fault handler can decode instructions, but the interrupt and
60  * user level code segments should not be.
61  */
62  SEG_SET_FLAG(desc, TYPE, SEG_TYPE_CODE_EX);
63 #endif
64 
65  SEG_SET_FLAG(desc, DPL, PRIV_LVL_INT);
66  gdt_insert(GDT_IDX_CODE_INT, desc);
67 
68  SEG_SET_FLAG(desc, DPL, PRIV_LVL_USER);
69  gdt_insert(GDT_IDX_CODE, desc);
70 
71  PROT_DOMAINS_INIT_ID(kern_dcd);
72  prot_domains_reg(&kern_dcd, 0, 0, 0, 0, true);
73  PROT_DOMAINS_INIT_ID(app_dcd);
74  prot_domains_reg(&app_dcd, 0, 0, 0, 0, false);
75 
76  prot_domains_impl_init();
77 }
78 /*---------------------------------------------------------------------------*/
#define __attribute__(nothing)
Define attribute to nothing since it isn't handled by IAR.
Definition: iar.h:194
Segment descriptor.
Definition: segmentation.h:89
Data associated with each protection domain that is owned by clients of that domain and used to ident...
Definition: prot-domains.h:247