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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Mon Oct 8 16:17:48 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 45684 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.676 2005/04/07 15:14:55 debug Exp $

Changelog for GXemul:
---------------------

20030829	Skeleton. ELF stuff. Some instructions.
20030830	Simple test programs using +-*/^|&%, function calls,
		loops, and stuff like that work.
20030903	Adding more instructions, fixing some bugs.
20030907	Making adding of memory mapped devices easier, although
		the framework isn't built for speed.
		Adding a -q switch to turn of debug output.
20030911	Trying to fix some bugs. Minor changes. Some COP0
		registers are now meaningful.
20030919	Making APs (non-bootstrap cpus) available via a simple
		'mp' device. Implementing ll/lld and sc/scd (for atomic
		memory updates, needed by MP operating systems).
20030923	Minor updates: more instructions (divu, mulu, lwu,
		perhaps some more), and opcode usage statistics.
20030924	If the next instruction is nullified (for 'branch
		likely' type of instructions), counters for delays etc
		are now decreased as they should.
		Adding some comments.
		Adding instructions: movz, movn.
		Adding a simple mandelbrot test to mipstest.c.
20030925	Adding instructions: bltzl, bgezl, lh, lhu, sh, mfc*,
		mtc*.
		Adding a dummy instructions: sync, cache.
		Adding minimal DECstation PROM functionality: printf()
		and getsysid() callback functions.
		Beginning work on address translation.
20030927	Adding some more cop0 functionality (tlb stuff).
		Adding mc146818 real-time clock. (Skeleton stuff.)
20030928	Adding a dc7085 serial console device (dummy, but enough
		to output chars to the screen). NetBSD uses this for
		the MIPSMATE 5100.
20030929	Working on the TLB stuff.
		Adding instructions: srlv, tlbwr, tlbr, tlbp, eret.
20030930	Trying to find a bug which causes NetBSD to bug out, but
		it is really hard.
		Adding some a.out support (for loading an old
		OpenBSD 2.8/pmax kernel image).
		Adding instructions: lwc*, ldc*, swc1 and swc3.
		Beginning to add special code to handle the differences
		between R4000 (the default emulation) and R2000/R3000.
20031001	Symbol listings produced by 'nm -S' can be used to
		show symbolic names for addresses. (-S)
20031002	Fixing the i/d fake cache for R2000/R3000. It's still
		just an ugly hack, though.
		Fixing minor bugs to make the 3100 emulation use the
		dc device (serial console) correctly. So far, 5100 and
		3100 are the only ones that get far enough to print
		stuff, when booting NetBSD.
20031004	Adding skeleton Cobalt machine emulation (-E).
		Adding a dummy ns16550 serial controller, used by the
		Cobalt machine emulation.
20031006	Adding unaligned load/store instructions (lwl, lwr,
		ldl, ldr, swl, swr, sdl, sdr), although they are not
		tested yet.
		Fixed a "data modified on freelist" bug when running
		NetBSD/cobalt: setting the top bit of the index register
		when a tlbp fails (as the R4000 manual says) isn't
		sufficient, I had to clear the low bits as well.
		Adding break and syscall instructions, but they are not
		tested yet.
		Adding a 'gt' device, faking a PCI bus, for the Cobalt
		emulation.
20031008	Adding initial support for HPCmips (-F), a framebuffer
		device using X11. NetBSD/hpcmips can output pixels to
		the framebuffer, but that's about it.
20031009	Fixing the NetBSD/pmax bug: the "0/tftp/netbsd" style
		bootstring was only passed correctly in the bootinfo
		block, it needs to be passed as argv[0] as well.
		Adding instructions: mtlo, mthi.
		Rearrangning the source tree layout.
		Adding console input functionality. The NetBSD/cobalt
		kernel's ddb can now be interacted with.
20031010	Adding experimental (semi-useless) -t option, to show
		a function call tree while a program runs.
		Linux/cobalt now prints a few messages, but then hangs
		at "Calibrating delay loop..." unless an ugly hack is
		used (setting a word of memory at 0x801e472c to non-zero).
20031013	Adding a framebuffer device used in DECstation 3100;
		VFB01 for mono is implemented so far, not yet the
		VFB02 (color) variant.  Rewriting the framebuffer
		device so that it is usable by both HPCmips and DECstation
		emulation.
20031014	Minor fixes. Everything should compile and run ok
		both with and without X11.
20031015	Adding support for ECOFF binary images; text, data,
		and symbols are loaded. (Playing around with ultrixboot
		and ultrix kernels.)
20031016	The DECstation argv,argc stuff must be at 0xa0000000,
		not 0x80000000, or Ultrix kernels complain.
		Adding R2000/R3000 'rfe' instruction.
		Implementing more R2K/R3K tlb specific stuff, so that
		NetBSD boots and uses the tlb correctly, but much of
		it is ugly. (Needs to be separated in a cleaner way.)
		ECOFF symbols sizes are now calculated, so that offsets
		within symbols are usable.
20031017	DECstation bootstrings now automatically include the
		correct name of the kernel that is booting.
		Ultrix boots a bit.
20031018	ELF symbols are now read automatically from the binary.
		-t trace looks a bit better (string arguments are shown).
		Trying to get initial R5900 stuff working (the 128-bit
		CPU used in Playstation 2).
		Fixing a minor bug to make the VFB02 (color framebuffer)
		device work better, but it is still just 256 grayscales,
		not real color. Ultrix can now use the framebuffer (it
		calls it PMAX-CFB).
		A machine can now consist of CPUs of different types.
		Adding instructions: daddi, mov_xxx, mult_xx. The xxx
		instructions are not documented MIPS64 instructions,
		but NetBSD/playstation2 uses them. Perhaps VR5432
		instructions?
		Adding sign-extension to 32-bit mult.
		Adding Playstation 2 devices: dmac (DMA controller),
		gs (Graphic something?), and gif (graphics something
		else, which has access to the PS2's framebuffer).
		NetBSD/playstation2 works a bit, and prints a few
		bootup messages.
20031020	The cpu_type field of the cpu struct now contains
		usable values in a much better form than before. This
		simplifies adding of new CPU types.
20031021	Fixing an interrupt related bug: pc_last was used, but
		for interrupts this was incorrect. Fixed now.
		Fixing a load/store related bug: if a load into a
		register was aborted due to an exception, the register
		was still modified.
		The mc146818 rtc now reads its time from the system's
		time() function.
		Fixing another exception bug: if loading an instruction
		caused an exception, something bogus happened as the
		emulator tried to execute the instruction anyway. This
		has been fixed now.
20031023	Adding a quick hack which skips "while (reg --) ;"
		kind of loops.
		NetBSD/pmax suddenly reached userland (!), but only
		once and attempts to repeat it have failed. I believe
		it is problems with my interrupt handling system.
20031024	Adding 8-bit color palette support to the framebuffer.
		Connecting the pmax vdac device to the framebuffer's
		rgb palette.
		Fixing a bug in the dc device, so that console input
		is possible; interaction with NetBSD/pmax's built-in
		kernel debugger works now.
		Symbol sizes for file formats where symbol size isn't
		included are now calculated regardless of file format.
		Physical memory space can now be smaller than 64 bits,
		improving emulation speed a bit.
		Doing other minor performance enhancements by moving
		around some statements in critical parts of the code.
20031025	Minor changes to the dc device.
20031026	Adding support for reading symbols directly from
		a.out files. (Works with OpenBSD/pmax binaries.)
		Hardware devices may now register "tick functions" at
		specific cycle intervals in a generic fashion.
		All four channels of the dc serial controller device
		should now work; playing around with keyboard scan
		code generation when using the DECstation framebuffer.
		Making various (speed) improvements to the framebuffer
		device.
20031027	Playing around with the sii SCSI controller.
20031028	Minor fixes.
		Adding an SGI emulation mode (-G), and some ARCBIOS
		stuff, which SGIs seem to use.
		Adding getbitmap() to the DEC prom emulation layer,
		so some more -D x models become more usable.
		Adding a dummy 'ssc' serial console device for
		DECsystem 5400 emulation.
		Playing around with TURBOchannel stuff.
20031030	Minor fixes.
		Adding the sub instruction. (Not tested yet?)
		Sign-extending the results of multu, addi,addiu,
		add,addu,sub,subu,mfcZ.
		Adding a colorplanemask device for DECstation 3100.
		Fixed the NetBSD/pmax bug: I had forgotten to reset
		asid_match to 0 between tlb entry checks. :-)  Now
		userland runs nicely...
20031031	Fixing more bugs:  unaligned load/store could fail
		because of an exception, but registers could be "half
		updated". This has been fixed now.  (As a result,
		NetBSD/pmax can now run with any of r2000,r3000,r4000,
		r4400, or r5000.)
		Adding some R5K and R10000 stuff.  (Note: R5K is NOT
		R5000. Weird.)
		Adding dummy serial console (scc) for MAXINE.
		MAXINE also works with framebuffer, but there is no
		color palette yet (only black and white output).
20031101	Moving code chunks around to increase performance by
		a few percent.
		The opcode statistics option (-s) now shows opcode
		names, and not just numbers. :-)
		Fixing the bug which caused NetBSD/pmax to refuse
		input in serial console mode, but not in keyboard/
		framebuffer mode: the osconsole environment variable
		wasn't set correctly.
		Adding DEC PROM getchar() call.
		The transmitter scanner of the dc device now scans
		all four channels at once, for each tick, so serial
		output is (approximately) 4 times faster.
20031103	Adding a dummy BT459 vdac device, which does nothing
		but allows a PMAG-BA turbochannel graphics card to be
		used as framebuffer.
		Several DECstation machines (-D 2, 3, and 4) can now
		use TURBOchannel option card framebuffers as console,
		for output. (Keyboard input is still not implemented
		for those models.)  Only PMAG-AA (1280x1024x8) and
		PMAG-BA (1024x864x8), both using BT459 vdac, have
		been tested so far.
		Modifying the X11 routines so that several framebuffer
		windows now can be used simultaneously (if several
		graphics option cards are to be emulated concurrently).
20031104	DEC MIPSMATE 5100 (KN230) interrupts are shared
		between devices. I've added an ugly hack to allow
		that to work, which makes it possible to boot NetBSD
		into userland with serial console.
20031106	Removing the -S (symbol) option, as symbol files can
		now be given in any order together with other file
		names to be loaded.
		cookin tipped me about using (int64_t) (int32_t)
		casts instead of manually sign-extending values.
		Casting sometimes increases performance, sometimes
		decreases. It's tricky.
		Importing mips64emul into CVS.
20031107	Adding a generic ARC emulation mode.
		Increasing performance of the framebuffer by not
		updating it (or the XImage) if a write to the
		framebuffer contains exactly what is already in it.
		(This improves scrolling speed and initialization.)
		Adding initial MIPS16 support.
		Adding initial disk image support (-d command line
		option), but this will not be used until I get some
		kind of SCSI-controller emulation working.
20031108	Adding the first MIPS16 instructions: "move y,X",
		"ld y,D(x)", and "daddiu S,K" (but the last one
		doesn't work yet).
		Fixing the console environment variable for
		Enough of the 'asc' controller is now implemented
		to let NetBSD get past scsi disk detection when
		no disk images are used.
		DECstation machine type 2; both serial console and
		graphical console work now.
		Other X-windows bit-depths than 24 bits work now,
		but colors are still not correct in non-24 bit modes.
		Keypresses in X framebuffer windows are now
		translated into console keypresses. (Normal keys, but
		not cursor keys or other special keys.)
20031111	Adding support for X11 using non-24-bit output.
20031120	Adding X11 mouse event to emulated mouse event
		translation, but it's not tested yet.
		Trying to get more of the SCSI controller emulation
		to work.
20031124	Raw binaries can now be loaded into memory.
20031204	Adding srec binary support.
20031220	Adding some super-ugly arcbios emulation code.
		Making some progress on the SGI and ARC machine
		emulations.
20031222	SGI and ARC progress. Multiple CPUs are now added to
		the arcbios component tree (although NetBSD cannot
		actually use more than one).
20031228	Adding 'crime' and 'macepci' fake devices for SGI
		emulation.
		Finally implementing the cop0 'compare' register.
		Improvements to the ns16550 device, but it is still
		incomplete.
		SGI userland is now reached, but interaction is broken
		(due to the buggy ns16550).
20031229	Adding some more instructions: teq, dsllv
		Adding a Nintendo 64 emulation mode (skeleton).
		Adding R4300 and R12000 to the cpu list.
20031230	Adding bltzal, bltzall, bgezal, bgezall (not really
		tested yet).
		Fixing the 16550 serial controller device (by not
		supporting fifo, so in fact it emulates a 16450
		instead).  This causes NetBSD/sgimips to run nicely
		into userland, sysinst, and so on.
		Some ARC/RD94 interrupts seem to work ok now, but
		i/o interrupts are still not correctly implemented.
		NetBSD/arc userland is reached and can be interacted
		with, but there's no sysinst (?).
20040103	Trying to get some Irix stuff to work, but it's hard.
		Fixing some Cobalt/linux problems.
20040104	Adding a dummy 8250 device, so that Linux/sgimips can output
		console messages.
		Adding dmultu. (The same as dmult, so I'm not sure it's correct.
		Perhaps dmultu is correct and dmult is wrong...)
		Fixing a bug in unaligned load/stores of 64-bit values (a cast
		was needed).
		Linux/sgimips in 64-bit works a bit more than before.
		Adding simple (polled) input functionality to dev_zs.
		Making some progress on SGI-IP22 (IP32 still works best,
		though).
		Fixing the mc146818 clock device in ARC/NEC and SGI emulation
		modes, the year field was not correct.
		Adding a fake 'pref' instruction (lwc3).
20040106	Separating out memory.h from misc.h.
		Refactoring of a lot of small code fragments.
		The PCI bus device is now shared between Cobalt, SGI, and ARC.
		Support for RAM mirroring (dev_ram.c, not really tested yet).
		Ugly hack to select the largest of ELF string symbol tables,
		if there are more than one.
		Memory hole fix for ARCBIOS, and a fix for very large (>= 4GB)
		amounts of emulated RAM.
		TGA (DEC 21030) PCI graphics device. NetBSD/arc can boot with
		this card and use it as a framebuffer console.
20040107	Adding a fix (partly incorrect) to daddi, to allow Linux/sgimips
		to boot in 64-bit mode.
20040108	Fixing a sll/nop bug (rd==0 for nop, not sa==0 as before).
20040109	Trying to get an SGI-IP32 PROM image to boot.
20040110	Faking R10000 cache things.
		The PROM image boots, although it takes almost forever for it
		to realize that there is no keyboard.
		The 'gbe' SGI-IP32 graphics device works enough to display the
		Linux framebuffer penguin in the upper left corner :-)
20040111	-p and -P addresses can now be given as symbol names, not just
		numeric values.
		Experimenting with adding a PCIIDE (dev_wdc) controller to the
		Cobalt emulation.
20040120	Adding src/bintrans.c. No code yet, but this is a place for
		ideas to be written down.
		Increasing performance a little bit by inlining the check for
		interrupts (which occurs for every instruction).
20040124	Experimenting with pure userland (syscall) emulation.
20040127	Fixes for compiling under Solaris.
20040206	Some bintrans experiments.
20040209	Adding some simple Ultrix userland emulation syscalls.
20040211	Adding decprom_dump_txt_to_bin.c to the experiments/ dir.
		Adding a section to doc/ on how to use DECstation PROM dumps.
		Adding a hello world example to doc/ as well.
20040218	TURBOchannel slots that are empty now return a DBE exception,
		so that Ultrix and DECstation PROMs don't complain about
		broken TURBOchannel ROMs.
		Working some more on the machine-dependant interrupt stuff.
20040219	Trying out some Linux/DECstation kernels (semi-successfully).
20040222	YES! I finally found the bug that caused Linux/SGI-IP32 to only
		work on Alpha, not on 32-bit machines.  It was a shift left,
		probably done using 6 bits on alpha, 5 bits on 32-bit machines.
20040223	Some minimal DEC KN5800 progress; Ultrix prints some boot
		messages, detects 16 XMI R3000 cpus, and get a NULL panic.
		It's all fake, though, the CPUs don't actually work.
		Still, better than nothing :-)
20040225	An Ultrix OSF1 kernel with a ramdisk now boots :-)  (It was
		a problem with ultrixboot not giving the same arguments as
		NetBSD's boot program.)
20040225(later)	Fixing a bug in the DECstation dc serial device; digits 0-9
		were translated to numeric keypad 0-9, not the normal 0-9.
		(This caused Ultrix to print escape sequences instead of
		digits.)
20040226	Some progress on machine-dependant interrupt delivery
		for -D7 (Maxine) and -D4, and some more 'scc' serial
		controller featuers are implemented (but no interrupts/
		dma/keyboard/mouse stuff yet).
20040228	Progress on the scc controller; -D4 works in both serial
		console mode and with keyboard (graphical console), but no
		mouse yet.
20040301	SGI mace interrupts are now done using the new machine-
		independant interrupt system.
20040303	Fixing an R5900 bug; the lowest 6 bits have special meaning
		for coprocessor functions, not just 5 bits as on non-R5900
		CPUs. (This fixes a bug which caused NetBSD to crash.)
20040304	Adding enough (fake) DMA capabilities to the ioasic device
		to allow Ultrix to print boot messages in the -D3, -D4,
		and -D7 modes, and also print graphical console messages
		in -D4 and -D7 modes.
		-D11 (DEC5500) polled getchar added (to the 'ssc' device).
		Adding the 'madd' instruction (including R5900 weird stuff).
20040304(later)	Playstation 2's GIF can now copy 640x16 pixel chunks, allowing
		NetBSD to scroll up the framebuffer.  The cursor also works
		better now.
		Playstation 2 bootinfo RTC data should now be passed correctly
		to the running kernel.
		DECstation rtc year should be either 72 or 73, anything else
		will cause Ultrix to give a warning about invalid year.
20040306	Combining playstation2's dmac, interrupt, and timer devices
		into one (ps2_stuff).
		Adding some R5900 instructions: mfsa, mtsa, pmfhi, pmflo, por,
		lq, and sq.  (Most of them are just guesses, though.)
		Implementing my own XImage putpixel routine, which can be
		inlined... significantly faster than normal XPutPixel. :-)
20040307	Implementing the basic functionality of a "PMAG-CA" pixelstamp
		accellerated framebuffer device. Works with NetBSD and
		Ultrix, but no cursor or color support.
20040308	PMAG-CA, -DA, and -FA pixelstamps seem to work now.
		Adding a hack to allow a pmax/mach kernel to be loaded (it's
		a COFF file with 0 (!) sections).
		Initial test of bt459 + framebuffer cursor support.
20040309	Fixes/updates of dev_dec5800 and dev_ssc (and dev_decxmi) allow
		a KN5800 Ultrix-OSF1-ramdisk kernel to boot all the way into
		userland and be interacted with.
		The bt459 cursor should now look semi-nice, but it is still
		a bit fake.
20040310	Moving the DEC CCA stuff from src/machine.c into a separate
		device file (devices/dev_deccca.c).
		An ugly hack added to allow some more OSF/1 kernels (almost
		a.out, but without many of the header fields) to load.
