Contiki 3.x
gdt.h
1 /*
2  * Copyright (C) 2015-2016, 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 GDT_H
32 #define GDT_H
33 
34 #include "gdt-layout.h"
35 #include "prot-domains.h"
36 #include "segmentation.h"
37 
38 extern segment_desc_t ATTR_KERN_ADDR_SPACE gdt[];
39 extern int ATTR_KERN_ADDR_SPACE _ebss_gdt_addr;
40 
41 #define GDT_IDX_OF_DESC(ptr) \
42  ((((uintptr_t)(ptr)) - ((uintptr_t)&gdt))/ \
43  sizeof(segment_desc_t))
44 
45 typedef struct far_pointer {
46  /** Far pointer offset. */
47  uint32_t offset;
48  /** Far pointer segment/gate selector. */
49  uint16_t sel;
50  uint16_t pad;
51 } __attribute__((packed)) far_pointer_t;
52 
53 /**
54  * \brief Compute the selector for a GDT entry allocated somewhere besides gdt.c.
55  * \param ptr Pointer to GDT descriptor.
56  * \param rpl Requested Privilege Level.
57  */
58 #define GDT_SEL_OF_DESC(ptr, rpl) GDT_SEL(GDT_IDX_OF_DESC(ptr), rpl)
59 
60 /* Section for fixed GDT entries */
61 #define ATTR_BSS_GDT \
62  __attribute__((section(".gdt_bss"))) ATTR_KERN_ADDR_SPACE
63 /* Section for TSS and LDT descriptors for protection domains */
64 #define ATTR_BSS_GDT_MID \
65  __attribute__((used, section(".gdt_bss_mid"))) ATTR_KERN_ADDR_SPACE
66 /* Section for other GDT entries */
67 #define ATTR_BSS_GDT_START \
68  __attribute__((section(".gdt_bss_start"))) ATTR_KERN_ADDR_SPACE
69 
70 void gdt_copy_desc_change_dpl(unsigned int dest_idx,
71  unsigned int src_idx,
72  unsigned dpl);
73 void gdt_init(void) ATTR_CODE_BOOT;
74 void gdt_insert(unsigned int idx, segment_desc_t desc);
75 void gdt_insert_boot(unsigned int idx, segment_desc_t desc) ATTR_CODE_BOOT;
76 void gdt_lookup(unsigned int idx, segment_desc_t *desc);
77 
78 #endif /* GDT_H */
#define __attribute__(nothing)
Define attribute to nothing since it isn't handled by IAR.
Definition: iar.h:194
Segment descriptor.
Definition: segmentation.h:89