- Merge from trunk up to r45543
[reactos.git] / boot / freeldr / freeldr / arch / i386 / linux.S
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2002 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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 .text
21 .code16
22
23 #define ASM
24 #include <arch.h>
25
26
27 .code32
28 EXTERN(_BootNewLinuxKernel)
29 call switch_to_real
30 .code16
31
32 /* Set the boot drive */
33 movb (_BootDrive),%dl
34
35 /* Load segment registers */
36 cli
37 movw $0x9000,%bx
38 movw %bx,%ds
39 movw %bx,%es
40 movw %bx,%fs
41 movw %bx,%gs
42 movw %bx,%ss
43 movw $0x9000,%sp
44
45 ljmpl $0x9020,$0x0000
46
47
48 .code32
49 /*
50 * VOID BootOldLinuxKernel(ULONG KernelSize);
51 */
52 EXTERN(_BootOldLinuxKernel)
53
54 /* First we have to copy the kernel down from 0x100000 to 0x10000 */
55 /* The reason we can overwrite low memory is because this code */
56 /* executes between 0000:8000 and 0000:FFFF. That leaves space for */
57 /* 32k of code before we start interfering with Linux kernel address space. */
58
59 /* Get KernelSize in ECX and move the kernel down */
60 movl 0x04(%esp),%ecx
61 movl $0x100000,%esi
62 movl $0x10000,%edi
63 rep movsb
64
65 call switch_to_real
66 .code16
67
68 /* Set the boot drive */
69 movb (_BootDrive),%dl
70
71 /* Load segment registers */
72 cli
73 movw $0x9000,%bx
74 movw %bx,%ds
75 movw %bx,%es
76 movw %bx,%fs
77 movw %bx,%gs
78 movw %bx,%ss
79 movw $0x9000,%sp
80
81 ljmpl $0x9020,$0x0000