- Compile fixes
[coreboot.git] / src / arch / i386 / lib / c_start.S
1 #include <arch/asm.h>
2 #include <arch/intel.h>
3 #ifdef SMP
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 */
23         leal    _stack, %edi
24         movl    $_estack, %ecx
25         subl    %edi, %ecx
26         xorl    %eax, %eax
27         rep
28         stosb
29
30         /** clear bss */
31         leal    _bss, %edi
32         movl    $_ebss, %ecx
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
42 #ifdef SMP
43         /* Get the cpu id */
44         movl    $APIC_DEFAULT_BASE, %edi
45         movl    APIC_ID(%edi), %eax
46         shrl    $24, %eax
47
48         /* Get the cpu index (MAX_CPUS on error) */
49         movl    $-4, %ebx
50 1:      addl    $4, %ebx
51         cmpl    $(MAX_CPUS << 2), %ebx
52         je      2
53         cmpl    %eax, initial_apicid(%ebx)
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 */
81         call    hardwaremain
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
119 #if defined(CONFIG_VGABIOS) && (CONFIG_VGABIOS == 1)
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