Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,66 @@ jobs:
set -e
grep -q 'uefi ok: \[1, 2, 3\] \["one", "two three", "a b"\]' run.log || { echo "::error::the application's output or arguments"; exit 1; }
grep -q 'files: true' run.log || { echo "::error::a file was not renamed or a listing shortened its name (release profile)"; exit 1; }
# A start of a program (0.32.0, openkal-uefi 0.13.0): LoadImage and StartImage.
grep -q 'starts: child 3' run.log || { echo "::error::the application did not start itself and read its status"; exit 1; }
[ "$status" -eq 42 ] || { echo "::error::the application returned $status, not 42"; exit 1; }
p=$(find target/x86_64-uefi -path '*bin/uefi.efi' -type f | head -1)
file "$p"
file "$p" | grep -q 'PE32+' && file "$p" | grep -q 'EFI application' \
|| { echo "::error::x86_64-uefi is not a PE32+ EFI application"; exit 1; }

# THE MACHINE WITH NO OPERATING SYSTEM ABOVE RISC-V SBI (0.32.0): `riscv64-none-musl', a C program
# and a C++ program that throws and catches, built over openkal-opensbi and run by QEMU's `virt'
# with OpenSBI; each status leaves the machine through its test finisher. A row a platform defines
# with no system is read by mcpp from the release after 2026.11.22.1 (mcpp-community/mcpp#1006),
# which MCPP_SOURCE_REF names until it is released.
sbi:
needs: resolves
name: riscv64-none-musl (built on Linux x86_64, run under QEMU virt with OpenSBI)
runs-on: ubuntu-24.04
timeout-minutes: 90
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4

- uses: mcpp-community/setup-mcpp@v1
with:
version: ${{ env.MCPP_VERSION }}
xlings-version: ${{ env.XLINGS_VERSION }}

- name: The mcpp under cross-validation
run: |
[ -n "${MCPP_SOURCE_REF:-}" ] || exit 0
src="$RUNNER_TEMP/mcpp-src"
git clone --quiet --depth 1 --branch "$MCPP_SOURCE_REF" https://github.com/mcpp-community/mcpp.git "$src"
rm -f "$src/.xlings.json"
( cd "$src" && mcpp build --release )
built=$(find "$src/target" -type f -name mcpp -path '*/bin/*' | head -1)
[ -n "$built" ] || { echo "::error::mcpp did not build from $MCPP_SOURCE_REF"; exit 1; }
echo "$(cd "$(dirname "$built")" && pwd)" >> "$GITHUB_PATH"
echo "under review: $("$built" --version) (from $MCPP_SOURCE_REF)"

