MIT OS 5. 小結@ Lab1

1.PC機的復位地址:[F000:FFF0] 位於BISO代碼快。
2.BISO之後第一條指令地址:[0000:7c00],位於內存中。BISO事先將MBR複製到此處。
3.printf.c / console.c 
  console.c裏面負責初始化顯示器(CGA/VGA),串口(UART),並口(Parallel).並實現了getchar和putchar函數。getchar以中斷方式從uart中獲得一個字符;putchar將一個字符同時打印到顯示器,串口和並口上。
  printf.c裏面是格式化輸出的函數,對於格式化字符串通過vprintfmt(不定參數個數)調用來確定要打印的字符串序列,最終都是通過putchar函數打印。
4.crt_pos表示當前光標的位置,而CRT_SIZE定義了整個屏幕的大小:
  #define CRT_SIZE        (CRT_ROWS * CRT_COLS)
  當光標超出當前屏幕的時候就需要滾屏了,就是屏幕往上翻。這裏一般向上滾動一行。
5.有關va_list以及相關的宏操作,參見:http://blog.csdn.net/yunhuang2010/article/details/8473279
  va_list主要是利用X86裏面函數參數用棧傳遞的特點。
6.X86系統調用函數必須先準備一定的環境。主要是通過壓棧實現,先壓函數參數,再壓函數返回地址(一般是由call指令實現),母函數的EBP返回值(一般在子函數的最開始壓棧)。(EBP--->ESP之間是當前活動棧的範圍,把母函數的棧底保存,同時將更新棧底成當前棧頂,開啓新的活動棧。這時的棧頂其實保存的老棧底。
7.kdebug:
Eipdebuginfo:
info->eip_file = "<unknown>";
        info->eip_line = 0;
        info->eip_fn_name = "<unknown>";
        info->eip_fn_namelen = 9;
        info->eip_fn_addr = addr;

        info->eip_fn_narg = 0;

kern/kdebug.c:182:

// Your code here.
182         stab_binsearch(stabs, &lline, &rline, N_SLINE, addr);
183         if(lline >= 0 && lline <= rline)
184         {
185                 info->eip_line = rline;
186                 //if(rline==lline) cprintf("info");
187         }
188         else return -1;
189

kern/kern/monitor.c:27:

 24 static struct Command commands[] = {
 25         { "help", "Display this list of commands", mon_help },
 26         { "kerninfo", "Display information about the kernel", mon_kerninfo },
 27
 28         { "trace", "trace back to upper functions", mon_backtrace },
 29 };

63:

 62 int
 63 mon_backtrace(int argc, char **argv, struct Trapframe *tf)
 64 {
 65         // Your code here.
 66         uint32_t ebp, * pointer;
 67         uint32_t addr;
 68         struct Eipdebuginfo info;
 69         ebp = read_ebp();
 70         while(ebp != 0x00)
 71         {
 72           pointer = (uint32_t *) ebp;
 73           addr = *(pointer+1);
 74           cprintf("ebp %08x eip %08x args %08x %08x %08x %08x %08x\r\n", \
 75                    ebp,addr,*(pointer+2),*(pointer+3),*(pointer+4),*(pointer+5),*(pointer+6));
 76           debuginfo_eip(addr,&info);
 77           cprintf("\t%s:%d: %.*s+%d\r\n",info.eip_file,info.eip_line, \
 78                info.eip_fn_namelen,info.eip_fn_name,addr - info.eip_fn_addr);
 79           ebp = *pointer;
 80         }
 81         return 0;
 82 }



發佈了97 篇原創文章 · 獲贊 10 · 訪問量 25萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章