20040314	Adding PMAG-JA and PMAG-RO (1280x1024 x 8-bit) TURBOchannel
		graphics devices. They work in Ultrix, but only monochrome
		and no cursor, because there are no ramdacs or such yet.
20040315	Pixelstamp solid fill now supports colors other than just
		zero-fill.
		Adding a (new) regression test skeleton.
20040321	Some really minor updates.
20040323	Fixes to allow SGI-IP20 and IP22 to work a bit better
		(aliased memory), and adding "private" firmware-like vectors
		to arcbios emul. An IP22 Irix kernel gets far enough to
		print an assertion warning (and then double panics). :-)
20040324	Adding a generalization hack to the SCC serial controller
		to work with SGI-IP19 (in addition to DECstations).
		Adding the 'sdc1' instruction.
		Some progress on various SGI emulation modes.
20040325	Minor updates.
20040326	Fixed a 'madd' bug (r5900). NetBSD/playstation2 now reaches
		userland correctly.  And a simple fix which allows NetBSD
		timer interrupts to be triggered; NetBSD uses T_MODE_CMPE
		(compare), while Linux uses _OVFE (overflow).
20040328	Linux on Playstation 2 boots a bit. The Playstation 2
		graphics controller has been extended to work better with
		NetBSD, and to include some Linux support as well.
		Some interrupt handling enhancements on Playstation 2,
		needed for Linux' dma.
		128-bit loads and stores (lq and sq) are allowed, although
		the top half of quadwords are not modified by other
		instructions. (Linux uses lq and sq.)
		Big-endian X Windows servers now display correct rgb color,
		not bgr as before.
20040330	Some minor updates to the documentation.
20040401	Adding a dummy ps2 OHCI device.
20040402	Progress on the asc SCSI controller.
20040406	Hack to allow ./configure, make to work on HP-UX B.11.00
		on HPPA-RISC, gcc 3.3.2. (Does not work with HP's cc.)
		More progress on the asc SCSI controller. Fixing INQUIRY,
		adding READ_CAPACITY, adding READ. Works a bit with NetBSD
		and some (but not all) Ultrix kernels, on DECstation type 2.
		Adding WRITE, SYNCRONIZE_CACHE.
		Mounting disks works in NetBSD :-)  It is a bit buggy,
		though. Or something else is buggy.
20040407	The bug is triggered by gunzip during NetBSD/pmax install.
20040408	Fixing a bug (non-nul-terminated string) which caused X11
		cursors to not display on Solaris.
		Unnecessary X11 redraws are skipped (removes some weird
		delays that existed before), and cursors are redrawn on
		window exposure. (The cursor functionality has been moved
		from dev_fb.c to x11.c.)
20040411	Fixing the DC7085 device so that Ultrix doesn't behave weird
		if both tx and rx interrupts occur at the same time.
		More advancements on the asc SCSI controller.
		More disk image filename prefixes are now recognized; c (for
		CD-ROM, as before), d for disk, b for boot device, r for
		read-only, and 0-7 for scsi id.
		Mounting disks works in Ultrix. Installing to disk usually
		crashes for various reasons, but an OSF/1 install gets
		relatively far (similar to the NetBSD/pmax install).
20040412	Trying to find the bug.
20040415	Finally found and fixed the bug; SCSI reads and writes
		(actually, any data in or data out) can be split up into
		multiple DMA transfers. That stuff was only partially
		implemented, and the part that was implemented was buggy.
		It works now. NetBSD/pmax and Ultrix 4.3 seems to like
		the SCSI stuff enough to install almost all the way.
20040415 (more)	Adding a hack which allows a host's cdrom device to be used as
		a cdrom device inside the emulator, eg /dev/cd0c.
		Making the cycle counter int64_t instead of long, as a 'long'
		overflows too easily on 32-bit machines. (The bug is still
		there, though.)
		I've now verified that a full NetBSD/pmax install can be done.
		If using a PMAG-AA graphics board, startx brings up X :-)
		mips64emul can be compiled inside NetBSD inside mips64emul,
		and it can run NetBSD in that environment. (I'm getting
		dizzy... :-)
20040417	Moving some coprocessor stuff from cpu.c to coproc.c.
20040424	Adding a BT455 vdac for PMAG-AA. Black and white are now
		rendered correctly in Xpmax.
		Adding colormap support to the BT459 device, for PMAG-BA.
20040425	Fixing a buffer length bug, which caused an Ultrix 4.5
		install to bug out on an i386 host.
20040429	FPU experiments.
20040502	More FPU experiments.
		Speedup for exception debug messages:  in quiet mode, debug
		messages were still evaluated, which took a relatively
		large amount of time.
20040503	Most FPU stuff fixed, but there is at least one known bug
		left; ps axu in NetBSD triggers it (ps loops forever).
20040504	A default install of Ultrix 4.5 succeeded! It boots up with
		a graphical login.
		Fixing the keyboard repetition bug (a lk201 "up" (release)
		scancode is now sent after every key).
20040505	Both CR and LF now produce the same lk201 scancode, so that
		pressing 'enter' works as expected in Ultrix.
20040506	Adding a vaddr to paddr translation cache, causing a speedup
		of perhaps 50% or more.
20040507	Fixing PMAG-BA color for Ultrix. (Ultrix relies on interrupts
		coming from the TURBOchannel slot to update the palette.)
20040508	Fixing cursor positioning for PMAG-BA.
20040511	Prints current nr of instructions per seconds, not only
		average, when using -N.
20040515	Some more bintrans experiments.
20040606	Adding ARCBIOS GetReadStatus() and Read().
		Adding some instructions: tlt, tltu, tge, tgeu, tne.
20040607	Adding the dsub instruction.
		Some minimal progress on SGI-IP30 emulation.
		Applying a patch from Juli Mallett to src/file.c (I'm not
		sure yet if it breaks or fixes anything).
		Some minor fixes for SGI-IP22 (such as faked board revision
		numbers).
20040608	ll/sc should now fail if any unrelated load/store occurs.
		Minor changes to the configure script.
		Adding some ifdefs around code which is not often used
		(the mfhi/mflo delay, and the last_used TLB experimental
		code); this might cause a tiny speedup.
20040609	Minor fixes.
20040610	Various minor SGI fixes (64-bit ARCS stuff, progress on the
		CRIME/MACE interrupt system, and some other random things).
20040611	More crime/mace progress, and some more work on pckbc.
		KN5800 progress: adding a XMI->BI adapter device; a disk
		controller is detected (but it is just a dummy so far).
20040612	Adding "dev_unreadable", which simplifies making memory
		areas unreadable. (NetBSD on SGI-IP22 no longer detects
		non-existant hpc1 and hpc2 busses.)
		Implementing rudimentary support for IP22 "local0" and
		"local1" interrupts, and "mappable" local interrupts.
		Some progress on the WDSC SCSI controller on IP22, enough
		to let NetBSD get past the disk detection and enter
		userland!  :-)
		The zs (zilog serial) device now works well enough to let
		NetBSD/sgimips be interacted with on IP22. :-)  (Though
		it is very ugly and hardcoded.)
20040613	IP32 didn't work last night, because there were too many
		tick functions registered. That has been increased now.
		Trying out NetBSD/sgimips 2.0 beta kernels. There are some
		differences compared to 1.6.2, which I'm trying to solve.
		Interrupt fixes for IP32: _serial and _misc are different.
		Separation of IP22 (Full-house) and IP24 (Guiness).
20040614	Modifying the memory layout for IP20,22,24,26 (RAM is now
		offset by 128MB, leaving room for EISA registers and such),
		and moving around some code chunks. This is not well
		tested yet, but seems to work.
		Moving parts of the tiny translation cache, as suggested
		by Juli Mallett.  It seems that the speedup isn't as
		apparent as it was a few weeks ago, though. :-(
		Speedups due to not translating addresses into symbol
		names unless the symbol name is actually printed.
		Added support for loading old big-endian (Irix) ECOFF
		kernels (0x60 0x01 as the first two bytes).
20040615 (late)	Adding enough SGI IP20 (Indigo) support to let NetBSD 2.0
		enter userland :-)  No interrupt specifics are implemented
		yet, so it hangs while doing terminal output.
20040618	Experimenting with the WDSC SCSI controller for IP20,22,24.
20040620	Adding a program which converts SGI prom dumps from text
		capture to binary, and some hacks to try to make such an
		IP22 PROM to work better in the emulator.
20040621	Removing the Nintendo 64 emulation mode, as it is too
		uninteresting to support.
		Adding SCSI tape device support (read-only, so far).
		Fixing a bug which caused the cursor to be corrupted if new
		data was written to the framebuffer, but the cursor wasn't
		moved.
20040622(early)	Finally! Making progress on the SCSI tape stuff; when going
		past the end of a file, automagically switch to the beginning
		of the next.
20040622(late)	Trying to track down the last SCSI tape bugs.
		Removing _all_ dynamic binary translation code (bintrans),
		starting from scratch again.
20040623(early)	Performing a general code cleanup (comments, fixing stuff
		that led to compiler warnings, ...).
		Disabling MIPS16 support by default, and making it a
		configure time option to enable it (--mips16). This gives
		a few percent speed increase overall.
		Increasing performance by assuming that instruction loads
		(reading from memory) will be at the same page as the last
		load.  (Several percent speedup.)
		Moving the list of kernels that can be found on the net from
		README to doc/.
20040624	Finally! I found and fixed the bug which caused 'ps', 'top',
		'xclock', and other programs in NetBSD/pmax to behave weird.
		Increasing performance by a few percent by running as many
		instructions in a row as possible, before checking for
		hardware ticks.
		When booting from SCSI tapes on DECstation, the bootstring
		now contains 'tz' instead of 'rz'.
		Adding a second ARC machine mode, "Acer PICA-61", -A2.
		Disabling the support for "instruction delays" by default
		(it has to be enabled manually in misc.h now, but is never
		used anywhere anyway).
		Other minor optimizations (moving around stuff in the
		cpu struct in misc.h, and caching cpu->pc in cpu.c).
		Separating the tiny translation cache into two, one for
		code and one for data. This gives a few percent speed
		increase.
20040625(early)	I think now is a good time for a "feature freeze",
		to let the code stabilize and then make some kind of
		first release.
20040625(later)	Adding a -v (verbose) command line option. If -v is not
		specified, the emulator goes into -q (quiet) mode just before
		it starts to execute MIPS code.
20040627	The configure script now adds -fomit-frame-pointer to the
		compile flags if the $CC seems to be able to handle that.
		Found and fixed a serious interrupt bug in BT459 (Ultrix'
		behaviour required a hack, which was incorrect), so
		performance for machines using the PMAG-BA framebuffer is
		now improved.
		For X11 bitdepths other than 8 or 24, a warning message
		is printed at startup.
		A number of other minor fixes, optimizations, updated
		comments and so on.
		Adding a BUGS file, a list of known bugs.
		Adding a minimal man page, doc/mips64emul.1.
20040628	Hacks for faking the existance of a second level cache
		(ARCBIOS and other places).
		An important fix for dc7085: tx interrupts should happen
		before rx interrupts, not the other way around as it was
		before. (This speeds up NetBSD boot on DECstation, and
		fixes a bug which Ultrix triggered on heavy keyboard input.)
		A couple of other minor fixes.
		Framebuffer fix: there was a bug which caused the rightmost/
		bottom pixel to sometimes not be updated, when running in
		scaledown mode. This is now fixed.
		Adding a small program which removes "zero holes" from
		harddisk image files.
20040629	More minor fixes.
20040629(later)	Adding -A3 (NEC RISCstation 2200) (this is similar to
		the 2250 model that NetBSD/arc can already boot all the
		way into userland and be interacted with), and -A4
		(Deskstation Tyne).
		Some more minor fixes.
20040630	Adding support for 15 and 16 bits X11 framebuffers,
		and converting from XYPixmap to ZPixmap (this fixes the
		problem of updates appearing in "layers" on some X
		servers).
		The pixels in the mouse cursor (for BT459) are now colored
		as the emulated OS sets them, although no transparency
		masking is done on the edges of the cursor yet. (In plain
		English:  the mouse cursor is no longer just a white solid
		square, you can actually see the mouse cursor image
		on the white square.)

==============  RELEASE 0.1  ==============

20040701	The -j option now takes a name, the of the kernel as passed
		on to the bootloader.  ("netbsd" is the default name.)
		Adding support to load bootstrap code directly from a disk
		image, for DECstation.  Both NetBSD/pmax and Ultrix boot
		straight of a disk image now, with no need to supply a
		kernel filename on the command line.  (Ultrix still needs
		-j vmunix, though, to boot from /vmunix instead of /netbsd.)
20040702	Minor bugfix (some new untested code for X11 keypresses was
		incorrect).
20040702(later)	Adding an ugly hack for CDROMs in FreeBSD; if an fread() isn't
		done at a 2048-byte aligned offset, it will fail. The hack
		tries to read at 2048-byte aligned offsets and move around
		buffers to make it work.
		Adding video off (screen blanking) support to BT459.

==============  RELEASE 0.1.1  ==============

20040702(later)	Cleanup to remove compiler warnings (Compaq's cc, Solaris' cc,
		and gcc 3.3.3/3.3.4 in Linux), mostly by putting ULL on large
		numeric constants.
		Better support for scaledown of BT459 cursors, but still not
		color-averaging.
		Beginning the work on adding better memory latency support
		(instruction delays), enabled by the --delays configure option.
20040703	Modifications to the configure script so that a config.h file
		is created, containing things that were passed along as
		-Dxxx on each cc command line before.
		More work on instruction latency support; trying to separate
		the concepts of nr of cycles and nr of instructions.
20040704	Working on R2000/R3000 caches.
		Adding a '--caches' option to the configure script.
		Various small optimizations.
		R3000 caches finally work. (I know that there is at least one
		bug, regarding interrupt response.)
20040705	Working on the 'le' device, and on a generic (device
		independant) networking framework. le can transmit and receive
		packets, and the network framework fakes ARP responses from a
		fake gateway machine (at a fixed ip address, 10.0.0.254).
		Adding a '-c' command line option, which makes emulated_hz
		automatically adjust itself to the current number of emulated
		cycles per host CPU second (measured at regular intervals).
20040707	Removing the '-c' option again, and making it the default
		behaviour of the emulator to automatically adjust clock
		interrupts to runtime speed (as long as it is above 1 MHz).
		(This can be overridden by specifying a static clock rate with
		the -I option.)
		Updating the doc/ stuff a bit.
		Generalization of the DECstation bootblock loading, to work
		with Sprite/pmax. Lots of other minor modifications to make
		Sprite work, such as adding support for DECstation "jump table"
		PROM functions, in addition to the old callback functions.
		Sprite boots from a disk image, starting the kernel if the
		argument "-j vmsprite" is used, but it seems to not like the
		DBE exceptions caused by reading empty TURBOchannel slots. :-/
20040708	Minor changes and perhaps some tiny speed improvements.
		The Lance chip is (apparently) supposed to set the length of
		received packets to len+4. (I've not found this in any 
		documentation, but this is what NetBSD expects.) So now, ICMP
		echo replies work :-)  UDP works in the outgoing direction,
		in the incoming direction, tcpdump can see the packets but they
		seem to be ignored anyway. (Weird.)
		Adding a separate virtual-address-to-host-page translation
		cache, 1-entry for loads, 1-entry for stores. (For now, it
		only works on R4000 as there are conflicts with cache usage
		on R3000).
		Changing the lower clock speed bound from 1 MHz to 1.5 MHz.
20040709	Incoming UDP checksums were wrong, but are now set to zero
		and NetBSD inside the emulator now accepts the packets (eg.
		nameserver responses).  Host lookups and even tftp file
		transfers (using UDP) work now :-)
		Adding a section on Networking to the Technical documentation,
		and a preliminary NetBSD/pmax install instruction for network
		installs to the User documentation.
		Some updates to the man page.
20040709(later)	Fix to the TURBOchannel code to allow Sprite to get past the
		card detection. Seems to still work with Ultrix and NetBSD.
		This also makes Linux/DECstation properly recognize both the
		Lance controller and the SCSI controller. Linux 2.4.26 from
		Debian boots nicely in framebuffer mode :-)
20040710	Some bits in the KN02 CSR that were supposed to be readonly
		weren't. That has been fixed, and this allows Linux/DECstation
		to get past SCSI detection. :-)
		Minor updates to the ASC controller, which makes Linux and
		OpenBSD/pmax like the controller enough to be able to access
		SCSI devices. OpenBSD/pmax boots from a disk image for the
		first time. :-)  Linux detects SCSI disks, but I have no
		bootable Linux diskimage to test this with.
		Updating the doc/ to include instructions on how to install
		OpenBSD/pmax onto a disk image.
		Naively added a PMAGB-BA (1280x1024x8) in hopes that it would
		basically be a PMAG-BA (1024x864x8) in higher resolution,
		but it didn't work that way. I'll have to look into this later.
		Adding a -o option, useful for selecting '-s' (single user
		mode) during OpenBSD install and other things.
		After a lot of debugging, a serious bug related to the tiny
		cache was found; Linux just changes the ASID and returns when
		switching between processes in some occasions without actually
		_writing_ to the TLB, and I had forgotten to invalidate the
		tiny cache on such a change.
20040711(early)	I've been trying to repeat the OpenBSD install from yesterday,
		but appart from the first initial install (which was
		successful), I've only been able to do one more. Several
		attempts have failed with a filesystem panic in the middle
		of install. I'm not sure why.
20040711	I found the "bug": wget downloaded the simpleroot28.fs.gz file
		as read-only, and gunzip preserved those flags. Thus, OpenBSD's
		installer crashed as it didn't get its writes through to the
		disk.
		Parts of the 1280x1024x8 PMAGB-BA graphics card has been
		implemented, it works (unaccelerated) in NetBSD and OpenBSD,
		but Ultrix does not seem to like it.
		Cleaned up the BT459 cursor offset stuff a bit.
		Trying to make the emulated mouse coordinates follow the host's
		mouse' coordinates (for lk201, DECstation), by
		"de-accelerating" the data sent to the emulated OS.
20040711(later)	Fix so that Sprite detects the PMAG-BA correctly.
		Adding some stuff about NFS via UDP to the documentation.
		Fixed the 'update flag' for seconds, so now Sprite doesn't
		crash because of timer-related issues anymore.
		Fixing KN02 interrupt masks a bit more, to make Sprite not
		crash. Sprite now runs quite well.
20040712	Working on IP/UDP fragementation issues. Incoming UDP packets
		from the outside world can now be broken up into fragments
		for the guest OS. (This allows, for example, OpenBSD/pmax to
		be installed via nfs.)  Outgoing fragmented packets are NOT
		yet handled.
		Linux doesn't use 64-bit file offsets by default, which is
		needed when using large disk images (more than 2GB), so the
		configure script has now been modified to add necessary
		compiler flags for Linux.
20040713	Trying out some minor optimizations.
		Refreshing the UDP implementation in src/net.c a little.
