Subversion Repositories shark

Rev

Rev 1618 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42 pj 1
/* Project:     OSLib
2
 * Description: The OS Construction Kit
3
 * Date:                1.6.2000
4
 * Idea by:             Luca Abeni & Gerardo Lamastra
5
 *
6
 * OSLib is an SO project aimed at developing a common, easy-to-use
7
 * low-level infrastructure for developing OS kernels and Embedded
8
 * Applications; it partially derives from the HARTIK project but it
9
 * currently is independently developed.
10
 *
11
 * OSLib is distributed under GPL License, and some of its code has
12
 * been derived from the Linux kernel source; also some important
13
 * ideas come from studying the DJGPP go32 extender.
14
 *
15
 * We acknowledge the Linux Community, Free Software Foundation,
16
 * D.J. Delorie and all the other developers who believe in the
17
 * freedom of software and ideas.
18
 *
19
 * For legalese, check out the included GPL license.
20
 */
21
 
22
/*      As the name says... All the hardware-dependent data structures... */
23
 
24
#ifndef __LL_I386_HW_DATA_H__
25
#define __LL_I386_HW_DATA_H__
26
 
27
#include <ll/i386/defs.h>
28
BEGIN_DEF
29
 
30
/* DO WE NEED A SEPARATE INCL FILE FOR THIS? */
31
#if defined(__GNU__)
32
#define __LL_ARCH__ "32/DJGPP C/COFF"
33
#elif defined(__LINUX__)
34
#define __LL_ARCH__ "32/LINUX CrossCompiled/ELF"
35
#else
36
#error Architecture Undefined!
37
#endif
38
 
39
#include <ll/i386/sel.h>
40
 
41
/* Useful basic types */
42
 
43
#ifndef __BASIC_DATA__
44
    #define __BASIC_DATA__
45
    typedef void *LIN_ADDR;
46
    typedef unsigned long long  QWORD;
47
    typedef unsigned long  DWORD;
48
    typedef unsigned short WORD;
49
    typedef unsigned char  BYTE;
50
    typedef unsigned long  TIME;
51
    typedef unsigned long  SYS_FLAGS;
52
    #define TRUE        1
53
    #define FALSE       0
54
    #define MAX_DWORD   0xFFFFFFFF
55
    #define MAX_WORD    0xFFFF
56
    #define MAX_BYTE    0xFF
57
    #define MAX_TIME    MAX_DWORD
58
#endif
59
 
60
typedef short CONTEXT;
61
 
62
/* Hardware based types (Self explanatory) */
63
 
64
typedef struct gate {
1681 fabio 65
    WORD offset_lo;
66
    WORD sel;
67
                BYTE dword_cnt;
68
                BYTE access;
69
    WORD offset_hi;
42 pj 70
} GATE;
71
 
72
typedef struct descriptor {
1681 fabio 73
    WORD lim_lo;
74
    WORD base_lo;
75
                BYTE base_med;
76
                BYTE access;
77
                BYTE gran;
78
                BYTE base_hi;
42 pj 79
} DESCRIPTOR;
80
 
81
/* A LDT/GDT entry could be a gate or a selector */
82
/* An IDT entry could be a gate only             */
83
 
84
union gdt_entry {
1681 fabio 85
    DESCRIPTOR d;
86
    GATE g;
42 pj 87
};
88
 
89
struct registers {
90
    DWORD dummy1;
91
    DWORD dummy2;
92
    DWORD egs;
93
    DWORD efs;
94
    DWORD ees;
95
    DWORD ess;
96
    DWORD eds;
97
    DWORD edi;
98
    DWORD esi;
99
    DWORD ebp;
100
    DWORD esp;
101
    DWORD ebx;
102
    DWORD edx;
103
    DWORD ecx;
104
    DWORD eax;
105
    DWORD eip;
106
    DWORD ecs;
107
    DWORD flags;
108
};
109
 
110
#define STACK_ACCESS    0x92    /* Basic Access bytes */
111
#define DATA_ACCESS     0x92
112
#define CODE_ACCESS     0x9A
113
 
114
/* At this level we just need to set up 2 gates to enter/exit PM */
115
/* The entry gate is a 386 32 bit call gate                      */
116
/* The exit (Back To Real Mode) gate is a 286 16 bit gate        */
117
 
