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:


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

Status
Everything mostly works except the GUI (no upstream LLVM support = no AMDGPU support = no discrete graphics; support for the LS7A integrated graphics is not upstream), but serial console and networking works perfectly.

LiveCD used to work but is reported to have initrd problems; in the meantime, any other new-world boot media can be used to install Gentoo.

Stage tarballs are currently built on a semi-regular basis by xen0n, and available on 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 packages
Because the architecture is still in its infancy, LoongArch support for many essential packages is still missing from upstream, aggravated by the fact that Loongson has not much experience in developing and upstreaming a brand-new architecture like this (and limited English communication abilities). Hence, many packages require patching to work on LoongArch; the more intrusive patches are only applied when USE=experimental-loong, force-enabled on loong while being masked on other arches. The other safer patches are applied unconditionally.

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 linux-user emulation, provided by the app-emulation/qemu package in ::loongson. Just enable the loongarch64 target:

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

System emulation support for LoongArch is present in this forked qemu version, but is too buggy to be usable. The package will be updated in ::loongson once the situation improves.

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 if 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 (中国科学技术大学; 中國科學技術大學)