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

rCore-Tutorial-Book-v3/chapter1/4first-instruction-in-kernel2 #96

Open
utterances-bot opened this issue Jan 5, 2022 · 94 comments
Open
Labels
comments An area where readers can discuss related topics after every article.

Comments

@utterances-bot
Copy link

内核第一条指令(实践篇) — rCore-Tutorial-Book-v3 3.6.0-alpha.1 文档

https://rcore-os.github.io/rCore-Tutorial-Book-v3/chapter1/4first-instruction-in-kernel2.html

Copy link

虽然老师提供了连接脚本,但是该怎么获知写的程序都有哪些段需要被链接呢?

Copy link

bswaterb commented Jan 5, 2022

开篇提供的 vm 镜像似乎并没安装 objcopy,需要使用如下语句来安装
$ cargo install cargo-binutils
$ rustup component add llvm-tools-preview
否则可能出如下的错误
Failed to execute tool: objcopy No such file or directory (error 2)

Copy link

bswaterb commented Jan 5, 2022

回翻了一下开篇,发现原来是自己漏掉工具链安装那一步了 ORZ

Copy link

请问 这里的 0x100c: ld t0,24(t0) 。 ld是什么意思?

@bswaterb
Copy link

bswaterb commented Jan 7, 2022

请问 这里的 0x100c: ld t0,24(t0) 。 ld是什么意思?

代表是 load 指令

Copy link

那请问 load指令 是指 汇编指令吗?

Copy link

请问 ld t0,24(t0) 这个是什么意思呢?

Copy link

lu-yidan commented Jan 7, 2022

请问一下为什么在终端输入cargo build后会遇到这种问题呢,把main.rs中的use core::arch::global_asm换成use core::global_asm还是不行,下面的github链接有没有找到方案
error[E0658]: use of unstable library feature 'global_asm': global_asm! is not stable enough for use and is subject to change
--> src/main.rs:8:1
|
8 | global_asm!(include_str!("entry.asm"));
| ^^^^^^^^^^
|
= note: see issue #35119 rust-lang/rust#35119 for more information

error[E0432]: unresolved import core::arch::global_asm
--> src/main.rs:7:5
|
7 | use core::arch::global_asm;
| ^^^^^^^^^^^^^^^^^^^^^^ no global_asm in arch
|
= note: this could be because a macro annotated with #[macro_export] will be exported at the root of the crate instead of the module where it is defined
help: a macro with this name exists at the root of the crate
|
7 | use core::global_asm;
| ^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0432, E0658.
For more information about an error, try rustc --explain E0432.
error: could not compile os

To learn more, run the command again with --verbose.

@wyfcyx
Copy link
Collaborator

wyfcyx commented Jan 7, 2022

@lu-yidan 请将Rust升级到最新版本,可以在os目录下创建一个rust-toolchain文件,内容为nightly-2022-01-01

Copy link

Tshiyao commented Jan 16, 2022

虚拟磁盘文件未安装riscv64-unknown-elf-gdb,该怎么安装呢?

@lu-yidan
Copy link

lu-yidan commented Jan 16, 2022 via email

Copy link

ZENOTME commented Jan 21, 2022

关于内核的加载这里有一个疑问,如果说按照这里内核是直接进行从文件中进行拷贝过去,那么是否会出现文件中相应片段大小小于实际在内存中占用大小的情况?(因为传统elf文件是有可能出现片段在文件中占用大小小于实际内存中大小的)

@wyfcyx
Copy link
Collaborator

wyfcyx commented Jan 21, 2022

@ZENOTME 据我所知,这种情况一般只出现在零初始化的.bss段,在ELF中可能有元数据记录该段的位置而不会真的有一个全零的数据段。可以看到我们在链接脚本中将.bss段置于最后,在加载的时候并不会拷贝一个全零数据段,而在内核中我们会通过clear_bss将其清零。

Copy link

konpoe commented Jan 22, 2022

