Subversion Repositories HelenOS

Rev

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

Rev 1184 Rev 1187
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
#ifndef __PM_H__
29
#ifndef __PM_H__
30
#define __PM_H__
30
#define __PM_H__
31
 
31
 
32
#define IDT_ITEMS 64
32
#define IDT_ITEMS 64
33
#define GDT_ITEMS 7
33
#define GDT_ITEMS 7
34
 
34
 
35
#define NULL_DES    0
35
#define NULL_DES    0
36
#define KTEXT_DES   1
36
#define KTEXT_DES   1
37
#define KDATA_DES   2
37
#define KDATA_DES   2
38
#define UTEXT_DES   3
38
#define UTEXT_DES   3
39
#define UDATA_DES   4
39
#define UDATA_DES   4
40
#define TSS_DES     5
40
#define TSS_DES     5
41
#define TLS_DES         6 /* Pointer to Thread-Local-Storage data */
41
#define TLS_DES         6 /* Pointer to Thread-Local-Storage data */
42
 
42
 
43
#define selector(des)   ((des)<<3)
43
#define selector(des)   ((des)<<3)
44
 
44
 
45
#define PL_KERNEL   0
45
#define PL_KERNEL   0
46
#define PL_USER     3
46
#define PL_USER     3
47
 
47
 
48
#define AR_PRESENT  (1<<7)
48
#define AR_PRESENT  (1<<7)
49
#define AR_DATA     (2<<3)
49
#define AR_DATA     (2<<3)
50
#define AR_CODE     (3<<3)
50
#define AR_CODE     (3<<3)
51
#define AR_WRITABLE (1<<1)
51
#define AR_WRITABLE (1<<1)
52
#define AR_INTERRUPT    (0xe)
52
#define AR_INTERRUPT    (0xe)
53
#define AR_TSS      (0x9)
53
#define AR_TSS      (0x9)
54
 
54
 
55
#define DPL_KERNEL  (PL_KERNEL<<5)
55
#define DPL_KERNEL  (PL_KERNEL<<5)
56
#define DPL_USER    (PL_USER<<5)
56
#define DPL_USER    (PL_USER<<5)
57
 
57
 
58
#define IO_MAP_BASE (104)
58
#define TSS_BASIC_SIZE  104
59
 
59
 
60
#ifndef __ASM__
60
#ifndef __ASM__
61
 
61
 
62
#include <arch/types.h>
62
#include <arch/types.h>
63
#include <typedefs.h>
63
#include <typedefs.h>
64
#include <arch/context.h>
64
#include <arch/context.h>
65
 
65
 
66
struct ptr_16_32 {
66
struct ptr_16_32 {
67
    __u16 limit;
67
    __u16 limit;
68
    __u32 base;
68
    __u32 base;
69
} __attribute__ ((packed));
69
} __attribute__ ((packed));
-
 
70
typedef struct ptr_16_32 ptr_16_32_t;
70
 
71
 
71
struct descriptor {
72
struct descriptor {
72
    unsigned limit_0_15: 16;
73
    unsigned limit_0_15: 16;
73
    unsigned base_0_15: 16;
74
    unsigned base_0_15: 16;
74
    unsigned base_16_23: 8;
75
    unsigned base_16_23: 8;
75
    unsigned access: 8;
76
    unsigned access: 8;
76
    unsigned limit_16_19: 4;
77
    unsigned limit_16_19: 4;
77
    unsigned available: 1;
78
    unsigned available: 1;
78
    unsigned unused: 1;
79
    unsigned unused: 1;
79
    unsigned special: 1;
80
    unsigned special: 1;
80
    unsigned granularity : 1;
81
    unsigned granularity : 1;
81
    unsigned base_24_31: 8;
82
    unsigned base_24_31: 8;
82
} __attribute__ ((packed));
83
} __attribute__ ((packed));
-
 
84
typedef struct descriptor  descriptor_t;
83
 
85
 
84
struct idescriptor {
86
struct idescriptor {
85
    unsigned offset_0_15: 16;
87
    unsigned offset_0_15: 16;
86
    unsigned selector: 16;
88
    unsigned selector: 16;
87
    unsigned unused: 8;
89
    unsigned unused: 8;
88
    unsigned access: 8;
90
    unsigned access: 8;
89
    unsigned offset_16_31: 16;
91
    unsigned offset_16_31: 16;
90
} __attribute__ ((packed));
92
} __attribute__ ((packed));
91
 