- name: A C program and a C++ program that throws, on the machine
working-directory: checks/sbi
run: |
mcpp --version
for p in sbi-c:7 sbi-cxx:9; do
bin=${p%%:*}; want=${p##*:}
set +e
timeout 600 mcpp run "$bin" --target riscv64-none-musl | tee "$bin.log"
status=${PIPESTATUS[0]}
set -e
[ "$status" -eq "$want" ] || { echo "::error::$bin ended with $status, not $want"; exit 1; }
done
grep -q 'sbi c: a mebibyte allocated, the clock advances' sbi-c.log || { echo "::error::the C program's output"; exit 1; }
grep -q 'sbi cxx: \["alpha", "mu", "zeta"\]' sbi-cxx.log && grep -q 'caught: across frames, 3 unwound' sbi-cxx.log \
|| { echo "::error::the C++ program's output, or its exception"; exit 1; }
p=$(find target/riscv64-none-musl -path '*bin/sbi-cxx' -type f | head -1)
file "$p"
file "$p" | grep -q 'ELF 64-bit LSB executable, UCB RISC-V' || { echo "::error::not a RISC-V executable"; exit 1; }

# I686-OPENKAL (0.28.0): the ok image of i386 (ELF32, REL), built from
# checks/i386 in both modes, checked by okld, and run by okrun built for
# i686-linux-musl from the openkal-image release this group names.
Expand Down Expand Up @@ -389,6 +443,18 @@ jobs:
[ "$status" -eq 7 ] || { echo "::error::the image returned $status, not 7 ($mode)"; exit 1; }
done

# The row's runner is the carrier, packed by mcpp (0.31.3, openkal-image#46): an
# image that starts itself is entered through the carrier as its loader.
- name: An image starts itself through the row's runner
working-directory: checks/starts
run: |
set +e
mcpp run --target i686-openkal | tee run.log
status=${PIPESTATUS[0]}
set -e
[ "$status" -eq 0 ] && grep -qx 'starts: child 3' run.log \
|| { echo "::error::an i386 image's start of itself through the carrier (status $status)"; exit 1; }

# System V Release 4 on i386 (0.30.0): a program of i686-svr4-musl (openkal-musl
# over openkal-svr4) built in both modes and run by the provider's runner,
# ibcs-us in a user namespace; then the same executable under the two other
Expand Down Expand Up @@ -494,6 +560,7 @@ jobs:
grep -q 'dos ok: \["one", "two"\]' run.log && grep -q 'caught: across a frame' run.log \
&& grep -q 'deep: 2080' run.log \
&& grep -q 'files: true' run.log \
&& grep -q 'starts: child 3' run.log \
|| { echo "::error::the DOS program's output ($mode)"; exit 1; }
[ "$status" -eq 7 ] || { echo "::error::the DOS program returned $status, not 7 ($mode)"; exit 1; }
done
Expand Down
64 changes: 60 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,29 @@ builds openkal-run's core runner as a program of the DOS row below, with the
image in its `.oke` section. Measured under DOSBox Staging: the image sorted its
arguments, caught its exception, read DOS's `PATH` and returned 7.

Platform 0.32.0 is a minor release of the group. A program of the firmware and
of DOS starts programs: openkal-uefi 0.13.0 provides `openkal.process` through
`LoadImage` and `StartImage`, and openkal-dos and openkal-dos-tools 0.3.0
through EXEC, each a started program run to its end before the start returns
(openkal clause 7.19), so `x86_64-uefi` and `i686-dos-musl` state the interface
and a program's `posix_spawn` and `waitpid` start and wait for a program there.
openkal-musl 0.30.1 names them. openkal-windows 0.23.1: a program without
memory for its arguments and variables ends with that reason. `checks/uefi` and
`checks/dos` start themselves through the rows' runners in CI and read the
status 3. A row is added for a machine with no operating system above RISC-V SBI
firmware, `riscv64-none-musl` (below), with openkal-opensbi 0.10.1 joining the
group. It holds 0.31.3's member, openkal-image 0.7.3.

Platform 0.31.3 is a patch of the group with one member. openkal-image 0.7.3:
okrun's command line is a function of the runner (`okrun_main`), and the
carrier, as a package's runner, is that function, so it names itself the
loader through which an image's start of an image file goes. Under 0.31.2 the
carrier named no loader: on `i686-openkal`, whose runner is the carrier, an
image that started an image was refused (`ENOEXEC` from `posix_spawn`, status
127 in a copy that called exec; openkal-image#46). `checks/starts` starts
itself on that row in CI. The carrier and the tools are 0.7.3. No other member
changes.

Platform 0.31.2 is a patch of the group with one member. openkal-image 0.7.2: a
copy of the program ends as the copy ends itself. A library composes `fork` by
starting a context in a copy of the address space (openkal.space); the copy
Expand Down Expand Up @@ -230,7 +253,7 @@ until a project or this machine does:

```toml
[target.x86_64-freebsd-musl]
platform = "openkal-platform@0.31.2"
platform = "openkal-platform@0.32.0"
runner = { enabled = true }
```

Expand Down Expand Up @@ -333,6 +356,39 @@ own openkal implementation (`checks/hosted`). `[host] platform` selects it for
the host graph: build programs are then compiled as ok images of the machine's
architecture and run by okrun (`checks/host-graph`).

## A machine with no operating system, above RISC-V SBI (0.32.0)

`riscv64-none-musl` is a row this platform defines and serves: a program that
OpenSBI starts on a RISC-V machine, on the same C library and C++ run-time over
openkal-opensbi, so it is written in C or in C++23 with `import std`.

```toml
[target.riscv64-none-musl]
platform = "openkal-platform@0.32.0"
runner = { enabled = true }
```

```sh
mcpp run --target riscv64-none-musl # QEMU's virt with the OpenSBI it bundles; the status comes back
```

The row is the family's row with no system (`cfg(os = "none")`): what
openkal-musl and openkal-llvm-runtime state for a machine with no operating
system applies, among it the unwinder that finds its tables through the symbols
the linker script defines, since the program headers lie below the address the
firmware enters and are not loaded. openkal-opensbi supplies the entry, the
memory map (`board.ld`: the image at 0x80200000, a stack and a heap past it) and
the console. The machine description is the built-in `riscv64-none-elf` row's:
RV64GC, LP64D, the medium-any code model. A program's status leaves the machine
through the test finisher its device tree describes (openkal-opensbi 0.10.1);
SBI gives a program no arguments, and it receives none. The runner (xim's
`qemu-riscv`) boots a machine and is enabled by the project. An engine reads a
row a platform defines with no system from the release after mcpp 2026.11.22.1.

`checks/sbi` runs in CI: a C program allocates, reads the clock and ends with 7;
a C++ program sorts, throws across three frames with a destructor in each and
catches, and ends with 9.

## UEFI applications (0.28.0)

`x86_64-uefi` is a row this platform defines and serves (`[[platform.define]]`,
Expand All @@ -342,7 +398,7 @@ with `import std`:

```toml
[target.x86_64-uefi]
platform = "openkal-platform@0.31.2"
platform = "openkal-platform@0.32.0"
runner = { enabled = true }
```

Expand Down Expand Up @@ -378,7 +434,7 @@ and C++ run-time over openkal-svr4, so it is written in C++23 with `import std`:

```toml
[target.i686-svr4-musl]
platform = "openkal-platform@0.31.2"
platform = "openkal-platform@0.32.0"
runner = { enabled = true }
```

Expand Down Expand Up @@ -432,7 +488,7 @@ run-time over openkal-dos, so it is written in C++23 with `import std`:

```toml
[target.i686-dos-musl]
platform = "openkal-platform@0.31.2"
platform = "openkal-platform@0.32.0"
```

The row is TECHNICAL EXPERIMENT ONLY (openkal-dos's README). A program is the
Expand Down
19 changes: 8 additions & 11 deletions carrier/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
// `mcpp_carried_end`, and its name at `mcpp_carried_name`:
//
// nothing the program is a package's runner
// (`libexec/okrun/<os>-<arch>/okrun`): it runs the image, or the
// okb, its first argument names, as okrun does;
// (`libexec/okrun/<os>-<arch>/okrun`): it is okrun's command
// line (okrun_main, openkal-run 0.7.3), and so the loader an
// image's start of an image file goes through;
// a zip the images of a program (a single file): the entry and the
// images it needs run from memory, nothing written to disk;
// an image the image runs from memory, as its own program (M3).
Expand All @@ -20,15 +21,11 @@ int main(int argc, char** argv) {
okrun_options options{};
const auto size = static_cast<unsigned long long>(mcpp_carried_end - mcpp_carried_begin);
const auto args = const_cast<const char* const*>(argv);
if (size == 0) {
if (argc < 2) {
std::fprintf(stderr, "usage: %s <image|okb> [arguments...]\n", argv[0]);
return 2;
}
okrun_run_file(argv[1], argc - 1, args + 1, &options, why, sizeof why);
std::fprintf(stderr, "%s: %s\n", argv[1], why);
return 127;
}
// A RUNNER NAMES ITSELF THE LOADER (0.31.3, openkal-image#46). With default
// options it named none, and an image's start of an image file was refused:
// on i686-openkal, whose runner this is, `posix_spawn` of the image itself
// gave ENOEXEC, and a copy that called exec ended with 127.
if (size == 0) return okrun_main(argc, argv);
options.carried = 1; // the program is the image's name, and what starts it again
if (size >= 4 && std::memcmp(mcpp_carried_begin, "PK\x03\x04", 4) == 0)
okrun_run_okb_bytes(mcpp_carried_begin, size, mcpp_carried_name, argc, args, &options,
Expand Down
19 changes: 19 additions & 0 deletions checks/dos/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
// (0.29.1, `-z stack-size'), which openkal-dos 0.1.1's stub reads from PT_GNU_STACK.
import std;

#include <spawn.h>
#include <sys/wait.h>

extern "C" char** environ;

int deep(int n) {
volatile char frame[8192];
frame[0] = static_cast<char>(n);
Expand Down Expand Up @@ -33,7 +38,20 @@ bool files() {
return names == std::vector<std::string>{"g1.txt"};
}

// A START OF A PROGRAM (0.32.0): the program starts itself by posix_spawn with `child', which ends
// with 3, and waitpid reads the status; the row's implementation provides openkal.process, a
// started program run to its end before the start returns (openkal clause 7.19).
int starts(const char* self) {
pid_t pid;
char* args[] = {const_cast<char*>(self), const_cast<char*>("child"), nullptr};
if (posix_spawn(&pid, self, nullptr, nullptr, args, environ) != 0) return -1;
int status = 0;
if (waitpid(pid, &status, 0) != pid) return -2;
return WIFEXITED(status) ? WEXITSTATUS(status) : -3;
}

int main(int argc, char** argv) {
if (argc >= 2 && std::string_view(argv[1]) == "child") return 3;
std::vector<std::string> v(argv + 1, argv + argc);
std::ranges::sort(v);
std::println("dos ok: {}", v);
Expand All @@ -42,5 +60,6 @@ int main(int argc, char** argv) {
std::println("PATH set: {}", std::getenv("PATH") != nullptr);
std::println("deep: {}", deep(64));
std::println("files: {}", files());
std::println("starts: child {}", starts(argv[0]));
return 7;
}
19 changes: 19 additions & 0 deletions checks/sbi/mcpp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# The machine with no operating system above RISC-V SBI (0.32.0): a C program and a C++ program
# that throws and catches, on the family's C library and C++ run-time over openkal-opensbi, run by
# QEMU's `virt' with OpenSBI. The platform is the directory above.
[package]
name = "sbi"
version = "0.1.0"

[targets.sbi-c]
kind = "bin"
main = "src/c.c"

[targets.sbi-cxx]
kind = "bin"
main = "src/cxx.cpp"

[target.riscv64-none-musl]
platform = { path = "../.." }
# The runner boots a machine and is enabled by the project (0.29.0).
runner = { enabled = true }
17 changes: 17 additions & 0 deletions checks/sbi/src/c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* C on the machine: the console, the allocator, the clock, and a status the machine ends with. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main(void) {
char* p = malloc(1 << 20);
if (p) memset(p, 1, 1 << 20);
struct timespec a, b;
clock_gettime(CLOCK_MONOTONIC, &a);
clock_gettime(CLOCK_MONOTONIC, &b);
printf("sbi c: %s, the clock %s\n", p ? "a mebibyte allocated" : "no memory",
(b.tv_sec > a.tv_sec || b.tv_nsec >= a.tv_nsec) ? "advances" : "runs back");
free(p);
return 7;
}
21 changes: 21 additions & 0 deletions checks/sbi/src/cxx.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// C++23 on the machine: `import std', containers and ranges, an exception thrown across frames and
// caught with a destructor run on the way, and a status the machine ends with.
import std;

namespace {
int unwound = 0;
struct guard { ~guard() { ++unwound; } };
[[gnu::noinline]] void thrower(int depth) {
guard g;
if (depth == 0) throw std::runtime_error("across frames");
thrower(depth - 1);
}
} // namespace

int main() {
std::vector<std::string> v{"zeta", "alpha", "mu"};
std::ranges::sort(v);
std::println("sbi cxx: {}", v);
try { thrower(2); } catch (const std::exception& e) { std::println("caught: {}, {} unwound", e.what(), unwound); }
return 9;
}
13 changes: 13 additions & 0 deletions checks/starts/mcpp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# An image that starts itself (0.31.3, openkal-image#46): built for i686-openkal and run by the
# row's runner, the carrier as its package's runner, which names itself the loader of an
# image's start of an image file. The platform is the directory above.
[package]
name = "starts"
version = "0.1.0"

[targets.starts]
kind = "bin"
main = "src/main.c"

[target.i686-openkal]
platform = { path = "../.." }
20 changes: 20 additions & 0 deletions checks/starts/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Started with no argument, the image starts itself with `child' by posix_spawn and
* writes the child's status; started with `child', it ends with 3. */
#include <spawn.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>

extern char** environ;

int main(int argc, char** argv) {
if (argc > 1 && strcmp(argv[1], "child") == 0) return 3;
pid_t pid;
char* args[] = { argv[0], "child", NULL };
const int rc = posix_spawn(&pid, argv[0], NULL, NULL, args, environ);
if (rc != 0) { printf("starts: posix_spawn %d\n", rc); return 1; }
int status = 0;
if (waitpid(pid, &status, 0) != pid) { printf("starts: waitpid\n"); return 1; }
printf("starts: child %d\n", WIFEXITED(status) ? WEXITSTATUS(status) : -1);
return 0;
}
Loading
Loading