]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/bootstrap_custom/server/src/ARCH-x86/crt0.S
6fd45587694ea781e08e0783e40253fde62b9d87
[l4.git] / l4 / pkg / bootstrap_custom / server / src / ARCH-x86 / crt0.S
1 /*
2  * (c) 2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *          Frank Mehnert <fm3@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #include <l4/sys/compiler.h>
11 #define JH
12 #ifdef JH
13 #include "inmate.h" 
14 #define X86_CR0_PE              0x00000001
15
16 .code16
17     .section ".jh.boot", "ax"
18
19     .globl __reset_entry
20 __reset_entry:
21     ljmp $0xf000,$start16
22
23     .section ".jh.startup", "ax"
24
25 start16:
26     lgdtl %cs:gdt_ptr
27
28     mov %cr0,%eax
29     or $X86_CR0_PE,%al
30     mov %eax,%cr0
31
32     ljmpl $INMATE_CS32,$_start + FSEGMENT_BASE
33
34 .code32
35
36 loader_gdt:
37         .quad   0
38         .quad   0x00cf9b000000ffff
39         .quad   0x00af9b000000ffff
40         .quad   0x00cf93000000ffff
41
42 gdt_ptr:
43         .short  gdt_ptr - loader_gdt - 1
44         .long   loader_gdt + FSEGMENT_BASE
45
46         .align(4096)
47         .global loader_pdpt
48 loader_pdpt:
49         .long   0x00000083
50         .align(4096)
51 #endif 
52
53         
54         .section .init
55
56         .globl  _start
57 _start:
58 #ifdef REALMODE_LOADING
59         cld
60         cli
61         mov     $(3 * 8), %eax
62         mov     %eax, %ds
63         mov     %eax, %es
64         mov     %eax, %fs
65         mov     %eax, %gs
66         mov     %eax, %ss
67         lss     _stack_seg, %esp
68 #else
69         leal    _stack, %esp
70 #endif
71         pushl   $0
72         pushl   %esi    /* Pointer to real mode or Xen start_info pointer */
73         pushl   %eax
74         pushl   %ebx
75
76 #ifndef XEN
77         /* initialize vector for exception 6 */
78         movl    $trap6_entry,%eax
79         movw    %ax, _idt_offset_low
80         shrl    $16, %eax
81         movw    %ax, _idt_offset_high
82         movw    %cs, %ax
83         movw    %ax, _idt_selector
84
85         /* load tiny interrupt descriptor table to catch exception 6 */
86         lidtl   _idtdesc
87 #endif
88
89         pushl   $_exit
90         jmp     __main
91
92         /* Show an error message and wait for keypress to reboot. */
93 trap6_entry:
94         pusha
95         cld
96
97         jmp 8f
98
99         /* printhex
100          * edx: value to print
101          * eax: location on screen
102          */
103 99:     mov     %eax, %edi
104         add     $(2*8), %edi
105 98:     mov     $numbers,%ebx
106         mov     %edx,%ecx
107         shr     $28,%ecx
108         shl     $4,%edx
109         movzbl  (%ebx,%ecx,1),%ecx
110         mov     $0x4, %ch
111         mov     %cx,(%eax)
112         add     $0x2,%eax
113         cmp     %edi,%eax
114         jne     98b
115         ret
116
117 8:
118         /* print out warning */
119         movl    $trap6_warning, %esi
120         movl    $(0xb8000 + (24*80*2)), %edi
121         movb    $0x0F, %ah
122         
123 1:      /* read next character from string */
124         lodsb
125
126         /* check for end-of-string */
127         cmpb    $0, %al
128         je      3f
129
130         /* Check for hex number */
131         cmpb    $'      ', %al
132         jne     4f
133         pusha
134         mov     (32 + 32)(%esp),%edx
135         mov     %edi, %eax
136         call    99b
137         popa
138         add     $(8*2), %edi
139         jmp     1b
140         
141 4:      /* check for newline */
142         cmpb    $'\n', %al
143         jne     2f
144         
145         pushl   %eax
146         pushl   %esi
147         
148         /* move screen upwards 1 line */
149         movl    $((24*80*2)/4), %ecx
150         movl    $(0xb8000 + 1*80*2), %esi
151         movl    $0xb8000, %edi
152         rep     movsl
153
154         /* clear last line of screen */
155         movl    $((1*80*2)/4), %ecx
156         movl    $0x07200720, %eax
157         rep     stosl
158
159         popl    %esi
160         popl    %eax
161         
162         /* jump to new line */
163         movl    $(0xb8000 + (24*80*2)), %edi
164         jmp     1b
165         
166 2:      /* print character */
167         stosw
168         jmp     1b
169
170 3:      /* wait for keypress */
171         inb     $0x64, %al
172         testb   $0x01, %al
173         je      3b
174
175         movb    %al, %ah
176
177         /* empty keyboard buffer */
178         inb     $0x60, %al
179         
180         /* ignore PS/2 mouse events */
181         testb   $0x20, %ah
182         jne     3b
183
184         jmp     reboot
185
186
187         /* the warning text */
188 trap6_warning:
189         .ascii  "\n"
190         .ascii  "Bootstrap: Invalid opcode at    detected!\n"
191         .ascii  "Be sure that you don't use any CPU optimization flags like\n"
192         .ascii  "           -march=i686\n"
193         .ascii  "when compiling Bootstrap and the depending libraries.\n"
194         .ascii  "\n"
195         .asciz  "           Press any key to reboot..."
196
197 numbers:
198         .ascii  "0123456789abcdef"
199
200         /* MultiBoot header - see multiboot.h.  */
201         .p2align(2)
202
203 #define MULTIBOOT_MEMORY_INFO 0x00000002
204 _mb_header:
205         .long   0x1BADB002              /* magic */
206         .long   MULTIBOOT_MEMORY_INFO   /* flags: AOUT_KLUDGE */
207         .long   0 - 0x1BADB002 - MULTIBOOT_MEMORY_INFO
208
209 #ifndef XEN
210         .word   0
211 _idtdesc:
212         .word   (7*8)-1
213         .long   _idt
214
215 _idt:
216         .word   0,0,0,0                 /* trap 0 */
217         .word   0,0,0,0                 /* trap 1 */
218         .word   0,0,0,0                 /* trap 2 */
219         .word   0,0,0,0                 /* trap 3 */
220         .word   0,0,0,0                 /* trap 4 */
221         .word   0,0,0,0                 /* trap 5 */
222
223 _idt_offset_low:
224         .word   0
225 _idt_selector:
226         .word   0
227         .byte   0
228         .byte   0xee
229 _idt_offset_high:
230         .word   0
231 #endif
232
233 #ifdef REALMODE_LOADING
234 _stack_seg:
235         .long   _stack
236         .long   (3 * 8)
237 #endif
238
239         .bss
240         .space  8192
241         .globl  _stack
242 _stack: