/[gxemul]/trunk/src/devices/dev_8259.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 /trunk/src/devices/dev_8259.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (show annotations)
Mon Oct 8 16:18:11 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 6096 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.772 2005/06/04 12:02:16 debug Exp $
20050428	Disabling the "-fmove-all-movables" option in the configure
		script, because it causes the compile to fail on OpenBSD/sgi.
20050502	Minor updates.
20050503	Removing the WRT54G mode (it was bogus anyway), and adding a
		comment about Windows NT for MIPS in doc/experiments.html.
		Minor updates to the x86 instruction decoding.
20050504	Adding some more x86 instructions.
		Adding support for reading files from ISO9660 CDROMs (including
		gzipped files). It's an ugly hack, but it seems to work.
		Various other minor updates (dev_vga.c, pc_bios.c etc).
20050505	Some more x86-related updates.
		Beginning (what I hope will be) a major code cleanup phase.
		"bootris" (an x86 bootsector) runs :-)
20050506	Adding some more x86 instructions.
20050507	tmpnam => mkstemp.
		Working on a hack to allow VGA charcells to be shown even when
		not running with X11.
		Adding more x86 instructions.
20050508	x86 32-bit SIB addressing fix, and more instructions.
20050509	Adding more x86 instructions.
20050510	Minor documentation updates, and other updates (x86 stuff etc.)
20050511	More x86-related updates.
20050513	Various updates, mostly x86-related. (Trying to fix flag 
		calculation, factoring out the ugly shift/rotate code, and
		some other things.)
20050514	Adding support for loading some old i386 a.out executables.
		Finally beginning the cleanup of machine/PROM/bios dependant
		info.
		Some minor documentation updates.
		Trying to clean up ARCBIOS stuff a little.
20050515	Trying to make it possible to actually use more than one disk
		type per machine (floppy, ide, scsi).
		Trying to clean up the kbd vs PROM console stuff. (For PC and
		ARC emulation modes, mostly.)
		Beginning to add an 8259 interrupt controller, and connecting
		it to the x86 emulation.
20050516	The first x86 interrupts seem to work (keyboard stuff).
		Adding a 8253/8254 programmable interval timer skeleton.
		FreeDOS now reaches a command prompt and can be interacted
		with.
20050517	After some bugfixes, MS-DOS also (sometimes) reaches a
		command prompt now.
		Trying to fix the pckbc to work with MS-DOS' keyb.com, but no
		success yet.
20050518	Adding a simple 32-bit x86 MMU skeleton.
20050519	Some more work on the x86 stuff. (Beginning the work on paging,
		and various other fixes).
20050520	More updates. Working on dev_vga (4-bit graphics modes), adding
		40 columns support to the PC bios emulation.
		Trying to add support for resizing windows when switching
		between graphics modes.
20050521	Many more x86-related updates.
20050522	Correcting the initial stack pointer's sign-extension for
		ARCBIOS emulation (thanks to Alec Voropay for noticing the
		error).
		Continuing on the cleanup (ARCBIOS etc).
		dev_vga updates.
20050523	More x86 updates: trying to add some support for protected mode
		interrupts (via gate descriptors) and many other fixes.
		More ARCBIOS cleanup.
		Adding a device flag which indicates that reads cause no
		side-effects. (Useful for the "dump" command in the debugger,
		and other things.)
		Adding support for directly starting up x86 ELFs, skipping the
		bootloader stage. (Most ELFs, however, are not suitable for
		this.)
20050524	Adding simple 32-bit x86 TSS task switching, but no privilege
		level support yet.
		More work on dev_vga. A small "Copper bars" demo works. :-)
		Adding support for Trap Flag (single-step exceptions), at least
		in real mode, and various other x86-related fixes.
20050525	Adding a new disk image prefix (gH;S;) which can be used to
		override the default nr of heads and sectors per track.
20050527	Various bug fixes, more work on the x86 mode (stack change on
		interrupts between different priv.levels), and some minor
		documentation updates.
20050528	Various fixes (x86 stuff).
20050529	More x86 fixes. An OpenBSD/i386 bootfloppy reaches userland
		and can be interacted with (although there are problems with
		key repetition). NetBSD/i386 triggers a serious CISC-related
		problem: instruction fetches across page boundaries, where
		the later part isn't actually part of the instruction.
20050530	Various minor updates. (Documentation updates, etc.)
20050531	Adding some experimental code (experiments/new_test_*) which
		could be useful for dynamic (but not binary) translation in
		the future.
20050602	Adding a dummy ARM skeleton.
		Fixing the pckbc key repetition problem (by adding release
		scancodes for all keypresses).
20050603	Minor updates for the next release.
20050604	Release testing. Minor updates.

==============  RELEASE 0.3.3  ==============

