/[gxemul]/trunk/src/devices/dev_ns16550.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/devices/dev_ns16550.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 12 by dpavlin, Mon Oct 8 16:18:38 2007 UTC revision 18 by dpavlin, Mon Oct 8 16:19:11 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *   *
28   *  $Id: dev_ns16550.c,v 1.40 2005/08/12 06:15:31 debug Exp $   *  $Id: dev_ns16550.c,v 1.42 2005/10/26 14:37:04 debug Exp $
29   *     *  
30   *  NS16550 serial controller.   *  NS16550 serial controller.
31   *   *
# Line 56  struct ns_data { Line 56  struct ns_data {
56          int             addrmult;          int             addrmult;
57          int             in_use;          int             in_use;
58          int             irqnr;          int             irqnr;
59            char            *name;
60          int             console_handle;          int             console_handle;
61          int             enable_fifo;          int             enable_fifo;
62    
# Line 113  int dev_ns16550_access(struct cpu *cpu, Line 114  int dev_ns16550_access(struct cpu *cpu,
114          int i;          int i;
115          struct ns_data *d = extra;          struct ns_data *d = extra;
116    
117          idata = memory_readmax64(cpu, data, len);          if (writeflag == MEM_WRITE)
118                    idata = memory_readmax64(cpu, data, len);
119    
120          /*  The NS16550 should be accessed using byte read/writes:  */          /*  The NS16550 should be accessed using byte read/writes:  */
121          if (len != 1)          if (len != 1)
122                  fatal("[ ns16550: len=%i, idata=0x%16llx! ]\n",                  fatal("[ ns16550 (%s): len=%i, idata=0x%16llx! ]\n",
123                      len, (long long)idata);                      d->name, len, (long long)idata);
124    
125          /*          /*
126           *  Always ready to transmit:           *  Always ready to transmit:
# Line 137  int dev_ns16550_access(struct cpu *cpu, Line 139  int dev_ns16550_access(struct cpu *cpu,
139          relative_addr /= d->addrmult;          relative_addr /= d->addrmult;
140    
141          if (relative_addr >= DEV_NS16550_LENGTH) {          if (relative_addr >= DEV_NS16550_LENGTH) {
142                  fatal("[ ns16550: outside register space? relative_addr="                  fatal("[ ns16550 (%s): outside register space? relative_addr="
143                      "0x%llx. bad addrmult? bad device length? ]\n",                      "0x%llx. bad addrmult? bad device length? ]\n", d->name,
144                      (long long)relative_addr);                      (long long)relative_addr);
145                  return 0;                  return 0;
146          }          }
# Line 178  int dev_ns16550_access(struct cpu *cpu, Line 180  int dev_ns16550_access(struct cpu *cpu,
180                          if (writeflag == MEM_WRITE) {                          if (writeflag == MEM_WRITE) {
181                                  /*  Set the high byte of the divisor:  */                                  /*  Set the high byte of the divisor:  */
182                                  d->divisor = (d->divisor & 0xff) | (idata << 8);                                  d->divisor = (d->divisor & 0xff) | (idata << 8);
183                                  debug("[ ns16550: speed set to %i bps ]\n",                                  debug("[ ns16550 (%s): speed set to %i bps ]\n",
184                                      (int)(115200 / d->divisor));                                      d->name, (int)(115200 / d->divisor));
185                          } else                          } else
186                                  odata = d->divisor >> 8;                                  odata = d->divisor >> 8;
187                          break;                          break;
# Line 189  int dev_ns16550_access(struct cpu *cpu, Line 191  int dev_ns16550_access(struct cpu *cpu,
191                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
192                          /*  This is to supress Linux' behaviour  */                          /*  This is to supress Linux' behaviour  */
193                          if (idata != 0)                          if (idata != 0)
194                                  debug("[ ns16550: write to ier: 0x%02x ]\n",                                  debug("[ ns16550 (%s): write to ier: 0x%02x ]"
195                                      (int)idata);                                      "\n", d->name, (int)idata);
196    
197                          /*  Needed for NetBSD 2.0.x, but not 1.6.2?  */                          /*  Needed for NetBSD 2.0.x, but not 1.6.2?  */
198                          if (!(d->reg[com_ier] & IER_ETXRDY)                          if (!(d->reg[com_ier] & IER_ETXRDY)
# Line 205  int dev_ns16550_access(struct cpu *cpu, Line 207  int dev_ns16550_access(struct cpu *cpu,
207    
208          case com_iir:   /*  interrupt identification (r), fifo control (w)  */          case com_iir:   /*  interrupt identification (r), fifo control (w)  */
209                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
210                          debug("[ ns16550: write to fifo control: 0x%02x ]\n",                          debug("[ ns16550 (%s): write to fifo control: 0x%02x ]"
211                              (int)idata);                              "\n", d->name, (int)idata);
212                          d->fcr = idata;                          d->fcr = idata;
213                  } else {                  } else {
214                          odata = d->reg[com_iir];                          odata = d->reg[com_iir];
215                          debug("[ ns16550: read from iir: 0x%02x ]\n",                          debug("[ ns16550 (%s): read from iir: 0x%02x ]\n",
216                              (int)odata);                              d->name, (int)odata);
217                          dev_ns16550_tick(cpu, d);                          dev_ns16550_tick(cpu, d);
218                  }                  }
219                  break;                  break;
220    
221          case com_lsr:          case com_lsr:
222                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
223                          debug("[ ns16550: write to lsr: 0x%02x ]\n",                          debug("[ ns16550 (%s): write to lsr: 0x%02x ]\n",
224                              (int)idata);                              d->name, (int)idata);
225                          d->reg[com_lsr] = idata;                          d->reg[com_lsr] = idata;
226                  } else {                  } else {
227                          odata = d->reg[com_lsr];                          odata = d->reg[com_lsr];
228                          /*  debug("[ ns16550: read from lsr: 0x%02x ]\n",                          /*  debug("[ ns16550 (%s): read from lsr: 0x%02x ]\n",
229                              (int)odata);  */                              d->name, (int)odata);  */
230                  }                  }
231                  break;                  break;
232    
233          case com_msr:          case com_msr:
234                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
235                          debug("[ ns16550: write to msr: 0x%02x ]\n",                          debug("[ ns16550 (%s): write to msr: 0x%02x ]\n",
236                              (int)idata);                              d->name, (int)idata);
237                          d->reg[com_msr] = idata;                          d->reg[com_msr] = idata;
238                  } else {                  } else {
239                          odata = d->reg[com_msr];                          odata = d->reg[com_msr];
240                          debug("[ ns16550: read from msr: 0x%02x ]\n",                          debug("[ ns16550 (%s): read from msr: 0x%02x ]\n",
241                              (int)odata);                              d->name, (int)odata);
242                  }                  }
243                  break;                  break;
244    
# Line 266  int dev_ns16550_access(struct cpu *cpu, Line 268  int dev_ns16550_access(struct cpu *cpu,
268    
269                          d->dlab = idata & 0x80? 1 : 0;                          d->dlab = idata & 0x80? 1 : 0;
270    
271                          debug("[ ns16550: write to lctl: 0x%02x (%s%s"                          debug("[ ns16550 (%s): write to lctl: 0x%02x (%s%s"
272                              "setting mode %i%c%s) ]\n",                              "setting mode %i%c%s) ]\n", d->name, (int)idata,
                             (int)idata,  
273                              d->dlab? "Divisor Latch access, " : "",                              d->dlab? "Divisor Latch access, " : "",
274                              idata&0x40? "sending BREAK, " : "",                              idata&0x40? "sending BREAK, " : "",
275                              d->databits, d->parity, d->stopbits);                              d->databits, d->parity, d->stopbits);
276                  } else {                  } else {
277                          odata = d->reg[com_lctl];                          odata = d->reg[com_lctl];
278                          debug("[ ns16550: read from lctl: 0x%02x ]\n",                          debug("[ ns16550 (%s): read from lctl: 0x%02x ]\n",
279                              (int)odata);                              d->name, (int)odata);
280                  }                  }
281                  break;                  break;
282    
283          case com_mcr:          case com_mcr:
284                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
285                          d->reg[com_mcr] = idata;                          d->reg[com_mcr] = idata;
286                          debug("[ ns16550: write to mcr: 0x%02x ]\n",                          debug("[ ns16550 (%s): write to mcr: 0x%02x ]\n",
287                              (int)idata);                              d->name, (int)idata);
288                  } else {                  } else {
289                          odata = d->reg[com_mcr];                          odata = d->reg[com_mcr];
290                          debug("[ ns16550: read from mcr: 0x%02x ]\n",                          debug("[ ns16550 (%s): read from mcr: 0x%02x ]\n",
291                              (int)odata);                              d->name, (int)odata);
292                  }                  }
293                  break;                  break;
294    
295          default:          default:
296                  if (writeflag==MEM_READ) {                  if (writeflag==MEM_READ) {
297                          debug("[ ns16550: read from reg %i ]\n",                          debug("[ ns16550 (%s): read from reg %i ]\n",
298                              (int)relative_addr);                              d->name, (int)relative_addr);
299                          odata = d->reg[relative_addr];                          odata = d->reg[relative_addr];
300                  } else {                  } else {
301                          debug("[ ns16550: write to reg %i:",                          debug("[ ns16550 (%s): write to reg %i:",
302                              (int)relative_addr);                              d->name, (int)relative_addr);
303                          for (i=0; i<len; i++)                          for (i=0; i<len; i++)
304                                  debug(" %02x", data[i]);                                  debug(" %02x", data[i]);
305                          debug(" ]\n");                          debug(" ]\n");
# Line 327  int devinit_ns16550(struct devinit *devi Line 328  int devinit_ns16550(struct devinit *devi
328                  exit(1);                  exit(1);
329          }          }
330          memset(d, 0, sizeof(struct ns_data));          memset(d, 0, sizeof(struct ns_data));
331          d->irqnr        = devinit->irq_nr;          d->irqnr        = devinit->irq_nr;
332          d->addrmult     = devinit->addr_mult;          d->addrmult     = devinit->addr_mult;
333          d->in_use       = devinit->in_use;          d->in_use       = devinit->in_use;
334          d->enable_fifo  = 1;          d->enable_fifo  = 1;
335          d->dlab         = 0;          d->dlab         = 0;
336          d->divisor      = 115200 / 9600;          d->divisor      = 115200 / 9600;
337          d->databits     = 8;          d->databits     = 8;
338          d->parity       = 'N';          d->parity       = 'N';
339          d->stopbits     = "1";          d->stopbits     = "1";
340            d->name         = devinit->name2 != NULL? devinit->name2 : "";
341          d->console_handle =          d->console_handle =
342              console_start_slave(devinit->machine, devinit->name);              console_start_slave(devinit->machine, devinit->name);
343    

Legend:
Removed from v.12  
changed lines
  Added in v.18

  ViewVC Help
Powered by ViewVC 1.1.26