Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for LoongArch64-2K500 and 2K1000 development boards #136

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
34de609
feat: add basic loongarch64 support
Godones Sep 18, 2023
fabae91
fix: fix the CI error about loongarch64 crate
Godones Sep 18, 2023
7aa5260
refactor: use loongarch64 crate
Godones Sep 22, 2023
42fdc45
refactor: Remove most useless code
Godones Sep 23, 2023
ad413d0
feat: pass apps/exception
Godones Sep 23, 2023
a2b1f30
feat: Support yield application
Godones Sep 23, 2023
f4c2b70
Implement support for all apps/task and fs.
Godones Sep 24, 2023
3606df6
Restore cargo.lock
Godones Sep 24, 2023
e83ec55
feat: Add basic C App support for la64
Godones Sep 28, 2023
a1fa046
feat: support net/display app
Godones Sep 29, 2023
0c78582
loongarch64 support for rust apps
jtzhpf Oct 11, 2023
897e3f4
fix halt implementation problems
jtzhpf Oct 11, 2023
1d4f672
Merge branch 'rcore-os:main' into main
jtzhpf Nov 30, 2023
e5bc021
simply solve the bug about clang not support 'loongarch64-unknown-no…
llh730 Nov 30, 2023
d9ce782
time-test case pass!
llh730 Nov 30, 2023
80a4ce3
Merge pull request #3 from llh730/main
jtzhpf Dec 13, 2023
971a75c
add la-2k500 and la-2k1000 support
jtzhpf Dec 16, 2023
99a205e
update 2k500 and 2k1000 config files, AddressNotAligned problem remai…
jtzhpf Dec 19, 2023
1c2960a
avoid AddressNotAligned problem
jtzhpf Dec 22, 2023
e5a7bc7
pass all C programs in apps
jtzhpf Dec 28, 2023
50abb70
add loongarch64-unknown-none into rust-toolchain.toml
jtzhpf Dec 28, 2023
da61043
update CI/CD
jtzhpf Dec 28, 2023
9cc43c9
switch loongarch64 toolchain from hard-float to soft-float
jtzhpf Jan 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions .github/workflows/actions/setup-musl/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,67 @@ runs:
steps:
- name: Cache musl
id: cache-musl
if: inputs.arch != 'loongarch64'
uses: actions/cache/restore@v3
with:
path: ${{ inputs.arch }}-linux-musl-cross
key: ${{ inputs.arch }}-linux-musl-cross

- name: Cache loongarch64 GNU
id: cache-GNU
if: inputs.arch == 'loongarch64'
uses: actions/cache/restore@v3
with:
path: loongarch64-unknown-linux-gnu-cross
key: loongarch64-unknown-linux-gnu-cross

- name: Download musl toolchain
if: steps.cache-musl.outputs.cache-hit != 'true'
if: steps.cache-musl.outputs.cache-hit != 'true' && inputs.arch != 'loongarch64'
shell: bash
run: |
MUSL_PATH=${{ inputs.arch }}-linux-musl-cross
wget https://musl.cc/${MUSL_PATH}.tgz
tar -xf ${MUSL_PATH}.tgz

- name: Download GNU toolchain for loongarch64
if: inputs.arch == 'loongarch64'
shell: bash
run: |
wget https://github.com/jtzhpf/loongarch64-unknown-linux-gnu-cross/releases/download/12.2.0/loongarch64-unknown-linux-gnu-cross.tgz
tar -xf loongarch64-unknown-linux-gnu-cross.tgz loongarch64-unknown-linux-gnu-cross

- uses: actions/cache/save@v3
if: steps.cache-musl.outputs.cache-hit != 'true'
if: steps.cache-musl.outputs.cache-hit != 'true' && inputs.arch != 'loongarch64'
with:
path: ${{ inputs.arch }}-linux-musl-cross
key: ${{ inputs.arch }}-linux-musl-cross

- uses: actions/cache/save@v3
if: steps.cache-musl.outputs.cache-hit != 'true' && inputs.arch == 'loongarch64'
with:
path: loongarch64-unknown-linux-gnu-cross
key: loongarch64-unknown-linux-gnu-cross

- name: Add to PATH environment variable
if: inputs.arch != 'loongarch64'
shell: bash
run: |
echo "$PWD/${{ inputs.arch }}-linux-musl-cross/bin" >> $GITHUB_PATH

- name: Add to PATH environment variable for loongarch64
if: inputs.arch == 'loongarch64'
shell: bash
run: |
echo "$PWD/loongarch64-unknown-linux-gnu-cross/bin" >> $GITHUB_PATH

- name: Verify installation
if: inputs.arch != 'loongarch64'
shell: bash
run: |
${{ inputs.arch }}-linux-musl-gcc --version

