blob: 47fb64588ca10af7939e2331cb05349e8bd0975f [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001#include <arch/asm.h>
2#include <arch/intel.h>
Ronald G. Minnich57ffeb02003-07-30 03:05:20 +00003#if CONFIG_SMP==1
Eric Biederman8ca8d762003-04-22 19:02:15 +00004#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
131: 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 Biedermanae948f72003-07-14 20:40:38 +000023 leal _stack, %edi
24 movl $_estack, %ecx
Eric Biederman8ca8d762003-04-22 19:02:15 +000025 subl %edi, %ecx
26 xorl %eax, %eax
27 rep
28 stosb
29
30 /** clear bss */
Eric Biedermanae948f72003-07-14 20:40:38 +000031 leal _bss, %edi
32 movl $_ebss, %ecx
Eric Biederman8ca8d762003-04-22 19:02:15 +000033 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. Minnich57ffeb02003-07-30 03:05:20 +000042#if CONFIG_SMP==1
Eric Biederman8ca8d762003-04-22 19:02:15 +000043 /* Get the cpu id */
44 movl $APIC_DEFAULT_BASE, %edi
45 movl APIC_ID(%edi), %eax
46 shrl $24, %eax
47
Eric Biederman9bdb4602003-09-01 23:17:58 +000048 /* Get the cpu index (CONFIG_MAX_CPUS on error) */
Eric Biederman8ca8d762003-04-22 19:02:15 +000049 movl $-4, %ebx
501: addl $4, %ebx
Eric Biederman9bdb4602003-09-01 23:17:58 +000051 cmpl $(CONFIG_MAX_CPUS << 2), %ebx
Eric Biederman8ca8d762003-04-22 19:02:15 +000052 je 2
Eric Biedermanae948f72003-07-14 20:40:38 +000053 cmpl %eax, initial_apicid(%ebx)
Eric Biederman8ca8d762003-04-22 19:02:15 +000054 jne 1b
552: 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 Biedermanae948f72003-07-14 20:40:38 +000081 call hardwaremain
Eric Biederman8ca8d762003-04-22 19:02:15 +000082 /*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
91gdt_limit = gdt_end - gdt - 1 /* compute the table limit */
92gdtaddr:
93 .word gdt_limit
94 .long gdt /* we know the offset */
95
96gdt:
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. Minnich02fa3b22004-10-06 17:33:54 +0000119#if defined(CONFIG_LEGACY_VGABIOS) && (CONFIG_LEGACY_VGABIOS == 1)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000120 // 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)
133gdt_end:
134
135.code32