/[gxemul]/trunk/src/devices/dev_8250.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_8250.c

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

revision 20 by dpavlin, Mon Oct 8 16:19:23 2007 UTC revision 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2004-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2004-2006  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *   *
28   *  $Id: dev_8250.c,v 1.18 2005/11/13 00:14:08 debug Exp $   *  $Id: dev_8250.c,v 1.22 2006/02/18 13:42:39 debug Exp $
29   *     *  
30   *  8250 serial controller.   *  8250 serial controller.
31   *   *
# Line 45  Line 45 
45    
46    
47  struct dev_8250_data {  struct dev_8250_data {
         int             reg[8];  
   
48          int             console_handle;          int             console_handle;
49            char            *name;
50    
51          int             irq_enable;          int             irq_enable;
52          int             irqnr;          int             irqnr;
53            int             in_use;
54          int             addrmult;          int             addrmult;
55    
56            int             reg[8];
57    
58          int             dlab;           /*  Divisor Latch Access bit  */          int             dlab;           /*  Divisor Latch Access bit  */
59          int             divisor;          int             divisor;
60          int             databits;          int             databits;
# Line 61  struct dev_8250_data { Line 63  struct dev_8250_data {
63  };  };
64    
65  #define DEV_8250_LENGTH         8  #define DEV_8250_LENGTH         8
66    #define DEV_8250_TICKSHIFT      15
67    
68    
69  /*  /*
# Line 100  void dev_8250_tick(struct cpu *cpu, void Line 103  void dev_8250_tick(struct cpu *cpu, void
103  /*  /*
104   *  dev_8250_access():   *  dev_8250_access():
105   */   */
106  int dev_8250_access(struct cpu *cpu, struct memory *mem, uint64_t relative_addr,  DEVICE_ACCESS(8250)
         unsigned char *data, size_t len, int writeflag, void *extra)  
107  {  {
108          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
109          struct dev_8250_data *d = extra;          struct dev_8250_data *d = extra;
# Line 111  int dev_8250_access(struct cpu *cpu, str Line 113  int dev_8250_access(struct cpu *cpu, str
113    
114          relative_addr /= d->addrmult;          relative_addr /= d->addrmult;
115    
116          if (writeflag == MEM_WRITE && relative_addr == 0)          if (writeflag == MEM_WRITE && relative_addr == 0) {
117                  console_putchar(d->console_handle, idata);                  console_putchar(d->console_handle, idata);
118          else          } else if (writeflag == MEM_READ && relative_addr == 5) {
         if (writeflag == MEM_READ && relative_addr == 5)  
119                  odata = 64 + 32;                  odata = 64 + 32;
120          else {          } else {
121  #if 0  #if 0
122                  if (writeflag == MEM_WRITE)                  if (writeflag == MEM_WRITE)
123                          fatal("[ 8250: write addr=0x%02x idata = 0x%02x ]\n",                          fatal("[ 8250: write addr=0x%02x idata = 0x%02x ]\n",
# Line 133  int dev_8250_access(struct cpu *cpu, str Line 134  int dev_8250_access(struct cpu *cpu, str
134  }  }
135    
136    
137  /*  DEVINIT(8250)
  *  devinit_8250():  
  */  
 int devinit_8250(struct devinit *devinit)  
138  {  {
139            size_t nlen;
140            char *name;
141          struct dev_8250_data *d;          struct dev_8250_data *d;
142    
143          d = malloc(sizeof(struct dev_8250_data));          d = malloc(sizeof(struct dev_8250_data));
# Line 146  int devinit_8250(struct devinit *devinit Line 146  int devinit_8250(struct devinit *devinit
146                  exit(1);                  exit(1);
147          }          }
148          memset(d, 0, sizeof(struct dev_8250_data));          memset(d, 0, sizeof(struct dev_8250_data));
149          d->irqnr = devinit->irq_nr;          d->irqnr    = devinit->irq_nr;
150          d->addrmult = devinit->addr_mult;          d->addrmult = devinit->addr_mult;
151          d->console_handle = console_start_slave(devinit->machine, "console");          d->in_use   = devinit->in_use;
152          d->dlab = 0;          d->dlab     = 0;
153          d->divisor  = 115200 / 9600;          d->divisor  = 115200 / 9600;
154          d->databits = 8;          d->databits = 8;
155          d->parity   = 'N';          d->parity   = 'N';
156          d->stopbits = "1";          d->stopbits = "1";
157            d->name = devinit->name2 != NULL? devinit->name2 : "";
158            d->console_handle =
159                console_start_slave(devinit->machine, devinit->name2 != NULL?
160                devinit->name2 : devinit->name, d->in_use);
161    
162            nlen = strlen(devinit->name) + 10;
163            if (devinit->name2 != NULL)
164                    nlen += strlen(devinit->name2);
165            name = malloc(nlen);
166            if (name == NULL) {
167                    fprintf(stderr, "out of memory\n");
168                    exit(1);
169            }
170            if (devinit->name2 != NULL && devinit->name2[0])
171                    snprintf(name, nlen, "%s [%s]", devinit->name, devinit->name2);
172            else
173                    snprintf(name, nlen, "%s", devinit->name);
174    
175          memory_device_register(devinit->machine->memory, devinit->name,          memory_device_register(devinit->machine->memory, name,
176              devinit->addr, DEV_8250_LENGTH * devinit->addr_mult,              devinit->addr, DEV_8250_LENGTH * devinit->addr_mult,
177              dev_8250_access, d, DM_DEFAULT, NULL);              dev_8250_access, d, DM_DEFAULT, NULL);
178          machine_add_tickfunction(devinit->machine, dev_8250_tick, d, 14);          machine_add_tickfunction(devinit->machine, dev_8250_tick, d,
179                DEV_8250_TICKSHIFT);
180    
181          return 1;          return 1;
182  }  }

Legend:
Removed from v.20  
changed lines
  Added in v.22

  ViewVC Help
Powered by ViewVC 1.1.26