cf7c2ab5e934984d29ee54b25b3d2d33bc071037
[coreboot.git] / src / arch / i386 / init / crt0.S.lb
1 /* -*- asm -*-
2  * $ $
3  *
4  */
5
6 /* 
7  * Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
8  *
9  * This file is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * Originally this code was part of ucl the data compression library
15  * for upx the ``Ultimate Packer of eXecutables''.
16  *
17  * - Converted to gas assembly, and refitted to work with etherboot.
18  *   Eric Biederman 20 Aug 2002
19  * - Merged the nrv2b decompressor into crt0.base of coreboot
20  *   Eric Biederman 26 Sept 2002
21  */
22
23
24 #include <arch/asm.h>
25 #include <arch/intel.h>
26 #include <console/loglevel.h>   
27
28 /*
29  * This is the entry code the code in .reset section
30  * jumps to this address.
31  *
32  */
33 .section ".rom.data", "a", @progbits
34 .section ".rom.text", "ax", @progbits
35
36         intel_chip_post_macro(0x01)             /* delay for chipsets */
37
38 #include "crt0_includes.h"
39
40 #if USE_DCACHE_RAM == 0
41 #ifndef CONSOLE_DEBUG_TX_STRING
42         /* uses:         esp, ebx, ax, dx */
43 # define __CRT_CONSOLE_TX_STRING(string) \
44         mov     string, %ebx    ; \
45         CALLSP(crt_console_tx_string)
46
47 # if defined(TTYS0_BASE) && (ASM_CONSOLE_LOGLEVEL > BIOS_DEBUG)
48 #  define CONSOLE_DEBUG_TX_STRING(string)        __CRT_CONSOLE_TX_STRING(string)
49 # else
50 #  define CONSOLE_DEBUG_TX_STRING(string)
51 # endif
52 #endif
53
54         /* clear boot_complete flag */
55         xorl    %ebp, %ebp
56 __main:
57         CONSOLE_DEBUG_TX_STRING($str_copying_to_ram)
58
59         /*
60          *      Copy data into RAM and clear the BSS. Since these segments
61          *      isn\'t really that big we just copy/clear using bytes, not
62          *      double words.
63          */
64         intel_chip_post_macro(0x11)             /* post 11 */
65
66         cld                             /* clear direction flag */
67         
68         /* copy coreboot from it's initial load location to 
69          * the location it is compiled to run at.
70          * Normally this is copying from FLASH ROM to RAM.
71          */
72         movl    %ebp, %esi
73         movl    $0x4000000, %esp
74         movl    %esp, %ebp
75         pushl %esi
76 #if CONFIG_CBFS == 1
77         pushl $str_coreboot_ram_name
78         call cbfs_and_run_core
79 #else
80         movl    $_liseg, %esi
81         movl    $_iseg,  %edi
82         movl    $_eiseg, %ecx
83         subl    %edi, %ecx
84         pushl %ecx
85         pushl %edi
86         pushl %esi
87         call copy_and_run_core
88 #endif
89
90 .Lhlt:  
91         intel_chip_post_macro(0xee)     /* post fe */
92         hlt
93         jmp     .Lhlt
94
95 #ifdef __CRT_CONSOLE_TX_STRING
96         /* Uses esp, ebx, ax, dx  */
97 crt_console_tx_string:
98         mov     (%ebx), %al
99         inc     %ebx
100         cmp     $0, %al
101         jne     9f
102         RETSP
103 9:
104 /* Base Address */
105 #ifndef TTYS0_BASE
106 #define TTYS0_BASE      0x3f8
107 #endif
108 /* Data */
109 #define TTYS0_RBR (TTYS0_BASE+0x00)
110
111 /* Control */
112 #define TTYS0_TBR TTYS0_RBR
113 #define TTYS0_IER (TTYS0_BASE+0x01)
114 #define TTYS0_IIR (TTYS0_BASE+0x02)
115 #define TTYS0_FCR TTYS0_IIR
116 #define TTYS0_LCR (TTYS0_BASE+0x03)
117 #define TTYS0_MCR (TTYS0_BASE+0x04)
118 #define TTYS0_DLL TTYS0_RBR
119 #define TTYS0_DLM TTYS0_IER
120
121 /* Status */
122 #define TTYS0_LSR (TTYS0_BASE+0x05)
123 #define TTYS0_MSR (TTYS0_BASE+0x06)
124 #define TTYS0_SCR (TTYS0_BASE+0x07)
125         
126         mov     %al, %ah
127 10:     mov     $TTYS0_LSR, %dx
128         inb     %dx, %al
129         test    $0x20, %al
130         je      10b
131         mov     $TTYS0_TBR, %dx
132         mov     %ah, %al
133         outb    %al, %dx
134
135         jmp crt_console_tx_string
136 #endif /* __CRT_CONSOLE_TX_STRING */
137
138 #if defined(CONSOLE_DEBUG_TX_STRING) && (ASM_CONSOLE_LOGLEVEL > BIOS_DEBUG)
139 .section ".rom.data"
140 #if CONFIG_COMPRESS
141 str_copying_to_ram:  .string "Uncompressing coreboot to RAM.\r\n"
142 #else
143 str_copying_to_ram:  .string "Copying coreboot to RAM.\r\n"
144 #endif
145 #if CONFIG_CBFS
146 # if USE_FALLBACK_IMAGE == 1
147 str_coreboot_ram_name:  .string "fallback/coreboot_ram"
148 # else
149 str_coreboot_ram_name:  .string "normal/coreboot_ram"
150 # endif
151 #endif
152 str_pre_main:        .string "Jumping to coreboot.\r\n"
153 .previous
154
155 #endif /* ASM_CONSOLE_LOGLEVEL > BIOS_DEBUG */
156
157 #endif /* USE_DCACHE_RAM */