/[dynamips]/upstream/dynamips-0.2.7-RC1/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

Contents of /upstream/dynamips-0.2.7-RC1/dev_rom.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (show annotations)
Sat Oct 6 16:06:49 2007 UTC (16 years, 5 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.6-RC3/dev_rom.c
File MIME type: text/plain
File size: 2164 byte(s)
dynamips-0.2.6-RC3

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 m_uint8_t microcode[] = {
19 #include "microcode_dump.inc"
20 };
21
22 ssize_t microcode_len = sizeof(microcode);
23
24 /* ROM private data */
25 struct rom_data {
26 vm_obj_t vm_obj;
27 struct vdevice dev;
28 m_uint8_t *rom_ptr;
29 m_uint32_t rom_size;
30 };
31
32 /*
33 * dev_rom_access()
34 */
35 void *dev_rom_access(cpu_mips_t *cpu,struct vdevice *dev,
36 m_uint32_t offset,u_int op_size,u_int op_type,
37 m_uint64_t *data)
38 {
39 struct rom_data *d = dev->priv_data;
40
41 if (op_type == MTS_WRITE) {
42 cpu_log(cpu,"ROM","write attempt at address 0x%llx (data=0x%llx)\n",
43 dev->phys_addr+offset,*data);
44 return NULL;
45 }
46
47 if (offset >= d->rom_size) {
48 *data = 0;
49 return NULL;
50 }
51
52 return((void *)(d->rom_ptr + offset));
53 }
54
55 /* Shutdown a ROM device */
56 void dev_rom_shutdown(vm_instance_t *vm,struct rom_data *d)
57 {
58 if (d != NULL) {
59 /* Remove the device */
60 dev_remove(vm,&d->dev);
61
62 /* Free the structure itself */
63 free(d);
64 }
65 }
66
67 /* Initialize a ROM zone */
68 int dev_rom_init(vm_instance_t *vm,char *name,m_uint64_t paddr,m_uint32_t len)
69 {
70 struct rom_data *d;
71
72 /* allocate the private data structure */
73 if (!(d = malloc(sizeof(*d)))) {
74 fprintf(stderr,"ROM: unable to create device.\n");
75 return(-1);
76 }
77
78 memset(d,0,sizeof(*d));
79 d->rom_ptr = microcode;
80 d->rom_size = sizeof(microcode);
81
82 vm_object_init(&d->vm_obj);
83 d->vm_obj.name = name;
84 d->vm_obj.data = d;
85 d->vm_obj.shutdown = (vm_shutdown_t)dev_rom_shutdown;
86
87 dev_init(&d->dev);
88 d->dev.name = name;
89 d->dev.priv_data = d;
90 d->dev.phys_addr = paddr;
91 d->dev.phys_len = len;
92 d->dev.flags = VDEVICE_FLAG_CACHING;
93 d->dev.handler = dev_rom_access;
94
95 /* Map this device to the VM */
96 vm_bind_device(vm,&d->dev);
97 vm_object_add(vm,&d->vm_obj);
98 return(0);
99 }

  ViewVC Help
Powered by ViewVC 1.1.26