Subversion Repositories HelenOS

Rev

Rev 178 | Rev 206 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 178 Rev 188
1
/*
1
/*
2
 * Copyright (C) 2001-2004 Jakub Jermar
2
 * Copyright (C) 2001-2004 Jakub Jermar
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
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
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.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
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
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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
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.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
#include <arch/pm.h>
29
#include <arch/pm.h>
30
#include <arch/mm/page.h>
30
#include <arch/mm/page.h>
31
#include <arch/types.h>
31
#include <arch/types.h>
32
 
32
 
33
 
33
 
34
/*
34
/*
35
 * There is no segmentation in long mode so we set up flat mode. In this
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
36
 * mode, we use, for each privilege level, two segments spanning the
37
 * whole memory. One is for code and one is for data.
37
 * whole memory. One is for code and one is for data.
38
 */
38
 */
39
 
39
 
40
struct descriptor gdt[GDT_ITEMS] = {
40
struct descriptor gdt[GDT_ITEMS] = {
41
    /* NULL descriptor */
41
    /* NULL descriptor */
42
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
42
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
43
    /* KTEXT descriptor */
43
    /* KTEXT descriptor */
44
    { .limit_0_15  = 0xffff,
44
    { .limit_0_15  = 0xffff,
45
      .base_0_15   = 0,
45
      .base_0_15   = 0,
46
      .base_16_23  = 0,
46
      .base_16_23  = 0,
47
      .access      = AR_PRESENT | AR_CODE | DPL_KERNEL,
47
      .access      = AR_PRESENT | AR_CODE | DPL_KERNEL | AR_READABLE ,
48
      .limit_16_19 = 0xf,
48
      .limit_16_19 = 0xf,
49
      .available   = 0,
49
      .available   = 0,
50
      .longmode    = 1,
50
      .longmode    = 1,
51
      .special     = 0,
51
      .special     = 0,
52
      .granularity = 1,
52
      .granularity = 1,
53
      .base_24_31  = 0 },
53
      .base_24_31  = 0 },
54
    /* KDATA descriptor */
54
    /* KDATA descriptor */
55
    { .limit_0_15  = 0xffff,
55
    { .limit_0_15  = 0xffff,
56
      .base_0_15   = 0,
56
      .base_0_15   = 0,
57
      .base_16_23  = 0,
57
      .base_16_23  = 0,
58
      .access      = AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_KERNEL,
58
      .access      = AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_KERNEL,
59
      .limit_16_19 = 0xf,
59
      .limit_16_19 = 0xf,
60
      .available   = 0,
60
      .available   = 0,
61
      .longmode    = 0,
61
      .longmode    = 0,
62
      .special     = 0,
62
      .special     = 0,
63
      .granularity = 0,
63
      .granularity = 1,
64
      .base_24_31  = 0 },
64
      .base_24_31  = 0 },
65
    /* UTEXT descriptor */
65
    /* UTEXT descriptor */
66
    { .limit_0_15  = 0xffff,
66
    { .limit_0_15  = 0xffff,
67
      .base_0_15   = 0,
67
      .base_0_15   = 0,
68
      .base_16_23  = 0,
68
      .base_16_23  = 0,
69
      .access      = AR_PRESENT | AR_CODE | DPL_USER,
69
      .access      = AR_PRESENT | AR_CODE | DPL_USER,
70
      .limit_16_19 = 0xf,
70
      .limit_16_19 = 0xf,
71
      .available   = 0,
71
      .available   = 0,
72
      .longmode    = 1,
72
      .longmode    = 1,
73
      .special     = 0,
73
      .special     = 0,
74
      .granularity = 0,
74
      .granularity = 0,
75
      .base_24_31  = 0 },
75
      .base_24_31  = 0 },
76
    /* UDATA descriptor */
76
    /* UDATA descriptor */
77
    { .limit_0_15  = 0xffff,
77
    { .limit_0_15  = 0xffff,
78
      .base_0_15   = 0,
78
      .base_0_15   = 0,
79
      .base_16_23  = 0,
79
      .base_16_23  = 0,
80
      .access      = AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_USER,
80
      .access      = AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_USER,
81
      .limit_16_19 = 0xf,
81
      .limit_16_19 = 0xf,
82
      .available   = 0,
82
      .available   = 0,
83
      .longmode    = 0,
83
      .longmode    = 0,
84
      .special     = 1,
84
      .special     = 1,
85
      .granularity = 1,
85
      .granularity = 1,
86
      .base_24_31  = 0 },
86
      .base_24_31  = 0 },
-
 
87
    /* KTEXT 16-bit protected */
-
 
88
    { .limit_0_15  = 0xffff,
-
 
89
      .base_0_15   = 0,
-
 
90
      .base_16_23  = 0,
-
 
91
      .access      = AR_PRESENT | AR_CODE | DPL_KERNEL | AR_READABLE,
-
 
92
      .limit_16_19 = 0xf,
-
 
93
      .available   = 0,
-
 
94
      .longmode    = 0,
-
 
95
      .special     = 0,
-
 
96
      .granularity = 1,
-
 
97
      .base_24_31  = 0 },
87
    /* TSS descriptor - set up will be completed later */
98
    /* TSS descriptor - set up will be completed later */
88
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
99
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
89
};
100
};
90
 
101
 
91
struct idescriptor idt[IDT_ITEMS];
102
struct idescriptor idt[IDT_ITEMS];
92
 
103
 
93
static struct tss tss;
104
static struct tss tss;
94
 
105
 
95
/* gdtr is changed by kmp before next CPU is initialized */
106
/* Does not compile correctly if it does not exist */
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) };
107
int __attribute__ ((section ("K_DATA_START"))) __fake;
99
 
108