Subversion Repositories HelenOS

Rev

Rev 2071 | Rev 3386 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2001-2004 Jakub Jermar
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup amd64  
  30.  * @{
  31.  */
  32. /** @file
  33.  */
  34.  
  35. #ifndef KERN_amd64_PM_H_
  36. #define KERN_amd64_PM_H_
  37.  
  38. #ifndef __ASM__
  39. #   include <arch/types.h>
  40. #   include <arch/context.h>
  41. #endif
  42.  
  43. #define IDT_ITEMS 64
  44. #define GDT_ITEMS 8
  45.  
  46.  
  47. #define NULL_DES    0
  48. /* Warning: Do not reorder next items, unless you look into syscall.c!!! */
  49. #define KTEXT_DES   1
  50. #define KDATA_DES   2
  51. #define UDATA_DES   3
  52. #define UTEXT_DES   4
  53. #define KTEXT32_DES     5
  54. /* EndOfWarning */
  55. #define TSS_DES     6
  56.  
  57.  
  58.  
  59. #ifdef CONFIG_FB
  60.  
  61. #define VESA_INIT_DES       8
  62. #define VESA_INIT_SEGMENT 0x8000
  63. #undef GDT_ITEMS
  64. #define GDT_ITEMS 9
  65.  
  66. #endif /*CONFIG_FB*/
  67.  
  68.  
  69.  
  70. #define gdtselector(des)    ((des) << 3)
  71. #define idtselector(des)    ((des) << 4)
  72.  
  73. #define PL_KERNEL   0
  74. #define PL_USER     3
  75.  
  76. #define AR_PRESENT  (1<<7)
  77. #define AR_DATA     (2<<3)
  78. #define AR_CODE     (3<<3)
  79. #define AR_WRITABLE (1<<1)
  80. #define AR_READABLE     (1<<1)
  81. #define AR_TSS      (0x9)
  82. #define AR_INTERRUPT    (0xe)
  83. #define AR_TRAP         (0xf)
  84.  
  85. #define DPL_KERNEL  (PL_KERNEL<<5)
  86. #define DPL_USER    (PL_USER<<5)
  87.  
  88. #define TSS_BASIC_SIZE  104
  89. #define TSS_IOMAP_SIZE  (16*1024+1) /* 16K for bitmap + 1 terminating byte for convenience */
  90.  
  91. #define IO_PORTS    (64*1024)
  92.  
  93. #ifndef __ASM__
  94.  
  95. struct descriptor {
  96.     unsigned limit_0_15: 16;
  97.     unsigned base_0_15: 16;
  98.     unsigned base_16_23: 8;
  99.     unsigned access: 8;
  100.     unsigned limit_16_19: 4;
  101.     unsigned available: 1;
  102.     unsigned longmode: 1;
  103.     unsigned special: 1;
  104.     unsigned granularity : 1;
  105.     unsigned base_24_31: 8;
  106. } __attribute__ ((packed));
  107. typedef struct descriptor descriptor_t;
  108.  
  109. struct tss_descriptor {
  110.     unsigned limit_0_15: 16;
  111.     unsigned base_0_15: 16;
  112.     unsigned base_16_23: 8;
  113.     unsigned type: 4;
  114.     unsigned : 1;
  115.     unsigned dpl : 2;
  116.     unsigned present : 1;
  117.     unsigned limit_16_19: 4;
  118.     unsigned available: 1;
  119.     unsigned : 2;
  120.     unsigned granularity : 1;
  121.     unsigned base_24_31: 8;
  122.     unsigned base_32_63 : 32;
  123.     unsigned  : 32;
  124. } __attribute__ ((packed));
  125. typedef struct tss_descriptor tss_descriptor_t;
  126.  
  127. struct idescriptor {
  128.     unsigned offset_0_15: 16;
  129.     unsigned selector: 16;
  130.     unsigned ist:3;
  131.     unsigned unused: 5;
  132.     unsigned type: 5;
  133.     unsigned dpl: 2;
  134.     unsigned present : 1;
  135.     unsigned offset_16_31: 16;
  136.     unsigned offset_32_63: 32;
  137.     unsigned  : 32;
  138. } __attribute__ ((packed));
  139. typedef struct idescriptor idescriptor_t;
  140.  
  141. struct ptr_16_64 {
  142.     uint16_t limit;
  143.     uint64_t base;
  144. } __attribute__ ((packed));
  145. typedef struct ptr_16_64 ptr_16_64_t;
  146.  
  147. struct ptr_16_32 {
  148.     uint16_t limit;
  149.     uint32_t base;
  150. } __attribute__ ((packed));
  151. typedef struct ptr_16_32 ptr_16_32_t;
  152.  
  153. struct tss {
  154.     uint32_t reserve1;
  155.     uint64_t rsp0;
  156.     uint64_t rsp1;
  157.     uint64_t rsp2;
  158.     uint64_t reserve2;
  159.     uint64_t ist1;
  160.     uint64_t ist2;
  161.     uint64_t ist3;
  162.     uint64_t ist4;
  163.     uint64_t ist5;
  164.     uint64_t ist6;
  165.     uint64_t ist7;
  166.     uint64_t reserve3;
  167.     uint16_t reserve4;
  168.     uint16_t iomap_base;
  169.     uint8_t iomap[TSS_IOMAP_SIZE];
  170. } __attribute__ ((packed));
  171. typedef struct tss tss_t;
  172.  
  173. extern tss_t *tss_p;
  174.  
  175. extern descriptor_t gdt[];
  176. extern idescriptor_t idt[];
  177.  
  178. extern ptr_16_64_t gdtr;
  179. extern ptr_16_32_t bootstrap_gdtr;
  180. extern ptr_16_32_t protected_ap_gdtr;
  181.  
  182. extern void pm_init(void);
  183.  
  184. extern void gdt_tss_setbase(descriptor_t *d, uintptr_t base);
  185. extern void gdt_tss_setlimit(descriptor_t *d, uint32_t limit);
  186.  
  187. extern void idt_init(void);
  188. extern void idt_setoffset(idescriptor_t *d, uintptr_t offset);
  189.  
  190. extern void tss_initialize(tss_t *t);
  191.  
  192. #endif /* __ASM__ */
  193.  
  194. #endif
  195.  
  196. /** @}
  197.  */
  198.