]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/jdb/ia32/jdb_io_ports.cpp
update
[l4.git] / kernel / fiasco / src / jdb / ia32 / jdb_io_ports.cpp
1 IMPLEMENTATION[ia32,amd64]:
2
3 #include <cstdio>
4 #include "simpleio.h"
5
6 #include "io.h"
7 #include "jdb_module.h"
8 #include "jdb.h"
9 #include "pci.h"
10 #include "pic.h"
11 #include "static_init.h"
12
13 /**
14  * Private IA32-I/O module.
15  */
16 class Io_m : public Jdb_module
17 {
18 public:
19   Io_m() FIASCO_INIT;
20
21 private:
22   static char porttype;
23
24   struct Port_io_buf {
25     unsigned adr;
26     unsigned val;
27   };
28
29   struct Pci_port_buf {
30     unsigned bus;
31     unsigned dev;
32     unsigned subdev;
33     unsigned reg;
34     unsigned val;
35   };
36   
37   struct Irq_buf {
38     unsigned irq;
39   };
40
41   union Input_buffer {
42     Port_io_buf io;
43     Pci_port_buf pci;
44     Irq_buf irq;
45   };
46
47   static Input_buffer buf;
48 };
49
50 static Io_m io_m INIT_PRIORITY(JDB_MODULE_INIT_PRIO);
51
52 char               Io_m::porttype;
53 Io_m::Input_buffer Io_m::buf;
54
55
56 PUBLIC
57 Jdb_module::Action_code
58 Io_m::action( int cmd, void *&args, char const *&fmt, int &)
59 {
60   static char const *const port_in_fmt    = " addr=%8p";
61   static char const *const port_out_fmt   = " addr=%8p, val=%8x";
62   static char const *const pci_in_fmt     = 
63     "\b\b\b\b\b\bPCI conf: bus=%2x, dev=%2x, subdev=%2x, reg=%2x";
64   static char const *const pci_out_fmt    = 
65     "\b\b\b\b\b\bPCI conf: bus=%2x, dev=%2x, subdev=%2x, reg=%2x, val=%8x";
66   static char const *const ack_irq_fmt    = " ack IRQ=%2x";
67   static char const *const mask_irq_fmt   = " mask IRQ=%2x";
68   static char const *const unmask_irq_fmt = " unmask IRQ=%2x";
69
70   unsigned answer = 0xffffffff;
71
72   if(args != &buf)
73     {
74       args = &buf;
75       if (cmd==0) // in
76         {
77           switch (porttype)
78             {
79             case '1':
80             case '2':
81             case '4': fmt = port_in_fmt;    return EXTRA_INPUT;
82             case 'p': fmt = pci_in_fmt;     return EXTRA_INPUT;
83             default:
84               puts(" - unknown port type (must be 1,2,4 or p)");
85               return NOTHING;
86             }
87         }
88       else // out
89         {
90           switch (porttype)
91             {
92             case '1':
93             case '2':
94             case '4': fmt = port_out_fmt;   return EXTRA_INPUT;
95             case 'p': fmt = pci_out_fmt;    return EXTRA_INPUT;
96             case 'a': fmt = ack_irq_fmt;    return EXTRA_INPUT;
97             case 'm': fmt = mask_irq_fmt;   return EXTRA_INPUT;
98             case 'u': fmt = unmask_irq_fmt; return EXTRA_INPUT;
99             default:
100               puts(" - unknown port type (must be 1,2,4,p,a,m or u)");
101               return NOTHING;
102             }
103         }
104     }
105   else
106     {
107       switch (porttype)
108         {
109         case '1': // in/out 8bit
110         case '2': // in/out 16bit
111         case '4': // in/out 32bit
112           if (buf.io.adr == 0xffffffff)
113             return NOTHING;
114           if(cmd==0) // in
115             putstr(" => ");
116           switch (porttype)
117             {
118             case '1':
119               if (cmd==0) // in
120                 {
121                   if (buf.io.adr == Pic::MASTER_OCW)
122                     printf("%02x (shadow of master-PIC register)\n",
123                         Jdb::pic_status & 0x0ff);
124                   else if (buf.io.adr == Pic::SLAVES_OCW)
125                     printf("%02x (shadow of slave-PIC register)\n",
126                         Jdb::pic_status >> 8);
127                   else
128                     {
129                       answer = Io::in8(buf.io.adr);
130                       printf("%02x\n", (int)answer);
131                     }
132                 }
133               else // out
134                 {
135                   if (buf.io.adr == Pic::MASTER_OCW)
136                     {
137                       Jdb::pic_status = 
138                         (Jdb::pic_status & 0xff00) | buf.io.val;
139                       putstr(" (PIC mask will be set on \"g\")");
140                     }
141                   else if (buf.io.adr == Pic::SLAVES_OCW)
142                     {
143                       Jdb::pic_status =
144                         (Jdb::pic_status & 0x00ff) | (buf.io.val<<8);
145                       putstr(" (PIC mask will be set on \"g\")");
146                     }
147                   else 
148                     Io::out8(buf.io.val, buf.io.adr );
149                 }
150               break;
151             case '2':
152               if(cmd==0) // in
153                 {
154                   answer = Io::in16(buf.io.adr);
155                   printf("%04x\n", answer);
156                 } 
157               else
158                 Io::out16(buf.io.val, buf.io.adr);
159               break;
160             case '4': 
161               if(cmd==0) // in
162                 {
163                   answer = Io::in32(buf.io.adr);
164                   printf("%08x\n", answer);
165                 }
166               else
167                 Io::out32(buf.io.val, buf.io.adr );
168               break;
169             }
170           if (cmd==1)
171             putchar('\n');
172           break;
173
174         case 'p': // pci
175           if (cmd == 0)
176             printf(" => 0x%08x",
177                    Pci::read_cfg(Pci::Cfg_addr(buf.pci.bus, buf.pci.dev, buf.pci.subdev,
178                                                buf.pci.reg), Pci::Cfg_width::Long));
179           else
180             Pci::write_cfg(Pci::Cfg_addr(buf.pci.bus, buf.pci.dev, buf.pci.subdev,
181                                          buf.pci.reg), (Unsigned32)buf.pci.val);
182           putchar('\n');
183           break;
184
185         case 'a': // manual acknowledge IRQ at pic
186           if (buf.irq.irq < 8)
187             Io::out8(0x60 + buf.irq.irq, Pic::MASTER_ICW);
188           else 
189             {
190               Io::out8(0x60 + (buf.irq.irq & 7), Pic::SLAVES_ICW);
191               Io::out8(0x60 + 2,                 Pic::MASTER_ICW);
192             }
193           putchar('\n');
194           break;
195
196         case 'm': // manual mask IRQ
197           Jdb::pic_status |= (1 << buf.irq.irq);
198           puts(" (PIC mask will be set on \"g\")");
199           break;
200
201         case 'u': // manual unmask IRQ
202           Jdb::pic_status  &= ~(Unsigned16)(1 << buf.irq.irq);
203           puts(" (PIC mask will be set on \"g\")");
204           break;
205         }
206     }
207   return NOTHING;
208 }
209
210 PUBLIC
211 int Io_m::num_cmds() const
212
213   return 2;
214 }
215
216 PUBLIC
217 Jdb_module::Cmd const * Io_m::cmds() const
218 {
219   static Cmd cs[] =
220     { 
221         { 0, "i", "in", " type:%c",
222           "i{1|2|4|p}<num>\tin port",
223           &porttype },
224         { 1, "o", "out", " type:%c",
225           "o{1|2|4|a|u|m}<num>\tout port, ack/(un)mask/ack irq",
226           &porttype },
227     };
228   return cs;
229 }
230
231 IMPLEMENT
232 Io_m::Io_m()
233   : Jdb_module("INFO")
234 {}
235