type
status
date
slug
summary
tags
category
icon
password
PA2.2学习日志
AM相关

分析应该是通过改make file来将 CONFIG_TARGET_AM的选项打开,但在AM的makefile中添加如下代码并不行,留到后面再思考吧。
尝试,但未成功

直接修改默认值了

使用 riscv-test-am测试的结果

实现库函数中 srtcmp和memcmp借鉴了网上的代码,其他库函数似乎可以通过;
可以通过string的test,但是其他库函数有可能会出错。

现存问题,riscv-test中的div等,执行时会报出异常。导致结果不过。
疑惑:在am-kernal中执行make是怎么导致nemu也重新编译的???
找到了,在下面的链接中,直接批处理的方式也找到了 —09.08
09.08看了一天只看懂了itrace 是怎么实现的。
下面准备实现iring buf;
09.09-09.22 个人变动加中秋节,项目短暂停滞。不能隔太久,太久就都忘记了。
12.15 重启
基础设施部分,开始。
在cpu/ 下创建了trace.c文件,同时创建了trace.h文件。
在cpu/cpu-exec.c中进行调用。
如果在sdb中故意触发Assert错误,可以大体验证该功能正确
专门设置 输入 si 199时触发Assert错误,此时除了打印寄存器值之外,还打印了环形缓冲器的值。该设置在提交时被注释。


经过参考完成mtrace 功能,扫描内容时,会打印读取的动作。
目前还没有实现写内存的动作,因此没有验证写入时的mtrace。

2025.1.7 尝试进行ftrace的开发,首先学习如何生成.elf文件。
gcc -o xxx.elf xxx.c 可以生成elf文件
readelf xxx.elf 将结果显示成文本


以下是16进制显示的elf内容

以下是readelf读出的内容

通过上述两个文件,字符串应该在rodata中。
为什么会这样?

ftrace开发时的bug,定义的符号表是全局变量
在monitor.c文件中采用结构体动态定义:
Symbol *symbol = NULL;
那么在trace.c中引用时,就要采用同样的方式定义:
extern Symbol *symbol;
一开始写成了extern Symbol[];就不能输出正确结果;
总结:结构体全局定义时需要格式对应:
如果初次定义采用动态定义,那其他文件引用时就需要采用相应形式:extern Symbol *symbol;
如果初次定义采用静态定义:Symbol symbol[10]; ,那其他文件引用时就需要采用相应形式:extern Symbol symbol[];
以上两种方式都可以。
完成ftrace接入


似乎是因为函数一直在递归,但是函数内调用函数并不会用jalr指令,但是第一个完整执行的晚点函数并调用ret指令返回的有可能在其他函数内。
冗余的符号表

左图为丢弃符号表后解析出的elf信息,右图为原信息。strtab被丢弃

丢弃符号表后仍然能运行。

如果将hello.o中的符号表丢弃,然后再链接,则链接报错

链接报错,无法运行。

似乎是在链接过程中需要使用符号表进行符号解析并重定向,没有符号表就不能完成重定向功能。
而链接完成后丢弃符号表并不影响程序执行。
如何生成native的可执行文件

首先解析ARCH的名称,将其存入$(ARCH)变量中

然后根据$(ARCH)分析是否需要交叉编译.

如果ARCH选择的是riscv32-nemu
则会包含riscv32-nemu的文件

并包含riscv32编译所需的文件

在之后的编译和链接过程中,就会使用前缀为 riscv64-linux-gnu- 相关的指令。
如果ARCH选择是native,则使用默认的编译和链接等命令,就会将可执行程序编译到linux平台下。
这是如何实现的?

在klib下的strxx.c中有条件编译选项:

如果有宏定义 __NATIVE__USE__KLIB__,则会编译klib中的字符处理函数,如果没有宏定义,则会寻找glibc中的字符处理函数。
编写更多的测试


编写makefile和验证文件,运行如下命令,无报错证明验证通过。

测试strcpy函数。


memcpy_test简单测试通过

memmove_test简单测试通过,使用了三层循环,输出巨多。


memcmp可以借助memcpy来进行测试,判断的区间同样分成三段,第一段和第三段未复制,cmp结果应该小于0,第二段复制,cmp结果应该等于0。
完成memcmp验证

完成strlen验证


native打印的数值如下,将下面数值整理至test程序中。

记录一个调试过程
make ALL=sprintf_test ARCH=native gdb 时原框架并不能进入调试状态,需要在am的makefile中加入-g选项。
同时要make clean 或着 换一个程序编译之后,再换回来。否则由于可能存在的增量编译使得新加的选项并不能生效。
需进行以下修改,否则可能无法全部生效。



通过sprintf测试

验证时还是找到了bug,起初itoa函数中并未对value起初等于0进行处理,导致sprintf只打印一个0时,不会将0写入到目的buffer中,导致错误。单独增加处理0的代码,测试既能通过。

Differential Testing
终于开始差分测试了,又到了曾经熟悉的内容,加油。