{"id":92173,"date":"2020-05-14T04:54:34","date_gmt":"2020-05-13T20:54:34","guid":{"rendered":"http:\/\/4563.org\/?p=92173"},"modified":"2020-05-14T04:54:34","modified_gmt":"2020-05-13T20:54:34","slug":"6-828-lab1-exercise-2-%e6%ad%bb%e5%be%aa%e7%8e%af%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=92173","title":{"rendered":"6.828 lab1 Exercise 2 \u6b7b\u5faa\u73af\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  6.828 lab1 Exercise 2 \u6b7b\u5faa\u73af\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dogedoge <\/span>  <span><i><\/i> 18<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>https:\/\/pdos.csail.mit.edu\/6.828\/2018\/labs\/lab1\/<\/p>\n<p>\u7248\u672c\uff1a<\/p>\n<ul>\n<li><code>qemu<\/code>\uff1aQEMU emulator version 1.5.3 (qemu-kvm-1.5.3-167.el7_7.4), Copyright (c) 2003-2008 Fabrice Bellard<\/li>\n<li><code>centos<\/code>\uff1aCentOS-7-x86_64-Minimal-1908<\/li>\n<li><code>gdb<\/code>\uff1aGNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-115.el7<\/li>\n<\/ul>\n<p><strong>The ROM BIOS<\/strong> \u8fd9\u4e2a\u7ae0\u8282\uff0cA \u7a97\u53e3 <code>make qemu-gdb<\/code>\uff0cB \u7a97\u53e3 <code>make gdb<\/code><\/p>\n<p>A\uff1a<\/p>\n<pre><code>\/usr\/libexec\/qemu-kvm -drive file=obj\/kern\/kernel.img,index=0,media=disk,format=raw -serial mon:stdio -gdb tcp::25000 -D qemu.log  -S VNC server running on `::1:5900' <\/code><\/pre>\n<p>B <code>si<\/code> \u5355\u6b65\u8c03\u8bd5:<\/p>\n<pre><code>[f000:fff0]    0xffff0: ljmp   $0xf000,$0xe05b [f000:e05b]    0xfe05b: cmpl   $0x0,%cs:0x69c8 [f000:e062]    0xfe062: jne    0xfd0f7 [f000:e066]    0xfe066: xor    %dx,%dx [f000:e068]    0xfe068: mov    %dx,%ss [f000:e070]    0xfe070: mov    $0xf1399,%edx [f000:e076]    0xfe076: jmp    0xfcf8c [f000:cf8c]    0xfcf8c: cli [f000:cf8d]    0xfcf8d: cld [f000:cf8e]    0xfcf8e: mov    %eax,%ecx [f000:cf91]    0xfcf91: mov    $0x8f,%eax [f000:cf97]    0xfcf97: out    %al,$0x70 [f000:cf9b]    0xfcf9b: in     $0x92,%al [f000:cf9d]    0xfcf9d: or     $0x2,%al [f000:cf9f]    0xfcf9f: out    %al,$0x92 [f000:cfa4]    0xfcfa4: lidtw  %cs:0x69b8 [f000:cfaa]    0xfcfaa: lgdtw  %cs:0x6974 [f000:cfb0]    0xfcfb0: mov    %cr0,%ecx [f000:cfb3]    0xfcfb3: and    $0x1fffffff,%ecx [f000:cfba]    0xfcfba: or     $0x1,%ecx [f000:cfbe]    0xfcfbe: mov    %ecx,%cr0 <\/code><\/pre>\n<p>\u5207\u5165 PE \u4e4b\u540e\uff1a<\/p>\n<pre><code>The target architecture is assumed to be i386 =&gt; 0xfcfc9:     mov    $0x10,%ecx =&gt; 0xfcfce:     mov    %ecx,%ds =&gt; 0xfcfd0:     mov    %ecx,%es =&gt; 0xfcfd2:     mov    %ecx,%ss =&gt; 0xfcfd6:     mov    %ecx,%gs =&gt; 0xfcfd8:     jmp    *%edx =&gt; 0xf1399:     sub    $0x8,%esp =&gt; 0xf139c:     movl   $0xf4254,0x4(%esp) =&gt; 0xf13a4:     movl   $0xf390a,(%esp) =&gt; 0xf13ab:     call   0xee4dd =&gt; 0xee4dd:     lea    0x8(%esp),%ecx =&gt; 0xee4e1:     mov    0x4(%esp),%edx =&gt; 0xee4e5:     mov    $0xf4200,%eax =&gt; 0xee4ea:     call   0xedd5a =&gt; 0xedd5a:     push   %ebp =&gt; 0xedd5b:     push   %edi =&gt; 0xedd5c:     push   %esi =&gt; 0xedd5d:     push   %ebx =&gt; 0xedd5e:     sub    $0xc,%esp =&gt; 0xedd61:     mov    %eax,%ebx =&gt; 0xedd63:     mov    %edx,0x4(%esp) =&gt; 0xedd67:     mov    %ecx,%ebp =&gt; 0xedd69:     mov    0x4(%esp),%esi =&gt; 0xedd6d:     movsbl (%esi),%edx =&gt; 0xedd70:     test   %dl,%dl =&gt; 0xedd72:     je     0xedfb6 =&gt; 0xedd78:     cmp    $0x25,%dl =&gt; 0xedd7b:     jne    0xede1b =&gt; 0xede1b:     mov    %ebx,%eax =&gt; 0xede1d:     call   0xec570 =&gt; 0xec570:     mov    %eax,%ecx =&gt; 0xec572:     movsbl %dl,%edx =&gt; 0xec575:     call   *(%ecx) =&gt; 0xec565:     mov    %edx,%eax =&gt; 0xec567:     mov    0xf683c,%dx =&gt; 0xec56e:     out    %al,(%dx) =&gt; 0xec577:     ret  =&gt; 0xede22:     jmp    0xedfaa =&gt; 0xedfaa:     lea    0x1(%esi),%eax =&gt; 0xedfad:     mov    %eax,0x4(%esp) =&gt; 0xedfb1:     jmp    0xedd69 =&gt; 0xedd69:     mov    0x4(%esp),%esi =&gt; 0xedd6d:     movsbl (%esi),%edx =&gt; 0xedd70:     test   %dl,%dl =&gt; 0xedd72:     je     0xedfb6 =&gt; 0xedd78:     cmp    $0x25,%dl =&gt; 0xedd7b:     jne    0xede1b =&gt; 0xede1b:     mov    %ebx,%eax =&gt; 0xede1d:     call   0xec570 =&gt; 0xec570:     mov    %eax,%ecx =&gt; 0xec572:     movsbl %dl,%edx =&gt; 0xec575:     call   *(%ecx) =&gt; 0xec565:     mov    %edx,%eax =&gt; 0xec567:     mov    0xf683c,%dx =&gt; 0xec56e:     out    %al,(%dx) =&gt; 0xec577:     ret ... <\/code><\/pre>\n<p>\u4e2d\u95f4\u9694\u5f00\u7684\u90a3\u4e00\u6bb5\u4e00\u76f4\u5230 <code>...<\/code> \u5c31\u662f\u6b7b\u5faa\u73af\uff0c\u4f46\u662f\u5982\u679c\u8fd9\u4e2a\u65f6\u5019 <code>c<\/code> continue \u7684\u8bdd A \u53c8\u53ef\u4ee5\u8fdb kernel\uff0c\u800c\u4e14\u8bd5\u4e86\u65ad\u70b9\uff0c\u5e76\u6ca1\u6709\u8fdb <code>0x7c00<\/code>\u3002<\/p>\n<p>\u627e\u5230\u4e00\u7bc7\uff1ahttps:\/\/stackoverflow.com\/questions\/11408041\/how-to-debug-the-linux-kernel-with-gdb-and-qemu\/33203642#33203642\uff0c\u628a A \u7a97\u53e3\u6362\u6210\u76f4\u63a5\u6267\u884c\uff1a<\/p>\n<pre><code>\/usr\/libexec\/qemu-kvm -drive file=obj\/kern\/kernel.img,index=0,media=disk,format=raw -serial mon:stdio -D qemu.log -S -s <\/code><\/pre>\n<p>\u5176\u5b9e\u5c31\u662f\u6362\u4e86 gdb TCP 1234 \u7aef\u53e3\uff0c\u7136\u540e\u6309\u7167 stackoverflow \u4e0a\u5728 B \u8fde 1234\uff1a<\/p>\n<pre><code>target remote localhost:1234 <\/code><\/pre>\n<p>\u6700\u7ec8 <code>si<\/code> \u8fd8\u662f\u8fdb\u4e86\u6b7b\u5faa\u73af&#8230; \u53e6\u5916\u8bd5\u4e86 <code>-bios<\/code> \u53c2\u6570\uff0c\u4e5f\u786e\u5b9e\u662f\u4f7f\u7528\u7684 <code>seabios.bin<\/code>\u3002<\/p>\n<p>\u5df2\u7ecf\u67e5\u4e0d\u52a8\u4e86\uff0c\u6c42\u5927\u4f6c\u89e3\u7b54~<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>6.828 lab1 Exerci&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/92173"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=92173"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/92173\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=92173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=92173"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=92173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}