Major merge of YhLu's code from 2004/04/20: add s2875, various other updates,
[coreboot.git] / src / mainboard / tyan / s2875 / failover.c
1 #define ASSEMBLY 1
2 #include <stdint.h>
3 #include <device/pci_def.h>
4 #include <device/pci_ids.h>
5 #include <arch/io.h>
6 #include <arch/romcc_io.h>
7 #include <arch/smp/lapic.h>
8 #include "pc80/mc146818rtc_early.c"
9 #include "southbridge/amd/amd8111/amd8111_enable_rom.c"
10 #include "northbridge/amd/amdk8/early_ht.c"
11 #include "cpu/p6/boot_cpu.c"
12 #include "northbridge/amd/amdk8/reset_test.c"
13
14 #define HAVE_REGPARM_SUPPORT 0
15 #if HAVE_REGPARM_SUPPORT
16 static unsigned long main(unsigned long bist)
17 {
18 #else
19 static void main(void)
20 {
21         unsigned long bist = 0;
22 #endif
23         /* Make cerain my local apic is useable */
24         enable_lapic();
25
26         /* Is this a cpu only reset? */
27         if (cpu_init_detected()) {
28                 if (last_boot_normal()) {
29                         goto normal_image;
30                 } else {
31                         goto cpu_reset;
32                 }
33         }
34         /* Is this a secondary cpu? */
35         if (!boot_cpu()) {
36                 if (last_boot_normal()) {
37                         goto normal_image;
38                 } else {
39                         goto fallback_image;
40                 }
41         }
42         
43
44         /* Nothing special needs to be done to find bus 0 */
45         /* Allow the HT devices to be found */
46         enumerate_ht_chain();
47         
48         /* Setup the 8111 */
49         amd8111_enable_rom();
50
51         /* Is this a deliberate reset by the bios */
52         if (bios_reset_detected() && last_boot_normal()) {
53                 goto normal_image;
54         }
55         /* This is the primary cpu how should I boot? */
56         else if (do_normal_boot()) {
57                 goto normal_image;
58         }
59         else {
60                 goto fallback_image;
61         }
62  normal_image:
63         asm("jmp __normal_image" 
64                 : /* outputs */ 
65                 : "a" (bist) /* inputs */
66                 : /* clobbers */
67                 );
68  cpu_reset:
69         asm("jmp __cpu_reset"
70                 : /* outputs */ 
71                 : "a"(bist) /* inputs */
72                 : /* clobbers */
73                 );
74  fallback_image:
75 #if HAVE_REGPARM_SUPPORT
76         return bist;
77 #else
78         return;
79 #endif
80 }