[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NetBSD/powerpc with PSIM



PSIMは、PSIM - Model of the PowerPC(tm) Architecture
	<URL:ftp://ftp.ci.com.au/pub/psim/index.html>
	(NetBSDのソースツリーにも入ってます)
というPowerPCのシミュレータです。
OpenFirmwareをも網羅しているので、NetBSD/powerpcを動かすことが可能です。
他にもOSのエミュレーションなども含んでいるので、
いろんなバイナリを実行することができます。

これならPowerPC持ってなくても、NetBSD/powerpcその他をhackできます :-)
私は NetBSD/i386(PentiumPro200MHz メモリ96M)上で動かしてます。

たとえばNetBSD/powerpcを動かすと、こうなります (ktermのlog)
-----------
psim -f tree ofwboot.elf
>> NetBSD/powerpc OpenFirmware Boot, Revision 1.3
>> (sakamoto@saturn100, Thu Feb 25 21:34:39 JST 1998)
|^H/^H-^H\^H|^H/^HBooting ofdisk1/netbsd
^H877604@0x100000+113328@0x1d6424 
 start=0x100000
warning: released chunks within region 0x20000..0x710af
IPKDB: No interface found!
Copyright (c) 1996, 1997, 1998
    The NetBSD Foundation, Inc.  All rights reserved.
Copyright (c) 1982, 1986, 1989, 1991, 1993
    The Regents of the University of California.  All rights reserved.

NetBSD 1.3D (GENERIC) #0: Thu Feb 25 21:31:53 JST 1998
    sakamoto@saturn100:/usr/local/Be/cvs/src/sys/arch/powerpc/compile/GENERIC
CPU: Version 0 (Revision 0)
real mem = 67108864
avail mem = 61149184
using 819 buffers containing 3354624 bytes of memory
mainbus0 (root)
ofbus0 at mainbus0
ofbus1 at ofbus0 (cpus)
cpu@0 at ofbus1 not configured
ofbus2 at ofbus0 (phb@0x80000000)
ofbus3 at ofbus2 (ide@1)
ofdisk0 at ofbus3 (disk@0)
ofdisk1 at ofbus3 (disk@0)
ofdisk2 at ofbus3 (cdrom@0)
ofdisk3 at ofbus3 (cdrom@0)
ofcons0 at ofbus2 (com@2)
boot device: <unknown>
root device: ofdisk2c
ofdisk2c
dump device (default ofdisk2b): 

file system (default generic): cd9660
cd9660
root on ofdisk2c dumps on ofdisk2b
init: copying out flags `-s' 3
init: copying out path `/sbin/init' 11
Jan  1 00:00:14 init: /etc/pwd.db: No such file or directory
Enter pathname of shell or RETURN for sh: 

# ls
ls
TRANS.TBL bin       etc       mnt       root      stand     usr
altroot   dev       home      netbsd    sbin      tmp       var
# mount /dev/ofdisk0c /mnt
mount /dev/ofdisk0c /mnt
# cd /mnt
cd /mnt
# ls -la
ls -la
total 4280
drwxr-xr-x  15 0  0      512 Feb 22  1998 .
dr-xr-xr-x  14 0  0     2048 Feb 26  1998 ..
-rw-r--r--   2 0  0      242 Feb  9  1998 .cshrc
-rw-r--r--   2 0  0      230 Dec 18  1997 .profile
drwxr-xr-x   2 0  0      512 Feb  9  1998 a
drwxr-xr-x   2 0  0      512 Dec 18  1997 altroot
drwxr-xr-x   2 0  0      512 Feb 11  1998 bin
-rw-r--r--   1 0  0    51884 Feb 22  1998 boot
drwxr-xr-x   3 0  0     6144 Jan  1 00:01 dev
drwxr-xr-x   8 0  0     1536 Feb 22  1998 etc
drwxr-xr-x   2 0  0      512 Feb 10  1998 home
drwxr-xr-x   2 0  0      512 Dec 18  1997 mnt
-rwxr-xr-x   1 0  0  1042240 Feb 22  1998 netbsd
-rwxr-xr-x   1 0  0  1041379 Feb 22  1998 netbsd.ofcons
drwxr-xr-x   3 0  0      512 Feb 17  1998 root
drwxr-xr-x   2 0  0     1536 Feb 22  1998 sbin
drwxr-xr-x   2 0  0      512 Dec 18  1997 stand
lrwxrwxrwx   1 0  0       11 Feb 11  1998 sys -> usr/src/sys
drwxr-xr-x   2 0  0      512 Feb  8  1998 tmp
drwxr-xr-x   2 0  0      512 Feb  8  1998 usr
drwxr-xr-x   2 0  0      512 Feb  8  1998 var
# strings netbsd |grep tsubai
strings netbsd |grep tsubai
    tsubai@powermac:/a/1.3/src/sys/arch/powermac/compile/POWERMAC
