bios_interrupts.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. struct udevice *dev;
  99. /* Use short to get rid of gabage in upper half of 32-bit register */
  100. short devindex;
  101. unsigned char bus;
  102. pci_dev_t bdf;
  103. u32 dword;
  104. u16 word;
  105. u8 byte, reg;
  106. int ret;
  107. switch (func) {
  108. case 0xb101: /* PCIBIOS Check */
  109. M.x86.R_EDX = 0x20494350; /* ' ICP' */
  110. M.x86.R_EAX &= 0xffff0000; /* Clear AH / AL */
  111. M.x86.R_EAX |= PCI_CONFIG_SPACE_TYPE1 |
  112. PCI_SPECIAL_CYCLE_TYPE1;
  113. /*
  114. * last bus in the system. Hard code to 255 for now.
  115. * dev_enumerate() does not seem to tell us (publically)
  116. */
  117. M.x86.R_ECX = 0xff;
  118. M.x86.R_EDI = 0x00000000; /* protected mode entry */
  119. retval = 1;
  120. break;
  121. case 0xb102: /* Find Device */
  122. devid = M.x86.R_ECX;
  123. vendorid = M.x86.R_EDX;
  124. devindex = M.x86.R_ESI;
  125. bdf = -1;
  126. ret = dm_pci_find_device(vendorid, devid, devindex, &dev);
  127. if (!ret) {
  128. unsigned short busdevfn;
  129. bdf = dm_pci_get_bdf(dev);
  130. M.x86.R_EAX &= 0xffff00ff; /* Clear AH */
  131. M.x86.R_EAX |= PCIBIOS_SUCCESSFUL;
  132. /*
  133. * busnum is an unsigned char;
  134. * devfn is an int, so we mask it off.
  135. */
  136. busdevfn = (PCI_BUS(bdf) << 8) | PCI_DEV(bdf) << 3 |
  137. PCI_FUNC(bdf);
  138. debug("0x%x: return 0x%x\n", func, busdevfn);
  139. M.x86.R_EBX = busdevfn;
  140. retval = 1;
  141. } else {
  142. M.x86.R_EAX &= 0xffff00ff; /* Clear AH */
  143. M.x86.R_EAX |= PCIBIOS_NODEV;
  144. retval = 0;
  145. }
  146. break;
  147. case 0xb10a: /* Read Config Dword */
  148. case 0xb109: /* Read Config Word */
  149. case 0xb108: /* Read Config Byte */
  150. case 0xb10d: /* Write Config Dword */
  151. case 0xb10c: /* Write Config Word */
  152. case 0xb10b: /* Write Config Byte */
  153. devfn = M.x86.R_EBX & 0xff;
  154. bus = M.x86.R_EBX >> 8;
  155. reg = M.x86.R_EDI;
  156. bdf = PCI_BDF(bus, devfn >> 3, devfn & 7);
  157. ret = dm_pci_bus_find_bdf(bdf, &dev);
  158. if (ret) {
  159. debug("%s: Device %x not found\n", __func__, bdf);
  160. break;
  161. }
  162. switch (func) {
  163. case 0xb108: /* Read Config Byte */
  164. dm_pci_read_config8(dev, reg, &byte);
  165. M.x86.R_ECX = byte;
  166. break;
  167. case 0xb109: /* Read Config Word */
  168. dm_pci_read_config16(dev, reg, &word);
  169. M.x86.R_ECX = word;
  170. break;
  171. case 0xb10a: /* Read Config Dword */
  172. dm_pci_read_config32(dev, reg, &dword);
  173. M.x86.R_ECX = dword;
  174. break;
  175. case 0xb10b: /* Write Config Byte */
  176. byte = M.x86.R_ECX;
  177. dm_pci_write_config8(dev, reg, byte);
  178. break;
  179. case 0xb10c: /* Write Config Word */
  180. word = M.x86.R_ECX;
  181. dm_pci_write_config16(dev, reg, word);
  182. break;
  183. case 0xb10d: /* Write Config Dword */
  184. dword = M.x86.R_ECX;
  185. dm_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. }