- name: Verify installation for loongarch64
if: inputs.arch == 'loongarch64'
shell: bash
run: |
loongarch64-unknown-linux-gnu-gcc --version
16 changes: 16 additions & 0 deletions .github/workflows/actions/setup-qemu/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ runs:
with:
path: qemu_build
key: qemu-${{ inputs.qemu-version }}

- name: Download and build QEMU
if: steps.cache-qemu.outputs.cache-hit != 'true'
env:
Expand All @@ -28,6 +29,20 @@ runs:
&& ./configure --prefix=$PREFIX --target-list=x86_64-softmmu,riscv64-softmmu,aarch64-softmmu \
&& make -j > /dev/null 2>&1 \
&& make install

- name: Download and build QEMU for loongarch
if: steps.cache-qemu.outputs.cache-hit != 'true'
env:
QEMU_PATH: qemu-${{ inputs.qemu-version }}
PREFIX: ${{ github.workspace }}/qemu_build
shell: bash
run: |
git clone https://github.com/foxsen/qemu qemu-6.2.50
cd qemu-6.2.50
./configure --prefix=$PREFIX --target-list=loongarch64-softmmu
make -j
make install

- uses: actions/cache/save@v3
if: steps.cache-qemu.outputs.cache-hit != 'true'
with:
Expand All @@ -44,3 +59,4 @@ runs:
qemu-system-x86_64 --version
qemu-system-aarch64 --version
qemu-system-riscv64 --version
qemu-system-loongarch64 --version
14 changes: 13 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
run: make clippy ARCH=riscv64
- name: Clippy for aarch64
run: make clippy ARCH=aarch64
- name: Clippy for loongarch64
run: make clippy ARCH=loongarch64
- name: Check code format
run: cargo fmt --all -- --check

Expand All @@ -34,7 +36,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
arch: [x86_64, riscv64, aarch64]
arch: [x86_64, riscv64, aarch64, loongarch64]
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -118,6 +120,16 @@ jobs:
with:
arch: x86_64

- name: Build helloworld for loongarch-2k500
run: make PLATFORM=loongarch64-2k500 A=apps/helloworld
- name: Build fs/shell for loongarch-2k500
run: make PLATFORM=loongarch64-2k500 A=apps/fs/shell FEATURES=driver-ramdisk

- name: Build helloworld for loongarch-2k1000
run: make PLATFORM=loongarch64-2k1000 A=apps/helloworld
- name: Build fs/shell for loongarch-2k1000
run: make PLATFORM=loongarch64-2k1000 A=apps/fs/shell FEATURES=driver-ramdisk

- name: Build helloworld for x86_64-pc-oslab
run: make PLATFORM=x86_64-pc-oslab A=apps/helloworld
- name: Build net/httpserver for x86_64-pc-oslab
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
arch: [x86_64, riscv64, aarch64]
arch: [x86_64, riscv64, aarch64, loongarch64]
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
/.vscode
.DS_Store
*.asm
*.img
disk.img
actual.out
qemu.log
rusty-tags.vi
.idea
*.log
*.bin.gz
uImage
riscv64-linux-musl-cross/
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 26 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,19 @@ else ifeq ($(ARCH), aarch64)
ACCEL ?= n
PLATFORM_NAME ?= aarch64-qemu-virt
TARGET := aarch64-unknown-none-softfloat
else ifeq ($(ARCH), loongarch64)
ACCEL ?= n
PLATFORM_NAME ?= loongarch64-qemu-virt
TARGET := loongarch64-unknown-none-softfloat
BUS := pci
else
$(error "ARCH" must be one of "x86_64", "riscv64", or "aarch64")
$(error "ARCH" must be one of "x86_64", "riscv64", "aarch64" or "loongarch64")
endif

ifeq ($(PLATFORM_NAME), loongarch64-2k500)
BUS := mmio
else ifeq ($(PLATFORM_NAME), loongarch64-2k1000)
BUS := mmio
endif

export AX_ARCH=$(ARCH)
Expand All @@ -122,15 +133,22 @@ export AX_GW=$(GW)

# Binutils
CROSS_COMPILE ?= $(ARCH)-linux-musl-
ifeq ($(ARCH), loongarch64)
CROSS_COMPILE := $(ARCH)-linux-gnu-
# CROSS_COMPILE := $(ARCH)-unknown-linux-gnu-
endif
CC := $(CROSS_COMPILE)gcc
AR := $(CROSS_COMPILE)ar
RANLIB := $(CROSS_COMPILE)ranlib
LD := rust-lld -flavor gnu

OBJDUMP ?= rust-objdump -d --print-imm-hex --x86-asm-syntax=intel
OBJCOPY ?= rust-objcopy --binary-architecture=$(ARCH)
GDB ?= gdb-multiarch

ifeq ($(ARCH), loongarch64)
GDB :=gdb
else
GDB ?= gdb-multiarch
endif
# Paths
OUT_DIR ?= $(APP)