20040714	Updating the documentation a little on how to experiment
		with a Debian Linux install kernel for DECstations.
		A 'mini.iso' Linux image for DECstation has different fields
		at offsets 0x10 and 0x14, so I'm guessing that the first is
		the load address and the second is the initial PC value.
		Hopefully this doesn't break anything.
		Some initial TCP hacks, but not much is working yet.
		Some updates for IP30:  The load/store 1-entry cache didn't
		work too well with IP30 memory, so it's only turned on for
		"MMU4K" now. (This needs to be fixed some better way.)
		Adding a hack which allows Linux/Octane to use ARC write()
		and getchild() on IP30. Linux uses ARCBIOS_SPB_SIGNATURE as a
		64-bit field, it was 32-bit before.
		Making ugly hacks to the arcbios emulation to semi-support
		64-bit equivalents of 32-bit structures.
20040716	Minor fixes to the configure script (and a few other places)
		to make the sources compile out-of-the-box on HP-UX (ia64
		and HPPA), old OpenBSD/pmax (inside the emulator itself), and
		Tru64 (OSF/1) on Alpha.
		A couple of other minor fixes.
20040717	A little TCP progress; OpenBSD/pmax likes my SYN+ACK replies,
		and tries to send out data, but NetBSD/pmax just drops the
		SYN+ACK packets.
		Trial-and-error led me to change the 64-bit ARCS component
		struct again (Linux/IP30 likes it now). I'm not sure about all 
		of the offsets yet, but some things seem to work.
		More 64-bit ARCS updates (memory descriptors etc).
		Better memory offset fix for IP30, similar to how I did it for
		IP22 etc. (Hopefully this doesn't break anything else.)
		Adding a MardiGras graphics controller skeleton for SGI-IP30
		(dev_sgi_mardigras.c).
		Thanks to Stanislaw Skowronek for dual-licensing mgras.h.
		Finally rewrote get_symbol_name() to O(log n) instead of O(n)
		(Stanislaw's Linux kernel had so many symbols that tracing
		with the old get_symbol_name() was unbareably slow).
		Removing all of the experimental tlbmod tag optimization code
		(the 1-entry load/store cache), as it causes more trouble than
		the performance gain was worth.
20040718	The MardiGras device works well enough to let Linux draw the
		SGI logo and output text.
		A bunch of other minor changes.
20040719	Trying to move out all of the instruction_trace stuff from the
		main cpu loop (for two reasons: a little performance gain,
		and to make it easier to add a GUI later on).
20040720	Finally found and fixed the ethernet/tcp bug. The hardware
		address is comprised of 6 bytes, where the _first_ byte should
		have a zero as the lowest bit, not the last byte. (This causes
		NetBSD and Linux running in the emulator to accept my SYN+ACK
		packets.)
		Getting the first nameserver address from /etc/resolv.conf.
		(This is not used yet, but could be useful if/when I add
		internal DHCP support.)
		Working more on the TCP stuff; TCP seems to be almost working,
		the only immediate problem left is that the guest OS gets
		stuck in the closing and last-ack states, when it shouldn't.
		It is now possible to install NetBSD and OpenBSD via ftp. :-)
20040721	Trying to fix the last-ack bug, by sending an RST after the
		end of a connection. (Probably not a correct fix, but seems
		to work?)
		Adding a my_fseek() function, which works like fseek() but
		with off_t instead of long, so that large disk images can
		be used on systems where long is 32 bits.
20040722	Trying to fix some more TCP related bugs.
20040725	Changing the inlined asm statement in bintrans_alpha.c into
		a call to a hardcoded array of bytes that do the same thing
		(an instruction cache invalidation). This allows the same
		invalidation code to be used regardless of compiler.
		Some other minor changes.
20040726	Minor updates. The configure script is now more verbose.
		A Debian/IP22 Linux tftp boot kernel requires ARCS memory to
		be FreeMemory, not FreeContiguous. (This should still work with
		other SGI and ARC OSes.)
		Fix for ARCS write(), so it returns good write count and
		success result (0).
		Some hacks to the IP22 memory controller, to fake 72MB RAM
		in bank 0.
		The IP22 Debian kernel reaches userland (ramdisk) when run
		with -G24 -M72 -CR4400, if a special hack is done to the
		zs device.
20040730	Removing mgras.h, as I'm not sure a file dual-licensed this way
		would work. (Dual-licensing as two separate files would work
		though.)
		Preparing for the upcoming release (0.2).
20040801	Fixing the 512 vs 2048 cdrom sector size bug; I hadn't 
		implemented the mode select SCSI command. (It still isn't
		really implemented.)
		A bug which crashes the emulator is triggered when run with
		new NetBSD 2.0_BETA snapshots on a Linux/i386 host. I'm not
		sure why.
		UDP packets sent to the gateway (at 10.0.0.254) are now
		forwarded to the machine that the host uses as its nameserver.
		Some other minor fixes.

==============  RELEASE 0.2  ==============

20040803	A post-3.5 OpenBSD/sgimips kernel snapshot with ramdisk seems
		to boot fine in the emulator, all the way to userland, and
		can be interacted with.
		Adding a -y option, used to set how many (random) instructions
		to run from each CPU at max (useful for SMP instruction
		interleave experiments).
		Importing a 8x16 console font from FreeBSD (vt220l.816).
		Adding a skeleton for a 80x25 text console device (dev_vga),
		useful for some ARC modes. (Character output is possible, but
		no cursor yet.)
		Adding a dev_zero device (returns zeroes on read).
		OpenBSD/arc 2.3 can get all the way to userland with -A4 (if
		the wdc devices are commented out) but bugs out there, probably
		because of interrupt issues.
		Adding a -A5 ARC emulation mode (Microsoft-Jazz, "MIPS Magnum")
		which NetBSD seems to like. No interrupt specifics yet, so
		it hangs while waiting for SCSI.
20040804	Some dev_mp updates.
		The -y switch has to do with number of cycles, not number
		of instructions; variable names have been changed to reflect
		this.
20040805	Minor updates. Adding some more CPU types/names, but they
		are probably bogus.
		Adding a MeshCube emulation mode. Just a skeleton so far, but
		enough to let a Linux kernel print some boot messages.
		Adding the 'deret' instruction.
20040806	Adding include/impactsr-bsd.h (a newer version of what was in
		mgras.h before, and this time with only a BSD-style license),
		but it is not used yet.
20040810	Some Au1500 updates.
20040811	Adding the 'clz', 'clo', 'dclz', and 'dclo' special2 (MIPS32
		and MIPS64) instructions.
		More Au1500 updates.
20040812	Using fseeko(), when it is available.
		Other minor updates.
		Adding a NetGear WG602 emulation mode skeleton (-g); after
		a lot of trial and error, a Linux kernel (WG602_V1715.img)
		gets all the way to userland, but hangs there.
20040818	Adding signal handlers to better cope with CTRL-Z and CTRL-C.
		Adding a simple interactive single-step debugger which is
		activated by CTRL-C. (Commands so far: continue, dump, help,
		itrace, quit, registers, step, trace, version)
20040818(later)	Adding a 'tlbdump' debugger command, and some other minor
		fixes.
20040819	Minor updates. Adding an 'unassemble' debugger command.
20040822	Minor updates to the regression testing framework.
20040824	Minor updates based on feedback from Alec Voropay
		(configure script updates for Cygwin and documentation).
20040826	Minor updates.
		Adding a cursor to the VGA text console device.
		Changing all old 11:22:..55:66 ethernet macs to 10:20..60,
		still hardcoded though.
20040828	Minor updates.
20040829	mips64emul is 1 year old today :-)
20040901	tests/README now lists "all" MIPS opcodes. This list should
		be updated whenever a new opcode is implemented, or when a
		regression test is added. (A combination of instructions from
		the TX79 manual, the GNU assembler, and the MIPS64 manual).
		Hopefully I haven't missed too many.
		Adding a section on regression testing to doc/technical.html.
20040902	Finally beginning the work on separating out the stuff from
		main.c into a "struct emul". Very time-consuming.
		Some minor fixes for LL/SC on R10000.
20040905	Moving more stuff from main.c into struct emul. Unfortunately,
		it seems that this causes a slowdown of the emulator.
		Userland emulation is now only used if --userland is used
		when running configure.
		Modifying src/symbol.c to not use global variables.
20040906	Minor update.
20040914	Using $COPTIM when detecting which compiler flags to use in
		the configure script. (This makes sure that combinations of
		flags should work.)
		There'll probably be a 0.2.1 release some time soon, but I'll
		do some more clean-up first.
		Minor update to the detection of ECOFF files, but I don't like
		it; sometimes the endianness of the magic value seems to be
		swapped, but it doesn't have to do with endianness of the
		actual data?
20040916	Minor updates. Adding an Example section to the manpage, but
		as I'm not really familiar with manpage formatting, it will
		need to be rewritten later.
20040917	Finally making the coprocessor instructions disassemblable
		even when not running.
		Doing some testing for the 0.2.1 release.

==============  RELEASE 0.2.1  ==============

20040923	Updating the documentation about how to (try to) install
		Debian GNU/Linux.
20040924	Some more updates to the documentation.
20040925	Adding overflow stuff to 'add' and 'sub'.
20040926	Minor updates: possibly a fix to 'sltiu' (the imm value
		should be treated as signed, and then converted to unsigned,
		according to the MIPS64 manual), and removing the
		'last_was_rfe' stuff (again).
		OpenBSD/arc used speed-hack jumps with other deltas than just
		+/- 1 (it used -3 iirc), so the jump speedhack should now
		support any delta. Also adding bgtzl and blezl as possible
		instructions for the speed-hack jumps. (This needs to be
		tested more.)
20040928	Minor updates. Some ARC stuff ("arcdiag" runs now).
		cpu_register_dump() now also dumps coprocessor registers.
20040929	More ARC updates. Making the code look a tiny bit nicer
		than before. "arcdiag.ip22" works for -G22 (SGI-IP22).
		Apparently the overflow support in the 'add' instruction
		was incorrect, so I disabled it.
20041002	Trying to install Ultrix in the emulator, but the installer
		crashes; found (and fixed) the bug rather quickly: the "fix"
		I implemented a few days ago for the 'sub' instruction
		(according to the MIPS64 manual) caused the bug.
20041004	Changing the behaviour of the -j command line option. The
		default is now "" (or taken from the last filename given on
		the command line), not "netbsd". In practice, this doesn't
		change much, except that -j netbsd.pmax is no longer needed
		when installing NetBSD.
		Adding a COMPILE_DATE string to config.h.
20041007	Adding a NEC RISCserver 4200 model (-A6), and some more
		updates to the ARC component tree generator.
20041008	The 'll' instruction should be signed, not unsigned as before.
		This (and some other minor fixes) causes Irix on SGI-IP32 (O2)
		to actually boot far enough to print its first boot messages :)
		Working on some new dynamic bintrans code. Enough is now
		implemented so that the 'nop' instruction is translated
		and there is support for Alpha, i386 and UltraSparc backends,
		but performance is about 50% worse than when running without
		bintrans. (This is as expected, though.)
20041009	Minor updates to the documentation.
		Using mprotect() to make sure that the code created dynamically
		by the bintrans subsystem is allowed to be executed. (This
		affects newer OpenBSD systems, and possibly others.)
		The translated code chunks now only get one argument passed to
		them, the (struct cpu *) of the current cpu.
20041010	Hack to dev_le.c which makes Ultrix accept the initialization
		of the LANCE controller. (This goes against the LANCE
		documentation though.)
		In src/net.c, a fix for Ultrix (which seems to send larger
		ethernet packets than the actual TCP/IP contents). The hack to
		dev_le.c and this fix is enough to let Ultrix access the
		Internet.
		For DECstation, when booting without a disk image (or when
		"-O" is used on the command line), use "tftp" instead of "rzX"
		for the boot string.
20041011	Adding cache size variables to the emul struct, so that these
		can be set on a per-machine basis (or potentially manually
		on the command line).
20041012	Mach/PMAX now passes the LK201 keyboard self-test (although
		the keyboard ID is still bogus).
20041013	Minor updates.
		Hacks to the ASC SCSI controller for Mach/PMAX, hopefully this
		will not break support for other OSes.
20041014	Minor fix to src/emul.c for reading bootblocks at the end of
		a disk or cdrom image (thanks to Alexandru Lazar for making me
		aware of this).
		Adding "gets()" to src/dec_prom.c.
		Working a bit on ARC stuff. Importing pica.h from NetBSD.
		Minor updates to the ARC component tree for PICA-61.
		Adding a dev_jazz.c (mostly for PICA-61).
		Renaming dev_jazz.c into dev_pica.c. Working on PICA timer
		and interrupt specifics.
20041016	Adding some dummy entries to lk201.c to reduce debug output.
		Some bintrans updates (don't run in delay slots or nullified
		slots, read directly from host memory and not via memory_rw(),
		try mmap() before malloc() at startup, and many other minor
		updates).
		Adding bintrans_mips.c for 64-bit MIPS hosts, but it is not
		used yet.
20041017	Minor updates.
20041018	Update to dev_mc146818 to allow Mach to boot a bit further.
		The "hardware random" in dev_mp.c now returns up to 64 bits
		of random.
20041019	Minor updates to the way cache sizes are used throughout the
		code. Should be mostly ok for R[234]x00.
		src/file.c now loads files using NO_EXCEPTIONS. Whether this
		is good or bad, I'm not sure.
20041020	Adding a Linksys WRT54G emulation skeleton (-H).
20041021	Minor updates.
		R1[024]000 cache size bits in the config register should now
		be ok.
		Trying to make dev_asc.c work better with PICA.
		More work on PICA interrupts (but they are broken now).
20041022	Generalizing the dev_vga text console device so that it can be
		used in other resolutions than just 80x25. Works with
		OpenBSD/arc.
		emul->boot_string_argument is now empty by default (except
		for DECstation modes, where it is "-a").
		Speedup of dev_ram by using mmap() instead of malloc().
		Using mmap() in memory.c as well, which reduces memory usage
		when emulating large memory sizes if the memory isn't actually
		written to.
20041023	Minor updates.
20041024	Updates to the PC-style keyboard controller, used by PICA.
		Updates to the PICA (Jazz) interrupt system. Both NetBSD/arc
		and OpenBSD/arc now reach userland with PICA emulation, and
		can be interacted with (there are a few programs on the
		INSTALL kernel ramdisks). In the case of OpenBSD, a VGA text
		console and PC-style keyboard controller is used, NetBSD
		runs on serial console.
		Adding a framework for DMA transfer for the ASC SCSI
		controller.
		Implementing a R4030 DMA controller for PICA, enough to let
		OpenBSD/arc and NetBSD/arc be installed on an emulated
		Pica. :-)
		Updates to the documentation.
20041025	Working on ISA interrupts for PICA.
		Adding an Olivetti M700 emulation mode (-A7).
		Better separation of PICA and M700 stuff (which I accidentally
		mixed up before, I thought the M700 Linux kernel would 
		also work on PICA because it almost booted).
		Writing a skeleton G364 framebuffer for M700, enough to show
		the Linux penguin and some text, although scrolling isn't
		correctly implemented yet.
		Adding a dummy SONIC (ethernet) device, dev_sn, for PICA.
		Fixing the passing of OSLOADOPTIONS for ARC, the default is
		now "-aN" which works fine with OpenBSD/arc and NetBSD/arc.
20041027	Minor updates.
20041029	Adding a Sony NeWS "newsmips" emulation mode skeleton (-f).
		Found and fixed a bug which prevented Linux/IP32 from running
		(the speed-hack-jump-optimization fix I made a few weeks ago
		was buggy).
		Adding the trunc.w.fmt and trunc.l.fmt instructions, although
		the are probably not really tested yet.
		Changes to how floating point values are handled in
		src/coproc.c, but right now it is probably very unstable.
20041101	I had accidentally removed the instructions on how to install
		Ultrix from doc/index.html. They are back now.
		Adding a -Z option, which makes it easier to run dual- or
		tripple-head with Ultrix. (Default nr of graphics cards
		without -X is 0, with -X is 1.)
		Minor update which makes it possible to switch to the left
		monitor when running tripple-head, not just right as before.
		When using more than one framebuffer window, and the host's
		mouse cursor is in a different window than the emulated mouse
		cursor, the emulated mouse will now try to move "very far",
		so that it in practice changes screen.
		Running Ultrix with dual- and tripple-head now feels really
		great.
20041101(later)	OpenBSD/arc and Linux/Olivetti-M700 don't both work at the
		same time with the speed-hack stuff. So, from now on, you
		need to add -J for Linux, and add nothing for openbsd.
20041102	Minor update for OSF/1 V4.0 (include sys/time.h in src/net.c
		and add -D_POSIX_PII_SOCKET to the C compiler flags).
20041103	Minor updates for the release.
		For some reason, Mach/PMAX caused the emulator to bug out on
		SunOS/sparc64 (compiled in 64-bit mode); a minor update/hack
		to dev_asc fixed this.

==============  RELEASE 0.2.2  ==============

20041103	Minor updates.
20041104	Minor updates.
20041105	Running with different framebuffer windows on different X11
		displays works now (even with different bit depths and
		endiannesses on different displays). A new command line option
		(-z) adds DISPLAYs that should be used.
		Update regarding how DECstation BT459 cursors are used;
		transparency :-) and some other bug fixes.
20041106	More bt459 updates. The cursor color seems to be correct for
		NetBSD, OpenBSD, Ultrix, and Sprite.
		Some minor bintrans updates (redesigning some things).
20041107	More bintrans updates (probably broken for non-Alpha targets).
		Moving doc/mips64emul.1 to man/.
20041108	Some updates.
20041109	More updates. Bintrans experiments mostly.
20041110	Some minor bintrans updates.
20041111	Minor updates.
20041112	A little rewrite of the bintrans system (again :-), this time
		a lot more naďve and non-optimizing, in order to support delay
		slots in a much simpler way.
		Ultrix 4.5 boots into a usable desktop on my home machine in
		3min 28sec, compared to 6-8 minutes without bintrans.
20041113	Some minor bintrans updates.
20041114	More bintrans updates. Ultrix now boots in exactly 3 minutes
		on my home machine.
20041115	More bintrans updates.
20041116	Bintrans updates.
20041117	Working on dev_dec_ioasic and related issues.
		Adding support for letting translated code access devices in
		some cases (such as framebuffers).
20041118	Moving some MIPS registers into Alpha registers, which gives
		a speed improvement.
		Beginning to write an i386 bintrans backend. Skeleton stuff
		works, lui, jr/jalr, addiu/daddiu/andi/ori/xori, j/jal,
		addu/daddu/subu/xor/or/nor/and.
20041119	dsubu/sll/srl/sra, rfe,mfc0,dmfc0, beq,bne, delayed branches.
		Some load/store (but not for bigendian emulation yet.)
		Time to reach Ultrix 4.5's graphical login on a 2.8 GHz Xeon
		host is now down to 20 seconds!
		Adding bgez, bltz, bgtz, and blez to the i386 backend.
20041120	Minor updates (bintrans related mostly).
		Time to reach Ultrix login on the Xeon is now 11 seconds.
		Adding 'mult', 'multu' and a some parts of mtc0 to the Alpha
		backend.
		The transparency updates to the X11 cursor support made the
		OpenBSD/arc cursor disappear; that has been fixed now.
		Unfortunately, something with Acer Pica emulation is broken
		when bintrans is enabled.
20041121	Making tlbwr, tlbwi, tlbp, tlbr callable directly from
		translated code.
		Adding sltiu, slti, slt, and sltu to the i386 backend.
