Refactor copy_and_run so that it uses a single code base instead of
[coreboot.git] / src / cpu / intel / model_6fx / cache_as_ram_disable.c
1 /*
2  * This file is part of the coreboot project.
3  * 
4  * Copyright (C) 2007-2008 coresystems GmbH
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; version 2 of
9  * the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  */
21
22 #include "cpu/x86/car/copy_and_run.c"
23
24 void real_main(unsigned long bist);
25
26 void stage1_main(unsigned long bist)
27 {
28         unsigned int cpu_reset = 0;
29
30 #if USE_FALLBACK_IMAGE == 1
31         /* Is this a deliberate reset by the bios */
32         if (bios_reset_detected() && last_boot_normal()) {
33                 goto normal_image;
34         } else {
35                 /* This is the primary cpu how should I boot? */
36                 check_cmos_failed();
37                 if (do_normal_boot()) {
38                         goto normal_image;
39                 }
40                 else {
41                         goto fallback_image;
42                 }
43         }
44  normal_image:
45         __asm__ volatile ("jmp __normal_image"
46                 : /* outputs */
47                 : "a" (bist) /* inputs */
48                 );
49  fallback_image:
50 #endif
51
52         real_main(bist);
53
54         /* No servicable parts below this line .. */
55
56         {
57                 /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
58                 unsigned v_esp;
59                 __asm__ volatile (
60                         "movl   %%esp, %0\n\t"
61                         : "=a" (v_esp)
62                 );
63                 printk_spew("v_esp=%08x\r\n", v_esp);
64         }
65
66 cpu_reset_x:
67
68         printk_spew("cpu_reset = %08x\r\n",cpu_reset);
69
70         if(cpu_reset == 0) {
71                 print_spew("Clearing initial memory region: ");
72         }
73         print_spew("No cache as ram now - ");
74
75         /* store cpu_reset to ebx */
76         __asm__ volatile (
77                 "movl %0, %%ebx\n\t"
78                 ::"a" (cpu_reset)
79         );
80
81         if(cpu_reset==0) {
82 #define CLEAR_FIRST_1M_RAM 1
83 #include "cache_as_ram_post.c"
84         } else {
85 #undef CLEAR_FIRST_1M_RAM 
86 #include "cache_as_ram_post.c"
87         }
88
89         __asm__ volatile (
90                 /* set new esp */ /* before _RAMBASE */
91                 "subl   %0, %%ebp\n\t"
92                 "subl   %0, %%esp\n\t"
93                 ::"a"( (DCACHE_RAM_BASE + DCACHE_RAM_SIZE)- _RAMBASE )
94         );
95
96         {
97                 unsigned new_cpu_reset;
98
99                 /* get back cpu_reset from ebx */
100                 __asm__ volatile (
101                         "movl %%ebx, %0\n\t"
102                         :"=a" (new_cpu_reset)
103                 );
104
105 #ifdef CONFIG_DEACTIVATE_CAR
106                 print_debug("Deactivating CAR");
107 #include CONFIG_DEACTIVATE_CAR_FILE
108                 print_debug(" - Done.\r\n");
109 #endif
110                 /* Copy and execute coreboot_ram */
111                 copy_and_run(new_cpu_reset);
112                 /* We will not return */
113         }
114
115         print_debug("sorry. parachute did not open.\r\n");
116 }