根据文档riscv-spec-20191213.pdf中Ch2和Ch25
0x1000: auipc t0,0x0
Add Upper Immediate PC: rd = pc + imm[31:12]
U型指令
把当前指令的地址加上立即数这里的立即数对应的是寄存器中的高20位,相对于imm<<12,然后保存到寄存器t0
0x1004: addi a2,t0,40
ADD Immeiate: rd = rs1 + imm[11:0]
执行后 a2 = 0x1028
I型指令
0x1008: csrr a0,mhartid
伪指令
Control State Register Read: a0 = mhartid
mhartid寄存器,当前hart的id#0
0x100c: ld a1,32(t0)
Load Double-word: rd = rs1 + imm[11:0]
I型号指令
从地址rs1+imm[11:0]出加载4个字节的数据到寄存器rd
$a1 = [4bytes@0x1020]
0x1010: ld t0,24(t0)
$t0 = [4bytes@1018] 这里是1018出开始加载4个字节,小端内存序,所以寄存器中的数据应该是0x0080_0000
0x1014: jr t0
伪指令,jr rs <=> jalr x0, 0(rs),Jump register
意思是跳转到t0位置

注意这里寄存器的名字,
1.开头的t代表temporary,一般用于临时变量,t0~6
2.开头的a代表argument,表示是用于函数调用传入的参数,a0~7
3这里用到了a0,a1,a2,a0是hartid,a1和a2代表了个啥不是很确定
jr应该像个函数调用传的参数是hartid : a0,unknown: a1,unkown : a2,
4.没有用到堆栈,目测是8个以内参数和7个以内临时变量的函数吧
汇编我不熟,有错误请指正

@wyfcyx
Copy link
Collaborator

wyfcyx commented Jan 22, 2022

@konpoe 很棒!大体上正确,帮你修改了一下格式。有一个问题是0x1010的指令执行完毕后t0应该是0x8000_0000而不是0x0080_0000,这个在前面讲解Qemu启动流程的时候有提到过。可能是小端序理解有误,从Qemu上可以看到以0x101a开头两字节的数据是0x8000,按照字节分开看,0x101a0x101b的数据分别是0x000x80。然后0x10180x1019的数据都是0x00。这样ld后的结果就是0x8000_0000

@konpoe
Copy link

konpoe commented Jan 22, 2022

谢谢指正

@konpoe
Copy link

konpoe commented Jan 22, 2022

我仔细检查了一下,ld加载双字(8字节),所以$a1 应该是[8bytes@0x1020]后面的t0应该是[8bytes@0x1018]。
应该是这8个字节的数据:
0x1018: unimp 0x101a: 0x8000 0x101c: unimp 0x101e: unimp
按照之前的教程,t0的值应该是0x0000_0000_8000_0000, 小端序是没问题的,就是gdb显示的问题。其他的好像问题不大。
我马虎过头了。

Copy link

SenkiTK commented Jan 29, 2022

弱弱问一下,为什么我使用objcopy strip之后的文件为什么会是0size呢……Orz?
错误信息如下:

llvm-objcopy --strip-all target/riscv64gc-unknown-none-elf/release/os -O binary target/riscv64gc-unknown-none-elf/release/os.bin

stat /home/senki/Documents/xv6-rust/os/target/riscv64gc-unknown-none-elf/release/os.bin
File: /home/senki/Documents/xv6-rust/os/target/riscv64gc-unknown-none-elf/release/os.bin
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 8,3 Inode: 17961165 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 1000/ senki) Gid: ( 1000/ senki)
Access: 2022-01-30 00:08:19.840070679 +0800
Modify: 2022-01-30 00:08:19.130054408 +0800
Change: 2022-01-30 00:08:19.130054408 +0800
Birth: 2022-01-30 00:08:19.130054408 +0800

我使用rust-objcopy无法运行,所以使用了llvm-objcopy(虽然说cargo-binutils也只是对这些工具做了封装)。
所有的依赖项也是安装好了的。

Copy link

SenkiTK commented Jan 29, 2022

但是生成的os文件 大小是正常的(1000左右)

Copy link

SenkiTK commented Jan 29, 2022

我搞清楚了!原来是:
stext = .;
11 .text : {
12
*(.text.entry)
13 (.text .text.)
14 }
15
16 . = ALIGN(4K);
17 etext = .;

12行与13行没有缩进(我以为不缩进功能也是一样的)
想问一下,这里是为什么需要缩进呢?

Copy link

MrZLeo commented Jan 30, 2022

演示代码

