<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>ZH</title>
 <link href="http://zhanghang.github.com/atom.xml" rel="self"/>
 <link href="http://zhanghang.github.com"/>
 <updated>2013-06-22T22:51:56-07:00</updated>
 <id>http://zhanghang.github.com</id>
 <author>
   <name>ZH</name>
   <email>zh199111@gmail.com</email>
 </author>

 
 <entry>
   <title>投资</title>
   <link href="http://zhanghang.github.com/life/2013/06/23/invest"/>
   <updated>2013-06-23T00:00:00-07:00</updated>
   <id>http://zhanghang.github.com/life/2013/06/23/invest</id>
   <content type="html">&lt;p&gt;手边用了三年多的小白到了退居二线的年纪，该有什么替代它，成为我未来三年的主力了。&lt;/p&gt;

&lt;p&gt;夏雨渗进泥土，凉风吹进窗子般的操作感。&lt;/p&gt;

&lt;p&gt;&lt;img src='/assets/images/iMac.jpg' alt='iMac' /&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>旅行</title>
   <link href="http://zhanghang.github.com/life/2013/04/29/the-travel"/>
   <updated>2013-04-29T00:00:00-07:00</updated>
   <id>http://zhanghang.github.com/life/2013/04/29/the-travel</id>
   <content type="html">&lt;p&gt;&lt;img src='http://zhanghang.github.io/assets/images/wuzhen.jpg' alt='wuzhen' /&gt;&lt;/p&gt;

&lt;p&gt;一人玩了五天，花的自己的钱。&lt;/p&gt;

&lt;p&gt;整个旅途没怎么规划，4 月 20 号那天，在微博上看到朋友刚刚结束了六天的旅行，突然就心动了。我对自己说，诶，这事儿你也可以干啊。那就干吧。&lt;/p&gt;

&lt;p&gt;做完要出去玩的决定后，打电话咨询注意事项，看旅游攻略，一切就发生得很自然。&lt;/p&gt;

&lt;p&gt;早晨七点半的飞机，我前一天夜里就到了机场，加上感冒，生熬一夜，不舒服。22 号九点半到的杭州，按照计划跑到四眼井青年旅舍定了两天房间，倒在床上就睡了。&lt;/p&gt;

&lt;p&gt;四眼井青年旅舍很静，在动物园站，离西湖不远，做公交车三四站到苏堤。院里有几只花猫，会趁你吃早餐的时偷偷围过来，一个人出来玩，这些都是惊喜。酒吧里有桌上足球，台球，每晚睡前我都在那点杯热牛奶，一两天过去感冒好了大半。第一天服务生指着几种啤酒说『出来玩怎么能点牛奶呢。』，我带着鼻音说『感冒了，喝点热的。』&lt;/p&gt;

&lt;h2 id='id1'&gt;杭州&lt;/h2&gt;

&lt;p&gt;玩了三天，前三天阴雨多云，很适合一人逛西塘。&lt;/p&gt;

&lt;p&gt;刚到的那天，睡了一下午，晚上在四眼井青旅酒吧的沙发上制定行程，上网和朋友聊天&lt;sup id='fnref:1'&gt;&lt;a href='#fn:1' rel='footnote'&gt;1&lt;/a&gt;&lt;/sup&gt;。按照设想，我会认识几个青旅的朋友，痛快的聊一晚上，实际没有，一点说话的欲望都没有。&lt;/p&gt;

&lt;p&gt;第二天办了张杭州 Z 卡，租自行车逛西湖，从柳浪闻莺开始，在雷峰塔结束，整个西湖不会大到迷路，也不至于小到一天就能逛完。一天下来没有太大惊喜，就像在公园中逛了一天。&lt;/p&gt;

&lt;p&gt;第三天整个上午都靠在沙发上看电影&lt;sup id='fnref:2'&gt;&lt;a href='#fn:2' rel='footnote'&gt;2&lt;/a&gt;&lt;/sup&gt;，下午看着地图，想到还有一半西湖没去过，就又定了一天房间。骑着车沿着杨公堤向北而去。事实证明这个决定很正确。这个下午，我顺路去浙江大学图书馆体验了一下，很有学术气氛，和杭州其他地方一样，到处飘着花香，听雪姐说『浙大很NB啊，前两年超清华北大。稳居全国前三』。晚上奔西溪湿地骑了一小时车，可惜关门了，回来时候惊喜的路过支付宝大楼，晚上七点灯火通明。&lt;/p&gt;

&lt;h2 id='id2'&gt;乌镇&lt;/h2&gt;

&lt;p&gt;高铁到桐乡倒大巴再走路，路上荒凉，到处是经济开发区的标识牌，环境还没三线城市承德好，路上走着我一直在想干嘛要来这种地方，要不直接去上海或者回家吧，趁不是太晚还来得及。&lt;/p&gt;

&lt;p&gt;硬着头皮接着走到乌镇西栅，街干净了，建筑物不挤了，古镇的风格特色也有了。于是买票订房开始逛。&lt;/p&gt;

&lt;p&gt;整个旅途我都给自己留了很大改变余地，不到最后不会定下一步怎么走，那种知道只能玩三天，第四天回家的票已经买好的感觉就像看着课表，也许这辈子我跟 GTD 无缘。走之前前跟朋友聊过这个问题，她说『也是一种玩法』。&lt;/p&gt;

&lt;p&gt;在乌镇玩了两天，看了夜景，听了戏，回想下来印象最深的竟然是我所住的13号民宿对面粥店的骨头粥，其他的感慨道不大，乌镇西栅较商业。&lt;/p&gt;

&lt;p&gt;现在网络发达，到了才能看到的风景越来越少，旅行的意义更多是&lt;strong&gt;让自己充满陌生感，发现原来这件事我也可以做&lt;/strong&gt;。&lt;/p&gt;
&lt;div class='footnotes'&gt;&lt;hr /&gt;&lt;ol&gt;&lt;li id='fn:1'&gt;
&lt;p&gt;杭州在这天晚上开始下雨。&lt;/p&gt;
&lt;a href='#fnref:1' rev='footnote'&gt;&amp;#8617;&lt;/a&gt;&lt;/li&gt;&lt;li id='fn:2'&gt;
&lt;p&gt;『EVA Q』和『忍者之路』。&lt;/p&gt;
&lt;a href='#fnref:2' rev='footnote'&gt;&amp;#8617;&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>起床的方式</title>
   <link href="http://zhanghang.github.com/life/2012/11/18/the-way-i-get-up"/>
   <updated>2012-11-18T00:00:00-08:00</updated>
   <id>http://zhanghang.github.com/life/2012/11/18/the-way-i-get-up</id>
   <content type="html">&lt;p&gt;昨天学车起太早，补觉 12 小时后，才精神饱满，体力充沛。&lt;/p&gt;
&lt;p&gt;今早起床的方式很奇特，用意识去提高血压，身体像充电一样，耳朵能听到血液撞击血管的嗡嗡声（或者是生物电？），身体兴奋，困意退散。在继高二某个夏天的日子，我第二次做到了有意识控制肾上腺素。&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Mandelbrot Set</title>
   <link href="http://zhanghang.github.com/life/2012/11/18/mandelbrot-set"/>
   <updated>2012-11-18T00:00:00-08:00</updated>
   <id>http://zhanghang.github.com/life/2012/11/18/mandelbrot-set</id>
   <content type="html">&lt;p&gt;ifanr &lt;a href=&quot;http://www.ifanr.com/dasheng/197540&quot;&gt;你见过的最疯狂的代码是什么样的&lt;/a&gt; 一文中提到一段可以生成经典分形图 &lt;a href=&quot;http://en.wikipedia.org/wiki/Mandelbrot_set&quot;&gt;Mandelbrot Set&lt;/a&gt; 的 &lt;a href=&quot;http://preshing.com/20110926/high-resolution-mandelbrot-in-obfuscated-python&quot;&gt;Python 代码&lt;/a&gt; 。&lt;/p&gt;
&lt;p&gt;看起来很好玩，于是试着用 10 年的老 MacBook(2.26 GHz Intel Core 2 Duo ，4 GB 1333 MHz DDR3)渲染一幅分辨率 4096 X 3072 的。&lt;/p&gt;
&lt;p&gt;睡前开始，早上醒来刚好完成，花了 5 个小时，一个 37.7 MB 的 bmp，转换成 &lt;span class=&quot;caps&quot;&gt;PNG&lt;/span&gt; 后 4.9 MB 。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/mandelbrot_set.png&quot; width=&quot;800&quot;&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>JOS 实验一</title>
   <link href="http://zhanghang.github.com/dev/2012/10/15/JOS-Lab1"/>
   <updated>2012-10-15T00:00:00-07:00</updated>
   <id>http://zhanghang.github.com/dev/2012/10/15/JOS-Lab1</id>
   <content type="html">
		&lt;ol&gt;
			&lt;li&gt;Part 1: PC BootStrap&lt;/li&gt;
		&lt;/ol&gt;&lt;h4&gt;Exercise 1&lt;/h4&gt;
