因为linux-header包里面含有/lib/modules/build
,指向header安装的根目录
所以通过一个简单的makefile
obj-m += xxxx.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
就能直接得到ko模块
全員が等しく 不幸の世界を見せてやる!
因为linux-header包里面含有/lib/modules/build
,指向header安装的根目录
所以通过一个简单的makefile
obj-m += xxxx.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
就能直接得到ko模块
问题日志
(base) ➜ bin ./vitis_hls -showguiout
****** Vitis HLS - High-Level Synthesis from C, C++ and OpenCL v2022.2 (64-bit)
**** SW Build 3670227 on Oct 13 2022
**** IP Build 3669848 on Fri Oct 14 08:30:02 MDT 2022
** Copyright 1986-2022 Xilinx, Inc. All Rights Reserved.
source /home/ztn/Embedded/Xilinx/Vitis_HLS/2022.2/scripts/vitis_hls/hls.tcl -notrace
INFO: [HLS 200-10] Running '/home/ztn/Embedded/Xilinx/Vitis_HLS/2022.2/bin/unwrapped/lnx64.o/vitis_hls'
INFO: [HLS 200-10] For user 'ztn' on host 'ztn-Legion-Y9000P-IRX8' (Linux_x86_64 version 6.8.0-49-generic) on Tue Dec 10 15:44:46 CST 2024
INFO: [HLS 200-10] On os Ubuntu 24.04.1 LTS
INFO: [HLS 200-10] In directory '/home/ztn/Embedded/Xilinx/Vitis_HLS/2022.2/bin'
INFO: [HLS 200-10] Bringing up Vitis HLS GUI ...
HLS_GUI_DEBUG_INFO: Start loading HLS Swig Library: xv_hls_main
HLS_GUI_DEBUG_INFO: Finish loading HLS Swig Library: xv_hls_main
HLS_GUI_DEBUG_INFO: Running GuiDriver.tclInitFromJava, tclIsRunning=false
INFO: [HLS 200-10] Running '/home/ztn/Embedded/Xilinx/Vitis_HLS/2022.2/tps/lnx64/jre11.0.11_9/bin/java'
INFO: [HLS 200-10] For user 'ztn' on host 'ztn-Legion-Y9000P-IRX8' (Linux_x86_64 version 6.8.0-49-generic) on Tue Dec 10 15:44:48 CST 2024
INFO: [HLS 200-10] On os Ubuntu 24.04.1 LTS
INFO: [HLS 200-10] In directory '/home/ztn/Embedded/Xilinx/Vitis_HLS/2022.2/bin'
HLS_GUI_DEBUG_INFO: TCL was started from GUI
HLS_GUI_DEBUG_INFO: Start initializing Parts data
HLS_GUI_DEBUG_INFO: Start initializing Boards data
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
(Vitis HLS:66803): Gtk-WARNING **: 15:44:48.936: Could not load a pixbuf from icon theme.
This may indicate that pixbuf loaders or the mime database could not be found.
**
Gtk:ERROR:../../../gtk/gtkiconhelper.c:495:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /usr/share/icons/breeze-dark/status/16/image-missing.svg: Unable to load image-loading module: /usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so: /home/ztn/Embedded/Xilinx/Vitis_HLS/2022.2/lib/lnx64.o/Ubuntu/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /lib/x86_64-linux-gnu/libicuuc.so.74) (gdk-pixbuf-error-quark, 5)
Bail out! Gtk:ERROR:../../../gtk/gtkiconhelper.c:495:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /usr/share/icons/breeze-dark/status/16/image-missing.svg: Unable to load image-loading module: /usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so: /home/ztn/Embedded/Xilinx/Vitis_HLS/2022.2/lib/lnx64.o/Ubuntu/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /lib/x86_64-linux-gnu/libicuuc.so.74) (gdk-pixbuf-error-quark, 5)
INFO: [HLS 200-112] Total CPU user time: 12.91 seconds. Total CPU system time: 0.74 seconds. Total elapsed time: 4.02 seconds; peak allocated memory: 98.949 MB.
INFO: [Common 17-206] Exiting vitis_hls at Tue Dec 10 15:44:50 2024...
(base) ➜ bin
解决方法,软连接libstdc++.so.6到系统库
(base) ➜ bin cd /home/ztn/Embedded/Xilinx/Vitis_HLS/2022.2/lib/lnx64.o/Ubuntu/
(base) ➜ Ubuntu ls
18 20 libgcc_s.so.1 libgomp.so.1 libstdc++.so libstdc++.so.6
(base) ➜ Ubuntu mv libstdc++.so.6 libstdc++.so.6.old
(base) ➜ Ubuntu ls
18 20 libgcc_s.so.1 libgomp.so.1 libstdc++.so libstdc++.so.6.old
(base) ➜ Ubuntu ln
(base) ➜ Ubuntu ls -l
total 1816
drwxr-xr-x 2 ztn ztn 4096 12月 8 23:09 18
drwxr-xr-x 2 ztn ztn 4096 12月 8 23:09 20
-rwxr-xr-x 25 ztn ztn 94000 10月 14 2022 libgcc_s.so.1
-rwxr-xr-x 25 ztn ztn 184304 10月 14 2022 libgomp.so.1
lrwxrwxrwx 1 ztn ztn 14 12月 8 23:09 libstdc++.so -> libstdc++.so.6
-rwxr-xr-x 35 ztn ztn 1570176 10月 14 2022 libstdc++.so.6.old
(base) ➜ Ubuntu ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6
(base) ➜ Ubuntu ls -l
total 1816
drwxr-xr-x 2 ztn ztn 4096 12月 8 23:09 18
drwxr-xr-x 2 ztn ztn 4096 12月 8 23:09 20
-rwxr-xr-x 25 ztn ztn 94000 10月 14 2022 libgcc_s.so.1
-rwxr-xr-x 25 ztn ztn 184304 10月 14 2022 libgomp.so.1
lrwxrwxrwx 1 ztn ztn 14 12月 8 23:09 libstdc++.so -> libstdc++.so.6
lrwxrwxrwx 1 ztn ztn 40 12月 10 15:46 libstdc++.so.6 -> /usr/lib/x86_64-linux-gnu/libstdc++.so.6
-rwxr-xr-x 35 ztn ztn 1570176 10月 14 2022 libstdc++.so.6.old
(base) ➜ Ubuntu
然后就可以启动
用msvc编译后(之所以不用mingw是因为 HLS Csim用的是一个老的mingw,如果你用新的编译很麻烦)
编译完后dll丢进D:\Xilinx\Vitis_HLS\2022.2\tps\win64\msys64\mingw64\bin
然后HLS project里面设置Ldflags 为lib导入库SDL2d.lib
还有SDL2maind.lib
如果不想用SDL_main(),在include SDL2.h之前设置
Touhou Resource:https://tieba.baidu.com/p/9007150098
ra(x1) saved by _swtch,
And _swtch should act like an 'nop'
And tp is never used by compiler
"And I am not frightened of dying, any time will do, I
don't mind. Why should I be frightened of dying?
There's no reason for it, you've gotta go sometime."
"I never said I was frightened of dying."
cf. https://wiki.qemu.org/Hosts/W32
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-glib2 mingw-w64-x86_64-gettext-runtime mingw-w64-x86_64-gcc mingw-w64-x86_64-binutils mingw-w64-x86_64-pixman mingw-w64-x86_64-SDL2 mingw-w64-x86_64-gtk3 mingw-w64-x86_64-riscv64-unknown-elf-gcc mingw-w64-x86_64-gdb-multiarch git diffutils zsh vim)
Please enable Developer Mode to support soft link without Administrator permission, otherwise it prompts
Found ninja-1.12.1 at D:/msys64/usr/bin/ninja.exe
Running postconf script 'D:/ZJUI/ECE391/qemu/build/pyvenv/bin/python3.exe D:/ZJUI/ECE391/qemu/scripts/symlink-install-tree.py'
Please enable Developer Mode to support soft link without Administrator permission
error making symbolic link D:/msys64/opt/toolchains/riscv/lib/libfdt.a
Traceback (most recent call last):
File "D:/ZJUI/ECE391/qemu/scripts/symlink-install-tree.py", line 35, in <module>
raise e
File "D:/ZJUI/ECE391/qemu/scripts/symlink-install-tree.py", line 28, in <module>
os.symlink(source, bundle_dest)
OSError: [WinError 1314] 客户端没有所需的特权。: 'D:/ZJUI/ECE391/qemu/build/subprojects/dtc/libfdt/libfdt.a' -> 'qemu-bundle/msys64/opt/toolchains/riscv/lib/libfdt.a'
./configure --prefix=/opt/toolchains/riscv --target-list=riscv32-softmmu,riscv64-softmmu --enable-gtk --enable-system --disable-werror
make -j
make install
Change zsh for MINGW session https://superuser.com/questions/961699/change-default-shell-on-msys2
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Set in mingw64.ini
:
SHELL=/usr/bin/zsh
There is no PTS on windows so use telnet instead
source:https://www.uni-koeln.de/~pbogusze/posts/QEMU_serial_console.html
qemu-system-riscv64 -machine virt -bios none -kernel cp1.elf -m 8M -nographic -serial mon:stdio -serial telnet:localhost:4321,server,nowait
Add D:\msys64\mingw64\bin
to PATH of Windows
Then telnet to attach to con1
telnet localhost 4321
CSR can't be accessed directly, thus those instructions are needed.
Only 6 instructions, CSR[RS,RC,RW,RSI,RCI,RWI],I is immediate.
S for set, C for clear, W for write, other mnemonic(e.g. CSRR/CSRW) are pseudo-instructions with either rs1=x0
or ds=x0
.
For both CSRRS and CSRRC, if rs1=x0
, then the instruction will not write to the CSR at all
For both CSRRSI and CSRRCI, if uimm[4:0] field is zero
, then the instruction will not write to the CSR at all
But CAVEAT LECTOR!, if rs1=x0
or uimm[4:0]=0
for CSRRW or CSRRWI
, then csr will be CLEARED
It is modified based on https://github.com/qemu/qemu/blob/master/hw/riscv/virt.c
7 uarts are added and IRQ number of RTC is moved to 9
\n\t
to seperate assembly instructions in a single Assembly Template,
delimiter
[ [asmSymbolicName] ] constraint (cexpression)
Output:
[ [asmSymbolicName] ] constraint (cvariablename)
assembler template
by enclosing it in square brackets (i.e. %[Value]). The scope of the name is the asm statement that contains the definition. Any valid C variable name is acceptable, including names already defined in the surrounding code. No two operands within the same asm statement can use the same symbolic name.zero-based
) position of the operand in the list of operands in the assembler template. For example if there are two output operands
and three inputs
, use %2
in the template to refer to the first input operand
, %3 for the second, and %4 for the third.For example
uint32_t Mask = 1234;
uint32_t Index;
asm ("bsfl %[aMask], %[aIndex]"
: [aIndex] "=r" (Index)
: [aMask] "r" (Mask)
: "cc");
if no asmSymbolicName
__asm__ ("btsl %2,%1\n\t" // Turn on zero-based bit #Offset in Base.
"sbb %0,%0" // Use the CF to calculate old.
: "=r" (old), "+rm" (*Base)
: "Ir" (Offset)
: "cc");
return old;
output registers begin with 0, the number of input regs are after output regs.
If using I
(immediate) as constraint, the input value must be known at assembly time or later.
mstatus:
mip:
mie:
mtvec:
mcause:
mepc:
Each source has a priority(0 is disabled, higher for high prio).
destination is a contex, which is a HART combined with mode(M/S)
every context (e.g. context 0) has a source enable(not prio).
PLIC Indicates which interrupt source raised the interrupt by
When CPU is finished servicing the itnerrupt, it signals completion to the PLIC
Allow Breakpoints Everywhere
Vscode 在汇编文件中添加调试断点ASFLAGS = -g
在workspace下.vscode
下新建启动文件与任务文件launch.json
, tasks.json
在miDebuggerPath
填riscv-gdb绝对路径,program
填要调的程序
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug RISC-V",
"type": "cppdbg",
"request": "launch",
"program":"${workspaceFolder}/demo.elf",
"cwd": "${workspaceFolder}",
"miDebuggerPath": "/opt/toolchains/riscv/bin/riscv64-unknown-elf-gdb",
"miDebuggerServerAddress": "localhost:1234",
"stopOnEntry": true,
"preLaunchTask": "Run QEMU"
}
]
}
在command
中修改调试器启动参数,修改对应启动elf文件。不要删除前面的一条命令echo 'QEMU started'
,这个是为了让vscode结束启动等待用
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "make",
"args": [
""
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
},
{
"label": "Run QEMU",
"type": "shell",
"command": "echo 'QEMU started';qemu-system-riscv64 -s -S -machine virt -bios none -kernel demo.elf -m 128M -serial mon:stdio -device bochs-display",
"dependsOn": ["Build"],
"args": [],
"group": {
"kind": "test",
"isDefault": true
},
"isBackground": true,
"problemMatcher": [
{
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": ".",
}
}
]
}
]
}