Hey y’all ![]()
Here’s some of the components involved in booting a plan9 system:
COMPONENT SOURCE CODE MAN PAGE
--------------------------------------------------------------
kernel
/boot/boot # /sys/src/9/boot/boot.c boot(8)
/sys/src/9/boot/bootrc # rc script boot(8)
/$cputype/init # /sys/src/cmd/init.c init(8)
/rc/bin/cpurc # rc script cpurc(8)
On a terminal, /rc/bin/termrc would be used instead of /rc/bin/cpurc.
cpurc is an rc shell script:
Here’s an experimental conversion of this to ocaml:
As you can see, boot_cpu_main.ml simply calls out to different modules.
These modules can be found here:
This conversion from rc to ocaml is an early first pass.
A fairly naive approach has been taken.
There is lots of room for improvement.
Making some of these modules more idiomatic would likely require building plan9-specific libraries, instead of working with the portable OS libraries offered by the ocaml.
As you browse each of the modules used by boot_cpu_main.ml,
a convention you’ll notice is that the original rc code
is at the top of the file in a comment.
This makes it straighforward to compare the rc and ocaml code.
Here’s boot_factotum.ml for example:
(* Stock cpurc lines 21-22 and termrc lines 22-23 from the tracked baselines:
mount /srv/factotum /mnt/factotum factotum
bind -q /mnt/factotum/factotum /mnt/factotum
*)
let run () =
Mount.mount ~flags:[]
~service:"/srv/factotum"
~old_name:"/mnt/factotum"
~spec:"factotum" ();
Bind.bind ~flags:[ "-q" ]
~new_name:"/mnt/factotum/factotum"
~old_name:"/mnt/factotum"
The code works in that I have booted plan9 with it (boot_cpu_main.ml) and the system is apparently usable.
This is currently intended as an exploratory proof-of-concept.
A sort of experiment in what it’s like to use ocaml on plan9 instead of rc.
Here’s a post about the port of ocaml to plan9 that was used for this experiment:
Ed