Gentoo Archives: gentoo-dev

From: WANG Xuerui <i.gentoo@×××××.name>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] [RFC] Plans for a Gentoo/LoongArch port
Date: Wed, 11 Aug 2021 16:39:43
Message-Id: b008ca13-896a-0a8f-3e9d-1be07cdd65d4@xen0n.name
1 Hi everyone,
2
3 I'm your average Gentoo user who obviously thought his sleeping time is more
4 than enough, and just decided to start porting Gentoo to LoongArch. As this
5 is such a niche architecture with no upstreamed support so far, I'm posting
6 this to announce my intent and gather advice on how to best push this.
7
8 I'll first give some background material to help people gain context, then
9 describe my porting plan. This is going to be a bit long; apologizes for
10 that.
11
12
13 Note: I'm not affiliated with Loongson in any way; I'm just doing this in my
14 spare time (once meant for some quality sleep).
15
16
17 ## A bit of introduction on the LoongArch
18
19 LoongArch, as its name implies, is the brand-new ISA developed by the
20 Loongson Corporation, incompatible with MIPS which was implemented by
21 all previous Loongson processors. Currently only the base ISA specification
22 is publicly available; it has fixed-length 32-bit instructions, vastly more
23 instruction formats (39 distinct formats in the base ISA alone!), and its
24 instruction semantics mostly resemble RISC-V, with a bit of MIPS R6 here and
25 there. It is capable of 64-bit operations, obviously.
26
27 ISA documentation: https://github.com/loongson/LoongArch-Documentation
28 ELF psABI draft: https://github.com/loongson/LoongArch-Documentation/pull/3
29
30 The draft ABI is undergoing fierce review, and is subject to change,
31 especially the relocation types. Other parts like the register
32 convention and
33 data layout is unlikely to change much, though.
34
35 There is little code upstreamed for basic software (GNU toolchain, QEMU,
36 Linux and the like), but many are open-sourced already. Nevertheless, the
37 code quality is still very much inferior, and much of it is obviously based
38 on respective MIPS support. There is continuous debate inside and outside
39 Loongson on this matter, too.
40
41 Kernel ABI and glibc code seems to be inspired by RISC-V, but still some
42 parts show MIPS heritage. The kernel bits are being reviewed on the
43 linux-arch
44 mailing list.
45
46 All of the projects above can be accessed at https://github.com/loongson.
47
48 Loongson 3A5000 is the first LoongArch CPU; the Lemote A2101 board with this
49 CPU can be bought in China for ~4000 CNY already.
50
51
52 ## Gentoo porting plans
53
54 I'm planning to take ARCH=loongarch for the port; and support the LP64 ABI
55 first. I'd like to support both LP64 and ILP32 ABIs, but that's not a
56 priority.
57
58 The ABI flag might be named "ABI_LOONGARCH" but that's IMO a bit long (pun
59 semi-intended); ARCH=loong and ABI_LOONG might be better, I'm open to
60 suggestions.
61
62 Because much of the ABI and even some toolchain internals are going through
63 VERY fierce debate and rework, obviously the port will remain experimental
64 for a long time. Some minimal support should get in tree though; doing so
65 would ease a lot of pain for experimentation. I already hacked my way to
66 generate working crossdev toolchains, and is halfway towards a rootfs with
67 working Python (and Portage). I've already independently ported strace, and
68 plan to do the same to libffi in the coming days which would give me Python.
69
70 I'll do all work in my own loongson-overlay first, and upstream these when
71 appropriate. Eventually I hope to have working crossdev, qemu-user emulation
72 and proper catalyst support.
73
74
75 And that's about all; the message is getting long! Your opinions are
76 welcome,
77 and thanks again for following along.
78
79
80 Regards,
81 WANG "xen0n" Xuerui

Replies