From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25208 invoked from network); 30 Dec 2022 18:25:32 -0000 Received: from minnie.tuhs.org (50.116.15.146) by inbox.vuxu.org with ESMTPUTF8; 30 Dec 2022 18:25:32 -0000 Received: from minnie.tuhs.org (localhost [IPv6:::1]) by minnie.tuhs.org (Postfix) with ESMTP id AA18642366; Sat, 31 Dec 2022 04:25:22 +1000 (AEST) Received: from ewsoutbound.kpnmail.nl (unknown [195.121.94.170]) by minnie.tuhs.org (Postfix) with ESMTPS id 175D042363 for ; Sat, 31 Dec 2022 04:25:12 +1000 (AEST) X-KPN-MessageId: 3e390d0f-886f-11ed-8e68-005056ab378f Received: from smtp.kpnmail.nl (unknown [10.31.155.40]) by ewsoutbound.so.kpn.org (Halon) with ESMTPS id 3e390d0f-886f-11ed-8e68-005056ab378f; Fri, 30 Dec 2022 19:24:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=planet.nl; s=planet01; h=to:date:message-id:subject:mime-version:content-type:from; bh=EmVXq0xJ7kGFIsfykqv46lgjaZhaK+D+ZSdbb5oaN9A=; b=gcOFvh868mNh+QnwC5agJA3aiHFjdJrzSJomzuWhRvtNPzY/OYvOnhkdrCdVVIfAJav/BsjvoziNO PNyMVoFwj1Ziv18BNpyvNqe8UtihsZfn3OtPEsLEC7G1vIxkCFVIxWaT07AabRwWy0Jr7imtuFJZa/ 8I273XkAD3gOKSGo= X-KPN-MID: 33|Czk+2XVkgksq4O4mjXOL30ZZTN1qaIhd+i0bojIndNA/ykOZhMzNivrq76pEnUX m2FA5xBc9Ych4WF5XmrcacFdmOTiVwMUTZkzW5HY1Cgw= X-KPN-VerifiedSender: Yes X-CMASSUN: 33|IfOKpYStJo7BUgI9YaawzcIRgm5EknHl2Ff4uW9PXjY/GDE3meQp8tlcCEjN8Ol 7bQBUMOnfSER3257SgstSwg== X-Originating-IP: 77.172.38.96 Received: from smtpclient.apple (77-172-38-96.fixed.kpn.net [77.172.38.96]) by smtp.kpnmail.nl (Halon) with ESMTPSA id 45e58398-886f-11ed-927c-005056ab7584; Fri, 30 Dec 2022 19:25:01 +0100 (CET) From: Paul Ruizendaal Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Message-Id: Date: Fri, 30 Dec 2022 19:25:01 +0100 To: The Eunuchs Hysterical Society X-Mailer: Apple Mail (2.3654.120.0.1.13) Message-ID-Hash: Y62E5V25Z3GKQXR7G3F7PG3GGBVB2JF5 X-Message-ID-Hash: Y62E5V25Z3GKQXR7G3F7PG3GGBVB2JF5 X-MailFrom: pnr@planet.nl X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-tuhs.tuhs.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [TUHS] Riscv, Plan-9 and a toolchain List-Id: The Unix Heritage Society mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: After initially gearing up to use the Motorola 68020 or 68030 as a = porting target for a study of Unix in the 1980-1985 era, I reconsidered = and used Risc-V as a target instead. As the original RISC and MIPS = projects were contemporaneous with early 32-bit Unix (32V, BSD, SysIII = and SVr1,r2) it seems appropriate and there is currently considerable = interest (hype?) around Risc-V. =46rom a programming perspective, the Risk-V ISA does not feel (at least = to me) all that different from what was current in the early 80=E2=80=99s = =E2=80=94 the number of WTFs/min is low. The modularity is a pleasant = surprise, as is the observation that the 32-bit and 64-bit instruction = sets are almost identical and that compressed instructions mingle nicely = with full size ones. The MMU design appears straightforward. Maybe this = is because the ISA is still relatively new and has not acquired much = historical baggage at this point in its lifespan, but it also seems to = be a good synthesis of insights gained over the last 4 decades and = applied with a sense of minimalism. At first I was thinking to create a toolchain based on pcc or pcc2 for = the SysIII porting effort, based on some preparation I had done when I = was still thinking about 68030 as a target (the surviving Blit code = includes a pcc-based 68000 compiler and the SysV/68 source archive = contains a pcc2-based compiler). Before I got underway with that, I came = across a presentation Richard Miller had done about his Risc-V compiler: = https://riscv.org/news/2020/10/a-plan-9-c-compiler-for-rv32gc-and-rv64gc/ Richard was kind enough to share the source code for his Risc-V = back-end. The first complication was that the source code assumes that = it will be running inside a Plan-9 environment, whereas I was looking = for a Unix/Posix environment. Luckily somebody already had assembled the = libraries needed for this: https://github.com/aryx/fork-kencc I=E2=80=99m not sure where it came from, but I would assume it has some = roots in the "Plan-9 from user space" effort. =46rom this work I = extracted the minimum needed to get the C compiler working and to build = from scratch. The libraries mostly just worked. The compiler was a bit = harder: the source code assumes a LLP64 model in a few places and = compiling this with clang (which uses a LP64 model) introduces issues in = a handful of places. Other than this initial hurdle, the compiler and = tools have worked flawlessly, both for 64-bit code and for 32-bit code, = and have been a joy to use. One particular nicety is that Plan 9 style = "abstract assembler" source for 64-bit code is even more identical to = its 32-bit variant than with the mainstream Risc-V assembler syntax. My = repo for the tool chain is here: https://gitlab.com/pnru/riscv-kencc Initially, my expectation was that I could only use these compilers as = cross-compilers and that I would need to do a pcc2 version for native = compilation at some point. However, when I saw how small and fast the = tools were, I experimented with using them on SysIII. Much to my = surprise the effort required was absolutely minimal, all that was needed = was adding a dozen simple standard functions in libc (see here: = https://gitlab.com/pnru/SysIII_rv64/-/tree/master/libc/compat) and = adding the =E2=80=98dup2' sys call. I had not expected that SysIII was = so close to the Unix systems of the 1990=E2=80=99s in this regard. This = result inspires ideas for future projects: as I plan to add an 8th = edition style file system switch anyway, maybe it will not be all that = hard to make the Plan-9 debugger work on this =E2=80=9CSysIII+=E2=80=9D = as well. Another observation has been that the code size of binaries compiled for = Risc-V by this tool chain is almost the same as those compiled for the = VAX by pcc (the Risc-V ones are maybe 10-20% larger). This is using the = compressed instructions where possible. This is I think another = indication that both the Risc-V ISA and the tool chain are quite well = done. The one less positive surprise has been the memory use of the compiler. = Even on a relatively simple program file it will quickly use 1 megabyte = or more of ram. I understood from Richard that this is because the = compiler only malloc()=E2=80=99s and never free()=E2=80=99s by design. = This has been a mixed blessing. Such large memory images don=E2=80=99t = work all that well with the "scatter paging + partial swapping" memory = management of SysIII when memory is constrained to say 4MB of core to = mimic the systems of the era. On the other hand, parallel compiling the = kernel on SysIII itself heavily exercises the partial swapping code and = has been a great test case for debugging. Many thanks to Ken, Rob, Richard and all the others who created this = fine tool chain!