Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | #include <arch/asm.h> |
| 2 | #include <arch/intel.h> |
Ronald G. Minnich | 57ffeb0 | 2003-07-30 03:05:20 +0000 | [diff] [blame] | 3 | #if CONFIG_SMP==1 |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 4 | #include <cpu/p6/apic.h> |
| 5 | #endif |
| 6 | .section ".text" |
| 7 | .code32 |
| 8 | .globl _start |
| 9 | _start: |
| 10 | cli |
| 11 | lgdt %cs:gdtaddr |
| 12 | ljmp $0x10, $1f |
| 13 | 1: movl $0x18, %eax |
| 14 | movl %eax, %ds |
| 15 | movl %eax, %es |
| 16 | movl %eax, %ss |
| 17 | movl %eax, %fs |
| 18 | movl %eax, %gs |
| 19 | |
| 20 | intel_chip_post_macro(0x13) /* post 12 */ |
| 21 | |
| 22 | /** clear stack */ |
Eric Biederman | ae948f7 | 2003-07-14 20:40:38 +0000 | [diff] [blame] | 23 | leal _stack, %edi |
| 24 | movl $_estack, %ecx |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 25 | subl %edi, %ecx |
| 26 | xorl %eax, %eax |
| 27 | rep |
| 28 | stosb |
| 29 | |
| 30 | /** clear bss */ |
Eric Biederman | ae948f7 | 2003-07-14 20:40:38 +0000 | [diff] [blame] | 31 | leal _bss, %edi |
| 32 | movl $_ebss, %ecx |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 33 | subl %edi, %ecx |
| 34 | jz .Lnobss |
| 35 | xorl %eax, %eax |
| 36 | rep |
| 37 | stosb |
| 38 | .Lnobss: |
| 39 | |
| 40 | /* set new stack */ |
| 41 | movl $_estack, %esp |
Ronald G. Minnich | 57ffeb0 | 2003-07-30 03:05:20 +0000 | [diff] [blame] | 42 | #if CONFIG_SMP==1 |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 43 | /* Get the cpu id */ |
| 44 | movl $APIC_DEFAULT_BASE, %edi |
| 45 | movl APIC_ID(%edi), %eax |
| 46 | shrl $24, %eax |
| 47 | |
Eric Biederman | 9bdb460 | 2003-09-01 23:17:58 +0000 | [diff] [blame] | 48 | /* Get the cpu index (CONFIG_MAX_CPUS on error) */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 49 | movl $-4, %ebx |
| 50 | 1: addl $4, %ebx |
Eric Biederman | 9bdb460 | 2003-09-01 23:17:58 +0000 | [diff] [blame] | 51 | cmpl $(CONFIG_MAX_CPUS << 2), %ebx |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 52 | je 2 |
Eric Biederman | ae948f7 | 2003-07-14 20:40:38 +0000 | [diff] [blame] | 53 | cmpl %eax, initial_apicid(%ebx) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 54 | jne 1b |
| 55 | 2: shrl $2, %ebx |
| 56 | |
| 57 | /* Now compute the appropriate stack */ |
| 58 | movl %ebx, %eax |
| 59 | movl $STACK_SIZE, %ebx |
| 60 | mull %ebx |
| 61 | subl %eax, %esp |
| 62 | #endif |
| 63 | |
| 64 | /* push the boot_complete flag */ |
| 65 | pushl %ebp |
| 66 | |
| 67 | /* Save the stack location */ |
| 68 | movl %esp, %ebp |
| 69 | |
| 70 | /* |
| 71 | * Now we are finished. Memory is up, data is copied and |
| 72 | * bss is cleared. Now we call the main routine and |
| 73 | * let it do the rest. |
| 74 | */ |
| 75 | intel_chip_post_macro(0xfe) /* post fe */ |
| 76 | |
| 77 | /* Resort the stack location */ |
| 78 | movl %ebp, %esp |
| 79 | |
| 80 | /* The boot_complete flag has already been pushed */ |
Eric Biederman | ae948f7 | 2003-07-14 20:40:38 +0000 | [diff] [blame] | 81 | call hardwaremain |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 82 | /*NOTREACHED*/ |
| 83 | .Lhlt: |
| 84 | intel_chip_post_macro(0xee) /* post fe */ |
| 85 | hlt |
| 86 | jmp .Lhlt |
| 87 | |
| 88 | |
| 89 | .globl gdt, gdt_end, gdt_limit |
| 90 | |
| 91 | gdt_limit = gdt_end - gdt - 1 /* compute the table limit */ |
| 92 | gdtaddr: |
| 93 | .word gdt_limit |
| 94 | .long gdt /* we know the offset */ |
| 95 | |
| 96 | gdt: |
| 97 | // selgdt 0 |
| 98 | .word 0x0000, 0x0000 /* dummy */ |
| 99 | .byte 0x00, 0x00, 0x00, 0x00 |
| 100 | |
| 101 | // selgdt 8 |
| 102 | .word 0x0000, 0x0000 /* dummy */ |
| 103 | .byte 0x00, 0x00, 0x00, 0x00 |
| 104 | |
| 105 | // selgdt 0x10 |
| 106 | /* flat code segment */ |
| 107 | .word 0xffff, 0x0000 |
| 108 | .byte 0x00, 0x9b, 0xcf, 0x00 |
| 109 | |
| 110 | //selgdt 0x18 |
| 111 | /* flat data segment */ |
| 112 | .word 0xffff, 0x0000 |
| 113 | .byte 0x00, 0x93, 0xcf, 0x00 |
| 114 | |
| 115 | //selgdt 0x20 |
| 116 | .word 0x0000, 0x0000 /* dummy */ |
| 117 | .byte 0x00, 0x00, 0x00, 0x00 |
| 118 | |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame^] | 119 | #if defined(CONFIG_LEGACY_VGABIOS) && (CONFIG_LEGACY_VGABIOS == 1) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 120 | // from monty: |
| 121 | /* 0x00009a00,0000ffffULL, 20h: 16-bit 64k code at 0x00000000 */ |
| 122 | /* 0x00009200,0000ffffULL 28h: 16-bit 64k data at 0x00000000 */ |
| 123 | // selgdt 0x28 |
| 124 | /*16-bit 64k code at 0x00000000 */ |
| 125 | .word 0xffff, 0x0000 |
| 126 | .byte 0, 0x9a, 0, 0 |
| 127 | |
| 128 | // selgdt 0x30 |
| 129 | /*16-bit 64k data at 0x00000000 */ |
| 130 | .word 0xffff, 0x0000 |
| 131 | .byte 0, 0x92, 0, 0 |
| 132 | #endif // defined(CONFIG_VGABIOS) && (CONFIG_VGABIOS == 1) |
| 133 | gdt_end: |
| 134 | |
| 135 | .code32 |