当前位置: 首页 > news >正文

(undone) MIT6.S081 2023 学习笔记 (Day5: LAB4 traps)

LAB 网页:https://pdos.csail.mit.edu/6.S081/2023/labs/traps.html


任务1:RISC-V assembly (完成)

初步看问题要求,这是一道文科题(问答题)

在你的 xv6 仓库中有一个文件 user/call.c。执行 make fs.img 会对其进行编译,并生成一个可读的汇编版本文件 user/call.asm。

阅读 call.asm 中关于函数 g、f 和 main 的代码。RISC-V 的指令手册可以在参考页面中找到。请在 answers-traps.txt 文件中回答以下问题:

Q: Which registers contain arguments to functions? For example, which register holds 13 in main’s call to printf?
A: 根据题意,我们先运行 make fs.img 生成 call.asm
随后阅读 user/call.c 和 user/call.asm 的代码,如下:
在这里插入图片描述
可以看到,储存函数参数的寄存器是 a0, a1, a2。其中,储存整数 13 的寄存器是 a2

Q: Where is the call to function f in the assembly code for main? Where is the call to g? (Hint: the compiler may inline functions.)
A: main 函数的汇编代码中没有函数 f 和 g 的函数调用。它们在编译阶段被编译器优化掉了。

Q: At what address is the function printf located?
A:搜索 call.asm 中 printf 的位置,如下
在这里插入图片描述
可以看到是 0x64a

Q: What value is in the register ra just after the jalr to printf in main?
A: 运行 jalr 指令后,寄存器 ra 的值是 0x38。
方式:使用 make qemu-gdb 启动 xv6,随后对 0x34 (jalr指令的地址) 打断点。
启动 xv6 后,运行 call 程序,qemu-gdb 会停留在 0x34 处。
此时运行 si 命令,执行 0x34 的 jalr 指令,可以看到 pc 跳转到了 0x64a 处。
再运行 info registers ra,即可看到 ra 寄存器的值为 0x38

Q:

Run the following code.unsigned int i = 0x00646c72;printf("H%x Wo%s", 57616, &i);What is the output? Here's an ASCII table that maps bytes to characters.
The output depends on that fact that the RISC-V is little-endian. If the RISC-V were instead big-endian what would you set i to in order to yield the same output? Would you need to change 57616 to a different value?Here's a description of little- and big-endian and a more whimsical description.

A:输出为 “He110 World”
如果 RISCV 是大端,那么 i 改为 0x726c6400
不需要修改 57616
(这里的回答不用太正确,反正不是代码)

Q:

In the following code, what is going to be printed after 'y='? (note: the answer is not a specific value.) Why does this happen?printf("x=%d y=%d", 3);

A: y= 后的数字是个垃圾数字 (junk value)。因为编译器仅仅给 a0 和 a1 寄存器赋值了,没有给 y=%d 的 %d 所对应的存储空间赋值


任务2:Backtrace (doing)

TODO: here

http://www.lryc.cn/news/520350.html

相关文章:

  • 前端笔记----
  • 学习华为熵减,激发组织活力
  • 9Hive数据倾斜
  • 【大数据】机器学习 -----关于data.csv数据集分析案例
  • 深入解析 C++ 类型转换
  • C++ union 联合(八股总结)
  • 聊聊AI Agent
  • scala代码打包配置(maven)
  • 慧集通(DataLinkX)iPaaS集成平台-业务建模之业务对象(二)
  • C++使用minio-cpp库在minio中创建bucket
  • 【大模型】大语言模型的数据准备:构建高质量训练数据的关键指南
  • 【解决】okhttp的java.lang.IllegalStateException: closed错误
  • TCP-IP详解卷 TCP的超时与重传
  • Linux服务器查看【可用端口号连接】的命令和方式【netstat,ss,lsof】
  • 【WPS】【WORDEXCEL】【VB】实现微软WORD自动更正的效果
  • Attention计算中的各个矩阵的维度都是如何一步步变化的?
  • 【数模学习笔记】插值算法和拟合算法
  • 探索 C++ 与 LibUSB:开启 USB 设备交互的奇幻之旅
  • 二、模型训练与优化(4):模型优化-实操
  • 3D可视化产品定制,应用于哪些行业领域?
  • Avalonia 入门笔记(零):概述
  • Unity TextMesh Pro入门
  • [论文阅读] (35)TIFS24 MEGR-APT:基于攻击表示学习的高效内存APT猎杀系统
  • 12 USART串口通讯
  • CF 368A.Sereja and Coat Rack(Java实现)
  • 清华大学、字节跳动等单位联合发布最新视觉语言动作模型RoboVLMs
  • 网络安全、Web安全、渗透测试之笔经面经总结
  • .NET Core NPOI 导出图片到Excel指定单元格并自适应宽度
  • python bs4 selenium 查找a href=javascript:();的实际点击事件和url
  • 三 BH1750 光感驱动调试1