Use ARC-Path to boot ReactOS
[reactos.git] / freeldr / freeldr / mb.S
1 /*
2 * FreeLoader
3 * Copyright (C) 1999, 2000, 2001 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 .text
21 .code16
22
23 #define ASM
24 #include "asmcode.h"
25 #include "multiboot.h"
26
27 /*
28 * Here we assume the kernel is loaded at 1mb
29 * This boots the kernel
30 */
31 .code32
32 EXTERN(_boot_reactos)
33 call switch_to_real
34 .code16
35
36 /* Save cursor position */
37 movw $3,%ax //! Reset video mode
38 int $0x10
39
40
41 movb $10,%bl
42 movb $12,%ah
43 int $0x10
44
45 movw $0x1112,%ax // Use 8x8 font
46 xorb %bl,%bl
47 int $0x10
48 movw $0x1200,%ax // Use alternate print screen
49 movb $0x20,%bl
50 int $0x10
51 movb $1,%ah // Define cursor (scan lines 6 to 7)
52 movw $0x0607,%cx
53 int $0x10
54
55 movb $1,%ah
56 movw $0x600,%cx
57 int $0x10
58
59 movb $6,%ah // Scroll active page up
60 movb $0x32,%al // Clear 25 lines
61 movw $0,%cx // Upper left of scroll
62 movw $0x314F,%dx // Lower right of scroll
63 movb $(1*0x10+1),%bh // Use normal attribute on blanked line
64 int $0x10 // Video-IO
65
66
67 movw $0,%dx
68 movb $0,%dh
69
70 movb $2,%ah
71 movb $0,%bh
72 int $0x10
73
74 movw $0,%dx
75 movb $0,%dh
76
77 movb $2,%ah
78 movb $0,%bh
79 int $0x10
80
81 call _multi_boot
82
83 // Should never get here
84 cli
85 hlt
86
87
88 /*
89 * After you have setup the _mb_header and _mb_info structures
90 * then call this routine to transfer control to the kernel.
91 * This routine must be entered in 16-bit mode.
92 */
93 .code16
94 EXTERN(_multi_boot)
95
96 cli
97
98 /*
99 * Setup various variables
100 */
101 movw %ds,%bx
102 movzwl %bx,%eax
103 shll $4,%eax
104 addl %eax,kernel_gdtbase
105
106 /*
107 * Load the absolute address of the multiboot information structure
108 */
109 movl $_mb_info,%ebx
110
111 /*
112 * load gdt
113 */
114 lgdt kernel_gdtptr
115
116 /*
117 * Enter pmode and clear prefetch queue
118 */
119 movl %cr0,%eax
120 orl $0x10001,%eax
121 movl %eax,%cr0
122 jmp next
123 next:
124 /*
125 * NOTE: This must be position independant (no references to
126 * non absolute variables)
127 */
128
129 /*
130 * Initalize segment registers
131 */
132 movw $KERNEL_DS,%ax
133 movw %ax,%ds
134 movw %ax,%ss
135 movw %ax,%es
136 movw %ax,%fs
137 movw %ax,%gs
138
139 /*
140 * Initalize eflags
141 */
142 pushl $0
143 popfl
144
145 /*
146 * Load the multiboot magic value into eax
147 */
148 movl $0x2badb002,%eax
149
150 /*
151 * Jump to start of 32 bit code at 0xc0000000 + 0x1000
152 */
153
154 pushl $KERNEL_CS
155 pushl _mb_entry_addr
156 lretl
157
158 //ljmpl $KERNEL_CS,$(0x0200000+0x1000)
159 //ljmpl $KERNEL_CS,(_mb_entry_addr)
160 //ljmpl $KERNEL_CS,$(KERNEL_BASE+0x1000)
161
162
163 .p2align 2 /* force 4-byte alignment */
164 kernel_gdt:
165 .word 0 // Zero descriptor
166 .word 0
167 .word 0
168 .word 0
169
170 .word 0xffff // Kernel code descriptor
171 .word 0x0000 //
172 .word 0x9a00 // base 0h limit 4gb
173 .word 0x00cf
174
175 .word 0xffff // Kernel data descriptor
176 .word 0x0000 //
177 .word 0x9200 // base 0h limit 4gb
178 .word 0x00cf
179
180 kernel_gdtptr:
181 .word (3*8)-1 /* Limit */
182 kernel_gdtbase:
183 .long kernel_gdt /* Base Address */
184
185
186 EXTERN(_mb_header)
187 _mb_magic:
188 .long 0 // unsigned long magic;
189 _mb_flags:
190 .long 0 // unsigned long flags;
191 _mb_checksum:
192 .long 0 // unsigned long checksum;
193 _mb_header_addr:
194 .long 0 // unsigned long header_addr;
195 _mb_load_addr:
196 .long 0 // unsigned long load_addr;
197 _mb_load_end_addr:
198 .long 0 // unsigned long load_end_addr;
199 _mb_bss_end_addr:
200 .long 0 // unsigned long bss_end_addr;
201 _mb_entry_addr:
202 .long 0 // unsigned long entry_addr;
203
204 //
205 // Boot information structure
206 //
207
208 EXTERN(_mb_info)
209 _multiboot_flags:
210 .long 0
211 _multiboot_mem_lower:
212 .long 0
213 _multiboot_mem_upper:
214 .long 0
215 _multiboot_boot_device:
216 .long 0
217 _multiboot_cmdline:
218 .long 0
219 _multiboot_mods_count:
220 .long 0
221 _multiboot_mods_addr:
222 .long 0
223 _multiboot_syms:
224 .rept 12
225 .byte 0
226 .endr
227 _multiboot_mmap_length:
228 .long 0
229 _multiboot_mmap_addr:
230 .long 0
231 _multiboot_drives_count:
232 .long 0
233 _multiboot_drives_addr:
234 .long 0
235 _multiboot_config_table:
236 .long 0
237 _multiboot_boot_loader_name:
238 .long 0
239 _multiboot_apm_table:
240 .long 0
241
242 EXTERN(_multiboot_modules)
243 .rept (64 * /*multiboot_module_size*/ 16)
244 .byte 0
245 .endr
246 EXTERN(_multiboot_module_strings)
247 .rept (64*256)
248 .byte 0
249 .endr
250
251 _multiboot_address_range_descriptor_size:
252 .long 0
253
254 _multiboot_address_ranges:
255 .rept (64 * /*multiboot_address_range_size*/24)
256 .byte 0
257 .endr
258
259 EXTERN(_multiboot_kernel_cmdline)
260 .rept 255
261 .byte 0
262 .endr