20050604	There'll probably be a 0.3.3.1 release soon, with some very
		very tiny updates.


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_8259.c,v 1.9 2005/06/02 17:11:35 debug Exp $
29 *
30 * 8259 Programmable Interrupt Controller.
31 *
32 * This is mostly bogus. TODO. See the following URL for more details:
33 * http://www.nondot.org/sabre/os/files/MiscHW/8259pic.txt
34 */
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39
40 #include "cpu.h"
41 #include "device.h"
42 #include "devices.h"
43 #include "emul.h"
44 #include "machine.h"
45 #include "memory.h"
46 #include "misc.h"
47
48
49 #define DEV_8259_LENGTH 2
50
51
52 /*
53 * dev_8259_access():
54 */
55 int dev_8259_access(struct cpu *cpu, struct memory *mem,
56 uint64_t relative_addr, unsigned char *data, size_t len,
57 int writeflag, void *extra)
58 {
59 struct pic8259_data *d = (struct pic8259_data *) extra;
60 uint64_t idata = 0, odata = 0;
61
62 idata = memory_readmax64(cpu, data, len);
63
64 switch (relative_addr) {
65 case 0x00:
66 if (writeflag == MEM_WRITE) {
67 if ((idata & 0x10) == 0x10) {
68 /* Bit 3: 0=edge, 1=level */
69 if (idata & 0x08)
70 fatal("[ 8259: TODO: Level "
71 "triggered (MCA bus) ]\n");
72 if (idata & 0x04)
73 fatal("[ 8259: WARNING: Bit 2 set ]\n");
74 /* Bit 1: 0=cascade, 1=single */
75 /* Bit 0: 1=4th init byte */
76 if (!(idata & 0x01))
77 fatal("[ 8259: WARNING: Bit 0 NOT set!"
78 "!! ]\n");
79 d->init_state = 1;
80 break;
81 }
82
83 /* TODO: Is it ok to abort init state when there
84 is a non-init command? */
85 if (d->init_state)
86 fatal("[ 8259: WARNING: Was in init-state, but"
87 " it was aborted? ]\n");
88 d->init_state = 0;
89
90 switch (idata) {
91 case 0x0a:
92 d->current_command = 0x0a;
93 break;
94 case 0x0b:
95 d->current_command = 0x0b;
96 break;
97 case 0x20: /* End Of Interrupt */
98 d->irr &= ~d->isr;
99 d->isr = 0;
100 /* Recalculate interrupt assertions: */
101 cpu_interrupt(cpu, 16);
102 break;
103 case 0x60:
104 case 0x61:
105 case 0x62:
106 case 0x63:
107 case 0x64:
108 case 0x65:
109 case 0x66:
110 case 0x67: /* Specific EOI */
111 d->irr &= ~(1 << (idata & 7));
112 d->isr &= ~(1 << (idata & 7));
113 /* Recalculate interrupt assertions: */
114 cpu_interrupt(cpu, 16);
115 break;
116 case 0x68: /* Set Special Mask Mode */
117 /* TODO */
118 break;
119 case 0xc0:
120 case 0xc1:
121 case 0xc2:
122 case 0xc3:
123 case 0xc4:
124 case 0xc5:
125 case 0xc6:
126 case 0xc7: /* Set IRQ Priority Order */
127 /* TODO */
128 break;
129 default:
130 fatal("[ 8259: unimplemented command 0x%02x"
131 " ]\n", idata);
132 cpu->running = 0;
133 }
134 } else {
135 switch (d->current_command) {
136 case 0x0a:
137 odata = d->irr;
138 break;
139 case 0x0b:
140 odata = d->isr;
141 break;
142 default:
143 fatal("[ 8259: unimplemented command 0x%02x"
144 " while reading ]\n", d->current_command);
145 cpu->running = 0;
146 }
147 }
148 break;
149 case 0x01:
150 if (d->init_state > 0) {
151 if (d->init_state == 1) {
152 d->irq_base = idata & 0xf8;
153 if (idata & 7)
154 fatal("[ 8259: WARNING! Lowest"
155 " bits in Init Cmd 1 are"
156 " non-zero! ]\n");
157 d->init_state = 2;
158 } else if (d->init_state == 2) {
159 /* Slave attachment. TODO */
160 d->init_state = 3;
161 } else if (d->init_state == 3) {
162 if (idata & 0x02)
163 fatal("[ 8259: WARNING! Bit 1 i"
164 "n Init Cmd 4 is set! ]\n");
165 if (!(idata & 0x01))
166 fatal("[ 8259: WARNING! Bit 0 "
167 "in Init Cmd 4 is not"
168 " set! ]\n");
169 d->init_state = 0;
170 }
171 break;
172 }
173
174 if (writeflag == MEM_WRITE) {
175 d->ier = idata;
176 /* Recalculate interrupt assertions: */
177 cpu_interrupt(cpu, 16);
178 } else {
179 odata = d->ier;
180 }
181 break;
182 default:
183 if (writeflag == MEM_WRITE) {
184 fatal("[ 8259: unimplemented write to address 0x%x"
185 " data=0x%02x ]\n", (int)relative_addr, (int)idata);
186 cpu->running = 0;
187 } else {
188 fatal("[ 8259: unimplemented read from address 0x%x "
189 "]\n", (int)relative_addr);
190 cpu->running = 0;
191 }
192 }
193
194 if (writeflag == MEM_READ)
195 memory_writemax64(cpu, data, len, odata);
196
197 return 1;
198 }
199
200
201 /*
202 * devinit_8259():
203 */
204 int devinit_8259(struct devinit *devinit)
205 {
206 struct pic8259_data *d = malloc(sizeof(struct pic8259_data));
207 char *name2;
208 int nlen = 40;
209
210 if (d == NULL) {
211 fprintf(stderr, "out of memory\n");
212 exit(1);
213 }
214 memset(d, 0, sizeof(struct pic8259_data));
215 d->irq_nr = devinit->irq_nr;
216
217 name2 = malloc(nlen);
218 snprintf(name2, nlen, "%s", devinit->name);
219 if ((devinit->addr & 0xfff) == 0xa0)
220 strcat(name2, " [secondary]");
221
222 memory_device_register(devinit->machine->memory, name2,
223 devinit->addr, DEV_8259_LENGTH, dev_8259_access, (void *)d,
224 MEM_DEFAULT, NULL);
225
226 devinit->return_ptr = d;
227 return 1;
228 }
229

  ViewVC Help
Powered by ViewVC 1.1.26