20041122	More bintrans updates.
		With the Alpha backend, the status and entryhi registers
		can (in some cases) be written without exiting to the main
		loop. Ultrix boot time until a usable desktop is reached
		is about 1 min 35 seconds on the 533 MHz pca56.
		Adding srlv, srav, and sllv to the i386 backend.
20041123	Removing the special handling of high physical addresses for
		DECstation emulation from the main memory handling code, and
		replacing it with a mirror device instead. (This results in
		a tiny increase in performance, and cleaner code.)
		Various minor updates.
20041124	Ripping out _all_ bintrans load/store code, because I have
		a new idea I'd like to try out.
		A total rewrite of the load/store system. It works when
		emulating 32-bit MIPS, but not for 64-bit code yet.
		Some minor updates to the dev_fb, but no speed improvement.
		Making the 'le' ethernet device' SRAM work with bintrans.
20041125	Various updates.
		Adding a little "bootup logo" to the framebuffer.
		There is now one translate_address() for R3000-style MMUs,
		and one for the other types. (This gives a tiny speed
		improvement.)
20041126	Minor updates, bintrans.
		Fixing the bug which caused OpenBSD/arc (R4000) to bug out;
		it was introduced between the 7:th and 10:th of November
		when moving up the check for interrupts to above the code
		which runs bintrans code, in src/cpu.c.
		Adding movn and movz to the Alpha bintrans backend.
20041127	Various minor updates.
20041128	Making the R2000/R3000 caches work with bintrans, even in
		isolated mode. (Not true cache emulation, but it works with
		NetBSD/pmax, OpenBSD/pmax, and Ultrix.)
		Making the default cache size for R3000 4KB instr, 4 KB data;
		a real R3000 could have 64KB each, but emulated OSes run
		faster when they think the cache is smaller :-)
		Updates to the i386 backend: the nr of executed instructions
		is now placed in ebp at all times, and some support for
		mtc0 similar to how it is done in the Alpha backend has been
		added. A full NetBSD/pmax 1.6.2 install can now be done in
		5 minutes 35 seconds, on a 2.8 GHz Xeon host (with -bD2 -M20).
		Adding mult and multu to the i386 bintrans backend.
		Reducing the number of malloc/free calls used by the
		diskimage subsystem.
20041129	Minor updates to the Alpha bintrans backend.
20041130	Trying to fix the bug which prevents Linux from working
		with bintrans. It _seems_ to work now. (Pages could in some
		cases be written to after they were translated, but that
		has been fixed now.)
		A couple of other minor fixes.
		Minor updates to the Alpha backend (directly using Alpha
		registers in some cases, instead of loading into temporaries).
		Updates to the i386 backend (special hacks for 32-bit
		MIPS emulation, which are fast on i386, for example only
		updating half of the pc register).
20041201	More updates to the i386 backend, similar to those yesterday.
		Preparing for release 0.2.3.
		Adding a generic load/store mechanism, which is used when the
		32-bit optimized version cannot be used (for R4000 etc).

==============  RELEASE 0.2.3  ==============

20041202	If ALWAYS_SIGNEXTEND_32 is defined in misc.h, and an
		incorrectly extended register is detected, the emulator now
		exits instead of continues.
		Removing the LAST_USED_TLB_EXPERIMENT stuff.
		Minor updates to work better with Windows NT's ARCINST.EXE;
		printing 0x9b via arcbios becomes ESC + '[', and the ARC
		memory descriptor stuff has been generalized a bit more.
		Adding arbios hacks for Open(), Seek(), GetRelativeTime(),
		and Read() to allow WinNT's SETUPLDR to read the filesystem
		on the diskimage used for booting.
20041203	Adding a terminal emulation layer which converts arcbios
		stdout writes to "VGA text console" cell characters. Seems
		to work with Windows NT and arcdiag.
		Adding a 8x8 font to dev_vga.
		Adding more ARC components to the component tree (for PICA
		emulation).
20041204	Minor updates.
		More updates to dev_vga. Adding a 8x10 font.
		Adding a hack so that the framebuffer logo is visible at
		startup with dev_vga. (It disappears at the first scroll.)
		A minor fix for a bug which was triggered when running
		dual- or tripple-head, on 2 or 3 actual X11 displays.
20041205	Fixing a bintrans bug.
		Some other minor updates (some of them bintrans related).
20041206	Moving the web page to http://gavare.se.
		Adding a hack for mmap() which supports anonymous mapping
		using /dev/zero, but not using MAP_ANON{,YMOUS}.
		Separating out opcodes.h, cop0.h, and cpu_types.h from misc.h.
20041207	Minor bintrans update. (In some cases, it isn't necessary
		to return to the main loop, when translating from a new page.)
		Some other minor i386 bintrans backend optimizations.
		And some other minor updates.
		i386 backend update: the lowest 32 bits of the pc register
		are now placed in an i386 register.
