blob: 6491e522ec4ef18513e1763f0434a80429175d05 [file] [log] [blame]
wdenk2262cfe2002-11-18 00:14:45 +00001/*
2 * (C) Copyright 2002
3 * Daniel Engström, Omicron Ceti AB, daniel@omicron.se
wdenk8bde7f72003-06-27 21:31:46 +00004 *
wdenk2262cfe2002-11-18 00:14:45 +00005 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24
25/*
26 * Partly based on msbios.c from rolo 1.6:
27 *----------------------------------------------------------------------
28 * (C) Copyright 2000
29 * Sysgo Real-Time Solutions GmbH
30 * Klein-Winternheim, Germany
31 *----------------------------------------------------------------------
32 */
33
34#include <common.h>
wdenk7a8e9bed2003-05-31 18:35:21 +000035#include <pci.h>
wdenk2262cfe2002-11-18 00:14:45 +000036#include <asm/realmode.h>
37#include <asm/io.h>
38
Wolfgang Denkd87080b2006-03-31 18:32:53 +020039DECLARE_GLOBAL_DATA_PTR;
40
wdenk2262cfe2002-11-18 00:14:45 +000041#define NUMVECTS 256
42
43#define BIOS_DATA ((char*)0x400)
44#define BIOS_DATA_SIZE 256
45#define BIOS_BASE ((char*)0xf0000)
46#define BIOS_CS 0xf000
47
Graeme Russcabe5792009-11-24 20:04:20 +110048extern ulong _i386boot_bios;
49extern ulong _i386boot_bios_size;
50
wdenk7a8e9bed2003-05-31 18:35:21 +000051/* these are defined in a 16bit segment and needs
52 * to be accessed with the RELOC_16_xxxx() macros below
53 */
wdenk2262cfe2002-11-18 00:14:45 +000054extern u16 ram_in_64kb_chunks;
55extern u16 bios_equipment;
wdenk7a8e9bed2003-05-31 18:35:21 +000056extern u8 pci_last_bus;
57
wdenk2262cfe2002-11-18 00:14:45 +000058extern void *rm_int00;
59extern void *rm_int01;
60extern void *rm_int02;
61extern void *rm_int03;
62extern void *rm_int04;
63extern void *rm_int05;
64extern void *rm_int06;
65extern void *rm_int07;
66extern void *rm_int08;
67extern void *rm_int09;
68extern void *rm_int0a;
69extern void *rm_int0b;
70extern void *rm_int0c;
71extern void *rm_int0d;
72extern void *rm_int0e;
73extern void *rm_int0f;
74extern void *rm_int10;
75extern void *rm_int11;
76extern void *rm_int12;
77extern void *rm_int13;
78extern void *rm_int14;
79extern void *rm_int15;
80extern void *rm_int16;
81extern void *rm_int17;
82extern void *rm_int18;
83extern void *rm_int19;
84extern void *rm_int1a;
85extern void *rm_int1b;
86extern void *rm_int1c;
87extern void *rm_int1d;
88extern void *rm_int1e;
89extern void *rm_int1f;
90extern void *rm_def_int;
91
wdenk7a8e9bed2003-05-31 18:35:21 +000092extern void *realmode_reset;
93extern void *realmode_pci_bios_call_entry;
94
wdenk8bde7f72003-06-27 21:31:46 +000095static int set_jmp_vector(int entry_point, void *target)
wdenk7a8e9bed2003-05-31 18:35:21 +000096{
97 if (entry_point & ~0xffff) {
98 return -1;
99 }
wdenk8bde7f72003-06-27 21:31:46 +0000100
wdenk7a8e9bed2003-05-31 18:35:21 +0000101 if (((u32)target-0xf0000) & ~0xffff) {
102 return -1;
103 }
104 printf("set_jmp_vector: 0xf000:%04x -> %p\n",
105 entry_point, target);
wdenk8bde7f72003-06-27 21:31:46 +0000106
wdenk7a8e9bed2003-05-31 18:35:21 +0000107 /* jmp opcode */
108 writeb(0xea, 0xf0000 + entry_point);
wdenk8bde7f72003-06-27 21:31:46 +0000109
wdenk7a8e9bed2003-05-31 18:35:21 +0000110 /* offset */
111 writew(((u32)target-0xf0000), 0xf0000 + entry_point + 1);
wdenk8bde7f72003-06-27 21:31:46 +0000112
wdenk7a8e9bed2003-05-31 18:35:21 +0000113 /* segment */
114 writew(0xf000, 0xf0000 + entry_point + 3);
wdenk8bde7f72003-06-27 21:31:46 +0000115
wdenk7a8e9bed2003-05-31 18:35:21 +0000116 return 0;
117}
118
119
wdenk2262cfe2002-11-18 00:14:45 +0000120/*
121 ************************************************************
122 * Install an interrupt vector
123 ************************************************************
124 */
125
126static void setvector(int vector, u16 segment, void *handler)
127{
128 u16 *ptr = (u16*)(vector*4);
129 ptr[0] = ((u32)handler - (segment << 4))&0xffff;
130 ptr[1] = segment;
wdenk8bde7f72003-06-27 21:31:46 +0000131
132#if 0
wdenk2262cfe2002-11-18 00:14:45 +0000133 printf("setvector: int%02x -> %04x:%04x\n",
134 vector, ptr[1], ptr[0]);
wdenk8bde7f72003-06-27 21:31:46 +0000135#endif
wdenk2262cfe2002-11-18 00:14:45 +0000136}
137
wdenk8bde7f72003-06-27 21:31:46 +0000138#define RELOC_16_LONG(seg, off) *(u32*)(seg << 4 | (u32)&off)
139#define RELOC_16_WORD(seg, off) *(u16*)(seg << 4 | (u32)&off)
140#define RELOC_16_BYTE(seg, off) *(u8*)(seg << 4 | (u32)&off)
wdenk7a8e9bed2003-05-31 18:35:21 +0000141
wdenk2262cfe2002-11-18 00:14:45 +0000142int bios_setup(void)
143{
Graeme Russcabe5792009-11-24 20:04:20 +1100144 ulong i386boot_bios = (ulong)&_i386boot_bios;
145 ulong i386boot_bios_size = (ulong)&_i386boot_bios_size;
146
wdenk8bde7f72003-06-27 21:31:46 +0000147 static int done=0;
wdenk2262cfe2002-11-18 00:14:45 +0000148 int vector;
Graeme Russ3ef96de2008-09-07 07:08:42 +1000149#ifdef CONFIG_PCI
wdenk7a8e9bed2003-05-31 18:35:21 +0000150 struct pci_controller *pri_hose;
Graeme Russ3ef96de2008-09-07 07:08:42 +1000151#endif
wdenk2262cfe2002-11-18 00:14:45 +0000152 if (done) {
153 return 0;
154 }
155 done = 1;
wdenk8bde7f72003-06-27 21:31:46 +0000156
wdenk2262cfe2002-11-18 00:14:45 +0000157 if (i386boot_bios_size > 65536) {
wdenk8bde7f72003-06-27 21:31:46 +0000158 printf("BIOS too large (%ld bytes, max is 65536)\n",
wdenk2262cfe2002-11-18 00:14:45 +0000159 i386boot_bios_size);
160 return -1;
161 }
wdenk8bde7f72003-06-27 21:31:46 +0000162
wdenk2262cfe2002-11-18 00:14:45 +0000163 memcpy(BIOS_BASE, (void*)i386boot_bios, i386boot_bios_size);
164
165 /* clear bda */
166 memset(BIOS_DATA, 0, BIOS_DATA_SIZE);
wdenk8bde7f72003-06-27 21:31:46 +0000167
wdenk2262cfe2002-11-18 00:14:45 +0000168 /* enter some values to the bda */
169 writew(0x3f8, BIOS_DATA); /* com1 addr */
170 writew(0x2f8, BIOS_DATA+2); /* com2 addr */
171 writew(0x3e8, BIOS_DATA+4); /* com3 addr */
172 writew(0x2e8, BIOS_DATA+6); /* com4 addr */
173 writew(0x278, BIOS_DATA+8); /* lpt1 addr */
174 /*
175 * The kernel wants to read the base memory size
176 * from 40:13. Put a zero there to avoid an error message
177 */
178 writew(0, BIOS_DATA+0x13); /* base memory size */
179
wdenk8bde7f72003-06-27 21:31:46 +0000180
181 /* setup realmode interrupt vectors */
wdenk2262cfe2002-11-18 00:14:45 +0000182 for (vector = 0; vector < NUMVECTS; vector++) {
183 setvector(vector, BIOS_CS, &rm_def_int);
184 }
wdenk8bde7f72003-06-27 21:31:46 +0000185
wdenk2262cfe2002-11-18 00:14:45 +0000186 setvector(0x00, BIOS_CS, &rm_int00);
187 setvector(0x01, BIOS_CS, &rm_int01);
188 setvector(0x02, BIOS_CS, &rm_int02);
189 setvector(0x03, BIOS_CS, &rm_int03);
190 setvector(0x04, BIOS_CS, &rm_int04);
191 setvector(0x05, BIOS_CS, &rm_int05);
192 setvector(0x06, BIOS_CS, &rm_int06);
193 setvector(0x07, BIOS_CS, &rm_int07);
194 setvector(0x08, BIOS_CS, &rm_int08);
195 setvector(0x09, BIOS_CS, &rm_int09);
196 setvector(0x0a, BIOS_CS, &rm_int0a);
197 setvector(0x0b, BIOS_CS, &rm_int0b);
198 setvector(0x0c, BIOS_CS, &rm_int0c);
199 setvector(0x0d, BIOS_CS, &rm_int0d);
200 setvector(0x0e, BIOS_CS, &rm_int0e);
201 setvector(0x0f, BIOS_CS, &rm_int0f);
202 setvector(0x10, BIOS_CS, &rm_int10);
203 setvector(0x11, BIOS_CS, &rm_int11);
204 setvector(0x12, BIOS_CS, &rm_int12);
205 setvector(0x13, BIOS_CS, &rm_int13);
206 setvector(0x14, BIOS_CS, &rm_int14);
207 setvector(0x15, BIOS_CS, &rm_int15);
208 setvector(0x16, BIOS_CS, &rm_int16);
209 setvector(0x17, BIOS_CS, &rm_int17);
210 setvector(0x18, BIOS_CS, &rm_int18);
211 setvector(0x19, BIOS_CS, &rm_int19);
212 setvector(0x1a, BIOS_CS, &rm_int1a);
213 setvector(0x1b, BIOS_CS, &rm_int1b);
214 setvector(0x1c, BIOS_CS, &rm_int1c);
215 setvector(0x1d, BIOS_CS, &rm_int1d);
216 setvector(0x1e, BIOS_CS, &rm_int1e);
217 setvector(0x1f, BIOS_CS, &rm_int1f);
218
wdenk7a8e9bed2003-05-31 18:35:21 +0000219 set_jmp_vector(0xfff0, &realmode_reset);
220 set_jmp_vector(0xfe6e, &realmode_pci_bios_call_entry);
wdenk8bde7f72003-06-27 21:31:46 +0000221
wdenk2262cfe2002-11-18 00:14:45 +0000222 /* fill in data area */
wdenk7a8e9bed2003-05-31 18:35:21 +0000223 RELOC_16_WORD(0xf000, ram_in_64kb_chunks) = gd->ram_size >> 16;
224 RELOC_16_WORD(0xf000, bios_equipment) = 0; /* FixMe */
wdenk8bde7f72003-06-27 21:31:46 +0000225
wdenk7a8e9bed2003-05-31 18:35:21 +0000226 /* If we assume only one PCI hose, this PCI hose
wdenk8bde7f72003-06-27 21:31:46 +0000227 * will own PCI bus #0, and the last PCI bus of
228 * that PCI hose will be the last PCI bus in the
229 * system.
wdenk7a8e9bed2003-05-31 18:35:21 +0000230 * (This, ofcause break on multi hose systems,
wdenk8bde7f72003-06-27 21:31:46 +0000231 * but our PCI BIOS only support one hose anyway)
wdenk7a8e9bed2003-05-31 18:35:21 +0000232 */
Graeme Russ3ef96de2008-09-07 07:08:42 +1000233#ifdef CONFIG_PCI
wdenk7a8e9bed2003-05-31 18:35:21 +0000234 pri_hose = pci_bus_to_hose(0);
235 if (NULL != pri_hose) {
wdenk8bde7f72003-06-27 21:31:46 +0000236 /* fill in last pci bus number for use by the realmode
wdenk7a8e9bed2003-05-31 18:35:21 +0000237 * PCI BIOS */
238 RELOC_16_BYTE(0xf000, pci_last_bus) = pri_hose->last_busno;
239 }
Graeme Russ3ef96de2008-09-07 07:08:42 +1000240#endif
wdenk2262cfe2002-11-18 00:14:45 +0000241 return 0;
242}