home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / research / Dennis_v3 / Changes.txt next >
Text File  |  1999-01-14  |  14KB  |  421 lines

  1.  
  2.                          Compiling and Booting the
  3.                               Nsys UNIX Kernel
  4.  
  5.                                Warren Toomey
  6.                           Email: wkt@cs.adfa.edu.au
  7.  
  8.                              15th January, 1999
  9.  
  10. Introduction
  11. ------------
  12.  
  13. The `nsys' UNIX kernel was recently donated to the PUPS Archive by Dennis
  14. Ritchie. This file describes how you can boot a slightly-modified version of
  15. this kernel on a 5th Edition RK05 root filesystem.
  16.  
  17. Background
  18. ----------
  19.  
  20. In January 1999, Dennis Ritchie sent in a copy of the `nsys' UNIX kernel for
  21. inclusion in the PUPS Archive. In the accompanying README, he says:
  22.  
  23.      So far as I can determine, this is the earliest version of Unix
  24.      that currently exists in machine-readable form. ... The dates on
  25.      the transcription are hard to interpret correctly; if my program
  26.      that interprets the image are correct, the files were last touched
  27.      on 22 Jan, 1973. ...
  28.  
  29.      What is here is just the source of the OS itself, written in the
  30.      pre-K&R dialect of C. The file u is evidently a binary image of
  31.      the kernel. It is intended only for PDP-11/45, and has setup and
  32.      memory-handling code that will not work on other models (it's
  33.      missing things special to the later, smaller models, and the
  34.      larger physical address space of the still later 11/70.) It
  35.      appears that it is intended to be loaded into memory at physical
  36.      0, and transferred to at location 0.
  37.  
  38.      I'm not sure how much work it would take to get this system to
  39.      boot. Even compiling it might be a bit of a challenge, though I
  40.      imagine that circa V5-V6 compilers would handle the language
  41.      (maybe even V7). It is full of =+ and use of char * as unsigned
  42.      integers, and integers used as pointers in locations like p->x.
  43.  
  44.      So far as I can determine, the disk format it expects is
  45.      compatible with the layout of other earlyish research systems (V5,
  46.      V6) for example. But perhaps not, and it's not certain that the
  47.      source is complete. Even the compilation mechanism is a bit
  48.      unclear, though it certainly used the shell script ken/rc, which
  49.      appears to depend on having the *.o files from ken/* and dmr/* and
  50.      also slib.a, which doesn't exist on the tape. My guess is that
  51.      this was an archive of already compiled .o files, so that (for
  52.      example) to test-build a system one would edit a file, compile it,
  53.      and run ken/rc to load it. The 'ustr' routine referred to in
  54.      ken/rc evidently stripped off the a.out header and the symbols
  55.      from the a.out file.
  56.  
  57.      Best wishes with this. I'd be interested to hear whether anyone
  58.      gets the u image to run. If you're in luck, all you need is an
  59.      11/45 processor or emulator and a V5/6/7 disk image.
  60.  
  61. I decided to try and compile the `nsys' code, and get it to boot on a
  62. PDP-11/45 emulator. A secondary goal was to use the `nsys' compilation
  63. effort to find any remaining bugs in my Apout PDP-11 user-mode emulator.
  64.  
  65. Tools Required
  66. --------------
  67.  
  68. Because the `nsys' kernel is dated 1973, I decided to use a 5th Edition
  69. development enviromnent to compile it. This minimised the changes I had to
  70. make to the source code.
  71.  
  72. There are several ways you can obtain a 5th Edition development enviromnent:
  73.  
  74.    * Load a 5th Edition filesystem on an RK05, and boot it on a PDP 11/45;
  75.    * Load a 5th Edition filesystem on an RK05 disk image, and boot it on a
  76.      PDP 11/45 emulator; or
  77.  
  78.    * Unpack the 5th Edition root filesystem tree on a 32-bit little-endian
  79.      Unix system, and use the Apout emulator.
  80.  
  81. For convenience, I chose to use the Apout emulator (version 2.2alpha8) as my
  82. development environment, and Bob Supnik's PDP-11 simulator (version 2.3d) as
  83. the booting environment. With the latter, I used the 5th Edition RK05 disk
  84. image Distributions/research/Dennis_v5/v5root.gz (from the PUPS Archive) as
  85. the filesystem.
  86.  
  87. Regardless of the method you choose, the modified `nsys' source must be
  88. unpacked in the directory /sys/nsys, relative to the top of the 5th Edition
  89. root directory, i.e the file u (size 26,266 bytes) becomes /sys/nsys/u. This
  90. file is the original `nsys' kernel image, as supplied by Dennis; we will
  91. build our own kernel image.
  92.  
  93. Changes to the Nsys Source
  94. --------------------------
  95.  
  96. Several files in the `nsys' source had to be modified so as the `nsys'
  97. kernel would work with a 5th Edition filesystem & boot environment. The
  98. discovery of these changes took me several days of fiddling with C code,
  99. assembly code, single-stepping machine code, and perusing the Lions'
  100. commentary. Email me if you really want to know the gory details.
  101.  
  102. The changes to the ten `nsys' source code files are described below:
  103.  
  104. Filesystem
  105.      The 5th Edition filesystem is laid out slightly differently to that
  106.      which the `nsys' kernel is expecting. The filsys struct needs an extra
  107.      field, s_ronly, and the inode struct needs an extra field, i_lastr. The
  108.      two files affected are filsys.h and inode.h.
  109.  
  110. C language
  111.      The C language changed slightly from the `nsys' kernel to the 5th
  112.      Edition. Sub-structures defined within a structure were delimited by
  113.      parentheses in `nsys', but by braces in 5th Edition. The only file
  114.      affected is user.h.
  115.  
  116.      Several lines in the psig() routine in ken/sig.c were rearranged
  117.      because the 5th Edition C compiler refused to parse them. The actual
  118.      operations performed are unchanged.
  119.  
  120. Device table changes
  121.      The `nsys' kernel is configured to have four block device drivers (rf,
  122.      rk, tc and tm), and ten character device drivers (kl, dc, pc, dp, dn,
  123.      mm, vt, da, ct, vs). To minimise debugging, I chose to remove as many
  124.      of the drivers as possible. I left two block device drivers, rk and tm,
  125.      and two character device drivers, kl and mm. The two main files
  126.      affected were conf/c.c and conf/l.s.
  127.  
  128.      The device driver dmr/rk.c also had to be modified, as it was
  129.      hard-wired to be block device number 1. It is now block device number
  130.      0.
  131.  
  132. Deficiencies
  133.      In the putchar() routine in prf.c, a test is made on a register in the
  134.      console KL device. This register isn't described in my PDP-11
  135.      peripherals handbook (dated 1973), and it isn't implemented in Bob
  136.      Supnik's simulator, so I removed the code.
  137.  
  138.      The declaration of the clist struct in tty.h need a semicolon to end
  139.      the declaration; again, this could be due to a change in the C
  140.      language.
  141.  
  142.      The machine code for location 0 in conf/l.s has the octal value 4 then
  143.      the instruction br 1f. In 5th Edition, these two are transposed. It
  144.      appears that the entry to the `nsys' kernel must have been at location
  145.      2 (i.e the br instruction), whereas the 5th Edition kernel starts at
  146.      location 0. Octal 4 is an IOT instruction, which causes an immediate
  147.      hardware exception on the PDP-11. I have transposed these two lines in
  148.      the `nsys' code.
  149.  
  150. Cosmetic changes
  151.      While trying to get the `nsys' kernel to boot properly, I added the 5th
  152.      Edition printf line to main() in main.c, which outputs the amount of
  153.      physical memory available on the machine.
  154.  
  155. As well as these changes, I have moved a few files around so that those
  156. parts of the kernel which must be tailored for each hardware configuration
  157. are kept in the conf/ directory. Final linking of the `nsys' kernel is also
  158. done in this directory. A few other files have been renamed or moved, again
  159. to tidy up the layout of the source. The changes are:
  160.  
  161.    * dmr/malloc.c becomes dmr/mem.c
  162.    * tables.c becomes dmr/partab.c
  163.    * ken/45.s becomes conf/mch.s
  164.    * ken/low.s becomes conf/l.s
  165.    * ken/conf.c becomes conf/c.c
  166.  
  167. There are several new RCS directories, which hold the changes to the ten
  168. `nsys' files listed above. Finally, three short shell scripts have been
  169. created to make compilation of the `nsys' kernel relatively easy: ken/mklib,
  170. dmr/mklib and conf/mkunix.
  171.  
  172. Compiling the Nsys Kernel
  173. -------------------------
  174.  
  175. Here is a typescript of the commands required to compile the `nsys' kernel.
  176. I have added some comments to the typescript.
  177.  
  178. % alias 5sh
  179. setenv APOUT_ROOT /usr/local/src/V5; apout $APOUT_ROOT/bin/sh
  180.  
  181. % 5sh                           # Run Apout
  182.  
  183. # chdir /sys/nsys               Move to the `nsys' directory
  184. # chdir ken                     Start with the kernel code
  185. # cat mklib
  186. cc -c -O *.c
  187. rm ../lib1
  188. ar vr ../lib1 main.o alloc.o iget.o prf.o rdwri.o slp.o subr.o text.o trap.o \
  189.  sig.o sysent.o clock.o fio.o malloc.o nami.o prproc.o sys1.o sys2.o \
  190.  sys3.o sys4.o
  191.  
  192. # sh mklib                      Run the script to build lib1
  193. alloc.c:
  194. clock.c:
  195. fio.c:
  196. iget.c:
  197. main.c:
  198. malloc.c:
  199. nami.c:
  200. prf.c:
  201. prproc.c:
  202. rdwri.c:
  203. sig.c:
  204. slp.c:
  205. subr.c:
  206. sys1.c:
  207. sys2.c:
  208. sys3.c:
  209. sys4.c:
  210. sysent.c:
  211. text.c:
  212. trap.c:
  213. ../lib1: non existent
  214. a main.o
  215. a alloc.o
  216. a iget.o
  217. a prf.o
  218. a rdwri.o
  219. a slp.o
  220. a subr.o
  221. a text.o
  222. a trap.o
  223. a sig.o
  224. a sysent.o
  225. a clock.o
  226. a fio.o
  227. a malloc.o
  228. a nami.o
  229. a prproc.o
  230. a sys1.o
  231. a sys2.o
  232. a sys3.o
  233. a sys4.o
  234.  
  235. # chdir ../dmr                          Move to the devices directory
  236. # cat mklib
  237. cc -c -O *.c
  238. as gput.s
  239. mv a.out gput.o
  240. rm ../lib2
  241. ar vr ../lib2 *.o
  242.  
  243. # sh mklib                              Run the script to build lib2
  244. bio.c:
  245. cat.c:
  246. dc.c:
  247. dn.c:
  248. dp.c:
  249. draa.c:
  250. kl.c:
  251. mem.c:
  252. partab.c:
  253. pc.c:
  254. rf.c:
  255. rk.c:
  256. tc.c:
  257. tm.c:
  258. tty.c:
  259. vs.c:
  260. vt.c:
  261. ../lib2: non existent
  262. a bio.o
  263. a cat.o
  264. a dc.o
  265. a dn.o
  266. a dp.o
  267. a draa.o
  268. a gput.o
  269. a kl.o
  270. a mem.o
  271. a partab.o
  272. a pc.o
  273. a rf.o
  274. a rk.o
  275. a tc.o
  276. a tm.o
  277. a tty.o
  278. a vs.o
  279. a vt.o
  280.  
  281. # chdir ../conf                         Move to the configuration directory
  282. # cat mkunix
  283. as mch.s
  284. mv a.out mch.o
  285. cc -c c.c
  286. as l.s
  287. mv a.out l.o
  288. ld -x l.o mch.o c.o ../dmr/gput.o ../lib1 ../lib2
  289. mv a.out unix
  290. nm -n unix > namelist
  291. ls -l unix
  292. size unix
  293.  
  294. # sh mkunix                             Build config, link the kernel
  295. -rwxrwxrwx  1 root    25322 Jan 14 22:02 unix
  296. 21286+888+15962=38136 (0112370)
  297.  
  298. # ls -l                                 And see what other files we have
  299. total 82
  300. drwxr-xr-x  2 root      512 Jan 14 05:37 RCS
  301. -r--r--r--  1 root      307 Jan 14 00:31 c.c
  302. -rw-rw-rw-  1 root      292 Jan 14 22:02 c.o
  303. -rw-rw-rw-  1 root     1200 Jan 14 22:02 l.o
  304. -r--r--r--  1 root     2004 Jan 13 22:37 l.s
  305. -rw-rw-rw-  1 root     1888 Jan 14 22:02 mch.o
  306. -r--r--r--  1 root     3896 Jan 10 18:19 mch.s
  307. -r--r--r--  1 root      161 Jan 14 19:37 mkunix
  308. -rw-------  1 root     3995 Jan 14 22:02 namelist
  309. -rwxrwxrwx  1 root    25322 Jan 14 22:02 unix
  310. #
  311.  
  312. Installing the Nsys Kernel
  313. --------------------------
  314.  
  315. Now that the `nsys' kernel is compiled, we have to install it in the root
  316. directory of an RK05 5th Edition UNIX root filesystem. I used the bootable
  317. 5th Edition disk image v5root and Bob Supnik's emulator to do this.
  318.  
  319. 5th Edition UNIX doesn't have tar, so I mounted v5root as RK pack 0, and I
  320. mounted the new `nsys' kernel as RK pack 1, after doing some padding to the
  321. file.
  322.  
  323. % ls -l
  324. -rwx------  1 wkt  wheel   117728 Jan 11 14:02 pdp      Supnik simulator
  325. -rw-------  1 wkt  wheel       55 Jan 15 14:12 v5       Config file
  326. -r--------  1 wkt  wheel  2494464 Jan 15 13:35 v5root   V5 filesystem
  327. -rw-------  1 wkt  wheel     4096 Jan 14 12:06 zero     File of zeroes
  328.  
  329. % cp ../V5/sys/nsys/conf/unix nsys.binary       Copy the kernel here
  330. % cat zero >> nsys.binary                       Pad it with zeroes
  331.  
  332. % cat v5                                        Here is the config file
  333. set cpu 18b
  334. att rk0 v5root
  335. att rk1 nsys.binary
  336. boot rk
  337.  
  338. % ./pdp v5                                      Run the simulator
  339.  
  340. PDP-11 simulator V2.3d
  341. @unix                                           Start V5 UNIX
  342.  
  343. login: root
  344. # check /dev/rrk0                               Check root filesystem
  345. /dev/rrk0:
  346. spcl       5
  347. files    566
  348. large    126
  349. direc     28
  350. indir    126
  351. used    3790
  352. last    3985
  353. free     128
  354.  
  355. # ls -l /dev                                    You may need to /etc/mknod
  356. total 0                                         at least /dev/rrk1
  357. cr--r--r--  1 bin     1,  0 Nov 26 18:13 mem
  358. crw-rw-rw-  1 bin     1,  2 Nov 26 18:13 null
  359. crw-rw-rw-  1 root    2,  0 Mar 21 13:53 rrk0
  360. crw-rw-rw-  1 root    2,  1 Mar 21 14:18 rrk1
  361. crw--w--w-  1 root    0,  0 Mar 21 15:26 tty8
  362.  
  363. # dd if=/dev/rrk1 count=50 of=z                 Load in `nsys' kernel + pad
  364. 50+0 records in
  365. 50+0 records out
  366.  
  367. # dd if=z of=nsys bs=11761 count=2              Trim back to correct size
  368. 2+0 records in
  369. 2+0 records out
  370.  
  371. # rm z                                          Remove temporary files
  372.  
  373. # ls -l nsys                                    Check correct size
  374. -rw-rw-rw-  1 root    23522 Mar 21 15:29 nsys
  375.  
  376. # size nsys                                     Verify a.out values, should
  377. 21286+888+15962=38136 (0112370)                 be the same as before
  378.  
  379. # sync                                          Shut down V5 UNIX
  380. # sync
  381. # ^E                                            and exit the simulator
  382. Simulation stopped, PC: 014116 (BNE 14150)
  383. sim> q
  384. Goodbye
  385.  
  386. You now have the `nsys' kernel stored in the root directory of the 5th
  387. Edition root filesystem. You can now boot it and see that it works.
  388.  
  389. % ./pdp v5                                      Run the simulator
  390.  
  391. PDP-11 simulator V2.3d
  392. @nsys                                           Load the nsys kernel
  393. mem = 64539                                     Printout of avail memory
  394.  
  395. login: root                                     /etc/init works!
  396.  
  397. # ls -l                                         So does /bin/ls
  398. total 107
  399. drwxr-xr-x  2 bin       944 Nov 26 18:13 bin
  400. drwxr-xr-x  2 bin       112 Mar 21 14:21 dev
  401. drwxr-xr-x  2 bin       240 Mar 21 12:07 etc
  402. drwxr-xr-x  2 bin       224 Nov 26 18:13 lib
  403. drwxr-xr-x  2 bin        32 Nov 26 18:13 mnt
  404. -rw-rw-rw-  1 root    23522 Mar 21 15:29 nsys
  405. drwxrwxrwx  2 bin       128 Mar 21 14:16 tmp
  406. -rwxrwxrwx  1 bin     25802 Mar 21 12:07 unix
  407. drwxr-xr-x 14 bin       224 Nov 26 18:13 usr
  408. # sync
  409. # ^E                                            Exit the simulator
  410. Simulation stopped, PC: 015140 (BLT 15050)
  411.  
  412. Final Notes
  413. -----------
  414.  
  415. The `nsys' kernel can now boot and run some 5th Edition UNIX a.out binaries.
  416. However, `nsys' is an earlier version than 5th Edition, so there will be
  417. some V5 functionality which `nsys' does not support. In particular, `nsys'
  418. does not have the pipe() system call. I have only just got the `nsys' kernel
  419. to boot, so I have not had a chance to sit down and work out exactly what
  420. functionality is missing.
  421.