$ (gdb) si
0x0000000000001004 in ?? ()
$ (gdb) si
0x0000000000001008 in ?? ()
$ (gdb) si
0x000000000000100c in ?? ()
$ (gdb) si
0x0000000000001010 in ?? ()
$ (gdb) p/x $t0
$1 = 0x80000000
$ (gdb) si
0x0000000080000000 in ?? ()

应该是五次si后才能得到

$ (gdb) p/x $t0
$1 = 0x80000000

实机演示:

(gdb) x/10i $pc
=> 0x1000:	auipc	t0,0x0
   0x1004:	addi	a2,t0,40
   0x1008:	csrr	a0,mhartid
   0x100c:	ld	a1,32(t0)
   0x1010:	ld	t0,24(t0)
   0x1014:	jr	t0
   0x1018:	unimp
   0x101a:	0x8000
   0x101c:	unimp
   0x101e:	unimp
(gdb) si
0x0000000000001004 in ?? ()
(gdb) 
0x0000000000001008 in ?? ()
(gdb) 
0x000000000000100c in ?? ()
(gdb) 
0x0000000000001010 in ?? ()
(gdb) p/x $t0
$1 = 0x1000
(gdb) si
0x0000000000001014 in ?? ()
(gdb) p/x $t0
$2 = 0x80000000

Copy link

Mac OS 执行 riscv64-unknown-elf-gdb 命令报:

riscv64-unknown-elf-gdb: command not found

解决办法:

  1. 安装 homebrew
    2.执行 sudo xcode-select --install
    3.执行 brew tap riscv/riscv
    3.执行 brew install riscv-tools

Copy link

iruhh commented Feb 28, 2022

@lu-yidan 的方法有用,不过得注意:
1、gedit .bashrc的前要先cd ~让终端回到home位置。
2、export PATH=$PATH:/home/oslab/.riscv64-unknown-elf-gcc-8.3.0-2020.04.1-x86_64-linux-ubuntu14/bin可能在文件浏览器中不会显示.../oslab/...但实际是要加上的。
3、添加export PATH=$PATH:/home/osla...x-ubuntu14/bin时,要添加在最后一行。
4、编辑完.bashrc并保存后,需要重启terminal,才会生效。

Copy link

关于riscv64-unknown-elf-gdb,对于我而言除了@lu-yidan 的方法,还要对riscv64-unknown-elf-gcc-8.3.0-2020.04.1-x86_64-linux-ubuntu14 chmod -R 777 一下

Copy link

麻烦请问启动 Qemu 并加载 RustSBI 和内核镜像出现以下报错可能是什么原因呢?

qemu-system-riscv64 \

-machine virt
-nographic
-bios ../bootloader/rustsbi-qemu.bin
-device loader,file=target/riscv64gc-unknown-none-elf/release/os.bin,addr=0x80200000
-s -S
qemu-system-riscv64: Unable to load the RISC-V firmware "../bootloader/rustsbi-qemu.bin"

@wuyuesong
Copy link

麻烦请问启动 Qemu 并加载 RustSBI 和内核镜像出现以下报错可能是什么原因呢?

qemu-system-riscv64 \

-machine virt
-nographic
-bios ../bootloader/rustsbi-qemu.bin
-device loader,file=target/riscv64gc-unknown-none-elf/release/os.bin,addr=0x80200000
-s -S
qemu-system-riscv64: Unable to load the RISC-V firmware "../bootloader/rustsbi-qemu.bin"

可能是目录下没有bootloader文件,可以从ch1分支的代码中复制一份

Copy link

ch1 ..为什么我没看到有 ch1 的分支。。

Copy link

原来我down错仓库了。。把 python 文档的那个仓库下载了。。。抱歉,找到了

Copy link

stat target/riscv64gc-unknown-none-elf/release/os
File: target/riscv64gc-unknown-none-elf/release/os
Size: 1016 Blocks: 8 IO Block: 4096 regular file


为什么我的是 Size: 5240,而课件里的是 Size: 1016...

$ stat target/riscv64gc-unknown-none-elf/release/os
  File: target/riscv64gc-unknown-none-elf/release/os
  Size: 5240            Blocks: 16         IO Block: 4096   regular file
