ics-nju-wl / icspa-public Goto Github PK
View Code? Open in Web Editor NEWICSPA for MOOC
ICSPA for MOOC
pa3-3 测试过程中遇到Segmentation fault
使用gdb调试有以下log:
Program received signal SIGSEGV, Segmentation fault.
__memcpy_sse2_unaligned () at ../sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S:667
667 ../sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S: No such file or directory.
(gdb) bt
#0 __memcpy_sse2_unaligned () at ../sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S:667
#1 0x0041b532 in hw_mem_read (len=, paddr=)
at src/memory/memory.c:20
#2 paddr_read (len=, paddr=) at src/memory/memory.c:35
#3 laddr_read (laddr=3221475392, len=4) at src/memory/memory.c:62
#4 0x0040612f in operand_read (opr=0x49f880 <opr_src>) at src/cpu/decode/operand.c:15
#5 0x0040c2cc in instr_execute_2op () at src/cpu/instr/mov.c:5
#6 0x0040cafd in mov_o2a_v (eip=204689, opcode=161 '\241') at src/cpu/instr/mov.c:21
#7 0x00405612 in exec_inst () at src/cpu/cpu.c:147
#8 0x0040568c in exec (n=) at src/cpu/cpu.c:71
#9 0x0041defa in cmd_c (args=0x434854 "") at src/monitor/ui.c:319
#10 ui_mainloop (autorun=1 '\001') at src/monitor/ui.c:319
#11 0x0041b38e in single_run (img_file_path=0x84b2400 <image_path> "./kernel/kernel.img",
elf_file_path=0x84b2000 <elf_path> "./testcase/bin/mov") at src/main.c:75
#12 0x004043f3 in main (argc=5, argv=0xbffff304) at src/main.c:158
(gdb) p/x 204689
$1 = 0x31f91
(gdb) p/x 3221475392
$2 = 0xc003d040
(gdb)
其中mov_o2a_v 这条指令地址是c0031f91,完整内容如下:
c0031f90 <__getreent>:
c0031f90: 55 push %ebp
c0031f91: a1 40 d0 03 c0 mov 0xc003d040,%eax
c0031f96: 89 e5 mov %esp,%ebp
c0031f98: 5d pop %ebp
c0031f99: c3 ret
c0031f9a: 66 90 xchg %ax,%ax
c0031f9c: 66 90 xchg %ax,%ax
c0031f9e: 66 90 xchg %ax,%ax
以上指令传递给 laddr_read 方法的参数是0xc003d040
由于此时kernel还没有设置开启内存分页模式(此时cpu.cr0.pg==0),所以直接继续调用paddr_read 和hw_mem_read ,方法参数依旧是0xc003d040,最终造成了段错误,
这个问题暂时还没有解决,还在持续跟进,不知老师可否有空指点下解决思路
有个疑问是关于PA-4-1中的 push %esp
指令,如果要运行成功,那么压入栈中的需要是旧的 esp
,可是按照手册的说法,压入栈中的是已经改变过的的 esp
手册上关于 push
指令的描述为
PUSH decrements the stack pointer by 2 if the operand-size attribute of the instruction is 16 bits; otherwise, it decrements the stack pointer by 4. PUSH then places the operand on the new top of stack, which is pointed to by the stack pointer.
意思应该是先改变esp
的值,再把源操作数的值放入新的esp指向的地方。
Float
类型没有 significand
属性,应该改成fraction
在alu.c文件中相关代码为:
void set_SF(uint32_t result, size_t data_size){
result = sign_ext(result & (0xFFFFFFFF >> (32 - data_size)), datasize);
cpu.eflags.SF = sign(result)
}
在alu_test.c种相关代码为:①断言处代码,②是定义SF标志位代码
但是我发现这两处代码均无错误,而alu.c 中的 sign() 函数在 include/cpu/alu.h中,源代码如下:
在这里可以看到,代码中的最终结果应该是32位的数据,然而标志位SF只是一位数据,所以需要将之转化为一位数据。
因此需要将之改变为:
#define sign(x) (((uint_32_t)(x) >> 31) == 1)
这样返回值为布尔类型、一位数据。但是如果只改变这一处会报redefine错误,因此,同时还需要将src/cpu/cpu.c 中定义的sign(x)作出同样的修改。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.