Expand All @@ -149,6 +167,10 @@ ifeq ($(PLATFORM_NAME), aarch64-raspi4)
include scripts/make/raspi4.mk
else ifeq ($(PLATFORM_NAME), aarch64-bsta1000b)
include scripts/make/bsta1000b-fada.mk
else ifeq ($(PLATFORM_NAME), loongarch64-2k500)
include scripts/make/2k500.mk
else ifeq ($(PLATFORM_NAME), loongarch64-2k1000)
include scripts/make/2k1000.mk
endif

build: $(OUT_DIR) $(OUT_BIN)
Expand All @@ -167,7 +189,7 @@ debug: build
$(GDB) $(OUT_ELF) \
-ex 'target remote localhost:1234' \
-ex 'b rust_entry' \
-ex 'continue' \
-ex 'continue' \
-ex 'disp /16i $$pc'

clippy:
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ ArceOS was inspired a lot by [Unikraft](https://github.com/unikraft/unikraft).

## Features & TODOs

* [x] Architecture: x86_64, riscv64, aarch64
* [x] Platform: QEMU pc-q35 (x86_64), virt (riscv64/aarch64)
* [x] Architecture: x86_64, riscv64, aarch64, loongarch64
* [x] Platform: QEMU pc-q35 (x86_64), virt (riscv64/aarch64/loongarch64)
* [x] Multi-thread
* [x] FIFO/RR/CFS scheduler
* [x] VirtIO net/blk/gpu drivers
Expand Down Expand Up @@ -73,12 +73,14 @@ Download&Install `cross-musl-based toolchains`:
wget https://musl.cc/aarch64-linux-musl-cross.tgz
wget https://musl.cc/riscv64-linux-musl-cross.tgz
wget https://musl.cc/x86_64-linux-musl-cross.tgz
wget https://github.com/jtzhpf/loongarch64-unknown-linux-gnu-cross/releases/download/12.2.0/loongarch64-unknown-linux-gnu-cross.tgz
# install
tar zxf aarch64-linux-musl-cross.tgz
tar zxf riscv64-linux-musl-cross.tgz
tar zxf x86_64-linux-musl-cross.tgz
tar zxf loongarch64-unknown-linux-gnu-cross.tgz
# exec below command in bash OR add below info in ~/.bashrc
export PATH=`pwd`/x86_64-linux-musl-cross/bin:`pwd`/aarch64-linux-musl-cross/bin:`pwd`/riscv64-linux-musl-cross/bin:$PATH
export PATH=`pwd`/x86_64-linux-musl-cross/bin:`pwd`/aarch64-linux-musl-cross/bin:`pwd`/riscv64-linux-musl-cross/bin:`pwd`/loongarch64-unknown-linux-gnu-cross/bin:$PATH
```

### Example apps
Expand All @@ -88,7 +90,7 @@ export PATH=`pwd`/x86_64-linux-musl-cross/bin:`pwd`/aarch64-linux-musl-cross/bin
make A=path/to/app ARCH=<arch> LOG=<log>
```

Where `<arch>` should be one of `riscv64`, `aarch64``x86_64`.
Where `<arch>` should be one of `riscv64`, `aarch64`, `x86_64`, `loongarch64`.

`<log>` should be one of `off`, `error`, `warn`, `info`, `debug`, `trace`.

Expand Down
1 change: 1 addition & 0 deletions api/arceos_posix_api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ typedef struct {{

let mut builder = bindgen::Builder::default()
.header(in_file)
.clang_arg("--target=x86_64-pc-linux-gnu")
.clang_arg("-I./../../ulib/axlibc/include")
.parse_callbacks(Box::new(MyCallbacks))
.derive_default(true)
Expand Down
9 changes: 9 additions & 0 deletions apps/c/testcase/interrupts-test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.PHONY: all clean

all:
for i in 1 2; do \
$(CC) test$$i.c -static -O3 -Wall -o interrupts-test-$$i.o; \
done

clean:
rm -f interrupts-test-*
1 change: 1 addition & 0 deletions apps/c/testcase/interrupts-test/axbuild.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app-objs := main.o
2 changes: 2 additions & 0 deletions apps/c/testcase/interrupts-test/features.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fs
alloc
42 changes: 42 additions & 0 deletions apps/c/testcase/interrupts-test/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

void die(const char *msg) {
fputs(msg, stderr);
exit(-1);
}

void check_read() {
int fd = open("/proc/interrupts", O_RDONLY);
if (fd < 0) {
die("open failed\n");
}
close(fd);
}

void check_write() {
int fd = open("/proc/interrupts", O_WRONLY);
if (fd >= 0) {
int n = write(fd, "a", 1);
if (n == 1) {
die("write succeeded\n");
}
close(fd);
}
}

int main() {
check_write();
if (remove("/proc/interrupts") == 0) {
die("remove succeeded\n");
}
if (rename("/proc/interrupts", "/proc/interrupts2") == 0) {
die("rename succeeded\n");
}
puts("interrupts-test: passed case 1");
return 0;
}
Loading