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