+diff --git a/build/Makefile b/build/Makefile
+index 7b23f41..a77cc82 100644
+@@ -105,7 +105,7 @@ $(ALLSRCS) patched : $(CLEANSRCS)
+ @echo Building kernel...
+- @$(NM) a.out | sort > usyms
++ @$(NM) a.out | LANG=C sort > usyms
+ # build a prototype filesystems
+@@ -143,6 +143,7 @@ tape : protofs
+ install : rf0.dsk rk0.dsk
+ @cp rf0.dsk rk0.dsk ../boot/m792low.load ../images
+ # clean intermediate files
+diff --git a/patches/core/initorig.patch b/patches/core/initorig.patch
+index 3f13b20..01c4590 100644
+--- a/patches/core/initorig.patch
++++ b/patches/core/initorig.patch
+---- init.clean 2008-06-25 08:39:57.000000000 -1000
+-+++ init.s 2008-06-25 08:40:08.000000000 -1000
++--- build/init.clean 2024-02-21 09:38:45.071459600 +0900
+++++ build/init.s 2024-02-21 09:38:48.915208600 +0900
+ / init -- process control initialization
+diff --git a/tools/apout/bsd_ioctl.c b/tools/apout/bsd_ioctl.c
+index 3fd1e0f..d1496e9 100644
+--- a/tools/apout/bsd_ioctl.c
++++ b/tools/apout/bsd_ioctl.c
++#if !defined(FIOCLEX) || !defined(FIOSETOWN)
+ #define TR_TIOCSETP 0x40067409 /* 0x8 is a write */
+ #define TR_TIOCSETN 0x8006740a
+ #define TR_TIOCSETC 0x80067411
+ #define TR_TIOCGETD 0x40027400
+ #define TR_TIOCSETD 0x80027401
+ #define TR_TIOCGETC 0x40067412
+ #define TR_TIOCGLTC 0x40067474
+ #define TR_TIOCSLTC 0x80067475
+@@ -132,8 +139,12 @@ int trap_ioctl()
+ case TR_TIOCSETP: fprintf(dbg_file, "TIOCSETP "); break;
+ case TR_TIOCSETN: fprintf(dbg_file, "TIOCSETN "); break;
+ case TR_TIOCSETC: fprintf(dbg_file, "TIOCSETC "); break;
+ case TR_TIOCGETD: fprintf(dbg_file, "TIOCGETD "); break;
+ case TR_TIOCSETD: fprintf(dbg_file, "TIOCSETD "); break;
+ case TR_TIOCGETC: fprintf(dbg_file, "TIOCGETC "); break;
+ case TR_TIOCGLTC: fprintf(dbg_file, "TIOCGLTC "); break;
+ case TR_TIOCSLTC: fprintf(dbg_file, "TIOCSLTC "); break;
+@@ -171,12 +182,18 @@ int trap_ioctl()
+ i = trap_settermios(uarg1, larg1, uarg4); break;
+ i = ioctl(uarg1, FIOCLEX, NULL); break;
++ i = fcntl(uarg1, F_SETFD, FD_CLOEXEC); break;
+ shortptr = (int16_t *) &dspace[uarg4];
+ i = ioctl(uarg1, TIOCGETD, &val);
+ if (i==0) *shortptr= val;
+ shortptr = (int16_t *) &dspace[uarg4];
+ i = ioctl(uarg1, TIOCGPGRP, &val);
+@@ -185,15 +202,21 @@ int trap_ioctl()
+ shortptr = (int16_t *) &dspace[uarg4];
+ val= *shortptr; i = ioctl(uarg1, TIOCSPGRP, &val); break;
+ shortptr = (int16_t *) &dspace[uarg4];
+ val= *shortptr; i = ioctl(uarg1, TIOCSETD, &val); break;
+ shortptr = (int16_t *) &dspace[uarg4];
+ /* Something wrong here, wonder why! */
+ TrapDebug((dbg_file, "fd %d val %d ",uarg1,val));
+ i = ioctl(uarg1, FIOSETOWN, &val); break;
++ i = fcntl(uarg1, F_SETOWN, val); break;
+ shortptr = (int16_t *) &dspace[uarg4];
+ i = ioctl(uarg1, TIOCMGET, &val);
+diff --git a/tools/apout/bsdtrap.c b/tools/apout/bsdtrap.c
+index 2c450d5..ff3017e 100644
+--- a/tools/apout/bsdtrap.c
++++ b/tools/apout/bsdtrap.c
+@@ -57,11 +57,16 @@ bsdtrap()
++#ifdef STREAM_BUFFERING
+ char *fmode; /* used with fdopen only */
+ struct stat stbuf; /* used in STAT */
+ struct tr_stat *tr_stbuf; /* used in STAT */
+ struct tr_timeval *tr_del, *tr_oldel; /* used in ADJTIME */
+- struct timeval del, oldel; /* used in ADJTIME */
++ struct timeval del; /* used in ADJTIME */
++#if !defined(NO_ADJTIME)
++ struct timeval oldel; /* used in ADJTIME */
+ struct timeval utv[2]; /* used in UTIMES */
+ struct tr_timezone *tr_zone; /* used in GETTIMEOFDAY */
+ struct timezone zone; /* used in GETTIMEOFDAY */
+@@ -222,9 +227,11 @@ bsdtrap()
+ case S_RMDIR: /* DONE */
+ buf = xlate_filename((char *)&dspace[uarg1]);
+ case S_ACCT: /* DONE */
+ buf = xlate_filename((char *)&dspace[uarg1]);
+ case S_WRITEV: /* DONE */
+ case S_READV: /* DONE */
+ ivec= (struct iovec *)malloc(uarg3 * sizeof(struct iovec));
+@@ -323,6 +330,7 @@ dostat:
+ copylong(tr_oldel->tv_sec, utv[1].tv_sec);
+ copylong(tr_oldel->tv_usec, utv[1].tv_usec);
++#if !defined(NO_ADJTIME)
+ case S_ADJTIME: /* DONE */
+ tr_del = (struct tr_timeval *) &dspace[uarg1];
+ /* Convert tr_del to del */
+@@ -336,6 +344,7 @@ dostat:
+ copylong(tr_oldel->tv_usec, oldel.tv_usec);
+ case S_GETTIMEOFDAY: /* DONE */
+ tr_del = (struct tr_timeval *) &dspace[uarg1];
+ tr_zone = (struct tr_timezone *) &dspace[uarg2];
+@@ -385,17 +394,21 @@ dostat:
+ i = stat(buf, &stbuf); /* If file is a directory */
+ if (i == 0 && (stbuf.st_mode & S_IFDIR)) {
++#ifdef STREAM_BUFFERING
+ TrapDebug((dbg_file, "(dir) on %s ",buf));
+ sarg2= map_fcntl(sarg2);
++#ifdef STREAM_BUFFERING
+ switch (sarg2 & O_ACCMODE) {
+ case O_RDONLY: fmode = "r"; break;
+ case O_WRONLY: fmode = "w"; break;
+ default: fmode = "w+"; break;
+ i = open(buf, sarg2, sarg3);
+ TrapDebug((dbg_file, "on %s ",buf));
+ TrapDebug((dbg_file, "sarg2 is %d, sarg3 is 0x%x ",sarg2,sarg3));
+@@ -506,9 +519,11 @@ dostat:
++#if !defined(NO_SETHOSTID)
+ case S_SETHOSTID: /* DONE */
+ larg1 = (sarg2 << 16) | uarg3;
+ sethostid(larg1); i=0; break;
+ case S_GETUID: /* DONE */
+ case S_SETUID: /* DONE */
+@@ -559,7 +574,7 @@ dostat:
+ tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
+ sock.sa_family= tr_sock->sa_family;
+ memcpy(sock.sa_data, tr_sock->sa_data, len);
+@@ -573,7 +588,7 @@ dostat:
+ tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
+ sock.sa_family= tr_sock->sa_family;
+ memcpy(sock.sa_data, tr_sock->sa_data, len);
+@@ -587,7 +602,7 @@ dostat:
+ tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
+ sock.sa_family= tr_sock->sa_family;
+ memcpy(sock.sa_data, tr_sock->sa_data, len);
+@@ -601,7 +616,7 @@ dostat:
+ tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
+ sock.sa_family= tr_sock->sa_family;
+ memcpy(sock.sa_data, tr_sock->sa_data, len);
+@@ -611,7 +626,7 @@ dostat:
+ tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
+ sock.sa_family= tr_sock->sa_family;
+ memcpy(sock.sa_data, tr_sock->sa_data, len);
+@@ -621,7 +636,7 @@ dostat:
+ tr_sock= (struct tr_sockaddr *)&dspace[uarg5];
+ sock.sa_family= tr_sock->sa_family;
+ memcpy(sock.sa_data, tr_sock->sa_data, len);
+diff --git a/tools/apout/defines.h b/tools/apout/defines.h
+index 1f27603..59fb5eb 100644
+--- a/tools/apout/defines.h
++++ b/tools/apout/defines.h
+ # define NEED_MAP_FCNTL
+ # define Reboot(x) exit(0)
+-#if !defined(__FreeBSD__) && !defined(__NetBSD__) && \
+- !defined(__OpenBSD__) && !defined(__linux__) && !defined(__APPLE__)
+-/* Type definitions for PDP data types. You may need to
+- * define NEED_INT_N if your system doesn't provide the
+- * types defined below. If you do this, the best way is
+- * to add some #if .. #define .. #endif lines above,
+- * rather then modifying the ones below. If you make
+- * changes to the #if's above, then I would be very
+- * happy to include them.
+- * Warren Toomey: wkt@tuhs.org
+-typedef unsigned char u_int8_t;
+-typedef unsigned short u_int16_t;
+-typedef unsigned long u_int32_t;
++#define u_int8_t uint8_t
++#define u_int16_t uint16_t
++#define u_int32_t uint32_t
+ /* Macro defines for debug output, makes
+ * the code look somewhat cleaner
+diff --git a/tools/apout/fp.c b/tools/apout/fp.c
+index 3b69cb3..b5f5b51 100644
+@@ -42,7 +42,7 @@ int INTMODE=0; /* 0 = integers, 1 = longs */
+ /* Temporary variables */
+ FLOAT Srcflt; /* Float specified by FSRC field */
+ pdpfloat *fladdr; /* Address of float in dspace */
+-int AC; /* Accumulator field in ir */
++extern int AC; /* Accumulator field in ir */
+ int32_t srclong; /* Longword from source address */
+ int32_t dstlong; /* Longword for destination address */
+ static char *buf, *buf2; /* for copylong */
+diff --git a/tools/apout/v7trap.c b/tools/apout/v7trap.c
+index 00a2f31..4f1d685 100644
+--- a/tools/apout/v7trap.c
++++ b/tools/apout/v7trap.c
+@@ -68,7 +68,7 @@ v7trap()
+ char *fmode; /* used with fdopen only */
+@@ -692,9 +692,9 @@ static int v7signal(int sig, int val)
+- return((int)signal(v7sig[sig], SIG_IGN));
++ return((intptr_t)signal(v7sig[sig], SIG_IGN));
+- return((int)signal(v7sig[sig], SIG_DFL));
++ return((intptr_t)signal(v7sig[sig], SIG_DFL));
+ return(0); /* No handling of this as yet */
+diff --git a/tools/disaout/opset.c b/tools/disaout/opset.c
+index 9745d76..4359ca5 100644
+--- a/tools/disaout/opset.c
++++ b/tools/disaout/opset.c
+@@ -358,7 +358,9 @@ void branch(char *str, int addr, int ins)
+@@ -374,7 +376,9 @@ int printins(int addr)
+ /* Get the instruction from the ispace array */
+ int ins = ispace[addr] + (ispace[addr + 1] << 8);
+ for (p = optab;; p++) {
+ if ((ins & ~p->mask) == p->val) {
+@@ -389,7 +393,9 @@ int printins(int addr)
+@@ -405,7 +411,9 @@ int printins(int addr)
+diff --git a/tools/fixaout.py b/tools/fixaout.py
+index ce5ac90..ca768d2 100755
+ Convert an 0407 binary into an 0405 binary, under the assumption
+ that the code starts at 040014 (by ".. = 40014").
+@@ -6,6 +6,7 @@ See tools/as.
+@@ -15,17 +16,17 @@ def unwords(ws) :
+ return struct.pack('<%dH' % l, *ws)
+ d1 = words(read('a.out'))
+-d = [0405, 12+hdr[1], 0, 0, hdr[4], 0] + d1[8:]
++d = [0o405, 12+hdr[1], 0, 0, hdr[4], 0] + d1[8:]
+ write("a.out", unwords(d))
+diff --git a/tools/mkfs.c b/tools/mkfs.c
+index a463044..1403f0b 100644
+@@ -128,7 +128,7 @@ void write_superblock(void)
+ printf("Writing inodelist from block 2\n");
+ fseek(diskfh, 2 * BLKSIZE, SEEK_SET);
+- if (debug) printf("Writing %d inodes, each size %d, total %d\n",
++ if (debug) printf("Writing %d inodes, each size %ld, total %ld\n",
+ icount, sizeof(struct v1inode), icount * sizeof(struct v1inode));
+ fwrite(&inodelist[1], sizeof(struct v1inode), icount - 1, diskfh);
+@@ -361,7 +361,7 @@ void write_dir(struct directory *d, char *name)
+- printf("Writing dir %s, size %d, %d blks from block %d (offset 0x%x) on\n",
++ printf("Writing dir %s, size %ld, %ld blks from block %d (offset %#x) on\n",
+ name, d->numentries * sizeof(struct v1dirent),
+ d->numentries / DIRENTPERBLOCK, d->block,
+@@ -683,7 +683,9 @@ int main(int argc, char *argv[])
+ int fs_size; /* Equal to disksize minus any swap */
+ /* Get any optional arguments */
+ while ((ch = getopt(argc, argv, "dp:")) != -1) {
+@@ -707,10 +709,14 @@ int main(int argc, char *argv[])
+ /* XXX: I can't seem to go past 4864 to 4872 blocks, and I haven't */
+ /* worked out why yet. */
+ fs_size = RF_NOSWAPSIZE;
+diff --git a/tools/mktape.py b/tools/mktape.py
+index 1682606..4ad2df6 100755
+ Make a tape for 1st ed cold boot.
+@@ -15,6 +15,7 @@ metadata:
+ from struct import pack
+ # unfortunately the permission bits and uids weren't preserved
+ # so we have to restore them based on this table...
+@@ -120,12 +121,12 @@ noisy = 0
+- if s[0] == 'u' : m |= 040 | 020
+- if s[0] == 'x' : m |= 020
+- if s[1] == 'r' : m |= 010
+- if s[2] == 'w' : m |= 004
+- if s[3] == 'r' : m |= 002
+- if s[4] == '2' : m |= 001
++ if s[0] == 'u' : m |= 0o40 | 0o20
++ if s[0] == 'x' : m |= 0o20
++ if s[1] == 'r' : m |= 0o10
++ if s[2] == 'w' : m |= 0o04
++ if s[3] == 'r' : m |= 0o02
++ if s[4] == '2' : m |= 0o01
+ # preprocess the perms table to form perm :: path -> (mode, uid)
+@@ -138,31 +139,31 @@ def pad(d) :
+ "pad to 512-byte boundary"
+ m = ((l + 511) & ~511) - l
++ return d + str.encode("\0" * m)
+- ("-","s")[(m & 040) != 0] +
+- ("-","x")[(m & 020) != 0] +
+- ("-","r")[(m & 010) != 0] +
+- ("-","w")[(m & 004) != 0] +
+- ("-","r")[(m & 002) != 0] +
+- ("-","w")[(m & 001) != 0] )
++ ("-","s")[(m & 0o40) != 0] +
++ ("-","x")[(m & 0o20) != 0] +
++ ("-","r")[(m & 0o10) != 0] +
++ ("-","w")[(m & 0o04) != 0] +
++ ("-","r")[(m & 0o02) != 0] +
++ ("-","w")[(m & 0o01) != 0] )
+ def wrFile(out, fn, d, mode, uid) :
+- print sMode(mode), uid, fn
++ print(sMode(mode), uid, fn)
+ meta = pack("<HBB", len(d), mode, uid) + fn
+- wrFile(out, "", "", 0, 0)
++ wrFile(out, b"", b"", 0, 0)
+ def copyFile(root, out, fn) :
+ "copy file from local filesystem to tape."
+@@ -170,19 +171,19 @@ def copyFile(root, out, fn) :
+ # get the perm from the table, if not present, just make it
+- mode,uid = perms.get(fn, (037, 1))
+- if not fn in perms : print "making up mode"
+- wrFile(out, fn, d, mode, uid)
++ mode,uid = perms.get(fn, (0o37, 1))
++ if not fn in perms : print("making up mode")
++ wrFile(out, str.encode(fn), d, mode, uid)
+- print "usage: %s root files" % sys.argv[0]
++ print("usage: %s root files" % sys.argv[0])
+- f = file("tape", "wb")
+- f.write("\0" * (512 * 65)) # start at block 65
++ f = open("tape", "wb")
++ f.write(str.encode("\0" * (512 * 65))) # start at block 65