Subversion Repositories shark

Rev

Rev 3 | Go to most recent revision | 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
/* The first things to do when an OSLib application starts :	*/
23
/* Set up segment registers & stack; then execute startup code	*/
24
/* When the application returns the gate-jmp make us return to	*/
25
/* RM through X interface!					*/
26
 
27
/* Use X standard GDT selectors */
28
#include <ll/i386/sel.h>
29
#include <ll/i386/linkage.h>
30
#include <ll/i386/defs.h>
31
#include <ll/i386/mb-hdr.h>
32
 
33
/* #define __DEBUG__ */
34
 
35
#ifdef __LINUX__ /* ELF mode */
36
#define MULTIBOOT_FLAGS (MULTIBOOT_MEMORY_INFO)
37
#else /* else it is COFF! */
38
#define MULTIBOOT_FLAGS (MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE)
39
#endif
40
 
41
.extern SYMBOL_NAME(_startup)
42
.extern SYMBOL_NAME(_stkbase)
43
.extern SYMBOL_NAME(_stktop)
44
 
45
.extern SYMBOL_NAME(halt)
46
 
47
.data
48
 
49
ASMFILE(X0)
50
 
51
.globl SYMBOL_NAME(IDT)
52
.globl SYMBOL_NAME(GDT_base)
53
.globl SYMBOL_NAME(mb_signature)
54
.globl SYMBOL_NAME(mbi)
55
 
56
/* GDT Definition */
57
GDT:
58
.word	0,0,0,0		/* X_NULL_SEL */
59
.word	0,0,0,0		/* X_DATA16_SEL */
60
.word	0,0,0,0		/* X_CODE16_SEL */
61
.word	0,0,0,0		/* X_CODE32_SEL */
62
			/* X_RM_BACK_GATE */
63
rmBckGateFix1:		/* X_FLATCODE_SEL */
64
.word	0
65
.word	X_FLATCODE_SEL
66
.word	0x8C00
67
rmBckGateFix2:
68
.word	0
69
 
70
.word	0,0,0,0		/* X_PM_BACK_GATE */
71
.word	0xFFFF		/* X_FLATDATA_SEL */
72
.word	0
73
.word	0x9200
74
.word	0x00CF
75
.word	0xFFFF		/* X_FLATCODE_SEL */
76
.word	0
77
.word	0x9A00
78
.word	0x00CF
79
.word	0,0,0,0		/* X_CALLBIOS_SEL */
80
.word	0,0,0,0		/* X_CALLBIOS_GATE */
81
.word	0,0,0,0		/* X_VM86_TSS */
82
.word	0,0,0,0		/* X_MAIN_TSS */
83
	.fill 256 - 12,8,0
84
 
85
GDT_descr:
86
.word 256*8-1
87
SYMBOL_NAME_LABEL(GDT_base)
88
.long GDT
89
 
90
IDT_descr:
91
	.word 256*8-1		# idt contains 256 entries
92
	.long SYMBOL_NAME(IDT)
93
 
94
/* MultiBoot Data Stuff definition */
95
SYMBOL_NAME_LABEL(mb_signature) .long 0
96
SYMBOL_NAME_LABEL(mbi) .long 0
97
 
98
.bss		/* This MUST be in the BSS !!! */
99
/* IDT definition */
100
SYMBOL_NAME_LABEL(IDT)
101
	.fill 256,8,0		# idt is uninitialized
102
 
103
/* Protected mode stack */
104
base:
105
.space 	8192,0
106
tos:
107
 
108
.text
109
.globl	SYMBOL_NAME(_start)
110
.globl SYMBOL_NAME(__exit)
111
/*.globl	SYMBOL_NAME(start)*/
112
.globl start
113
 
114
SYMBOL_NAME_LABEL(_start)
115
/*SYMBOL_NAME_LABEL(start)*/
116
start:
117
.align		8
118
/*start:*/
119
		jmp	boot_entry
120
		/*
121
		Here we go with the multiboot header...
122
		---------------------------------------
123
		*/
124
.align		8
125
boot_hdr:
126
.align		8
127
		.long	MULTIBOOT_MAGIC
