Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Ported palacios to Kbuild
[palacios.git] / bios / vmxassist / head.S
1 /*
2  * head.S: VMXAssist runtime start off.
3  *
4  * Leendert van Doorn, leendert@watson.ibm.com
5  * Copyright (c) 2005, International Business Machines Corporation.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms and conditions of the GNU General Public License,
9  * version 2, as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18  * Place - Suite 330, Boston, MA 02111-1307 USA.
19  */
20 #include "vm86.h"
21 #include "machine.h"
22
23 /*
24  * When a partition tries to mask off the CR0_PE bit a world
25  * switch happens to the environment below. The magic indicates
26  * that this is a valid context.
27  */
28 #ifdef TEST
29         .byte 0x55, 0xaa
30         .byte 0x80
31         .code16
32         jmp     _start16
33 #else
34         jmp     _start
35 #endif
36
37         .align  8
38         .long   VMXASSIST_MAGIC
39         .long   newctx                  /* new context */
40         .long   oldctx                  /* old context */
41
42 #ifdef TEST
43 /*
44  * We are running in 16-bit. Get into the protected mode as soon as
45  * possible. We use our own (minimal) GDT to get started.
46  *
47  * ROM is a misnomer as this code isn't really rommable (although it
48  * only requires a few changes) but it does live in a BIOS ROM segment.
49  * This code allows me to debug vmxassists under (a modified version of)
50  * Bochs and load it as a "optromimage1".
51  */
52         .code16
53         .globl  _start16
54 _start16:
55         cli
56
57         /* load our own global descriptor table */
58         data32 addr32 lgdt %cs:(rom_gdtr - TEXTADDR)
59
60         /* go to protected mode */
61         movl    %cr0, %eax
62         orl     $CR0_PE, %eax
63         movl    %eax, %cr0
64         data32  ljmp $0x08, $1f
65
66         .align  32
67         .globl  rom_gdt
68 rom_gdt:
69         .word   0, 0            /* 0x00: reserved */
70         .byte   0, 0, 0, 0
71
72         .word   0xFFFF, 0       /* 0x08: CS 32-bit */
73         .byte   0, 0x9A, 0xCF, 0
74
75         .word   0xFFFF, 0       /* 0x10: CS 32-bit */
76         .byte   0, 0x92, 0xCF, 0
77 rom_gdt_end:
78
79         .align  4
80         .globl  rom_gdtr
81 rom_gdtr:
82         .word   rom_gdt_end - rom_gdt - 1
83         .long   rom_gdt
84
85         .code32
86 1:
87         /* welcome to the 32-bit world */
88         movw    $0x10, %ax
89         movw    %ax, %ds
90         movw    %ax, %es
91         movw    %ax, %ss
92         movw    %ax, %fs
93         movw    %ax, %gs
94
95         /* enable Bochs debug facilities */
96         movw    $0x8A00, %dx
97         movw    $0x8A00, %ax
98         outw    %ax, (%dx)
99
100         jmp     _start
101 #endif /* TEST */
102
103 /*
104  * This is the real start. Control was transfered to this point
105  * with CR0_PE set and executing in some 32-bit segment. We call
106  * main and setup our own environment.
107  */
108         .globl  _start
109         .code32
110 _start:
111         cli
112
113         /* save register parameters to C land */
114 #ifdef TEST
115         xorl    %edx, %edx
116 #endif
117
118         /* clear bss */
119         cld
120         xorb    %al, %al
121         movl    $_bbss, %edi
122         movl    $_ebss, %ecx
123         subl    %edi, %ecx
124         rep     stosb
125
126         movl    %edx, booting_cpu
127         movl    %ebx, booting_vector
128
129         /* make sure we are in a sane world */
130         clts
131
132         /* setup my own stack */
133         movl    $stack_top - 4*4, %esp
134         movl    %esp, %ebp
135
136         /* go ... */
137         call    main
138         jmp     halt
139
140 /*
141  * Something bad happened, print invoking %eip and loop forever
142  */
143         .align  4
144         .globl  halt
145 halt:
146         push    $halt_msg
147         call    printf
148 #ifdef TEST
149         movw    $0x8A00, %dx
150         movw    $0x8AE0, %ax
151         outw    %ax, (%dx)
152 #endif
153         cli
154         jmp     .
155
156         .data
157 halt_msg:
158         .asciz  "Halt called from %%eip 0x%x\n"
159
160
161 /*
162  * Our stack
163  */
164         .bss
165         .align  8
166         .globl  stack, stack_top
167 stack:
168         .skip   STACK_SIZE
169 stack_top:
170