Rev 1683 | Details | Compare with Previous | 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) |
||
574 | mauro | 111 | .globl SYMBOL_NAME(start) |
2 | pj | 112 | .globl start |
113 | |||
114 | SYMBOL_NAME_LABEL(_start) |
||
574 | mauro | 115 | SYMBOL_NAME_LABEL(start) |
2 | pj | 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 |
||
40 | pj | 156 | andl $0x0200,%ecx /* MB_INFO_BOOT_LOADER_NAME */ |
2 | pj | 157 | movl $0xB8000,%edi |
158 | addl $150,%edi |
||
159 | movb $'1',%gs:0(%edi) |
||
160 | incl %edi |
||
161 | movb $6,%gs:0(%edi) |
||
40 | pj | 162 | jz GDT_is_not_OK |
2 | pj | 163 | incl %edi |
164 | movb $'2',%gs:0(%edi) |
||
165 | incl %edi |
||
166 | movb $6,%gs:0(%edi) |
||
167 | |||
40 | pj | 168 | movl %gs:64(%ebx), %ebp /* Name Address... */ |
169 | cmpb $'X', %gs:0(%ebp) |
||
170 | je GDT_is_OK |
||
171 | GDT_is_not_OK: |
||
172 | /* |
||
173 | * Fix the X_RM_BACK_GATE with the address of halt() |
||
174 | */ |
||
175 | |||
176 | /* Now I test if the check mechanism is OK... */ |
||
2 | pj | 177 | movl $SYMBOL_NAME(halt),%eax |
178 | movw %ax,%gs:rmBckGateFix1 |
||
179 | shrl $16,%eax |
||
180 | movw %ax,%gs:rmBckGateFix2 |
||
181 | |||
182 | /* Load GDT, using the predefined assignment! */ |
||
183 | lgdt GDT_descr |
||
184 | movl $0xB8000,%edi |
||
185 | addl $146,%edi |
||
186 | movb $'0',%gs:0(%edi) |
||
187 | incl %edi |
||
188 | movb $6,%gs:0(%edi) |
||
189 | |||
190 | GDT_is_OK: movw $(X_FLATDATA_SEL),%ax |
||
191 | movw %ax,%ds |
||
192 | movw %ax,%es |
||
193 | movw %ax,%ss |
||
194 | movw %ax,%fs |
||
195 | movw %ax,%gs |
||
196 | movl $tos,%esp |
||
197 | movl $base,SYMBOL_NAME(_stkbase) |
||
198 | movl $tos,SYMBOL_NAME(_stktop) |
||
199 | |||
200 | /* Store the MULTIBOOT informations */ |
||
201 | movl %eax,SYMBOL_NAME(mb_signature) |
||
202 | movl %ebx,SYMBOL_NAME(mbi) |
||
203 | |||
204 | /* Store the X passed GDT address! |
||
205 | * If GDT is not available is a dummy instruction! |
||
206 | */ |
||
207 | sgdt GDT_descr |
||
208 | |||
209 | /* Now probably is the case to load CS... */ |
||
210 | ljmp $X_FLATCODE_SEL, $load_cs |
||
211 | |||
212 | load_cs: |
||
213 | /* Load IDT */ |
||
214 | lidt IDT_descr |
||
215 | |||
216 | cld |
||
217 | call SYMBOL_NAME(_startup) |
||
218 | |||
219 | /* Well I hope when I reach this |
||
220 | The X_RM_BACK_GATE has been setup correctly |
||
221 | even if the kernel has not been loaded through X! |
||
222 | */ |
||
223 | .byte 0x0EA /* Direct gate jmp */ |
||
224 | .long 0 |
||
225 | .word X_RM_BACK_GATE |
||
226 | |||
227 | /* Simple function to terminate PM application */ |
||
228 | |||
229 | /* void __exit(int code) */ |
||
230 | |||
231 | SYMBOL_NAME_LABEL(__exit) |
||
232 | pushl %ebp |
||
233 | movl %esp,%ebp |
||
234 | movl 8(%ebp),%eax |
||
235 | .byte 0x0ea /* Direct gate jmp */ |
||
236 | .long 0 |
||
237 | .word X_RM_BACK_GATE |