[comp.os.minix] Porting Minix to an 68020, tips

thomas@trane.UUCP (Thomas Driemeyer) (06/15/90)

Several months ago, I bought the Atari-ST Minix to port it to my 68020
box. I don't have access to an Atari, so I used a Sun 3 workstation and
its cc. Sun's cc does not have an option to generate 16-bit integers.

This is a list of the main problems. If you plan to do something similar,
ask me for the diffs; they are over 900 lines uncompressed, far too long
for this posting. If there is enough interest, I'll post anyway. I also
wrote SunOs utilities to unpack Minix archives, and to convert Motorola/
Minix assembler syntax to SunOs assembler syntax. Don't ask me to mail or
post the entire Minix sources, they are copyrighted.

Minix certainly is the the best-written operating system code I have
ever seen. It is easy to understand, well-structured (unlike certain
other Unix sources :-) and largely free of kludges. Congratulations!


No RAM at address 0:
	Minix was designed for systems with RAM at address 0 in mind. In an
	680[1234]0 system, there is no reason to put RAM there, because the
	exception vector table can be relocated. The changes in Minix are
	mostly in kernel/stmain.c: The first RAM address >> SHIFT_CLICK has
	to be added to the rp->p_map[*].mem_phys variables and the `base'
	variable. The shifted RAM base address also needs to be assigned to
	hole[0].h_base in mm/alloc.c. In mm/main.c, the shifted RAM base
	must be subtracted from tot_clicks in the alloc_mem() call, and from
	ram_base in the mem2 assignment. Also, the routine get_tot_mem() in
	mm/main.c must be changed to return the shifted RAM size. In three
	places in kernel/stdmp.c, the RAM start address needs to be
	subtracted from ltmp. This is not essential, but it avoids huge
	numbers in the dumps.

Interrupts:
	Kernel/stmain.c masks out interrupt levels 1 and 2. If you have
	interrupt sources in these levels, change the rp->p_pcpsw.psw
	constants from 0x2200 to 0x2000.

Messages:
	In h/type.h, all `int's in the mess_* struct declarations need to be
	replaced with `short', except for the routine pointer in mess_6. This
	maintains compatibility with commands that use 16-bit `int's.

Library routines:
	The library routines that interface to the kernel must push 32-bit
	`int's. This affects lib/stcatch.s, lib/stcrtso.s, lib/stsetjmp.s,
	and, most importantly, lib/stsndrec.s.

Stacks:
	I had to increase the kernel task stack size from 1024 to 4096. This
	is almost certainly too large, but it won't work with 1024. I didn't
	investigate yet which task needs so much stack.
	Also, few of the utilities worked until I added 4096 to their initial
	stack. I do this by adding 4096 to *tot_mem in mm/exec.c.

File system bitmaps:
	In fs/super.c, the routines for allocation and deallocation of
	inode/zone bitmap bits look at bit 0 of the first `int' first.
	If an `int' is 16 bits, this is bit 0 of byte 1. If an `int' is
	32 bits, this is bit 0 of byte 3 - a different bit. To fix, I
	replaced all appropriate `int's with `short', and changed buf.h.

TTY output:
	Since I am lazy, I am using the kernel putc for output in tty.c.
	This should be interrupt driven, of course. To use putc, the tty.c
	line (*tp->tty_echo)(tp, c) must be changed to (*tp->tty_echo)(c).

RAM above 0x7fffff:
	In my system, memory below 0x800000 is local, and memory above
	0x7fffff is global to all three CPUs. The large RAM is global. I
	couldn't get this configuration to work with 32-bit `int's, because
	click addresses are frequently passed in messages as `short's, and
	when the click address is converted to a pointer again, it is
	sign-extended. I suppose I could find all the places where this
	happens, and use casts; but that would make the 1.5.10 upgrade even
	more difficult than it already is. I fixed the problem by changing
	the address decoders on my main CPU board. Sorry.

Obsolete files:
	I removed some Atari-specific files in the kernel directory:
	stacia.h staddr.h stdma.c stdma.h stfdc.h stfnt.c sthdc.h
	stkbd.c stmfp.h stram.h stsound.h stvdu.c stvideo.h.

Rewritten files:
	The device drivers are _quite_ different on my system, so I
	rewrote several files in the kernel directory:
	stcon.c stfloppy.c stmpx.s stprint.c stwini.c.
	Stmpx.s is particularly interesting. I use a 68681 for the console
	and for the timer, so my stcon.c might be of interest to others.


Thomas Driemeyer
pyramid!pacbell!trane!thomas
	^^^^^^^ We just reconnected to Usenet, only pacbell knows us at the
		moment. Don't use pyramid!trane.

Disclaimer: My company has nothing to do with any of this.