/[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 4 by dpavlin, Mon Oct 8 16:18:00 2007 UTC revision 14 by dpavlin, Mon Oct 8 16:18:51 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *   *
28   *  $Id: dev_mp.c,v 1.25 2005/02/25 06:27:48 debug Exp $   *  $Id: dev_mp.c,v 1.28 2005/09/18 19:54:15 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 50  struct mp_data { Line 50  struct mp_data {
50          uint64_t        startup_addr;          uint64_t        startup_addr;
51          uint64_t        stack_addr;          uint64_t        stack_addr;
52          uint64_t        pause_addr;          uint64_t        pause_addr;
53    
54            /*  Each CPU has an array of pending ipis.  */
55            int             *n_pending_ipis;
56            int             **ipi;
57  };  };
58    
59    
60    extern int single_step;
61    
62    
63  /*  /*
64   *  dev_mp_access():   *  dev_mp_access():
65   */   */
# Line 153  int dev_mp_access(struct cpu *cpu, struc Line 160  int dev_mp_access(struct cpu *cpu, struc
160                  odata = cpu->machine->physical_ram_in_mb * 1048576;                  odata = cpu->machine->physical_ram_in_mb * 1048576;
161                  break;                  break;
162    
163            case DEV_MP_IPI_ONE:
164            case DEV_MP_IPI_MANY:
165                    /*
166                     *  idata should be of the form:
167                     *
168                     *              (IPI_nr << 16) | cpu_id
169                     *
170                     *  This will send an Inter-processor interrupt to a specific
171                     *  CPU. (DEV_MP_IPI_MANY sends to all _except_ the specific
172                     *  CPU.)
173                     *
174                     *  Sending an IPI means adding the IPI last in the list of
175                     *  pending IPIs, and asserting the IPI "pin".
176                     */
177                    which_cpu = (idata & 0xffff);
178                    for (i=0; i<cpu->machine->ncpus; i++) {
179                            int send_it = 0;
180                            if (relative_addr == DEV_MP_IPI_ONE && i == which_cpu)
181                                    send_it = 1;
182                            if (relative_addr == DEV_MP_IPI_MANY && i != which_cpu)
183                                    send_it = 1;
184                            if (send_it) {
185                                    d->n_pending_ipis[i] ++;
186                                    d->ipi[i] = realloc(d->ipi[i],
187                                        d->n_pending_ipis[i] * sizeof(int));
188                                    if (d->ipi[i] == NULL) {
189                                            fprintf(stderr, "out of memory\n");
190                                            exit(1);
191                                    }
192                                    /*  Add the IPI last in the array:  */
193                                    d->ipi[i][d->n_pending_ipis[i] - 1] =
194                                        idata >> 16;
195                                    cpu_interrupt(d->cpus[i], MIPS_IPI_INT);
196                            }
197                    }
198                    break;
199    
200            case DEV_MP_IPI_READ:
201                    /*
202                     *  If the current CPU has any IPIs pending, accessing this
203                     *  address reads the IPI value. (Writing to this address
204                     *  discards _all_ pending IPIs.)  If there is no pending
205                     *  IPI, then 0 is returned. Usage of the value 0 for real
206                     *  IPIs should thus be avoided.
207                     */
208                    if (writeflag == MEM_WRITE) {
209                            d->n_pending_ipis[cpu->cpu_id] = 0;
210                    }
211                    odata = 0;
212                    if (d->n_pending_ipis[cpu->cpu_id] > 0) {
213                            odata = d->ipi[cpu->cpu_id][0];
214                            if (d->n_pending_ipis[cpu->cpu_id]-- > 1)
215                                    memmove(&d->ipi[cpu->cpu_id][0],
216                                        &d->ipi[cpu->cpu_id][1],
217                                        d->n_pending_ipis[cpu->cpu_id]);
218                    }
219                    /*  Deassert the interrupt, if there are no pending IPIs:  */
220                    if (d->n_pending_ipis[cpu->cpu_id] == 0)
221                            cpu_interrupt_ack(d->cpus[cpu->cpu_id], MIPS_IPI_INT);
222                    break;
223    
224            case DEV_MP_NCYCLES:
225                    /*
226                     *  Return approximately the number of cycles executed
227                     *  in this machine.  (This value is not updated for each
228                     *  instruction.)
229                     */
230                    odata = cpu->machine->ncycles;
231                    break;
232    
233          default:          default:
234                  fatal("[ dev_mp: unimplemented relative addr 0x%x ]\n",                  fatal("[ dev_mp: unimplemented relative addr 0x%x ]\n",
235                      relative_addr);                      relative_addr);
# Line 171  int dev_mp_access(struct cpu *cpu, struc Line 248  int dev_mp_access(struct cpu *cpu, struc
248  int devinit_mp(struct devinit *devinit)  int devinit_mp(struct devinit *devinit)
249  {  {
250          struct mp_data *d;          struct mp_data *d;
251            int n;
252    
253          d = malloc(sizeof(struct mp_data));          d = malloc(sizeof(struct mp_data));
254          if (d == NULL) {          if (d == NULL) {
255                  fprintf(stderr, "out of memory\n");                  fprintf(stderr, "out of memory\n");
# Line 181  int devinit_mp(struct devinit *devinit) Line 260  int devinit_mp(struct devinit *devinit)
260          d->startup_addr = INITIAL_PC;          d->startup_addr = INITIAL_PC;
261          d->stack_addr = INITIAL_STACK_POINTER;          d->stack_addr = INITIAL_STACK_POINTER;
262    
263          memory_device_register(devinit->machine->memory,          n = devinit->machine->ncpus;
264              devinit->name, devinit->addr, DEV_MP_LENGTH,          d->n_pending_ipis = malloc(n * sizeof(int));
265              dev_mp_access, d, MEM_DEFAULT, NULL);          d->ipi = malloc(n * sizeof(int *));
266            if (d->ipi == NULL || d->n_pending_ipis == NULL) {
267                    fprintf(stderr, "out of memory\n");
268                    exit(1);
269            }
270            memset(d->n_pending_ipis, 0, sizeof(int) * n);
271            memset(d->ipi, 0, sizeof(int *) * n);
272    
273            memory_device_register(devinit->machine->memory, devinit->name,
274                devinit->addr, DEV_MP_LENGTH, dev_mp_access, d, MEM_DEFAULT, NULL);
275    
276          return 1;          return 1;
277  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26