# cd /
cd /
# umount /mnt
umount /mnt
# halt
halt
Jan  1 00:02:49 init: kernel security level changed from 0 to 1
syncing disks... done
unmounting / (root_device)...
halted

sakamoto@saturn100% ls
total 280620
     8 MAKEDEV*         88 mkisofs*     128080 ppcfs             4 tree-970207
149888 fl9660         1952 netbsd*           2 root/
     2 mkimg*          592 ofwboot.elf*      4 tree
sakamoto@saturn100% 
-----------

ね、面白いでしょ(^^)
tsubaiさんのroot imageをffsとしてmountして、
そこにあるnetbsdをstringsとってみました。

そのとき使ったkernel,ofwbootは、currentのソースをegcsでcross compileしたもの。
ofwbootに関してはstackを広げてますが。
あと、ppc-objcopy --remove-section=.note ofwboot.elfというようにして
 .noteセクションを削っておかないとPSIMで使用できません。

filesystemのイメージは、fl9660は beboxのbase.tgzにdeviceファイルを
追加したもので、ppcfsがtsubaiさんの。

イメージの作成には、mkisofsを使用しました。
./mkisofs -l -r -L -T -a root > fl9660

treeファイルは、
-------------
/#address-cells 1

/openprom/options
	./os-emul "chirp
	./oea-memory-size 0x4000000
	./use-stdio? false
/openprom/trace
#	./events 1
#	./interrupts 1

/aliases
	./ofdisk0 "/phb/ide/disk@0
	./ofdisk1 "/phb/ide/cdrom@0

/phb@0x80000000
	./device_type "pci
	./name "pci
	./#address-cells 3
	./#size-cells 2
	./ranges ni0,0,0,0 0xc0000000 0x10000

/phb/ide@1
	./device_type "ide
	./name "ide
	./assigned-addresses \
		ni0,0,10,1f0 8 \
		ni0,0,14,3f0 8 \
		ni0,0,18,170 8 \
		ni0,0,1c,370 8 \
		ni0,0,20,200 8
	./reg \
		1 0 \
		i0,0,10,0 8 \
		i0,0,18,0 8 \
		i0,0,14,6 1 \
		i0,0,1c,6 1 \
		i0,0,20,0 8
#	./ready-delay 1000
	./ready-delay 1

/phb/ide@1/disk@0
	./device_type "block
	./name "disk
	./file "ppcfs

/phb/ide@1/cdrom@0
	./device_type "block
	./name "cdrom
	./file "fl9660

/phb/com@2
	./device_type "serial"
	./name "com"
	./assigned-addresses \
		ni0,0,10,3f8 8
	./reg \
		2 0 \
		i0,0,10,0 8

# TMP for NetBSD
/cpus
	./device_type "cpus
	./name "cpus
	./timebase-frequency 1000000
/cpus/cpu@0
	./device_type "cpu
	./name "cpu
	./timebase-frequency 1000000

/options/real-mode? true
/chosen/bootpath "ofdisk1"
/chosen/bootargs "-s"

/chosen/stdin */phb/com
/chosen/stdout !/chosen/stdin
-------------

MAKEDEV
-------------
#!/bin/sh -
#
#	$NetBSD: MAKEDEV,v 1.58 1997/08/22 11:19:43 lukem Exp $
#
# Copyright (c) 1990 The Regents of the University of California.
# All rights reserved.
#
# Written and contributed by W. Jolitz 12/90
#
# Redistribution and use in source and binary forms are permitted provided
# that: (1) source distributions retain this entire copyright notice and
# comment, and (2) distributions including binaries display the following
# acknowledgement:  ``This product includes software developed by the
# University of California, Berkeley and its contributors'' in the
# documentation or other materials provided with the distribution and in
# all advertising materials mentioning features or use of this software.
# Neither the name of the University nor the names of its contributors may
# be used to endorse or promote products derived from this software without
# specific prior written permission.
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
#	@(#)MAKEDEV	5.2 (Berkeley) 6/22/90
#
# Device "make" file.  Valid arguments:
#

PATH=/sbin:/usr/sbin:/bin:/usr/bin
umask 77
for i
do
case $i in

all)
	sh $0 std fd ofdisk0 ofdisk1 ofdisk2 ofdisk3 ofcons0
	;;

