162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci========================= 462306a36Sopenharmony_ciIntroduction to LoongArch 562306a36Sopenharmony_ci========================= 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciLoongArch is a new RISC ISA, which is a bit like MIPS or RISC-V. There are 862306a36Sopenharmony_cicurrently 3 variants: a reduced 32-bit version (LA32R), a standard 32-bit 962306a36Sopenharmony_civersion (LA32S) and a 64-bit version (LA64). There are 4 privilege levels 1062306a36Sopenharmony_ci(PLVs) defined in LoongArch: PLV0~PLV3, from high to low. Kernel runs at PLV0 1162306a36Sopenharmony_ciwhile applications run at PLV3. This document introduces the registers, basic 1262306a36Sopenharmony_ciinstruction set, virtual memory and some other topics of LoongArch. 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ciRegisters 1562306a36Sopenharmony_ci========= 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ciLoongArch registers include general purpose registers (GPRs), floating point 1862306a36Sopenharmony_ciregisters (FPRs), vector registers (VRs) and control status registers (CSRs) 1962306a36Sopenharmony_ciused in privileged mode (PLV0). 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ciGPRs 2262306a36Sopenharmony_ci---- 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ciLoongArch has 32 GPRs ( ``$r0`` ~ ``$r31`` ); each one is 32-bit wide in LA32 2562306a36Sopenharmony_ciand 64-bit wide in LA64. ``$r0`` is hard-wired to zero, and the other registers 2662306a36Sopenharmony_ciare not architecturally special. (Except ``$r1``, which is hard-wired as the 2762306a36Sopenharmony_cilink register of the BL instruction.) 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ciThe kernel uses a variant of the LoongArch register convention, as described in 3062306a36Sopenharmony_cithe LoongArch ELF psABI spec, in :ref:`References <loongarch-references>`: 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci================= =============== =================== ============ 3362306a36Sopenharmony_ciName Alias Usage Preserved 3462306a36Sopenharmony_ci across calls 3562306a36Sopenharmony_ci================= =============== =================== ============ 3662306a36Sopenharmony_ci``$r0`` ``$zero`` Constant zero Unused 3762306a36Sopenharmony_ci``$r1`` ``$ra`` Return address No 3862306a36Sopenharmony_ci``$r2`` ``$tp`` TLS/Thread pointer Unused 3962306a36Sopenharmony_ci``$r3`` ``$sp`` Stack pointer Yes 4062306a36Sopenharmony_ci``$r4``-``$r11`` ``$a0``-``$a7`` Argument registers No 4162306a36Sopenharmony_ci``$r4``-``$r5`` ``$v0``-``$v1`` Return value No 4262306a36Sopenharmony_ci``$r12``-``$r20`` ``$t0``-``$t8`` Temp registers No 4362306a36Sopenharmony_ci``$r21`` ``$u0`` Percpu base address Unused 4462306a36Sopenharmony_ci``$r22`` ``$fp`` Frame pointer Yes 4562306a36Sopenharmony_ci``$r23``-``$r31`` ``$s0``-``$s8`` Static registers Yes 4662306a36Sopenharmony_ci================= =============== =================== ============ 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci.. Note:: 4962306a36Sopenharmony_ci The register ``$r21`` is reserved in the ELF psABI, but used by the Linux 5062306a36Sopenharmony_ci kernel for storing the percpu base address. It normally has no ABI name, 5162306a36Sopenharmony_ci but is called ``$u0`` in the kernel. You may also see ``$v0`` or ``$v1`` 5262306a36Sopenharmony_ci in some old code,however they are deprecated aliases of ``$a0`` and ``$a1`` 5362306a36Sopenharmony_ci respectively. 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ciFPRs 5662306a36Sopenharmony_ci---- 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ciLoongArch has 32 FPRs ( ``$f0`` ~ ``$f31`` ) when FPU is present. Each one is 5962306a36Sopenharmony_ci64-bit wide on the LA64 cores. 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ciThe floating-point register convention is the same as described in the 6262306a36Sopenharmony_ciLoongArch ELF psABI spec: 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci================= ================== =================== ============ 6562306a36Sopenharmony_ciName Alias Usage Preserved 6662306a36Sopenharmony_ci across calls 6762306a36Sopenharmony_ci================= ================== =================== ============ 6862306a36Sopenharmony_ci``$f0``-``$f7`` ``$fa0``-``$fa7`` Argument registers No 6962306a36Sopenharmony_ci``$f0``-``$f1`` ``$fv0``-``$fv1`` Return value No 7062306a36Sopenharmony_ci``$f8``-``$f23`` ``$ft0``-``$ft15`` Temp registers No 7162306a36Sopenharmony_ci``$f24``-``$f31`` ``$fs0``-``$fs7`` Static registers Yes 7262306a36Sopenharmony_ci================= ================== =================== ============ 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci.. Note:: 7562306a36Sopenharmony_ci You may see ``$fv0`` or ``$fv1`` in some old code, however they are 7662306a36Sopenharmony_ci deprecated aliases of ``$fa0`` and ``$fa1`` respectively. 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ciVRs 7962306a36Sopenharmony_ci---- 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ciThere are currently 2 vector extensions to LoongArch: 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci- LSX (Loongson SIMD eXtension) with 128-bit vectors, 8462306a36Sopenharmony_ci- LASX (Loongson Advanced SIMD eXtension) with 256-bit vectors. 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ciLSX brings ``$v0`` ~ ``$v31`` while LASX brings ``$x0`` ~ ``$x31`` as the vector 8762306a36Sopenharmony_ciregisters. 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ciThe VRs overlap with FPRs: for example, on a core implementing LSX and LASX, 9062306a36Sopenharmony_cithe lower 128 bits of ``$x0`` is shared with ``$v0``, and the lower 64 bits of 9162306a36Sopenharmony_ci``$v0`` is shared with ``$f0``; same with all other VRs. 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ciCSRs 9462306a36Sopenharmony_ci---- 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ciCSRs can only be accessed from privileged mode (PLV0): 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci================= ===================================== ============== 9962306a36Sopenharmony_ciAddress Full Name Abbrev Name 10062306a36Sopenharmony_ci================= ===================================== ============== 10162306a36Sopenharmony_ci0x0 Current Mode Information CRMD 10262306a36Sopenharmony_ci0x1 Pre-exception Mode Information PRMD 10362306a36Sopenharmony_ci0x2 Extension Unit Enable EUEN 10462306a36Sopenharmony_ci0x3 Miscellaneous Control MISC 10562306a36Sopenharmony_ci0x4 Exception Configuration ECFG 10662306a36Sopenharmony_ci0x5 Exception Status ESTAT 10762306a36Sopenharmony_ci0x6 Exception Return Address ERA 10862306a36Sopenharmony_ci0x7 Bad (Faulting) Virtual Address BADV 10962306a36Sopenharmony_ci0x8 Bad (Faulting) Instruction Word BADI 11062306a36Sopenharmony_ci0xC Exception Entrypoint Address EENTRY 11162306a36Sopenharmony_ci0x10 TLB Index TLBIDX 11262306a36Sopenharmony_ci0x11 TLB Entry High-order Bits TLBEHI 11362306a36Sopenharmony_ci0x12 TLB Entry Low-order Bits 0 TLBELO0 11462306a36Sopenharmony_ci0x13 TLB Entry Low-order Bits 1 TLBELO1 11562306a36Sopenharmony_ci0x18 Address Space Identifier ASID 11662306a36Sopenharmony_ci0x19 Page Global Directory Address for PGDL 11762306a36Sopenharmony_ci Lower-half Address Space 11862306a36Sopenharmony_ci0x1A Page Global Directory Address for PGDH 11962306a36Sopenharmony_ci Higher-half Address Space 12062306a36Sopenharmony_ci0x1B Page Global Directory Address PGD 12162306a36Sopenharmony_ci0x1C Page Walk Control for Lower- PWCL 12262306a36Sopenharmony_ci half Address Space 12362306a36Sopenharmony_ci0x1D Page Walk Control for Higher- PWCH 12462306a36Sopenharmony_ci half Address Space 12562306a36Sopenharmony_ci0x1E STLB Page Size STLBPS 12662306a36Sopenharmony_ci0x1F Reduced Virtual Address Configuration RVACFG 12762306a36Sopenharmony_ci0x20 CPU Identifier CPUID 12862306a36Sopenharmony_ci0x21 Privileged Resource Configuration 1 PRCFG1 12962306a36Sopenharmony_ci0x22 Privileged Resource Configuration 2 PRCFG2 13062306a36Sopenharmony_ci0x23 Privileged Resource Configuration 3 PRCFG3 13162306a36Sopenharmony_ci0x30+n (0≤n≤15) Saved Data register SAVEn 13262306a36Sopenharmony_ci0x40 Timer Identifier TID 13362306a36Sopenharmony_ci0x41 Timer Configuration TCFG 13462306a36Sopenharmony_ci0x42 Timer Value TVAL 13562306a36Sopenharmony_ci0x43 Compensation of Timer Count CNTC 13662306a36Sopenharmony_ci0x44 Timer Interrupt Clearing TICLR 13762306a36Sopenharmony_ci0x60 LLBit Control LLBCTL 13862306a36Sopenharmony_ci0x80 Implementation-specific Control 1 IMPCTL1 13962306a36Sopenharmony_ci0x81 Implementation-specific Control 2 IMPCTL2 14062306a36Sopenharmony_ci0x88 TLB Refill Exception Entrypoint TLBRENTRY 14162306a36Sopenharmony_ci Address 14262306a36Sopenharmony_ci0x89 TLB Refill Exception BAD (Faulting) TLBRBADV 14362306a36Sopenharmony_ci Virtual Address 14462306a36Sopenharmony_ci0x8A TLB Refill Exception Return Address TLBRERA 14562306a36Sopenharmony_ci0x8B TLB Refill Exception Saved Data TLBRSAVE 14662306a36Sopenharmony_ci Register 14762306a36Sopenharmony_ci0x8C TLB Refill Exception Entry Low-order TLBRELO0 14862306a36Sopenharmony_ci Bits 0 14962306a36Sopenharmony_ci0x8D TLB Refill Exception Entry Low-order TLBRELO1 15062306a36Sopenharmony_ci Bits 1 15162306a36Sopenharmony_ci0x8E TLB Refill Exception Entry High-order TLBEHI 15262306a36Sopenharmony_ci Bits 15362306a36Sopenharmony_ci0x8F TLB Refill Exception Pre-exception TLBRPRMD 15462306a36Sopenharmony_ci Mode Information 15562306a36Sopenharmony_ci0x90 Machine Error Control MERRCTL 15662306a36Sopenharmony_ci0x91 Machine Error Information 1 MERRINFO1 15762306a36Sopenharmony_ci0x92 Machine Error Information 2 MERRINFO2 15862306a36Sopenharmony_ci0x93 Machine Error Exception Entrypoint MERRENTRY 15962306a36Sopenharmony_ci Address 16062306a36Sopenharmony_ci0x94 Machine Error Exception Return MERRERA 16162306a36Sopenharmony_ci Address 16262306a36Sopenharmony_ci0x95 Machine Error Exception Saved Data MERRSAVE 16362306a36Sopenharmony_ci Register 16462306a36Sopenharmony_ci0x98 Cache TAGs CTAG 16562306a36Sopenharmony_ci0x180+n (0≤n≤3) Direct Mapping Configuration Window n DMWn 16662306a36Sopenharmony_ci0x200+2n (0≤n≤31) Performance Monitor Configuration n PMCFGn 16762306a36Sopenharmony_ci0x201+2n (0≤n≤31) Performance Monitor Overall Counter n PMCNTn 16862306a36Sopenharmony_ci0x300 Memory Load/Store WatchPoint MWPC 16962306a36Sopenharmony_ci Overall Control 17062306a36Sopenharmony_ci0x301 Memory Load/Store WatchPoint MWPS 17162306a36Sopenharmony_ci Overall Status 17262306a36Sopenharmony_ci0x310+8n (0≤n≤7) Memory Load/Store WatchPoint n MWPnCFG1 17362306a36Sopenharmony_ci Configuration 1 17462306a36Sopenharmony_ci0x311+8n (0≤n≤7) Memory Load/Store WatchPoint n MWPnCFG2 17562306a36Sopenharmony_ci Configuration 2 17662306a36Sopenharmony_ci0x312+8n (0≤n≤7) Memory Load/Store WatchPoint n MWPnCFG3 17762306a36Sopenharmony_ci Configuration 3 17862306a36Sopenharmony_ci0x313+8n (0≤n≤7) Memory Load/Store WatchPoint n MWPnCFG4 17962306a36Sopenharmony_ci Configuration 4 18062306a36Sopenharmony_ci0x380 Instruction Fetch WatchPoint FWPC 18162306a36Sopenharmony_ci Overall Control 18262306a36Sopenharmony_ci0x381 Instruction Fetch WatchPoint FWPS 18362306a36Sopenharmony_ci Overall Status 18462306a36Sopenharmony_ci0x390+8n (0≤n≤7) Instruction Fetch WatchPoint n FWPnCFG1 18562306a36Sopenharmony_ci Configuration 1 18662306a36Sopenharmony_ci0x391+8n (0≤n≤7) Instruction Fetch WatchPoint n FWPnCFG2 18762306a36Sopenharmony_ci Configuration 2 18862306a36Sopenharmony_ci0x392+8n (0≤n≤7) Instruction Fetch WatchPoint n FWPnCFG3 18962306a36Sopenharmony_ci Configuration 3 19062306a36Sopenharmony_ci0x393+8n (0≤n≤7) Instruction Fetch WatchPoint n FWPnCFG4 19162306a36Sopenharmony_ci Configuration 4 19262306a36Sopenharmony_ci0x500 Debug Register DBG 19362306a36Sopenharmony_ci0x501 Debug Exception Return Address DERA 19462306a36Sopenharmony_ci0x502 Debug Exception Saved Data Register DSAVE 19562306a36Sopenharmony_ci================= ===================================== ============== 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ciERA, TLBRERA, MERRERA and DERA are sometimes also known as EPC, TLBREPC, MERREPC 19862306a36Sopenharmony_ciand DEPC respectively. 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ciBasic Instruction Set 20162306a36Sopenharmony_ci===================== 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ciInstruction formats 20462306a36Sopenharmony_ci------------------- 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ciLoongArch instructions are 32 bits wide, belonging to 9 basic instruction 20762306a36Sopenharmony_ciformats (and variants of them): 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci=========== ========================== 21062306a36Sopenharmony_ciFormat name Composition 21162306a36Sopenharmony_ci=========== ========================== 21262306a36Sopenharmony_ci2R Opcode + Rj + Rd 21362306a36Sopenharmony_ci3R Opcode + Rk + Rj + Rd 21462306a36Sopenharmony_ci4R Opcode + Ra + Rk + Rj + Rd 21562306a36Sopenharmony_ci2RI8 Opcode + I8 + Rj + Rd 21662306a36Sopenharmony_ci2RI12 Opcode + I12 + Rj + Rd 21762306a36Sopenharmony_ci2RI14 Opcode + I14 + Rj + Rd 21862306a36Sopenharmony_ci2RI16 Opcode + I16 + Rj + Rd 21962306a36Sopenharmony_ci1RI21 Opcode + I21L + Rj + I21H 22062306a36Sopenharmony_ciI26 Opcode + I26L + I26H 22162306a36Sopenharmony_ci=========== ========================== 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ciRd is the destination register operand, while Rj, Rk and Ra ("a" stands for 22462306a36Sopenharmony_ci"additional") are the source register operands. I8/I12/I14/I16/I21/I26 are 22562306a36Sopenharmony_ciimmediate operands of respective width. The longer I21 and I26 are stored 22662306a36Sopenharmony_ciin separate higher and lower parts in the instruction word, denoted by the "L" 22762306a36Sopenharmony_ciand "H" suffixes. 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ciList of Instructions 23062306a36Sopenharmony_ci-------------------- 23162306a36Sopenharmony_ci 23262306a36Sopenharmony_ciFor brevity, only instruction names (mnemonics) are listed here; please see the 23362306a36Sopenharmony_ci:ref:`References <loongarch-references>` for details. 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ci1. Arithmetic Instructions:: 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ci ADD.W SUB.W ADDI.W ADD.D SUB.D ADDI.D 23962306a36Sopenharmony_ci SLT SLTU SLTI SLTUI 24062306a36Sopenharmony_ci AND OR NOR XOR ANDN ORN ANDI ORI XORI 24162306a36Sopenharmony_ci MUL.W MULH.W MULH.WU DIV.W DIV.WU MOD.W MOD.WU 24262306a36Sopenharmony_ci MUL.D MULH.D MULH.DU DIV.D DIV.DU MOD.D MOD.DU 24362306a36Sopenharmony_ci PCADDI PCADDU12I PCADDU18I 24462306a36Sopenharmony_ci LU12I.W LU32I.D LU52I.D ADDU16I.D 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_ci2. Bit-shift Instructions:: 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci SLL.W SRL.W SRA.W ROTR.W SLLI.W SRLI.W SRAI.W ROTRI.W 24962306a36Sopenharmony_ci SLL.D SRL.D SRA.D ROTR.D SLLI.D SRLI.D SRAI.D ROTRI.D 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_ci3. Bit-manipulation Instructions:: 25262306a36Sopenharmony_ci 25362306a36Sopenharmony_ci EXT.W.B EXT.W.H CLO.W CLO.D SLZ.W CLZ.D CTO.W CTO.D CTZ.W CTZ.D 25462306a36Sopenharmony_ci BYTEPICK.W BYTEPICK.D BSTRINS.W BSTRINS.D BSTRPICK.W BSTRPICK.D 25562306a36Sopenharmony_ci REVB.2H REVB.4H REVB.2W REVB.D REVH.2W REVH.D BITREV.4B BITREV.8B BITREV.W BITREV.D 25662306a36Sopenharmony_ci MASKEQZ MASKNEZ 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_ci4. Branch Instructions:: 25962306a36Sopenharmony_ci 26062306a36Sopenharmony_ci BEQ BNE BLT BGE BLTU BGEU BEQZ BNEZ B BL JIRL 26162306a36Sopenharmony_ci 26262306a36Sopenharmony_ci5. Load/Store Instructions:: 26362306a36Sopenharmony_ci 26462306a36Sopenharmony_ci LD.B LD.BU LD.H LD.HU LD.W LD.WU LD.D ST.B ST.H ST.W ST.D 26562306a36Sopenharmony_ci LDX.B LDX.BU LDX.H LDX.HU LDX.W LDX.WU LDX.D STX.B STX.H STX.W STX.D 26662306a36Sopenharmony_ci LDPTR.W LDPTR.D STPTR.W STPTR.D 26762306a36Sopenharmony_ci PRELD PRELDX 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_ci6. Atomic Operation Instructions:: 27062306a36Sopenharmony_ci 27162306a36Sopenharmony_ci LL.W SC.W LL.D SC.D 27262306a36Sopenharmony_ci AMSWAP.W AMSWAP.D AMADD.W AMADD.D AMAND.W AMAND.D AMOR.W AMOR.D AMXOR.W AMXOR.D 27362306a36Sopenharmony_ci AMMAX.W AMMAX.D AMMIN.W AMMIN.D 27462306a36Sopenharmony_ci 27562306a36Sopenharmony_ci7. Barrier Instructions:: 27662306a36Sopenharmony_ci 27762306a36Sopenharmony_ci IBAR DBAR 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_ci8. Special Instructions:: 28062306a36Sopenharmony_ci 28162306a36Sopenharmony_ci SYSCALL BREAK CPUCFG NOP IDLE ERTN(ERET) DBCL(DBGCALL) RDTIMEL.W RDTIMEH.W RDTIME.D 28262306a36Sopenharmony_ci ASRTLE.D ASRTGT.D 28362306a36Sopenharmony_ci 28462306a36Sopenharmony_ci9. Privileged Instructions:: 28562306a36Sopenharmony_ci 28662306a36Sopenharmony_ci CSRRD CSRWR CSRXCHG 28762306a36Sopenharmony_ci IOCSRRD.B IOCSRRD.H IOCSRRD.W IOCSRRD.D IOCSRWR.B IOCSRWR.H IOCSRWR.W IOCSRWR.D 28862306a36Sopenharmony_ci CACOP TLBP(TLBSRCH) TLBRD TLBWR TLBFILL TLBCLR TLBFLUSH INVTLB LDDIR LDPTE 28962306a36Sopenharmony_ci 29062306a36Sopenharmony_ciVirtual Memory 29162306a36Sopenharmony_ci============== 29262306a36Sopenharmony_ci 29362306a36Sopenharmony_ciLoongArch supports direct-mapped virtual memory and page-mapped virtual memory. 29462306a36Sopenharmony_ci 29562306a36Sopenharmony_ciDirect-mapped virtual memory is configured by CSR.DMWn (n=0~3), it has a simple 29662306a36Sopenharmony_cirelationship between virtual address (VA) and physical address (PA):: 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_ci VA = PA + FixedOffset 29962306a36Sopenharmony_ci 30062306a36Sopenharmony_ciPage-mapped virtual memory has arbitrary relationship between VA and PA, which 30162306a36Sopenharmony_ciis recorded in TLB and page tables. LoongArch's TLB includes a fully-associative 30262306a36Sopenharmony_ciMTLB (Multiple Page Size TLB) and set-associative STLB (Single Page Size TLB). 30362306a36Sopenharmony_ci 30462306a36Sopenharmony_ciBy default, the whole virtual address space of LA32 is configured like this: 30562306a36Sopenharmony_ci 30662306a36Sopenharmony_ci============ =========================== ============================= 30762306a36Sopenharmony_ciName Address Range Attributes 30862306a36Sopenharmony_ci============ =========================== ============================= 30962306a36Sopenharmony_ci``UVRANGE`` ``0x00000000 - 0x7FFFFFFF`` Page-mapped, Cached, PLV0~3 31062306a36Sopenharmony_ci``KPRANGE0`` ``0x80000000 - 0x9FFFFFFF`` Direct-mapped, Uncached, PLV0 31162306a36Sopenharmony_ci``KPRANGE1`` ``0xA0000000 - 0xBFFFFFFF`` Direct-mapped, Cached, PLV0 31262306a36Sopenharmony_ci``KVRANGE`` ``0xC0000000 - 0xFFFFFFFF`` Page-mapped, Cached, PLV0 31362306a36Sopenharmony_ci============ =========================== ============================= 31462306a36Sopenharmony_ci 31562306a36Sopenharmony_ciUser mode (PLV3) can only access UVRANGE. For direct-mapped KPRANGE0 and 31662306a36Sopenharmony_ciKPRANGE1, PA is equal to VA with bit30~31 cleared. For example, the uncached 31762306a36Sopenharmony_cidirect-mapped VA of 0x00001000 is 0x80001000, and the cached direct-mapped 31862306a36Sopenharmony_ciVA of 0x00001000 is 0xA0001000. 31962306a36Sopenharmony_ci 32062306a36Sopenharmony_ciBy default, the whole virtual address space of LA64 is configured like this: 32162306a36Sopenharmony_ci 32262306a36Sopenharmony_ci============ ====================== ====================================== 32362306a36Sopenharmony_ciName Address Range Attributes 32462306a36Sopenharmony_ci============ ====================== ====================================== 32562306a36Sopenharmony_ci``XUVRANGE`` ``0x0000000000000000 - Page-mapped, Cached, PLV0~3 32662306a36Sopenharmony_ci 0x3FFFFFFFFFFFFFFF`` 32762306a36Sopenharmony_ci``XSPRANGE`` ``0x4000000000000000 - Direct-mapped, Cached / Uncached, PLV0 32862306a36Sopenharmony_ci 0x7FFFFFFFFFFFFFFF`` 32962306a36Sopenharmony_ci``XKPRANGE`` ``0x8000000000000000 - Direct-mapped, Cached / Uncached, PLV0 33062306a36Sopenharmony_ci 0xBFFFFFFFFFFFFFFF`` 33162306a36Sopenharmony_ci``XKVRANGE`` ``0xC000000000000000 - Page-mapped, Cached, PLV0 33262306a36Sopenharmony_ci 0xFFFFFFFFFFFFFFFF`` 33362306a36Sopenharmony_ci============ ====================== ====================================== 33462306a36Sopenharmony_ci 33562306a36Sopenharmony_ciUser mode (PLV3) can only access XUVRANGE. For direct-mapped XSPRANGE and 33662306a36Sopenharmony_ciXKPRANGE, PA is equal to VA with bits 60~63 cleared, and the cache attribute 33762306a36Sopenharmony_ciis configured by bits 60~61 in VA: 0 is for strongly-ordered uncached, 1 is 33862306a36Sopenharmony_cifor coherent cached, and 2 is for weakly-ordered uncached. 33962306a36Sopenharmony_ci 34062306a36Sopenharmony_ciCurrently we only use XKPRANGE for direct mapping and XSPRANGE is reserved. 34162306a36Sopenharmony_ci 34262306a36Sopenharmony_ciTo put this in action: the strongly-ordered uncached direct-mapped VA (in 34362306a36Sopenharmony_ciXKPRANGE) of 0x00000000_00001000 is 0x80000000_00001000, the coherent cached 34462306a36Sopenharmony_cidirect-mapped VA (in XKPRANGE) of 0x00000000_00001000 is 0x90000000_00001000, 34562306a36Sopenharmony_ciand the weakly-ordered uncached direct-mapped VA (in XKPRANGE) of 0x00000000 34662306a36Sopenharmony_ci_00001000 is 0xA0000000_00001000. 34762306a36Sopenharmony_ci 34862306a36Sopenharmony_ciRelationship of Loongson and LoongArch 34962306a36Sopenharmony_ci====================================== 35062306a36Sopenharmony_ci 35162306a36Sopenharmony_ciLoongArch is a RISC ISA which is different from any other existing ones, while 35262306a36Sopenharmony_ciLoongson is a family of processors. Loongson includes 3 series: Loongson-1 is 35362306a36Sopenharmony_cithe 32-bit processor series, Loongson-2 is the low-end 64-bit processor series, 35462306a36Sopenharmony_ciand Loongson-3 is the high-end 64-bit processor series. Old Loongson is based on 35562306a36Sopenharmony_ciMIPS, while New Loongson is based on LoongArch. Take Loongson-3 as an example: 35662306a36Sopenharmony_ciLoongson-3A1000/3B1500/3A2000/3A3000/3A4000 are MIPS-compatible, while Loongson- 35762306a36Sopenharmony_ci3A5000 (and future revisions) are all based on LoongArch. 35862306a36Sopenharmony_ci 35962306a36Sopenharmony_ci.. _loongarch-references: 36062306a36Sopenharmony_ci 36162306a36Sopenharmony_ciReferences 36262306a36Sopenharmony_ci========== 36362306a36Sopenharmony_ci 36462306a36Sopenharmony_ciOfficial web site of Loongson Technology Corp. Ltd.: 36562306a36Sopenharmony_ci 36662306a36Sopenharmony_ci http://www.loongson.cn/ 36762306a36Sopenharmony_ci 36862306a36Sopenharmony_ciDeveloper web site of Loongson and LoongArch (Software and Documentation): 36962306a36Sopenharmony_ci 37062306a36Sopenharmony_ci http://www.loongnix.cn/ 37162306a36Sopenharmony_ci 37262306a36Sopenharmony_ci https://github.com/loongson/ 37362306a36Sopenharmony_ci 37462306a36Sopenharmony_ci https://loongson.github.io/LoongArch-Documentation/ 37562306a36Sopenharmony_ci 37662306a36Sopenharmony_ciDocumentation of LoongArch ISA: 37762306a36Sopenharmony_ci 37862306a36Sopenharmony_ci https://github.com/loongson/LoongArch-Documentation/releases/latest/download/LoongArch-Vol1-v1.02-CN.pdf (in Chinese) 37962306a36Sopenharmony_ci 38062306a36Sopenharmony_ci https://github.com/loongson/LoongArch-Documentation/releases/latest/download/LoongArch-Vol1-v1.02-EN.pdf (in English) 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_ciDocumentation of LoongArch ELF psABI: 38362306a36Sopenharmony_ci 38462306a36Sopenharmony_ci https://github.com/loongson/LoongArch-Documentation/releases/latest/download/LoongArch-ELF-ABI-v2.01-CN.pdf (in Chinese) 38562306a36Sopenharmony_ci 38662306a36Sopenharmony_ci https://github.com/loongson/LoongArch-Documentation/releases/latest/download/LoongArch-ELF-ABI-v2.01-EN.pdf (in English) 38762306a36Sopenharmony_ci 38862306a36Sopenharmony_ciLinux kernel repository of Loongson and LoongArch: 38962306a36Sopenharmony_ci 39062306a36Sopenharmony_ci https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson.git 391