MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / arch / i386 / boot / compressed / head.S
blob86e9f4b76b54bd30b26198e025f2c71762c085d3
1 /*
2  *  linux/boot/head.S
3  *
4  *  Copyright (C) 1991, 1992, 1993  Linus Torvalds
5  */
7 /*
8  *  head.S contains the 32-bit startup code.
9  *
10  * NOTE!!! Startup happens at absolute address 0x00001000, which is also where
11  * the page directory will exist. The startup code will be overwritten by
12  * the page directory. [According to comments etc elsewhere on a compressed
13  * kernel it will end up at 0x1000 + 1Mb I hope so as I assume this. - AC]
14  *
15  * Page 0 is deliberately kept safe, since System Management Mode code in 
16  * laptops may need to access the BIOS data stored there.  This is also
17  * useful for future device drivers that either access the BIOS via VM86 
18  * mode.
19  */
22  * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
23  */
24 .text
26 #include <linux/linkage.h>
27 #include <asm/segment.h>
28 #include <asm/page.h>
30 #undef  __BOOT_CS
31 #define __BOOT_CS       0x10
32 #undef  __BOOT_DS
33 #define __BOOT_DS       0x18
36         .globl startup_32
37         
38 startup_32:
39         cld
40         cli
41         movl $(__BOOT_DS),%eax
42         movl %eax,%ds
43         movl %eax,%es
44         movl %eax,%fs
45         movl %eax,%gs
47         lss stack_start,%esp
48         xorl %eax,%eax
49 1:      incl %eax               # check that A20 really IS enabled
50         movl %eax,0x000000      # loop forever if it isn't
51         cmpl %eax,0x100000
52         je 1b
55  * Initialize eflags.  Some BIOS's leave bits like NT set.  This would
56  * confuse the debugger if this code is traced.
57  * XXX - best to initialize before switching to protected mode.
58  */
59         pushl $0
60         popfl
62  * Clear BSS
63  */
64         xorl %eax,%eax
65         movl $_edata,%edi
66         movl $_end,%ecx
67         subl %edi,%ecx
68         cld
69         rep
70         stosb
72  * Do the decompression, and jump to the new kernel..
73  */
74         subl $16,%esp   # place for structure on the stack
75         movl %esp,%eax
76         pushl %esi      # real mode pointer as second arg
77         pushl %eax      # address of structure as first arg
78         call decompress_kernel
79         orl  %eax,%eax 
80         jnz  3f
81         popl %esi       # discard address
82         popl %esi       # real mode pointer
83         xorl %ebx,%ebx
84         ljmp $(__BOOT_CS), $__PHYSICAL_START
87  * We come here, if we were loaded high.
88  * We need to move the move-in-place routine down to 0x1000
89  * and then start it with the buffer addresses in registers,
90  * which we got from the stack.
91  */
93         movl $move_routine_start,%esi
94         movl $0x1000,%edi
95         movl $move_routine_end,%ecx
96         subl %esi,%ecx
97         addl $3,%ecx
98         shrl $2,%ecx
99         cld
100         rep
101         movsl
103         popl %esi       # discard the address
104         popl %ebx       # real mode pointer
105         popl %esi       # low_buffer_start
106         popl %ecx       # lcount
107         popl %edx       # high_buffer_start
108         popl %eax       # hcount
109         movl $__PHYSICAL_START,%edi
110         cli             # make sure we don't get interrupted
111         ljmp $(__BOOT_CS), $0x1000 # and jump to the move routine
114  * Routine (template) for moving the decompressed kernel in place,
115  * if we were high loaded. This _must_ PIC-code !
116  */
117 move_routine_start:
118         movl %ecx,%ebp
119         shrl $2,%ecx
120         rep
121         movsl
122         movl %ebp,%ecx
123         andl $3,%ecx
124         rep
125         movsb
126         movl %edx,%esi
127         movl %eax,%ecx  # NOTE: rep movsb won't move if %ecx == 0
128         addl $3,%ecx
129         shrl $2,%ecx
130         rep
131         movsl
132         movl %ebx,%esi  # Restore setup pointer
133         xorl %ebx,%ebx
134         ljmp $(__BOOT_CS), $__PHYSICAL_START
135 move_routine_end: