This is a general cleanup patch
[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 !defined(CONFIG_TINY_BOOTBLOCK) || !CONFIG_TINY_BOOTBLOCK
31 #if CONFIG_USE_FALLBACK_IMAGE == 1
32         /* Is this a deliberate reset by the bios */
33         if (bios_reset_detected() && last_boot_normal()) {
34                 goto normal_image;
35         } else {
36                 /* This is the primary cpu how should I boot? */
37                 check_cmos_failed();
38                 if (do_normal_boot()) {
39                         goto normal_image;
40                 }
41                 else {
42                         goto fallback_image;
43                 }
44         }
45  normal_image:
46         __asm__ volatile ("jmp __normal_image"
47                 : /* outputs */
48                 : "a" (bist) /* inputs */
49                 );
50  fallback_image:
51 #endif
52 #endif
53
54         real_main(bist);
55
56         /* No servicable parts below this line .. */
57 #ifdef CAR_DEBUG
58         /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
59         unsigned v_esp;
60         __asm__ volatile (
61                 "movl   %%esp, %0\n"
62                 : "=a" (v_esp)
63         );
64         printk_spew("v_esp=%08x\n", v_esp);
65 #endif
66
67 cpu_reset_x:
68
69         printk_spew("cpu_reset = %08x\n", cpu_reset);
70         printk_spew("No cache as ram now - ");
71
72         /* store cpu_reset to ebx */
73         __asm__ volatile (
74                 "movl %0, %%ebx\n\t"
75                 ::"a" (cpu_reset)
76         );
77
78 #undef CLEAR_FIRST_1M_RAM 
79 #include "cache_as_ram_post.c"
80
81         /* For now: use rambase + 1MB - 64K (counting downwards) as stack. This
82          * makes sure that we stay completely within the 1M of memory we
83          * preserve with the memcpy above.
84          */
85
86 #ifndef HIGH_MEMORY_SAVE
87 #define HIGH_MEMORY_SAVE ( (1024 - 64) * 1024 )
88 #endif
89
90         __asm__ volatile (
91                 "movl %0, %%ebp\n"
92                 "movl %0, %%esp\n"
93                 :: "a" (CONFIG_RAMBASE + HIGH_MEMORY_SAVE)
94         );
95
96         {
97                 unsigned new_cpu_reset;
98
99                 /* get back cpu_reset from ebx */
100                 __asm__ volatile (
101                         "movl %%ebx, %0\n"
102                         :"=a" (new_cpu_reset)
103                 );
104
105                 /* Copy and execute coreboot_ram */
106                 copy_and_run(new_cpu_reset);
107         }
108
109         /* We will not return */
110         printk_debug("sorry. parachute did not open.\n");
111 }