std)
	rm -f console drum mem kmem null zero io tty klog stdin stdout stderr
	mknod console		c 0 0
	mknod drum		c 6 0	; chmod 640 drum ; chgrp kmem drum
	mknod kmem		c 2 1	; chmod 640 kmem ; chgrp kmem kmem
	mknod mem		c 2 0	; chmod 640 mem	; chgrp kmem mem
	mknod null		c 2 2	; chmod 666 null
	mknod zero		c 2 12	; chmod 666 zero
	mknod io		c 2 14	; chmod 640 io ; chgrp kmem io
	mknod tty		c 1 0	; chmod 666 tty
	mknod klog		c 5 0	; chmod 600 klog
	;;

fd)
	rm -f fd/*
	mkdir fd > /dev/null 2>&1
	n=0
	while [ $n -lt 64 ]; do
		mknod fd/$n c 22 $n
		n=$(($n + 1))
	done
	chown -R bin.bin fd
	chmod 555 fd
	chmod 666 fd/*
	;;

vnd*|ofdisk*)
	case $i in
	vnd*) name=vnd;	unit=${i#vnd};	blk=14;	chr=41;;
	ofdisk*) name=ofdisk;	unit=${i#ofdisk};	blk=0;	chr=8;;
	esac
	rm -f $name$unit? r$name$unit?
	mknod ${name}${unit}a	b $blk $(($unit * 8 + 0))
	mknod ${name}${unit}b	b $blk $(($unit * 8 + 1))
	mknod ${name}${unit}c	b $blk $(($unit * 8 + 2))
	mknod ${name}${unit}d	b $blk $(($unit * 8 + 3))
	mknod ${name}${unit}e	b $blk $(($unit * 8 + 4))
	mknod ${name}${unit}f	b $blk $(($unit * 8 + 5))
	mknod ${name}${unit}g	b $blk $(($unit * 8 + 6))
	mknod ${name}${unit}h	b $blk $(($unit * 8 + 7))
	mknod r${name}${unit}a	c $chr $(($unit * 8 + 0))
	mknod r${name}${unit}b	c $chr $(($unit * 8 + 1))
	mknod r${name}${unit}c	c $chr $(($unit * 8 + 2))
	mknod r${name}${unit}d	c $chr $(($unit * 8 + 3))
	mknod r${name}${unit}e	c $chr $(($unit * 8 + 4))
	mknod r${name}${unit}f	c $chr $(($unit * 8 + 5))
	mknod r${name}${unit}g	c $chr $(($unit * 8 + 6))
	mknod r${name}${unit}h	c $chr $(($unit * 8 + 7))
	chgrp operator $name$unit? r$name$unit?
	chmod 640 $name$unit? r$name$unit?
	;;

ofcons*)
	unit=${i#???}
	rm -f ofcons$unit
	mknod ofcons$unit c 7 $unit
	chown uucp.wheel ofcons$unit
	;;

pty*)
	class=${i#pty}
	case $class in
	0)      name=p;;
	1)      name=q;;
	2)      name=r;;
	3)      name=s;;
	4)      name=t;;
	5)      name=u;;
	6)      name=v
		echo "$0: $i: pty unit conflicts with console ttyv* devices."
		continue;;
	7)      name=w;;
	8)      name=x;;
	9)      name=y;;
	10)     name=z;;
	11)     name=P;;
	12)     name=Q;;
	13)     name=R;;
	14)     name=S;;
	15)     name=T;;
	*)      echo "$0: $i: pty unit must be between 0 and 15"
	        continue ;;
	esac
	rm -f tty$name[0-9a-f] pty$name[0-9a-f]
	for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f
	do
		case $j in
		[0-9])  jn=$j ;;
		a)      jn=10 ;;
		b)      jn=11 ;;
		c)      jn=12 ;;
		d)      jn=13 ;;
		e)      jn=14 ;;
		f)      jn=15 ;;
		esac
		unit=$(($class * 16 + $jn))
		mknod tty$name$j c 5 $unit
		mknod pty$name$j c 6 $unit
	done
        chgrp wheel tty$name? pty$name?
        chmod 666 tty$name? pty$name?
	;;

local)
	umask 0
	sh $0.local all
	umask 77
	;;

*)
	echo $i: unknown device
	;;

esac
done
-------------

という感じです。

psim -f tree ofwboot.elf だと、ちゃんと動くのですが、
psim -f tree netbsd というように直接kernelを指定すると、
findrootでpanicしてしまいます。ちょっとhackすれば動くでしょう。

また、gdb上でPSIMを動かすこともできますので、デバッグにも使えます!

sakamoto@cec.co.jp