simh中安裝運行unix v7

參考http://gunkies.org/wiki/Installing_v7_on_SIMH工具

1、原料:.net

到ftp://minnie.tuhs.org/UnixArchive/PDP-11/Distributions/research/Keith_Bostic_v7/下載unix

f0.gz  f1.gz  f2.gz  f3.gz  f4.gz  f5.gz  f6.gz並解壓爲:f0  f1  f2  f3  f4  f5  f6code

或到這裏下載,也可下載打包好了的ip

2、工具ci

perl腳本rem

~/simhSample/v7$ cat mkdisttap.pl 
#!/usr/bin/perl -w
use strict;

# Based on mkdisttap.pl
# ftp://ftp.mrynet.com/pub/os/PUPS/PDP-11/Boot_Images/2.11_on_Simh/211bsd/mkdisttap.pl

#
# $Id: mkdisttap.pl,v 1.1 2006/09/16 23:33:46 kirk Exp kirk $
#

# Based on the example in the HOWTO using dd.  Does not work!
# add_file("cat mtboot mtboot boot |", 512);

# Based on the maketape.c program and the maketape.data data file.
add_file("f0", 512);
end_file();
add_file("f1", 512);
end_file();
add_file("f2", 512);
end_file();
add_file("f3", 512);
end_file();
add_file("f4", 512);
end_file();
add_file("f5", 10240);
end_file();
add_file("f6", 10240);
end_file();
end_file();

sub end_file {
  print "\x00\x00\x00\x00";
}

sub add_file {
  my($filename, $blocksize) = @_;
  my($block, $bytes_read, $length);

  open(FILE, $filename) || die("Can't open $filename: $!");
  while($bytes_read = read(FILE, $block, $blocksize)) {
    if($bytes_read < $blocksize) {
      $block .= "\x00" x ($blocksize - $bytes_read);
      $bytes_read = $blocksize;
    }
    $length = pack("V", $bytes_read);
    print $length, $block, $length;
  }
  close(FILE);
}

C語言:mktape.cget

/*
 * mktape.c
 */


#include <stdio.h>
#include <stdlib.h>


struct {
  char *name;
  int blocksize;
} files[] = {
  { "f0",   512 },
  { "f1",   512 },
  { "f2",   512 },
  { "f3",   512 },
  { "f4",   512 },
  { "f5", 10240 },
  { "f6", 10240 }
};


void error(char *msg) {
  printf("**** Error: %s ****\n", msg);
  exit(0);
}


void writeCount(long count, FILE *file) {
  if (fwrite(&count, 4, 1, file) != 1) {
    error("cannot write byte count");
  }
}


int main(void) {
  FILE *outfile;
  FILE *infile;
  long size;
  int blocksize;
  int blocks;
  int i, j;
  unsigned char buffer[20000];

  outfile = fopen("unix_v7.tm", "wb");
  if (outfile == NULL) {
    error("cannot open output file");
  }
  for (i = 0; i < sizeof(files)/sizeof(files[0]); i++) {
    printf("%s: ", files[i].name);
    infile = fopen(files[i].name, "rb");
    if (infile == NULL) {
      error("cannot open input file");
    }
    fseek(infile, 0, SEEK_END);
    size = ftell(infile);
    fseek(infile, 0, SEEK_SET);
    blocksize = files[i].blocksize;
    blocks = size / blocksize;
    printf("%ld bytes = %d records (blocksize %d bytes)\n",
           size, blocks, blocksize);
    if (size % blocksize != 0) {
      error("file size is not a multiple of block size");
    }
    for (j = 0; j < blocks; j++) {
      if (fread(buffer, blocksize, 1, infile) != 1) {
        error("cannot read input file");
      }
      writeCount(blocksize, outfile);
      if (fwrite(buffer, blocksize, 1, outfile) != 1) {
        error("cannot write output file");
      }
      writeCount(blocksize, outfile);
    }
    fclose(infile);
    writeCount(0, outfile);
  }
  writeCount(0xFFFFFFFF, outfile);
  fclose(outfile);
  return 0;
}

3、生成磁帶鏡像文件: input

    三種方法:it

         一、直接下載並解壓:Unix-v7-Keith-Bostic.tap.bz2

         二、 ./mkdisttap.pl > v7.tap

         三、  gcc -Wall -g -o mktape mktape.c

                 ./mktape

最後兩種方法必須把前面準備的f0  f1  f2  f3  f4  f5  f6放到目錄下。

獲得有可能unix_v7.tm、Unix-v7-Keith-Bostic.tap等,文件大小11.7M,爲了下面描述的統一都更名爲:v7.tap

4、安裝

