bios_setup.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. * Partly based on msbios.c from rolo 1.6:
  25. *----------------------------------------------------------------------
  26. * (C) Copyright 2000
  27. * Sysgo Real-Time Solutions GmbH
  28. * Klein-Winternheim, Germany
  29. *----------------------------------------------------------------------
  30. */
  31. #include <common.h>
  32. #include <pci.h>
  33. #include <asm/realmode.h>
  34. #include <asm/io.h>
  35. DECLARE_GLOBAL_DATA_PTR;
  36. #define NUMVECTS 256
  37. #define BIOS_DATA ((char*)0x400)
  38. #define BIOS_DATA_SIZE 256
  39. #define BIOS_BASE ((char*)0xf0000)
  40. #define BIOS_CS 0xf000
  41. extern ulong __bios_start;
  42. extern ulong __bios_size;
  43. /* these are defined in a 16bit segment and needs
  44. * to be accessed with the RELOC_16_xxxx() macros below
  45. */
  46. extern u16 ram_in_64kb_chunks;
  47. extern u16 bios_equipment;
  48. extern u8 pci_last_bus;
  49. extern void *rm_int00;
  50. extern void *rm_int01;
  51. extern void *rm_int02;
  52. extern void *rm_int03;
  53. extern void *rm_int04;
  54. extern void *rm_int05;
  55. extern void *rm_int06;
  56. extern void *rm_int07;
  57. extern void *rm_int08;
  58. extern void *rm_int09;
  59. extern void *rm_int0a;
  60. extern void *rm_int0b;
  61. extern void *rm_int0c;
  62. extern void *rm_int0d;
  63. extern void *rm_int0e;
  64. extern void *rm_int0f;
  65. extern void *rm_int10;
  66. extern void *rm_int11;
  67. extern void *rm_int12;
  68. extern void *rm_int13;
  69. extern void *rm_int14;
  70. extern void *rm_int15;
  71. extern void *rm_int16;
  72. extern void *rm_int17;
  73. extern void *rm_int18;
  74. extern void *rm_int19;
  75. extern void *rm_int1a;
  76. extern void *rm_int1b;
  77. extern void *rm_int1c;
  78. extern void *rm_int1d;
  79. extern void *rm_int1e;
  80. extern void *rm_int1f;
  81. extern void *rm_def_int;
  82. extern void *realmode_reset;
  83. extern void *realmode_pci_bios_call_entry;
  84. static int set_jmp_vector(int entry_point, void *target)
  85. {
  86. if (entry_point & ~0xffff) {
  87. return -1;
  88. }
  89. if (((u32)target-0xf0000) & ~0xffff) {
  90. return -1;
  91. }
  92. printf("set_jmp_vector: 0xf000:%04x -> %p\n",
  93. entry_point, target);
  94. /* jmp opcode */
  95. writeb(0xea, 0xf0000 + entry_point);
  96. /* offset */
  97. writew(((u32)target-0xf0000), 0xf0000 + entry_point + 1);
  98. /* segment */
  99. writew(0xf000, 0xf0000 + entry_point + 3);
  100. return 0;
  101. }
  102. /*
  103. ************************************************************
  104. * Install an interrupt vector
  105. ************************************************************
  106. */
  107. static void setvector(int vector, u16 segment, void *handler)
  108. {
  109. u16 *ptr = (u16*)(vector*4);
  110. ptr[0] = ((u32)handler - (segment << 4))&0xffff;
  111. ptr[1] = segment;
  112. #if 0
  113. printf("setvector: int%02x -> %04x:%04x\n",
  114. vector, ptr[1], ptr[0]);
  115. #endif
  116. }
  117. #define RELOC_16_LONG(seg, off) *(u32*)(seg << 4 | (u32)&off)
  118. #define RELOC_16_WORD(seg, off) *(u16*)(seg << 4 | (u32)&off)
  119. #define RELOC_16_BYTE(seg, off) *(u8*)(seg << 4 | (u32)&off)
  120. int bios_setup(void)
  121. {
  122. ulong bios_start = (ulong)&__bios_start + gd->reloc_off;
  123. ulong bios_size = (ulong)&__bios_size;
  124. static int done=0;
  125. int vector;
  126. #ifdef CONFIG_PCI
  127. struct pci_controller *pri_hose;
  128. #endif
  129. if (done) {
  130. return 0;
  131. }
  132. done = 1;
  133. if (bios_size > 65536) {
  134. printf("BIOS too large (%ld bytes, max is 65536)\n",
  135. bios_size);
  136. return -1;
  137. }
  138. memcpy(BIOS_BASE, (void*)bios_start, bios_size);
  139. /* clear bda */
  140. memset(BIOS_DATA, 0, BIOS_DATA_SIZE);
  141. /* enter some values to the bda */
  142. writew(0x3f8, BIOS_DATA); /* com1 addr */
  143. writew(0x2f8, BIOS_DATA+2); /* com2 addr */
  144. writew(0x3e8, BIOS_DATA+4); /* com3 addr */
  145. writew(0x2e8, BIOS_DATA+6); /* com4 addr */
  146. writew(0x278, BIOS_DATA+8); /* lpt1 addr */
  147. /*
  148. * The kernel wants to read the base memory size
  149. * from 40:13. Put a zero there to avoid an error message
  150. */
  151. writew(0, BIOS_DATA+0x13); /* base memory size */
  152. /* setup realmode interrupt vectors */
  153. for (vector = 0; vector < NUMVECTS; vector++) {
  154. setvector(vector, BIOS_CS, &rm_def_int);
  155. }
  156. setvector(0x00, BIOS_CS, &rm_int00);
  157. setvector(0x01, BIOS_CS, &rm_int01);
  158. setvector(0x02, BIOS_CS, &rm_int02);
  159. setvector(0x03, BIOS_CS, &rm_int03);
  160. setvector(0x04, BIOS_CS, &rm_int04);
  161. setvector(0x05, BIOS_CS, &rm_int05);
  162. setvector(0x06, BIOS_CS, &rm_int06);
  163. setvector(0x07, BIOS_CS, &rm_int07);
  164. setvector(0x08, BIOS_CS, &rm_int08);
  165. setvector(0x09, BIOS_CS, &rm_int09);
  166. setvector(0x0a, BIOS_CS, &rm_int0a);
  167. setvector(0x0b, BIOS_CS, &rm_int0b);
  168. setvector(0x0c, BIOS_CS, &rm_int0c);
  169. setvector(0x0d, BIOS_CS, &rm_int0d);
  170. setvector(0x0e, BIOS_CS, &rm_int0e);
  171. setvector(0x0f, BIOS_CS, &rm_int0f);
  172. setvector(0x10, BIOS_CS, &rm_int10);
  173. setvector(0x11, BIOS_CS, &rm_int11);
  174. setvector(0x12, BIOS_CS, &rm_int12);
  175. setvector(0x13, BIOS_CS, &rm_int13);
  176. setvector(0x14, BIOS_CS, &rm_int14);
  177. setvector(0x15, BIOS_CS, &rm_int15);
  178. setvector(0x16, BIOS_CS, &rm_int16);
  179. setvector(0x17, BIOS_CS, &rm_int17);
  180. setvector(0x18, BIOS_CS, &rm_int18);
  181. setvector(0x19, BIOS_CS, &rm_int19);
  182. setvector(0x1a, BIOS_CS, &rm_int1a);
  183. setvector(0x1b, BIOS_CS, &rm_int1b);
  184. setvector(0x1c, BIOS_CS, &rm_int1c);
  185. setvector(0x1d, BIOS_CS, &rm_int1d);
  186. setvector(0x1e, BIOS_CS, &rm_int1e);
  187. setvector(0x1f, BIOS_CS, &rm_int1f);
  188. set_jmp_vector(0xfff0, &realmode_reset);
  189. set_jmp_vector(0xfe6e, &realmode_pci_bios_call_entry);
  190. /* fill in data area */
  191. RELOC_16_WORD(0xf000, ram_in_64kb_chunks) = gd->ram_size >> 16;
  192. RELOC_16_WORD(0xf000, bios_equipment) = 0; /* FixMe */
  193. /* If we assume only one PCI hose, this PCI hose
  194. * will own PCI bus #0, and the last PCI bus of
  195. * that PCI hose will be the last PCI bus in the
  196. * system.
  197. * (This, ofcause break on multi hose systems,
  198. * but our PCI BIOS only support one hose anyway)
  199. */
  200. #ifdef CONFIG_PCI
  201. pri_hose = pci_bus_to_hose(0);
  202. if (NULL != pri_hose) {
  203. /* fill in last pci bus number for use by the realmode
  204. * PCI BIOS */
  205. RELOC_16_BYTE(0xf000, pci_last_bus) = pri_hose->last_busno;
  206. }
  207. #endif
  208. return 0;
  209. }