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