besys.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. /****************************************************************************
  2. *
  3. * BIOS emulator and interface
  4. * to Realmode X86 Emulator Library
  5. *
  6. * ========================================================================
  7. *
  8. * Copyright (C) 2007 Freescale Semiconductor, Inc. All rights reserved.
  9. * Jason Jin<Jason.jin@freescale.com>
  10. *
  11. * Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.
  12. *
  13. * This file may be distributed and/or modified under the terms of the
  14. * GNU General Public License version 2.0 as published by the Free
  15. * Software Foundation and appearing in the file LICENSE.GPL included
  16. * in the packaging of this file.
  17. *
  18. * Licensees holding a valid Commercial License for this product from
  19. * SciTech Software, Inc. may use this file in accordance with the
  20. * Commercial License Agreement provided with the Software.
  21. *
  22. * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
  23. * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24. * PURPOSE.
  25. *
  26. * See http://www.scitechsoft.com/license/ for information about
  27. * the licensing options available and how to purchase a Commercial
  28. * License Agreement.
  29. *
  30. * Contact license@scitechsoft.com if any conditions of this licensing
  31. * are not clear to you, or you have questions about licensing options.
  32. *
  33. * ========================================================================
  34. *
  35. * Language: ANSI C
  36. * Environment: Any
  37. * Developer: Kendall Bennett
  38. *
  39. * Description: This file includes BIOS emulator I/O and memory access
  40. * functions.
  41. *
  42. * Jason ported this file to u-boot to run the ATI video card
  43. * BIOS in u-boot. Removed some emulate functions such as the
  44. * timer port access. Made all the VGA port except reading 0x3c3
  45. * be emulated. Seems like reading 0x3c3 should return the high
  46. * 16 bit of the io port.
  47. *
  48. ****************************************************************************/
  49. #include <common.h>
  50. #include "biosemui.h"
  51. /*------------------------- Global Variables ------------------------------*/
  52. #ifndef __i386__
  53. static char *BE_biosDate = "08/14/99";
  54. static u8 BE_model = 0xFC;
  55. static u8 BE_submodel = 0x00;
  56. #endif
  57. /*----------------------------- Implementation ----------------------------*/
  58. /****************************************************************************
  59. PARAMETERS:
  60. addr - Emulator memory address to convert
  61. RETURNS:
  62. Actual memory address to read or write the data
  63. REMARKS:
  64. This function converts an emulator memory address in a 32-bit range to
  65. a real memory address that we wish to access. It handles splitting up the
  66. memory address space appropriately to access the emulator BIOS image, video
  67. memory and system BIOS etc.
  68. ****************************************************************************/
  69. static u8 *BE_memaddr(u32 addr)
  70. {
  71. if (addr >= 0xC0000 && addr <= _BE_env.biosmem_limit) {
  72. return (u8*)(_BE_env.biosmem_base + addr - 0xC0000);
  73. } else if (addr > _BE_env.biosmem_limit && addr < 0xD0000) {
  74. DB(printf("BE_memaddr: address %#lx may be invalid!\n", addr);)
  75. return M.mem_base;
  76. } else if (addr >= 0xA0000 && addr <= 0xBFFFF) {
  77. return (u8*)(_BE_env.busmem_base + addr - 0xA0000);
  78. }
  79. #ifdef __i386__
  80. else if (addr >= 0xD0000 && addr <= 0xFFFFF) {
  81. /* We map the real System BIOS directly on real PC's */
  82. DB(printf("BE_memaddr: System BIOS address %#lx\n", addr);)
  83. return _BE_env.busmem_base + addr - 0xA0000;
  84. }
  85. #else
  86. else if (addr >= 0xFFFF5 && addr < 0xFFFFE) {
  87. /* Return a faked BIOS date string for non-x86 machines */
  88. DB(printf("BE_memaddr - Returning BIOS date\n");)
  89. return (u8 *)(BE_biosDate + addr - 0xFFFF5);
  90. } else if (addr == 0xFFFFE) {
  91. /* Return system model identifier for non-x86 machines */
  92. DB(printf("BE_memaddr - Returning model\n");)
  93. return &BE_model;
  94. } else if (addr == 0xFFFFF) {
  95. /* Return system submodel identifier for non-x86 machines */
  96. DB(printf("BE_memaddr - Returning submodel\n");)
  97. return &BE_submodel;
  98. }
  99. #endif
  100. else if (addr > M.mem_size - 1) {
  101. HALT_SYS();
  102. return M.mem_base;
  103. }
  104. return M.mem_base + addr;
  105. }
  106. /****************************************************************************
  107. PARAMETERS:
  108. addr - Emulator memory address to read
  109. RETURNS:
  110. Byte value read from emulator memory.
  111. REMARKS:
  112. Reads a byte value from the emulator memory. We have three distinct memory
  113. regions that are handled differently, which this function handles.
  114. ****************************************************************************/
  115. u8 X86API BE_rdb(u32 addr)
  116. {
  117. if (_BE_env.emulateVGA && addr >= 0xA0000 && addr <= 0xBFFFF)
  118. return 0;
  119. else {
  120. u8 val = readb_le(BE_memaddr(addr));
  121. return val;
  122. }
  123. }
  124. /****************************************************************************
  125. PARAMETERS:
  126. addr - Emulator memory address to read
  127. RETURNS:
  128. Word value read from emulator memory.
  129. REMARKS:
  130. Reads a word value from the emulator memory. We have three distinct memory
  131. regions that are handled differently, which this function handles.
  132. ****************************************************************************/
  133. u16 X86API BE_rdw(u32 addr)
  134. {
  135. if (_BE_env.emulateVGA && addr >= 0xA0000 && addr <= 0xBFFFF)
  136. return 0;
  137. else {
  138. u8 *base = BE_memaddr(addr);
  139. u16 val = readw_le(base);
  140. return val;
  141. }
  142. }
  143. /****************************************************************************
  144. PARAMETERS:
  145. addr - Emulator memory address to read
  146. RETURNS:
  147. Long value read from emulator memory.
  148. REMARKS:
  149. Reads a 32-bit value from the emulator memory. We have three distinct memory
  150. regions that are handled differently, which this function handles.
  151. ****************************************************************************/
  152. u32 X86API BE_rdl(u32 addr)
  153. {
  154. if (_BE_env.emulateVGA && addr >= 0xA0000 && addr <= 0xBFFFF)
  155. return 0;
  156. else {
  157. u8 *base = BE_memaddr(addr);
  158. u32 val = readl_le(base);
  159. return val;
  160. }
  161. }
  162. /****************************************************************************
  163. PARAMETERS:
  164. addr - Emulator memory address to read
  165. val - Value to store
  166. REMARKS:
  167. Writes a byte value to emulator memory. We have three distinct memory
  168. regions that are handled differently, which this function handles.
  169. ****************************************************************************/
  170. void X86API BE_wrb(u32 addr, u8 val)
  171. {
  172. if (!(_BE_env.emulateVGA && addr >= 0xA0000 && addr <= 0xBFFFF)) {
  173. writeb_le(BE_memaddr(addr), val);
  174. }
  175. }
  176. /****************************************************************************
  177. PARAMETERS:
  178. addr - Emulator memory address to read
  179. val - Value to store
  180. REMARKS:
  181. Writes a word value to emulator memory. We have three distinct memory
  182. regions that are handled differently, which this function handles.
  183. ****************************************************************************/
  184. void X86API BE_wrw(u32 addr, u16 val)
  185. {
  186. if (!(_BE_env.emulateVGA && addr >= 0xA0000 && addr <= 0xBFFFF)) {
  187. u8 *base = BE_memaddr(addr);
  188. writew_le(base, val);
  189. }
  190. }
  191. /****************************************************************************
  192. PARAMETERS:
  193. addr - Emulator memory address to read
  194. val - Value to store
  195. REMARKS:
  196. Writes a 32-bit value to emulator memory. We have three distinct memory
  197. regions that are handled differently, which this function handles.
  198. ****************************************************************************/
  199. void X86API BE_wrl(u32 addr, u32 val)
  200. {
  201. if (!(_BE_env.emulateVGA && addr >= 0xA0000 && addr <= 0xBFFFF)) {
  202. u8 *base = BE_memaddr(addr);
  203. writel_le(base, val);
  204. }
  205. }
  206. #if defined(DEBUG) || !defined(__i386__)
  207. /* For Non-Intel machines we may need to emulate some I/O port accesses that
  208. * the BIOS may try to access, such as the PCI config registers.
  209. */
  210. #define IS_TIMER_PORT(port) (0x40 <= port && port <= 0x43)
  211. #define IS_CMOS_PORT(port) (0x70 <= port && port <= 0x71)
  212. /*#define IS_VGA_PORT(port) (_BE_env.emulateVGA && 0x3C0 <= port && port <= 0x3DA)*/
  213. #define IS_VGA_PORT(port) (0x3C0 <= port && port <= 0x3DA)
  214. #define IS_PCI_PORT(port) (0xCF8 <= port && port <= 0xCFF)
  215. #define IS_SPKR_PORT(port) (port == 0x61)
  216. /****************************************************************************
  217. PARAMETERS:
  218. port - Port to read from
  219. type - Type of access to perform
  220. REMARKS:
  221. Performs an emulated read from the Standard VGA I/O ports. If the target
  222. hardware does not support mapping the VGA I/O and memory (such as some
  223. PowerPC systems), we emulate the VGA so that the BIOS will still be able to
  224. set NonVGA display modes such as on ATI hardware.
  225. ****************************************************************************/
  226. static u8 VGA_inpb (const int port)
  227. {
  228. u8 val = 0xff;
  229. switch (port) {
  230. case 0x3C0:
  231. /* 3C0 has funky characteristics because it can act as either
  232. a data register or index register depending on the state
  233. of an internal flip flop in the hardware. Hence we have
  234. to emulate that functionality in here. */
  235. if (_BE_env.flipFlop3C0 == 0) {
  236. /* Access 3C0 as index register */
  237. val = _BE_env.emu3C0;
  238. } else {
  239. /* Access 3C0 as data register */
  240. if (_BE_env.emu3C0 < ATT_C)
  241. val = _BE_env.emu3C1[_BE_env.emu3C0];
  242. }
  243. _BE_env.flipFlop3C0 ^= 1;
  244. break;
  245. case 0x3C1:
  246. if (_BE_env.emu3C0 < ATT_C)
  247. return _BE_env.emu3C1[_BE_env.emu3C0];
  248. break;
  249. case 0x3CC:
  250. return _BE_env.emu3C2;
  251. case 0x3C4:
  252. return _BE_env.emu3C4;
  253. case 0x3C5:
  254. if (_BE_env.emu3C4 < ATT_C)
  255. return _BE_env.emu3C5[_BE_env.emu3C4];
  256. break;
  257. case 0x3C6:
  258. return _BE_env.emu3C6;
  259. case 0x3C7:
  260. return _BE_env.emu3C7;
  261. case 0x3C8:
  262. return _BE_env.emu3C8;
  263. case 0x3C9:
  264. if (_BE_env.emu3C7 < PAL_C)
  265. return _BE_env.emu3C9[_BE_env.emu3C7++];
  266. break;
  267. case 0x3CE:
  268. return _BE_env.emu3CE;
  269. case 0x3CF:
  270. if (_BE_env.emu3CE < GRA_C)
  271. return _BE_env.emu3CF[_BE_env.emu3CE];
  272. break;
  273. case 0x3D4:
  274. if (_BE_env.emu3C2 & 0x1)
  275. return _BE_env.emu3D4;
  276. break;
  277. case 0x3D5:
  278. if ((_BE_env.emu3C2 & 0x1) && (_BE_env.emu3D4 < CRT_C))
  279. return _BE_env.emu3D5[_BE_env.emu3D4];
  280. break;
  281. case 0x3DA:
  282. _BE_env.flipFlop3C0 = 0;
  283. val = _BE_env.emu3DA;
  284. _BE_env.emu3DA ^= 0x9;
  285. break;
  286. }
  287. return val;
  288. }
  289. /****************************************************************************
  290. PARAMETERS:
  291. port - Port to write to
  292. type - Type of access to perform
  293. REMARKS:
  294. Performs an emulated write to one of the 8253 timer registers. For now
  295. we only emulate timer 0 which is the only timer that the BIOS code appears
  296. to use.
  297. ****************************************************************************/
  298. static void VGA_outpb (int port, u8 val)
  299. {
  300. switch (port) {
  301. case 0x3C0:
  302. /* 3C0 has funky characteristics because it can act as either
  303. a data register or index register depending on the state
  304. of an internal flip flop in the hardware. Hence we have
  305. to emulate that functionality in here. */
  306. if (_BE_env.flipFlop3C0 == 0) {
  307. /* Access 3C0 as index register */
  308. _BE_env.emu3C0 = val;
  309. } else {
  310. /* Access 3C0 as data register */
  311. if (_BE_env.emu3C0 < ATT_C)
  312. _BE_env.emu3C1[_BE_env.emu3C0] = val;
  313. }
  314. _BE_env.flipFlop3C0 ^= 1;
  315. break;
  316. case 0x3C2:
  317. _BE_env.emu3C2 = val;
  318. break;
  319. case 0x3C4:
  320. _BE_env.emu3C4 = val;
  321. break;
  322. case 0x3C5:
  323. if (_BE_env.emu3C4 < ATT_C)
  324. _BE_env.emu3C5[_BE_env.emu3C4] = val;
  325. break;
  326. case 0x3C6:
  327. _BE_env.emu3C6 = val;
  328. break;
  329. case 0x3C7:
  330. _BE_env.emu3C7 = (int) val *3;
  331. break;
  332. case 0x3C8:
  333. _BE_env.emu3C8 = (int) val *3;
  334. break;
  335. case 0x3C9:
  336. if (_BE_env.emu3C8 < PAL_C)
  337. _BE_env.emu3C9[_BE_env.emu3C8++] = val;
  338. break;
  339. case 0x3CE:
  340. _BE_env.emu3CE = val;
  341. break;
  342. case 0x3CF:
  343. if (_BE_env.emu3CE < GRA_C)
  344. _BE_env.emu3CF[_BE_env.emu3CE] = val;
  345. break;
  346. case 0x3D4:
  347. if (_BE_env.emu3C2 & 0x1)
  348. _BE_env.emu3D4 = val;
  349. break;
  350. case 0x3D5:
  351. if ((_BE_env.emu3C2 & 0x1) && (_BE_env.emu3D4 < CRT_C))
  352. _BE_env.emu3D5[_BE_env.emu3D4] = val;
  353. break;
  354. }
  355. }
  356. /****************************************************************************
  357. PARAMETERS:
  358. regOffset - Offset into register space for non-DWORD accesses
  359. value - Value to write to register for PCI_WRITE_* operations
  360. func - Function to perform (PCIAccessRegFlags)
  361. RETURNS:
  362. Value read from configuration register for PCI_READ_* operations
  363. REMARKS:
  364. Accesses a PCI configuration space register by decoding the value currently
  365. stored in the _BE_env.configAddress variable and passing it through to the
  366. portable PCI_accessReg function.
  367. ****************************************************************************/
  368. static u32 BE_accessReg(int regOffset, u32 value, int func)
  369. {
  370. #ifdef __KERNEL__
  371. int function, device, bus;
  372. u8 val8;
  373. u16 val16;
  374. u32 val32;
  375. /* Decode the configuration register values for the register we wish to
  376. * access
  377. */
  378. regOffset += (_BE_env.configAddress & 0xFF);
  379. function = (_BE_env.configAddress >> 8) & 0x7;
  380. device = (_BE_env.configAddress >> 11) & 0x1F;
  381. bus = (_BE_env.configAddress >> 16) & 0xFF;
  382. /* Ignore accesses to all devices other than the one we're POSTing */
  383. if ((function == _BE_env.vgaInfo.function) &&
  384. (device == _BE_env.vgaInfo.device) &&
  385. (bus == _BE_env.vgaInfo.bus)) {
  386. switch (func) {
  387. case REG_READ_BYTE:
  388. pci_read_config_byte(_BE_env.vgaInfo.pcidev, regOffset,
  389. &val8);
  390. return val8;
  391. case REG_READ_WORD:
  392. pci_read_config_word(_BE_env.vgaInfo.pcidev, regOffset,
  393. &val16);
  394. return val16;
  395. case REG_READ_DWORD:
  396. pci_read_config_dword(_BE_env.vgaInfo.pcidev, regOffset,
  397. &val32);
  398. return val32;
  399. case REG_WRITE_BYTE:
  400. pci_write_config_byte(_BE_env.vgaInfo.pcidev, regOffset,
  401. value);
  402. return 0;
  403. case REG_WRITE_WORD:
  404. pci_write_config_word(_BE_env.vgaInfo.pcidev, regOffset,
  405. value);
  406. return 0;
  407. case REG_WRITE_DWORD:
  408. pci_write_config_dword(_BE_env.vgaInfo.pcidev,
  409. regOffset, value);
  410. return 0;
  411. }
  412. }
  413. return 0;
  414. #else
  415. PCIDeviceInfo pciInfo;
  416. pciInfo.mech1 = 1;
  417. pciInfo.slot.i = 0;
  418. pciInfo.slot.p.Function = (_BE_env.configAddress >> 8) & 0x7;
  419. pciInfo.slot.p.Device = (_BE_env.configAddress >> 11) & 0x1F;
  420. pciInfo.slot.p.Bus = (_BE_env.configAddress >> 16) & 0xFF;
  421. pciInfo.slot.p.Enable = 1;
  422. /* Ignore accesses to all devices other than the one we're POSTing */
  423. if ((pciInfo.slot.p.Function ==
  424. _BE_env.vgaInfo.pciInfo->slot.p.Function)
  425. && (pciInfo.slot.p.Device == _BE_env.vgaInfo.pciInfo->slot.p.Device)
  426. && (pciInfo.slot.p.Bus == _BE_env.vgaInfo.pciInfo->slot.p.Bus))
  427. return PCI_accessReg((_BE_env.configAddress & 0xFF) + regOffset,
  428. value, func, &pciInfo);
  429. return 0;
  430. #endif
  431. }
  432. /****************************************************************************
  433. PARAMETERS:
  434. port - Port to read from
  435. type - Type of access to perform
  436. REMARKS:
  437. Performs an emulated read from one of the PCI configuration space registers.
  438. We emulate this using our PCI_accessReg function which will access the PCI
  439. configuration space registers in a portable fashion.
  440. ****************************************************************************/
  441. static u32 PCI_inp(int port, int type)
  442. {
  443. switch (type) {
  444. case REG_READ_BYTE:
  445. if ((_BE_env.configAddress & 0x80000000) && 0xCFC <= port
  446. && port <= 0xCFF)
  447. return BE_accessReg(port - 0xCFC, 0, REG_READ_BYTE);
  448. break;
  449. case REG_READ_WORD:
  450. if ((_BE_env.configAddress & 0x80000000) && 0xCFC <= port
  451. && port <= 0xCFF)
  452. return BE_accessReg(port - 0xCFC, 0, REG_READ_WORD);
  453. break;
  454. case REG_READ_DWORD:
  455. if (port == 0xCF8)
  456. return _BE_env.configAddress;
  457. else if ((_BE_env.configAddress & 0x80000000) && port == 0xCFC)
  458. return BE_accessReg(0, 0, REG_READ_DWORD);
  459. break;
  460. }
  461. return 0;
  462. }
  463. /****************************************************************************
  464. PARAMETERS:
  465. port - Port to write to
  466. type - Type of access to perform
  467. REMARKS:
  468. Performs an emulated write to one of the PCI control registers.
  469. ****************************************************************************/
  470. static void PCI_outp(int port, u32 val, int type)
  471. {
  472. switch (type) {
  473. case REG_WRITE_BYTE:
  474. if ((_BE_env.configAddress & 0x80000000) && 0xCFC <= port
  475. && port <= 0xCFF)
  476. BE_accessReg(port - 0xCFC, val, REG_WRITE_BYTE);
  477. break;
  478. case REG_WRITE_WORD:
  479. if ((_BE_env.configAddress & 0x80000000) && 0xCFC <= port
  480. && port <= 0xCFF)
  481. BE_accessReg(port - 0xCFC, val, REG_WRITE_WORD);
  482. break;
  483. case REG_WRITE_DWORD:
  484. if (port == 0xCF8)
  485. {
  486. _BE_env.configAddress = val & 0x80FFFFFC;
  487. }
  488. else if ((_BE_env.configAddress & 0x80000000) && port == 0xCFC)
  489. BE_accessReg(0, val, REG_WRITE_DWORD);
  490. break;
  491. }
  492. }
  493. #endif
  494. /****************************************************************************
  495. PARAMETERS:
  496. port - Port to write to
  497. RETURNS:
  498. Value read from the I/O port
  499. REMARKS:
  500. Performs an emulated 8-bit read from an I/O port. We handle special cases
  501. that we need to emulate in here, and fall through to reflecting the write
  502. through to the real hardware if we don't need to special case it.
  503. ****************************************************************************/
  504. u8 X86API BE_inb(X86EMU_pioAddr port)
  505. {
  506. u8 val = 0;
  507. #if defined(DEBUG) || !defined(__i386__)
  508. if (IS_VGA_PORT(port)){
  509. /*seems reading port 0x3c3 return the high 16 bit of io port*/
  510. if(port == 0x3c3)
  511. val = LOG_inpb(port);
  512. else
  513. val = VGA_inpb(port);
  514. }
  515. else if (IS_TIMER_PORT(port))
  516. DB(printf("Can not interept TIMER port now!\n");)
  517. else if (IS_SPKR_PORT(port))
  518. DB(printf("Can not interept SPEAKER port now!\n");)
  519. else if (IS_CMOS_PORT(port))
  520. DB(printf("Can not interept CMOS port now!\n");)
  521. else if (IS_PCI_PORT(port))
  522. val = PCI_inp(port, REG_READ_BYTE);
  523. else if (port < 0x100) {
  524. DB(printf("WARN: INVALID inb.%04X -> %02X\n", (u16) port, val);)
  525. val = LOG_inpb(port);
  526. } else
  527. #endif
  528. val = LOG_inpb(port);
  529. return val;
  530. }
  531. /****************************************************************************
  532. PARAMETERS:
  533. port - Port to write to
  534. RETURNS:
  535. Value read from the I/O port
  536. REMARKS:
  537. Performs an emulated 16-bit read from an I/O port. We handle special cases
  538. that we need to emulate in here, and fall through to reflecting the write
  539. through to the real hardware if we don't need to special case it.
  540. ****************************************************************************/
  541. u16 X86API BE_inw(X86EMU_pioAddr port)
  542. {
  543. u16 val = 0;
  544. #if defined(DEBUG) || !defined(__i386__)
  545. if (IS_PCI_PORT(port))
  546. val = PCI_inp(port, REG_READ_WORD);
  547. else if (port < 0x100) {
  548. DB(printf("WARN: Maybe INVALID inw.%04X -> %04X\n", (u16) port, val);)
  549. val = LOG_inpw(port);
  550. } else
  551. #endif
  552. val = LOG_inpw(port);
  553. return val;
  554. }
  555. /****************************************************************************
  556. PARAMETERS:
  557. port - Port to write to
  558. RETURNS:
  559. Value read from the I/O port
  560. REMARKS:
  561. Performs an emulated 32-bit read from an I/O port. We handle special cases
  562. that we need to emulate in here, and fall through to reflecting the write
  563. through to the real hardware if we don't need to special case it.
  564. ****************************************************************************/
  565. u32 X86API BE_inl(X86EMU_pioAddr port)
  566. {
  567. u32 val = 0;
  568. #if defined(DEBUG) || !defined(__i386__)
  569. if (IS_PCI_PORT(port))
  570. val = PCI_inp(port, REG_READ_DWORD);
  571. else if (port < 0x100) {
  572. val = LOG_inpd(port);
  573. } else
  574. #endif
  575. val = LOG_inpd(port);
  576. return val;
  577. }
  578. /****************************************************************************
  579. PARAMETERS:
  580. port - Port to write to
  581. val - Value to write to port
  582. REMARKS:
  583. Performs an emulated 8-bit write to an I/O port. We handle special cases
  584. that we need to emulate in here, and fall through to reflecting the write
  585. through to the real hardware if we don't need to special case it.
  586. ****************************************************************************/
  587. void X86API BE_outb(X86EMU_pioAddr port, u8 val)
  588. {
  589. #if defined(DEBUG) || !defined(__i386__)
  590. if (IS_VGA_PORT(port))
  591. VGA_outpb(port, val);
  592. else if (IS_TIMER_PORT(port))
  593. DB(printf("Can not interept TIMER port now!\n");)
  594. else if (IS_SPKR_PORT(port))
  595. DB(printf("Can not interept SPEAKER port now!\n");)
  596. else if (IS_CMOS_PORT(port))
  597. DB(printf("Can not interept CMOS port now!\n");)
  598. else if (IS_PCI_PORT(port))
  599. PCI_outp(port, val, REG_WRITE_BYTE);
  600. else if (port < 0x100) {
  601. DB(printf("WARN:Maybe INVALID outb.%04X <- %02X\n", (u16) port, val);)
  602. LOG_outpb(port, val);
  603. } else
  604. #endif
  605. LOG_outpb(port, val);
  606. }
  607. /****************************************************************************
  608. PARAMETERS:
  609. port - Port to write to
  610. val - Value to write to port
  611. REMARKS:
  612. Performs an emulated 16-bit write to an I/O port. We handle special cases
  613. that we need to emulate in here, and fall through to reflecting the write
  614. through to the real hardware if we don't need to special case it.
  615. ****************************************************************************/
  616. void X86API BE_outw(X86EMU_pioAddr port, u16 val)
  617. {
  618. #if defined(DEBUG) || !defined(__i386__)
  619. if (IS_VGA_PORT(port)) {
  620. VGA_outpb(port, val);
  621. VGA_outpb(port + 1, val >> 8);
  622. } else if (IS_PCI_PORT(port))
  623. PCI_outp(port, val, REG_WRITE_WORD);
  624. else if (port < 0x100) {
  625. DB(printf("WARN: MAybe INVALID outw.%04X <- %04X\n", (u16) port,
  626. val);)
  627. LOG_outpw(port, val);
  628. } else
  629. #endif
  630. LOG_outpw(port, val);
  631. }
  632. /****************************************************************************
  633. PARAMETERS:
  634. port - Port to write to
  635. val - Value to write to port
  636. REMARKS:
  637. Performs an emulated 32-bit write to an I/O port. We handle special cases
  638. that we need to emulate in here, and fall through to reflecting the write
  639. through to the real hardware if we don't need to special case it.
  640. ****************************************************************************/
  641. void X86API BE_outl(X86EMU_pioAddr port, u32 val)
  642. {
  643. #if defined(DEBUG) || !defined(__i386__)
  644. if (IS_PCI_PORT(port))
  645. PCI_outp(port, val, REG_WRITE_DWORD);
  646. else if (port < 0x100) {
  647. DB(printf("WARN: INVALID outl.%04X <- %08X\n", (u16) port,val);)
  648. LOG_outpd(port, val);
  649. } else
  650. #endif
  651. LOG_outpd(port, val);
  652. }