Device: a5h/165d        Inode: 1187295     Links: 2
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-28 13:02:28.913213000 +0000
Modify: 2022-03-27 15:00:03.103959000 +0000
Change: 2022-03-27 15:00:03.112959000 +0000
 Birth: -

Copy link

qi-xmu commented Apr 4, 2022

wsl2环境遇到riscv64-unknown-elf-gdb缺失问题,可以按如下方法解决,具体思路是下载与编译工具链,并添加到环境变量中。

# 下载预编译文件
wget https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz

后面是解压和添加环境变量,最后需要source ~/.bashrc

Copy link

我在gdb-py加载dashboard的时候遇到了这个问题undefined symbol: PyFloat_Type。请问有人遇到过吗?如何解决的呢?
工具链新的旧的都试过了,还是一样。

➜  bin riscv64-unknown-elf-gdb-py --batch -ex 'python import sys; print(sys.version)'
Traceback (most recent call last):
  File "<string>", line 33, in <module>
ImportError: /home/****/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/python/lib/python3.7/lib-dynload/math.cpython-37m-x86_64-linux-gnu.so: undefined symbol: PyFloat_Type
/home/****/.gdbinit:2318: Error in sourced command file:
Error while executing Python code.
3.7.7 (default, Jul  6 2020, 09:36:26)
[GCC 5.4.0 20160609]

Copy link

ubuntu 下 riscv64-unknown-elf-gdb 可以用 gdb-multiarch 代替

@yangyue-1993
Copy link

yangyue-1993 commented Jan 12, 2023 via email

@OctopusWen
Copy link

OctopusWen commented Jan 12, 2023 via email

Copy link

wsl2 ubuntu 22.04 配置了gdb调试环境以后, 当启动qemu `qemu-system-riscv64 \

-machine virt \

-nographic \

-bios ../bootloader/rustsbi-qemu.bin \

-device loader,file=target/riscv64gc-unknown-none-elf/release/os.bin,addr=0x80200000 \

-s -S`后,gdb无法连接上, `riscv64-unknown-elf-gdb     -ex 'file target/riscv64gc-unknown-none-elf/release/os'     -ex 'set arch riscv:rv64'     -ex 'target remote localhost:1234'`,提示`Reading symbols from target/riscv64gc-unknown-none-elf/release/os...

The target architecture is set to "riscv:rv64".
localhost:1234: Connection timed out.`,可能是什么原因引起的呢

Copy link

xukp20 commented Feb 8, 2023

@fengyeall111 也许是qemu没有在1234端口?我在直接使用文档中的qemu指令启动qemu时,默认监听的端口不是1234。-s 选项换成

-gdb tcp::1234

能指定1234端口,其他不变,gdb在1234端口能够连接上

Copy link

TD-Sky commented Feb 9, 2023

0x80200000打完断点,却无法持续执行到该位置的朋友,检查一下自己的qemu版本,若是7.2.x,通过 https://github.com/rustsbi/rustsbi-qemu 编译出支持 qemu-7.2 的 rustsbi-qemu.bin,作为启动的bootloader

Copy link

AnlangA commented Mar 18, 2023

大哥大姐萌,我没有../bootloader/rustsbi-qemu.bin",我该去哪找啊,

@wyfcyx
Copy link
Collaborator

wyfcyx commented Mar 18, 2023

@AnlangA 可以直接在我们的代码仓库里面找到,每个分支上都有一份。比如这里

@wyfcyx wyfcyx added the comments An area where readers can discuss related topics after every article. label Jun 2, 2023
Copy link

也可以用 vscode 直接连接查看 ,这个配置:

{
    // 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": "rcore-os",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/hn/code/rCore-Tutorial-v3/os/target/riscv64gc-unknown-none-elf/debug/os",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "miDebuggerPath": "/usr/bin/riscv64-unknown-elf-gdb", //riscv64-unknown-elf-gdb 位置
            "miDebuggerServerAddress": "localhost:1234" // gdb server 地址
        }
    ]
}

Copy link

能夠使用以下指令進行連接,使用起來挺方便的
gdb-multiarch --ex "target remote:1234"

Copy link

Instead of copying the boot loader directory, how can I create my very own boot loader from the rustSBI repository?

Copy link

xuanz20 commented Aug 17, 2023

