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

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

revision 14 by dpavlin, Mon Oct 8 16:18:51 2007 UTC revision 24 by dpavlin, Mon Oct 8 16:19:56 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-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_mp.c,v 1.28 2005/09/18 19:54:15 debug Exp $   *  $Id: dev_mp.c,v 1.36 2006/05/04 19:49:25 debug Exp $
29   *   *
30   *  This is a fake multiprocessor (MP) device. It can be useful for   *  This is a fake multiprocessor (MP) device. It can be useful for
31   *  theoretical experiments, but probably bares no resemblance to any   *  theoretical experiments, but probably bares no resemblance to any
# Line 42  Line 42 
42  #include "machine.h"  #include "machine.h"
43  #include "memory.h"  #include "memory.h"
44  #include "misc.h"  #include "misc.h"
45  #include "mp.h"  
46    #include "testmachine/dev_mp.h"
47    
48    
49  struct mp_data {  struct mp_data {
# Line 63  extern int single_step; Line 64  extern int single_step;
64  /*  /*
65   *  dev_mp_access():   *  dev_mp_access():
66   */   */
67  int dev_mp_access(struct cpu *cpu, struct memory *mem, uint64_t relative_addr,  DEVICE_ACCESS(mp)
         unsigned char *data, size_t len, int writeflag, void *extra)  
68  {  {
69          struct mp_data *d = extra;          struct mp_data *d = extra;
70          int i, which_cpu;          int i, which_cpu;
71          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
72    
73          idata = memory_readmax64(cpu, data, len);          if (writeflag == MEM_WRITE)
74                    idata = memory_readmax64(cpu, data, len);
75    
76          /*          /*
77           *  NOTE: It is up to the user of this device to read or write           *  NOTE: It is up to the user of this device to read or write
# Line 120  int dev_mp_access(struct cpu *cpu, struc Line 121  int dev_mp_access(struct cpu *cpu, struc
121                  break;                  break;
122    
123          case DEV_MP_PAUSE_CPU:          case DEV_MP_PAUSE_CPU:
124                  /*  Pause all cpus except our selves:  */                  /*  Pause all cpus except a specific CPU:  */
125                  which_cpu = idata;                  which_cpu = idata;
126    
127                  for (i=0; i<cpu->machine->ncpus; i++)                  for (i=0; i<cpu->machine->ncpus; i++)
128                          if (i!=which_cpu)                          if (i != which_cpu)
129                                  d->cpus[i]->running = 0;                                  d->cpus[i]->running = 0;
130                  break;                  break;
131    
132          case DEV_MP_UNPAUSE_CPU:          case DEV_MP_UNPAUSE_CPU:
133                  /*  Unpause all cpus except our selves:  */                  /*  Unpause a specific CPU:  */
134                  which_cpu = idata;                  which_cpu = idata;
135                  for (i=0; i<cpu->machine->ncpus; i++)  
136                          if (i!=which_cpu)                  if (which_cpu >= 0 && which_cpu <cpu->machine->ncpus)
137                                  d->cpus[i]->running = 1;                          d->cpus[which_cpu]->running = 1;
138                  break;                  break;
139    
140          case DEV_MP_STARTUPSTACK:          case DEV_MP_STARTUPSTACK:
# Line 143  int dev_mp_access(struct cpu *cpu, struc Line 144  int dev_mp_access(struct cpu *cpu, struc
144                  break;                  break;
145    
146          case DEV_MP_HARDWARE_RANDOM:          case DEV_MP_HARDWARE_RANDOM:
147                  /*  Return (up to) 64 bits of "hardware random":  */                  /*
148                     *  Return (up to) 64 bits of "hardware random":
149                     *
150                     *  NOTE: Remember that random() is (usually) 31 bits of
151                     *        random data, _NOT_ 32, hence this construction.
152                     */
153                  odata = random();                  odata = random();
154                  odata = (odata << 31) ^ random();                  odata = (odata << 31) ^ random();
155                  odata = (odata << 31) ^ random();                  odata = (odata << 31) ^ random();
# Line 242  int dev_mp_access(struct cpu *cpu, struc Line 248  int dev_mp_access(struct cpu *cpu, struc
248  }  }
249    
250    
251  /*  DEVINIT(mp)
  *  devinit_mp():  
  */  
 int devinit_mp(struct devinit *devinit)  
252  {  {
253          struct mp_data *d;          struct mp_data *d;
254          int n;          int n;
# Line 271  int devinit_mp(struct devinit *devinit) Line 274  int devinit_mp(struct devinit *devinit)
274          memset(d->ipi, 0, sizeof(int *) * n);          memset(d->ipi, 0, sizeof(int *) * n);
275    
276          memory_device_register(devinit->machine->memory, devinit->name,          memory_device_register(devinit->machine->memory, devinit->name,
277              devinit->addr, DEV_MP_LENGTH, dev_mp_access, d, MEM_DEFAULT, NULL);              devinit->addr, DEV_MP_LENGTH, dev_mp_access, d, DM_DEFAULT, NULL);
278    
279          return 1;          return 1;
280  }  }

Legend:
Removed from v.14  
changed lines
  Added in v.24

  ViewVC Help
Powered by ViewVC 1.1.26