118
#define CALL_GATE286    0x84    /* Call & Int Gate Access bytes */
119
#define CALL_GATE386    0x8C    
120
#define TASK_GATE       0x85
121
#define INT_GATE286     0x86
122
#define INT_GATE386     0x8E
123
#define TRAP_GATE286    0x87
124
#define TRAP_GATE386    0x8F
125
 
126
/* TSS selectors */
127
 
128
#define FREE_TSS386     0x89
129
#define BUSY_TSS386     0x8B
130
#define FREE_TSS286     0x81
131
#define BUSY_TSS286     0x83
132
 
133
#define GRAN_32B        0xC0    /* Granularity settings */
134
#define GRAN_32         0x40
135
#define GRAN_16         0x00
136
 
137
/* This is the TSS image for a 386 hardware task                        */
138
/* I added two other fields to the basic structure:                     */
139
/* 1) The CONTROL field which is used by system software to detect      */
140
/*    particular conditions; in this the first phase it is mainly used  */
141
/*    to mark the unused TSS & TSS which use math, altough thanks to    */
142
/*    the automatic FPU preemption supported in 386 this would be not   */
143
/*    necessary.                                                        */
144
/* 2) The ctx_FPU field used to store the FPU context if necessaary     */
145
 
146
#define TSS_USED                0x8000
147
#define FPU_USED                0x4000
148
 
149
#define FPU_CONTEXT_SIZE        108
150
 
151
/* CPU flags definitions */
152
#define CPU_FLAG_TF     0x00000100
153
#define CPU_FLAG_IF     0x00000200
154
#define CPU_FLAG_IOPL   0x00003000
155
#define CPU_FLAG_NT     0x00004000
156
#define CPU_FLAG_VM     0x00020000
157
#define CPU_FLAG_AC     0x00040000
158
#define CPU_FLAG_VIF    0x00080000
159
#define CPU_FLAG_VIP    0x00100000
160
#define CPU_FLAG_ID     0x00200000
161
 
162
 
163
typedef struct tss {
1681 fabio 164
    WORD back_link;
165
    WORD _fill0;
166
    DWORD esp0;
167
    WORD ss0;
168
    WORD _fill1;
169
    DWORD esp1;
170
    WORD ss1;
171
    WORD _fill2;
172
    DWORD esp2;
173
    WORD ss2;
174
    WORD _fill3;
175
    DWORD cr3;
176
    DWORD eip;
177
    DWORD eflags;
178
    DWORD eax;
179
    DWORD ecx;
180
    DWORD edx;
181
    DWORD ebx;
182
    DWORD esp;
183
    DWORD ebp;
184
    DWORD esi;
185
    DWORD edi;
186
    WORD es;
187
    WORD _fill5;
188
    WORD cs;
189
    WORD _fill6;
190
    WORD ss;
191
    WORD _fill7;
192
    WORD ds;
193
    WORD _fill8;
194
    WORD fs;
195
    WORD _fill9;
196
    WORD gs;
197
    WORD _fill10;
198
    WORD ldt;
199
    WORD _fill11;
200
    WORD trap;
201
    WORD io_base;
202
    DWORD control;
203
                BYTE ctx_FPU[FPU_CONTEXT_SIZE];
42 pj 204
} TSS;
205
 
206
/* Irq services specifications */
207
 
208
#define TIMER_IRQ       0
209
#define KEYB_IRQ        1
210
#define COM2_IRQ        3
211
#define COM1_IRQ        4
212
#define COM4_IRQ        3
213
#define COM3_IRQ        4
214
#define SB_IRQ          5
215
#define FDC_IRQ         6
216
#define SB2_IRQ         7
217
#define RTC_IRQ         8
218
#define PS2MOUSE_IRQ    12
219
#define COPROC_IRQ      13
220
#define IDE0_IRQ        14
221
#define IDE1_IRQ        15
222
 
223
typedef void (*INTERRUPT)(void);
224
 
225
/* Any Kernel primitive is declared with the SYSCALL() modifier         */
226
/* This is useful to add special purposes meaning to the function       */
227
/* defclaration                                                         */
228
 
229
#define SYSCALL(x)      x
230
 
231
END_DEF
232
 
233
#endif