久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

Linux 內(nèi)核

 panic moon 2012-04-07

本文分析基于Linux 0.11內(nèi)核,,轉(zhuǎn)載請(qǐng)標(biāo)明出處,http://blog.csdn.net/yming0221/archive/2011/06/01/6459119.aspx

在main.c的程序中,當(dāng)設(shè)備初始化完畢后,,程序?qū)膬?nèi)核模式切換到用戶模式,也就是所說的任務(wù)0,,執(zhí)行fork()函數(shù)(該函數(shù)使用內(nèi)嵌的匯

編,,防止函數(shù)調(diào)用弄亂堆棧,造成寫時(shí)復(fù)制COPY_ON_WRITE)切換到用戶堆棧并執(zhí)行任務(wù)0使用iret指令,,首先將有關(guān)的值壓入堆棧,,然后執(zhí)

行iret指令。將剛剛壓入對(duì)堆棧的數(shù)據(jù)根據(jù)標(biāo)志位彈入相應(yīng)的寄存器,。

  1. //// 切換到用戶模式運(yùn)行,。  
  2. // 該函數(shù)利用iret 指令實(shí)現(xiàn)從內(nèi)核模式切換到用戶模式(初始任務(wù)0)。  
  3. #define move_to_user_mode() /  
  4. __asm__ ( "movl %%esp,%%eax/n/t" /   // 保存堆棧指針esp 到eax 寄存器中,。  
  5. "pushl $0x17/n/t" /     // 首先將堆棧段選擇符(SS)入棧,。  
  6.   "pushl %%eax/n/t" /       // 然后將保存的堆棧指針值(esp)入棧。  
  7.   "pushfl/n/t" /        // 將標(biāo)志寄存器(eflags)內(nèi)容入棧,。  
  8.   "pushl $0x0f/n/t" /       // 將內(nèi)核代碼段選擇符(cs)入棧,。  
  9.   "pushl $1f/n/t" /     // 將下面標(biāo)號(hào)1 的偏移地址(eip)入棧。  
  10.   "iret/n" /            // 執(zhí)行中斷返回指令,則會(huì)跳轉(zhuǎn)到下面標(biāo)號(hào)1 處,。  
  11.   "1:/tmovl $0x17,%%eax/n/t" /  // 此時(shí)開始執(zhí)行任務(wù)0,,  
  12.   "movw %%ax,%%ds/n/t" /    // 初始化段寄存器指向本局部表的數(shù)據(jù)段。  
  13. "movw %%ax,%%es/n/t" "movw %%ax,%%fs/n/t" "movw %%ax,%%gs":::"ax")  
 

執(zhí)行iret前的堆棧如下:

一下這段話引用自http://faydoc./cpu/iret.htm


In Protected Mode, the action of the IRET instruction depends on the settings of the NT (nested task) and VM flags in the EFLAGS register and the VM flag in the EFLAGS image stored on the current stack. Depending on the setting of these flags, the processor performs the following types of interrupt returns:

  • Return from virtual-8086 mode.
  • Return to virtual-8086 mode.
  • Intra-privilege level return.
  • Inter-privilege level return.
  • Return from nested task (task switch).

If the NT flag (EFLAGS register) is cleared, the IRET instruction performs a far return from the interrupt procedure, without a task switch. The code segment being returned to must be equally or less privileged than the interrupt handler routine (as indicated by the RPL field of the code segment selector popped from the stack). As with a real-address mode interrupt return, the IRET instruction pops the return instruction pointer, return code segment selector, and EFLAGS image from the stack to the EIP, CS, and EFLAGS registers, respectively, and then resumes execution of the interrupted program or procedure. If the return is to another privilege level, the IRET instruction also pops the stack pointer and SS from the stack, before resuming program execution. If the return is to virtual-8086 mode, the processor also pops the data segment registers from the stack.

-----------------------------------

由于在sched_init()中已經(jīng)設(shè)置了標(biāo)志寄存器中的vm標(biāo)志為0,,所以iret掉用后不會(huì)發(fā)生任務(wù)切換,,而是繼續(xù)執(zhí)行EIP指向的指令故繼續(xù)執(zhí)行

1標(biāo)號(hào)的代碼,開始執(zhí)行任務(wù)0,,任務(wù)0的堆棧段選擇符為0x17,,在sched_init()中已設(shè)置了任務(wù)0 的任務(wù)描述符和局部描述符為INIT_TASK

  1. set_tss_desc (gdt + FIRST_TSS_ENTRY, &(init_task.task.tss));  
  2. set_ldt_desc (gdt + FIRST_LDT_ENTRY, &(init_task.task.ldt));  
 
  1. /* 
  2. * INIT_TASK is used to set up the first task table, touch at 
  3. * your own risk!. Base=0, limit=0x9ffff (=640kB) 
  4. */  
  5. /* 
  6. * INIT_TASK 用于設(shè)置第1 個(gè)任務(wù)表,若想修改,,責(zé)任自負(fù)?,! 
  7. * 基址Base = 0,段長(zhǎng)limit = 0x9ffff(=640kB),。 
  8. */  
  9. // 對(duì)應(yīng)上面任務(wù)結(jié)構(gòu)的第1 個(gè)任務(wù)的信息,。  
  10. #define INIT_TASK /  
  11. /* state etc */ { 0,15,15, /    // state, counter, priority  
  12. /* signals */ 0,  
  13. {  
  14.   {  
  15.   }  
  16. ,}  
  17. , 0, /              // signal, sigaction[32], blocked  
  18.                     /* ec,brk... */ 0, 0, 0, 0, 0, 0, /  
  19.                     // exit_code,start_code,end_code,end_data,brk,start_stack  
  20.                     /* pid etc.. */ 0, -1, 0, 0, 0, /  
  21.                     // pid, father, pgrp, session, leader  
  22.                     /* uid etc */ 0, 0, 0, 0, 0, 0, /  
  23.                     // uid, euid, suid, gid, egid, sgid  
  24.                     /* alarm */ 0, 0, 0, 0, 0, 0, /  
  25.                     // alarm, utime, stime, cutime, cstime, start_time  
  26.                 /* math */ 0, /  
  27.                 // used_math  
  28.                             /* fs info */ -1, 0022, NULL, NULL, NULL, 0, /  
  29.                             // tty,umask,pwd,root,executable,close_on_exec  
  30. /* filp */  
  31. {  
  32. NULL,}  
  33. , /             // filp[20]  
  34. {  
  35.   /             // ldt[3]  
  36.   {  
  37.   0, 0}  
  38.   ,  
  39. /* ldt */  
  40.   {  
  41.   0x9f, 0xc0fa00}  
  42.   , /               // 代碼長(zhǎng)640K,基址0x0,,G=1,D=1,,DPL=3,,P=1 TYPE=0x0a  
  43.   {  
  44.   0x9f, 0xc0f200}  
  45.   , /               // 數(shù)據(jù)長(zhǎng)640K,基址0x0,,G=1,,D=1,DPL=3,,P=1 TYPE=0x02  
  46. }  
  47. ,  
  48. /*tss*/  
  49. {  
  50.   0, PAGE_SIZE + (long) &init_task, 0x10, 0, 0, 0, 0, (long) &pg_dir, / // tss  
  51.     0, 0, 0, 0, 0, 0, 0, 0,  
  52.     0, 0, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, _LDT (0), 0x80000000,  
  53.   {  
  54.   }  
  55. }  
  56. ,} 

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多