&lt;p&gt;Familiarize yourself with the assembly language materials available on &lt;a href=&quot;http://pdos.csail.mit.edu/6.828/2012/reference.html&quot;&gt;the 6.828 reference page&lt;/a&gt; . You don&amp;#8217;t have to read them now, but you&amp;#8217;ll almost certainly want to refer to some of this material when reading and writing x86 assembly.&lt;/p&gt;
&lt;p&gt;We do recommend reading the section &amp;#8220;The Syntax&amp;#8221; in &lt;a href=&quot;http://www.delorie.com/djgpp/doc/brennan/brennan_att_inline_djgpp.html&quot;&gt;Brennan&amp;#8217;s Guide to Inline Assembly&lt;/a&gt; . It gives a good (and quite brief) description of the AT&amp;amp;T assembly syntax we&amp;#8217;ll be using with the &lt;span class=&quot;caps&quot;&gt;GNU&lt;/span&gt; assembler in &lt;span class=&quot;caps&quot;&gt;JOS&lt;/span&gt;.&lt;/p&gt;
&lt;h4&gt;Exercise 2&lt;/h4&gt;
&lt;p&gt;Use GDB&amp;#8217;s si (Step Instruction) command to trace into the &lt;span class=&quot;caps&quot;&gt;ROM&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;BIOS&lt;/span&gt; for a few more instructions, and try to guess what it might be doing.You might want to look at &lt;a href=&quot;http://web.archive.org/web/20040404164813/members.iweb.net.au/~pstorr/pcbook/book2/book2.htm&quot;&gt;Phil Storrs I/O Ports Description&lt;/a&gt; , as well as other materials on the &lt;a href=&quot;http://pdos.csail.mit.edu/6.828/2012/reference.html&quot;&gt;6.828 reference materials page&lt;/a&gt; . No need to figure out all the details &amp;#8211; just the general idea of what the &lt;span class=&quot;caps&quot;&gt;BIOS&lt;/span&gt; is doing first.&lt;/p&gt;
&lt;h3&gt;Part 2: The Boot Loader&lt;/h3&gt;
&lt;h4&gt;Exercise 3&lt;/h4&gt;
&lt;p&gt;Take a look at the lab tools guide, especially the section on &lt;span class=&quot;caps&quot;&gt;GDB&lt;/span&gt; commands. Even if you&amp;#8217;re familiar with &lt;span class=&quot;caps&quot;&gt;GDB&lt;/span&gt;, this includes some esoteric &lt;span class=&quot;caps&quot;&gt;GDB&lt;/span&gt; commands that are useful for OS work.&lt;/p&gt;
&lt;p&gt;Set a breakpoint at address 0&amp;#215;7c00, which is where the boot sector will be loaded. Continue execution until that breakpoint. Trace through the code in boot/boot.S, using the source code and the disassembly file obj/boot/boot.asm to keep track of where you are. Also use the x/i command in &lt;span class=&quot;caps&quot;&gt;GDB&lt;/span&gt; to disassemble sequences of instructions in the boot loader, and compare the original boot loader source code with both the disassembly in obj/boot/boot.asm and &lt;span class=&quot;caps&quot;&gt;GDB&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Trace into bootmain() in boot/main.c, and then into readsect(). Identify the exact assembly instructions that correspond to each of the statements in readsect(). Trace through the rest of readsect() and back out into bootmain(), and identify the begin and end of the for loop that reads the remaining sectors of the kernel from the disk. Find out what code will run when the loop is finished, set a breakpoint there, and continue to that breakpoint. Then step through the remainder of the boot loader.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;在一切开始之前，我们要弄懂如何调用 gdb 调试运行在 qemu 虚拟的计算机中的系统。&lt;/p&gt;
&lt;p&gt;资料上说运行&lt;/p&gt;
&lt;pre&gt;
make qemu-gdb
&lt;/pre&gt;
&lt;p&gt;那么 make 是什么？为什么 qemu-gdb 作为参数就可以调试了？&lt;/p&gt;
&lt;pre&gt;
Make gets its knowledge of how to build your program from a file called the makefile, which lists each of the non-source files and how to compute it from other files. When you write a program, you should write a makefile for it, so that it is possible to use Make to build and install the program
&lt;/pre&gt;
&lt;p&gt;make 是个按照规则执行批处理操作的工具。&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;JOS&lt;/span&gt; 中规则文件叫 GNUmakefile，其中定义了编译、调用虚拟机、调试相关的规则，下面列出对我们这次实验有用的参数&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;make ``编译 &lt;span class=&quot;caps&quot;&gt;JOS&lt;/span&gt;``&lt;/li&gt;
	&lt;li&gt;make qemu ``调用配置 qemu 载入 &lt;span class=&quot;caps&quot;&gt;JOS&lt;/span&gt; 镜像``&lt;/li&gt;
	&lt;li&gt;make qemu-gdb ``调用配置 qemu 载入 &lt;span class=&quot;caps&quot;&gt;JOS&lt;/span&gt; 镜像并连接 &lt;span class=&quot;caps&quot;&gt;GDB&lt;/span&gt; 供调试``&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;问题弄懂后开始实践，切换到JOS源代码目录&lt;/p&gt;
&lt;pre&gt;
make qemu-gdb
&lt;/pre&gt;
&lt;p&gt;打开另一个终端，运行 gdb&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/jos_gdb.png&quot; maxwidth=700&gt;&lt;/p&gt;
&lt;p&gt;然后一个新终端，运行 gdb 就可以开始调试了，我们可以运行很多命令，比如：&lt;/p&gt;
&lt;p&gt;在 0&amp;#215;7c00 处下断点&lt;/p&gt;
&lt;pre&gt;
b *0x7c00
&lt;/pre&gt;
&lt;p&gt;继续运行&lt;/p&gt;
&lt;pre&gt;
c
&lt;/pre&gt;
&lt;p&gt;下一步&lt;/p&gt;
&lt;pre&gt;
si
&lt;/pre&gt;
&lt;hr /&gt;
&lt;p&gt;Be able to answer the following questions:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;At what point does the processor start executing 32-bit code? What exactly causes the switch from 16- to 32-bit mode?&lt;/li&gt;
	&lt;li&gt;What is the last instruction of the boot loader executed, and what is the first instruction of the kernel it just loaded?&lt;/li&gt;
	&lt;li&gt;Where is the first instruction of the kernel?&lt;/li&gt;
	&lt;li&gt;How does the boot loader decide how many sectors it must read in order to fetch the entire kernel from disk? Where does it find this information?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;1. &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; 中有个寄存器叫 CR0，它 &lt;a href=&quot;http://en.wikipedia.org/wiki/Control_register#CR0&quot;&gt;每一位都是个标示符&lt;/a&gt; ，其中第 0 位用来标识 &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; 是运行在实时模式还是保护模式。所以从头开始找到修改 &lt;span class=&quot;caps&quot;&gt;CRO&lt;/span&gt; 第 0 位的代码也就找到了使 &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; 切换到 32 位的代码。&lt;/p&gt;