128
		.long   MULTIBOOT_FLAGS
129
		/* Checksum */
130
		.long	-(MULTIBOOT_MAGIC+MULTIBOOT_FLAGS)
131
#ifndef __LINUX__ /* COFF mode */
132
		.long	boot_hdr
133
/*		.long	SYMBOL_NAME(start)*/
134
		.long   start
135
		.long	_edata
136
		.long	_end
137
		.long	boot_entry
138
#endif
139
 
140
boot_entry:	/* Just a brief debug check */
141
		#ifdef __DEBUG__
142
		/* A Brown 1 should appear... */
143
		    movl	$0xB8000,%edi
144
		    addl	$158,%edi
145
		    movb	$'1',%gs:0(%edi)
146
		    incl	%edi
147
		    movb	$6,%gs:0(%edi)
148
		#endif
149
 
150
		/*
151
		 * Hopefully if it gets here, CS & DS are
152
		 * Correctly set for FLAT LINEAR mode
153
		 */
154
		/* Test if GDT is usable */
155
		movl	%gs:0(%ebx),%ecx
156
		andl	$0x080,%ecx
157
		jnz	GDT_is_OK
158
		/*
159
		 * Fix the X_RM_BACK_GATE with the address of halt()
160
		*/
161
 
162
/* Now I test if the check mechanism is OK... */
163
movl	$0xB8000,%edi
164
addl	$150,%edi
165
movb	$'1',%gs:0(%edi)
166
incl	%edi
167
movb	$6,%gs:0(%edi)
168
incl	%edi
169
movb	$'2',%gs:0(%edi)
170
incl	%edi
171
movb	$6,%gs:0(%edi)
172
 
173
		movl	$SYMBOL_NAME(halt),%eax
174
		movw	%ax,%gs:rmBckGateFix1
175
		shrl	$16,%eax
176
		movw	%ax,%gs:rmBckGateFix2
177
 
178
		/* Load GDT, using the predefined assignment! */
179
		lgdt	GDT_descr
180
movl	$0xB8000,%edi
181
addl	$146,%edi
182
movb	$'0',%gs:0(%edi)
183
incl	%edi
184
movb	$6,%gs:0(%edi)
185
 
186
GDT_is_OK:	movw	$(X_FLATDATA_SEL),%ax
187
		movw	%ax,%ds
188
		movw	%ax,%es
189
		movw	%ax,%ss
190
		movw	%ax,%fs
191
		movw	%ax,%gs
192
		movl	$tos,%esp
193
		movl	$base,SYMBOL_NAME(_stkbase)
194
		movl	$tos,SYMBOL_NAME(_stktop)
195
 
196
		/* Store the MULTIBOOT informations */
197
		movl	%eax,SYMBOL_NAME(mb_signature)
198
		movl	%ebx,SYMBOL_NAME(mbi)
199
 
200
		/* Store the X passed GDT address!
201
		 * If GDT is not available is a dummy instruction!
202
		 */
203
		sgdt 	GDT_descr
204
 
205
		/* Now probably is the case to load CS... */
206
		ljmp $X_FLATCODE_SEL, $load_cs
207
 
208
load_cs:
209
		/* Load IDT */
210
		lidt	IDT_descr
211
 
212
		cld
213
		call SYMBOL_NAME(_startup)
214
 
215
		/* Well I hope when I reach this
216
		   The X_RM_BACK_GATE has been setup correctly
217
		   even if the kernel has not been loaded through X!
218
		*/
219
		.byte	0x0EA		   /* Direct gate jmp */
220
		.long	0
221
		.word	X_RM_BACK_GATE
222
 
223
/* Simple function to terminate PM application	*/
224
 
225
/* void __exit(int code)				*/
226
 
227
SYMBOL_NAME_LABEL(__exit)
228
		pushl	%ebp
229
		movl	%esp,%ebp
230
		movl	8(%ebp),%eax
231
		.byte	0x0ea		   /* Direct gate jmp */
232
		.long	0
233
		.word	X_RM_BACK_GATE