Nitros9 for the masses (was) Re: [Coco] COCO4 Emulator

James Jones jamesjones01 at mchsi.com
Sun May 7 23:11:39 EDT 2006


James Hrubik wrote:
> Out of curiosity, how would writing a 6809/6309 emu compare in 
> difficulty to rewriting NitrOS-9 for the same chipset?  I thought that 
> perhaps the two tasks would be similar in nature.

Writing an emulator at one level is not terribly difficult; you set up 
data that represents the machine state, and then write an instruction 
decoder and routines for each instruction that modify the machine state 
in a way analogous to the way executing the instruction modifies the 
state of the actual processor. (That's a first cut; the fun part is 
making it efficient, emulating peripherals, and especially making an 
emulation precise enough to match the speed of the original. An 
emulation such as Mr. Keil's, for example, is quite a piece of work.)

Retargeting an operating system involves at least three things:

1. Defining the mechanism for system calls, and the conventions for 
parameter passing to system calls and what processes can expect to have 
in what registers when they receive processor time. If you're writing 
the OS in a higher-level language, its ABI will influence how parameters 
are passed; if you're using assembly language, you may have a little 
more flexibility.

2. Rewriting the OS for the new target, using the conventions 
established in (1). Some parts of the OS are inherently 
target-dependent, and will have to be completely rethought, e.g. 
interrupt handlers, context switching, and booting. Moving from 
Motorola, where I/O is typically memory-mapped, to x86, which has a 
separate I/O space and IN and OUT instructions, will make a significant 
difference in how I/O is done.

3. Writing libraries that allow access to system calls from higher-level 
langauges, and writing hefty chunks of the libraries of higher-level 
languages (stdio, memory, signal handling, and so forth).

	James



More information about the Coco mailing list