&lt;p&gt;计算机在启动后会调用 BIOS，它做完基础的系统初始化工作，比如检查内存容量后会把启动分区第一扇区的 bootloader 读到内存 0&amp;#215;7c00 处，交给 bootloader 控制权，执行它。&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;JOS&lt;/span&gt; 的 bootloader 由 /boot/boot.s 和 /boot/mian.c 两部分组成，当执行 bootloader 时首先运行的是 boot.s ，所以我们从这里开始看。&lt;/p&gt;
&lt;p&gt;找到&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;gas&quot;&gt;&lt;span class=&quot;c&quot;&gt;# Switch from real to protected mode, using a bootstrap GDT&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# and segment translation that makes virtual addresses &lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# identical to their physical addresses, so that the &lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# effective memory map does not change during the switch.&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;lgdt&lt;/span&gt;    &lt;span class=&quot;no&quot;&gt;gdtdesc&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;movl&lt;/span&gt;    &lt;span class=&quot;nv&quot;&gt;%cr0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;%eax&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;orl&lt;/span&gt;     &lt;span class=&quot;no&quot;&gt;$CR0_PE_ON&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;%eax&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;movl&lt;/span&gt;    &lt;span class=&quot;nv&quot;&gt;%eax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;%cr0&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Jump to next instruction, but in 32-bit code segment.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Switches processor into 32-bit mode.&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;ljmp&lt;/span&gt;    &lt;span class=&quot;no&quot;&gt;$PROT_MODE_CSEG&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;$protcseg&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;往前看到&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;gas&quot;&gt;&lt;span class=&quot;na&quot;&gt;.set&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;CR0_PE_ON&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;      &lt;span class=&quot;mi&quot;&gt;0x1&lt;/span&gt;         &lt;span class=&quot;c&quot;&gt;# protected mode enable flag&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;这就是把 CR0 的 0 位改为 1 ，使 &lt;span class=&quot;caps&quot;&gt;CPU&lt;/span&gt; 切换到 32 位保护模式的地方。&lt;/p&gt;
&lt;p&gt;2.阅读 boot.s 发现在最后它去运行了 main.c 中的 bootmain&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;gas&quot;&gt;&lt;span class=&quot;c&quot;&gt;# Set up the stack pointer and call into C.&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;movl&lt;/span&gt;    &lt;span class=&quot;no&quot;&gt;$start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;%esp&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;call&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;bootmain&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;bootmain，最后一行代码即 bootloader 最后一行代码&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;c1&quot;&gt;// call the entry point from the ELF header&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// note: does not return!&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ELFHDR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e_entry&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;整个 bootmain 做的事情就是把 &lt;span class=&quot;caps&quot;&gt;ELF&lt;/span&gt; 格式的内核镜像载入内存，然后去叫内核的入口，ELF 格式的详细信息前面的资料有。&lt;/p&gt;
&lt;p&gt;这时我们可以说 bootloader 最后一行代码就是去执行 e_entry 启动内核。&lt;/p&gt;
&lt;p&gt;那么内核第一句执行的是什么？&lt;br /&gt;
先看 main.c&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;cp&quot;&gt;#define ELFHDR		((struct Elf *) 0x10000) &lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;// scratch space&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;内核从内存 0&amp;#215;10000 开始。&lt;/p&gt;
&lt;p&gt;但&lt;/p&gt;
&lt;pre&gt;
objdump -x obj/kern/kernel
&lt;/pre&gt;
&lt;p&gt;看到&lt;/p&gt;
&lt;pre&gt;
SYMBOL TABLEL
f0100000 l     d .text 00000000 .text
f010000c g       .text 00000000 entry
&lt;/pre&gt;
&lt;p&gt;0xf01000c &amp;#8211; (0xf0100000 &amp;#8211; 0&amp;#215;00100000) = 0&amp;#215;0010000c 就是内核入口地址。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/jos_kernel_entry.png&quot; maxwidth=700&gt;&lt;/p&gt;
&lt;p&gt;内核执行的第一句代码是&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;gas&quot;&gt;&lt;span class=&quot;nf&quot;&gt;movw&lt;/span&gt;    &lt;span class=&quot;no&quot;&gt;$0x1234&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0x472&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;3. 内核第一句话在 obj/kern/Kernel.asm 中&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;gas&quot;&gt;&lt;span class=&quot;nl&quot;&gt;entry:&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;movw&lt;/span&gt;    &lt;span class=&quot;no&quot;&gt;$0x1234&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0x472&lt;/span&gt;     &lt;span class=&quot;c&quot;&gt;#warm boot&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;4.这个操作系统老实说 &lt;span class=&quot;caps&quot;&gt;ELF&lt;/span&gt; 这种格式决定了所有关于 sector 的信息都存在文件头了，bootmain 中把读入的头转换成了 Proghdr，里面就是 sector 的信息，具体以后添加。&lt;/p&gt;
&lt;h4&gt;Exercise 4&lt;/h4&gt;
&lt;p&gt;Read about programming with pointers in C. The best reference for the C language is The C Programming Language by Brian Kernighan and Dennis Ritchie (known as &amp;#8216;K&amp;amp;R&amp;#8217;). We recommend that students purchase this book (here is an &lt;a href=&quot;http://www.amazon.com/C-Programming-Language-2nd/dp/0131103628/sr=8-1/qid=1157812738/ref=pd_bbs_1/104-1502762-1803102?ie=UTF8&amp;amp;s=books&quot;&gt;Amazon Link&lt;/a&gt; ) or find one of &lt;a href=&quot;http://library.mit.edu/F/AI9Y4SJ2L5ELEE2TAQUAAR44XV5RTTQHE47P9MKP5GQDLR9A8X-10422?func=item-global&amp;amp;doc_library=MIT01&amp;amp;doc_number=000355242&amp;amp;year=&amp;amp;volume=&amp;amp;sub_library&quot;&gt;MIT&amp;#8217;s 7 copies&lt;/a&gt;= .&lt;/p&gt;
&lt;p&gt;Read 5.1 (Pointers and Addresses) through 5.5 (Character Pointers and Functions) in K&amp;amp;R. Then download the code for &lt;a href=&quot;http://pdos.csail.mit.edu/6.828/2012/labs/lab1/pointers.c&quot;&gt;pointers.c&lt;/a&gt; , run it, and make sure you understand where all of the printed values come from. In particular, make sure you understand where the pointer addresses in lines 1 and 6 come from, how all the values in lines 2 through 4 get there, and why the values printed in line 5 are seemingly corrupted.&lt;/p&gt;
&lt;p&gt;There are other references on pointers in C, though not as strongly recommended. &lt;a href=&quot;http://pdos.csail.mit.edu/6.828/2012/readings/pointers.pdf&quot;&gt;A tutorial by Ted Jensen&lt;/a&gt; that cites K&amp;amp;R heavily is available in the course readings.&lt;/p&gt;
&lt;p&gt;Warning: Unless you are already thoroughly versed in C, do not skip or even skim this reading exercise. If you do not really understand pointers in C, you will suffer untold pain and misery in subsequent labs, and then eventually come to understand them the hard way. Trust us; you don&amp;#8217;t want to find out what &amp;#8220;the hard way&amp;#8221; is.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;cp&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;1: a = %p, b = %p, c = %p&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;2: a[0] = %d, a[1] = %d, a[2] = %d, a[3] = %d&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
	   &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;300&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;301&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;302&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;3: a[0] = %d, a[1] = %d, a[2] = %d, a[3] = %d&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
	   &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;400&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;4: a[0] = %d, a[1] = %d, a[2] = %d, a[3] = %d&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
	   &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;5: a[0] = %d, a[1] = %d, a[2] = %d, a[3] = %d&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
	   &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;6: a = %p, b = %p, c = %p&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ac&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;av&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;输出结果为&lt;/p&gt;
&lt;pre&gt;
1: a = 0x7fff5e0fe4c0, b = 0x7fca114000e0, c = 0x7fff61701740
2: a[ 0 ] = 200, a[ 1 ] = 101, a[ 2 ] = 102, a[ 3 ] = 103
3: a[ 0 ] = 200, a[ 1 ] = 300, a[ 2 ] = 301, a[ 3 ] = 302
4: a[ 0 ] = 200, a[ 1 ] = 400, a[ 2 ] = 301, a[ 3 ] = 302
5: a[ 0 ] = 200, a[ 1 ] = 128144, a[ 2 ] = 256, a[ 3 ] = 302
6: a = 0x7fff5e0fe4c0, b = 0x7fff5e0fe4c4, c = 0x7fff5e0fe4c1
&lt;/pre&gt;
&lt;p&gt;其中&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;每个 int 占用 4 字节，而 char 占 1 字节，所以 （char *）a + 1 的结果为 a 后的 1 字节，再（int *）后，c 为指向由 a[ 0 ] 后 3 字节与 a[ 1 ] 组成的 int 的指针。&lt;/p&gt;
&lt;p&gt;观察&lt;/p&gt;
&lt;pre&gt;
6: a = 0x7fff5e0fe4c0, b = 0x7fff5e0fe4c4, c = 0x7fff5e0fe4c1
&lt;/pre&gt;
&lt;p&gt;结论得证。&lt;/p&gt;
&lt;h4&gt;Exercise 5&lt;/h4&gt;
&lt;p&gt;Trace through the first few instructions of the boot loader again and identify the first instruction that would &amp;#8220;break&amp;#8221; or otherwise do the wrong thing if you were to get the boot loader&amp;#8217;s link address wrong. Then change the link address in boot/Makefrag to something wrong, run make clean, recompile the lab with make, and trace into the boot loader again to see what happens. Don&amp;#8217;t forget to change the link address back and make clean again afterward!&lt;/p&gt;
&lt;h4&gt;Exercise 6&lt;/h4&gt;
&lt;p&gt;We can examine memory using GDB&amp;#8217;s x command. The &lt;span class=&quot;caps&quot;&gt;GDB&lt;/span&gt; manual has full details, but for now, it is enough to know that the command &lt;strong&gt;x/Nx &lt;span class=&quot;caps&quot;&gt;ADDR&lt;/span&gt;&lt;/strong&gt; prints N words of memory at &lt;strong&gt;&lt;span class=&quot;caps&quot;&gt;ADDR&lt;/span&gt;&lt;/strong&gt; . (Note that both &amp;#8217;x&amp;#8217;s in the command are lowercase.) Warning: The size of a word is not a universal standard. In &lt;span class=&quot;caps&quot;&gt;GNU&lt;/span&gt; assembly, a word is two bytes (the &amp;#8216;w&amp;#8217; in xorw, which stands for word, means 2 bytes).&lt;/p&gt;
&lt;p&gt;Reset the machine (exit &lt;span class=&quot;caps&quot;&gt;QEMU&lt;/span&gt;/&lt;span class=&quot;caps&quot;&gt;GDB&lt;/span&gt; and start them again). Examine the 8 words of memory at 0&amp;#215;00100000 at the point the &lt;span class=&quot;caps&quot;&gt;BIOS&lt;/span&gt; enters the boot loader, and then again at the point the boot loader enters the kernel. Why are they different? What is there at the second breakpoint? (You do not really need to use &lt;span class=&quot;caps&quot;&gt;QEMU&lt;/span&gt; to answer this question. Just think.)&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;BIOS&lt;/span&gt; 刚进入 boot loader 时，内存里只有 从 0&amp;#215;7c00 开始的 boot loader，它有（待填）大，0x00100000 空，boot loader 执行完把内核载入到从 0&amp;#215;10000 开始的地方，0x00100000 区域被用来放内核了，里面内容不再为空。Easy？&lt;/p&gt;
&lt;h3&gt;Part 3: The Kernel&lt;/h3&gt;
&lt;h4&gt;Exercise 7&lt;/h4&gt;
&lt;p&gt;Use &lt;span class=&quot;caps&quot;&gt;QEMU&lt;/span&gt; and &lt;span class=&quot;caps&quot;&gt;GDB&lt;/span&gt; to trace into the &lt;span class=&quot;caps&quot;&gt;JOS&lt;/span&gt; kernel and stop at the movl %eax, %cr0. Examine memory at 0&amp;#215;00100000 and at 0xf0100000. Now, single step over that instruction using the stepi &lt;span class=&quot;caps&quot;&gt;GDB&lt;/span&gt; command. Again, examine memory at 0&amp;#215;00100000 and at 0xf0100000. Make sure you understand what just happened.&lt;/p&gt;
&lt;p&gt;What is the first instruction after the new mapping is established that would fail to work properly if the mapping weren&amp;#8217;t in place? Comment out the movl %eax, %cr0 in kern/entry.S, trace into it, and see if you were right.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;gas&quot;&gt;&lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;eax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;%cr0&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;后启用了虚拟地址转换，然后 0xf0100000 就被映射成 0&amp;#215;0010000，所以都一样了。&lt;/p&gt;
&lt;h4&gt;Exercise 8&lt;/h4&gt;
&lt;p&gt;We have omitted a small fragment of code &amp;#8211; the code necessary to print octal numbers using patterns of the form &amp;#8220;%o&amp;#8221;. Find and fill in this code fragment.&lt;/p&gt;
&lt;p&gt;终于开始要写代码了，第一个问题非常简单，找到 printfmt.c 中的 vprintfmt 函数&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vprintfmt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;putch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;putdat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;va_list&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;里面处理了各种参数，很好玩的是，这个函数的实现用了 goto 语句，找到 case &amp;#8220;o&amp;#8221; ，这就是 8 进制相关的代码，照猫画虎，改成:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&amp;#39;o&amp;#39;&lt;/span&gt;:
	&lt;span class=&quot;n&quot;&gt;num&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getuint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lflag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;base&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;goto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;好了，我们的 print 函数升级了，重新运行 JOS，不开 debug，输出如下：&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/print_o.png&quot; maxwidth=700&gt;&lt;/p&gt;
&lt;pre&gt;
6828 decimal is 15254 octal!
&lt;/pre&gt;
&lt;p&gt;Be able to answer the following questions:&lt;/p&gt;
&lt;p&gt;1. Explain the interface between printf.c and console.c. Specifically, what function does console.c export? How is this function used by printf.c?&lt;/p&gt;
&lt;p&gt;printf.c 中的&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;putch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cnt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;cputchar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cnt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;调用了 console.c 中的 putch，它的功能就是和硬件打交道打印一个字符&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;c1&quot;&gt;// output a character to the console&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;cons_putc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;serial_putc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;lpt_putc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;cga_putc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;2. Explain the following from console.c:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;crt_pos&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CRT_SIZE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;memcpy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;crt_buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;crt_buf&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CRT_COLS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CRT_SIZE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CRT_COLS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;uint16_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CRT_SIZE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CRT_COLS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CRT_SIZE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;crt_buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x0700&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;crt_pos&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CRT_COLS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;3. For the following questions you might wish to consult the notes for Lecture 2. These notes cover GCC&amp;#8217;s calling convention on the x86.&lt;br /&gt;
Trace the execution of the following code step-by-step:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cprintf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;x %d, y %x, z %d&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
	&lt;li&gt;In the call to cprintf(), to what does fmt point? To what does ap point?&lt;/li&gt;
	&lt;li&gt;List (in order of execution) each call to cons_putc, va_arg, and vcprintf. For cons_putc, list its argument as well. For va_arg, list what ap points to before and after the call. For vcprintf list the values of its two arguments.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;fmt 指向 &amp;#8220;x %d, y %x, z %d\n&amp;#8221; 的头，也就是&amp;quot; &amp;quot; &amp;quot;，ap指向 xyz 所组成内存区域的头， 也就是 x。&lt;/p&gt;
&lt;p&gt;4. Run the following code.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x00646c72&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cprintf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;H%x Wo%s&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;57616&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;What is the output? Explain how this output is arrived at in the step-by-step manner of the previous exercise. Here&amp;#8217;s an &lt;span class=&quot;caps&quot;&gt;ASCII&lt;/span&gt; table that maps bytes to characters.&lt;br /&gt;
The output depends on that fact that the x86 is little-endian. If the x86 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?&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s a description of little- and big-endian and a more whimsical description.&lt;/p&gt;
&lt;p&gt;得到打印结果是&lt;/p&gt;
&lt;pre&gt;
He110 World!
&lt;/pre&gt;
&lt;p&gt;根据 &lt;span class=&quot;caps&quot;&gt;ASSIC&lt;/span&gt; 表查到 0&amp;#215;00646c72 对应：&lt;/p&gt;
&lt;pre&gt;
d     100 0144 0x64
l     108 0154 0x6c
r     114 0162 0x72
(nul)   0 0000 0x00
&lt;/pre&gt;
&lt;p&gt;57616 十六进制对应:&lt;/p&gt;
&lt;pre&gt;
e11
&lt;/pre&gt;
&lt;p&gt;看对应结果知道我们的机器是 big-endian.&lt;/p&gt;
&lt;p&gt;5. In the following code, what is going to be printed after &amp;#8216;y=&amp;#8217;? (note: the answer is not a specific value.) Why does this happen?&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;n&quot;&gt;cprintf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;x=%d y=%d&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;当 printfmt 的 ap 去找 y 的时候，那块内存区域没有被正确赋值，所以内容不是我们想要的。&lt;/p&gt;
&lt;p&gt;6. Let&amp;#8217;s say that &lt;span class=&quot;caps&quot;&gt;GCC&lt;/span&gt; changed its calling convention so that it pushed arguments on the stack in declaration order, so that the last argument is pushed last. How would you have to change cprintf or its interface so that it would still be possible to pass it a variable number of arguments?&lt;/p&gt;
&lt;h3&gt;The Stack&lt;/h3&gt;
&lt;h4&gt;Exercise 9&lt;/h4&gt;
&lt;p&gt;Determine where the kernel initializes its stack, and exactly where in memory its stack is located. How does the kernel reserve space for its stack? And at which &amp;#8220;end&amp;#8221; of this reserved area is the stack pointer initialized to point to?&lt;/p&gt;
&lt;p&gt;entry.S 中 stack 初值被设置为空指针 0&amp;#215;0&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;gas&quot;&gt;&lt;span class=&quot;c&quot;&gt;# Clear the frame pointer register (EBP)&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# so that once we get into debugging C code,&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# stack backtraces will be terminated properly.&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;movl&lt;/span&gt;    &lt;span class=&quot;no&quot;&gt;$0x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;%ebp&lt;/span&gt;           &lt;span class=&quot;c&quot;&gt;# nuke frame pointer&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Set the stack pointer&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;movl&lt;/span&gt;    &lt;span class=&quot;no&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;bootstacktop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;%esp&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# now to C code&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;call&lt;/span&gt;    &lt;span class=&quot;no&quot;&gt;i386_init&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;再看定义：&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;gas&quot;&gt;&lt;span class=&quot;na&quot;&gt;.data&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;###################################################################&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# boot stack&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;###################################################################&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;.p2align&lt;/span&gt;    &lt;span class=&quot;no&quot;&gt;PGSHIFT&lt;/span&gt;     &lt;span class=&quot;c&quot;&gt;# force page alignment&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;.globl&lt;/span&gt;      &lt;span class=&quot;no&quot;&gt;bootstack&lt;/span&gt;
&lt;span class=&quot;nl&quot;&gt;bootstack:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;.space&lt;/span&gt;      &lt;span class=&quot;no&quot;&gt;KSTKSIZE&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;.globl&lt;/span&gt;      &lt;span class=&quot;no&quot;&gt;bootstacktop&lt;/span&gt;   
&lt;span class=&quot;no&quot;&gt;bootstacktop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;stack 大小 &lt;span class=&quot;caps&quot;&gt;KSTKSIZE&lt;/span&gt; (32KB)，栈低就是 bootstacktop。&lt;/p&gt;
&lt;h4&gt;Exercise 10&lt;/h4&gt;
&lt;p&gt;To become familiar with the C calling conventions on the x86, find the address of the test_backtrace function in obj/kern/kernel.asm, set a breakpoint there, and examine what happens each time it gets called after the kernel starts. How many 32-bit words does each recursive nesting level of test_backtrace push on the stack, and what are those words?&lt;br /&gt;
Note that, for this exercise to work properly, you should be using the patched version of &lt;span class=&quot;caps&quot;&gt;QEMU&lt;/span&gt; available on the tools page or on Athena. Otherwise, you&amp;#8217;ll have to manually translate all breakpoint and memory addresses to linear addresses.&lt;/p&gt;
&lt;p&gt;这个在北京大学 &lt;span class=&quot;caps&quot;&gt;JOS&lt;/span&gt; 实验一中说的很清楚了，共 32bit 被压入栈中。&lt;/p&gt;
&lt;h4&gt;Exercise 11&lt;/h4&gt;
&lt;p&gt;Implement the backtrace function as specified above. Use the same format as in the example, since otherwise the grading script will be confused. When you think you have it working right, run make grade to see if its output conforms to what our grading script expects, and fix it if it doesn&amp;#8217;t. After you have handed in your Lab 1 code, you are welcome to change the output format of the backtrace function any way you like.&lt;/p&gt;
&lt;h4&gt;Exercise 12&lt;/h4&gt;
&lt;p&gt;Modify your stack backtrace function to display, for each eip, the function name, source file name, and line number corresponding to that eip.&lt;br /&gt;
In debuginfo_eip, where do __STAB_* come from? This question has a long answer; to help you to discover the answer, here are some things you might want to do:&lt;/p&gt;
&lt;pre&gt;
look in the file kern/kernel.ld for __STAB_*
run i386-jos-elf-objdump -h obj/kern/kernel
run i386-jos-elf-objdump -G obj/kern/kernel
run i386-jos-elf-gcc -pipe -nostdinc -O2 -fno-builtin -I. -MD -Wall -Wno- format -DJOS_KERNEL -gstabs -c -S kern/init.c, and look at init.s.
see if the bootloader loads the symbol table in memory as part of loading the kernel binary
Complete the implementation of debuginfo_eip by inserting the call to stab_binsearch to find the line number for an address.
Add a backtrace command to the kernel monitor, and extend your implementation of mon_backtrace to call debuginfo_eip and print a line for each stack frame of the form:

K&amp;gt; backtrace
Stack backtrace:
  ebp f010ff78  eip f01008ae  args 00000001 f010ff8c 00000000 f0110580 00000000
         kern/monitor.c:143: monitor+106
  ebp f010ffd8  eip f0100193  args 00000000 00001aac 00000660 00000000 00000000
         kern/init.c:49: i386_init+59
  ebp f010fff8  eip f010003d  args 00000000 00000000 0000ffff 10cf9a00 0000ffff
         kern/entry.S:70: &amp;lt;unknown&amp;gt;+0
K&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Each line gives the file name and line within that file of the stack frame&amp;#8217;s eip, followed by the name of the function and the offset of the eip from the first instruction of the function (e.g., monitor+106 means the return eip is 106 bytes past the beginning of monitor).&lt;br /&gt;
Be sure to print the file and function names on a separate line, to avoid confusing the grading script.&lt;br /&gt;
Tip: printf format strings provide an easy, albeit obscure, way to print non-null-terminated strings like those in ST &lt;span class=&quot;caps&quot;&gt;ABS&lt;/span&gt; tables. printf(&amp;#8220;%.*s&amp;#8221;, length, string) prints at most length characters of string. Take a look at the printf man page to find out why this works.&lt;br /&gt;
You may find that some functions are missing from the backtrace. For example, you will probably see a call to monitor() but not to runcmd(). This is because the compiler in-lines some function calls. Other optimizations may cause you to see unexpected line numbers. If you get rid of the -O2 from GNUMakefile, the backtraces may make more sense (but your kernel will run more slowly).&lt;br /&gt;
￼￼￼&lt;/p&gt;
&lt;p&gt;两个练习合起来一起做:&lt;/p&gt;
&lt;p&gt;eip_debuginfo 中实现查找行数的代码，具体为什么这么实现，实际上我就是按照代码注释说的逻辑翻译成代码。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;  &lt;span class=&quot;n&quot;&gt;stab_binsearch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stabs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;N_SLINE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;addr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lline&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eip_line&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;stabs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_desc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;￼&lt;/p&gt;
&lt;p&gt;在终端中加入 backrace 命令：&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Command&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;commands&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;help&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Display this list of commands&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mon_help&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;kerninfo&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Display information about the kernel&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mon_kerninfo&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;backtrace&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Display function stack one line at a time&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mon_backtrace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;￼&lt;/p&gt;
&lt;p&gt;弄明白 debuginfo_eip ，利用它实现 mon_backtrace：&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;c&quot;&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;mon_backtrace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Trapframe&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;uint32_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ebp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;uint32_t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read_ebp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Eipdebuginfo&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;cprintf&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Stack backtrace:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ebp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;cprintf&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot; ebp %08x eip %08x args %08x %08x %08x %08x %08x&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ebp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ebp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
                 &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ebp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ebp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ebp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ebp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ebp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;debuginfo_eip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ebp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;    
        &lt;span class=&quot;n&quot;&gt;cprintf&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;%s:%d: %.*s+%d&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eip_file&lt;/span&gt;
                    &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eip_line&lt;/span&gt;
                    &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eip_fn_namelen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eip_fn_name&lt;/span&gt;
                    &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ebp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eip_fn_addr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;ebp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;uint32_t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ebp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼￼&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;好了，这时候运行 :&lt;/p&gt;
&lt;pre&gt;
make grade
&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/lab1_grade.png&quot; maxwidth=700&gt;&lt;/p&gt;
&lt;p&gt;实验一完成。&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>学操作系统</title>
   <link href="http://zhanghang.github.com/dev/2012/10/13/JOS-Intro"/>
   <updated>2012-10-13T00:00:00-07:00</updated>
   <id>http://zhanghang.github.com/dev/2012/10/13/JOS-Intro</id>
   <content type="html">&lt;p&gt;大三了，这学期有一门完全翘不了的课叫“金工实习”，于是很少去公司转悠（每周一次）。不过有好有坏，有门讲操作系统的课，课程和老师都很有意思，我和几个同学一个小组跟着 &lt;a href=&quot;http://pdos.csail.mit.edu/6.828/2012/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;MIT&lt;/span&gt; 6.828 Operating System&lt;/a&gt; 一起，边学原理边写操作系统。&lt;/p&gt;
&lt;pre&gt;
6.828 teaches the fundamentals of engineering operating systems. You will study, in detail, virtual memory, kernel and user mode, system calls, threads, context switches, interrupts, interprocess communication, coordination of concurrent activities, and the interface between software and hardware. Most importantly, you will study the interactions between these concepts, and how to manage the complexity introduced by the interactions.
&lt;/pre&gt;
&lt;p&gt;课程实践分六个实验&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Booting&lt;/li&gt;
	&lt;li&gt;Memory management&lt;/li&gt;
	&lt;li&gt;User-level environments&lt;/li&gt;
	&lt;li&gt;Preemptive multitasking&lt;/li&gt;
	&lt;li&gt;File system and spawn&lt;/li&gt;
	&lt;li&gt;A shell&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;大概看了一下，从汇编到寄存器，从内存管理到分页策略啊什么的都要涉及。&lt;/p&gt;
&lt;p&gt;每个实验都涉及大量知识，我大二这一整年在公司没好好学汇编和计算机组成原理，准备知识上差一大截，借这个机会正好给补上。&lt;/p&gt;
&lt;p&gt;实验会用到 Git&lt;sup class=&quot;footnote&quot; id=&quot;fnr1&quot;&gt;&lt;a href=&quot;#fn1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;，于是我把整个实验放到了 &lt;a href=&quot;http://github.com/ZhangHang/JOS_2012&quot;&gt;Github&lt;/a&gt; 上，回顾比较方便。&lt;/p&gt;
&lt;p&gt;fn1: Git (/ɡɪt/) is a distributed revision control and source code management (&lt;span class=&quot;caps&quot;&gt;SCM&lt;/span&gt;) system with an emphasis on speed&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>面孔</title>
   <link href="http://zhanghang.github.com/doodle/2012/09/15/Face"/>
   <updated>2012-09-15T00:00:00-07:00</updated>
   <id>http://zhanghang.github.com/doodle/2012/09/15/Face</id>
   <content type="html">&lt;p&gt;&lt;img src=&quot;/assets/doodle/face.PNG&quot; width=700&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>鼠标</title>
   <link href="http://zhanghang.github.com/doodle/2012/09/14/Mouse"/>
   <updated>2012-09-14T00:00:00-07:00</updated>
   <id>http://zhanghang.github.com/doodle/2012/09/14/Mouse</id>
   <content type="html">&lt;p&gt;&lt;img src=&quot;/assets/doodle/mouse.PNG&quot; width=700&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>做七天阿米什人</title>
   <link href="http://zhanghang.github.com/life/2012/06/29/Amish-for-A-Week"/>
   <updated>2012-06-29T00:00:00-07:00</updated>
   <id>http://zhanghang.github.com/life/2012/06/29/Amish-for-A-Week</id>
   <content type="html">&lt;p&gt;今天是考前回家休息的第一天，无法完全静下来学习，人人网、新郎微博、Flipboard、Reeder、V2EX 翻了个遍。我这么一个自制力弱且有拖延症的人遇上考试，这么干是很合乎情理的&amp;#8230;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;我必须静下来，过两天清静日子。&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Kevin Kelly 在 『What Technology Wants』中提到生活在北美的阿米什人，过着尽量远离科技的生活，他们没有电视，没有互联网，拥有相对较少的选择，纯朴而满足。我相信 Kevin Kelly 说的不是鬼话，我遇到过几位没有 QQ，没有注册任何 SNS，联络用邮件的人，他们都活的好好的，那我也应该试试。&lt;/p&gt;
&lt;p&gt;计划如下：&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;封印除了 Path 外的 &lt;span class=&quot;caps&quot;&gt;SNS&lt;/span&gt;&lt;/li&gt;
	&lt;li&gt;删掉各类微博应用&lt;/li&gt;
	&lt;li&gt;每晚记录实验结果&lt;/li&gt;
	&lt;li&gt;除需要查资料和更新博客外不上网&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>Untitled</title>
   <link href="http://zhanghang.github.com/life/2012/05/21/Untitled"/>
   <updated>2012-05-21T00:00:00-07:00</updated>
   <id>http://zhanghang.github.com/life/2012/05/21/Untitled</id>
   <content type="html">&lt;p&gt;我就是压力再大也不会影响心情的人，早晨被老娘的电话叫起来后，泡了杯绿茶，天空整个被灰白的云罩住，我靠在木椅子上边喝茶边看 Flipboard。&lt;/p&gt;
&lt;p&gt;上班路上读到扎克伯格为了检测自制力「2009年整年带领带上班，去年只吃自己杀死的动物，今年重新开始学习编程」后想起自己年初定下的「180天不睡懒觉」这个基本完不成的大计划，它就要被完成了。&lt;/p&gt;
&lt;p&gt;望着前些日子麻烦的项目一个个按部就班排队被搞定，长得越来越快的胡子和我那烫破了皮儿的本儿，我才发现大二这一年过得可真够快的。&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>读完一本书</title>
   <link href="http://zhanghang.github.com/life/2012/04/23/book"/>
   <updated>2012-04-23T00:00:00-07:00</updated>
   <id>http://zhanghang.github.com/life/2012/04/23/book</id>
   <content type="html">&lt;p&gt;最近物欲膨胀，虽然在积极的简化生活，但还是有很强的被物质奴役的感觉，每次出门前对着的书包，我都会花上五分钟去想这回放什么。&lt;/p&gt;
&lt;p&gt;这个周末静下心来看继续看《松本行弘的程序世界》才意识到多久没有去看 &lt;b&gt;书&lt;/b&gt; ，而不是 &lt;span class=&quot;caps&quot;&gt;RSS&lt;/span&gt; 上的某篇文章。这时我不得不担心自己的大脑结构已经被互联网塑造成什么样子了。&lt;/p&gt;
&lt;p&gt;看到自己在豆瓣上标记为正在读状态的书是五本，是时候一本一本来了。&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>寒假实践报告</title>
   <link href="http://zhanghang.github.com/life/2012/03/05/winter-vacation"/>
   <updated>2012-03-05T00:00:00-08:00</updated>
   <id>http://zhanghang.github.com/life/2012/03/05/winter-vacation</id>
   <content type="html">&lt;h3&gt;做了&lt;/h3&gt;
&lt;ul&gt;
	&lt;li&gt;累计工作 25 个工作日，加班 1 天
	&lt;ul&gt;
		&lt;li&gt;累计上班总路程: 30&amp;#215;2&amp;#215;25 = 600 (公里)&lt;/li&gt;
		&lt;li&gt;累计上班时间: 9&amp;#215;25 = 225 (小时)&lt;/li&gt;
	&lt;/ul&gt;&lt;/li&gt;
	&lt;li&gt;一款用 C++ 写的移动软件
	&lt;ul&gt;
		&lt;li&gt;5000 多行代码&lt;/li&gt;
		&lt;li&gt;基于网络&lt;/li&gt;
		&lt;li&gt;用时半个月&lt;/li&gt;
	&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;写脚本在十几万条数据中匹配筛选
	&lt;ul&gt;
		&lt;li&gt;用的 Bash&lt;/li&gt;
		&lt;li&gt;grep&lt;/li&gt;
		&lt;li&gt;awk&lt;/li&gt;
		&lt;li&gt;sed&lt;/li&gt;
	&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;呼吸了一下午微软大楼里的空气，然后就滚了&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;学了&lt;/h3&gt;
&lt;ul&gt;
	&lt;li&gt;一点 Bash&lt;/li&gt;
	&lt;li&gt;一点编程思想&lt;/li&gt;
	&lt;li&gt;一点如何做人&lt;/li&gt;
	&lt;li&gt;一点 .&lt;span class=&quot;caps&quot;&gt;NET&lt;/span&gt; 和 C#&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;感悟了&lt;/h3&gt;
&lt;ul&gt;
	&lt;li&gt;别闹&lt;/li&gt;
	&lt;li&gt;要淡定&lt;/li&gt;
	&lt;li&gt;要谦虚&lt;/li&gt;
	&lt;li&gt;少说话多做事儿&lt;/li&gt;
	&lt;li&gt;不当家不知道油盐贵&lt;/li&gt;
	&lt;li&gt;一定得有那么一次翘课旅游&lt;/li&gt;
	&lt;li&gt;Android 弱爆了&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>Bada Form Manager</title>
   <link href="http://zhanghang.github.com/dev/2012/01/18/bada-formMgr"/>
   <updated>2012-01-18T00:00:00-08:00</updated>
   <id>http://zhanghang.github.com/dev/2012/01/18/bada-formMgr</id>
   <content type="html">&lt;p&gt;最近在接触移动应用方面的开发，入门没多久，随着深入，开始有了一点思考。&lt;/p&gt;
&lt;p&gt;“Form 切换”是每个移动软件开发者要面对的问题，如果这里实现的好了，心情会好很多。&lt;/p&gt;
&lt;h3&gt;曾经的实现&lt;/h3&gt;
&lt;image src=&quot;/assets/images/bada_form_old.png&quot;&gt;
&lt;p&gt;原理很简单，每个 Form 负责切换到相关 Form, 处理创建 Form、删除Form、传递参数给 Form的任务，逻辑很复杂，而且造成非常多的重复代码，浪费时间。&lt;br /&gt;
当 Form 种类，数量变多时，那就是梦魇。这不是一个好方法。&lt;/p&gt;
&lt;h3&gt;更好的实现&lt;/h3&gt;
&lt;p&gt;一个更好的办法？单独的 Form Manager 处理所有切换请求，&lt;/p&gt;
&lt;image src=&quot;/assets/images/bada_form_new.png&quot;&gt;
&lt;p&gt;它具有:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;方便的切换&lt;/li&gt;
	&lt;li&gt;自动清理不用的 Form&lt;/li&gt;
	&lt;li&gt;记录点击 Form 的历史&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;也就是说 FormMgr 会记录 Form 被创建的顺序。自动返回上一个 Form 并删除子 Form。&lt;/p&gt;
&lt;p&gt;Form 被创建的顺序放堆栈中来实现记录顺序的功能。&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>新的入口</title>
   <link href="http://zhanghang.github.com/dev/2012/01/15/new-entrance"/>
   <updated>2012-01-15T00:00:00-08:00</updated>
   <id>http://zhanghang.github.com/dev/2012/01/15/new-entrance</id>
   <content type="html">&lt;p&gt;刚刚放假，趁着一切都还没有开始，我为这里修建了一个新的入口&lt;a href=&quot;/entrance.html&quot;&gt;&lt;strong&gt; → &lt;/strong&gt;&lt;/a&gt;。&lt;/p&gt;
&lt;p&gt;一切都基于『钥匙』，不同的钥匙打开不同的门。&lt;br /&gt;
那里是我所创造的世界，它不会给你太多指引，它需要你探索。&lt;br /&gt;
入口处的告示牌会有小小的提示，比如钥匙的数量。&lt;/p&gt;
&lt;p&gt;现在拿着『ZH』这把钥匙去试试吧。&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>2011</title>
   <link href="http://zhanghang.github.com/life/2012/01/02/2011"/>
   <updated>2012-01-02T00:00:00-08:00</updated>
   <id>http://zhanghang.github.com/life/2012/01/02/2011</id>
   <content type="html">&lt;p&gt;除了外表，这一年一切都变了。&lt;/p&gt;
&lt;p&gt;不过这确实是我想要的，在不断的微小提升中获得幸福感。&lt;/p&gt;
&lt;p&gt;大家都在做并不说明你该去做，不是每天被梦想叫醒的话，那不是活着。&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Christmas</title>
   <link href="http://zhanghang.github.com/life/2011/12/25/Christmas"/>
   <updated>2011-12-25T00:00:00-08:00</updated>
   <id>http://zhanghang.github.com/life/2011/12/25/Christmas</id>
   <content type="html">&lt;p&gt;Christmas ，圣诞节，基督弥撒的简称。这天基督徒们举行特别的仪式庆祝耶稣的诞生。&lt;/p&gt;
&lt;p&gt;一如既往我什么也没有庆祝。用过三餐，喝了几杯咖啡，雀巢的。&lt;/p&gt;
&lt;p&gt;三天前，左手的中指、无名指、小拇指被一把非常锋利的剑割伤，小拇指肌腱部分断裂，如果事情发生时我再用一点力，恐怕肌腱会完全断裂，小拇指永远失去活动能力。&lt;/p&gt;
&lt;p&gt;这意外发生在一瞬间，刀刃瞬间划过表层皮肤，伴随巨大压力继续切入深处，这一切快到神经没来得及反应便被切断，没有痛感，流了这辈子最多的血。&lt;/p&gt;
&lt;p&gt;在未来的一到两年受伤的肌腱会逐渐长好，那是一段漫长的时间，足够一个人发生一次以上的巨变。&lt;/p&gt;
&lt;p&gt;&lt;b&gt;两年后，我应该会在圣诞节做些比憋在家里养伤更有趣的事情吧。&lt;/b&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>iOS 和我</title>
   <link href="http://zhanghang.github.com/life/2011/11/13/iOS-and-ZH"/>
   <updated>2011-11-13T00:00:00-08:00</updated>
   <id>http://zhanghang.github.com/life/2011/11/13/iOS-and-ZH</id>
   <content type="html">&lt;p&gt;几个月前手里的 Nokia C5 阵亡了，相继用了公司借我的 Samsung S8500 和三星送的 Samsung 7250 后我得出一结论：&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
三星自主的 Bada 真是太棒了，我用它这几个月 QQ 不挂，短信能不发就不发，甚至都不打电话了，这诡异的可触摸长方体在我身上竟然跟BB机没区别。&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
眼馋 iOS 好一阵子后，我终于在一个月前买了 iPod Touch 4，稍微把自己拉出了泥沼。发现前方一片光明。&lt;/p&gt;
&lt;p&gt;在这里总结一下我使用 Touch 的经历。&lt;/p&gt;
&lt;p&gt;我的原则是：&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
生命有限，绝不放在无止境地尝鲜上，有那些时间我会去做更多有有趣的事情。应用尽量的少而精，该花钱就花钱，&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;image src=&quot;/assets/assets/images/iCloud.png&quot;&gt;
&lt;p&gt;首先，刚买回来我便将它升到了 iOS 5，利用 iCloud 得到了丝绸般顺滑的同步体验。&lt;/p&gt;
&lt;h3&gt;Reminder&lt;/h3&gt;
&lt;image src=&quot;/assets/assets/images/reminder.jpg&quot;&gt;
&lt;p&gt;Get Things Done 类的程序最重要的是速度快，同步，简单 。这个在 iOS 5 后内建的程序都做到了。&lt;/p&gt;
&lt;h3&gt;Mail&lt;/h3&gt;
&lt;image src=&quot;/assets/assets/images/mail.jpg&quot;&gt;
&lt;p&gt;It just works.&lt;/p&gt;
&lt;h3&gt;&lt;a href=&quot;http://www.instapaper.com&quot;&gt;Instapaper&lt;/a&gt;&lt;/h3&gt;
&lt;image src=&quot;/assets/assets/images/instapaper.jpg&quot;&gt;
&lt;p&gt;按作者的话说“A simple tool to save web pages for reading later.”&lt;br /&gt;
整个流程非常的简单，当你想要把当前页面保存下来，点一下书签栏的“ Read it Later ”，boom,完成了。&lt;br /&gt;
程序会把这篇文章的内容提取出来，很认真的排版，方便阅读。&lt;/p&gt;
&lt;h3&gt;instagram&lt;/h3&gt;
&lt;image src=&quot;/assets/assets/images/instagram.png&quot;&gt;
&lt;p&gt;保存我生命中某个有意义时间点的工具，即使是 iPod Touch 这种像素很低的设备 instagram 也能照出很好的效果。&lt;br /&gt;
&lt;image src=&quot;/assets/assets/images/morning.jpg&quot;width=&quot;700&quot;&gt;&lt;/p&gt;
&lt;h3&gt;Dropbox&lt;/h3&gt;
&lt;image src=&quot;/assets/assets/images/dropbox.png&quot;&gt;
&lt;p&gt;这是一个同步存储服务，它会把你电脑上的某个文件夹同步到你所有的设备中。永远不会丢。&lt;/p&gt;
&lt;p&gt;例子：有一个课件你想路上看，把它放到文件夹中，打开 Dropbox ，打开，看。&lt;/p&gt;
&lt;h3&gt;Sleep Cycle&lt;/h3&gt;
&lt;image src=&quot;/assets/assets/images/sleepcycle.png&quot;&gt;
&lt;p&gt;你有过起床以后头疼的经历吧？人睡眠分深睡眠和浅睡眠两种状态，如果你在深睡眠强行被叫醒，那你就头疼了。&lt;br /&gt;
它就是解决这个问题的。&lt;br /&gt;
这软件神了，你睡前设定闹铃，把它放在身旁，它利用设备内置的加速度传感器分析你身体的震动，判断你处于哪种睡眠状态并纪录，用最适合的声音慢慢把你叫醒。&lt;/p&gt;
&lt;h3&gt;Nike Training&lt;/h3&gt;
&lt;image src=&quot;/assets/assets/images/niketraining.png&quot;&gt;
&lt;p&gt;你的健身减肥教练。里面有非常详尽的健身指导。&lt;/p&gt;
&lt;h3&gt;下厨房&lt;/h3&gt;
&lt;image src=&quot;/assets/assets/images/xiachufang.png&quot;&gt;
&lt;p&gt;首先，下厨房是一个美食网站，有非常多菜谱。看的总让人流口水。&lt;br /&gt;
其次，网站设计的非常干净，我比较在意这个，我从这个网站学到了许多设计上的东西。&lt;br /&gt;
再其次，在 Beijing Open Party 上听过创始人《将感情融入产品》的演讲，有好感。&lt;br /&gt;
最后，iOS 版本延续了网站的风格。&lt;/p&gt;
&lt;h3&gt;豆瓣电台&lt;/h3&gt;
&lt;image src=&quot;/assets/assets/images/doubanFM.png&quot;&gt;
&lt;p&gt;根据你的喜好来播放音乐，我爱豆瓣。&lt;/p&gt;
&lt;h3&gt;更多&lt;/h3&gt;
&lt;ul&gt;
	&lt;li&gt;拓词 &amp;#8211; 背单词利器&lt;/li&gt;
	&lt;li&gt;OuO &amp;#8211; 卖萌专用&lt;/li&gt;
	&lt;li&gt;知乎&lt;/li&gt;
	&lt;li&gt;Days Matter&lt;/li&gt;
	&lt;li&gt;随手记&lt;/li&gt;
	&lt;li&gt;植物大战僵尸&lt;/li&gt;
	&lt;li&gt;水果忍者&lt;/li&gt;
	&lt;li&gt;微信&lt;/li&gt;
	&lt;li&gt;飞聊&lt;/li&gt;
	&lt;li&gt;人人网&lt;/li&gt;
	&lt;li&gt;Twitter&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>R.I.P.</title>
   <link href="http://zhanghang.github.com/life/2011/10/06/r.i.p"/>
   <updated>2011-10-06T00:00:00-07:00</updated>
   <id>http://zhanghang.github.com/life/2011/10/06/r.i.p</id>
   <content type="html">&lt;p&gt;密密麻麻记录着 ET 降落地点的地图，某间属于我的巨大空旷房间，老旧残缺的暗色调图书馆。最近的梦都很奇幻，每个背后都藏着一个巨大的故事，我看到的只是几个点，几条不交错的线。过去的几个月里，我曾经历过一段完全无梦的日子，这个十一，它们集中爆发了。&lt;/p&gt;
&lt;p&gt;但今天 Steve Jobs 的过世并不是梦，我有些伤心，留下了眼泪，感觉就像一个亲戚走了。所以我试着写点什么去具象化此时的情绪，但无以表达。所以我决定在此时停笔，与其用拙劣的语言不如保持沉默，在沉默中祈祷，祈祷。&lt;/p&gt;
&lt;pre&gt;
Rest in Peace Steve.
&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;/assets/assets/images/t_hero.png&quot;/&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>一些想法</title>
   <link href="http://zhanghang.github.com/life/2011/09/18/thoughts"/>
   <updated>2011-09-18T00:00:00-07:00</updated>
   <id>http://zhanghang.github.com/life/2011/09/18/thoughts</id>
   <content type="html">&lt;p&gt;过完七月某个悠闲下午，我跨过了大一这一年。&lt;/p&gt;
&lt;p&gt;总结性的概括说，我在人生的路上前进了不大的一步，经历了几次崭新的体验。&lt;/p&gt;
&lt;p&gt;内在的，更坚定，更承认自我，更可以在某些时候无耻。&lt;/p&gt;
&lt;p&gt;外在的，世界在大一一年有了某种更为广阔的延伸。&lt;/p&gt;
&lt;p&gt;挖了几个坑，努力地填。&lt;/p&gt;
&lt;h3&gt;过去做的&lt;/h3&gt;
&lt;p&gt;跷了许多的课，挂了三科。&lt;/p&gt;
&lt;p&gt;疯狂的买过书，无耻的吃过霸王餐，谈过一个不长的恋爱。&lt;/p&gt;
&lt;p&gt;与许多人相识，与几人要好，与两人陌路。&lt;/p&gt;
&lt;p&gt;建设了一个在线社区，当了一个社团的社长。&lt;/p&gt;
&lt;p&gt;开发了两个手机软件，错过了与三星高层交流的机会。&lt;/p&gt;
&lt;p&gt;买了一个 Kindle 3 3G，企图扔掉实体书，最终失败。&lt;/p&gt;
&lt;p&gt;在学校之间骑车来回几十次，大腿见粗。&lt;/p&gt;
&lt;p&gt;夏去秋来，冬去春来，轮回间，一年就这么算不上浑浑噩噩的过了。&lt;/p&gt;
&lt;h3&gt;现在做的&lt;/h3&gt;
&lt;p&gt;让社团往好的方向行进。&lt;/p&gt;
&lt;p&gt;维护开发在线社区，让手头的两个软件不再坑爹。&lt;/p&gt;
&lt;p&gt;准备补考高等数学下，立誓哥要好好的把这学期的都过了。&lt;/p&gt;
&lt;p&gt;当然坑还在不断的挖与填。&lt;/p&gt;
&lt;h3&gt;关于生活&lt;/h3&gt;
&lt;p&gt;生活需要慢下来，如许多人，太浮躁，节奏快到无法看清周围的景象。&lt;/p&gt;
&lt;p&gt;我记得有一种病叫【下载控】&lt;/p&gt;
&lt;p&gt;信息成瘾症。&lt;/p&gt;
&lt;p&gt;他们不断的下载，爬过每一条链接，寻找有价值的资源。&lt;/p&gt;
&lt;p&gt;他们硬盘里分门别类的放慢了各种公开课、学习资料、音乐全集、软件安装包、系统安装镜像。&lt;/p&gt;
&lt;p&gt;他们在不与世界进行比特通信的时候，似乎会产生焦虑。&lt;/p&gt;
&lt;p&gt;那么，知识他们消化了吗？一半都没有。&lt;/p&gt;
&lt;p&gt;我们都有自己的生活，但活在如此世界，似乎有些可悲。&lt;/p&gt;
&lt;p&gt;我曾经也是如此，所以如今努力改正。&lt;/p&gt;
&lt;p&gt;&lt;b&gt;幸福感是建立在不断的微小自我提升上，自我之外的都不算数。&lt;/b&gt;&lt;/p&gt;
&lt;h3&gt;关于盗版软件&lt;/h3&gt;
&lt;p&gt;信息成瘾我相信在中国是更普遍的，它的另一种表现形式是【不断的尝鲜】。&lt;/p&gt;
&lt;p&gt;我们获取软件相比外国少了【花钱】这步。&lt;/p&gt;
&lt;p&gt;好了说是缺少版权意识，但终归是道德问题。&lt;/p&gt;
&lt;p&gt;我开始在软件上花钱，我不喜欢双重标准。&lt;/p&gt;
&lt;h3&gt;感兴趣的&lt;/h3&gt;
&lt;p&gt;源于业界对 C++ 的偏见，对 &lt;span class=&quot;caps&quot;&gt;JAVA&lt;/span&gt; 的不看好。&lt;/p&gt;
&lt;p&gt;这两门语言，前者本人不打算深入，后者不学了。&lt;/p&gt;
&lt;p&gt;Python 与 Ruby 更为适合我更快地将所想带入现实。它们激起了我心中的小桃心。&lt;/p&gt;
&lt;p&gt;我对聚集我认同的人这件事需要的方法和需要经过的途径也非常感兴趣。&lt;/p&gt;
&lt;p&gt;在微软创新实验室在线社区的 Mission 中我写道：&lt;/p&gt;
&lt;pre&gt;
「推动人才涌现的最大因素就是，让有天赋的人聚集在一起，共同解决某个难题，互相激励比天赋更重要。」－《Hacker &amp;amp; Painter》  

我们来自五湖四海，聚集在一起，却缺少一个便捷的平台来互相激励与交流，mslab.me 以解决此问题为使命。 

mslab.me 是为了大家而存在的。它希望大家的生活因其而更轻松简单一点。
&lt;/pre&gt;
&lt;p&gt;【聚集】后互相【激励】，我要营造一个如此的气氛。&lt;/p&gt;
&lt;p&gt;参加 Beijing Linux User Group &amp;amp; Beijing Open Party 后，我喜欢上了他们的氛围。&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;CEO&lt;/span&gt; 会给你聊聊想法，谈谈梦想。项目经理带领你思考问题。&lt;/p&gt;
&lt;p&gt;这是我在大学也希望看到。&lt;/p&gt;
&lt;p&gt;如果在年级或班级这个范围内无法营造的话，那我就在更小的圈子让它出现。&lt;/p&gt;
&lt;p&gt;时间荏苒，瞧，大二已经来了。&lt;/p&gt;
&lt;p&gt;革命尚未成功，同志仍需努力。&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>2011暑假</title>
   <link href="http://zhanghang.github.com/life/2011/08/28/summer-vacation"/>
   <updated>2011-08-28T00:00:00-07:00</updated>
   <id>http://zhanghang.github.com/life/2011/08/28/summer-vacation</id>
   <content type="html">&lt;p&gt;假期便意味着你有很大一段时间去探索人生，去看或是平淡或是惊艳的风景，我喜欢探索，去做疯狂的事。&lt;/p&gt;
&lt;p&gt;去年的此时，大学前的真空期，我每天和好朋友沉浸在文字的乐趣中，那是记忆中最好的假期。&lt;/p&gt;
&lt;p&gt;如今，我很高兴的发现自己正处于生命中一个更好的假期。&lt;/p&gt;
&lt;h3&gt;一些高亮&lt;/h3&gt;
&lt;p&gt;＊ 写了最多的 &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; 代码，创建了 &lt;a href=&quot;http://www.mslab.me&quot;&gt;mslab.me&lt;/a&gt; &lt;span style=&quot;color:#999&quot;&gt;- 一个刚生出来的婴儿社区&lt;/span&gt;&lt;br /&gt;
＊ 写了最多的 C++ 代码 &lt;span style=&quot;color:#999&quot;&gt;- 重构三次,开发了豆瓣电台doubanFM,并在期间暴力过滤JSON &lt;/span&gt;&lt;br /&gt;
＊ 达成了 500KM 的自行车里程，第一次受很重的伤，并第一次不眨眼用酒精清洗伤口。&lt;br /&gt;
＊ 远离社交网络&lt;br /&gt;
＊ 重开了博客，应用了一个满意的模版&lt;br /&gt;
＊ 开始用 Markdown 语法写作 &lt;span style=&quot;color:#999&quot;&gt;- 这节省了我很多时间 &lt;/span&gt;&lt;br /&gt;
＊ 俯览平流层下方静止的巨大白色柱状云&lt;br /&gt;
＊ 在海拔4000米的地方见到了最美的景色，并有了缺氧体验&lt;br /&gt;
&lt;img src=&quot;/assets/assets/images/LuoJiShan.png&quot; /&gt;&lt;br /&gt;
＊ 乘坐亚洲最长的缆车&lt;br /&gt;
＊ 结交了为乐趣而不是钱而生活的人&lt;br /&gt;
＊ 参加了一个最有趣的婚礼&lt;br /&gt;
＊ 吃了油炸的某种昆虫&lt;br /&gt;
＊ 开始履行一个社长的职责&lt;br /&gt;
＊ 删除所有盗版应用，不再剽窃。&lt;br /&gt;
＊ 完全放弃一个人&lt;/p&gt;
&lt;h3&gt;还有&lt;/h3&gt;
&lt;p&gt;它同时也是一个没有任何心仪异性的假期，实体书阅读量最少的假期，在咖啡厅累计时间最长的假期。&lt;/p&gt;
&lt;p&gt;另外，它还在继续。&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Ground Zero</title>
   <link href="http://zhanghang.github.com/life/2011/08/24/ground-zero"/>
   <updated>2011-08-24T00:00:00-07:00</updated>
   <id>http://zhanghang.github.com/life/2011/08/24/ground-zero</id>
   <content type="html">&lt;p&gt;停止了偷窃行为，删除了所有的盗版软件。&lt;/p&gt;
&lt;p&gt;目前常用的如下&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;iLife 11&lt;/li&gt;
	&lt;li&gt;Evernote&lt;/li&gt;
	&lt;li&gt;QQ&lt;/li&gt;
	&lt;li&gt;OmmWriter&lt;/li&gt;
	&lt;li&gt;Wunderlist&lt;/li&gt;
	&lt;li&gt;MindNode&lt;/li&gt;
	&lt;li&gt;FanRadio&lt;/li&gt;
	&lt;li&gt;Xcode&lt;/li&gt;
	&lt;li&gt;Time Out Free&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;近期打算入手&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Byword&lt;/li&gt;
	&lt;li&gt;Keynote&lt;/li&gt;
	&lt;li&gt;Mac OS X Lion&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;在不远的未来，我对手头软件的利用率会提高很多。&lt;/p&gt;
&lt;p&gt;接下来，迎接转型期。&lt;/p&gt;</content>
 </entry>
 
 
</feed>