bios_interrupts.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * From Coreboot
  3. *
  4. * Copyright (C) 2001 Ronald G. Minnich
  5. * Copyright (C) 2005 Nick.Barker9@btinternet.com
  6. * Copyright (C) 2007-2009 coresystems GmbH
  7. *
  8. * SPDX-License-Identifier: GPL-2.0
  9. */
  10. #include <common.h>
  11. #include <asm/pci.h>
  12. #include "bios_emul.h"
  13. /* errors go in AH. Just set these up so that word assigns will work */
  14. enum {
  15. PCIBIOS_SUCCESSFUL = 0x0000,
  16. PCIBIOS_UNSUPPORTED = 0x8100,
  17. PCIBIOS_BADVENDOR = 0x8300,
  18. PCIBIOS_NODEV = 0x8600,
  19. PCIBIOS_BADREG = 0x8700
  20. };
  21. int int10_handler(void)
  22. {
  23. static u8 cursor_row, cursor_col;
  24. int res = 0;
  25. switch ((M.x86.R_EAX & 0xff00) >> 8) {
  26. case 0x01: /* Set cursor shape */
  27. res = 1;
  28. break;
  29. case 0x02: /* Set cursor position */
  30. if (cursor_row != ((M.x86.R_EDX >> 8) & 0xff) ||
  31. cursor_col >= (M.x86.R_EDX & 0xff)) {
  32. debug("\n");
  33. }
  34. cursor_row = (M.x86.R_EDX >> 8) & 0xff;
  35. cursor_col = M.x86.R_EDX & 0xff;
  36. res = 1;
  37. break;
  38. case 0x03: /* Get cursor position */
  39. M.x86.R_EAX &= 0x00ff;
  40. M.x86.R_ECX = 0x0607;
  41. M.x86.R_EDX = (cursor_row << 8) | cursor_col;
  42. res = 1;
  43. break;
  44. case 0x06: /* Scroll up */
  45. debug("\n");
  46. res = 1;
  47. break;
  48. case 0x08: /* Get Character and Mode at Cursor Position */
  49. M.x86.R_EAX = 0x0f00 | 'A'; /* White on black 'A' */
  50. res = 1;
  51. break;
  52. case 0x09: /* Write Character and attribute */
  53. case 0x0e: /* Write Character */
  54. debug("%c", M.x86.R_EAX & 0xff);
  55. res = 1;
  56. break;
  57. case 0x0f: /* Get video mode */
  58. M.x86.R_EAX = 0x5002; /*80 x 25 */
  59. M.x86.R_EBX &= 0x00ff;
  60. res = 1;
  61. break;
  62. default:
  63. printf("Unknown INT10 function %04x\n", M.x86.R_EAX & 0xffff);
  64. break;
  65. }
  66. return res;
  67. }
  68. int int12_handler(void)
  69. {
  70. M.x86.R_EAX = 64 * 1024;
  71. return 1;
  72. }
  73. int int16_handler(void)
  74. {
  75. int res = 0;
  76. switch ((M.x86.R_EAX & 0xff00) >> 8) {
  77. case 0x00: /* Check for Keystroke */
  78. M.x86.R_EAX = 0x6120; /* Space Bar, Space */
  79. res = 1;
  80. break;
  81. case 0x01: /* Check for Keystroke */
  82. M.x86.R_EFLG |= 1 << 6; /* Zero Flag set (no key available) */
  83. res = 1;
  84. break;
  85. default:
  86. printf("Unknown INT16 function %04x\n", M.x86.R_EAX & 0xffff);
  87. break;
  88. }
  89. return res;
  90. }
  91. #define PCI_CONFIG_SPACE_TYPE1 (1 << 0)
  92. #define PCI_SPECIAL_CYCLE_TYPE1 (1 << 4)
  93. int int1a_handler(void)
  94. {
  95. unsigned short func = (unsigned short)M.x86.R_EAX;
  96. int retval = 1;
  97. unsigned short devid, vendorid, devfn;
  98. /* Use short to get rid of gabage in upper half of 32-bit register */
  99. short devindex;
  100. unsigned char bus;
  101. pci_dev_t dev;
  102. u32 dword;
  103. u16 word;
  104. u8 byte, reg;
  105. switch (func) {
  106. case 0xb101: /* PCIBIOS Check */
  107. M.x86.R_EDX = 0x20494350; /* ' ICP' */
  108. M.x86.R_EAX &= 0xffff0000; /* Clear AH / AL */
  109. M.x86.R_EAX |= PCI_CONFIG_SPACE_TYPE1 |
  110. PCI_SPECIAL_CYCLE_TYPE1;
  111. /*
  112. * last bus in the system. Hard code to 255 for now.
  113. * dev_enumerate() does not seem to tell us (publically)
  114. */
  115. M.x86.R_ECX = 0xff;
  116. M.x86.R_EDI = 0x00000000; /* protected mode entry */
  117. retval = 1;
  118. break;
  119. case 0xb102: /* Find Device */
  120. devid = M.x86.R_ECX;
  121. vendorid = M.x86.R_EDX;
  122. devindex = M.x86.R_ESI;
  123. dev = pci_find_device(vendorid, devid, devindex);
  124. if (dev != -1) {
  125. unsigned short busdevfn;
  126. M.x86.R_EAX &= 0xffff00ff; /* Clear AH */
  127. M.x86.R_EAX |= PCIBIOS_SUCCESSFUL;
  128. /*
  129. * busnum is an unsigned char;
  130. * devfn is an int, so we mask it off.
  131. */
  132. busdevfn = (PCI_BUS(dev) << 8) | PCI_DEV(dev) << 3 |
  133. PCI_FUNC(dev);
  134. debug("0x%x: return 0x%x\n", func, busdevfn);
  135. M.x86.R_EBX = busdevfn;
  136. retval = 1;
  137. } else {
  138. M.x86.R_EAX &= 0xffff00ff; /* Clear AH */
  139. M.x86.R_EAX |= PCIBIOS_NODEV;
  140. retval = 0;
  141. }
  142. break;
  143. case 0xb10a: /* Read Config Dword */
  144. case 0xb109: /* Read Config Word */
  145. case 0xb108: /* Read Config Byte */
  146. case 0xb10d: /* Write Config Dword */
  147. case 0xb10c: /* Write Config Word */
  148. case 0xb10b: /* Write Config Byte */
  149. devfn = M.x86.R_EBX & 0xff;
  150. bus = M.x86.R_EBX >> 8;
  151. reg = M.x86.R_EDI;
  152. dev = PCI_BDF(bus, devfn >> 3, devfn & 7);
  153. if (!dev) {
  154. debug("0x%x: BAD DEVICE bus %d devfn 0x%x\n", func,
  155. bus, devfn);
  156. /* Or are we supposed to return PCIBIOS_NODEV? */
  157. M.x86.R_EAX &= 0xffff00ff; /* Clear AH */
  158. M.x86.R_EAX |= PCIBIOS_BADREG;
  159. retval = 0;
  160. return retval;
  161. }
  162. switch (func) {
  163. case 0xb108: /* Read Config Byte */
  164. byte = pci_read_config8(dev, reg);
  165. M.x86.R_ECX = byte;
  166. break;
  167. case 0xb109: /* Read Config Word */
  168. word = pci_read_config16(dev, reg);
  169. M.x86.R_ECX = word;
  170. break;
  171. case 0xb10a: /* Read Config Dword */
  172. dword = pci_read_config32(dev, reg);
  173. M.x86.R_ECX = dword;
  174. break;
  175. case 0xb10b: /* Write Config Byte */
  176. byte = M.x86.R_ECX;
  177. pci_write_config8(dev, reg, byte);
  178. break;
  179. case 0xb10c: /* Write Config Word */
  180. word = M.x86.R_ECX;
  181. pci_write_config16(dev, reg, word);
  182. break;
  183. case 0xb10d: /* Write Config Dword */
  184. dword = M.x86.R_ECX;
  185. pci_write_config32(dev, reg, dword);
  186. break;
  187. }
  188. #ifdef CONFIG_REALMODE_DEBUG
  189. debug("0x%x: bus %d devfn 0x%x reg 0x%x val 0x%x\n", func,
  190. bus, devfn, reg, M.x86.R_ECX);
  191. #endif
  192. M.x86.R_EAX &= 0xffff00ff; /* Clear AH */
  193. M.x86.R_EAX |= PCIBIOS_SUCCESSFUL;
  194. retval = 1;
  195. break;
  196. default:
  197. printf("UNSUPPORTED PCIBIOS FUNCTION 0x%x\n", func);
  198. M.x86.R_EAX &= 0xffff00ff; /* Clear AH */
  199. M.x86.R_EAX |= PCIBIOS_UNSUPPORTED;
  200. retval = 0;
  201. break;
  202. }
  203. return retval;
  204. }