/[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 18 by dpavlin, Mon Oct 8 16:19:11 2007 UTC revision 28 by dpavlin, Mon Oct 8 16:20:26 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.29 2005/10/26 14:37:04 debug Exp $   *  $Id: dev_mp.c,v 1.37 2006/07/01 21:15:46 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;
# Line 121  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 144  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 224  int dev_mp_access(struct cpu *cpu, struc Line 229  int dev_mp_access(struct cpu *cpu, struc
229    
230          case DEV_MP_NCYCLES:          case DEV_MP_NCYCLES:
231                  /*                  /*
232                   *  Return approximately the number of cycles executed                   *  Return _approximately_ the number of cycles executed
233                   *  in this machine.  (This value is not updated for each                   *  in this machine.
234                   *  instruction.)                   *
235                     *  Note: At the moment, this is actually the number of
236                     *  instructions executed on CPU 0.
237                     *
238                     *  (This value is not updated for each instruction.)
239                   */                   */
240                  odata = cpu->machine->ncycles;                  odata = cpu->machine->ninstrs;
241                  break;                  break;
242    
243          default:          default:
# Line 243  int dev_mp_access(struct cpu *cpu, struc Line 252  int dev_mp_access(struct cpu *cpu, struc
252  }  }
253    
254    
255  /*  DEVINIT(mp)
  *  devinit_mp():  
  */  
 int devinit_mp(struct devinit *devinit)  
256  {  {
257          struct mp_data *d;          struct mp_data *d;
258          int n;          int n;
# Line 272  int devinit_mp(struct devinit *devinit) Line 278  int devinit_mp(struct devinit *devinit)
278          memset(d->ipi, 0, sizeof(int *) * n);          memset(d->ipi, 0, sizeof(int *) * n);
279    
280          memory_device_register(devinit->machine->memory, devinit->name,          memory_device_register(devinit->machine->memory, devinit->name,
281              devinit->addr, DEV_MP_LENGTH, dev_mp_access, d, MEM_DEFAULT, NULL);              devinit->addr, DEV_MP_LENGTH, dev_mp_access, d, DM_DEFAULT, NULL);
282    
283          return 1;          return 1;
284  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26