/[dynamips]/trunk/dev_rom.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

Annotation of /trunk/dev_rom.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (hide annotations)
Sat Oct 6 16:23:47 2007 UTC (16 years, 5 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.7-RC1/dev_rom.c
File MIME type: text/plain
File size: 2437 byte(s)
dynamips-0.2.7-RC1

1 dpavlin 1 /*
2 dpavlin 7 * Cisco router simulation platform.
3 dpavlin 1 * Copyright (c) 2006 Christophe Fillot. All rights reserved.
4 dpavlin 7 *
5     * ROM Emulation.
6 dpavlin 1 */
7    
8     #include <stdio.h>
9     #include <stdlib.h>
10     #include <string.h>
11     #include <time.h>
12     #include <errno.h>
13    
14 dpavlin 7 #include "cpu.h"
15     #include "vm.h"
16 dpavlin 1 #include "dynamips.h"
17     #include "memory.h"
18     #include "device.h"
19    
20 dpavlin 7 /* Embedded MIPS64 ROM */
21     m_uint8_t mips64_microcode[] = {
22     #include "mips64_microcode_dump.inc"
23 dpavlin 1 };
24    
25 dpavlin 7 ssize_t mips64_microcode_len = sizeof(mips64_microcode);
26 dpavlin 4
27 dpavlin 7 /* Embedded PPC32 ROM */
28     m_uint8_t ppc32_microcode[] = {
29     #include "ppc32_microcode_dump.inc"
30     };
31    
32     ssize_t ppc32_microcode_len = sizeof(ppc32_microcode);
33    
34 dpavlin 1 /* ROM private data */
35     struct rom_data {
36     vm_obj_t vm_obj;
37     struct vdevice dev;
38     m_uint8_t *rom_ptr;
39     m_uint32_t rom_size;
40     };
41    
42     /*
43     * dev_rom_access()
44     */
45 dpavlin 7 void *dev_rom_access(cpu_gen_t *cpu,struct vdevice *dev,
46 dpavlin 1 m_uint32_t offset,u_int op_size,u_int op_type,
47     m_uint64_t *data)
48     {
49     struct rom_data *d = dev->priv_data;
50    
51     if (op_type == MTS_WRITE) {
52     cpu_log(cpu,"ROM","write attempt at address 0x%llx (data=0x%llx)\n",
53     dev->phys_addr+offset,*data);
54     return NULL;
55     }
56    
57     if (offset >= d->rom_size) {
58     *data = 0;
59     return NULL;
60     }
61    
62     return((void *)(d->rom_ptr + offset));
63     }
64    
65     /* Shutdown a ROM device */
66     void dev_rom_shutdown(vm_instance_t *vm,struct rom_data *d)
67     {
68     if (d != NULL) {
69     /* Remove the device */
70     dev_remove(vm,&d->dev);
71    
72     /* Free the structure itself */
73     free(d);
74     }
75     }
76    
77     /* Initialize a ROM zone */
78 dpavlin 7 int dev_rom_init(vm_instance_t *vm,char *name,m_uint64_t paddr,m_uint32_t len,
79     m_uint8_t *rom_data,ssize_t rom_data_size)
80 dpavlin 1 {
81     struct rom_data *d;
82    
83     /* allocate the private data structure */
84     if (!(d = malloc(sizeof(*d)))) {
85     fprintf(stderr,"ROM: unable to create device.\n");
86     return(-1);
87     }
88    
89     memset(d,0,sizeof(*d));
90 dpavlin 7 d->rom_ptr = rom_data;
91     d->rom_size = rom_data_size;
92 dpavlin 1
93     vm_object_init(&d->vm_obj);
94     d->vm_obj.name = name;
95     d->vm_obj.data = d;
96     d->vm_obj.shutdown = (vm_shutdown_t)dev_rom_shutdown;
97    
98     dev_init(&d->dev);
99     d->dev.name = name;
100     d->dev.priv_data = d;
101     d->dev.phys_addr = paddr;
102     d->dev.phys_len = len;
103     d->dev.flags = VDEVICE_FLAG_CACHING;
104     d->dev.handler = dev_rom_access;
105    
106     /* Map this device to the VM */
107     vm_bind_device(vm,&d->dev);
108     vm_object_add(vm,&d->vm_obj);
109     return(0);
110     }

  ViewVC Help
Powered by ViewVC 1.1.26