/[dynamips]/trunk/dev_bswap.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_bswap.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_bswap.c
File MIME type: text/plain
File size: 2689 byte(s)
dynamips-0.2.7-RC1

1 dpavlin 7 /*
2     * Cisco router simulation platform.
3     * Copyright (c) 2007 Christophe Fillot (cf@utc.fr)
4     *
5     * Byte-swapping device.
6     */
7    
8     #include <stdio.h>
9     #include <stdlib.h>
10     #include <string.h>
11     #include <unistd.h>
12     #include <assert.h>
13    
14     #include "cpu.h"
15     #include "vm.h"
16     #include "dynamips.h"
17     #include "memory.h"
18     #include "device.h"
19    
20     struct bswap_data {
21     /* VM object info */
22     vm_obj_t vm_obj;
23    
24     /* VM instance */
25     vm_instance_t *vm;
26    
27     /* Byte-swap device */
28     struct vdevice dev;
29    
30     /* Physical address base for rewrite */
31     m_uint64_t phys_base;
32     };
33    
34     /*
35     * Byte swapped access.
36     */
37     static void *dev_bswap_access(cpu_gen_t *cpu,struct vdevice *dev,
38     m_uint32_t offset,u_int op_size,u_int op_type,
39     m_uint64_t *data)
40     {
41     struct bswap_data *d = dev->priv_data;
42     m_uint64_t paddr;
43    
44     paddr = d->phys_base + offset;
45    
46     //printf("access to paddr = 0x%llx\n",paddr);
47    
48     switch(op_size) {
49     case 1:
50     if (op_type == MTS_READ)
51     *data = physmem_copy_u8_from_vm(d->vm,paddr ^ 0x03);
52     else
53     physmem_copy_u8_to_vm(d->vm,paddr ^ 0x03,*data);
54     break;
55    
56     case 2:
57     if (op_type == MTS_READ)
58     *data = swap16(physmem_copy_u16_from_vm(d->vm,paddr ^ 0x02));
59     else
60     physmem_copy_u16_to_vm(d->vm,paddr ^ 0x02,swap16(*data));
61     break;
62    
63     case 4:
64     if (op_type == MTS_READ)
65     *data = swap32(physmem_copy_u32_from_vm(d->vm,paddr));
66     else
67     physmem_copy_u32_to_vm(d->vm,paddr,swap32(*data));
68     break;
69     }
70    
71     return NULL;
72     }
73    
74     /* Shutdown an byte-swap device */
75     void dev_bswap_shutdown(vm_instance_t *vm,struct bswap_data *d)
76     {
77     if (d != NULL) {
78     /* Remove the alias, the byte-swapped and the main device */
79     dev_remove(vm,&d->dev);
80    
81     /* Free the structure itself */
82     free(d);
83     }
84     }
85    
86     /* Initialized a byte-swap device */
87     int dev_bswap_init(vm_instance_t *vm,char *name,
88     m_uint64_t paddr,m_uint32_t len,
89     m_uint64_t remap_addr)
90     {
91     struct bswap_data *d;
92    
93     if (!(d = malloc(sizeof(*d)))) {
94     fprintf(stderr,"BSWAP: unable to create device.\n");
95     return(-1);
96     }
97    
98     vm_object_init(&d->vm_obj);
99     d->vm = vm;
100     d->phys_base = remap_addr;
101     d->vm_obj.name = name;
102     d->vm_obj.data = d;
103     d->vm_obj.shutdown = (vm_shutdown_t)dev_bswap_shutdown;
104    
105     dev_init(&d->dev);
106     d->dev.name = name;
107     d->dev.phys_addr = paddr;
108     d->dev.phys_len = len;
109     d->dev.handler = dev_bswap_access;
110     d->dev.priv_data = d;
111    
112     /* Map this device to the VM */
113     vm_bind_device(vm,&d->dev);
114     vm_object_add(vm,&d->vm_obj);
115     return(0);
116     }

  ViewVC Help
Powered by ViewVC 1.1.26