Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of cross-compilation to Knuth's MMIX #102766

Merged
merged 1 commit into from Nov 14, 2020

Conversation

siraben
Copy link
Member

@siraben siraben commented Nov 4, 2020

Motivation for this change

Let's make Nix one of the first Linux package managers to have cross-compile support for MMIX!

The following command cross-builds GNU Hello and runs it in Knuth's mmixware simulator for MMIX showing that indeed it works.

$ nix-shell -E 'with import ./. { }; runCommand "" { buildInputs = [ pkgsCross.mmix.hello mmixware ]; } ""' \                            
            --run 'mmix $(which hello)'
Hello, world!

Some variations I'm trying (failed ones are strikethroughed)

  • mmix-unknown-mmixware libc = newlib
  • mmix-unknown-linux-uclib
  • mmix-unknown-elf
  • mmix-none-elf
  • mmix-elf
  • mmix

Looks like we will only be able to use newlib, as it has mmixware support.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@siraben siraben changed the title Initial implementation of cross-compilation of Knuth's MMIX Initial implementation of cross-compilation to Knuth's MMIX Nov 4, 2020
@veprbl veprbl added the 6.topic: cross-compilation Building packages on a different sort platform than than they will be run on label Nov 4, 2020
@SuperSandro2000
Copy link
Member

Result of nixpkgs-review pr 102766 run on x86_64-linux 1

1 package built:
  • mmixware

lib/systems/parse.nix Outdated Show resolved Hide resolved
@Ericson2314
Copy link
Member

Ericson2314 commented Nov 5, 2020

There are these two nones left over. Note you will also need to make mmixware a "kernel". (We should really rename "kernel" to something better!!)

@siraben
Copy link
Member Author

siraben commented Nov 5, 2020

Where's the two nones? I found one in doubles.nix (answered on IRC)

@vikanezrimaya
Copy link
Member

Please clarify: can this architecture run the Linux kernel or is it just bare-metal for now?

@siraben
Copy link
Member Author

siraben commented Nov 5, 2020

Currently bare metal. I'll adjust the top comment with variations tried.

@siraben
Copy link
Member Author

siraben commented Nov 5, 2020

It appears possible to boot a patched Linux kernel, see http://mmix.cs.hm.edu/examples/Linux/index.html

Copy link
Member

@vikanezrimaya vikanezrimaya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unable to reproduce the nix-shell example above. Maybe I'm doing something wrong?

pkgs/development/tools/mmixware/default.nix Outdated Show resolved Hide resolved
pkgs/development/tools/mmixware/default.nix Outdated Show resolved Hide resolved
@siraben
Copy link
Member Author

siraben commented Nov 5, 2020

@kisik21 Please try again.

@vikanezrimaya
Copy link
Member

@siraben yay, it's compiling!

@siraben
Copy link
Member Author

siraben commented Nov 5, 2020

@Ericson2314 I added this target locally, and it works.

  mmix-embedded = {
    config = "mmix";
    libc = "newlib";
  };

However GNU hello's diff seems to be very small. Are they really different targets?

diff --git a/hello_mmixware.txt b/hello_mmixware-embedded.txt
index 99e4e08..0ca8e94 100644
--- a/hello_mmixware.txt
+++ b/hello_mmixware-embedded.txt
@@ -1,4 +1,4 @@
-00000000: 9809 0101 5fa2 a96c 9801 0002 0000 0000  ...._..l........
+00000000: 9809 0101 5fa3 ea56 9801 0002 0000 0000  ...._..V........
 00000010: 0000 0100 6000 0000 0000 0000 0000 0000  ....`...........
 00000020: 0002 9758 0000 0000 0002 983c 2000 0000  ...X.......< ...
 00000030: 0000 0000 2000 0000 0000 1480 e3ff 0020  .... .......... 

Copy link
Member

@vikanezrimaya vikanezrimaya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built and run the provided example successfully!

@vikanezrimaya
Copy link
Member

It looks like ./lib/tests/release.nix needs updating to not see the new architecture as an error.

@siraben
Copy link
Member Author

siraben commented Nov 5, 2020

Looks like

It looks like ./lib/tests/release.nix needs updating to not see the new architecture as an error.

What do you mean by this?

@vikanezrimaya
Copy link
Member

$ nix-build --arg pkgs 'import ./. {}' ./lib/tests/release.nix
warning: unknown setting 'extra-sandbox-paths'
error: --- ThrownError ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ nix-build
[{"expected":["aarch64-darwin","aarch64-genode","aarch64-linux","aarch64-none","arm-none","armv5tel-linux","armv6l-linux","armv6l-none","armv7a-darwin","armv7a-linux","armv7l-linux","avr-none","i686-cygwin","i686-darwin","i686-freebsd","i686-genode","i686-linux","i686-netbsd","i686-none","i686-openbsd","i686-windows","js-ghcjs","mipsel-linux","msp430-none","powerpc-none","powerpc64le-linux","riscv32-linux","riscv32-none","riscv64-linux","riscv64-none","vc4-none","wasm32-wasi","wasm64-wasi","x86_64-cygwin","x86_64-darwin","x86_64-freebsd","x86_64-genode","x86_64-linux","x86_64-netbsd","x86_64-none","x86_64-openbsd","x86_64-redox","x86_64-solaris","x86_64-windows"],"name":"testall","result":["aarch64-darwin","aarch64-genode","aarch64-linux","aarch64-none","arm-none","armv5tel-linux","armv6l-linux","armv6l-none","armv7a-darwin","armv7a-linux","armv7l-linux","avr-none","i686-cygwin","i686-darwin","i686-freebsd","i686-genode","i686-linux","i686-netbsd","i686-none","i686-openbsd","i686-windows","js-ghcjs","mipsel-linux","mmix-mmixware","msp430-none","powerpc-none","powerpc64le-linux","riscv32-linux","riscv32-none","riscv64-linux","riscv64-none","vc4-none","wasm32-wasi","wasm64-wasi","x86_64-cygwin","x86_64-darwin","x86_64-freebsd","x86_64-genode","x86_64-linux","x86_64-netbsd","x86_64-none","x86_64-openbsd","x86_64-redox","x86_64-solaris","x86_64-windows"]}]

Passing that through jq '.[0].result - .[0].expected' gets me ["mmix-mmixware"] - it means that the lib test suite doesn't expect to see the new double in the list of available doubles.

@ehmry ehmry added the 6.topic: exotic Exotic hardware or software platform label Nov 6, 2020
@SuperSandro2000
Copy link
Member

Result of nixpkgs-review pr 102766 run on x86_64-darwin 1

1 package built:
  • mmixware

@siraben
Copy link
Member Author

siraben commented Nov 7, 2020

@kisik21 I'm not sure what files I have to change to resolve that error.

@FRidh
Copy link
Member

FRidh commented Nov 8, 2020

You need to add the new arch to lib/tests/systems.nix. I suggest having a look at the file's log, because this issue happened more often when new architectures were added.

@Ericson2314
Copy link
Member

@kisik21

Please clarify: can this architecture run the Linux kernel or is it just bare-metal for now?

The simulator supports some basic system calls. So it's like having a basic OS that just read writes out to serial ports or something.

Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@Ericson2314 Ericson2314 merged commit 86fedc3 into NixOS:master Nov 14, 2020
@siraben siraben deleted the mmix branch November 14, 2020 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants