2002-11-18 09:14:45 +09:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2002
|
2011-08-05 01:45:45 +09:00
|
|
|
* Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
|
2003-06-28 06:31:46 +09:00
|
|
|
*
|
2002-11-18 09:14:45 +09:00
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Partly based on msbios.c from rolo 1.6:
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
* (C) Copyright 2000
|
|
|
|
* Sysgo Real-Time Solutions GmbH
|
|
|
|
* Klein-Winternheim, Germany
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2003-06-01 03:35:21 +09:00
|
|
|
#include <pci.h>
|
2002-11-18 09:14:45 +09:00
|
|
|
#include <asm/realmode.h>
|
|
|
|
#include <asm/io.h>
|
2011-11-08 11:33:15 +09:00
|
|
|
#include "bios.h"
|
2002-11-18 09:14:45 +09:00
|
|
|
|
2006-04-01 01:32:53 +09:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2002-11-18 09:14:45 +09:00
|
|
|
#define NUMVECTS 256
|
|
|
|
|
2003-06-28 06:31:46 +09:00
|
|
|
static int set_jmp_vector(int entry_point, void *target)
|
2003-06-01 03:35:21 +09:00
|
|
|
{
|
2011-11-08 11:33:15 +09:00
|
|
|
if (entry_point & ~0xffff)
|
2003-06-01 03:35:21 +09:00
|
|
|
return -1;
|
2003-06-28 06:31:46 +09:00
|
|
|
|
2011-11-08 11:33:15 +09:00
|
|
|
if (((u32)target - 0xf0000) & ~0xffff)
|
2003-06-01 03:35:21 +09:00
|
|
|
return -1;
|
2011-11-08 11:33:15 +09:00
|
|
|
|
2003-06-01 03:35:21 +09:00
|
|
|
printf("set_jmp_vector: 0xf000:%04x -> %p\n",
|
2011-11-08 11:33:15 +09:00
|
|
|
entry_point, target);
|
2003-06-28 06:31:46 +09:00
|
|
|
|
2003-06-01 03:35:21 +09:00
|
|
|
/* jmp opcode */
|
|
|
|
writeb(0xea, 0xf0000 + entry_point);
|
2003-06-28 06:31:46 +09:00
|
|
|
|
2003-06-01 03:35:21 +09:00
|
|
|
/* offset */
|
|
|
|
writew(((u32)target-0xf0000), 0xf0000 + entry_point + 1);
|
2003-06-28 06:31:46 +09:00
|
|
|
|
2003-06-01 03:35:21 +09:00
|
|
|
/* segment */
|
|
|
|
writew(0xf000, 0xf0000 + entry_point + 3);
|
2003-06-28 06:31:46 +09:00
|
|
|
|
2003-06-01 03:35:21 +09:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-08 11:33:15 +09:00
|
|
|
/* Install an interrupt vector */
|
2002-11-18 09:14:45 +09:00
|
|
|
static void setvector(int vector, u16 segment, void *handler)
|
|
|
|
{
|
2011-11-08 11:33:15 +09:00
|
|
|
u16 *ptr = (u16 *)(vector * 4);
|
|
|
|
ptr[0] = ((u32)handler - (segment << 4)) & 0xffff;
|
2002-11-18 09:14:45 +09:00
|
|
|
ptr[1] = segment;
|
2003-06-28 06:31:46 +09:00
|
|
|
|
|
|
|
#if 0
|
2002-11-18 09:14:45 +09:00
|
|
|
printf("setvector: int%02x -> %04x:%04x\n",
|
2011-11-08 11:33:15 +09:00
|
|
|
vector, ptr[1], ptr[0]);
|
2003-06-28 06:31:46 +09:00
|
|
|
#endif
|
2002-11-18 09:14:45 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
int bios_setup(void)
|
|
|
|
{
|
x86: Fix how the location of the realmode and bios blobs are calculated
There are two blobs embedded into the u-boot image which are linked to run
at an address which is different from where they actually end up in the
ROM, one called "realmode" and one called "bios". There are realmode_setup
and bios_setup functions which prepare those blobs by copying them into the
location they're supposed to run from, among other things.
During u-boot relocation from ROM to RAM, the text and a few data segments
are copied over. The realmode and bios sections are not copied, and so the
only place they can be read from is their original location in the ROM.
Looking specifically at the bios blob, there are symbols defined in the
linker script called __bios_start and __bios_size which are defined to be
the start and size of the blob in the ROM.
In the bios_setup function, there seem to be two mistakes happening. First,
the offset from ROM to RAM is being added to __bios_start which implies that
this code expects to use the copy moved to RAM. No such copy is made, so
that's wrong. More subtly, when u-boot relocates itself, it goes through
all of the relocations stored in .rel.dyn and fixes them up. This has the
effect of transforming the __bios_start reference in bios_setup so that it
refers to the version in RAM (if one existed) instead of the one in ROM. To
correct for that, the offset actually needs to be subtracted out again to
translate the address back into the ROM.
The net effect is that for both blobs, a + needs to be changed to a -.
Signed-off-by: Gabe Black <gabeblack@chromium.org>
2011-11-13 01:31:18 +09:00
|
|
|
/*
|
|
|
|
* The BIOS section is not relocated and still in the ROM. The
|
|
|
|
* __bios_start symbol was adjusted, though, so adjust it back.
|
|
|
|
*/
|
|
|
|
ulong bios_start = (ulong)&__bios_start - gd->reloc_off;
|
2010-10-07 18:03:31 +09:00
|
|
|
ulong bios_size = (ulong)&__bios_size;
|
2009-11-24 18:04:20 +09:00
|
|
|
|
2011-11-08 11:33:15 +09:00
|
|
|
static int done;
|
2002-11-18 09:14:45 +09:00
|
|
|
int vector;
|
2008-09-07 06:08:42 +09:00
|
|
|
#ifdef CONFIG_PCI
|
2003-06-01 03:35:21 +09:00
|
|
|
struct pci_controller *pri_hose;
|
2008-09-07 06:08:42 +09:00
|
|
|
#endif
|
2011-11-08 11:33:15 +09:00
|
|
|
if (done)
|
2002-11-18 09:14:45 +09:00
|
|
|
return 0;
|
2011-11-08 11:33:15 +09:00
|
|
|
|
2002-11-18 09:14:45 +09:00
|
|
|
done = 1;
|
2003-06-28 06:31:46 +09:00
|
|
|
|
2010-10-07 18:03:31 +09:00
|
|
|
if (bios_size > 65536) {
|
2003-06-28 06:31:46 +09:00
|
|
|
printf("BIOS too large (%ld bytes, max is 65536)\n",
|
2011-11-08 11:33:15 +09:00
|
|
|
bios_size);
|
2002-11-18 09:14:45 +09:00
|
|
|
return -1;
|
|
|
|
}
|
2003-06-28 06:31:46 +09:00
|
|
|
|
2011-11-08 11:33:15 +09:00
|
|
|
memcpy(BIOS_BASE, (void *)bios_start, bios_size);
|
2002-11-18 09:14:45 +09:00
|
|
|
|
|
|
|
/* clear bda */
|
|
|
|
memset(BIOS_DATA, 0, BIOS_DATA_SIZE);
|
2003-06-28 06:31:46 +09:00
|
|
|
|
2002-11-18 09:14:45 +09:00
|
|
|
/* enter some values to the bda */
|
|
|
|
writew(0x3f8, BIOS_DATA); /* com1 addr */
|
|
|
|
writew(0x2f8, BIOS_DATA+2); /* com2 addr */
|
|
|
|
writew(0x3e8, BIOS_DATA+4); /* com3 addr */
|
|
|
|
writew(0x2e8, BIOS_DATA+6); /* com4 addr */
|
|
|
|
writew(0x278, BIOS_DATA+8); /* lpt1 addr */
|
|
|
|
/*
|
|
|
|
* The kernel wants to read the base memory size
|
|
|
|
* from 40:13. Put a zero there to avoid an error message
|
|
|
|
*/
|
|
|
|
writew(0, BIOS_DATA+0x13); /* base memory size */
|
|
|
|
|
2003-06-28 06:31:46 +09:00
|
|
|
|
|
|
|
/* setup realmode interrupt vectors */
|
2011-11-08 11:33:15 +09:00
|
|
|
for (vector = 0; vector < NUMVECTS; vector++)
|
2002-11-18 09:14:45 +09:00
|
|
|
setvector(vector, BIOS_CS, &rm_def_int);
|
2003-06-28 06:31:46 +09:00
|
|
|
|
2002-11-18 09:14:45 +09:00
|
|
|
setvector(0x00, BIOS_CS, &rm_int00);
|
|
|
|
setvector(0x01, BIOS_CS, &rm_int01);
|
|
|
|
setvector(0x02, BIOS_CS, &rm_int02);
|
|
|
|
setvector(0x03, BIOS_CS, &rm_int03);
|
|
|
|
setvector(0x04, BIOS_CS, &rm_int04);
|
|
|
|
setvector(0x05, BIOS_CS, &rm_int05);
|
|
|
|
setvector(0x06, BIOS_CS, &rm_int06);
|
|
|
|
setvector(0x07, BIOS_CS, &rm_int07);
|
|
|
|
setvector(0x08, BIOS_CS, &rm_int08);
|
|
|
|
setvector(0x09, BIOS_CS, &rm_int09);
|
|
|
|
setvector(0x0a, BIOS_CS, &rm_int0a);
|
|
|
|
setvector(0x0b, BIOS_CS, &rm_int0b);
|
|
|
|
setvector(0x0c, BIOS_CS, &rm_int0c);
|
|
|
|
setvector(0x0d, BIOS_CS, &rm_int0d);
|
|
|
|
setvector(0x0e, BIOS_CS, &rm_int0e);
|
|
|
|
setvector(0x0f, BIOS_CS, &rm_int0f);
|
|
|
|
setvector(0x10, BIOS_CS, &rm_int10);
|
|
|
|
setvector(0x11, BIOS_CS, &rm_int11);
|
|
|
|
setvector(0x12, BIOS_CS, &rm_int12);
|
|
|
|
setvector(0x13, BIOS_CS, &rm_int13);
|
|
|
|
setvector(0x14, BIOS_CS, &rm_int14);
|
|
|
|
setvector(0x15, BIOS_CS, &rm_int15);
|
|
|
|
setvector(0x16, BIOS_CS, &rm_int16);
|
|
|
|
setvector(0x17, BIOS_CS, &rm_int17);
|
|
|
|
setvector(0x18, BIOS_CS, &rm_int18);
|
|
|
|
setvector(0x19, BIOS_CS, &rm_int19);
|
|
|
|
setvector(0x1a, BIOS_CS, &rm_int1a);
|
|
|
|
setvector(0x1b, BIOS_CS, &rm_int1b);
|
|
|
|
setvector(0x1c, BIOS_CS, &rm_int1c);
|
|
|
|
setvector(0x1d, BIOS_CS, &rm_int1d);
|
|
|
|
setvector(0x1e, BIOS_CS, &rm_int1e);
|
|
|
|
setvector(0x1f, BIOS_CS, &rm_int1f);
|
|
|
|
|
2003-06-01 03:35:21 +09:00
|
|
|
set_jmp_vector(0xfff0, &realmode_reset);
|
|
|
|
set_jmp_vector(0xfe6e, &realmode_pci_bios_call_entry);
|
2003-06-28 06:31:46 +09:00
|
|
|
|
2002-11-18 09:14:45 +09:00
|
|
|
/* fill in data area */
|
2003-06-01 03:35:21 +09:00
|
|
|
RELOC_16_WORD(0xf000, ram_in_64kb_chunks) = gd->ram_size >> 16;
|
|
|
|
RELOC_16_WORD(0xf000, bios_equipment) = 0; /* FixMe */
|
2003-06-28 06:31:46 +09:00
|
|
|
|
2003-06-01 03:35:21 +09:00
|
|
|
/* If we assume only one PCI hose, this PCI hose
|
2003-06-28 06:31:46 +09:00
|
|
|
* will own PCI bus #0, and the last PCI bus of
|
|
|
|
* that PCI hose will be the last PCI bus in the
|
|
|
|
* system.
|
2003-06-01 03:35:21 +09:00
|
|
|
* (This, ofcause break on multi hose systems,
|
2003-06-28 06:31:46 +09:00
|
|
|
* but our PCI BIOS only support one hose anyway)
|
2003-06-01 03:35:21 +09:00
|
|
|
*/
|
2008-09-07 06:08:42 +09:00
|
|
|
#ifdef CONFIG_PCI
|
2003-06-01 03:35:21 +09:00
|
|
|
pri_hose = pci_bus_to_hose(0);
|
|
|
|
if (NULL != pri_hose) {
|
2003-06-28 06:31:46 +09:00
|
|
|
/* fill in last pci bus number for use by the realmode
|
2003-06-01 03:35:21 +09:00
|
|
|
* PCI BIOS */
|
|
|
|
RELOC_16_BYTE(0xf000, pci_last_bus) = pri_hose->last_busno;
|
|
|
|
}
|
2008-09-07 06:08:42 +09:00
|
|
|
#endif
|
2002-11-18 09:14:45 +09:00
|
|
|
return 0;
|
|
|
|
}
|