/[gxemul]/upstream/0.3.3.2/src/devices/dev_pccmos.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/0.3.3.2/src/devices/dev_pccmos.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9 - (show annotations)
Mon Oct 8 16:18:22 2007 UTC (16 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 3954 byte(s)
0.3.3.2
1 /*
2 * Copyright (C) 2005 Anders Gavare. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 *
28 * $Id: dev_pccmos.c,v 1.3 2005/05/20 08:59:58 debug Exp $
29 *
30 * PC CMOS/RTC device.
31 *
32 * This is mostly bogus.
33 */
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39 #include "cpu.h"
40 #include "device.h"
41 #include "devices.h"
42 #include "emul.h"
43 #include "machine.h"
44 #include "memory.h"
45 #include "misc.h"
46
47
48 #define DEV_PCCMOS_LENGTH 2
49 #define PCCMOS_MC146818_FAKE_ADDR 0x1d00000000ULL
50
51 struct pccmos_data {
52 unsigned char select;
53 unsigned char ram[256];
54 };
55
56
57 /*
58 * dev_pccmos_access():
59 */
60 int dev_pccmos_access(struct cpu *cpu, struct memory *mem,
61 uint64_t relative_addr, unsigned char *data, size_t len,
62 int writeflag, void *extra)
63 {
64 struct pccmos_data *d = (struct pccmos_data *) extra;
65 uint64_t idata = 0, odata = 0;
66
67 idata = memory_readmax64(cpu, data, len);
68
69 switch (relative_addr) {
70 case 0: if (writeflag == MEM_WRITE) {
71 d->select = idata;
72 if (idata <= 0x0d)
73 cpu->memory_rw(cpu, cpu->mem,
74 PCCMOS_MC146818_FAKE_ADDR, data, 1,
75 MEM_WRITE, PHYSICAL);
76 } else
77 odata = d->select;
78 break;
79 case 1: if (d->select <= 0x0d) {
80 if (writeflag == MEM_WRITE)
81 cpu->memory_rw(cpu, cpu->mem,
82 PCCMOS_MC146818_FAKE_ADDR + 1, data, 1,
83 MEM_WRITE, PHYSICAL);
84 else
85 cpu->memory_rw(cpu, cpu->mem,
86 PCCMOS_MC146818_FAKE_ADDR + 1, data, 1,
87 MEM_READ, PHYSICAL);
88 return 1;
89 } else {
90 if (writeflag == MEM_WRITE)
91 d->ram[d->select] = idata;
92 else
93 odata = d->ram[d->select];
94 }
95 break;
96 default:
97 if (writeflag == MEM_WRITE) {
98 fatal("[ pccmos: unimplemented write to address 0x%x"
99 " data=0x%02x ]\n", (int)relative_addr, (int)idata);
100 } else {
101 fatal("[ pccmos: unimplemented read from address 0x%x "
102 "]\n", (int)relative_addr);
103 }
104 }
105
106 if (writeflag == MEM_READ)
107 memory_writemax64(cpu, data, len, odata);
108
109 return 1;
110 }
111
112
113 /*
114 * devinit_pccmos():
115 */
116 int devinit_pccmos(struct devinit *devinit)
117 {
118 struct pccmos_data *d = malloc(sizeof(struct pccmos_data));
119
120 if (d == NULL) {
121 fprintf(stderr, "out of memory\n");
122 exit(1);
123 }
124 memset(d, 0, sizeof(struct pccmos_data));
125
126 memory_device_register(devinit->machine->memory, devinit->name,
127 devinit->addr, DEV_PCCMOS_LENGTH, dev_pccmos_access, (void *)d,
128 MEM_DEFAULT, NULL);
129
130 dev_mc146818_init(devinit->machine, devinit->machine->memory,
131 PCCMOS_MC146818_FAKE_ADDR, 16 /* NOTE/TODO: No irq */,
132 MC146818_PC_CMOS, 1);
133
134 return 1;
135 }
136

  ViewVC Help
Powered by ViewVC 1.1.26