关于调整内核的内存布局,补充一下:
我们默认的链接器的内存布局是独立地址空间,可以通过来查看
rust-objdump -S target/riscv64gc-unknown-none-elf/debug/os --section-headers

target/riscv64gc-unknown-none-elf/debug/os:     file format elf64-littleriscv

Sections:
Idx Name              Size     VMA              Type
  0                   00000000 0000000000000000 
  1 .text             00000004 0000000000011120 TEXT
  2 .debug_aranges    00000030 0000000000000000 DEBUG
  3 .riscv.attributes 00000035 0000000000000000 
  4 .debug_abbrev     000000f6 0000000000000000 DEBUG
  5 .debug_info       000005bf 0000000000000000 DEBUG
  6 .debug_str        0000049e 0000000000000000 DEBUG
  7 .debug_pubnames   000000bb 0000000000000000 DEBUG
  8 .debug_pubtypes   0000036c 0000000000000000 DEBUG
  9 .debug_frame      00000038 0000000000000000 DEBUG
 10 .debug_line       0000004d 0000000000000000 DEBUG
 11 .comment          00000013 0000000000000000 
 12 .symtab           00000930 0000000000000000 
 13 .shstrtab         000000a9 0000000000000000 
 14 .strtab           0000003e 0000000000000000 

Disassembly of section .text:

0000000000011120 <_start>:
   11120: 93 00 40 06   li      ra, 100

可以看到这并不符合QEMU的内存布局,因此需要我们手动调整内存布局,使用链接脚本后再查看:

target/riscv64gc-unknown-none-elf/release/os:   file format elf64-littleriscv

Sections:
Idx Name              Size     VMA              Type
  0                   00000000 0000000000000000 
  1 .text             00000004 0000000080200000 TEXT
  2 .bss              00000000 0000000080201000 BSS
  3 .riscv.attributes 00000035 0000000000000000 
  4 .comment          00000013 0000000000000000 
  5 .symtab           00000168 0000000000000000 
  6 .shstrtab         00000041 0000000000000000 
  7 .strtab           0000007b 0000000000000000 

Disassembly of section .text:

0000000080200000 <stext>:
80200000: 93 00 40 06   li      ra, 100

Copy link

config文件中的首行 // os/.cargo/config 是不是应该改为 # os/.cargo/config ,使用WSL我改为#才能编译通过

Copy link

dinduck commented Oct 16, 2023

ld to 24(t0),这是一条M指令, 从内存中取数存如寄存器, 这里表达将 t0 储存的地址偏移24后的地址储存的数据储存至t0寄存器

Copy link

之前不太理解为什么会有短跳转,长跳转这类的概念,看了绝对地址和相对地址的分析,终于明白了

Copy link

etigan commented Nov 8, 2023

ArchLinux 执行$ riscv64-unknown-elf-gdb命令报:

riscv64-unknown-elf-gdb: command not found

解决办法:安装 RISC-V 工具集

$ git clone https://github.com/riscv/riscv-gnu-toolchain

$ cd riscv-gnu-toolchain

# /home/kay/tools/riscv-gnu-toolchain 为安装目录
$ ./configure --prefix=/home/kay/tools/riscv-gnu-toolchain

# riscv-gnu-toolchain 目录下
$ make

$ make install clean

# 添加环境变量
# 编辑 .bashrc 文件,添加:
export PATH=/home/kay/tools/riscv-gnu-toolchain/bin:$PATH

# 刷新
$ source ./.bashrc

@etigan
Copy link

etigan commented Dec 18, 2023 via email

Copy link

