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

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

revision 4 by dpavlin, Mon Oct 8 16:18:00 2007 UTC revision 42 by dpavlin, Mon Oct 8 16:22:32 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2004-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2004-2007  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_sn.c,v 1.10 2005/03/14 19:14:02 debug Exp $   *  $Id: dev_sn.c,v 1.19 2007/06/15 19:57:34 debug Exp $
29   *     *  
30   *  National Semiconductor SONIC ("sn") DP83932 ethernet.   *  COMMENT: National Semiconductor SONIC ("sn") DP83932 ethernet controller
  *  
31   *   *
32   *  TODO   *  TODO
33   */   */
# Line 51  Line 50 
50  #define DEV_SN_LENGTH           0x1000  #define DEV_SN_LENGTH           0x1000
51    
52  struct sn_data {  struct sn_data {
53          int             irq_nr;          struct interrupt irq;
54          unsigned char   macaddr[6];          unsigned char   macaddr[6];
55          uint32_t        reg[SONIC_NREGS];          uint32_t        reg[SONIC_NREGS];
56  };  };
57    
58    
59  /*  DEVICE_ACCESS(sn)
  *  dev_sn_access():  
  */  
 int dev_sn_access(struct cpu *cpu, struct memory *mem,  
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
60  {  {
61          struct sn_data *d = (struct sn_data *) extra;          struct sn_data *d = extra;
62          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
63          int regnr;          int regnr;
64    
65          idata = memory_readmax64(cpu, data, len);          if (writeflag == MEM_WRITE)
66                    idata = memory_readmax64(cpu, data, len);
67    
68          regnr = relative_addr / sizeof(uint32_t);          regnr = relative_addr / sizeof(uint32_t);
69    
70          if (regnr < SONIC_NREGS) {          if (regnr < SONIC_NREGS) {
# Line 79  int dev_sn_access(struct cpu *cpu, struc Line 75  int dev_sn_access(struct cpu *cpu, struc
75          }          }
76    
77          switch (regnr) {          switch (regnr) {
78    
79          default:          default:
80                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
81                          fatal("[ sn: unimplemented write to address 0x%x"                          fatal("[ sn: unimplemented write to address 0x%x"
# Line 88  int dev_sn_access(struct cpu *cpu, struc Line 85  int dev_sn_access(struct cpu *cpu, struc
85                          fatal("[ sn: unimplemented read from address 0x%x "                          fatal("[ sn: unimplemented read from address 0x%x "
86                              "(regnr %i) ]\n", (int)relative_addr, regnr);                              "(regnr %i) ]\n", (int)relative_addr, regnr);
87                  }                  }
88                    /*  exit(1);  */
89          }          }
90    
91          if (writeflag == MEM_READ)          if (writeflag == MEM_READ)
# Line 97  int dev_sn_access(struct cpu *cpu, struc Line 95  int dev_sn_access(struct cpu *cpu, struc
95  }  }
96    
97    
98  /*  DEVINIT(sn)
  *  devinit_sn():  
  */  
 int devinit_sn(struct devinit *devinit)  
99  {  {
100          char *name2;          char *name2;
101          struct sn_data *d = malloc(sizeof(struct sn_data));          size_t nlen = 55;
102            struct sn_data *d;
103    
104          if (d == NULL) {          CHECK_ALLOCATION(d = malloc(sizeof(struct sn_data)));
                 fprintf(stderr, "out of memory\n");  
                 exit(1);  
         }  
105          memset(d, 0, sizeof(struct sn_data));          memset(d, 0, sizeof(struct sn_data));
106          d->irq_nr = devinit->irq_nr;  
107            INTERRUPT_CONNECT(devinit->interrupt_path, d->irq);
108    
109          net_generate_unique_mac(devinit->machine, d->macaddr);          net_generate_unique_mac(devinit->machine, d->macaddr);
110    
111          name2 = malloc(50);          CHECK_ALLOCATION(name2 = malloc(nlen));
112          if (name2 == NULL) {          snprintf(name2, nlen, "%s [%02x:%02x:%02x:%02x:%02x:%02x]",
113                  fprintf(stderr, "out of memory in dev_sn_init()\n");              devinit->name, d->macaddr[0], d->macaddr[1], d->macaddr[2],
                 exit(1);  
         }  
         sprintf(name2, "%s [%02x:%02x:%02x:%02x:%02x:%02x]",  
             devinit->name,  
             d->macaddr[0], d->macaddr[1], d->macaddr[2],  
114              d->macaddr[3], d->macaddr[4], d->macaddr[5]);              d->macaddr[3], d->macaddr[4], d->macaddr[5]);
115    
116          memory_device_register(devinit->machine->memory, name2,          memory_device_register(devinit->machine->memory, name2,
117              devinit->addr, DEV_SN_LENGTH,              devinit->addr, DEV_SN_LENGTH,
118              dev_sn_access, (void *)d, MEM_DEFAULT, NULL);              dev_sn_access, (void *)d, DM_DEFAULT, NULL);
119    
120          net_add_nic(devinit->machine->emul->net, d, d->macaddr);          net_add_nic(devinit->machine->emul->net, d, d->macaddr);
121    

Legend:
Removed from v.4  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26