~/simhSample/v7/test$ ls
boot.ini   tapei.ini  tboot.ini  v7.tap
~/simhSample/v7/test$ cat tapei.ini 
set cpu 11/45
set cpu idle
set rp0 rp06
att rp0 rp06-0.disk
att tm0 v7.tap
boot tm0
~/simhSample/v7/test$ cat tapei.ini
set cpu 11/45
set cpu idle
set rp0 rp06
att rp0 rp06-0.disk
att tm0 v7.tap
boot tm0
~/simhSample/v7/test$ cat tapei.ini
set cpu 11/45
set cpu idle
set rp0 rp06
att rp0 rp06-0.disk
att tm0 v7.tap
boot tm0
~/simhSample/v7/test$ pdp11 tapei.ini

PDP-11 simulator V3.9-0
Disabling XQ
RP: creating new file
Overwrite last track? [N] 
Boot
: tm(0,3)
file sys size: 5000
file system: hp(0,0)
isize = 1600
m/n = 3 500
Exit called
Boot
: tm(0,4)
Tape? tm(0,5)
Disk? hp(0,0)
Last chance before scribbling on disk. 
End of tape
Boot
: hp(0,0)hptmunix
mem = 177344
# MV HPTMUNIX UNIX
# RM HP*IX
# LS *IX
RPHTUNIX
RPTMUNIX
UNIX
# RM RP*IX
# CD /DEV
# MAKE RP06
/ETC/MKNOD RP0 B 6 0
/ETC/MKNOD SWAP B 6 1
/ETC/MKNOD RP3 B 6 7
/ETC/MKNOD RRP0 C 14 0
/ETC/MKNOD RRP3 C 14 7
CHMOD GO-W RP0 SWAP RP3 RRP0 RRP3
# MAKE TM
/ETC/MKNOD MT0 B 3 0
/ETC/MKNOD RMT0 C 12 0
/ETC/MKNOD NRMT0 C 12 128
CHMOD GO+W MT0 RMT0 NRMT0
# CD /
# /ETC/MKFS /DEV/RP3 322276
ISIZE = 65496
M/N = 3 500
# DD IF=/DEV/NRMT0 OF=/DEV/NULL BS=20B FILES=6
202+80 RECORDS IN
202+75 RECORDS OUT
# RESTOR RF /DEV/RMT0 /DEV/RP3
LAST CHANCE BEFORE SCRIBBLING ON /DEV/RP3. 
END OF TAPE
# /ETC/MOUNT /DEV/RP3 /USR
# DD IF=/USR/MDEC/HPUBOOT OF=/DEV/RP0 COUNT=1
0+1 RECORDS IN
0+1 RECORDS OUT
# SYNC
# SYNC
# SYNC
# SYNC
# ^E
Simulation stopped, PC: 002306 (MOV (SP)+,177776)
sim> q
Goodbye
~/simhSample/v7/test$ cat 
rp06-0.disk  tapei.ini    tboot.ini    v7.tap       
~/simhSample/v7/test$ cat tboot.ini 
echo
echo at the prompt type in
echo @ hp(0,0)unix
echo
set cpu 11/70
set cpu 2M
set cpu idle
set rp0 rp06
att rp0 rp06-0.disk
att tm0 v7.tap
boot tm0
~/simhSample/v7/test$ pdp11 tboot.ini 

PDP-11 simulator V3.9-0

at the prompt type in
@ hp(0,0)unix

Disabling XQ
Boot
: hp(0,0)unix
mem = 2020544
#^D
# RESTRICTED RIGHTS: USE, DUPLICATION, OR DISCLOSURE
IS SUBJECT TO RESTRICTIONS STATED IN YOUR CONTRACT WITH
WESTERN ELECTRIC COMPANY, INC.
WED DEC 31 19:04:20 EST 1969

login: root
Password:root
You have mail.
# df
/dev/rp0 1297
/dev/rp3 297414
# ^E
Simulation stopped, PC: 002306 (MOV (SP)+,177776)
sim> q
Goodbye

5、運行(這個boot.ini解決的維基這篇文章中不能用磁盤rp06啓動的問題)

~/simhSample/v7/test$ cat boot.ini 
echo
echo at the prompt type in
echo @ hp(0,0)unix
echo
set cpu 11/70
set cpu 2M
set cpu idle
set rp0 rp06
attach rp0 rp06-0.disk
d cpu 2000 042102
d cpu 2002 012706
d cpu 2004 002000
d cpu 2006 012700
d cpu 2010 000000
d cpu 2012 012701
d cpu 2014 176700
d cpu 2016 012761
d cpu 2020 000040
d cpu 2022 000010
d cpu 2024 010061
d cpu 2026 000010
d cpu 2030 012711
d cpu 2032 000021
d cpu 2034 012761
d cpu 2036 010000
d cpu 2040 000032
d cpu 2042 012761
d cpu 2044 177000

d cpu 2046 000002

