Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/boot/head.S |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992, 1993 Linus Torvalds |
| 5 | */ |
| 6 | |
| 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 | */ |
| 20 | |
| 21 | /* |
| 22 | * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996 |
| 23 | */ |
| 24 | .text |
| 25 | |
| 26 | #include <linux/linkage.h> |
| 27 | #include <asm/segment.h> |
Eric W. Biederman | 3d345e3 | 2005-06-25 14:57:49 -0700 | [diff] [blame] | 28 | #include <asm/page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | .globl startup_32 |
| 31 | |
| 32 | startup_32: |
| 33 | cld |
| 34 | cli |
| 35 | movl $(__BOOT_DS),%eax |
| 36 | movl %eax,%ds |
| 37 | movl %eax,%es |
| 38 | movl %eax,%fs |
| 39 | movl %eax,%gs |
| 40 | |
| 41 | lss stack_start,%esp |
| 42 | xorl %eax,%eax |
| 43 | 1: incl %eax # check that A20 really IS enabled |
| 44 | movl %eax,0x000000 # loop forever if it isn't |
| 45 | cmpl %eax,0x100000 |
| 46 | je 1b |
| 47 | |
| 48 | /* |
| 49 | * Initialize eflags. Some BIOS's leave bits like NT set. This would |
| 50 | * confuse the debugger if this code is traced. |
| 51 | * XXX - best to initialize before switching to protected mode. |
| 52 | */ |
| 53 | pushl $0 |
| 54 | popfl |
| 55 | /* |
| 56 | * Clear BSS |
| 57 | */ |
| 58 | xorl %eax,%eax |
| 59 | movl $_edata,%edi |
| 60 | movl $_end,%ecx |
| 61 | subl %edi,%ecx |
| 62 | cld |
| 63 | rep |
| 64 | stosb |
| 65 | /* |
| 66 | * Do the decompression, and jump to the new kernel.. |
| 67 | */ |
| 68 | subl $16,%esp # place for structure on the stack |
| 69 | movl %esp,%eax |
| 70 | pushl %esi # real mode pointer as second arg |
| 71 | pushl %eax # address of structure as first arg |
| 72 | call decompress_kernel |
| 73 | orl %eax,%eax |
| 74 | jnz 3f |
| 75 | popl %esi # discard address |
| 76 | popl %esi # real mode pointer |
| 77 | xorl %ebx,%ebx |
Eric W. Biederman | 3d345e3 | 2005-06-25 14:57:49 -0700 | [diff] [blame] | 78 | ljmp $(__BOOT_CS), $__PHYSICAL_START |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * We come here, if we were loaded high. |
| 82 | * We need to move the move-in-place routine down to 0x1000 |
| 83 | * and then start it with the buffer addresses in registers, |
| 84 | * which we got from the stack. |
| 85 | */ |
| 86 | 3: |
| 87 | movl $move_routine_start,%esi |
| 88 | movl $0x1000,%edi |
| 89 | movl $move_routine_end,%ecx |
| 90 | subl %esi,%ecx |
| 91 | addl $3,%ecx |
| 92 | shrl $2,%ecx |
| 93 | cld |
| 94 | rep |
| 95 | movsl |
| 96 | |
| 97 | popl %esi # discard the address |
| 98 | popl %ebx # real mode pointer |
| 99 | popl %esi # low_buffer_start |
| 100 | popl %ecx # lcount |
| 101 | popl %edx # high_buffer_start |
| 102 | popl %eax # hcount |
Eric W. Biederman | 3d345e3 | 2005-06-25 14:57:49 -0700 | [diff] [blame] | 103 | movl $__PHYSICAL_START,%edi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | cli # make sure we don't get interrupted |
| 105 | ljmp $(__BOOT_CS), $0x1000 # and jump to the move routine |
| 106 | |
| 107 | /* |
| 108 | * Routine (template) for moving the decompressed kernel in place, |
| 109 | * if we were high loaded. This _must_ PIC-code ! |
| 110 | */ |
| 111 | move_routine_start: |
| 112 | movl %ecx,%ebp |
| 113 | shrl $2,%ecx |
| 114 | rep |
| 115 | movsl |
| 116 | movl %ebp,%ecx |
| 117 | andl $3,%ecx |
| 118 | rep |
| 119 | movsb |
| 120 | movl %edx,%esi |
| 121 | movl %eax,%ecx # NOTE: rep movsb won't move if %ecx == 0 |
| 122 | addl $3,%ecx |
| 123 | shrl $2,%ecx |
| 124 | rep |
| 125 | movsl |
| 126 | movl %ebx,%esi # Restore setup pointer |
| 127 | xorl %ebx,%ebx |
Eric W. Biederman | 3d345e3 | 2005-06-25 14:57:49 -0700 | [diff] [blame] | 128 | ljmp $(__BOOT_CS), $__PHYSICAL_START |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | move_routine_end: |