Project:LoongArch

Article description::The LoongArch Development Project is an effort to bring first-class support for the LoongArch CPU architecture (龙架构; 龍架構; Lóng-jiàgòu; 'Loong Architecture') to Gentoo. Because this is such a new platform with many fundamental pieces of software still under development, we also strive to make Gentoo/LoongArch the ideal testing ground for the wider community, so as to minimize the risk of overlooked mistakes going upstream.

Basic facts

 * We are . We don't use stable keywords for the moment.
 * Target tuple is loongarch64-unknown-linux-gnu. (Official spec says the LP64D ABI is loongarch64-unknown-linux-gnuf64, at least for Debian, but loongarch64-unknown-linux-gnu without the suffix behaves the same for compatibility and aesthetics.)
 * All LoongArch systems are little-endian.
 * LoongArch is not binary compatible with either MIPS or RISC-V, although the ISA and ABI show heavy influence of the two.
 * There are six ABIs defined for LoongArch, much like those of RISC-V. But for Gentoo, we intend to focus on LP64D only first. Multilib support will come later if truly necessary.

Binary compatibility with other distros
Gentoo/LoongArch belongs to the new world, just like any other properly open-sourced community distribution for LoongArch.

This does mean that all current commercial/closed-source offerings for LoongArch are unusable on Gentoo, such as Kingsoft Office (WPS Office) or LATX (Loongson Architecture Translator for X86; the Loongson binary translation solution allegedly based on QEMU and Wine but not open-source, supporting a subset of Windows applications and games), which are all compiled on, and for commercial distributions like Loongnix (pseudo-open-source), Kylin and UOS, that are the collective old world.

The two worlds differ both in kernel and user-space ABIs, so neither mixing-and-matching of binaries and libraries, nor full-fledged chroots will work. One consequence is that one has to pay attention to the flavor of live media used for installation or system rescue purposes; in particular, only new-world distributions can be used for bootstrapping Gentoo.

There are a few currently known new-world distributions:


 * Arch Linux LoongArch] by WU Xiaotian,
 * CLFS for LoongArch by SUN Haiyong,
 * LoongArch Slackware] by SHI Pujin.

Status
Everything mostly works as of Oct 2022. Software-accelerated GUI (llvmpipe) and AMD discrete graphics work with bleeding-edge LLVM 16, while support for the LS7A integrated graphics is not upstream yet.

LiveCD used to work but was reported to have initrd problems, and is not currently officially produced. In the meantime, any other new-world boot media can be used to install Gentoo.

Official stage tarballs are available from releng at the official Gentoo mirrors.

Profiles and initial sets of keywords sufficient for building stage3 are already upstreamed as of 2022-04-29, further keywording work will primarily happen in ::gentoo. The loongson-overlay remains available for general experimentation.

State of important non-upstreamed packages
While most of the fundamental software already has LoongArch support, there are still some patches floating around, waiting for the respective upstream to pick up. For the Gentoo builds, the more intrusive ones are only applied when USE=experimental-loong, force-enabled on loong while being masked on other arches. The other safer patches are applied unconditionally.

The table lists the known-good versions for packages that still haven't merged LoongArch support. Status for other packages are simply represented with the proper keyword (i.e. ~loong).

Trying out the stages
It's of course best to have actual LoongArch hardware to play with; any model will do, as currently there is only one hardware implementation of LoongArch that is the 3A5000. There are many form factors available, from laptops and MATX boards to rack-mounted servers, but it can be hard to purchase outside of China right now.

Fortunately, there is working QEMU support for both linux-user and system emulation starting from QEMU 7.1.0. Just enable the loongarch64 target then:

binfmt_misc configuration for both OpenRC and systemd should be automatically generated and installed. Afterwards just chroot like with any other Gentoo installation.

Cross-compiling for LoongArch
can be used to conveniently make LoongArch cross toolchains, just make sure you're using up-to-date crossdev:

You may optionally pin the versions for the various components to your liking, or in case you see failures.

External resources

 * The unofficial yet comprehensive FAQ for LoongArch by xen0n
 * Unofficial collection of various Loongson docs by the community (not all of them are LoongArch-related)
 * The official LoongArch documentation by Loongson

Historical stages are still available at several Chinese mirrors:


 * hosted by Aliyun (Alibaba Cloud; 阿里云; 阿里雲)
 * hosted by Tencent Cloud (腾讯云; 騰訊雲)
 * hosted by Tsinghua University (清华大学; 清華大學)
 * hosted by Beijing Foreign Studies University (北京外国语大学; 北京外國語大學)
 * hosted by University of Science and Technology of China (中国科学技术大学; 中國科學技術大學)