-
 
-
 
93
typedef struct idescriptor idescriptor_t;
92
 
94
 
93
struct tss {
95
struct tss {
94
    __u16 link;
96
    __u16 link;
95
    unsigned : 16;
97
    unsigned : 16;
96
    __u32 esp0;
98
    __u32 esp0;
97
    __u16 ss0;
99
    __u16 ss0;
98
    unsigned : 16;
100
    unsigned : 16;
99
    __u32 esp1;
101
    __u32 esp1;
100
    __u16 ss1;
102
    __u16 ss1;
101
    unsigned : 16;
103
    unsigned : 16;
102
    __u32 esp2;
104
    __u32 esp2;
103
    __u16 ss2;
105
    __u16 ss2;
104
    unsigned : 16;
106
    unsigned : 16;
105
    __u32 cr3;
107
    __u32 cr3;
106
    __u32 eip;
108
    __u32 eip;
107
    __u32 eflags;
109
    __u32 eflags;
108
    __u32 eax;
110
    __u32 eax;
109
    __u32 ecx;
111
    __u32 ecx;
110
    __u32 edx;
112
    __u32 edx;
111
    __u32 ebx;
113
    __u32 ebx;
112
    __u32 esp;
114
    __u32 esp;
113
    __u32 ebp;
115
    __u32 ebp;
114
    __u32 esi;
116
    __u32 esi;
115
    __u32 edi;
117
    __u32 edi;
116
    __u16 es;
118
    __u16 es;
117
    unsigned : 16;
119
    unsigned : 16;
118
    __u16 cs;
120
    __u16 cs;
119
    unsigned : 16;
121
    unsigned : 16;
120
    __u16 ss;
122
    __u16 ss;
121
    unsigned : 16;
123
    unsigned : 16;
122
    __u16 ds;
124
    __u16 ds;
123
    unsigned : 16;
125
    unsigned : 16;
124
    __u16 fs;
126
    __u16 fs;
125
    unsigned : 16;
127
    unsigned : 16;
126
    __u16 gs;
128
    __u16 gs;
127
    unsigned : 16;
129
    unsigned : 16;
128
    __u16 ldtr;
130
    __u16 ldtr;
129
    unsigned : 16;
131
    unsigned : 16;
130
    unsigned : 16;
132
    unsigned : 16;
131
    __u16 iomap_base;
133
    __u16 iomap_base;
132
    __u8 iomap[0x10000+1];  /* 64K + 1 terminating byte */
134
    __u8 iomap[0x10000+1];  /* 64K + 1 terminating byte */
133
} __attribute__ ((packed));
135
} __attribute__ ((packed));
-
 
136
typedef struct tss tss_t;
134
 
137
 
135
extern struct ptr_16_32 gdtr;
138
extern ptr_16_32_t gdtr;
136
extern struct ptr_16_32 bootstrap_gdtr;
139
extern ptr_16_32_t bootstrap_gdtr;
137
extern struct ptr_16_32 protected_ap_gdtr;
140
extern ptr_16_32_t protected_ap_gdtr;
138
extern struct tss *tss_p;
141
extern struct tss *tss_p;
139
 
142
 
140
extern struct descriptor gdt[];
143
extern descriptor_t gdt[];
141
 
144
 
142
extern void pm_init(void);
145
extern void pm_init(void);
143
 
146
 
144
extern void gdt_setbase(struct descriptor *d, __address base);
147
extern void gdt_setbase(descriptor_t *d, __address base);
145
extern void gdt_setlimit(struct descriptor *d, __u32 limit);
148
extern void gdt_setlimit(descriptor_t *d, __u32 limit);
146
 
149
 
147
extern void idt_init(void);
150
extern void idt_init(void);
148
extern void idt_setoffset(struct idescriptor *d, __address offset);
151
extern void idt_setoffset(idescriptor_t *d, __address offset);
149
 
152
 
150
extern void tss_initialize(struct tss *t);
153
extern void tss_initialize(tss_t *t);
151
extern void set_tls_desc(__address tls);
154
extern void set_tls_desc(__address tls);
152
 
155
 
153
#endif /* __ASM__ */
156
#endif /* __ASM__ */
154
 
157
 
155
#endif
158
#endif
156
 
159