Skip to content

Commit 672799e

Browse files
committed
feat: add basic la2k1000 support
1 parent a634925 commit 672799e

File tree

17 files changed

+1151
-1
lines changed

17 files changed

+1151
-1
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Architecture identifier.
2+
arch = "loongarch64"
3+
# Platform identifier.
4+
platform = "loongarch64-2k1000"
5+
6+
#
7+
# Platform configs
8+
#
9+
[plat]
10+
# Platform family.
11+
family = "loongarch64-2k1000"
12+
13+
# Base address of the whole physical memory.
14+
phys-memory-base = 0x9800_0000 # uint
15+
# Size of the whole physical memory. (128M)
16+
phys-memory-size = 0x2800_0000 # uint
17+
# Base physical address of the kernel image.
18+
kernel-base-paddr = 0x9800_0000 # uint
19+
20+
# Base virtual address of the kernel image.
21+
kernel-base-vaddr = "0x9000_0000_9800_0000" # uint
22+
# Linear mapping offset, for quick conversions between physical and virtual
23+
# addresses.
24+
phys-virt-offset = "0xffff_ffc0_0000_0000" # uint
25+
# Offset of bus address and phys address. some boards, the bus address is
26+
# different from the physical address.
27+
phys-bus-offset = 0 # uint
28+
# Kernel address space base.
29+
kernel-aspace-base = "0xffff_ffc0_0000_0000" # uint
30+
# Kernel address space size.
31+
kernel-aspace-size = "0x0000_003f_ffff_f000" # uint
32+
33+
#
34+
# Device specifications
35+
#
36+
[devices]
37+
# MMIO regions with format (`base_paddr`, `size`).
38+
mmio-regions = [
39+
[0x1FE2_0000, 0x0000_1000], # UART
40+
[0x2000_0000, 0x1000_0000], # PCI
41+
[0x4000_0000, 0x0002_0000], # PCI RANGES
42+
] # [(uint, uint)]
43+
# VirtIO MMIO regions with format (`base_paddr`, `size`).
44+
virtio-mmio-regions = [] # [(uint, uint)]
45+
# Base physical address of the PCIe ECAM space.
46+
pci-ecam-base = 0x2000_0000 # uint
47+
# End PCI bus number.
48+
pci-bus-end = 0x7f # uint
49+
# PCI device memory ranges.
50+
pci-ranges = [
51+
[0, 0],
52+
[0x4000_0000, 0x0002_0000]
53+
] # [(uint, uint)]
54+
# serial@1fe001e0 {
55+
# interrupt-parent = <0x00008003>;
56+
# interrupts = <0x00000002 0x00000004>;
57+
# clock-frequency = <0x05f5e100>;
58+
# reg = <0x00000000 0x1fe001e0 0x00000000 0x00000100>;
59+
# compatible = "ns16550a";
60+
# };
61+
uart-paddr = 0x1FE20000 # uint
62+
63+
# Timer interrupt frequency in Hz.
64+
timer-frequency = 100_000_000 # uint

modules/axhal/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const BUILTIN_PLATFORMS: &[&str] = &[
66
"aarch64-qemu-virt",
77
"aarch64-raspi4",
88
"loongarch64-qemu-virt",
9+
"loongarch64-2k1000",
910
"riscv64-qemu-virt",
1011
"x86_64-pc-oslab",
1112
"x86_64-qemu-q35",
@@ -17,6 +18,7 @@ const BUILTIN_PLATFORM_FAMILIES: &[&str] = &[
1718
"aarch64-qemu-virt",
1819
"aarch64-raspi",
1920
"loongarch64-qemu-virt",
21+
"loongarch64-2k1000",
2022
"riscv64-qemu-virt",
2123
"x86-pc",
2224
];

modules/axhal/src/arch/loongarch64/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod macros;
33

44
mod context;
55
mod trap;
6+
mod unaligned;
67

78
use core::arch::asm;
89
use loongArch64::register::{crmd, ecfg, eentry, pgdh, pgdl, stlbps, tlbidx, tlbrehi, tlbrentry};

modules/axhal/src/arch/loongarch64/trap.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use super::context::TrapFrame;
1+
use super::{
2+
context::TrapFrame,
3+
unaligned::emulate_load_store_insn
4+
};
25
use loongArch64::register::{
36
badv,
47
estat::{self, Exception, Trap},
@@ -48,6 +51,7 @@ fn loongarch64_trap_handler(tf: &mut TrapFrame, from_user: bool) {
4851
tf.era += 4;
4952
tf.regs.a0 = crate::trap::handle_syscall(tf, tf.regs.a7) as usize;
5053
}
54+
Trap::Exception(Exception::AddressNotAligned) => unsafe { emulate_load_store_insn(tf) },
5155
Trap::Exception(Exception::LoadPageFault)
5256
| Trap::Exception(Exception::PageNonReadableFault) => {
5357
handle_page_fault(tf, MappingFlags::READ, from_user)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
.macro fixup_ex from, to, fix
3+
.if \fix
4+
.section .fixup, "ax"
5+
\to:
6+
li.w $a0, -1
7+
jr $ra
8+
.previous
9+
.endif
10+
.section __ex_table, "a"
11+
.word \from\()b, \to\()b
12+
.previous
13+
.endm
14+
15+
/*
16+
* unsigned long probe_user_read(void *addr, void *value, unsigned long n, bool symbol)
17+
*
18+
* a0: addr
19+
* a1: value
20+
* a2: n
21+
* a3: symbol
22+
*/
23+
24+
.text
25+
.global temp_unaligned_read
26+
.p2align 2
27+
.type temp_unaligned_read,@function
28+
temp_unaligned_read:
29+
beqz $a2, 5f
30+
31+
li.w $t1, 8
32+
li.w $t2, 0
33+
34+
addi.d $t0, $a2, -1
35+
mul.d $t1, $t0, $t1
36+
add.d $a0, $a0, $t0
37+
38+
beq $a3, $zero, 2f
39+
1: ld.b $t3, $a0, 0
40+
b 3f
41+
42+
2: ld.bu $t3, $a0, 0
43+
3: sll.d $t3, $t3, $t1
44+
or $t2, $t2, $t3
45+
addi.d $t1, $t1, -8
46+
addi.d $a0, $a0, -1
47+
addi.d $a2, $a2, -1
48+
bgt $a2, $zero, 2b
49+
4: st.d $t2, $a1, 0
50+
51+
move $a0, $a2
52+
jr $ra
53+
54+
5: li.w $a0, -1
55+
jr $ra
56+
57+
fixup_ex 1, 6, 1
58+
fixup_ex 2, 6, 0
59+
fixup_ex 4, 6, 0
60+
61+
62+
/*
63+
* unsigned long unaligned_write(void *addr, unsigned long value, unsigned long n)
64+
*
65+
* a0: addr
66+
* a1: value
67+
* a2: n
68+
*/
69+
70+
.text
71+
.global temp_unaligned_write
72+
.p2align 2
73+
.type temp_unaligned_write,@function
74+
temp_unaligned_write:
75+
beqz $a2, 3f
76+
77+
li.w $t0, 0
78+
1: srl.d $t1, $a1, $t0
79+
2: st.b $t1, $a0, 0
80+
addi.d $t0, $t0, 8
81+
addi.d $a2, $a2, -1
82+
addi.d $a0, $a0, 1
83+
bgt $a2, $zero, 1b
84+
85+
move $a0, $a2
86+
jr $ra
87+
88+
3: li.w $a0, -1
89+
jr $ra
90+
91+
fixup_ex 2, 4, 1

0 commit comments

Comments
 (0)