d cpu 2050 005061

d cpu 2052 000004

d cpu 2054 005061

d cpu 2056 000006

d cpu 2060 005061

d cpu 2062 000034

d cpu 2064 012711

d cpu 2066 000071

d cpu 2070 105711

d cpu 2072 100376

d cpu 2074 005002

d cpu 2076 005003

d cpu 2100 012704

d cpu 2102 002020

d cpu 2104 005005

d cpu 2106 105011

d cpu 2110 005007

run 2002
~/simhSample/v7/test$ pdp11 boot.ini 

PDP-11 simulator V3.9-0

at the prompt type in
@ hp(0,0)unix

Disabling XQ
boot
Boot
: hp(0,0)unix
mem = 2020544
# ^D

# 
Simulation stopped, PC: 002306 (MOV (SP)+,177776)
sim> q
Goodbye
~/simhSample/v7/test$ pdp11 boot.ini 

PDP-11 simulator V3.9-0

at the prompt type in
@ hp(0,0)unix

Disabling XQ
boot
Boot
: hp(0,0)unix
mem = 2020544
# ^D
# RESTRICTED RIGHTS: USE, DUPLICATION, OR DISCLOSURE
IS SUBJECT TO RESTRICTIONS STATED IN YOUR CONTRACT WITH
WESTERN ELECTRIC COMPANY, INC.
WED DEC 31 19:04:52 EST 1969

login: root
Password:root
You have mail.
# # cat /etc/passwd
root:VwL97VCAx1Qhs:0:1::/:
daemon:x:1:1::/:
sys::2:2::/usr/sys:
bin::3:3::/bin:
uucp::4:4::/usr/lib/uucp:/usr/lib/uucico
dmr::7:3::/usr/dmr:
# ^D
login: dmr
$ cat >> hello.c
main()
{
   printf("Hello World!\n");
}
^D
$ cc hello.c
$  ./a.out
Hello World!
$

fortran77

$ ed euclid.f
?euclid.f
a
      PROGRAM EUCLID
        PRINT *, 'A?'
        READ *, NA
        IF (NA.LE.0) THEN
          PRINT *, 'A must be a positive integer.'
          STOP
        END IF
        PRINT *, 'B?'
        READ *, NB
        IF (NB.LE.0) THEN
          PRINT *, 'B must be a positive integer.'
          STOP
        END IF
        PRINT *, 'The GCD of', NA, ' and', NB, ' is', NGCD(NA, NB), '.'
        STOP
      END

      FUNCTION NGCD(NA, NB)
        IA = NA
        IB = NB
    1   IF (IB.NE.0) THEN
          ITEMP = IA
          IA = IB
          IB = MOD(ITEMP, IB)
          GOTO 1
        END IF
        NGCD = IA
        RETURN
      END
.
w
643
q
$ cat euclid.f
      PROGRAM EUCLID
        PRINT *, 'A?'
        READ *, NA
        IF (NA.LE.0) THEN
          PRINT *, 'A must be a positive integer.'
          STOP
        END IF
        PRINT *, 'B?'
        READ *, NB
        IF (NB.LE.0) THEN
          PRINT *, 'B must be a positive integer.'
          STOP
        END IF
        PRINT *, 'The GCD of', NA, ' and', NB, ' is', NGCD(NA, NB), '.'
        STOP
      END

      FUNCTION NGCD(NA, NB)
        IA = NA
        IB = NB
    1   IF (IB.NE.0) THEN
          ITEMP = IA
          IA = IB
          IB = MOD(ITEMP, IB)
          GOTO 1
        END IF
        NGCD = IA
        RETURN
      END
$ f77 euclid.f
euclid.f:
   MAIN euclid:
Warning on line 7 of euclid.f: statement cannot be reached
Warning on line 13 of euclid.f: statement cannot be reached
   ngcd:
Warning on line 26 of euclid.f: statement cannot be reached
$ a.out
 A?
20
 B?
28
 The GCD of 20  and 28  is 4 .
$ rm a.out euclid.o

unix v7源代碼下載

6、在unix v7中增長普通用戶(v7沒有adduser, 只能ed修改/etc/passwd)

# ed /etc/passwd
164
$a
dmr::47:13::/usr/dmr:
.
w
186
q
# cat /etc/passwd
root::0:1::/:
daemon:a:1:2::/:
sys::2:3::/usr/src/sys:
bin::3:4::/bin:
tbl:SOd/uxfAsK/P.:10:1:TBLondon,ho4e-624:/usr/tbl:
jfr:uzHcsfcSddAFs:11:1:JFReiser:/usr/jfr:
dmr::47:13::/usr/dmr:
(這裏dmr用戶已經增長)
# mkdir /usr/dmr
# chown dmr /usr/dmr
相關文章
相關標籤/搜索