wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Daniel Engström, Omicron Ceti AB, daniel@omicron.se |
| 4 | * |
| 5 | * 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> |
| 35 | #include <asm/realmode.h> |
| 36 | #include <asm/io.h> |
| 37 | |
| 38 | #define NUMVECTS 256 |
| 39 | |
| 40 | #define BIOS_DATA ((char*)0x400) |
| 41 | #define BIOS_DATA_SIZE 256 |
| 42 | #define BIOS_BASE ((char*)0xf0000) |
| 43 | #define BIOS_CS 0xf000 |
| 44 | |
| 45 | extern u16 ram_in_64kb_chunks; |
| 46 | extern u16 bios_equipment; |
| 47 | extern void *rm_int00; |
| 48 | extern void *rm_int01; |
| 49 | extern void *rm_int02; |
| 50 | extern void *rm_int03; |
| 51 | extern void *rm_int04; |
| 52 | extern void *rm_int05; |
| 53 | extern void *rm_int06; |
| 54 | extern void *rm_int07; |
| 55 | extern void *rm_int08; |
| 56 | extern void *rm_int09; |
| 57 | extern void *rm_int0a; |
| 58 | extern void *rm_int0b; |
| 59 | extern void *rm_int0c; |
| 60 | extern void *rm_int0d; |
| 61 | extern void *rm_int0e; |
| 62 | extern void *rm_int0f; |
| 63 | extern void *rm_int10; |
| 64 | extern void *rm_int11; |
| 65 | extern void *rm_int12; |
| 66 | extern void *rm_int13; |
| 67 | extern void *rm_int14; |
| 68 | extern void *rm_int15; |
| 69 | extern void *rm_int16; |
| 70 | extern void *rm_int17; |
| 71 | extern void *rm_int18; |
| 72 | extern void *rm_int19; |
| 73 | extern void *rm_int1a; |
| 74 | extern void *rm_int1b; |
| 75 | extern void *rm_int1c; |
| 76 | extern void *rm_int1d; |
| 77 | extern void *rm_int1e; |
| 78 | extern void *rm_int1f; |
| 79 | extern void *rm_def_int; |
| 80 | |
| 81 | /* |
| 82 | ************************************************************ |
| 83 | * Install an interrupt vector |
| 84 | ************************************************************ |
| 85 | */ |
| 86 | |
| 87 | static void setvector(int vector, u16 segment, void *handler) |
| 88 | { |
| 89 | u16 *ptr = (u16*)(vector*4); |
| 90 | ptr[0] = ((u32)handler - (segment << 4))&0xffff; |
| 91 | ptr[1] = segment; |
| 92 | |
| 93 | #if 0 |
| 94 | printf("setvector: int%02x -> %04x:%04x\n", |
| 95 | vector, ptr[1], ptr[0]); |
| 96 | #endif |
| 97 | } |
| 98 | |
| 99 | int bios_setup(void) |
| 100 | { |
| 101 | DECLARE_GLOBAL_DATA_PTR; |
| 102 | static int done=0; |
| 103 | int vector; |
| 104 | |
| 105 | if (done) { |
| 106 | return 0; |
| 107 | } |
| 108 | done = 1; |
| 109 | |
| 110 | if (i386boot_bios_size > 65536) { |
| 111 | printf("BIOS too large (%ld bytes, max is 65536)\n", |
| 112 | i386boot_bios_size); |
| 113 | return -1; |
| 114 | } |
| 115 | |
| 116 | memcpy(BIOS_BASE, (void*)i386boot_bios, i386boot_bios_size); |
| 117 | |
| 118 | /* clear bda */ |
| 119 | memset(BIOS_DATA, 0, BIOS_DATA_SIZE); |
| 120 | |
| 121 | /* enter some values to the bda */ |
| 122 | writew(0x3f8, BIOS_DATA); /* com1 addr */ |
| 123 | writew(0x2f8, BIOS_DATA+2); /* com2 addr */ |
| 124 | writew(0x3e8, BIOS_DATA+4); /* com3 addr */ |
| 125 | writew(0x2e8, BIOS_DATA+6); /* com4 addr */ |
| 126 | writew(0x278, BIOS_DATA+8); /* lpt1 addr */ |
| 127 | /* |
| 128 | * The kernel wants to read the base memory size |
| 129 | * from 40:13. Put a zero there to avoid an error message |
| 130 | */ |
| 131 | writew(0, BIOS_DATA+0x13); /* base memory size */ |
| 132 | |
| 133 | |
| 134 | /* setup realmode interrupt vectors */ |
| 135 | for (vector = 0; vector < NUMVECTS; vector++) { |
| 136 | setvector(vector, BIOS_CS, &rm_def_int); |
| 137 | } |
| 138 | |
| 139 | setvector(0x00, BIOS_CS, &rm_int00); |
| 140 | setvector(0x01, BIOS_CS, &rm_int01); |
| 141 | setvector(0x02, BIOS_CS, &rm_int02); |
| 142 | setvector(0x03, BIOS_CS, &rm_int03); |
| 143 | setvector(0x04, BIOS_CS, &rm_int04); |
| 144 | setvector(0x05, BIOS_CS, &rm_int05); |
| 145 | setvector(0x06, BIOS_CS, &rm_int06); |
| 146 | setvector(0x07, BIOS_CS, &rm_int07); |
| 147 | setvector(0x08, BIOS_CS, &rm_int08); |
| 148 | setvector(0x09, BIOS_CS, &rm_int09); |
| 149 | setvector(0x0a, BIOS_CS, &rm_int0a); |
| 150 | setvector(0x0b, BIOS_CS, &rm_int0b); |
| 151 | setvector(0x0c, BIOS_CS, &rm_int0c); |
| 152 | setvector(0x0d, BIOS_CS, &rm_int0d); |
| 153 | setvector(0x0e, BIOS_CS, &rm_int0e); |
| 154 | setvector(0x0f, BIOS_CS, &rm_int0f); |
| 155 | setvector(0x10, BIOS_CS, &rm_int10); |
| 156 | setvector(0x11, BIOS_CS, &rm_int11); |
| 157 | setvector(0x12, BIOS_CS, &rm_int12); |
| 158 | setvector(0x13, BIOS_CS, &rm_int13); |
| 159 | setvector(0x14, BIOS_CS, &rm_int14); |
| 160 | setvector(0x15, BIOS_CS, &rm_int15); |
| 161 | setvector(0x16, BIOS_CS, &rm_int16); |
| 162 | setvector(0x17, BIOS_CS, &rm_int17); |
| 163 | setvector(0x18, BIOS_CS, &rm_int18); |
| 164 | setvector(0x19, BIOS_CS, &rm_int19); |
| 165 | setvector(0x1a, BIOS_CS, &rm_int1a); |
| 166 | setvector(0x1b, BIOS_CS, &rm_int1b); |
| 167 | setvector(0x1c, BIOS_CS, &rm_int1c); |
| 168 | setvector(0x1d, BIOS_CS, &rm_int1d); |
| 169 | setvector(0x1e, BIOS_CS, &rm_int1e); |
| 170 | setvector(0x1f, BIOS_CS, &rm_int1f); |
| 171 | |
| 172 | /* fill in data area */ |
| 173 | ram_in_64kb_chunks = gd->ram_size >> 16; |
| 174 | bios_equipment = 0; /* FixMe */ |
| 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |