Subversion Repositories HelenOS

Rev

Rev 188 | 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. #include <arch/pm.h>
  30. #include <arch/mm/page.h>
  31. #include <arch/types.h>
  32.  
  33.  
  34. /*
  35.  * There is no segmentation in long mode so we set up flat mode. In this
  36.  * mode, we use, for each privilege level, two segments spanning the
  37.  * whole memory. One is for code and one is for data.
  38.  */
  39.  
  40. struct descriptor gdt[GDT_ITEMS] = {
  41.     /* NULL descriptor */
  42.     { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  43.     /* KTEXT descriptor */
  44.     { .limit_0_15  = 0xffff,
  45.       .base_0_15   = 0,
  46.       .base_16_23  = 0,
  47.       .access      = AR_PRESENT | AR_CODE | DPL_KERNEL,
  48.       .limit_16_19 = 0xf,
  49.       .available   = 0,
  50.       .longmode    = 1,
  51.       .special     = 0,
  52.       .granularity = 1,
  53.       .base_24_31  = 0 },
  54.     /* KDATA descriptor */
  55.     { .limit_0_15  = 0xffff,
  56.       .base_0_15   = 0,
  57.       .base_16_23  = 0,
  58.       .access      = AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_KERNEL,
  59.       .limit_16_19 = 0xf,
  60.       .available   = 0,
  61.       .longmode    = 0,
  62.       .special     = 0,
  63.       .granularity = 0,
  64.       .base_24_31  = 0 },
  65.     /* UTEXT descriptor */
  66.     { .limit_0_15  = 0xffff,
  67.       .base_0_15   = 0,
  68.       .base_16_23  = 0,
  69.       .access      = AR_PRESENT | AR_CODE | DPL_USER,
  70.       .limit_16_19 = 0xf,
  71.       .available   = 0,
  72.       .longmode    = 1,
  73.       .special     = 0,
  74.       .granularity = 0,
  75.       .base_24_31  = 0 },
  76.     /* UDATA descriptor */
  77.     { .limit_0_15  = 0xffff,
  78.       .base_0_15   = 0,
  79.       .base_16_23  = 0,
  80.       .access      = AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_USER,
  81.       .limit_16_19 = 0xf,
  82.       .available   = 0,
  83.       .longmode    = 0,
  84.       .special     = 1,
  85.       .granularity = 1,
  86.       .base_24_31  = 0 },
  87.     /* TSS descriptor - set up will be completed later */
  88.     { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  89. };
  90.  
  91. struct idescriptor idt[IDT_ITEMS];
  92.  
  93. static struct tss tss;
  94.  
  95. /* gdtr is changed by kmp before next CPU is initialized */
  96. struct ptr_16_32 gdtr __attribute__ ((section ("K_DATA_START"))) = { .limit = sizeof(gdt) };
  97. //struct ptr_16_32 gdtr __attribute__ ((section ("K_DATA_START"))) = { .limit = sizeof(gdt), .base = KA2PA((__address) gdt) };
  98. struct ptr_16_32 idtr __attribute__ ((section ("K_DATA_START"))) = { .limit = sizeof(idt) };
  99.