/[dynamips]/upstream/dynamips-0.2.6-RC3/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 /upstream/dynamips-0.2.6-RC3/dev_rom.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations)
Sat Oct 6 16:01:44 2007 UTC (16 years, 5 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.5/dev_rom.c
File MIME type: text/plain
File size: 2127 byte(s)
import 0.2.5 from upstream

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

  ViewVC Help
Powered by ViewVC 1.1.26