もっと minix
夕刻、暑いのを我慢して女房と散歩していると、老婆に呼びとめられた。お年寄りだから 熱中症で調子が悪くなって助けを求めてきたんかいなと、一瞬緊張したよ。
そしたら、『あんたら、ナスや枝豆いらんかね』なんて言うでは無いか。新種の押し売り? かと思っちゃったぞ。でも、その老婆は続けて、『畑でいっぱい出来てしまって、家じゃ食べ切れんから、良かったら持ってって』 と言う。
そうなんだよな。実家で家庭菜園もどきをやってるけど、時期になると本当に食べきれない程 取れ、近所におすそわけしてたっけ。この地では、そういう近所付き合いは無いのかな。 畑に入って、老婆の指導の下、熟れごろのナスと枝豆を採集させて頂きました。
現代でもこんな経験が出来るなんて。。ふと、わらしべ長者の話を思い出してしまったぞ。 ナスと枝豆を持って散歩してると、飲み屋の親父に呼び止められ、丁度、飲み屋で出す つまみが切れてしまったので、そのナスと枝豆を譲ってくれまいか。小銭を切らしてしまった ので、1000円でいいよ。
信心深いおいらは、翌日、霊験あらたな神社によってお祈りして、みずほの窓口へ。 サマージャンボを一点買い。これで、3億円当たる(予感)。
再コンパイル
やっぱり目が行くのは、/usr/src。他に/usr/bigsrcもあるけど、こちらは取り合えず無視ね。 Makefileが有ったので、見てみる。
# cd /usr/src
# make
Master Makefile for MINIX commands and utilities.
Root privileges are required for some actions.
Usage:
make world # Compile everything (libraries & commands)
make includes # Install include files from src/
make libraries # Compile and install libraries
make commands # Compile all, commands, but don't install
make install # Compile and install commands
make depend # Generate required .depend files
make gnu-includes # Install include files for GCC
make gnu-libraries # Compile and install libraries for GCC
make clean # Remove all compiler results
Run 'make' in tools/ to create a new MINIX configuration.
worldを用意してるあたり、なかなかリキが入ってますなあ。
# cd tools
# make
Master Makefile to create new MINIX configuration.
Root privileges are required.
Usage:
make includes # Install include files
make depend # Generate dependency files
make libraries # Make system libraries
make services # Compile and install all services
make image # Make needed services and create boot image
make install # Make image, and install to hard disk
make hdboot # Make image, and install to hard disk
make fdboot # Make image, and install to floppy disk
make bootable # Make hard disk bootable
make clean # Remove all compiler results, except libs
To create a fresh MINIX configuration, try:
make clean install # new boot image
make fresh install # new everything
こちらは、カーネルを作る時だな。ああ、カーネルと言うより、カーネルとその仲間達を 含めて、image と言うのか。言葉は難しい。
# make clean install
:
install ===> rtl8139
create rtl8139/liveupdate.d
create rtl8139/rtl8139.d
create rtl8139/.depend
compile rtl8139/rtl8139.o
compile rtl8139/liveupdate.o
link rtl8139/rtl8139
install /usr/sbin/rtl8139
:
depend ===> tty/keymaps
all ===> tty/keymaps
all ===> ramdisk
all ===> memory
installboot -image image ../kernel/kernel ../servers/ds/ds ../servers/rs/rs ../servers/pm/pm ../servers/sched/sched ../servers/vfs/vfs ../drivers/memory/memory ../drivers/log/log ../drivers/tty/tty ../servers/mfs/mfs ../servers/vm/vm ../servers/pfs/pfs ../servers/init/init
text data bss size
79408 27204 348040 454652 ../kernel/kernel
46608 14848 58104 119560 ../servers/ds/ds
47232 20648 192604 260484 ../servers/rs/rs
44496 14064 381524 440084 ../servers/pm/pm
21072 7824 9396 38292 ../servers/sched/sched
68928 19684 392516 481128 ../servers/vfs/vfs
28544 973364 16224 1018132 ../drivers/memory/memory
29296 10896 96332 136524 ../drivers/log/log
57472 20508 146692 224672 ../drivers/tty/tty
50512 14356 35132 100000 ../servers/mfs/mfs
68480 39380 1406708 1514568 ../servers/vm/vm
23360 7856 17940 49156 ../servers/pfs/pfs
24816 9568 3420 37804 ../servers/init/init
------ ------ ------ -------
590224 1180200 3104632 4875056 total
exec sh mkboot hdboot
install image /dev/c0d0p0s0:/boot/image/3.1.7r0
Done.
6分ぐらいかかって集合体をコンパイルし、インストールしてくれた。 そして、再起動。Web載ってた案内では、monitor(boot)のsetコマンドを使って、新しい imageを指定するようになってたけど、それをしなくてもいいみたい。
$ cat /var/log/messages : Jul 26 14:01:35 192 kernel: MINIX is open source software, see http://www.minix3.org : Jul 26 14:33:04 192 kernel: MINIX is open source software,(BSD license) :
新しいimageで起動したか分かるように、kernel/main.c にある、announce(void)内を ちょいと変更しておいたけど、ちゃんと変更されたバナーが出てきたよ。
$ cd /boot $ ls -l total 1776 -rwxr-xr-x 1 root operator 32000 Jun 11 11:52 boot drwxr-xr-x 2 root operator 256 Jul 26 14:22 image -rw------- 1 root operator 1784832 Jun 11 11:52 image_big $ ls -l image total 3486 -rw------- 1 root operator 1784832 Jun 11 11:52 3.1.7 -rw------- 1 root operator 1784832 Jul 26 14:22 3.1.7r0
これ、/bootの下の状況です。出来上がったイメージは、レビジョンが付くのか。某VMSみたいだな。 これら全体をどうやってまとめているかは、レシピが、tools/にあった。
$ cat chrootmake.sh
#!/bin/sh
set -e
export SHELL=/bin/sh
cd /usr/src
make etcfiles
make world
cd tools
rm revision
rm /boot/image/*
make install
cp /boot/image/* /boot/image_big # Make big image accessible by this name
cp ../boot/boot /boot/boot
cd /usr/src
if [ $MAKEMAP -ne 0 ]; then
find . -type f -perm 755 | xargs nm -n 2> /dev/null > symbols.txt
fi
make clean
make cleandepend
find . -name obj-ack -type d|xargs rm -rf
# Let man find the manpages
makewhatis /usr/man
makewhatis /usr/local/man
binsizes normal
先ほどimageを作っている時、xx.dと言う見慣れないサフィクスのファイルが出来て いたけど、こやつは何物ぞ。かにさんドライバーの所を覗いてみた。そして中身は?と言うと、
$ cd /usr/src/drivers/rtl8139 $ ls Makefile liveupdate.d rtl8139 rtl8139.d rtl8139.o liveupdate.c liveupdate.o rtl8139.c rtl8139.h
$ cat rtl8139.d rtl8139.o: /usr/include/ansi.h rtl8139.o: /usr/include/assert.h rtl8139.o: /usr/include/errno.h : rtl8139.o: /usr/src/kernel/type.h rtl8139.o: rtl8139.c rtl8139.o: rtl8139.h
どうやら、makeが使う依存データベースっぽい。曰く、コロンの右側に列挙されてるのに 依存しているとな。これを抽出するのに結構時間がかかっていたぞ。 Makefileを調べると、.includeがあって、そいつを追いかけて行くと、/etc/mkに行き着く。 適当に覗いてみると
# $NetBSD: bsd.prog.mk,v 1.244 2009/12/08 15:18:42 uebayasi Exp $ # @(#)bsd.prog.mk 8.2 (Berkeley) 4/2/94
何やら、NetBSDの上林 さんから借りてきてるみたいで、面白い。
そんじゃ、突然だけど、メモリー割り当てがどうなっているか、見てみる。その現場は、 /usr/src/servers/vm/alloc.c
/*===========================================================================*
* alloc_mem *
*===========================================================================*/
PUBLIC phys_clicks alloc_mem(phys_clicks clicks, u32_t memflags)
{
/* Allocate a block of memory from the free list using first fit. The block
* consists of a sequence of contiguous bytes, whose length in clicks is
* given by 'clicks'. A pointer to the block is returned. The block is
* always on a click boundary. This procedure is called when memory is
* needed for FORK or EXEC.
*/
MINIX本と同じだな。clicksってのは、minix専用の単位かどうか知らないけれど、16byteの 事だ。これも例の糞CPU由来なのだろうか?(セグメントは、4bitシフトしてるんで、16byte 単位でのメモリー割付になるというやつ)まあ、このあたりは、mallocと同じアルゴリズムかな。そして GCと言うか、返却されたメモリーは、未使用リスト(minix用語では、穴リスト)をスキャンして 、大きなブロックに結合出来れば、結合してしまう。GCとかを勉強した身からすれば、やけに 簡単に済ませているけど、スピード命って観点からすれば、そうせざるを得ないのだろうな。
Macではまる
minix3に進化して、ソースも大分増え、機能も充実してきたけど、基本はminix1.xの頃と 何も変わっていないな。よって、勉強するなら、minix本を元にするのがよさそう。 minix1.xのソースを、すいすいと飛びまわれるようにしておくかな。えっと古いソースは?
古いやつ と、お思いでしょうが、そんなに 変わるもんじゃありません。intel-1.1 あたりを取ってくるか、Macintoshを取ってくるか? Macだと、ひょっとして、68000な石なんだろうか?
悩んでるより、手を動かせ。Macintosh.tar.gzを取ってきたのはいいんだけど、展開すると MacMinix_1.5.10.7.sea.hqxなんてのが出てきた。えっと、どうするんだったけな? ports/archivers/macutilsを入れれば、取り合えず何とかなるんでないかいな。
[sakae@cdr ~/mac/Macintosh]$ hexbin MacMinix_1.5.10.7.sea.hqx [sakae@cdr ~/mac/Macintosh]$ macunpack MacMinix_1.5.10.7.sea.bin
hexbinって、unixで言うuudecodeね。macunpackって、Mac界のunzip。すっかり記憶が 飛んでるなあ。
[sakae@cdr ~/mac/Macintosh]$ ls -l total 20128 drwxr-xr-x 2 sakae kuma 1024 7 27 11:37 1.5.10.7_patches__/ -rw-r--r-- 1 sakae kuma 192512 7 27 11:40 MacBoot.bin -rw-r--r-- 1 sakae kuma 3975680 7 27 11:41 MacMinix_1.5.10.7.sea.bin -rw-r--r-- 1 sakae kuma 5403977 7 23 2005 MacMinix_1.5.10.7.sea.hqx -rw-r--r-- 1 sakae kuma 524416 7 27 11:40 ROOT.bin -rw-r--r-- 1 sakae kuma 163968 7 27 11:40 ROOT.small.bin -rw-r--r-- 1 sakae kuma 10240128 7 27 11:41 USR.bin
出来たのはいいけど、FreeBSD上じゃ、mount出来ないし、、、minix3へ持って行っても、mdcoonfig みたいな便利なのは無いし、これはもう諦めるしか。(Macのエミュレータないかな? ジョブス さんよ。iPadに軸足を移しちゃったから、昔のMACOSは、オープンソースで公開してね。 MacPaintのソース公開ぐらいでは、 騙されないもんね。 そしたら、iPadぐらいは、買ってやるよ。)
md
まてよ、諦めるのは早いかも知れないな。取り合えず mountがどうなっているか調べてみる。 mountって普通のコマンドだよな。
$ cd /usr/src/commands/mount
$ emacs mount.c
:
device = argv[1];
if (!strcmp(device, "none")) device = NULL;
if (mount(device, argv[2], mountflags, type, args) < 0) {
err = strerror(errno);
fprintf(stderr, "mount: Can't mount %s on %s: %s\n",
argv[1], argv[2], err);
exit(1);
}
/* The mount has completed successfully. Tell the user. */
printf("%s is read-%s mounted on %s\n",
argv[1], mountflags & MS_RDONLY ? "only" : "write", argv[2]);
/* Update /etc/mtab. */
はあ、mountを呼んで、結果を報告し、/etc/mtabを更新してるんだ。そうすると、肝はmount(2)だな。
$ cd /usr/src/servers/vfs
$ emacs mount.c
:
/*===========================================================================*
* do_mount *
*===========================================================================*/
PUBLIC int do_mount()
{
endpoint_t fs_e;
int r, proc_nr;
/* Only the super-user may do MOUNT. */
if (!super_user) return(EPERM);
このあたりだな。ちらちらと見て行くと、rootじゃなきゃ駄目よとかブロックデバイス じゃなきゃ駄目よとか厳しくチェックしてる。でも、minix3とminix1では、様変わりしてるなあ。 ここに、mdconfigを紛れこませようとしたら超大変。そもそも、FreeBSDのmdconfigって何よ?
MD(4) FreeBSD Kernel Interfaces Manual MD(4)
NAME
md -- memory disk
SYNOPSIS
device md
DESCRIPTION
The md driver provides support for four kinds of memory backed virtual
disks:
そっか、minixならramdiskへ紛れこませるって手があるな。それより、Mac-minixに、68000 のコードが含まれているのだろうか? 先にちょいと調べておく。
$ strings -20 USR.bin | more
:
_SetCTitle:
link a6,#0
movem.l d2/a5,-(sp)
pea 0xc(a6)
jsr __cstringtopstring
add.l #0x4,sp
tst.l savedsp
beq LL36
move.l a7,a0
move.l savedsp,a7
move.l a0,-(sp)
LL36:
move.l 0x8(a6),-(sp)
move.l 0xc(a6),-(sp)
move.l saveda5,a5
.data2 0xa95f
tst.l savedsp
beq LL37
move.l (sp)+,a7
:
おお、懐かしの68kアセンブラーだ。