blob: bc9781550dc60dfac3871c20a930f27120bbac2c [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
39#define NUMVECTS 256
40
41#define BIOS_DATA ((char*)0x400)
42#define BIOS_DATA_SIZE 256
43#define BIOS_BASE ((char*)0xf0000)
44#define BIOS_CS 0xf000
45
wdenk7a8e9bed2003-05-31 18:35:21 +000046/* these are defined in a 16bit segment and needs
47 * to be accessed with the RELOC_16_xxxx() macros below
48 */
wdenk2262cfe2002-11-18 00:14:45 +000049extern u16 ram_in_64kb_chunks;
50extern u16 bios_equipment;
wdenk7a8e9bed2003-05-31 18:35:21 +000051extern u8 pci_last_bus;
52
wdenk2262cfe2002-11-18 00:14:45 +000053extern void *rm_int00;
54extern void *rm_int01;
55extern void *rm_int02;
56extern void *rm_int03;
57extern void *rm_int04;
58extern void *rm_int05;
59extern void *rm_int06;
60extern void *rm_int07;
61extern void *rm_int08;
62extern void *rm_int09;
63extern void *rm_int0a;
64extern void *rm_int0b;
65extern void *rm_int0c;
66extern void *rm_int0d;
67extern void *rm_int0e;
68extern void *rm_int0f;
69extern void *rm_int10;
70extern void *rm_int11;
71extern void *rm_int12;
72extern void *rm_int13;
73extern void *rm_int14;
74extern void *rm_int15;
75extern void *rm_int16;
76extern void *rm_int17;
77extern void *rm_int18;
78extern void *rm_int19;
79extern void *rm_int1a;
80extern void *rm_int1b;
81extern void *rm_int1c;
82extern void *rm_int1d;
83extern void *rm_int1e;
84extern void *rm_int1f;
85extern void *rm_def_int;
86
wdenk7a8e9bed2003-05-31 18:35:21 +000087extern void *realmode_reset;
88extern void *realmode_pci_bios_call_entry;
89
wdenk8bde7f72003-06-27 21:31:46 +000090static int set_jmp_vector(int entry_point, void *target)
wdenk7a8e9bed2003-05-31 18:35:21 +000091{
92 if (entry_point & ~0xffff) {
93 return -1;
94 }
wdenk8bde7f72003-06-27 21:31:46 +000095
wdenk7a8e9bed2003-05-31 18:35:21 +000096 if (((u32)target-0xf0000) & ~0xffff) {
97 return -1;
98 }
99 printf("set_jmp_vector: 0xf000:%04x -> %p\n",
100 entry_point, target);
wdenk8bde7f72003-06-27 21:31:46 +0000101
wdenk7a8e9bed2003-05-31 18:35:21 +0000102 /* jmp opcode */
103 writeb(0xea, 0xf0000 + entry_point);
wdenk8bde7f72003-06-27 21:31:46 +0000104
wdenk7a8e9bed2003-05-31 18:35:21 +0000105 /* offset */
106 writew(((u32)target-0xf0000), 0xf0000 + entry_point + 1);
wdenk8bde7f72003-06-27 21:31:46 +0000107
wdenk7a8e9bed2003-05-31 18:35:21 +0000108 /* segment */
109 writew(0xf000, 0xf0000 + entry_point + 3);
wdenk8bde7f72003-06-27 21:31:46 +0000110
wdenk7a8e9bed2003-05-31 18:35:21 +0000111 return 0;
112}
113
114
wdenk2262cfe2002-11-18 00:14:45 +0000115/*
116 ************************************************************
117 * Install an interrupt vector
118 ************************************************************
119 */
120
121static void setvector(int vector, u16 segment, void *handler)
122{
123 u16 *ptr = (u16*)(vector*4);
124 ptr[0] = ((u32)handler - (segment << 4))&0xffff;
125 ptr[1] = segment;
wdenk8bde7f72003-06-27 21:31:46 +0000126
127#if 0
wdenk2262cfe2002-11-18 00:14:45 +0000128 printf("setvector: int%02x -> %04x:%04x\n",
129 vector, ptr[1], ptr[0]);
wdenk8bde7f72003-06-27 21:31:46 +0000130#endif
wdenk2262cfe2002-11-18 00:14:45 +0000131}
132
wdenk8bde7f72003-06-27 21:31:46 +0000133#define RELOC_16_LONG(seg, off) *(u32*)(seg << 4 | (u32)&off)
134#define RELOC_16_WORD(seg, off) *(u16*)(seg << 4 | (u32)&off)
135#define RELOC_16_BYTE(seg, off) *(u8*)(seg << 4 | (u32)&off)
wdenk7a8e9bed2003-05-31 18:35:21 +0000136
wdenk2262cfe2002-11-18 00:14:45 +0000137int bios_setup(void)
138{
139 DECLARE_GLOBAL_DATA_PTR;
wdenk8bde7f72003-06-27 21:31:46 +0000140 static int done=0;
wdenk2262cfe2002-11-18 00:14:45 +0000141 int vector;
wdenk7a8e9bed2003-05-31 18:35:21 +0000142 struct pci_controller *pri_hose;
wdenk8bde7f72003-06-27 21:31:46 +0000143
wdenk2262cfe2002-11-18 00:14:45 +0000144 if (done) {
145 return 0;
146 }
147 done = 1;
wdenk8bde7f72003-06-27 21:31:46 +0000148
wdenk2262cfe2002-11-18 00:14:45 +0000149 if (i386boot_bios_size > 65536) {
wdenk8bde7f72003-06-27 21:31:46 +0000150 printf("BIOS too large (%ld bytes, max is 65536)\n",
wdenk2262cfe2002-11-18 00:14:45 +0000151 i386boot_bios_size);
152 return -1;
153 }
wdenk8bde7f72003-06-27 21:31:46 +0000154
wdenk2262cfe2002-11-18 00:14:45 +0000155 memcpy(BIOS_BASE, (void*)i386boot_bios, i386boot_bios_size);
156
157 /* clear bda */
158 memset(BIOS_DATA, 0, BIOS_DATA_SIZE);
wdenk8bde7f72003-06-27 21:31:46 +0000159
wdenk2262cfe2002-11-18 00:14:45 +0000160 /* enter some values to the bda */
161 writew(0x3f8, BIOS_DATA); /* com1 addr */
162 writew(0x2f8, BIOS_DATA+2); /* com2 addr */
163 writew(0x3e8, BIOS_DATA+4); /* com3 addr */
164 writew(0x2e8, BIOS_DATA+6); /* com4 addr */
165 writew(0x278, BIOS_DATA+8); /* lpt1 addr */
166 /*
167 * The kernel wants to read the base memory size
168 * from 40:13. Put a zero there to avoid an error message
169 */
170 writew(0, BIOS_DATA+0x13); /* base memory size */
171
wdenk8bde7f72003-06-27 21:31:46 +0000172
173 /* setup realmode interrupt vectors */
wdenk2262cfe2002-11-18 00:14:45 +0000174 for (vector = 0; vector < NUMVECTS; vector++) {
175 setvector(vector, BIOS_CS, &rm_def_int);
176 }
wdenk8bde7f72003-06-27 21:31:46 +0000177
wdenk2262cfe2002-11-18 00:14:45 +0000178 setvector(0x00, BIOS_CS, &rm_int00);
179 setvector(0x01, BIOS_CS, &rm_int01);
180 setvector(0x02, BIOS_CS, &rm_int02);
181 setvector(0x03, BIOS_CS, &rm_int03);
182 setvector(0x04, BIOS_CS, &rm_int04);
183 setvector(0x05, BIOS_CS, &rm_int05);
184 setvector(0x06, BIOS_CS, &rm_int06);
185 setvector(0x07, BIOS_CS, &rm_int07);
186 setvector(0x08, BIOS_CS, &rm_int08);
187 setvector(0x09, BIOS_CS, &rm_int09);
188 setvector(0x0a, BIOS_CS, &rm_int0a);
189 setvector(0x0b, BIOS_CS, &rm_int0b);
190 setvector(0x0c, BIOS_CS, &rm_int0c);
191 setvector(0x0d, BIOS_CS, &rm_int0d);
192 setvector(0x0e, BIOS_CS, &rm_int0e);
193 setvector(0x0f, BIOS_CS, &rm_int0f);
194 setvector(0x10, BIOS_CS, &rm_int10);
195 setvector(0x11, BIOS_CS, &rm_int11);
196 setvector(0x12, BIOS_CS, &rm_int12);
197 setvector(0x13, BIOS_CS, &rm_int13);
198 setvector(0x14, BIOS_CS, &rm_int14);
199 setvector(0x15, BIOS_CS, &rm_int15);
200 setvector(0x16, BIOS_CS, &rm_int16);
201 setvector(0x17, BIOS_CS, &rm_int17);
202 setvector(0x18, BIOS_CS, &rm_int18);
203 setvector(0x19, BIOS_CS, &rm_int19);
204 setvector(0x1a, BIOS_CS, &rm_int1a);
205 setvector(0x1b, BIOS_CS, &rm_int1b);
206 setvector(0x1c, BIOS_CS, &rm_int1c);
207 setvector(0x1d, BIOS_CS, &rm_int1d);
208 setvector(0x1e, BIOS_CS, &rm_int1e);
209 setvector(0x1f, BIOS_CS, &rm_int1f);
210
wdenk7a8e9bed2003-05-31 18:35:21 +0000211 set_jmp_vector(0xfff0, &realmode_reset);
212 set_jmp_vector(0xfe6e, &realmode_pci_bios_call_entry);
wdenk8bde7f72003-06-27 21:31:46 +0000213
wdenk2262cfe2002-11-18 00:14:45 +0000214 /* fill in data area */
wdenk7a8e9bed2003-05-31 18:35:21 +0000215 RELOC_16_WORD(0xf000, ram_in_64kb_chunks) = gd->ram_size >> 16;
216 RELOC_16_WORD(0xf000, bios_equipment) = 0; /* FixMe */
wdenk8bde7f72003-06-27 21:31:46 +0000217
wdenk7a8e9bed2003-05-31 18:35:21 +0000218 /* If we assume only one PCI hose, this PCI hose
wdenk8bde7f72003-06-27 21:31:46 +0000219 * will own PCI bus #0, and the last PCI bus of
220 * that PCI hose will be the last PCI bus in the
221 * system.
wdenk7a8e9bed2003-05-31 18:35:21 +0000222 * (This, ofcause break on multi hose systems,
wdenk8bde7f72003-06-27 21:31:46 +0000223 * but our PCI BIOS only support one hose anyway)
wdenk7a8e9bed2003-05-31 18:35:21 +0000224 */
225 pri_hose = pci_bus_to_hose(0);
226 if (NULL != pri_hose) {
wdenk8bde7f72003-06-27 21:31:46 +0000227 /* fill in last pci bus number for use by the realmode
wdenk7a8e9bed2003-05-31 18:35:21 +0000228 * PCI BIOS */
229 RELOC_16_BYTE(0xf000, pci_last_bus) = pri_hose->last_busno;
230 }
wdenk8bde7f72003-06-27 21:31:46 +0000231
wdenk2262cfe2002-11-18 00:14:45 +0000232 return 0;
233}