20041208	Adding GetConfigurationData() and some support for config
		data, to src/arcbios.c.
		Adding a bogus 0xbd SCSI command (used by Windows NT). It is
		not listed in http://www.danbbs.dk/~dino/SCSI/SCSI2-D.html.
		If the framebuffer cursor contains more than 1 color, then
		the host's X11 cursor disappears. (Nice for DECstation
		emulation with emulated X.)
		For ARC and SGI emulation, if an exception occurs before an
		exception handler is installed, the emulator now exits
		nicely (as suggested by Alec Voropay).
		A couple of minor updates to the ARCBIOS emulation subsystem.
		The single step debugger is now automatically entered when
		all CPUs have stopped running, unless there was a clean
		shutdown of some kind (PROM halt() call, or similar).
		Adding a -V option for starting up in a paused state, into
		the single-step debugger.
		Adding a note about 'mmon' to the documentation
		(http://www.brouhaha.com/~eric/software/mmon/).
20041209	Fixes to devices/console.c which makes cursor keys and such
		a bit more reliable.
		ARCBIOS hack/update which creates memory descriptors _after_
		loading the executable. (Seems to work with OpenBSD/arc,
		NetBSD/arc, arcdiag, IRIX, NetBSD/sgimips, OpenBSD/sgi, and
		some Windows NT executables.)
		ARCBIOS support for cursor keys (ESC + '[' ==> 0x9b).
		A bintrans update (for 32-bit emulation) which speeds up
		jumps between pages, if code is already translated.
		Changing the default bintrans cache from 20 to 24 MB.
20041210	Optimizing unaligned load/stores a little bit in src/cpu.c.
		Omiting the check for nr of executed bintrans instructions
		on some forward jumps.
		Adding the 'syscall' and 'break' instructions to the
		bintrans backends.
		Allowing more bits of the status register to be written to
		from within inside translated code, on R3000.
		Getting rid of the final pixel when hiding the host's mouse
		cursor.
		store_buf() now copies data 8 or 4 bytes at a time, when
		possible. (This speeds up emulated ROM disk reads, etc.)
		Tiny bug fix: coprocessor unusable exceptions are now also
		generated (for coproc 1..3) even when in kernel mode, if the
		coprocessors are not enabled. This allows a Debian installation
		to proceed further than before. (It's still very unstable,
		though.)
20041212	Updating doc/index.html with better Debian installation
		instructions.
		If SLOWSERIALINTERRUPTS is defined at compile time, interrupts
		from the dc7085 device will not come as often as they normally
		do. This makes Debian seem more stable.
		Decreasing the bintrans cache to 20 MB again.
		Updating some files in preparation for a 0.2.4 release.
20041213	Updating the docs on how to install NetBSD 2.0/pmax, and also
		some updates to the section on installing Debian.
		32-bit bintrans backend optimization: don't inline large
		chunks of code, such as general jumps.
20041214	Minor fix for coproc unusable for R4000 (it's the PC that,
		matters, not the KSU bits).
		Separating out the debugger from emul.c into debugger.c.
		Rewriting parts of the debugger.
		Removing the -U command line option, as it wasn't really
		useful. Also removing the -P option.
		Renaming all instances of dumppoint to breakpoint, as that
		is what it really is.
		When a breakpoint is reached, the single-step debugger is
		entered, instead of just turning on instruction trace.
		Adding a 'breakpoints' debugger command.
		Better fix for coproc unusable on R4000: the KSU bits matter,
		but the ERL and EXL bits override that.
		Fix which allows Debian to boot directly from a disk image
		(with DELO). (It reads multiple separate areas from disk.)
		Update to the SLOWSERIALINTERRUPTS stuff, making it even
		slower.
		Fixes based on feedback from Alec Voropay (-Q with ARC
		emulation skips the setup of arcbios data structures in
		memory, and no sign-extension _after_ writing a 32-bit
		value to a 64-bit coproc 0 register).
		Adding a 'devices' command to the debugger.
		The 'registers' and 'tlbdump' commands now take an optional
		argument (a cpu id).
		Adding rudimentary tab-completion and cursor key stuff to
		debugger_readline().
		Adding some more debugger commands: 'bintrans' and 'machine'.
20041215	Adding a 'devstate' command; implementing a skeleton for a
		state function for the bt459 device.
		Implementing yet another variant of the SLOWSERIALINTERRUPTS
		stuff.
		Implementing more of the different exception offsets (taking
		CAUSE_IV and STATUS_BEV into account).
		hpc_bootinfo should now be correctly filled on big-endian
		hosts.
		Always shift left by 12, not by pageshift, to get physical
		addresses on MMU4K etc. (Thanks to Alec Voropay for noticing
		this.)
20041216	The KN02's CSR can now be read from bintranslated code.
		Adding a dummy dev_sgi_mec.
20041217	The default framebuffer and model settings for -F (hpcmips)
		should now be almost like Cassiopeia E-500.
		Changing -DSLOWSERIALINTERRUPTS into a command line option, -U.
20041218	Continuing a little bit on the mec controller.
		Removing lots of #include <math.h> that weren't really used.
20041219	Fixing stuff that broke because of the pageshift bugfix.
		Adding an argument to the s (step) debugger command, for doing
		more than 1 step at a time.
		ARCBIOS components representing disk images are now created
		to actually match the disk images in use, and some other
		arcbios-related updates; adding a dummy GetComponent().
		Adding a 'lookup' command to the debugger, for symbol lookups.
		Adding a "NEC Express RISCserver" mode (NEC-R96, -A8).
		Adding a dummy ARCBIOS GetFileInformation(), GetTime(), and
		SetEnvironmentVariable().
20041220	Improved command line editing (including command history)
		in the debugger.
		Separating some more .h files from each other, and fixing
		some Solaris compiler warnings.
20041221	Minor updates.
20041222	Minor updates; hpcmips (BE300, VR41xx) stuff.
		The 'register' debugger command is now 'reg', and it can
		be used to modify registers, not just read them.
		The syntax for hpcmips (-F) is now -F xx, where xx is a
		machine model identifier. (1 = BE300.)
20041223	Some really minor updates.
20041226	Minor updates to doc/index.html (NetBSD 1.6.2 -> 2.0, and
		some other rearrangements).
		Many updates to the debugger (better register manipulation,
		breakpoint manipulation, and other updates).
		Fix to dev_cons.c to allow the regression tests to work again.
		The configure script now tries to detect the presence of a
		MIPS cross compiler. (Used by "make regtest".)
		Regression tests are now run both with and without bintrans.
20041227	Some hacks to the VR41xx code to allow Linux for BE300 to
		get far enough to show the penguin on the framebuffer.
20041228	Merging dev_kn01_csr.c and dev_vdac.c into dev_kn01.c.
20041229	Various updates to the debugger (nicer tlb output and other
		things).
		Some floating point fixes in src/coproc.c (mov is not
		an arithmetic instruction), and in src/cpu.c (ldcX/sdcX in
		32-bit mode uses register pairs).
		'-O' now also affects the bootstring for SGI and ARC emulation.
		Bintrans updates (slightly faster 32-bit load/store on alpha).
		Updates to the i386 backend too, but no real speed improvement.
20041230	Cleaning up parts of the 64-bit virtual-to-physical code for
		R10000, and per-machine default TLB entries can now be set
		for SGI and ARC machines.
		Fix: SGI-IP27 is ARC64, not ARCS.
20050101	Minor updates.
20050102	Minor updates.
		Fixing a 32-bit 'addu' bug in the bintrans backends.
		Allowing fast load/stores even in 64-bit bintrans mode, if
		the top 32 bits are either 0x00000000 or 0xffffffff (for Alpha
		only).
		Re-enabling ctc0/cfc0 (but what do they do?).
		Adding beql, bnel, blezl, and bgtzl to the Alpha backend.
20050103	Adding fast 32-bit load/store for 64-bit mode emulation to
		the i386 backend too (similar to the Alpha code). Not really
		tested yet, though.
		Adding an incomplete regression test case for lwl/lwr/ldl/ldr.
		Playing around with bintranslated lwl and lwr for Alpha.
20040104	Changing many occurances of pica to jazz.
		Various other updates.
20050105	Fixing some more bintrans bugs (both Alpha and i386).
		Unaligned stores that cause tlb refill exceptions should now
		cause TLBS exceptions, not TLBL.
		Adding experimental swl and swr to the Alpha backend.
		Adding lwl, lwr, swl, and swr to the i386 backend.
20050106	Adding another hpcmips model (Casio E-105, -F2), and doing
		some updates to the VR41xx code. NetBSD/hpcmips prints some
		boot messages.
20050108	Minor updates.
20050109	dev_dec5500_ioboard.c and dev_sgec.c => dev_kn220.c.
		dev_crime.c, _mace.c, and _macepci.c => dev_sgi_ip32.c.
		Also adding dev_sgi_mec, _ust, and _mte into dev_sgi_ip32.c.
		A slight license change. Still revised BSD-style, though.
		memory_v2p.c is now included separately for MMU10K and
		MMU8K.
		Fixing a NS16550 bug, triggered by NetBSD 2.0, but not 1.6.2.
		Refreshing the UltraSPARC bintrans backend skeleton.
		Merging dev_decbi, _deccca, and _decxmi into dev_dec5800.c.
		Sparc backend instructions done so far: mthi/mtlo/mfhi/mflo,
		lui, addu, daddu, subu, dsubu, and, or, nor, xor, sll, dsll,
		srl, and sra.
		Adding more sparc backend instructions: addiu, daddiu, xori,
		ori, andi, srlv, srav, sllv, slt, sltu, slti, sltiu.
20050110	Changing the default bintrans cache to 16 MB, and some other
		minor updates.
		Adding div and divu to the i386 backend (but not Alpha yet).
		More work on ARCBIOS emulation.
		Trying to find a bug which affects Linux on Playstation 2 in
		bintrans mode.
20050111	Moving around some Playstation 2 stuff, but I haven't found
		the bug yet. It is triggered by load/stores.
		More ARCBIOS updates, enough to let Windows NT partition
		disks in some rudimentary fashion.
20050112	Testing for release 0.2.4.
		Fixes to suppress compiler warnings.

==============  RELEASE 0.2.4  ==============

20050113	Minor updates.
20050114	Fix to the Alpha bintrans backend to allow compilation with
		old versions of gcc (2.95.4).

==============  RELEASE 0.2.4.1  ==============

20050115	Various updates and fixes: some IP32 stuff, the debugger,
		ns16550 loopback tx isn't transmitted out anymore, ...
		Removing old/broken R10000 cache hacks, which weren't really
		used.
20050116	Minor updates to the documentation on using PROM images.
		Adding ARCBIOS function 0x100 (used by IRIX when returning
		from main, but undocumented).
		MC146818 updates (mostly SGI-related).
		ARCS64 updates (testing with an OpenBSD snapshot in IP27
		mode). This causes Linux/IP30 to not work. Maybe IP27 and
		IP30 differ, even though both are 64-bit?
		Removing some nonsensical ARCS64 code from machine.c.
		Better handling of 128MB and 512MB memory offsets used by
		various SGI models.
		Trying to revert the ARCS64 changes (OpenBSD/sgi does
		seem to be aware of 64-bit vs 32-bit data structures in
		_some_ places, but not all), to make Linux/IP30 work again.
		Adding "power off" capability to the RTC, as used on IP32
		(and possibly IP30 and others).
		Some IP30 updates.
20050117	Debugger updates (symbolic register names instead of just rX,
		and using %08x instead of %016llx when emulating 32-bit CPUs
		in more places than before).
		Removing the dummy sgi_nasid and sgi_cpuinfo devices.
		Also using symbolic names for coprocessor 0 registers.
		Adding DEV_MP_MEMORY to dev_mp.c.
		Adding a 'put' command to the debugger.
		ARCBIOS function 0x100 used by IRIX seems to _NOT_ be a
		ReturnFromMain(), but something else undocumented.
		The count and compare registers are now 32-bit in all
		places, as they should be. (This causes, among other things,
		OpenBSD/sgi to not hang randomly in userspace anymore.)
		On breakpoints, the debugger is now entered _at_ the
		instruction at the breakpoint, not after it.
		Some cursor keys now work when inputed via X.
		Refreshing the MC146818 device a bit more.
20050118	Trying to add some support for less-than-4KB virtual pages,
		used by at least VR4131. Thanks to Alexander Yurchenko for
		noticing this. (I'm assuming for now that all R41xx work
		this way, which is not necessarily true.) It doesn't really
		work yet though.
		Renicing the "loading files" messages and other things
		displayed during startup.
		Changing the disassembly output of ori, xori, and andi to
		unsigned hex immediate, instead of decimal (as suggested
		by Alec Voropay).
		configure-script update for HP-UX, and switching from using
		inet_aton() to inet_pton() (as suggested by Nils Weller).
		Also adding -lnsl on Solaris, if required by inet_pton().
		Lots of minor R4100-related updates.
20050119	Correcting the R4100 config register in src/coproc.c, and
		a minor update to dev_vr41xx.
		Finally began a redesign/remodelling/cleanup that I have had
		in mind for quite some time... moving many things that were
		in struct emul into a new struct machine.
		Userland emulation now works with bintrans.
		Refreshing the LANCE controller (dev_le.c).
		Fixing the LK201 keyboard id.
20050120	Continuing on the remodelling/cleanup.
		Fixing the SCSI bug (which was triggered sometimes by
		NetBSD 2.0/pmax on Linux/i386 hosts).
		Adding a speed-limit hack to the mc146818 device when running
		in DECstation mode (limiting to emulated 30 MHz clock, so
		that Ultrix doesn't freak out).
		Adding an ugly workaround for the floating-point bug which
		is triggered when running NetBSD/pmax 2.0 on an Alpha host.
		The count/compare interrupt will not be triggered now, if
		the compare register is left untouched.
		Many, many other fixes...
20050121	Continuing the remodelling/cleanup. (Mostly working on the
		network stack, and on moving towards multiple emulations
		with multiple machines per emulation.)
		Fixbug: not clearing lowest parts of lo0 and hi on tlbr
		(seems to increase performance when emulating Linux?).
20050122	Continuing the remodelling/cleanup.
		Linux on DECstation uses a non-used part of the RTC registers
		for the year value; this is supported now, so Linux thinks
		it is 2005 and not 2000.
		Began hacking on something to reply to Debian's DHCP requests,
		but it's not working yet.
20050123	Continuing the remodelling/cleanup.
20050124	Continuing the remodelling/cleanup.
		Converting the dev_vga charcell memory to support direct
		bintrans access (similar to how dev_fb works), and fixing a
		couple of bintrans bugs in the process.
		The emulator now compiles under OpenBSD/arc 2.3 without
		crashing (mostly due to the bintrans fixes, but also some
		minor updates to the configure script).
20050125	Continuing the remodelling/cleanup.
		The '-a' option was missing in the Hello World example in the
		documentation. (Thanks to Soohyun Cho for noticing this.)
20050126	Continuing the remodelling/cleanup. Moving around stuff in
		the header files, etc. Adding a '-K' command line option, which
		forces the debugger to be entered at the exit of a simulation,
		regardless of failure or success. Beginning to work on the
		config file parser.
		Splitting doc/index.html into experiments.html, guestoses.html,
		intro.html, and misc.html.
		Updating the man page and adding a skeleton section about the
		configure files to doc/misc.html.
20050127	Minor documentation updates.
20050128	Continuing the remodelling/cleanup, mostly working on the
		config file parser (adding a couple of machine words, enough
		to run simple emulations, and adding support for multi-line
		comments using tuborgs).
		Removing some command line options for the least working
		emulation modes (-e, -f, -g, -E, -H), adding new -E and -e
		options for selecting machine type.
		Moving global variables from src/x11.c into struct machine (a
		bit buggy, but it seems to almost work).
20050129	Removing the Playstation 2 mode (-B) and hpcmips modes (-F)
		from the command line as well.
		Changing the -T command line option from meaning "trace on bad
		address" to meaning "enter the single-step debugger on bad
		address".
		More updates to the configuration file parser (nested tuborg
		comments, more options, ...).
		Making -s a global setting, not just affecting one machine.
		Trying to fix the X11 event stuff... but it's so ugly that it
		must be rewritten later.
		Continuing the multi-emul cleanup.
		Bugfixes and other updates to dev_vga.
20050130	Continuing the remodelling/cleanup. Finally moving out the
		MIPS dependant stuff of the cpu struct into its own struct.
		Renaming cpu.c to cpu_mips.c, and cpu_common.c to cpu.c.
		Adding a dummy cpu_ppc.c.
		Removing the UltraSPARC bintrans backend.
		Many other minor updates.
		src/file.c should now be free from MIPS-dependancies.
20050131	Continuing a little bit more on src/file.c. PPC ELFs can now
		be loaded, it seems.
		Continuing on src/cpu_ppc.c.
		'mips' is undefined by the configure script, if it is defined
		by default. (Fixes build on at least OpenBSD/arc and
		NetBSD/arc, where gcc defines 'mips'.)
		A couple of other minor fixes.
		Removing the "Changing framebuffer resolution" section from
		doc/misc.h (because it's buggy and not very useful anway).
		Adding a mystrtoull(), used on systems where there is no
		strtoull() in libc.
		Adding 'add_x11_display' to the configure file parser 
		(corresponding to the -z command line option).
		Continuing the multi-emul machine cleanup.
20050201	Minor updates (man page, RELEASE, README).
		Continuing the cleanup.
		Adding a 'name' field to the emul struct, and adding a command
		to the debugger ("focus") to make it possible to switch focus
		to different machines (in different emuls).
		Beginning to work on the PPC disassembler etc. Hello World
		for linux-ppc64 can be disassembled :-)
20050202	Adding a hack for reading symbols from Microsoft's variant of
		COFF files.
		Adding a dummy cpu_sparc.c and include/cpu_sparc.h.
		Cleaning up more to support multiple cpu families.
		Various other minor updates.
		Fixing another old-gcc-on-Alpha problem.
20050203	Bintrans cache size is now variable, settable by a new
		configuration file option 'bintrans_size'.
		The debugger can now theoretically call disassembler functions
		for cpu families with non-fixed instruction word length.
		Working more on the mec controller. It now works well enough
		to let both NetBSD/sgimips and OpenBSD/sgi connect to the
		outside world using ftp :-)
		Continuing on the cleanup of the networking subsystem.
20050204	Continuing the cleanup.
		Working on a way to use separate xterms for serial ports and
		other console input, when emulating multiple machines (or one
		machine with multiple serial lines active).
20050205	Minor documentation updates.
20050206	Moving console.c from devices/ to src/, and continuing the
		work on using separate windows for each serial console.
		Trying to get OpenBSD/sgi to boot with root-on-nfs on an
		emulated NetBSD/pmax server, but no success in setting up
		the server yet.
20050207	Continuing on the console cleanup.
		Adding a 'start_paused' configuration file option, and a
		'pause' command to the debugger.
20050208	Everything now builds with --withoutmips.
		Continuing on the documentation on how to run OpenBSD/sgi, but
		no actual success yet.
		sizeof => (int)sizeof in the configure script (as suggested by
		Nils Weller).
20050209	Adding a check for -lm to the configure script.
		Continuing on the cleanup: trying to make memory_rw non-MIPS
		dependant.
		Trying to make a better fix for the cdrom-block-size problems
		on FreeBSD. (It now works with a Windows NT 4.0 cdrom in my
		drive.)
		Began a clean-up of the userland subsystem.
20050210	Continuing the userland cleanup.
		IBM's Hello World example for Linux/PPC64 runs fine now.
20050211	Continuing the cleanup. Removing the --userland configure
		option (because support for userland is always included now).
		Working more on getting OpenBSD/sgi to boot with root on
		nfs. (Booting with the ramdisk kernel, and mounting root via
		nfs works, but not yet from the generic kernel.)
		Major update to the manpage.
		Removing the -G command line option (SGI modes).
20050212	Updating the documentation (experimental devices: dev_cons
		and dev_mp, better hello.c, and some other things).
20050213	Some minor fixes: documentation, 80 columns in some source
		files, better configure script options.
		Adding some more PPC instructions.
		Added a NOFPU flag to the MIPS cpu flags, so that executing
		FPU instructions on for example VR4xxx will fail (as suggested
		by Alexander Yurchenko).
20050214	Implementing more PPC instructions.
		Adding dev_pmppc.
20050215	Continuing the work on PPC emulation. Adding a (mostly non-
		working) NetBSD/powerpc userland mode, a (buggy)
		show_trace_tree thing (simliar to the MIPS version).
20050216	Continuing...
20050218	Continuing the clean-up. (Merging the devices and devstate
		debugger commands, more 80-column cleanup, some documentation
		updates, ...).
20050219	Removing the -D, -A, and -a command line options. Updating the
		documentation, in preparation for the next release.
		Adding interrupt stuff to dev_cons.
		Single-stepping now looks/works better with bintrans enabled.
		Beginning the first phase of release testing; various minor
		updates to make everything build cleanly on Solaris.
20050220	Continuing testing for the release...
                
==============  RELEASE 0.3  ==============

20050221	Minor updates. Some more clean-up.
		Beginning on the new device registry stuff.
20050222	Continuing on the device stuff, and doing various other kinds
		of clean-up.
		Adding a dummy BeBox mode.
		Making the pc register common for all cpu families.
		Adding some more PPC instructions and fixing some bugs.
20050223	Continuing on the BeBox stuff, and adding more instructions.
		Adding an ns16550 to the VR4131 emulation (which is probably
		a close enough fake to the VR4131's SIU unit).
20050224	Minor updates. Adding dummy PReP, macppc, and DB64360 modes.
		Continuing on the device registry rewrite.
20050225	Continuing on the device stuff.
20050226	Continuing more on the device rewrite.
		Separating the "testmips" machine into testmips and baremips
		(and similarly with the ppc machine).
		Redesigning the device registry again :-)
		Adding a "device" command to the config file parser.
		Adding "device add" and "device remove" to the debugger.
		Removing pcidevs.h, because it was almost unused.
20050228	Correcting the Sprite disk image url in the documentation.
20050301	Adding an URISC cpu emulation mode (single-opcode machine).
20050303	Adding some files to the experiments directory (rssb_as.c,
		rssb_as.README, urisc_test.s).
		Continuing on the device stuff.
20050304	Minor documentation update. Also, the SPARC, PPC, and URISC
		modes are now enabled by default in the configure script.
		Some minor PPC updates (adding a VGA device to the bebox
		emulation mode).
20050305	Moving the static i386 bintrans runchunk code snippet (and the
		others) to be dynamically generated. (This allows the code to
		compile on i386 with old gcc.)
		Loading PPC64 ELFs now sets R2 to the TOC base.
		Changing the name of the emulator from mips64emul to GXemul.
		Splitting out the configuration file part of the documentation
		into its own file (configfiles.html).
20050306	Some really minor documentation updates.
		Adding a -D command line option (for "fully deterministic"
		behaviour).
20050308	Minor PPC updates. Adding a dummy OpenFirmware emulation layer.
20050309	Adding a hack for systems without inet_pton (such as Cygwin in
		Windows) as suggested by Soohyun Cho. (And updating the
		configure script too.)
		Adding a dummy HPPA cpu family.
		Some more OpenFirmware updates.
		Faster loading of badly aligned ELF regions.
20050311	Minor updates. Adding a dummy "NEC MobilePro 780" hpcmips
		machine mode; disabling direct bintrans access to framebuffers
		that are not 4K page aligned.
20050312	Adding an ugly KIU hack to the VR41xx device (which enables
		NetBSD/hpcmips MobilePro 780 keyboard input).
20050313	Adding a dummy "pcic" device (a pcmcia card controller).
		Adding a dummy Alpha cpu emulation mode.
		Fixing a strcmp length bug (thanks to Alexander Yurchenko for
		noticing the bug).
20050314	Some minor bintrans-related updates in preparation for a new
		bintrans subsystem: command line option -b now means "old
		bintrans", -B means "disable bintrans", and using no option at
		all selects "new bintrans".
		Better generation of MAC addresses when emulating multiple
		machines and/or NICs.
		Minor documentation updates (regarding configuration files).
20050315	Adding dummy standby, suspend, and hibernate MIPS opcodes.
		RTC interrupt hack for VR4121 (hpcmips).
		Enough of the pcic is now emulated to let NetBSD/hpcmips detect
		a PCMCIA harddisk controller card (but there is no support for
		ISA/PCMCIA interrupts yet).
		Adding preliminary instructions on how to install
		NetBSD/hpcmips.
		Continuing the attempt to get harddisks working with interrupts
		(pcic, wdc on hpcmips).
20050318	Minor updates. (Fixing disassembly of MIPS bgtz etc., 
		continuing on the device cleanup, ...)
20050319	Minor updates.
20050320	Minor updates.
20050322	Various minor updates.
20050323	Some more minor updates.
20050328	VR41xx-related updates (keyboard stuff: the space key and
		shifted and ctrled keys are now working in userland (ie
		NetBSD/hpcmips' ramdisk installer).
		Also adding simple cursor key support to the VR41xx kiu.
20050329	Some progress on the wdc.
		Updating the documentation of how to (possibly) install
		NetBSD/hpcmips, once it is working.
		Adding delays before wdc interrupts; this allows NetBSD
		2.0/hpcmips to be successfully installed!
		Mirroring physical addresses 0x8....... to 0x00000000 on
		hpcmips; this makes it possible to run X11 inside
		NetBSD/hpcmips :-)
		Updating the documentation regarding NetBSD/hpcmips.
		Fixing 16-bit vs 15-bit color in dev_fb.
20050330	Print a warning when the user attempts to load a gzipped
		file. (Thanks to Juan RP for making me aware of this "bug".)
20050331	Importing aic7xxx_reg.h from NetBSD.
		Adding a "-x" command line option, which forces xterms for
		each emulated serial port to always be opened.
		Adding a MobilePro 770 mode (same as 780, but different
		framebuffer address which allows bintrans = fast scrolling),
		and a MobilePro 800 (with 800x600 pixels framebuffer :-).
20050401	Minor updates.
20050402	Minor updates. (The standby and suspend instructions are
		bintransed as NOPs, and some minor documentation updates.)
20050403	Adding an Agenda VR3 mode, and playing around with a Linux
		kernel image, but not much success yet.
		Changing BIFB_D16_FFFF -> BIFB_D16_0000 for the hpcmips 
		framebuffers, causing NetBSD to boot with correct colors.
		New syntax for loading raw files: loadaddr:skiplen:
		initialpc:filename. (This is necessary to boot the Linux VR3
		kernels.)
		The Linux VR3 kernel boots in both serial console mode and
		using the framebuffer, but it panics relatively early.
20050404	Continuing on the AHC, and some other minor updates.
20050405	Adding a note in doc/experimental.html about "root1.2.6.cramfs"
		(thanks to Alec Voropay for noticing that it wasn't part
		of root1.2.6.kernel-8.00).
		Also adding a note about another cramfs image.
		-o options are now added to the command line passed to the
		Linux kernel, when emulating the VR3.
		Adding a MobilePro 880 mode, and a dummy IBM WorkPad Z50 mode.
20050406	Connecting the VR3 serial controller to irq 9 (Linux calls this
		irq 17), and some other interrupt-related cleanups.
		Reducing the memory overhead per bintranslated page. (Hopefully
		this makes things faster, or at least not slower...)
20050407	Some more cleanup regarding command line argument passing for
		the hpcmips modes.
		Playing with Linux kernels for MobilePro 770 and 800; they get
		as far as mounting a root filesystem, but then crash.
		Doing some testing for the next release.

==============  RELEASE 0.3.1  ==============


1 /*
2 * Copyright (C) 2003-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: file.c,v 1.85 2005/04/06 21:28:36 debug Exp $
29 *
30 * This file contains functions which load executable images into (emulated)
31 * memory. File formats recognized so far:
32 *
33 * ELF 32-bit and 64-bit ELFs
34 * a.out old format used by OpenBSD 2.x pmax kernels
35 * ecoff old format used by Ultrix, Windows NT, etc
36 * srec Motorola SREC format
37 * raw raw binaries, "address:[skiplen:[entrypoint:]]filename"
38 *
39 * If a file is not of one of the above mentioned formats, it is assumed
40 * to be symbol data generated by 'nm' or 'nm -S'.
41 */
42
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #include <sys/types.h>
47
48 #include "cpu.h"
49 #include "exec_aout.h"
50 #include "exec_ecoff.h"
51 #include "exec_elf.h"
52 #include "machine.h"
53 #include "memory.h"
54 #include "misc.h"
55 #include "symbol.h"
56
57
58 /* ELF machine types as strings: (same as exec_elf.h) */
59 #define N_ELF_MACHINE_TYPES 54
60 static char *elf_machine_type[N_ELF_MACHINE_TYPES] = {
61 "NONE", "M32", "SPARC", "386", /* 0..3 */
62 "68K", "88K", "486", "860", /* 4..7 */
63 "MIPS", "S370", "MIPS_RS3_LE", "RS6000", /* 8..11 */
64 "unknown12", "unknown13", "unknown14", "PARISC", /* 12..15 */
65 "NCUBE", "VPP500", "SPARC32PLUS", "960", /* 16..19 */
66 "PPC", "PPC64", "unknown22", "unknown23", /* 20..23 */
67 "unknown24", "unknown25", "unknown26", "unknown27", /* 24..27 */
68 "unknown28", "unknown29", "unknown30", "unknown31", /* 28..31 */
69 "unknown32", "unknown33", "unknown34", "unknown35", /* 32..35 */
70 "V800", "FR20", "RH32", "RCE", /* 36..39 */
71 "ARM", "ALPHA", "SH", "SPARCV9", /* 40..43 */
72 "TRICORE", "ARC", "H8_300", "H8_300H", /* 44..47 */
73 "H8S", "H8_500", "IA_64", "MIPS_X", /* 48..51 */
74 "COLDFIRE", "68HC12" /* 52..53 */
75 };
76
77
78 /*
79 * This should be increased by every routine here that actually loads an
80 * executable file into memory. (For example, loading a symbol file should
81 * NOT increase this.)
82 */
83 static int n_executables_loaded = 0;
84
85
86 struct aout_symbol {
87 uint32_t strindex;
88 uint32_t type;
89 uint32_t addr;
90 };
91
92 /* Special symbol format used by Microsoft-ish COFF files: */
93 struct ms_sym {
94 unsigned char name[8];
95 unsigned char value[4];
96 unsigned char section[2];
97 unsigned char type[2];
98 unsigned char storage_class;
99 unsigned char n_aux_syms;
100 };
101
102
103 #define unencode(var,dataptr,typ) { \
104 int Wi; unsigned char Wb; \
105 unsigned char *Wp = (unsigned char *) dataptr; \
106 int Wlen = sizeof(typ); \
107 var = 0; \
108 for (Wi=0; Wi<Wlen; Wi++) { \
109 if (encoding == ELFDATA2LSB) \
110 Wb = Wp[Wlen-1 - Wi]; \
111 else \
112 Wb = Wp[Wi]; \
113 if (Wi == 0 && (Wb & 0x80)) { \
114 var --; /* set var to -1 :-) */ \
115 var <<= 8; \
116 } \
117 var |= Wb; \
118 if (Wi < Wlen-1) \
119 var <<= 8; \
120 } \
121 }
122
123
124 /*
125 * file_load_aout():
126 *
127 * Loads an a.out binary image into the emulated memory. The entry point
128 * (read from the a.out header) is stored in the specified CPU's registers.
129 *
130 * TODO: This has to be rewritten / corrected to support multiple a.out
131 * formats, where text/data are aligned differently.
132 */
133 static void file_load_aout(struct machine *m, struct memory *mem,
134 char *filename, int osf1_hack,
135 uint64_t *entrypointp, int arch, int *byte_orderp)
136 {
137 struct exec aout_header;
138 FILE *f;
139 int len;
140 int encoding = ELFDATA2LSB;
141 uint32_t entry, datasize, textsize;
142 int32_t symbsize = 0;
143 uint32_t vaddr, total_len;
144 unsigned char buf[4096];
145 unsigned char *syms;
146
147 f = fopen(filename, "r");
148 if (f == NULL) {
149 perror(filename);
150 exit(1);
151 }
152
153 if (osf1_hack) {
154 fread(&buf, 1, 32, f);
155 vaddr = buf[16] + (buf[17] << 8) +
156 (buf[18] << 16) + (buf[19] << 24);
157 entry = buf[20] + (buf[21] << 8) +
158 (buf[22] << 16) + (buf[23] << 24);
159 debug("OSF1 a.out, load address 0x%08lx, "
160 "entry point 0x%08x\n", (long)vaddr, (long)entry);
161 symbsize = 0;
162 fseek(f, 0, SEEK_END);
163 /* This is of course wrong, but should work anyway: */
164 textsize = ftell(f) - 512;
165 datasize = 0;
166 fseek(f, 512, SEEK_SET);
167 } else {
168 len = fread(&aout_header, 1, sizeof(aout_header), f);
169 if (len != sizeof(aout_header)) {
170 fprintf(stderr, "%s: not a complete a.out image\n",
171 filename);
172 exit(1);
173 }
174
175 unencode(entry, &aout_header.a_entry, uint32_t);
176 vaddr = entry;
177 debug("a.out, entry point 0x%08lx\n", (long)entry);
178
179 unencode(textsize, &aout_header.a_text, uint32_t);
180 unencode(datasize, &aout_header.a_data, uint32_t);
181 debug("text + data = %i + %i bytes\n", textsize, datasize);
182
183 unencode(symbsize, &aout_header.a_syms, uint32_t);
184 }
185
186 /* Load text and data: */
187 total_len = textsize + datasize;
188 while (total_len != 0) {
189 len = total_len > sizeof(buf) ? sizeof(buf) : total_len;
190 len = fread(buf, 1, len, f);
191
192 /* printf("fread len=%i vaddr=%x buf[0..]=%02x %02x %02x\n",
193 len, (int)vaddr, buf[0], buf[1], buf[2]); */
194
195 if (len > 0)
196 m->cpus[0]->memory_rw(m->cpus[0], mem, vaddr,
197 &buf[0], len, MEM_WRITE, NO_EXCEPTIONS);
198 else {
199 if (osf1_hack)
200 break;
201 else {
202 fprintf(stderr, "could not read from %s\n",
203 filename);
204 exit(1);
205 }
206 }
207
208 vaddr += len;
209 total_len -= len;
210 }
211
212 if (symbsize != 0) {
213 struct aout_symbol *aout_symbol_ptr;
214 int i, n_symbols;
215 uint32_t type, addr, str_index;
216 uint32_t strings_len;
217 char *string_symbols;
218 off_t oldpos;
219
220 debug("symbols: %i bytes @ 0x%x\n", symbsize, (int)ftell(f));
221 syms = malloc(symbsize);
222 if (syms == NULL) {
223 fprintf(stderr, "out of memory\n");
224 exit(1);
225 }
226 len = fread(syms, 1, symbsize, f);
227 if (len != symbsize) {
228 fprintf(stderr, "error reading symbols from %s\n",
229 filename);
230 exit(1);
231 }
232
233 oldpos = ftell(f);
234 fseek(f, 0, SEEK_END);
235 strings_len = ftell(f) - oldpos;
236 fseek(f, oldpos, SEEK_SET);
237 debug("strings: %i bytes @ 0x%x\n", strings_len, (int)ftell(f));
238 string_symbols = malloc(strings_len);
239 if (string_symbols == NULL) {
240 fprintf(stderr, "out of memory\n");
241 exit(1);
242 }
243 fread(string_symbols, 1, strings_len, f);
244
245 aout_symbol_ptr = (struct aout_symbol *) syms;
246 n_symbols = symbsize / sizeof(struct aout_symbol);
247 i = 0;
248 while (i < n_symbols) {
249 unencode(str_index, &aout_symbol_ptr[i].strindex,
250 uint32_t);
251 unencode(type, &aout_symbol_ptr[i].type, uint32_t);
252 unencode(addr, &aout_symbol_ptr[i].addr, uint32_t);
253
254 /* debug("symbol type 0x%04x @ 0x%08x: %s\n",
255 type, addr, string_symbols + str_index); */
256
257 if (type != 0 && addr != 0)
258 add_symbol_name(&m->symbol_context,
259 addr, 0, string_symbols + str_index, 0);
260 i++;
261 }
262
263 free(string_symbols);
264 free(syms);
265 }
266
267 fclose(f);
268
269 *entrypointp = entry;
270
271 if (encoding == ELFDATA2LSB)
272 *byte_orderp = EMUL_LITTLE_ENDIAN;
273 else
274 *byte_orderp = EMUL_BIG_ENDIAN;
275
276 n_executables_loaded ++;
277 }
278
279
280 /*
281 * file_load_ecoff():
282 *
283 * Loads an ecoff binary image into the emulated memory. The entry point
284 * (read from the ecoff header) is stored in the specified CPU's registers.
285 */
286 static void file_load_ecoff(struct machine *m, struct memory *mem,
287 char *filename, uint64_t *entrypointp,
288 int arch, uint64_t *gpp, int *byte_orderp)
289 {
290 struct ecoff_exechdr exechdr;
291 int f_magic, f_nscns, f_nsyms;
292 int a_magic;
293 off_t f_symptr, a_tsize, a_dsize, a_bsize;
294 uint64_t a_entry, a_tstart, a_dstart, a_bstart, a_gp, end_addr=0;
295 char *format_name;
296 struct ecoff_scnhdr scnhdr;
297 FILE *f;
298 int len, secn, total_len, chunk_size;
299 int encoding = ELFDATA2LSB; /* Assume little-endian. See below */
300 int program_byte_order = -1;
301 unsigned char buf[8192];
302
303 f = fopen(filename, "r");
304 if (f == NULL) {
305 perror(filename);
306 exit(1);
307 }
308
309 len = fread(&exechdr, 1, sizeof(exechdr), f);
310 if (len != sizeof(exechdr)) {
311 fprintf(stderr, " not a complete ecoff image\n");
312 exit(1);
313 }
314
315 /*
316 * The following code looks a bit ugly, but it should work. The ECOFF
317 * 16-bit magic value seems to be stored in MSB byte order for
318 * big-endian binaries, and LSB byte order for little-endian binaries.
319 *
320 * The unencode() assumes little-endianness by default.
321 */
322 unencode(f_magic, &exechdr.f.f_magic, uint16_t);
323 switch (f_magic) {
324 case ((ECOFF_MAGIC_MIPSEB & 0xff) << 8) +
325 ((ECOFF_MAGIC_MIPSEB >> 8) & 0xff):
326 format_name = "MIPS1 BE";
327 encoding = ELFDATA2MSB;
328 break;
329 case ECOFF_MAGIC_MIPSEB:
330 /* NOTE: Big-endian header, little-endian code! */
331 format_name = "MIPS1 BE-LE";
332 encoding = ELFDATA2MSB;
333 program_byte_order = ELFDATA2LSB;
334 break;
335 case ECOFF_MAGIC_MIPSEL:
336 format_name = "MIPS1 LE";
337 encoding = ELFDATA2LSB;
338 break;
339 case ((ECOFF_MAGIC_MIPSEB2 & 0xff) << 8) +
340 ((ECOFF_MAGIC_MIPSEB2 >> 8) & 0xff):
341 format_name = "MIPS2 BE";
342 encoding = ELFDATA2MSB;
343 break;
344 case ECOFF_MAGIC_MIPSEL2:
345 format_name = "MIPS2 LE";
346 encoding = ELFDATA2LSB;
347 break;
348 case ((ECOFF_MAGIC_MIPSEB3 & 0xff) << 8) +
349 ((ECOFF_MAGIC_MIPSEB3 >> 8) & 0xff):
350 format_name = "MIPS3 BE";
351 encoding = ELFDATA2MSB;
352 break;
353 case ECOFF_MAGIC_MIPSEL3:
354 format_name = "MIPS3 LE";
355 encoding = ELFDATA2LSB;
356 break;
357 default:
358 fprintf(stderr, "%s: unimplemented ECOFF format, magic = "
359 "0x%04x\n", filename, (int)f_magic);
360 exit(1);
361 }
362
363 /* Read various header information: */
364 unencode(f_nscns, &exechdr.f.f_nscns, uint16_t);
365 unencode(f_symptr, &exechdr.f.f_symptr, uint32_t);
366 unencode(f_nsyms, &exechdr.f.f_nsyms, uint32_t);
367 debug("ECOFF, %s, %i sections, %i symbols @ 0x%lx\n",
368 format_name, f_nscns, f_nsyms, (long)f_symptr);
369
370 unencode(a_magic, &exechdr.a.magic, uint16_t);
371 unencode(a_tsize, &exechdr.a.tsize, uint32_t);
372 unencode(a_dsize, &exechdr.a.dsize, uint32_t);
373 unencode(a_bsize, &exechdr.a.bsize, uint32_t);
374 debug("magic 0x%04x, tsize 0x%x, dsize 0x%x, bsize 0x%x\n",
375 a_magic, (int)a_tsize, (int)a_dsize, (int)a_bsize);
376
377 unencode(a_tstart, &exechdr.a.text_start, uint32_t);
378 unencode(a_dstart, &exechdr.a.data_start, uint32_t);
379 unencode(a_bstart, &exechdr.a.bss_start, uint32_t);
380 debug("text @ 0x%08x, data @ 0x%08x, bss @ 0x%08x\n",
381 (int)a_tstart, (int)a_dstart, (int)a_bstart);
382
383 unencode(a_entry, &exechdr.a.entry, uint32_t);
384 unencode(a_gp, &exechdr.a.gp_value, uint32_t);
385 debug("entrypoint 0x%08x, gp = 0x%08x\n",
386 (int)a_entry, (int)a_gp);
387
388 /*
389 * Special hack for a MACH/pmax kernel, I don't know how applicable
390 * this is for other files:
391 * there are no sections (!), and a_magic = 0x0108 instead of
392 * 0x0107 as it is on most other (E)COFF files I've seen.
393 *
394 * Then load everything after the header to the text start address.
395 */
396 if (f_nscns == 0 && a_magic == 0x108) {
397 uint64_t where = a_tstart;
398 total_len = 0;
399 fseek(f, 0x50, SEEK_SET);
400 while (!feof(f)) {
401 chunk_size = 256;
402 len = fread(buf, 1, chunk_size, f);
403
404 if (len > 0)
405 m->cpus[0]->memory_rw(m->cpus[0], mem, where,
406 &buf[0], len, MEM_WRITE, NO_EXCEPTIONS);
407 where += len;
408 total_len += len;
409 }
410 debug("MACH/pmax hack (!), read 0x%x bytes\n", total_len);
411 }
412
413 /* Go through all the section headers: */
414 for (secn=0; secn<f_nscns; secn++) {
415 off_t s_scnptr, s_relptr, s_lnnoptr, oldpos;
416 int s_nreloc, s_nlnno, s_flags;
417 int s_size;
418 unsigned int i;
419 uint64_t s_paddr, s_vaddr;
420
421 /* Read a section header: */
422 len = fread(&scnhdr, 1, sizeof(scnhdr), f);
423 if (len != sizeof(scnhdr)) {
424 fprintf(stderr, "%s: incomplete section "
425 "header %i\n", filename, secn);
426 exit(1);
427 }
428
429 /* Show the section name: */
430 debug("section ");
431 for (i=0; i<sizeof(scnhdr.s_name); i++)
432 if (scnhdr.s_name[i] >= 32 && scnhdr.s_name[i] < 127)
433 debug("%c", scnhdr.s_name[i]);
434 else
435 break;
436 debug(" (");
437
438 unencode(s_paddr, &scnhdr.s_paddr, uint32_t);
439 unencode(s_vaddr, &scnhdr.s_vaddr, uint32_t);
440 unencode(s_size, &scnhdr.s_size, uint32_t);
441 unencode(s_scnptr, &scnhdr.s_scnptr, uint32_t);
442 unencode(s_relptr, &scnhdr.s_relptr, uint32_t);
443 unencode(s_lnnoptr, &scnhdr.s_lnnoptr, uint32_t);
444 unencode(s_nreloc, &scnhdr.s_nreloc, uint16_t);
445 unencode(s_nlnno, &scnhdr.s_nlnno, uint16_t);
446 unencode(s_flags, &scnhdr.s_flags, uint32_t);
447
448 debug("0x%x @ 0x%08x, offset 0x%lx, flags 0x%x)\n",
449 (int)s_size, (int)s_vaddr, (long)s_scnptr, (int)s_flags);
450
451 end_addr = s_vaddr + s_size;
452
453 if (s_relptr != 0) {
454 /*
455 * TODO: Read this url, or similar:
456 * http://www.iecc.com/linker/linker07.html
457 */
458 fprintf(stderr, "%s: relocatable code/data in "
459 "section nr %i: not yet implemented\n",
460 filename, secn);
461 exit(1);
462 }
463
464 /* Loadable? Then load the section: */
465 if (s_scnptr != 0 && s_size != 0 &&
466 s_vaddr != 0 && !(s_flags & 0x02)) {
467 /* Remember the current file offset: */
468 oldpos = ftell(f);
469
470 /* Load the section into emulated memory: */
471 fseek(f, s_scnptr, SEEK_SET);
472 total_len = 0;
473 chunk_size = 1;
474 if ((s_vaddr & 0xf) == 0) chunk_size = 0x10;
475 if ((s_vaddr & 0xff) == 0) chunk_size = 0x100;
476 if ((s_vaddr & 0xfff) == 0) chunk_size = 0x1000;
477 while (total_len < s_size) {
478 len = chunk_size;
479 if (total_len + len > s_size)
480 len = s_size - total_len;
481 len = fread(buf, 1, chunk_size, f);
482 if (len == 0) {
483 debug("!!! total_len = %i, "
484 "chunk_size = %i, len = %i\n",
485 total_len, chunk_size, len);
486 break;
487 }
488
489 m->cpus[0]->memory_rw(m->cpus[0], mem, s_vaddr,
490 &buf[0], len, MEM_WRITE, NO_EXCEPTIONS);
491 s_vaddr += len;
492 total_len += len;
493 }
494
495 /* Return to position inside the section headers: */
496 fseek(f, oldpos, SEEK_SET);
497 }
498 }
499
500 if (f_symptr != 0 && f_nsyms != 0) {
501 struct ecoff_symhdr symhdr;
502 int sym_magic, iextMax, issExtMax, issMax, crfd;
503 off_t cbRfdOffset, cbExtOffset, cbSsExtOffset, cbSsOffset;
504 char *symbol_data;
505 struct ecoff_extsym *extsyms;
506 int nsymbols, sym_nr;
507
508 fseek(f, f_symptr, SEEK_SET);
509
510 len = fread(&symhdr, 1, sizeof(symhdr), f);
511 if (len != sizeof(symhdr)) {
512 fprintf(stderr, "%s: not a complete "
513 "ecoff image: symhdr broken\n", filename);
514 exit(1);
515 }
516
517 unencode(sym_magic, &symhdr.magic, uint16_t);
518 unencode(crfd, &symhdr.crfd, uint32_t);
519 unencode(cbRfdOffset, &symhdr.cbRfdOffset, uint32_t);
520 unencode(issMax, &symhdr.issMax, uint32_t);
521 unencode(cbSsOffset, &symhdr.cbSsOffset, uint32_t);
522 unencode(issExtMax, &symhdr.issExtMax, uint32_t);
523 unencode(cbSsExtOffset, &symhdr.cbSsExtOffset, uint32_t);
524 unencode(iextMax, &symhdr.iextMax, uint32_t);
525 unencode(cbExtOffset, &symhdr.cbExtOffset, uint32_t);
526
527 if (sym_magic != MIPS_MAGIC_SYM) {
528 unsigned char *ms_sym_buf;
529 struct ms_sym *sym;
530 int n_real_symbols = 0;
531
532 debug("bad symbol magic, assuming Microsoft format: ");
533
534 /*
535 * See http://www.lisoleg.net/lisoleg/elfandlib/
536 * Microsoft%20Portable%20Executable%20COFF%20For
537 * mat%20Specification.txt
538 * for more details.
539 */
540 ms_sym_buf = malloc(sizeof(struct ms_sym) * f_nsyms);
541 if (ms_sym_buf == NULL) {
542 fprintf(stderr, "out of memory\n");
543 exit(1);
544 }
545 fseek(f, f_symptr, SEEK_SET);
546 len = fread(ms_sym_buf, 1,
547 sizeof(struct ms_sym) * f_nsyms, f);
548 sym = (struct ms_sym *) ms_sym_buf;
549 for (sym_nr=0; sym_nr<f_nsyms; sym_nr++) {
550 char name[300];
551 uint32_t v, t, altname;
552 /* debug("sym %5i: '", sym_nr);
553 for (i=0; i<8 && sym->name[i]; i++)
554 debug("%c", sym->name[i]); */
555 v = sym->value[0] + (sym->value[1] << 8)
556 + (sym->value[2] << 16)
557 + (sym->value[3] << 24);
558 altname = sym->name[4] + (sym->name[5] << 8)
559 + (sym->name[6] << 16)
560 + (sym->name[3] << 24);
561 t = (sym->type[1] << 8) + sym->type[0];
562 /* TODO: big endian COFF? */
563 /* debug("' value=0x%x type=0x%04x", v, t); */
564
565 if (t == 0x20 && sym->name[0]) {
566 memcpy(name, sym->name, 8);
567 name[8] = '\0';
568 add_symbol_name(&m->symbol_context,
569 v, 0, name, 0);
570 n_real_symbols ++;
571 } else if (t == 0x20 && !sym->name[0]) {
572 off_t ofs;
573 ofs = f_symptr + altname +
574 sizeof(struct ms_sym) * f_nsyms;
575 fseek(f, ofs, SEEK_SET);
576 fread(name, 1, sizeof(name), f);
577 name[sizeof(name)-1] = '\0';
578 /* debug(" [altname=0x%x '%s']",
579 altname, name); */
580 add_symbol_name(&m->symbol_context,
581 v, 0, name, 0);
582 n_real_symbols ++;
583 }
584
585
586 if (sym->n_aux_syms) {
587 int n = sym->n_aux_syms;
588 /* debug(" aux='"); */
589 while (n-- > 0) {
590 sym ++; sym_nr ++;
591 /* for (i=0; i<8 &&
592 sym->name[i]; i++)
593 debug("%c",
594 sym->name[i]); */
595 }
596 /* debug("'"); */
597 }
598 /* debug("\n"); */
599 sym ++;
600 }
601
602 debug("%i symbols\n", n_real_symbols);
603 free(ms_sym_buf);
604
605 goto skip_normal_coff_symbols;
606 }
607
608 debug("symbol header: magic = 0x%x\n", sym_magic);
609
610 debug("%i symbols @ 0x%08x (strings @ 0x%08x)\n",
611 iextMax, cbExtOffset, cbSsExtOffset);
612
613 symbol_data = malloc(issExtMax + 2);
614 if (symbol_data == NULL) {
615 fprintf(stderr, "out of memory\n");
616 exit(1);
617 }
618 memset(symbol_data, 0, issExtMax + 2);
619 fseek(f, cbSsExtOffset, SEEK_SET);
620 fread(symbol_data, 1, issExtMax + 1, f);
621
622 nsymbols = iextMax;
623
624 extsyms = malloc(iextMax * sizeof(struct ecoff_extsym));
625 if (extsyms == NULL) {
626 fprintf(stderr, "out of memory\n");
627 exit(1);
628 }
629 memset(extsyms, 0, iextMax * sizeof(struct ecoff_extsym));
630 fseek(f, cbExtOffset, SEEK_SET);
631 fread(extsyms, 1, iextMax * sizeof(struct ecoff_extsym), f);
632
633 /* Unencode the strindex and value first: */
634 for (sym_nr=0; sym_nr<nsymbols; sym_nr++) {
635 uint64_t value, strindex;
636
637 unencode(strindex, &extsyms[sym_nr].es_strindex,
638 uint32_t);
639 unencode(value, &extsyms[sym_nr].es_value, uint32_t);
640
641 extsyms[sym_nr].es_strindex = strindex;
642 extsyms[sym_nr].es_value = value;
643 }
644
645 for (sym_nr=0; sym_nr<nsymbols; sym_nr++) {
646 /* debug("symbol%6i: 0x%08x = %s\n",
647 sym_nr, (int)extsyms[sym_nr].es_value,
648 symbol_data + extsyms[sym_nr].es_strindex); */
649
650 add_symbol_name(&m->symbol_context,
651 extsyms[sym_nr].es_value, 0,
652 symbol_data + extsyms[sym_nr].es_strindex, 0);
653 }
654
655 free(extsyms);
656 free(symbol_data);
657
658 skip_normal_coff_symbols:
659 ;
660 }
661
662 fclose(f);
663
664 *entrypointp = a_entry;
665 *gpp = a_gp;
666 m->file_loaded_end_addr = end_addr;
667
668 if (program_byte_order != -1)
669 encoding = program_byte_order;
670
671 if (encoding == ELFDATA2LSB)
672 *byte_orderp = EMUL_LITTLE_ENDIAN;
673 else
674 *byte_orderp = EMUL_BIG_ENDIAN;
675
676 n_executables_loaded ++;
677 }
678
679
680 /*
681 * file_load_srec():
682 *
683 * Loads a Motorola SREC file into emulated memory. Description of the SREC
684 * file format can be found at here:
685 *
686 * http://www.ndsu.nodak.edu/instruct/tareski/373f98/notes/srecord.htm
687 * or http://www.amelek.gda.pl/avr/uisp/srecord.htm
688 */
689 static void file_load_srec(struct machine *m, struct memory *mem,
690 char *filename, uint64_t *entrypointp)
691 {
692 FILE *f;
693 unsigned char buf[516];
694 unsigned char bytes[270];
695 uint64_t entry = 0, vaddr = 0;
696 int i, j, count;
697 char ch;
698 int buf_len, data_start = 0;
699 int entry_set = 0;
700 int warning = 0;
701 int warning_len = 0;
702 int total_bytes_loaded = 0;
703
704 f = fopen(filename, "r");
705 if (f == NULL) {
706 perror(filename);
707 exit(1);
708 }
709
710 /* Load file contents: */
711 while (!feof(f)) {
712 memset(buf, 0, sizeof(buf));
713 fgets((char *)buf, sizeof(buf)-1, f);
714
715 if (buf[0] == 0 || buf[0]=='\r' || buf[0]=='\n')
716 continue;
717
718 if (buf[0] != 'S') {
719 if (!warning)
720 debug("WARNING! non-S-record found\n");
721 warning = 1;
722 continue;
723 }
724
725 buf_len = strlen((char *)buf);
726
727 if (buf_len < 10) {
728 if (!warning_len)
729 debug("WARNING! invalid S-record found\n");
730 warning_len = 1;
731 continue;
732 }
733
734 /*
735 * Stype count address data checksum
736 * 01 23 4.. .. (last 2 bytes)
737 *
738 * TODO: actually check the checksum
739 */
740
741 j = 0;
742 for (i=1; i<buf_len; i++) {
743 if (buf[i]>='a' && buf[i]<='f')
744 buf[i] += 10 - 'a';
745 else if (buf[i] >= 'A' && buf[i] <= 'F')
746 buf[i] += 10 - 'A';
747 else if (buf[i] >= '0' && buf[i] <= '9')
748 buf[i] -= '0';
749 else if (buf[i] == '\r' || buf[i] == '\n') {
750 } else
751 fatal("invalid characters '%c' in S-record\n",
752 buf[i]);
753
754 if (i >= 4) {
755 if (i & 1)
756 bytes[j++] += buf[i];
757 else
758 bytes[j] = buf[i] * 16;
759 }
760 }
761
762 count = buf[2] * 16 + buf[3];
763 /* debug("count=%i j=%i\n", count, j); */
764 /* count is j - 1. */
765
766 switch (buf[1]) {
767 case 0:
768 debug("SREC \"");
769 for (i=2; i<count-1; i++) {
770 ch = bytes[i];
771 if (ch >= ' ' && ch < 127)
772 debug("%c", ch);
773 else
774 debug("?");
775 }
776 debug("\"\n");
777 break;
778 case 1:
779 case 2:
780 case 3:
781 /* switch again, to get the load address: */
782 switch (buf[1]) {
783 case 1: data_start = 2;
784 vaddr = (bytes[0] << 8) + bytes[1];
785 break;
786 case 2: data_start = 3;
787 vaddr = (bytes[0] << 16) + (bytes[1] << 8) +
788 bytes[2];
789 break;
790 case 3: data_start = 4;
791 vaddr = (bytes[0] << 24) + (bytes[1] << 16) +
792 (bytes[2] << 8) + bytes[3];
793 }
794 m->cpus[0]->memory_rw(m->cpus[0], mem, vaddr,
795 &bytes[data_start], count - 1 - data_start,
796 MEM_WRITE, NO_EXCEPTIONS);
797 total_bytes_loaded += count - 1 - data_start;
798 break;
799 case 7:
800 case 8:
801 case 9:
802 /* switch again, to get the entry point: */
803 switch (buf[1]) {
804 case 7: entry = (bytes[0] << 24) + (bytes[1] << 16) +
805 (bytes[2] << 8) + bytes[3];
806 break;
807 case 8: entry = (bytes[0] << 16) + (bytes[1] << 8) +
808 bytes[2];
809 break;
810 case 9: entry = (bytes[0] << 8) + bytes[1];
811 break;
812 }
813 entry_set = 1;
814 debug("entry point 0x%08x\n", (unsigned int)entry);
815 break;
816 default:
817 debug("unimplemented S-record type %i\n", buf[1]);
818 }
819 }
820
821 debug("0x%x bytes loaded\n", total_bytes_loaded);
822
823 fclose(f);
824
825 if (!entry_set)
826 debug("WARNING! no entrypoint found!\n");
827 else
828 *entrypointp = entry;
829
830 n_executables_loaded ++;
831 }
832
833
834 /*
835 * file_load_raw():
836 *
837 * Loads a raw binary into emulated memory. The filename should be
838 * of the following form: loadaddress:filename
839 * or loadaddress:skiplen:filename
840 * or loadaddress:skiplen:pc:filename
841 */
842 static void file_load_raw(struct machine *m, struct memory *mem,
843 char *filename, uint64_t *entrypointp)
844 {
845 FILE *f;
846 int len;
847 unsigned char buf[4096];
848 uint64_t entry, loadaddr, vaddr, skip = 0;
849 char *p, *p2;
850
851 p = strchr(filename, ':');
852 if (p == NULL) {
853 fprintf(stderr, "\n");
854 perror(filename);
855 exit(1);
856 }
857
858 loadaddr = vaddr = entry = strtoull(filename, NULL, 0);
859 p2 = p+1;
860
861 /* A second value? That's the optional skip value */
862 p = strchr(p2, ':');
863 if (p != NULL) {
864 skip = strtoull(p2, NULL, 0);
865 p = p+1;
866 /* A third value? That's the initial pc: */
867 if (strchr(p, ':') != NULL) {
868 entry = strtoull(p, NULL, 0);
869 p = strchr(p, ':') + 1;
870 }
871 } else
872 p = p2;
873
874 f = fopen(strrchr(filename, ':')+1, "r");
875 if (f == NULL) {
876 perror(p);
877 exit(1);
878 }
879
880 fseek(f, skip, SEEK_SET);
881
882 /* Load file contents: */
883 while (!feof(f)) {
884 len = fread(buf, 1, sizeof(buf), f);
885
886 if (len > 0)
887 m->cpus[0]->memory_rw(m->cpus[0], mem, vaddr, &buf[0],
888 len, MEM_WRITE, NO_EXCEPTIONS);
889
890 vaddr += len;
891 }
892
893 debug("RAW: 0x%llx bytes @ 0x%08llx",
894 (long long) (ftell(f) - skip), (long long)loadaddr);
895 if (skip != 0)
896 debug(" (0x%llx bytes of header skipped)", (long long)skip);
897 debug("\n");
898
899 fclose(f);
900
901 *entrypointp = entry;
902
903 n_executables_loaded ++;
904 }
905
906
907 /*
908 * file_load_elf():
909 *
910 * Loads an ELF image into the emulated memory. The entry point (read from
911 * the ELF header) and the initial value of the gp register (read from the
912 * ELF symbol table) are stored in the specified CPU's registers.
913 *
914 * This is pretty heavy stuff, but is needed because of the heaviness of
915 * ELF files. :-/ Hopefully it will be able to recognize most valid ELFs.
916 */
917 static void file_load_elf(struct machine *m, struct memory *mem,
918 char *filename, uint64_t *entrypointp, int arch, uint64_t *gpp,
919 int *byte_order, uint64_t *tocp)
920 {
921 Elf32_Ehdr hdr32;
922 Elf64_Ehdr hdr64;
923 FILE *f;
924 uint64_t eentry;
925 int len, i, ok;
926 int elf64, encoding, eflags;
927 int etype, emachine;
928 int ephnum, ephentsize, eshnum, eshentsize;
929 off_t ephoff, eshoff;
930 Elf32_Phdr phdr32;
931 Elf64_Phdr phdr64;
932 Elf32_Shdr shdr32;
933 Elf64_Shdr shdr64;
934 Elf32_Sym sym32;
935 Elf64_Sym sym64;
936 int ofs;
937 int chunk_len = 1024, align_len;
938 char *symbol_strings = NULL; size_t symbol_length = 0;
939 char *s;
940 Elf32_Sym *symbols_sym32 = NULL; int n_symbols = 0;
941 Elf64_Sym *symbols_sym64 = NULL;
942
943 f = fopen(filename, "r");
944 if (f == NULL) {
945 perror(filename);
946 exit(1);
947 }
948
949 len = fread(&hdr32, 1, sizeof(Elf32_Ehdr), f);
950 if (len < (signed int)sizeof(Elf32_Ehdr)) {
951 fprintf(stderr, "%s: not an ELF file image\n", filename);
952 exit(1);
953 }
954
955 if (memcmp(&hdr32.e_ident[EI_MAG0], ELFMAG, SELFMAG) != 0) {
956 fprintf(stderr, "%s: not an ELF file image\n", filename);
957 exit(1);
958 }
959
960 switch (hdr32.e_ident[EI_CLASS]) {
961 case ELFCLASS32:
962 elf64 = 0;
963 break;
964 case ELFCLASS64:
965 elf64 = 1;
966 fseek(f, 0, SEEK_SET);
967 len = fread(&hdr64, 1, sizeof(Elf64_Ehdr), f);
968 if (len < (signed int)sizeof(Elf64_Ehdr)) {
969 fprintf(stderr, "%s: not an ELF64 file image\n",
970 filename);
971 exit(1);
972 }
973 break;
974 default:
975 fprintf(stderr, "%s: unknown ELF class '%i'\n",
976 filename, hdr32.e_ident[EI_CLASS]);
977 exit(1);
978 }
979
980 encoding = hdr32.e_ident[EI_DATA];
981 if (encoding != ELFDATA2LSB && encoding != ELFDATA2MSB) {
982 fprintf(stderr, "%s: unknown data encoding '%i'\n",
983 filename, hdr32.e_ident[EI_DATA]);
984 exit(1);
985 }
986
987 if (elf64) {
988 unencode(etype, &hdr64.e_type, Elf64_Quarter);
989 unencode(eflags, &hdr64.e_flags, Elf64_Half);
990 unencode(emachine, &hdr64.e_machine, Elf64_Quarter);
991 unencode(eentry, &hdr64.e_entry, Elf64_Addr);
992 unencode(ephnum, &hdr64.e_phnum, Elf64_Quarter);
993 unencode(ephentsize, &hdr64.e_phentsize, Elf64_Quarter);
994 unencode(ephoff, &hdr64.e_phoff, Elf64_Off);
995 unencode(eshnum, &hdr64.e_shnum, Elf64_Quarter);
996 unencode(eshentsize, &hdr64.e_shentsize, Elf64_Quarter);
997 unencode(eshoff, &hdr64.e_shoff, Elf64_Off);
998 if (ephentsize != sizeof(Elf64_Phdr)) {
999 fprintf(stderr, "%s: incorrect phentsize? %i, should "
1000 "be %i\n", filename, (int)ephentsize,
1001 (int)sizeof(Elf64_Phdr));
1002 exit(1);
1003 }
1004 if (eshentsize != sizeof(Elf64_Shdr)) {
1005 fprintf(stderr, "%s: incorrect phentsize? %i, should "
1006 "be %i\n", filename, (int)ephentsize,
1007 (int)sizeof(Elf64_Shdr));
1008 exit(1);
1009 }
1010 } else {
1011 unencode(etype, &hdr32.e_type, Elf32_Half);
1012 unencode(eflags, &hdr32.e_flags, Elf32_Word);
1013 unencode(emachine, &hdr32.e_machine, Elf32_Half);
1014 unencode(eentry, &hdr32.e_entry, Elf32_Addr);
1015 unencode(ephnum, &hdr32.e_phnum, Elf32_Half);
1016 unencode(ephentsize, &hdr32.e_phentsize, Elf32_Half);
1017 unencode(ephoff, &hdr32.e_phoff, Elf32_Off);
1018 unencode(eshnum, &hdr32.e_shnum, Elf32_Half);
1019 unencode(eshentsize, &hdr32.e_shentsize, Elf32_Half);
1020 unencode(eshoff, &hdr32.e_shoff, Elf32_Off);
1021 if (ephentsize != sizeof(Elf32_Phdr)) {
1022 fprintf(stderr, "%s: incorrect phentsize? %i, should "
1023 "be %i\n", filename, (int)ephentsize,
1024 (int)sizeof(Elf32_Phdr));
1025 exit(1);
1026 }
1027 if (eshentsize != sizeof(Elf32_Shdr)) {
1028 fprintf(stderr, "%s: incorrect phentsize? %i, should "
1029 "be %i\n", filename, (int)ephentsize,
1030 (int)sizeof(Elf32_Shdr));
1031 exit(1);
1032 }
1033 }
1034
1035 if ( etype != ET_EXEC ) {
1036 fprintf(stderr, "%s is not an ELF Executable file, type = %i\n",
1037 filename, etype);
1038 exit(1);
1039 }
1040
1041 ok = 0;
1042 switch (arch) {
1043 case ARCH_MIPS:
1044 switch (emachine) {
1045 case EM_MIPS:
1046 case EM_MIPS_RS3_LE:
1047 ok = 1;
1048 }
1049 break;
1050 case ARCH_PPC:
1051 switch (emachine) {
1052 case EM_PPC:
1053 case EM_PPC64:
1054 ok = 1;
1055 }
1056 break;
1057 case ARCH_SPARC:
1058 switch (emachine) {
1059 case EM_SPARC:
1060 case EM_SPARCV9:
1061 ok = 1;
1062 }
1063 break;
1064 case ARCH_HPPA:
1065 switch (emachine) {
1066 case EM_PARISC:
1067 ok = 1;
1068 }
1069 break;
1070 case ARCH_ALPHA:
1071 switch (emachine) {
1072 case EM_ALPHA:
1073 case -28634:
1074 ok = 1;
1075 }
1076 break;
1077 default:
1078 fatal("file.c: INTERNAL ERROR: Unimplemented arch!\n");
1079 }
1080 if (!ok) {
1081 fprintf(stderr, "%s: this is a ", filename);
1082 if (emachine >= 0 && emachine < N_ELF_MACHINE_TYPES)
1083 fprintf(stderr, elf_machine_type[emachine]);
1084 else
1085 fprintf(stderr, "machine type '%i'", emachine);
1086 fprintf(stderr, " ELF binary!\n");
1087 exit(1);
1088 }
1089
1090 s = "entry point";
1091 if (elf64 && arch == ARCH_PPC)
1092 s = "function descriptor at";
1093
1094 debug("ELF%i %s, %s 0x", elf64? 64 : 32,
1095 encoding == ELFDATA2LSB? "LSB (LE)" : "MSB (BE)", s);
1096
1097 if (elf64)
1098 debug("%016llx\n", (long long)eentry);
1099 else
1100 debug("%08x\n", (int)eentry);
1101
1102 /*
1103 * MIPS16 encoding?
1104 *
1105 * TODO: Find out what e_flag actually contains.
1106 * TODO 2: This only sets mips16 for cpu 0. Yuck. Fix this!
1107 */
1108
1109 if (((eflags >> 24) & 0xff) == 0x24) {
1110 debug("MIPS16 encoding (e_flags = 0x%08x)\n", eflags);
1111 #ifdef ENABLE_MIPS16
1112 m->cpus[0]->cd.mips.mips16 = 1;
1113 #else
1114 fatal("ENABLE_MIPS16 must be defined in misc.h.\n"
1115 "(or use the --mips16 configure option)\n");
1116 exit(1);
1117 #endif
1118 } else if (eentry & 0x3) {
1119 debug("MIPS16 encoding (eentry not 32-bit aligned)\n");
1120 #ifdef ENABLE_MIPS16
1121 m->cpus[0]->cd.mips.mips16 = 1;
1122 #else
1123 fatal("ENABLE_MIPS16 must be defined in misc.h.\n"
1124 "(or use the --mips16 configure option)\n");
1125 exit(1);
1126 #endif
1127 }
1128
1129 /* Read the program headers: */
1130
1131 for (i=0; i<ephnum; i++) {
1132 int p_type;
1133 uint64_t p_offset;
1134 uint64_t p_vaddr;
1135 uint64_t p_paddr;
1136 uint64_t p_filesz;
1137 uint64_t p_memsz;
1138 int p_flags;
1139 int p_align;
1140
1141 fseek(f, ephoff + i * ephentsize, SEEK_SET);
1142
1143 if (elf64) {
1144 fread(&phdr64, 1, sizeof(Elf64_Phdr), f);
1145 unencode(p_type, &phdr64.p_type, Elf64_Half);
1146 unencode(p_flags, &phdr64.p_flags, Elf64_Half);
1147 unencode(p_offset, &phdr64.p_offset, Elf64_Off);
1148 unencode(p_vaddr, &phdr64.p_vaddr, Elf64_Addr);
1149 unencode(p_paddr, &phdr64.p_paddr, Elf64_Addr);
1150 unencode(p_filesz, &phdr64.p_filesz, Elf64_Xword);
1151 unencode(p_memsz, &phdr64.p_memsz, Elf64_Xword);
1152 unencode(p_align, &phdr64.p_align, Elf64_Xword);
1153 } else {
1154 fread(&phdr32, 1, sizeof(Elf32_Phdr), f);
1155 unencode(p_type, &phdr32.p_type, Elf32_Word);
1156 unencode(p_offset, &phdr32.p_offset, Elf32_Off);
1157 unencode(p_vaddr, &phdr32.p_vaddr, Elf32_Addr);
1158 unencode(p_paddr, &phdr32.p_paddr, Elf32_Addr);
1159 unencode(p_filesz, &phdr32.p_filesz, Elf32_Word);
1160 unencode(p_memsz, &phdr32.p_memsz, Elf32_Word);
1161 unencode(p_flags, &phdr32.p_flags, Elf32_Word);
1162 unencode(p_align, &phdr32.p_align, Elf32_Word);
1163 }
1164
1165 if (p_memsz != 0 && (p_type == PT_LOAD ||
1166 (p_type & PF_MASKPROC) == PT_MIPS_REGINFO)) {
1167 debug("chunk %i (", i);
1168 if (p_type == PT_LOAD)
1169 debug("load");
1170 else
1171 debug("0x%08x", (int)p_type);
1172
1173 debug(") @ 0x%llx, vaddr 0x", (long long)p_offset);
1174
1175 if (elf64)
1176 debug("%016llx", (long long)p_vaddr);
1177 else
1178 debug("%08x", (int)p_vaddr);
1179
1180 debug(" len=0x%llx\n", (long long)p_memsz);
1181
1182 if (p_vaddr != p_paddr) {
1183 fprintf(stderr, "%s: vaddr != paddr. TODO: "
1184 "how to handle this? vaddr=%016llx paddr"
1185 "=%016llx\n", filename, (long long)p_vaddr,
1186 (long long)p_paddr);
1187 exit(1);
1188 }
1189
1190 if (p_memsz < p_filesz) {
1191 fprintf(stderr, "%s: memsz < filesz. TODO: how"
1192 " to handle this? memsz=%016llx filesz="
1193 "%016llx\n", filename, (long long)p_memsz,
1194 (long long)p_filesz);
1195 exit(1);
1196 }
1197
1198 fseek(f, p_offset, SEEK_SET);
1199 align_len = 1;
1200 if ((p_vaddr & 0xf)==0) align_len = 0x10;
1201 if ((p_vaddr & 0x3f)==0) align_len = 0x40;
1202 if ((p_vaddr & 0xff)==0) align_len = 0x100;
1203 if ((p_vaddr & 0xfff)==0) align_len = 0x1000;
1204 if ((p_vaddr & 0x3fff)==0) align_len = 0x4000;
1205 if ((p_vaddr & 0xffff)==0) align_len = 0x10000;
1206 ofs = 0; len = chunk_len = align_len;
1207 while (ofs < (int64_t)p_filesz && len==chunk_len) {
1208 unsigned char *ch = malloc(chunk_len);
1209 int i = 0;
1210
1211 /* Switch to larger size, if possible: */
1212 if (align_len < 0x10000 &&
1213 ((p_vaddr + ofs) & 0xffff)==0) {
1214 align_len = 0x10000;
1215 len = chunk_len = align_len;
1216 free(ch);
1217 ch = malloc(chunk_len);
1218 } else if (align_len < 0x1000 &&
1219 ((p_vaddr + ofs) & 0xfff)==0) {
1220 align_len = 0x1000;
1221 len = chunk_len = align_len;
1222 free(ch);
1223 ch = malloc(chunk_len);
1224 }
1225
1226 if (ch == NULL) {
1227 fprintf(stderr, "out of memory\n");
1228 exit(1);
1229 }
1230
1231 len = fread(&ch[0], 1, chunk_len, f);
1232 if (ofs + len > (int64_t)p_filesz)
1233 len = p_filesz - ofs;
1234
1235 while (i < len) {
1236 size_t len_to_copy;
1237 len_to_copy = (i + align_len) <= len?
1238 align_len : len - i;
1239 m->cpus[0]->memory_rw(m->cpus[0], mem,
1240 p_vaddr + ofs, &ch[i], len_to_copy,
1241 MEM_WRITE, NO_EXCEPTIONS);
1242 ofs += align_len;
1243 i += align_len;
1244 }
1245
1246 free(ch);
1247 }
1248 }
1249 }
1250
1251 /* Read the section headers to find the address of the _gp symbol: */
1252
1253 for (i=0; i<eshnum; i++) {
1254 int sh_name, sh_type, sh_flags, sh_link, sh_info, sh_entsize;
1255 uint64_t sh_addr, sh_size, sh_addralign;
1256 off_t sh_offset;
1257 int n_entries; /* for reading the symbol / string tables */
1258
1259 /* debug("section header %i at %016llx\n", i,
1260 (long long) eshoff+i*eshentsize); */
1261
1262 fseek(f, eshoff + i * eshentsize, SEEK_SET);
1263
1264 if (elf64) {
1265 len = fread(&shdr64, 1, sizeof(Elf64_Shdr), f);
1266 if (len != sizeof(Elf64_Shdr)) {
1267 fprintf(stderr, "couldn't read header\n");
1268 exit(1);
1269 }
1270 unencode(sh_name, &shdr64.sh_name, Elf64_Half);
1271 unencode(sh_type, &shdr64.sh_type, Elf64_Half);
1272 unencode(sh_flags, &shdr64.sh_flags, Elf64_Xword);
1273 unencode(sh_addr, &shdr64.sh_addr, Elf64_Addr);
1274 unencode(sh_offset, &shdr64.sh_offset, Elf64_Off);
1275 unencode(sh_size, &shdr64.sh_size, Elf64_Xword);
1276 unencode(sh_link, &shdr64.sh_link, Elf64_Half);
1277 unencode(sh_info, &shdr64.sh_info, Elf64_Half);
1278 unencode(sh_addralign, &shdr64.sh_addralign,
1279 Elf64_Xword);
1280 unencode(sh_entsize, &shdr64.sh_entsize, Elf64_Xword);
1281 } else {
1282 len = fread(&shdr32, 1, sizeof(Elf32_Shdr), f);
1283 if (len != sizeof(Elf32_Shdr)) {
1284 fprintf(stderr, "couldn't read header\n");
1285 exit(1);
1286 }
1287 unencode(sh_name, &shdr32.sh_name, Elf32_Word);
1288 unencode(sh_type, &shdr32.sh_type, Elf32_Word);
1289 unencode(sh_flags, &shdr32.sh_flags, Elf32_Word);
1290 unencode(sh_addr, &shdr32.sh_addr, Elf32_Addr);
1291 unencode(sh_offset, &shdr32.sh_offset, Elf32_Off);
1292 unencode(sh_size, &shdr32.sh_size, Elf32_Word);
1293 unencode(sh_link, &shdr32.sh_link, Elf32_Word);
1294 unencode(sh_info, &shdr32.sh_info, Elf32_Word);
1295 unencode(sh_addralign, &shdr32.sh_addralign,Elf32_Word);
1296 unencode(sh_entsize, &shdr32.sh_entsize, Elf32_Word);
1297 }
1298
1299 /* debug("sh_name=%04lx, sh_type=%08lx, sh_flags=%08lx"
1300 " sh_size=%06lx sh_entsize=%03lx\n",
1301 (long)sh_name, (long)sh_type, (long)sh_flags,
1302 (long)sh_size, (long)sh_entsize); */
1303
1304 /* Perhaps it is bad to reuse sh_entsize like this? TODO */
1305 if (elf64)
1306 sh_entsize = sizeof(Elf64_Sym);
1307 else
1308 sh_entsize = sizeof(Elf32_Sym);
1309
1310 if (sh_type == SHT_SYMTAB) {
1311 size_t len;
1312 n_entries = sh_size / sh_entsize;
1313
1314 fseek(f, sh_offset, SEEK_SET);
1315
1316 if (elf64) {
1317 if (symbols_sym64 != NULL)
1318 free(symbols_sym64);
1319 symbols_sym64 = malloc(sh_size);
1320 if (symbols_sym64 == NULL) {
1321 fprintf(stderr, "out of memory\n");
1322 exit(1);
1323 }
1324
1325 len = fread(symbols_sym64, 1, sh_entsize *
1326 n_entries, f);
1327 } else {
1328 if (symbols_sym32 != NULL)
1329 free(symbols_sym32);
1330 symbols_sym32 = malloc(sh_size);
1331 if (symbols_sym32 == NULL) {
1332 fprintf(stderr, "out of memory\n");
1333 exit(1);
1334 }
1335
1336 len = fread(symbols_sym32, 1,
1337 sh_entsize * n_entries, f);
1338 }
1339
1340 if (len != sh_size) {
1341 fprintf(stderr, "could not read symbols from "
1342 "%s\n", filename);
1343 exit(1);
1344 }
1345
1346 debug("%i symbol entries at 0x%llx\n",
1347 (int)n_entries, (long long)sh_offset);
1348
1349 n_symbols = n_entries;
1350 }
1351
1352 /*
1353 * TODO: This is incorrect, there may be several strtab
1354 * sections.
1355 *
1356 * For now, the simple/stupid guess that the largest string
1357 * table is the one to use seems to be good enough.
1358 */
1359
1360 if (sh_type == SHT_STRTAB && sh_size > symbol_length) {
1361 size_t len;
1362
1363 if (symbol_strings != NULL)
1364 free(symbol_strings);
1365
1366 symbol_strings = malloc(sh_size + 1);
1367 if (symbol_strings == NULL) {
1368 fprintf(stderr, "out of memory\n");
1369 exit(1);
1370 }
1371
1372 fseek(f, sh_offset, SEEK_SET);
1373 len = fread(symbol_strings, 1, sh_size, f);
1374 if (len != sh_size) {
1375 fprintf(stderr, "could not read symbols from "
1376 "%s\n", filename);
1377 exit(1);
1378 }
1379
1380 debug("%i bytes of symbol strings at 0x%llx\n",
1381 (int)sh_size, (long long)sh_offset);
1382
1383 symbol_strings[sh_size] = '\0';
1384 symbol_length = sh_size;
1385 }
1386 }
1387
1388 fclose(f);
1389
1390 /* Decode symbols: */
1391 if (symbol_strings != NULL) {
1392 for (i=0; i<n_symbols; i++) {
1393 uint64_t st_name, addr, size;
1394 int st_info;
1395
1396 if (elf64) {
1397 sym64 = symbols_sym64[i];
1398 unencode(st_name, &sym64.st_name, Elf64_Half);
1399 unencode(st_info, &sym64.st_info, Elf_Byte);
1400 unencode(addr, &sym64.st_value, Elf64_Addr);
1401 unencode(size, &sym64.st_size, Elf64_Xword);
1402 } else {
1403 sym32 = symbols_sym32[i];
1404 unencode(st_name, &sym32.st_name, Elf32_Word);
1405 unencode(st_info, &sym64.st_info, Elf_Byte);
1406 unencode(addr, &sym32.st_value, Elf32_Word);
1407 unencode(size, &sym32.st_size, Elf32_Word);
1408 }
1409
1410 if (size == 0)
1411 size ++;
1412
1413 if (addr != 0) {
1414 /* debug("symbol info=0x%02x addr=0x%016llx"
1415 " '%s'\n", st_info, (long long)addr,
1416 symbol_strings + st_name); */
1417 add_symbol_name(&m->symbol_context,
1418 addr, size, symbol_strings + st_name, 0);
1419 }
1420
1421 if (strcmp(symbol_strings + st_name, "_gp") == 0) {
1422 debug("found _gp address: 0x");
1423 if (elf64)
1424 debug("%016llx\n", (long long)addr);
1425 else
1426 debug("%08x\n", (int)addr);
1427 *gpp = addr;
1428 }
1429 }
1430 }
1431
1432 *entrypointp = eentry;
1433
1434 if (encoding == ELFDATA2LSB)
1435 *byte_order = EMUL_LITTLE_ENDIAN;
1436 else
1437 *byte_order = EMUL_BIG_ENDIAN;
1438
1439 if (elf64 && arch == ARCH_PPC) {
1440 /*
1441 * Special case for 64-bit PPC ELFs:
1442 *
1443 * The ELF starting symbol points to a ".opd" section
1444 * which contains a function descriptor:
1445 *
1446 * uint64_t start;
1447 * uint64_t toc_base;
1448 * uint64_t something_else; (?)
1449 */
1450 int res;
1451 unsigned char b[sizeof(uint64_t)];
1452 uint64_t toc_base;
1453
1454 debug("PPC64: ");
1455
1456 res = m->cpus[0]->memory_rw(m->cpus[0], mem, eentry, b,
1457 sizeof(b), MEM_READ, NO_EXCEPTIONS);
1458 if (!res)
1459 debug(" [WARNING: could not read memory?] ");
1460
1461 /* PPC are always big-endian: */
1462 *entrypointp = ((uint64_t)b[0] << 56) +
1463 ((uint64_t)b[1] << 48) + ((uint64_t)b[2] << 40) +
1464 ((uint64_t)b[3] << 32) + ((uint64_t)b[4] << 24) +
1465 ((uint64_t)b[5] << 16) + ((uint64_t)b[6] << 8) +
1466 (uint64_t)b[7];
1467
1468 res = m->cpus[0]->memory_rw(m->cpus[0], mem, eentry + 8,
1469 b, sizeof(b), MEM_READ, NO_EXCEPTIONS);
1470 if (!res)
1471 fatal(" [WARNING: could not read memory?] ");
1472
1473 toc_base = ((uint64_t)b[0] << 56) +
1474 ((uint64_t)b[1] << 48) + ((uint64_t)b[2] << 40) +
1475 ((uint64_t)b[3] << 32) + ((uint64_t)b[4] << 24) +
1476 ((uint64_t)b[5] << 16) + ((uint64_t)b[6] << 8) +
1477 (uint64_t)b[7];
1478
1479 debug("entrypoint 0x%016llx, toc_base 0x%016llx\n",
1480 (long long)*entrypointp, (long long)toc_base);
1481 if (tocp != NULL)
1482 *tocp = toc_base;
1483 }
1484
1485 n_executables_loaded ++;
1486 }
1487
1488
1489 /*
1490 * file_n_executables_loaded():
1491 *
1492 * Returns the number of executable files loaded into emulated memory.
1493 */
1494 int file_n_executables_loaded(void)
1495 {
1496 return n_executables_loaded;
1497 }
1498
1499
1500 /*
1501 * file_load():
1502 *
1503 * Sense the file format of a file (ELF, a.out, ecoff), and call the
1504 * right file_load_XXX() function. If the file isn't of a recognized
1505 * binary format, assume that it contains symbol definitions.
1506 *
1507 * If the filename doesn't exist, try to treat the name as
1508 * "address:filename" and load the file as a raw binary.
1509 */
1510 void file_load(struct machine *machine, struct memory *mem,
1511 char *filename, uint64_t *entrypointp,
1512 int arch, uint64_t *gpp, int *byte_orderp, uint64_t *tocp)
1513 {
1514 int iadd = 4;
1515 FILE *f;
1516 unsigned char buf[12];
1517 int len, i;
1518 off_t size;
1519
1520 if (byte_orderp == NULL) {
1521 fprintf(stderr, "file_load(): byte_order == NULL\n");
1522 exit(1);
1523 }
1524
1525 if (arch == ARCH_NOARCH) {
1526 fprintf(stderr, "file_load(): FATAL ERROR: no arch?\n");
1527 exit(1);
1528 }
1529
1530 if (mem == NULL || filename == NULL) {
1531 fprintf(stderr, "file_load(): mem or filename is NULL\n");
1532 exit(1);
1533 }
1534
1535 /* Skip configuration files: */
1536 if (filename[0] == '@')
1537 return;
1538
1539 debug("loading %s:\n", filename);
1540 debug_indentation(iadd);
1541
1542 f = fopen(filename, "r");
1543 if (f == NULL) {
1544 file_load_raw(machine, mem, filename, entrypointp);
1545 goto ret;
1546 }
1547
1548 fseek(f, 0, SEEK_END);
1549 size = ftell(f);
1550 fseek(f, 0, SEEK_SET);
1551
1552 memset(buf, 0, sizeof(buf));
1553 len = fread(buf, 1, sizeof(buf), f);
1554 fclose(f);
1555
1556 if (len < (signed int)sizeof(buf)) {
1557 fprintf(stderr, "\nThis file is too small to contain "
1558 "anything useful\n");
1559 exit(1);
1560 }
1561
1562 /* Is it an ELF? */
1563 if (buf[0] == 0x7f && buf[1]=='E' && buf[2]=='L' && buf[3]=='F') {
1564 file_load_elf(machine, mem, filename,
1565 entrypointp, arch, gpp, byte_orderp, tocp);
1566 goto ret;
1567 }
1568
1569 /* Is it an a.out? (Special case for DEC OSF1 kernels.) */
1570 if (buf[0]==0x00 && buf[1]==0x8b && buf[2]==0x01 && buf[3]==0x07) {
1571 file_load_aout(machine, mem, filename, 0,
1572 entrypointp, arch, byte_orderp);
1573 goto ret;
1574 }
1575 if (buf[0]==0x00 && buf[2]==0x00 && buf[8]==0x7a && buf[9]==0x75) {
1576 file_load_aout(machine, mem, filename, 1,
1577 entrypointp, arch, byte_orderp);
1578 goto ret;
1579 }
1580
1581 /*
1582 * Is it an ecoff?
1583 *
1584 * TODO: What's the deal with the magic value's byte order? Sometimes
1585 * it seems to be reversed for BE when compared to LE, but not always?
1586 */
1587 if (buf[0]+256*buf[1] == ECOFF_MAGIC_MIPSEB ||
1588 buf[0]+256*buf[1] == ECOFF_MAGIC_MIPSEL ||
1589 buf[0]+256*buf[1] == ECOFF_MAGIC_MIPSEB2 ||
1590 buf[0]+256*buf[1] == ECOFF_MAGIC_MIPSEL2 ||
1591 buf[0]+256*buf[1] == ECOFF_MAGIC_MIPSEB3 ||
1592 buf[0]+256*buf[1] == ECOFF_MAGIC_MIPSEL3 ||
1593 buf[1]+256*buf[0] == ECOFF_MAGIC_MIPSEB ||
1594 buf[1]+256*buf[0] == ECOFF_MAGIC_MIPSEL ||
1595 buf[1]+256*buf[0] == ECOFF_MAGIC_MIPSEB2 ||
1596 buf[1]+256*buf[0] == ECOFF_MAGIC_MIPSEL2 ||
1597 buf[1]+256*buf[0] == ECOFF_MAGIC_MIPSEB3 ||
1598 buf[1]+256*buf[0] == ECOFF_MAGIC_MIPSEL3) {
1599 file_load_ecoff(machine, mem, filename, entrypointp,
1600 arch, gpp, byte_orderp);
1601 goto ret;
1602 }
1603
1604 /* Is it a Motorola SREC file? */
1605 if ((buf[0]=='S' && buf[1]>='0' && buf[1]<='9')) {
1606 file_load_srec(machine, mem, filename, entrypointp);
1607 goto ret;
1608 }
1609
1610 /* gzipped files are not supported: */
1611 if (buf[0]==0x1f && buf[1]==0x8b) {
1612 fprintf(stderr, "\nYou need to gunzip the file before you"
1613 " try to use it.\n");
1614 exit(1);
1615 }
1616
1617 if (size > 24000000) {
1618 fprintf(stderr, "\nThis file is very large (%lli bytes)\n",
1619 (long long)size);
1620 fprintf(stderr, "Are you sure it is a kernel and not a disk "
1621 "image?\n");
1622 exit(1);
1623 }
1624
1625 /*
1626 * Last resort: symbol definitions from nm (or nm -S):
1627 *
1628 * If the buf contains typical 'binary' characters, then print
1629 * an error message and quit instead of assuming that it is a
1630 * symbol file.
1631 */
1632 for (i=0; i<(signed)sizeof(buf); i++)
1633 if (buf[i] < 32 && buf[i] != '\t' &&
1634 buf[i] != '\n' && buf[i] != '\r' &&
1635 buf[i] != '\f') {
1636 fprintf(stderr, "\nThe file format of '%s' is "
1637 "unknown.\n\n ", filename);
1638 for (i=0; i<(signed)sizeof(buf); i++)
1639 fprintf(stderr, " %02x", buf[i]);
1640 fprintf(stderr, "\n\nPossible explanations:\n\n"
1641 " o) If this is a disk image, you forgot '-d' "
1642 "on the command line.\n"
1643 " o) This is an unsupported binary format.\n\n");
1644 exit(1);
1645 }
1646
1647 symbol_readfile(&machine->symbol_context, filename);
1648
1649 ret:
1650 debug_indentation(-iadd);
1651 }
1652

  ViewVC Help
Powered by ViewVC 1.1.26