a22978e051776f3e66338bf11ef9b71da4315d0d
[coreboot.git] / src / cpu / intel / model_6ex / cache_as_ram_disable.c
1 /*
2  * This file is part of the coreboot project.
3  * 
4  * Copyright (C) 2007-2009 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 CONFIG_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 #if CAR_DEBUG
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"
61                 : "=a" (v_esp)
62         );
63         printk_spew("v_esp=%08x\n", v_esp);
64 #endif
65
66 cpu_reset_x:
67
68         printk_spew("cpu_reset = %08x\n", cpu_reset);
69         printk_spew("No cache as ram now - ");
70
71         /* store cpu_reset to ebx */
72         __asm__ volatile (
73                 "movl %0, %%ebx\n\t"
74                 ::"a" (cpu_reset)
75         );
76
77 #undef CLEAR_FIRST_1M_RAM 
78 #include "cache_as_ram_post.c"
79
80         /* For now: use rambase + 1MB - 64K (counting downwards) as stack. This
81          * makes sure that we stay completely within the 1M of memory we
82          * preserve with the memcpy above.
83          */
84
85 #ifndef HIGH_MEMORY_SAVE
86 #define HIGH_MEMORY_SAVE ( (1024 - 64) * 1024 )
87 #endif
88
89         __asm__ volatile (
90                 "movl %0, %%ebp\n"
91                 "movl %0, %%esp\n"
92                 :: "a" (CONFIG_RAMBASE + HIGH_MEMORY_SAVE)
93         );
94
95         {
96                 unsigned new_cpu_reset;
97
98                 /* get back cpu_reset from ebx */
99                 __asm__ volatile (
100                         "movl %%ebx, %0\n"
101                         :"=a" (new_cpu_reset)
102                 );
103
104                 /* Copy and execute coreboot_ram */
105                 copy_and_run(new_cpu_reset);
106         }
107
108         /* We will not return */
109         printk_debug("sorry. parachute did not open.\n");
110 }