1 /////////////////////////////////////////////////////////////////////////
2 // $Id: extfpuirq.cc 14163 2021-02-26 20:37:49Z vruppert $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 //  Copyright (C) 2002-2021  The Bochs Project
6 //
7 //  This library is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU Lesser General Public
9 //  License as published by the Free Software Foundation; either
10 //  version 2 of the License, or (at your option) any later version.
11 //
12 //  This library is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 //  Lesser General Public License for more details.
16 //
17 //  You should have received a copy of the GNU Lesser General Public
18 //  License along with this library; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20 
21 //
22 // External circuit for MSDOS compatible FPU exceptions
23 //
24 
25 // Define BX_PLUGGABLE in files that can be compiled into plugins.  For
26 // platforms that require a special tag on exported symbols, BX_PLUGGABLE
27 // is used to know when we are exporting symbols and when we are importing.
28 #define BX_PLUGGABLE
29 
30 #include "iodev.h"
31 #include "extfpuirq.h"
32 
33 #define LOG_THIS theExternalFpuIrq->
34 
35 bx_extfpuirq_c *theExternalFpuIrq = NULL;
36 
PLUGIN_ENTRY_FOR_MODULE(extfpuirq)37 PLUGIN_ENTRY_FOR_MODULE(extfpuirq)
38 {
39   if (mode == PLUGIN_INIT) {
40     theExternalFpuIrq = new bx_extfpuirq_c();
41     BX_REGISTER_DEVICE_DEVMODEL(plugin, type, theExternalFpuIrq, BX_PLUGIN_EXTFPUIRQ);
42   } else if (mode == PLUGIN_FINI) {
43     delete theExternalFpuIrq;
44   } else if (mode == PLUGIN_PROBE) {
45     return (int)PLUGTYPE_OPTIONAL;
46   }
47   return(0); // Success
48 }
49 
bx_extfpuirq_c(void)50 bx_extfpuirq_c::bx_extfpuirq_c(void)
51 {
52   put("extfpuirq", "EXFIRQ");
53 }
54 
~bx_extfpuirq_c(void)55 bx_extfpuirq_c::~bx_extfpuirq_c(void)
56 {
57   BX_DEBUG(("Exit"));
58 }
59 
init(void)60 void bx_extfpuirq_c::init(void)
61 {
62   // called once when bochs initializes
63   DEV_register_iowrite_handler(this, write_handler, 0x00F0, "External FPU IRQ", 1);
64   DEV_register_irq(13, "External FPU IRQ");
65 }
66 
reset(unsigned type)67 void bx_extfpuirq_c::reset(unsigned type)
68 {
69   // We should handle IGNNE here
70   DEV_pic_lower_irq(13);
71 }
72 
73 // static IO port write callback handler
74 // redirects to non-static class handler to avoid virtual functions
75 
write_handler(void * this_ptr,Bit32u address,Bit32u value,unsigned io_len)76 void bx_extfpuirq_c::write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len)
77 {
78 #if !BX_USE_EFI_SMF
79   bx_extfpuirq_c *class_ptr = (bx_extfpuirq_c *) this_ptr;
80   class_ptr->write(address, value, io_len);
81 }
82 
write(Bit32u address,Bit32u value,unsigned io_len)83 void bx_extfpuirq_c::write(Bit32u address, Bit32u value, unsigned io_len)
84 {
85 #else
86   UNUSED(this_ptr);
87 #endif // !BX_USE_EFI_SMF
88 
89   // We should handle IGNNE here
90   DEV_pic_lower_irq(13);
91 }
92