Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 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  DWORD;
47
    typedef unsigned short WORD;
48
    typedef unsigned char  BYTE;
49
    typedef unsigned long  TIME;
50
    typedef unsigned long  SYS_FLAGS;
51
    #define TRUE        1
52
    #define FALSE       0
53
    #define MAX_DWORD   0xFFFFFFFF
54
    #define MAX_WORD    0xFFFF
55
    #define MAX_BYTE    0xFF
56
    #define MAX_TIME    MAX_DWORD
57
#endif
58
 
59
typedef short CONTEXT;
60
 
61
/* Hardware based types (Self explanatory) */
62
 
63
typedef struct gate {
64
    WORD offset_lo __attribute__ ((packed));
65
    WORD sel __attribute__ ((packed));
66
    BYTE dword_cnt __attribute__ ((packed));
67
    BYTE access __attribute__ ((packed));
68
    WORD offset_hi __attribute__ ((packed));
69
} GATE;
70
 
71
typedef struct descriptor {
72
    WORD lim_lo __attribute__ ((packed));
73
    WORD base_lo __attribute__ ((packed));
74
    BYTE base_med __attribute__ ((packed));
75
    BYTE access __attribute__ ((packed));
76
    BYTE gran __attribute__ ((packed));
77
    BYTE base_hi __attribute__ ((packed));
78
} DESCRIPTOR;
79
 
80
/* A LDT/GDT entry could be a gate or a selector */
81
/* An IDT entry could be a gate only             */
82
 
83
union gdt_entry {
84
    DESCRIPTOR d __attribute__ ((packed));
85
    GATE g __attribute__ ((packed));
86
};
87
 
88
#define STACK_ACCESS    0x92    /* Basic Access bytes */
89
#define DATA_ACCESS     0x92
90
#define CODE_ACCESS     0x9A
91
 
92
/* At this level we just need to set up 2 gates to enter/exit PM */
93
/* The entry gate is a 386 32 bit call gate                      */
94
/* The exit (Back To Real Mode) gate is a 286 16 bit gate        */
95
 
96
#define CALL_GATE286    0x84    /* Call & Int Gate Access bytes */
97
#define CALL_GATE386    0x8C    
98
#define TASK_GATE       0x85
99
#define INT_GATE286     0x86
100
#define INT_GATE386     0x8E
101
#define TRAP_GATE286    0x87
102
#define TRAP_GATE386    0x8F
103
 
104
/* TSS selectors */
105
 
106
#define FREE_TSS386     0x89
107
#define BUSY_TSS386     0x8B
108
#define FREE_TSS286     0x81
109
#define BUSY_TSS286     0x83
110
 
111
#define GRAN_32B        0xC0    /* Granularity settings */
112
#define GRAN_32         0x40
113
#define GRAN_16         0x00
114
 
115
/* This is the TSS image for a 386 hardware task                        */
116
/* I added two other fields to the basic structure:                     */
117
/* 1) The CONTROL field which is used by system software to detect      */
118
/*    particular conditions; in this the first phase it is mainly used  */
119
/*    to mark the unused TSS & TSS which use math, altough thanks to    */
120
/*    the automatic FPU preemption supported in 386 this would be not   */
121
/*    necessary.                                                        */
122
/* 2) The ctx_FPU field used to store the FPU context if necessaary     */
123
 
124
#define TSS_USED                0x8000
125
#define FPU_USED                0x4000
126
 
127
#define FPU_CONTEXT_SIZE        108
128
 
129
/* CPU flags definitions */
130
#define CPU_FLAG_TF     0x00000100
131
#define CPU_FLAG_IF     0x00000200
132
#define CPU_FLAG_IOPL   0x00003000
133
#define CPU_FLAG_NT     0x00004000
134
#define CPU_FLAG_VM     0x00020000
135
#define CPU_FLAG_AC     0x00040000
136
#define CPU_FLAG_VIF    0x00080000
137
#define CPU_FLAG_VIP    0x00100000
138
#define CPU_FLAG_ID     0x00200000
139
 
140
 
141
typedef struct tss {
142
    WORD back_link __attribute__ ((packed));
143
    WORD _fill0 __attribute__ ((packed));
144
    DWORD esp0 __attribute__ ((packed));
145
    WORD ss0 __attribute__ ((packed));
146
    WORD _fill1 __attribute__ ((packed));
147
    DWORD esp1 __attribute__ ((packed));
148
    WORD ss1 __attribute__ ((packed));
149
    WORD _fill2 __attribute__ ((packed));
150
    DWORD esp2 __attribute__ ((packed));
151
    WORD ss2 __attribute__ ((packed));
152
    WORD _fill3 __attribute__ ((packed));
153
    DWORD cr3 __attribute__ ((packed));
154
    DWORD eip __attribute__ ((packed));
155
    DWORD eflags __attribute__ ((packed));
156
    DWORD eax __attribute__ ((packed));
157
    DWORD ecx __attribute__ ((packed));
158
    DWORD edx __attribute__ ((packed));
159
    DWORD ebx __attribute__ ((packed));
160
    DWORD esp __attribute__ ((packed));
161
    DWORD ebp __attribute__ ((packed));
162
    DWORD esi __attribute__ ((packed));
163
    DWORD edi __attribute__ ((packed));
164
    WORD es __attribute__ ((packed));
165
    WORD _fill5 __attribute__ ((packed));
166
    WORD cs __attribute__ ((packed));
167
    WORD _fill6 __attribute__ ((packed));
168
    WORD ss __attribute__ ((packed));
169
    WORD _fill7 __attribute__ ((packed));
170
    WORD ds __attribute__ ((packed));
171
    WORD _fill8 __attribute__ ((packed));
172
    WORD fs __attribute__ ((packed));
173
    WORD _fill9 __attribute__ ((packed));
174
    WORD gs __attribute__ ((packed));
175
    WORD _fill10 __attribute__ ((packed));
176
    WORD ldt __attribute__ ((packed));
177
    WORD _fill11 __attribute__ ((packed));
178
    WORD trap __attribute__ ((packed));
179
    WORD io_base __attribute__ ((packed));
180
    DWORD control __attribute__ ((packed));
181
    BYTE ctx_FPU[FPU_CONTEXT_SIZE] __attribute__ ((packed));
182
} TSS;
183
 
184
/* Irq services specifications */
185
 
186
#define TIMER_IRQ       0
187
#define KEYB_IRQ        1
188
#define COM2_IRQ        3
189
#define COM1_IRQ        4
190
#define COM4_IRQ        3
191
#define COM3_IRQ        4
192
#define SB_IRQ          5
193
#define FDC_IRQ         6
194
#define SB2_IRQ         7
195
#define RTC_IRQ         8
196
#define PS2MOUSE_IRQ    12
197
#define COPROC_IRQ      13
198
#define IDE0_IRQ        14
199
#define IDE1_IRQ        15
200
 
201
typedef void (*INTERRUPT)(void);
202
 
203
/* Any Kernel primitive is declared with the SYSCALL() modifier         */
204
/* This is useful to add special purposes meaning to the function       */
205
/* defclaration                                                         */
206
 
207
#define SYSCALL(x)      x
208
 
209
END_DEF
210
 
211
#endif