bios_setup.c 4.8 KB

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