一直卡在这个地方是什么原因导致的?无法跳转到0x80200000断点地址。
0x0000000000001000 in ?? ()
(gdb) x/10i $pc
=> 0x1000: auipc t0,0x0
0x1004: addi a1,t0,32
0x1008: csrr a0,mhartid
0x100c: ld t0,24(t0)
0x1010: jr t0
0x1014: unimp
0x1016: unimp
0x1018: unimp
0x101a: 0x8000
0x101c: unimp
(gdb) si
0x0000000000001004 in ?? ()
(gdb) si
0x0000000000001008 in ?? ()
(gdb) si
0x000000000000100c in ?? ()
(gdb) si
0x0000000000001010 in ?? ()
(gdb) si
0x0000000080000000 in ?? ()
(gdb) p/x $t0
$1 = 0x80000000
(gdb) si
0x0000000080000004 in ?? ()
(gdb) x/10i $pc
=> 0x80000004: jalr 834(ra)
0x80000008: auipc ra,0x0
0x8000000c: jalr 116(ra)
0x80000010: j 0x80001690
0x80000014: unimp
0x80000016: addi sp,sp,-80
0x80000018: sd ra,72(sp)
0x8000001a: ld a1,40(a0)
0x8000001c: ld a2,32(a0)
0x8000001e: addi a3,sp,64
(gdb) si
0x0000000080002342 in ?? ()
(gdb) si
0x0000000080002346 in ?? ()
(gdb) b *0x80200000
Breakpoint 1 at 0x80200000
(gdb) c
Continuing.

Copy link

我在单步调试时得到的结果如下:(地址在单步执行5次后跳转)
(gdb) x/10i $pc
=> 0x1000: auipc t0,0x0
0x1004: addi a2,t0,40
0x1008: csrr a0,mhartid
0x100c: ld a1,32(t0)
0x1010: ld t0,24(t0)
0x1014: jr t0
0x1018: unimp
0x101a: 0x8000
0x101c: unimp
0x101e: unimp
(gdb) si
0x0000000000001004 in ?? ()
(gdb) si
0x0000000000001008 in ?? ()
(gdb) si
0x000000000000100c in ?? ()
(gdb) si
0x0000000000001010 in ?? ()
(gdb) p/x $t0
$1 = 0x1000
(gdb) si
0x0000000000001014 in ?? ()
(gdb) p/x $t0
$2 = 0x80000000

Copy link

使用main分支下bootloader下的rustsbi-qemu.bin 可以解决。 一直卡住,不运行的问题

Copy link

我与main分支下的rustsbi-qemu.bin是一样的,且切到main分支也测试过。还是一样的问题

Copy link

@1059915154 你从github上下一个新的下来试试, 我就是下的新的替换了, 可以的。 大小是32Kb

Copy link

试了一下,链接器脚本可以改成这样
SECTIONS
{
.text : {
(.text.)
}

.rodata : {
    *(.rodata)
}

.data : {
    *(.data)
}

.bss : {
    *(.bss.stack)
    sbss = .;
    *(.bss .bss.*)
    *(.sbss .sbss.*)
}

ebss = .;

}

Copy link

有个困惑,既然链接脚本已经指定好0x80200000的地址,那为什么在没有做strip的时候,那些元数据会导致第一条指令会从0x80200000的地方被挤走呢?难道说,RustSBI无法从.bin文件的信息中,聪明地跳过“元数据”,直接把entry代码拷贝到0x80200000的位置上?

Copy link

脑袋看炸了

Copy link

“有个困惑,既然链接脚本已经指定好0x80200000的地址,那为什么在没有做strip的时候,那些元数据会导致第一条指令会从0x80200000的地方被挤走呢?难道说,RustSBI无法从.bin文件的信息中,聪明地跳过“元数据”,直接把entry代码拷贝到0x80200000的位置上?”

rustSBI加载不会解析elf格式,而且也不确定你的bin文件是否不是其他格式,如果解析,那RustSBI的代码量会增加,所以最简单的方式就是直接当成裸指令格式,直接jmp到那个地址。 你只需要将你要执行的第一条直连放在那个位置即可

Copy link

k997 commented Feb 9, 2025

srodata/erodata 建议换成start_of_rodata/ end_of_rodata,新手容易搞混srodata(Start of Read-Only DATA)和 .srodata (Small Read-Only DATA)。同理还有 sdata.sdata

 /* 
srodata(Start of Read-Only DATA),输出段,链接脚本中用户自定义的符号
.srodata(Small Read-Only DATA),输入段,编译器生成的段类型,专用于存储小于8字节的常量数据
*/
    srodata = .;
    .rodata : {

        *(.rodata .rodata.*)
        *(.srodata .srodata.*)
    }
    . = ALIGN(4K)
    erodata = .;

@zhangzhuang15
Copy link

zhangzhuang15 commented Feb 9, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comments An area where readers can discuss related topics after every article.
Projects
None yet
Development

No branches or pull requests