{"id":112606,"date":"2026-10-04T07:41:08","date_gmt":"2026-10-03T23:41:08","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/112606.html"},"modified":"2026-10-04T07:41:08","modified_gmt":"2026-10-03T23:41:08","slug":"%e5%94%b1%e7%9d%80%e6%ad%8c%e8%b0%a3%e6%8a%8a%e5%86%85%e6%a0%b8%e5%ad%a6%ef%bc%88%e5%8d%b7%e4%ba%8c%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/112606.html","title":{"rendered":"\u5531\u7740\u6b4c\u8c23\u628a\u5185\u6838\u5b66\uff08\u5377\u4e8c\uff09"},"content":{"rendered":"<h3>\u5185\u6838\u5b66\u4e60\u7b2c\u4e8c\u5377 \u00b7 \u8fdb\u7a0b<\/h3>\n<h4>&#xff08;1.&#xff09;\u6587\u6863\u8bf4\u660e<\/h4>\n<p>\u672c\u6587\u6863\u662f\u72ec\u7acb\u5b9e\u73b0\u5185\u6838&#xff0c;\u5e76\u4e14\u8bb0\u5f55\u5185\u6838\u5b66\u4e60\u8fc7\u7a0b&#xff0c;\u4ee5\u5e2e\u52a9\u540e\u6765\u7684\u5b66\u4e60\u8005\u6765\u7406\u89e3\u548c\u5b9e\u73b0\u5185\u6838&#xff0c;\u5982\u679c\u6709\u8bb2\u89e3\u4e0d\u6e05\u695a\u7684\u5730\u65b9\u8bf7\u89c1\u8c05\u3002<\/p>\n<h4>&#xff08;2.&#xff09;\u7ec4\u4ef6\u5206\u6790<\/h4>\n<p>#ifndef PROCESS_DEFS_H<br \/>\n#define PROCESS_DEFS_H<\/p>\n<p>\/\/ \u524d\u7f6e\u58f0\u660e<br \/>\nstruct task_struct;<br \/>\nstruct exec_domain;<\/p>\n<p>\/\/ \u5b8c\u6574\u5b9a\u4e49 restart_block<br \/>\nstruct restart_block {<br \/>\n    long fn;<br \/>\n    unsigned long arg0, arg1, arg2, arg3;<br \/>\n};<\/p>\n<p>typedef unsigned int __u32;<br \/>\ntypedef unsigned long mm_segment_t;<\/p>\n<p>struct thread_info {<br \/>\n    struct task_struct *task;<br \/>\n    struct exec_domain *exec_domain;<br \/>\n    __u32                flags;<br \/>\n    __u32                status;<br \/>\n    __u32                cpu;<br \/>\n    int                 preempt_count;<br \/>\n    mm_segment_t        addr_limit;<br \/>\n    struct restart_block restart_block;<br \/>\n    void                *sysenter_return;<br \/>\n    int                 uaccess_err;<br \/>\n};<\/p>\n<p>#endif \/\/ PROCESS_DEFS_H<\/p>\n<h5>&#xff08;2.1&#xff09;\u5934\u6587\u4ef6\u4fdd\u62a4\u5b8f&#xff1a;#ifndef \/ #define \/ #endif<\/h5>\n<p>\u4f5c\u7528&#xff1a;\u9632\u6b62\u540c\u4e00\u4e2a\u5934\u6587\u4ef6\u88ab\u591a\u6b21 include&#xff0c;\u9020\u6210\u91cd\u590d\u5b9a\u4e49\u7f16\u8bd1\u9519\u8bef\u3002<\/p>\n<h5>&#xff08;2.2&#xff09;\u524d\u7f6e\u58f0\u660e struct task_struct; struct exec_domain;<\/h5>\n<p>\u4f5c\u7528&#xff1a;\u53ef\u4ee5\u6682\u65f6\u4e0d\u9700\u8981\u5199\u51fa\u8fdb\u7a0b\u63cf\u8ff0\u7b26\u5185\u90e8\u6210\u5458\u3002<\/p>\n<h5>&#xff08;2.3&#xff09;typedef \u81ea\u5b9a\u4e49\u7c7b\u578b<\/h5>\n<p>\u4f5c\u7528&#xff1a;\u7ed9\u5df2\u6709\u7684\u6570\u636e\u7c7b\u578b\u8d77\u522b\u540d&#xff0c;\u4e0d\u662f\u521b\u5efa\u65b0\u7c7b\u578b\u3002<\/p>\n<h4>&#xff08;3.&#xff09;NASM\u6c47\u7f16<\/h4>\n<h5>&#xff08;3.1&#xff09;struct restart_block \u62c6\u89e3 &#043; NASM \u4f2a\u6307\u4ee4<\/h5>\n<p>struct restart_block {<br \/>\n    long fn;                \/\/ long&#xff0c;8\u5b57\u8282 \u2192 dq<br \/>\n    unsigned long arg0;     \/\/ unsigned long&#xff0c;8\u5b57\u8282 \u2192 dq<br \/>\n    unsigned long arg1;     \/\/ unsigned long&#xff0c;8\u5b57\u8282 \u2192 dq<br \/>\n    unsigned long arg2;     \/\/ unsigned long&#xff0c;8\u5b57\u8282 \u2192 dq<br \/>\n    unsigned long arg3;     \/\/ unsigned long&#xff0c;8\u5b57\u8282 \u2192 dq<br \/>\n};<\/p>\n<p>NASM&#xff1a;<\/p>\n<p>; struct restart_block<br \/>\nRB_FN    dq 0<br \/>\nRB_ARG0  dq 0<br \/>\nRB_ARG1  dq 0<br \/>\nRB_ARG2  dq 0<br \/>\nRB_ARG3  dq 0<\/p>\n<h5>&#xff08;3.2&#xff09;struct thread_info \u9010\u6210\u5458\u6807\u6ce8 NASM \u4f2a\u6307\u4ee4<\/h5>\n<p>struct thread_info {<br \/>\n    struct task_struct *task;              \/\/ 64\u4f4d\u6307\u9488&#xff0c;8B \u2192 dq<br \/>\n    struct exec_domain *exec_domain;       \/\/ 64\u4f4d\u6307\u9488&#xff0c;8B \u2192 dq<br \/>\n    __u32                flags;             \/\/ __u32&#xff0c;4B \u2192 dd<br \/>\n    __u32                status;            \/\/ __u32&#xff0c;4B \u2192 dd<br \/>\n    __u32                cpu;               \/\/ __u32&#xff0c;4B \u2192 dd<br \/>\n    int                 preempt_count;      \/\/ int&#xff0c;4B \u2192 dd<br \/>\n    mm_segment_t        addr_limit;         \/\/ unsigned long&#xff0c;8B \u2192 dq<br \/>\n    struct restart_block restart_block;     \/\/ \u5185\u5d4c\u7ed3\u6784\u4f53&#xff0c;40B&#xff08;5\u4e2adq&#xff09;<br \/>\n    void                *sysenter_return;   \/\/ 64\u4f4d\u6307\u9488&#xff0c;8B \u2192 dq<br \/>\n    int                 uaccess_err;        \/\/ int&#xff0c;4B \u2192 dd<br \/>\n};<\/p>\n<p>NASM \u9759\u6001\u5b9a\u4e49&#xff08;.data \u6bb5&#xff0c;db\/dw\/dd\/dq&#xff09;<\/p>\n<p>section .data<br \/>\nti:<br \/>\nti_task         dq  0    ; struct task_struct *task; 8B<br \/>\nti_exec_domain  dq  0    ; struct exec_domain *exec_domain; 8B<br \/>\nti_flags        dd  0    ; __u32 flags; 4B<br \/>\nti_status       dd  0    ; __u32 status;4B<br \/>\nti_cpu          dd  0    ; __u32 cpu;4B<br \/>\nti_preempt_cnt  dd  0    ; int preempt_count;4B<br \/>\nti_addr_limit   dq  0    ; mm_segment_t addr_limit;8B<\/p>\n<p>; struct restart_block \u5185\u5d4c\u5b9e\u4f53&#xff08;40\u5b57\u8282&#xff09;<br \/>\nti_rb_fn        dq  0<br \/>\nti_rb_arg0      dq  0<br \/>\nti_rb_arg1      dq  0<br \/>\nti_rb_arg2      dq  0<br \/>\nti_rb_arg3      dq  0<\/p>\n<p>ti_sysenter_ret dq  0    ; void *sysenter_return;8B<br \/>\nti_uaccess_err  dd  0    ; int uaccess_err;4B<\/p>\n<h4>&#xff08;4.&#xff09;\u63cf\u8ff0\u8fdb\u7a0b\u72b6\u6001<\/h4>\n<p>\u8fdb\u7a0b\u72b6\u6001\u662f\u653e\u5728 task_struct&#xff08;\u8fdb\u7a0b\u63cf\u8ff0\u7b26&#xff09;\u91cc\u9762\u7684\u6210\u5458\u3002<\/p>\n<p>\/\/ \u7c7b\u578b\u522b\u540d&#xff08;\u548cNASM\u4fdd\u6301\u4e00\u81f4&#xff0c;\u4e0d\u4f9d\u8d56\u5185\u6838\u5934&#xff09;<br \/>\ntypedef unsigned int __u32;<br \/>\ntypedef unsigned long mm_segment_t;<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 1. \u8fdb\u7a0b\u72b6\u6001\u5e38\u91cf&#xff08;\u72b6\u6001\u5f00\u5173&#xff09;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n#define TASK_RUNNING        0       \/\/ \u5c31\u7eea\/\u6b63\u5728\u8fd0\u884c&#xff0c;\u8c03\u5ea6\u5668\u53ef\u4ee5\u8c03\u5ea6\u4e0aCPU<br \/>\n#define TASK_INTERRUPTIBLE  1       \/\/ \u53ef\u4e2d\u65ad\u7761\u7720&#xff0c;\u7b49\u5f85\u4e8b\u4ef6&#xff0c;\u6536\u5230\u4fe1\u53f7\u53ef\u5524\u9192<br \/>\n#define TASK_UNINTERRUPTIBLE 2      \/\/ \u4e0d\u53ef\u4e2d\u65ad\u7761\u7720&#xff0c;\u7b49\u5f85IO&#xff0c;\u4e0d\u54cd\u5e94\u4fe1\u53f7<br \/>\n#define TASK_STOPPED        4       \/\/ \u8fdb\u7a0b\u6682\u505c<br \/>\n#define TASK_ZOMBIE         8       \/\/ \u50f5\u5c38\u8fdb\u7a0b&#xff0c;\u5df2\u9000\u51fa&#xff0c;\u7b49\u5f85\u7236\u8fdb\u7a0b\u56de\u6536<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 2. restart_block \u7ed3\u6784\u4f53&#xff08;\u5185\u5d4c\u5728thread_info&#xff09;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nstruct restart_block {<br \/>\n    long fn;                        \/\/ \u91cd\u542f\u51fd\u6570\u6307\u9488<br \/>\n    unsigned long arg0, arg1, arg2, arg3; \/\/ \u51fd\u6570\u53c2\u6570<br \/>\n};<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 3. \u8fdb\u7a0b\u63cf\u8ff0\u7b26 task_struct&#xff08;\u4fdd\u5b58\u8fdb\u7a0b\u6838\u5fc3\u4fe1\u606f&#xff0c;\u542bstate\u72b6\u6001&#xff09;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nstruct task_struct {<br \/>\n    long pid;                       \/\/ \u8fdb\u7a0bID<br \/>\n    long state;                     \/\/ \u2705\u8fdb\u7a0b\u72b6\u6001\u5f00\u5173&#xff08;\u6838\u5fc3&#xff09;<br \/>\n    char comm[16];                  \/\/ \u8fdb\u7a0b\u540d\u79f0&#xff0c;16\u5b57\u8282\u5b57\u7b26\u4e32<br \/>\n};<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 4. thread_info \u7ebf\u7a0b\u4fe1\u606f\u7ed3\u6784\u4f53 &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nstruct thread_info {<br \/>\n    struct task_struct *task;              \/\/ \u6307\u5411\u8fdb\u7a0b\u63cf\u8ff0\u7b26task_struct<br \/>\n    struct exec_domain *exec_domain;       \/\/ \u6267\u884c\u57df\u6307\u9488<br \/>\n    __u32                flags;<br \/>\n    __u32                status;<br \/>\n    __u32                cpu;<br \/>\n    int                 preempt_count;<br \/>\n    mm_segment_t        addr_limit;<br \/>\n    struct restart_block restart_block;     \/\/ \u5185\u5d4crestart_block\u5b9e\u4f53<br \/>\n    void                *sysenter_return;<br \/>\n    int                 uaccess_err;<br \/>\n};<\/p>\n<h5>&#xff08;4.1&#xff09;\u6bcf\u4e2a\u6210\u5458 \u2192 NASM \u5b57\u8282\u4f2a\u6307\u4ee4\u6620\u5c04&#xff08;x86-64&#xff09;<\/h5>\n<p>1\u3001struct restart_block<\/p>\n<p>struct restart_block {<br \/>\n    long fn;                \/\/ long 8B \u2192 dq<br \/>\n    unsigned long arg0;     \/\/ 8B \u2192 dq<br \/>\n    unsigned long arg1;     \/\/ 8B \u2192 dq<br \/>\n    unsigned long arg2;     \/\/ 8B \u2192 dq<br \/>\n    unsigned long arg3;     \/\/ 8B \u2192 dq<br \/>\n};<\/p>\n<p>2\u3001struct task_struct&#xff08;\u8fdb\u7a0b\u63cf\u8ff0\u7b26&#xff0c;\u65b0\u589e state&#xff09;<\/p>\n<p>struct task_struct {<br \/>\n    long pid;               \/\/ 8B \u2192 dq<br \/>\n    long state;             \/\/ 8B \u2192 dq  \u2705\u8fdb\u7a0b\u72b6\u6001<br \/>\n    char comm[16];          \/\/ 16B \u2192 db 16&#xff08;\u8fde\u7eed16\u4e2a\u5b57\u8282&#xff09;<br \/>\n};<\/p>\n<p>3\u3001struct thread_info<\/p>\n<p>struct thread_info {<br \/>\n    struct task_struct *task;              \/\/ \u6307\u94888B \u2192 dq<br \/>\n    struct exec_domain *exec_domain;       \/\/ \u6307\u94888B \u2192 dq<br \/>\n    __u32                flags;             \/\/ 4B \u2192 dd<br \/>\n    __u32                status;            \/\/ 4B \u2192 dd<br \/>\n    __u32                cpu;               \/\/ 4B \u2192 dd<br \/>\n    int                 preempt_count;      \/\/ int 4B \u2192 dd<br \/>\n    mm_segment_t        addr_limit;         \/\/ unsigned long 8B \u2192 dq<br \/>\n    struct restart_block restart_block;     \/\/ \u5185\u5d4c40\u5b57\u8282<br \/>\n    void                *sysenter_return;   \/\/ \u6307\u94888B \u2192 dq<br \/>\n    int                 uaccess_err;        \/\/ int 4B \u2192 dd<br \/>\n};<\/p>\n<h5>&#xff08;4.2&#xff09;NASM EQU \u504f\u79fb<\/h5>\n<p>; &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; restart_block \u504f\u79fb &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nRB_FN        equ 0<br \/>\nRB_ARG0      equ 8<br \/>\nRB_ARG1      equ 16<br \/>\nRB_ARG2      equ 24<br \/>\nRB_ARG3      equ 32<\/p>\n<p>; &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; thread_info \u504f\u79fb &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nTI_TASK         equ 0<br \/>\nTI_EXEC_DOMAIN  equ 8<br \/>\nTI_FLAGS        equ 16<br \/>\nTI_STATUS       equ 20<br \/>\nTI_CPU          equ 24<br \/>\nTI_PREEMPT_CNT  equ 28<br \/>\nTI_ADDR_LIMIT   equ 32<br \/>\nTI_RESTART_BLOCK equ 40<br \/>\nTI_SYSENTER_RET equ 80<br \/>\nTI_UACCESS_ERR  equ 88<\/p>\n<p>; &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;\u3010\u65b0\u589e\u3011task_struct \u8fdb\u7a0b\u63cf\u8ff0\u7b26\u504f\u79fb &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nTASK_PID    equ 0<br \/>\nTASK_STATE  equ 8    ; \u8fdb\u7a0b\u72b6\u6001state\u504f\u79fb<br \/>\nTASK_COMM   equ 16<\/p>\n<p>EQU \u5c31\u662f\u7ed9\u6570\u5b57\u8d77\u522b\u540d&#xff0c;\u65b9\u4fbf\u9605\u8bfb\u8bb0\u5fc6&#xff1b;\u66f4\u5927\u4ef7\u503c\u662f\u7edf\u4e00\u7ba1\u7406\u5e38\u91cf&#xff0c;\u4fee\u6539\u53ea\u6539\u4e00\u5904&#xff0c;\u907f\u514d\u786c\u7f16\u7801\u6570\u5b57\u5e26\u6765\u7684\u9519\u4f4d bug\u3002<\/p>\n<h4>&#xff08;5.&#xff09;\u6c47\u7f16test.asm<\/h4>\n<p>; test.asm<br \/>\n; NASM 64\u4f4d Linux \u7b80\u6613\u8fdb\u7a0b\u72b6\u6001\u8c03\u5ea6\u6f14\u793a<br \/>\n; \u7f16\u8bd1&#xff1a;nasm -f elf64 test.asm -o test.o &amp;&amp; ld test.o -o test<br \/>\n; \u8fd0\u884c&#xff1a;.\/test<\/p>\n<p>; &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; \u5168\u90e8EQU\u5e38\u91cf\u3010\u653e\u5728\u6587\u4ef6\u6700\u5f00\u5934\u3011&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n; &#8212;&#8212;&#8211; \u8fdb\u7a0b\u72b6\u6001\u5e38\u91cf &#8212;&#8212;&#8211;<br \/>\nTASK_RUNNING        equ 0<br \/>\nTASK_INTERRUPTIBLE  equ 1<br \/>\nTASK_UNINTERRUPTIBLE equ 2<br \/>\nTASK_STOPPED        equ 4<br \/>\nTASK_ZOMBIE         equ 8<\/p>\n<p>; &#8212;&#8212;&#8211; restart_block \u6210\u5458\u504f\u79fb &#8212;&#8212;&#8211;<br \/>\nRB_FN        equ 0<br \/>\nRB_ARG0      equ 8<br \/>\nRB_ARG1      equ 16<br \/>\nRB_ARG2      equ 24<br \/>\nRB_ARG3      equ 32<\/p>\n<p>; &#8212;&#8212;&#8211; thread_info \u6210\u5458\u504f\u79fb &#8212;&#8212;&#8211;<br \/>\nTI_TASK         equ 0<br \/>\nTI_EXEC_DOMAIN  equ 8<br \/>\nTI_FLAGS        equ 16<br \/>\nTI_STATUS       equ 20<br \/>\nTI_CPU          equ 24<br \/>\nTI_PREEMPT_CNT  equ 28<br \/>\nTI_ADDR_LIMIT   equ 32<br \/>\nTI_RESTART_BLOCK equ 40<br \/>\nTI_SYSENTER_RET equ 80<br \/>\nTI_UACCESS_ERR  equ 88<br \/>\nTI_SIZE         equ 92   ; thread_info\u603b\u5b57\u8282<\/p>\n<p>; &#8212;&#8212;&#8211; task_struct \u8fdb\u7a0b\u63cf\u8ff0\u7b26\u504f\u79fb &#8212;&#8212;&#8211;<br \/>\nTASK_PID    equ 0<br \/>\nTASK_STATE  equ 8<br \/>\nTASK_COMM   equ 16<br \/>\nTASK_SIZE   equ 32<br \/>\n; &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<\/p>\n<p>section .bss<br \/>\n    ; task_struct \u6574\u5757\u9884\u7559&#xff0c;\u8d77\u59cb\u6807\u7b7e task1<br \/>\ntask1 resb TASK_SIZE<\/p>\n<p>    ; thread_info \u6574\u5757\u9884\u7559&#xff0c;\u8d77\u59cb\u6807\u7b7e ti1 \u3010\u4fee\u590d\u5173\u952e\u70b9&#xff01;\u3011<br \/>\nti1   resb TI_SIZE<\/p>\n<p>section .data<br \/>\n    msg_run  db  &#034;\u8fdb\u7a0b&#xff1a;\u53ef\u8fd0\u884c\u72b6\u6001&#xff0c;\u51c6\u5907\u8c03\u5ea6&#034;,10,0<br \/>\n    msg_sleep db &#034;\u8fdb\u7a0b&#xff1a;\u7761\u7720\u72b6\u6001&#xff0c;\u8df3\u8fc7\u8c03\u5ea6&#034;,10,0<\/p>\n<p>section .text<br \/>\nglobal _start<\/p>\n<p>_start:<br \/>\n    ; \u521d\u59cb\u5316&#xff1a;ti1.task &#061; &amp;task1 &#xff08;\u5173\u8054thread_info \u548c\u8fdb\u7a0b\u63cf\u8ff0\u7b26&#xff09;<br \/>\n    mov rdi, ti1<br \/>\n    mov qword [rdi &#043; TI_TASK], task1<\/p>\n<p>    ; \u8bbe\u7f6ePID&#061;1001<br \/>\n    mov rbx, [rdi &#043; TI_TASK]<br \/>\n    mov qword [rbx &#043; TASK_PID], 1001<\/p>\n<p>    ; \u8bbe\u7f6e\u8fdb\u7a0b\u72b6\u6001&#xff1a;TASK_INTERRUPTIBLE&#xff08;\u7761\u7720\u6001&#xff09;<br \/>\n    mov qword [rbx &#043; TASK_STATE], TASK_INTERRUPTIBLE<\/p>\n<p>    ; &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; \u8c03\u5ea6\u5224\u65ad&#xff1a;\u8df3\u8f6c\u903b\u8f91 &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n    mov rax, [rbx &#043; TASK_STATE]<br \/>\n    cmp rax, TASK_RUNNING       ; \u5224\u65adstate\u662f\u5426\u7b49\u4e8e\u8fd0\u884c\u6001<br \/>\n    je  SCHED_RUN               ; \u76f8\u7b49\u5219\u8df3\u8f6c\u5230SCHED_RUN<br \/>\n    jmp SCHED_SKIP              ; \u5426\u5219\u8df3\u5230\u8df3\u8fc7\u8c03\u5ea6<\/p>\n<p>SCHED_RUN:<br \/>\n    mov rsi, msg_run<br \/>\n    call print_str<br \/>\n    jmp EXIT_PROG<\/p>\n<p>SCHED_SKIP:<br \/>\n    mov rsi, msg_sleep<br \/>\n    call print_str<\/p>\n<p>EXIT_PROG:<br \/>\n    ; \u7cfb\u7edf\u8c03\u7528\u9000\u51fa\u7a0b\u5e8f<br \/>\n    mov rax,60<br \/>\n    mov rdi,0<br \/>\n    syscall<\/p>\n<p>; \u5b50\u51fd\u6570 print_str(rsi&#061;\u5b57\u7b26\u4e32\u9996\u5730\u5740)<br \/>\nprint_str:<br \/>\n    push rsi<br \/>\n    xor rdx,rdx<br \/>\n.count:<br \/>\n    cmp byte [rsi&#043;rdx],0<br \/>\n    je .out<br \/>\n    inc rdx<br \/>\n    jmp .count<br \/>\n.out:<br \/>\n    mov rax,1<br \/>\n    mov rdi,1<br \/>\n    syscall<br \/>\n    pop rsi<br \/>\n    ret<\/p>\n<h4>&#xff08;6.&#xff09;\u88f8\u673aboot.asm<\/h4>\n<p>; boot.asm \u4e3b\u5f15\u5bfc\u6247\u533a 512\u5b57\u8282<br \/>\n[bits 16]<br \/>\n[org 0x7c00]<\/p>\n<p>start:<br \/>\n    mov ax, 0<br \/>\n    mov es, ax<br \/>\n    mov bx, 0x1000      ; \u628a\u7b2c\u4e8c\u9636\u6bb5\u52a0\u8f7d\u5230\u7269\u7406\u5730\u57400x1000<br \/>\n    mov ah, 0x02        ; BIOS\u8bfb\u6247\u533a<br \/>\n    mov al, 1           ; \u8bfb\u53d61\u4e2a\u6247\u533a(512\u5b57\u8282)<br \/>\n    mov ch, 0           ; \u78c1\u90530<br \/>\n    mov cl, 2           ; \u4ece\u7b2c2\u6247\u533a\u8bfb\u53d6&#xff08;\u6247\u533a1\u662f\u5f53\u524d\u5f15\u5bfc\u6247\u533a&#xff09;<br \/>\n    mov dh, 0           ; \u78c1\u59340<br \/>\n    int 0x13<br \/>\n    jc disk_error       ; \u8bfb\u76d8\u5931\u8d25\u8df3\u8f6c<\/p>\n<p>    cli<br \/>\n    lgdt [gdt_desc]<\/p>\n<p>    mov eax, cr0<br \/>\n    or eax, 1<br \/>\n    mov cr0, eax<\/p>\n<p>    jmp 0x08:pm_entry   ; \u8fdc\u8df3\u8f6c&#xff0c;\u5237\u65b0CS\u8fdb\u5165\u4fdd\u62a4\u6a21\u5f0f<\/p>\n<p>[bits 32]<br \/>\npm_entry:<br \/>\n    mov ax, 0x10<br \/>\n    mov ds, ax<br \/>\n    mov es, ax<br \/>\n    mov ss, ax<br \/>\n    mov esp, 0x7c00<\/p>\n<p>    ; \u6e05\u7a7a\u9875\u76ee\u5f55 0x2000<br \/>\n    mov edi, 0x2000<br \/>\n    mov ecx, 1024<br \/>\n    xor eax, eax<br \/>\n    rep stosd<\/p>\n<p>    ; \u9875\u76ee\u5f55\u7b2c0\u9879&#xff1a;\u6307\u5411\u9875\u88680x3000&#xff0c;Present&#043;RW<br \/>\n    mov dword [0x2000], 0x3003 <\/p>\n<p>    ; \u6e05\u7a7a\u9875\u8868 0x3000<br \/>\n    mov edi, 0x3000<br \/>\n    mov ecx, 1024<br \/>\n    xor eax, eax<br \/>\n    rep stosd<\/p>\n<p>    ; \u586b\u5145\u9875\u8868&#xff1a;\u6620\u5c04\u865a\u62df\u5730\u57400~4MB \u5230\u7269\u7406\u5730\u57400~4MB<br \/>\n    mov ebx, 0x3000<br \/>\n    mov eax, 0x00000003<br \/>\n    mov ecx, 1024<br \/>\nfill_pt:<br \/>\n    mov [ebx], eax<br \/>\n    add ebx, 4<br \/>\n    add eax, 0x1000<br \/>\n    loop fill_pt<\/p>\n<p>    mov eax, 0x2000<br \/>\n    mov cr3, eax        ; CR3 &#061; \u9875\u76ee\u5f55\u7269\u7406\u5730\u5740<\/p>\n<p>    mov eax, cr0<br \/>\n    or eax, 0x80000000<br \/>\n    mov cr0, eax        ; \u5f00\u542f\u5206\u9875<\/p>\n<p>    jmp 0x08:0x1000     ; \u8df3\u5230\u7b2c\u4e8c\u9636\u6bb5\u5185\u6838\u4ee3\u7801&#xff01;<\/p>\n<p>disk_error:<br \/>\n    cli<br \/>\n    hlt<\/p>\n<p>gdt_start:<br \/>\n    dq 0<br \/>\ngdt_code:<br \/>\n    dw 0xffff<br \/>\n    dw 0<br \/>\n    db 0<br \/>\n    db 0x9a<br \/>\n    db 0xcf<br \/>\n    db 0<br \/>\ngdt_data:<br \/>\n    dw 0xffff<br \/>\n    dw 0<br \/>\n    db 0<br \/>\n    db 0x92<br \/>\n    db 0xcf<br \/>\n    db 0<br \/>\ngdt_end:<\/p>\n<p>gdt_desc:<br \/>\n    dw gdt_end &#8211; gdt_start &#8211; 1<br \/>\n    dd gdt_start<\/p>\n<p>times 510 &#8211; ($-$$) db 0<br \/>\ndw 0xaa55<\/p>\n<h5>&#xff08;6.1&#xff09;kernel.asm<\/h5>\n<p>; kernel.asm \u7b2c\u4e8c\u9636\u6bb5\u88f8\u673a\u5185\u6838&#xff0c;\u52a0\u8f7d\u52300x1000<br \/>\n[bits 32]<\/p>\n<p>; &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; EQU\u5e38\u91cf \u5bf9\u5e94C\u7ed3\u6784\u4f53 &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n; \u8fdb\u7a0b\u72b6\u6001<br \/>\nTASK_RUNNING        equ 0<br \/>\nTASK_INTERRUPTIBLE  equ 1<br \/>\nTASK_UNINTERRUPTIBLE equ 2<br \/>\nTASK_STOPPED        equ 4<br \/>\nTASK_ZOMBIE         equ 8<\/p>\n<p>; restart_block<br \/>\nRB_FN        equ 0<br \/>\nRB_ARG0      equ 4<br \/>\nRB_ARG1      equ 8<br \/>\nRB_ARG2      equ 12<br \/>\nRB_ARG3      equ 16<\/p>\n<p>; thread_info<br \/>\nTI_TASK         equ 0<br \/>\nTI_EXEC_DOMAIN  equ 4<br \/>\nTI_FLAGS        equ 8<br \/>\nTI_STATUS       equ 12<br \/>\nTI_CPU          equ 16<br \/>\nTI_PREEMPT_CNT  equ 20<br \/>\nTI_ADDR_LIMIT   equ 24<br \/>\nTI_RESTART_BLOCK equ 28<br \/>\nTI_SYSENTER_RET equ 48<br \/>\nTI_UACCESS_ERR  equ 52<br \/>\nTI_SIZE         equ 56<\/p>\n<p>; task_struct \u8fdb\u7a0b\u63cf\u8ff0\u7b26<br \/>\nTASK_PID    equ 0<br \/>\nTASK_STATE  equ 4<br \/>\nTASK_COMM   equ 8<br \/>\nTASK_SIZE   equ 24<\/p>\n<p>; \u663e\u5b58\u6587\u672c\u6a21\u5f0f 0xB8000&#xff0c;\u6bcf\u4e2a\u5b57\u7b26 2\u5b57\u8282&#xff1a;ASCII &#043; \u989c\u8272<br \/>\nVID_MEM equ 0xB8000<br \/>\n; \u989c\u8272&#xff1a;0x0F &#061; \u9ed1\u5e95\u767d\u5b57<br \/>\nWHITE_ON_BLACK equ 0x0F<br \/>\n; \u989c\u8272&#xff1a;0x0A &#061; \u9ed1\u5e95\u7eff\u5b57<br \/>\nGREEN_ON_BLACK equ 0x0A<br \/>\n; \u989c\u8272&#xff1a;0x04 &#061; \u9ed1\u5e95\u7ea2\u5b57<br \/>\nRED_ON_BLACK equ 0x04<\/p>\n<p>; &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; \u5168\u5c40\u6570\u636e&#xff1a;\u4e24\u4e2a\u8fdb\u7a0b\u7684thread_info\u3001task_struct &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n; \u653e\u5728\u9759\u6001\u5185\u5b58&#xff0c;\u88f8\u673a\u76f4\u63a5\u56fa\u5b9a\u5730\u5740<br \/>\n; task1 PCB<br \/>\ntask1  equ 0x1200<br \/>\nti1    equ 0x1300<\/p>\n<p>; task2 PCB<br \/>\ntask2  equ 0x1400<br \/>\nti2    equ 0x1500<\/p>\n<p>KERNEL_START:<br \/>\n    ; &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; \u521d\u59cb\u5316\u8fdb\u7a0b1 &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n    mov dword [ti1 &#043; TI_TASK], task1     ; ti1-&gt;task &#061; &amp;task1<br \/>\n    mov dword [task1 &#043; TASK_PID], 1<br \/>\n    mov dword [task1 &#043; TASK_STATE], TASK_RUNNING<br \/>\n    mov byte [task1 &#043; TASK_COMM], &#039;p&#039;<br \/>\n    mov byte [task1 &#043; TASK_COMM&#043;1], &#039;1&#039;<\/p>\n<p>    ; &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; \u521d\u59cb\u5316\u8fdb\u7a0b2 &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n    mov dword [ti2 &#043; TI_TASK], task2<br \/>\n    mov dword [task2 &#043; TASK_PID], 2<br \/>\n    mov dword [task2 &#043; TASK_STATE], TASK_INTERRUPTIBLE<br \/>\n    mov byte [task2 &#043; TASK_COMM], &#039;p&#039;<br \/>\n    mov byte [task2 &#043; TASK_COMM&#043;1], &#039;2&#039;<\/p>\n<p>    ; \u6e05\u5c4f<br \/>\n    call clear_screen<\/p>\n<p>    ; &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; \u7b80\u6613\u8c03\u5ea6\u5faa\u73af &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nSCHED_LOOP:<br \/>\n    ; \u68c0\u67e5\u8fdb\u7a0b1<br \/>\n    mov esi, ti1<br \/>\n    call check_process<\/p>\n<p>    ; \u68c0\u67e5\u8fdb\u7a0b2<br \/>\n    mov esi, ti2<br \/>\n    call check_process<\/p>\n<p>    ; \u7b80\u5355\u5ef6\u65f6\u5faa\u73af<br \/>\n    mov ecx,0x080000<br \/>\ndelay:<br \/>\n    loop delay<br \/>\n    jmp SCHED_LOOP<\/p>\n<p>; \u51fd\u6570 check_process(esi &#061; thread_info\u6307\u9488)<br \/>\n; \u8bfb\u53d6task-&gt;state&#xff0c;\u5224\u65ad\u72b6\u6001&#xff0c;\u8f93\u51fa\u5f69\u8272\u6587\u5b57\u5230\u663e\u5b58<br \/>\ncheck_process:<br \/>\n    push ebx<br \/>\n    push eax<br \/>\n    push edx<\/p>\n<p>    mov ebx, [esi &#043; TI_TASK]        ; ebx &#061; ti-&gt;task (task_struct)<br \/>\n    mov eax, [ebx &#043; TASK_STATE]     ; eax &#061; task-&gt;state<br \/>\n    mov edx, [ebx &#043; TASK_PID]       ; edx &#061; pid<\/p>\n<p>    ; \u663e\u5b58\u4f4d\u7f6e&#xff1a;pid*80*2&#xff0c;\u6bcf\u884c80\u5b57\u7b26&#xff0c;2\u5b57\u8282\u4e00\u4e2a\u5b57\u7b26<br \/>\n    mov edi, VID_MEM<br \/>\n    imul edx, 160<br \/>\n    add edi, edx<\/p>\n<p>    cmp eax, TASK_RUNNING<br \/>\n    je .proc_run<br \/>\n    cmp eax, TASK_INTERRUPTIBLE<br \/>\n    je .proc_sleep<br \/>\n    jmp .proc_other<\/p>\n<p>.proc_run:<br \/>\n    ; \u7eff\u5b57&#xff1a;\u8fd0\u884c\u6001<br \/>\n    mov byte [edi], &#039;P&#039;<br \/>\n    mov byte [edi&#043;1], GREEN_ON_BLACK<br \/>\n    mov byte [edi&#043;2], &#039;I&#039;<br \/>\n    mov byte [edi&#043;3], GREEN_ON_BLACK<br \/>\n    mov byte [edi&#043;4], &#039;D&#039;<br \/>\n    mov byte [edi&#043;5], GREEN_ON_BLACK<br \/>\n    mov byte [edi&#043;6], &#039;:&#039;<br \/>\n    mov byte [edi&#043;7], GREEN_ON_BLACK<br \/>\n    add edi,8<br \/>\n    mov al, [ebx &#043; TASK_COMM]<br \/>\n    mov [edi],al<br \/>\n    mov byte [edi&#043;1],GREEN_ON_BLACK<br \/>\n    mov al, [ebx &#043; TASK_COMM&#043;1]<br \/>\n    mov [edi&#043;2],al<br \/>\n    mov byte [edi&#043;3],GREEN_ON_BLACK<br \/>\n    mov byte [edi&#043;4], &#039; &#039;<br \/>\n    mov byte [edi&#043;5],GREEN_ON_BLACK<br \/>\n    mov byte [edi&#043;6],&#039;R&#039;<br \/>\n    mov byte [edi&#043;7],GREEN_ON_BLACK<br \/>\n    mov byte [edi&#043;8],&#039;U&#039;<br \/>\n    mov byte [edi&#043;9],GREEN_ON_BLACK<br \/>\n    mov byte [edi&#043;10],&#039;N&#039;<br \/>\n    mov byte [edi&#043;11],GREEN_ON_BLACK<br \/>\n    jmp .proc_done<br \/>\n.proc_sleep:<br \/>\n    ; \u7ea2\u5b57&#xff1a;\u7761\u7720\u6001<br \/>\n    mov byte [edi], &#039;P&#039;<br \/>\n    mov byte [edi&#043;1], RED_ON_BLACK<br \/>\n    mov byte [edi&#043;2], &#039;I&#039;<br \/>\n    mov byte [edi&#043;3], RED_ON_BLACK<br \/>\n    mov byte [edi&#043;4], &#039;D&#039;<br \/>\n    mov byte [edi&#043;5], RED_ON_BLACK<br \/>\n    mov byte [edi&#043;6], &#039;:&#039;<br \/>\n    mov byte [edi&#043;7], RED_ON_BLACK<br \/>\n    add edi,8<br \/>\n    mov al, [ebx &#043; TASK_COMM]<br \/>\n    mov [edi],al<br \/>\n    mov byte [edi&#043;1],RED_ON_BLACK<br \/>\n    mov al, [ebx &#043; TASK_COMM&#043;1]<br \/>\n    mov [edi&#043;2],al<br \/>\n    mov byte [edi&#043;3],RED_ON_BLACK<br \/>\n    mov byte [edi&#043;4], &#039; &#039;<br \/>\n    mov byte [edi&#043;5],RED_ON_BLACK<br \/>\n    mov byte [edi&#043;6],&#039;S&#039;<br \/>\n    mov byte [edi&#043;7],RED_ON_BLACK<br \/>\n    mov byte [edi&#043;8],&#039;L&#039;<br \/>\n    mov byte [edi&#043;9],RED_ON_BLACK<br \/>\n    mov byte [edi&#043;10],&#039;E&#039;<br \/>\n    mov byte [edi&#043;11],RED_ON_BLACK<br \/>\n.proc_other:<br \/>\n.proc_done:<br \/>\n    pop edx<br \/>\n    pop eax<br \/>\n    pop ebx<br \/>\n    ret<\/p>\n<p>; \u6e05\u5c4f&#xff1a;\u628a\u6574\u4e2a\u5c4f\u5e55\u586b\u5145\u9ed1\u5e95\u7a7a\u767d<br \/>\nclear_screen:<br \/>\n    mov edi, VID_MEM<br \/>\n    mov ecx, 80*25<br \/>\n    mov ah, WHITE_ON_BLACK<br \/>\n    mov al, &#039; &#039;<br \/>\n.cls_loop:<br \/>\n    mov [edi], ax<br \/>\n    add edi, 2<br \/>\n    loop .cls_loop<br \/>\n    ret<\/p>\n<p>; \u8865\u9f50\u5230512\u5b57\u8282\u6247\u533a<br \/>\ntimes 512 &#8211; ($ &#8211; KERNEL_START) db 0<\/p>\n<h5>&#xff08;6.2&#xff09;\u7f16\u8bd1\u3001\u6253\u5305\u6210\u955c\u50cf&#xff08;Linux \u4e0b&#xff09;<\/h5>\n<p># \u7f16\u8bd1\u5f15\u5bfc\u6247\u533a<br \/>\nnasm -f bin boot.asm -o boot.bin<br \/>\n# \u7f16\u8bd1\u7b2c\u4e8c\u9636\u6bb5\u5185\u6838<br \/>\nnasm -f bin kernel.asm -o kernel.bin<\/p>\n<p># \u751f\u6210\u8f6f\u76d8\u955c\u50cf&#xff0c;1\u4e2a\u6247\u533aboot &#043; 1\u6247\u533akernel&#xff0c;\u5176\u4f59\u586b\u51450<br \/>\ndd if&#061;\/dev\/zero of&#061;os.img bs&#061;512 count&#061;2880<br \/>\ndd if&#061;boot.bin of&#061;os.img conv&#061;notrunc<br \/>\ndd if&#061;kernel.bin of&#061;os.img bs&#061;512 seek&#061;1 conv&#061;notrunc<\/p>\n<h5>&#xff08;6.3&#xff09;\u7528 qemu \u6a21\u62df\u5668\u542f\u52a8<\/h5>\n<p>qemu-system-i386 -drive format&#061;raw,file&#061;os.img<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"168\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261003234107-6ac192936433a.png\" width=\"886\" \/><\/p>\n<h4>&#xff08;7.&#xff09;32 \u4f4d\u88f8\u673a\u591a\u8fdb\u7a0b\u5185\u6838<\/h4>\n<p>\u4e00\u4e2a\u7528 NASM &#043; C \u5199\u7684 32 \u4f4d\u88f8\u673a\u5185\u6838&#xff1a;\u4ece\u8f6f\u76d8\u955c\u50cf\u542f\u52a8&#xff0c;\u8fdb\u5165\u4fdd\u62a4\u6a21\u5f0f\u3001\u5efa\u7acb\u81ea\u5df1\u7684 GDT \u548c\u5206\u9875&#xff0c;\u7136\u540e\u8fd0\u884c\u4e24\u4e2a\u8fdb\u7a0b&#xff08;proc1 \/ proc2&#xff09;&#xff0c;\u7528\u534f\u4f5c\u5f0f\u4e0a\u4e0b\u6587\u5207\u6362\u8f6e\u6d41\u6267\u884c&#xff0c;\u5e76\u5728 VGA \u6587\u672c\u6a21\u5f0f\u4e0b\u6253\u5370\u5e26\u6709\u81ea\u589e\u8ba1\u6570\u7684\u8fd0\u884c\u4fe1\u606f\u3002<\/p>\n<h5>&#xff08;7.1&#xff09;\u73af\u5883\u5b89\u88c5\u4e0e\u8981\u6c42<\/h5>\n<p>1\u3001\u8fd0\u884c\u73af\u5883<\/p>\n<p>\u00a0\u00a0\u00a0\u00a064 \u4f4d Linux&#xff08;Debian \/ Ubuntu \/ Kali \u7b49&#xff09;&#xff0c;\u6216 Windows \u4e0a\u7684 WSL2\u3002\u7ec8\u7aef\u91cc\u80fd\u6267\u884c make\u3002<\/p>\n<p>2\u3001\u4f9d\u8d56\u5de5\u5177<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0nasm \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u6c47\u7f16\u5668&#xff0c;\u6c47\u7f16 boot.asm\u3001loader.asm<br \/>\n\u00a0 \u00a0 gcc\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0C \u7f16\u8bd1\u5668&#xff0c;\u9700\u8981\u652f\u6301 -m32 \u7f16\u8bd1&#xff08;\u80fd\u751f\u6210 32 \u4f4d\u76ee\u6807\u6587\u4ef6\u5373\u53ef&#xff09;<br \/>\n\u00a0 \u00a0 ld (binutils)\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u94fe\u63a5\u5668&#xff0c;\u7528 -m elf_i386 \u6309 kernel.ld \u94fe\u63a5<br \/>\n\u00a0 \u00a0 make\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u6784\u5efa\u5de5\u5177&#xff0c;\u6267\u884c Makefile<br \/>\n\u00a0 \u00a0 qemu-system-i386 \u00a0 \u00a0\u6a21\u62df\u5668&#xff0c;\u8fd0\u884c\u751f\u6210\u7684 os.img<\/p>\n<p>3\u3001\u5b89\u88c5\u547d\u4ee4&#xff08;Debian \/ Ubuntu \/ Kali&#xff09;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0sudo apt-get update<br \/>\n\u00a0 \u00a0 sudo apt-get install -y nasm gcc make binutils qemu-system-x86<\/p>\n<p>\u00a0 \u00a0 # \u53ef\u9009&#xff1a;\u60f3\u5728\u7cfb\u7edf\u91cc\u53e6\u5916\u94fe\u63a5\u666e\u901a 32 \u4f4d\u7a0b\u5e8f\u65f6\u518d\u88c5<br \/>\n\u00a0 \u00a0 sudo apt-get install -y gcc-multilib<\/p>\n<p>\u00a0 \u00a0 \u8bf4\u660e&#xff1a;\u672c\u9879\u76ee\u662f freestanding \u94fe\u63a5&#xff08;\u4e0d\u8fde libc\u3001\u76f4\u63a5\u7528 ld&#xff09;&#xff0c;\u6240\u4ee5\u4e0d\u88c5<br \/>\n\u00a0 \u00a0 gcc-multilib \u4e5f\u80fd\u6784\u5efa\u6210\u529f&#xff0c;\u5b83\u53ea\u662f\u65b9\u4fbf\u4f60\u505a\u522b\u7684 32 \u4f4d\u5b9e\u9a8c\u3002<\/p>\n<h5>&#xff08;7.2&#xff09;\u6784\u5efa\u4e0e\u8fd0\u884c<\/h5>\n<p>\u00a0 \u00a0 make\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u751f\u6210 os.img<br \/>\n\u00a0 \u00a0 make run\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u7528 QEMU \u542f\u52a8\u5e76\u663e\u793a\u5185\u6838\u753b\u9762<br \/>\n\u00a0 \u00a0 make debug \u00a0 \u00a0\u542f\u52a8 QEMU \u5e76\u505c\u5728\u8d77\u70b9\u7b49\u5f85 gdb&#xff08;gdb: target remote :1234&#xff09;<br \/>\n\u00a0 \u00a0 make clean \u00a0 \u00a0\u00a0\u5220\u9664\u5168\u90e8\u7f16\u8bd1\u4ea7\u7269<br \/>\n\u00a0 \u00a0 make rebuild\u00a0 \u00a0\u5148 clean \u518d\u91cd\u65b0\u7f16\u8bd1<\/p>\n<p>\u00a0 \u00a0\u6ca1\u6709\u56fe\u5f62\u754c\u9762\u65f6&#xff0c;\u53ef\u7528\u65e0\u754c\u9762\u65b9\u5f0f\u542f\u52a8&#xff1a;<\/p>\n<p>\u00a0 \u00a0 qemu-system-i386 -drive format&#061;raw,file&#061;os.img -display none<\/p>\n<h5>&#xff08;7.3&#xff09;\u6587\u4ef6\u8bf4\u660e<\/h5>\n<p>boot.asm<\/p>\n<p>\u4e3b\u5f15\u5bfc\u6247\u533a&#xff08;512 \u5b57\u8282&#xff09;\u3002\u7528 INT 13h \u8bfb 16 \u4e2a\u6247\u533a\u5230 0x1000&#xff1b;\u8bbe\u7f6e GDT&#xff1b;<br \/>\n\u5efa\u7acb 0x10000 \u9875\u76ee\u5f55 &#043; 0x11000 \u9875\u8868&#xff08;\u6052\u7b49\u6620\u5c04 0~4MB&#xff09;&#xff1b;<br \/>\n\u5f00\u542f\u5206\u9875\u540e\u8df3\u5230 0x1000<\/p>\n<p>; boot.asm \u4e3b\u5f15\u5bfc\u6247\u533a 512\u5b57\u8282<br \/>\n[bits 16]<br \/>\n[org 0x7c00]<\/p>\n<p>start:<br \/>\n    mov ax, 0<br \/>\n    mov es, ax<br \/>\n    mov bx, 0x1000      ; \u628a\u7b2c\u4e8c\u9636\u6bb5\u52a0\u8f7d\u5230\u7269\u7406\u5730\u57400x1000<br \/>\n    mov ah, 0x02        ; BIOS\u8bfb\u6247\u533a<br \/>\n    mov al, 16          ; \u8bfb\u53d616\u4e2a\u6247\u533a(8KB)&#xff0c;\u8db3\u591f\u88c5\u4e0b\u6574\u4e2a\u5185\u6838\u955c\u50cf<br \/>\n    mov ch, 0           ; \u78c1\u90530<br \/>\n    mov cl, 2           ; \u4ece\u7b2c2\u6247\u533a\u8bfb\u53d6&#xff08;\u6247\u533a1\u662f\u5f53\u524d\u5f15\u5bfc\u6247\u533a&#xff09;<br \/>\n    mov dh, 0           ; \u78c1\u59340<br \/>\n    int 0x13<br \/>\n    jc disk_error       ; \u8bfb\u76d8\u5931\u8d25\u8df3\u8f6c<\/p>\n<p>    cli<br \/>\n    lgdt [gdt_desc]<\/p>\n<p>    mov eax, cr0<br \/>\n    or eax, 1<br \/>\n    mov cr0, eax<\/p>\n<p>    jmp 0x08:pm_entry   ; \u8fdc\u8df3\u8f6c&#xff0c;\u5237\u65b0CS\u8fdb\u5165\u4fdd\u62a4\u6a21\u5f0f<\/p>\n<p>[bits 32]<br \/>\npm_entry:<br \/>\n    mov ax, 0x10<br \/>\n    mov ds, ax<br \/>\n    mov es, ax<br \/>\n    mov ss, ax<br \/>\n    mov esp, 0x7c00<\/p>\n<p>    ; \u6e05\u7a7a\u9875\u76ee\u5f55 0x10000<br \/>\n    mov edi, 0x10000<br \/>\n    mov ecx, 1024<br \/>\n    xor eax, eax<br \/>\n    rep stosd<\/p>\n<p>    ; \u9875\u76ee\u5f55\u7b2c0\u9879&#xff1a;\u6307\u5411\u9875\u88680x11000&#xff0c;Present&#043;RW<br \/>\n    mov dword [0x10000], 0x11003<\/p>\n<p>    ; \u6e05\u7a7a\u9875\u8868 0x11000<br \/>\n    mov edi, 0x11000<br \/>\n    mov ecx, 1024<br \/>\n    xor eax, eax<br \/>\n    rep stosd<\/p>\n<p>    ; \u586b\u5145\u9875\u8868&#xff1a;\u6620\u5c04\u865a\u62df\u5730\u57400~4MB \u5230\u7269\u7406\u5730\u57400~4MB<br \/>\n    mov ebx, 0x11000<br \/>\n    mov eax, 0x00000003<br \/>\n    mov ecx, 1024<br \/>\nfill_pt:<br \/>\n    mov [ebx], eax<br \/>\n    add ebx, 4<br \/>\n    add eax, 0x1000<br \/>\n    loop fill_pt<\/p>\n<p>    mov eax, 0x10000<br \/>\n    mov cr3, eax        ; CR3 &#061; \u9875\u76ee\u5f55\u7269\u7406\u5730\u5740<\/p>\n<p>    mov eax, cr0<br \/>\n    or eax, 0x80000000<br \/>\n    mov cr0, eax        ; \u5f00\u542f\u5206\u9875<\/p>\n<p>    jmp 0x08:0x1000     ; \u8df3\u5230\u7b2c\u4e8c\u9636\u6bb5\u5185\u6838\u4ee3\u7801&#xff01;<\/p>\n<p>disk_error:<br \/>\n    cli<br \/>\n    hlt<\/p>\n<p>gdt_start:<br \/>\n    dq 0<br \/>\ngdt_code:<br \/>\n    dw 0xffff<br \/>\n    dw 0<br \/>\n    db 0<br \/>\n    db 0x9a<br \/>\n    db 0xcf<br \/>\n    db 0<br \/>\ngdt_data:<br \/>\n    dw 0xffff<br \/>\n    dw 0<br \/>\n    db 0<br \/>\n    db 0x92<br \/>\n    db 0xcf<br \/>\n    db 0<br \/>\ngdt_end:<\/p>\n<p>gdt_desc:<br \/>\n    dw gdt_end &#8211; gdt_start &#8211; 1<br \/>\n    dd gdt_start<\/p>\n<p>times 510 &#8211; ($-$$) db 0<br \/>\ndw 0xaa55<\/p>\n<p>loader.asm<\/p>\n<p>\u4fdd\u62a4\u6a21\u5f0f\u4e0b\u7684\u5165\u53e3 start\u3002\u628a\u6808\u8bbe\u4e3a 0x6000 \u5e76\u8c03\u7528 C \u7684 kernel_main&#xff1b;<br \/>\n\u8fd4\u56de\u540e\u6b7b\u5faa\u73af\u505c\u673a\u3002<\/p>\n<p>; loader.asm [bits 32]<br \/>\n[bits 32]<br \/>\nglobal start<br \/>\nextern kernel_main   <\/p>\n<p>section .text<br \/>\nstart:<br \/>\n    ; \u8bbe\u7f6eC\u4ee3\u7801\u6808<br \/>\n    mov esp, 0x6000<br \/>\n    call kernel_main<\/p>\n<p>; \u6b7b\u5faa\u73af&#xff0c;\u5185\u6838\u8fd4\u56de\u5c31\u505c\u673a<br \/>\nhang_loop:<br \/>\n    hlt<br \/>\n    jmp hang_loop<\/p>\n<p>kernel.c<\/p>\n<p>\u5185\u6838\u4e3b\u4f53&#xff1a;\u8fdb\u7a0b\u63cf\u8ff0\u7b26 task_struct\u3001\u4e0a\u4e0b\u6587\u5207\u6362 cpu_switch \/ switch_to\u3001<br \/>\n\u4e24\u4e2a\u8fdb\u7a0b proc1 \/ proc2\u3001\u663e\u5b58\u8f93\u51fa\u4e0e\u6574\u6570\u663e\u793a\u3002<\/p>\n<p>\/\/ kernel.c<br \/>\n\/\/ 32 \u4f4d\u88f8\u673a C \u5185\u6838&#xff08;freestanding&#xff0c;\u6ca1\u6709 libc&#xff09;<br \/>\n\/\/ \u76ee\u6807&#xff1a;\u8ba9\u4e24\u4e2a\u8fdb\u7a0b proc1 \/ proc2 \u901a\u8fc7 switch_to \u505a\u4e0a\u4e0b\u6587\u5207\u6362&#xff0c;\u8f6e\u6d41\u8fd0\u884c\u3002<br \/>\n\/\/<br \/>\n\/\/ \u7269\u7406\u5185\u5b58\u5e03\u5c40&#xff08;boot.asm \u5df2\u5efa\u7acb 0~4MB \u7684\u6052\u7b49\u5206\u9875&#xff09;&#xff1a;<br \/>\n\/\/   0x00001000  \u5185\u6838\u955c\u50cf (.text\/.rodata\/.data\/.bss)<br \/>\n\/\/   0x00003000  proc1 \u5185\u6838\u6808&#xff08;\u6808\u9876 0x4000&#xff0c;\u5411\u4e0b\u589e\u957f&#xff09;<br \/>\n\/\/   0x00004000  proc2 \u5185\u6838\u6808&#xff08;\u6808\u9876 0x5000&#xff0c;\u5411\u4e0b\u589e\u957f&#xff09;<br \/>\n\/\/   0x00005000  \u5185\u6838\u4e3b\u7ebf\u7a0b\u6808&#xff08;\u6808\u9876 0x6000&#xff0c;\u5411\u4e0b\u589e\u957f&#xff09;<br \/>\n\/\/   0x00010000  \u9875\u76ee\u5f55 PD&#xff08;boot.asm \u7528&#xff0c;\u5185\u6838\u4e0d\u78b0&#xff09;<br \/>\n\/\/   0x00011000  \u9875\u8868   PT&#xff08;boot.asm \u7528&#xff0c;\u5185\u6838\u4e0d\u78b0&#xff09;<\/p>\n<p>#define TASK_RUNNING         0<br \/>\n#define TASK_INTERRUPTIBLE   1<br \/>\n#define TASK_UNINTERRUPTIBLE 2<br \/>\n#define TASK_STOPPED         4<br \/>\n#define TASK_ZOMBIE          8<\/p>\n<p>#define VID_MEM        0xB8000<br \/>\n#define WHITE_ON_BLACK 0x0F<br \/>\n#define GREEN_ON_BLACK 0x0A<br \/>\n#define RED_ON_BLACK   0x04<\/p>\n<p>\/\/ \u8fdb\u7a0b\u4e0a\u4e0b\u6587&#xff1a;\u53ea\u9700\u4fdd\u5b58\u6808\u6307\u9488\u5373\u53ef&#xff0c;\u56e0\u4e3a\u6240\u6709\u901a\u7528\u5bc4\u5b58\u5668\u90fd\u5df2\u7ecf<br \/>\n\/\/ \u538b\u5728\u8fd9\u4e2a\u4efb\u52a1\u81ea\u5df1\u7684\u6808\u4e0a\u4e86\u3002<br \/>\nstruct context {<br \/>\n    unsigned int eax;<br \/>\n    unsigned int ebx;<br \/>\n    unsigned int ecx;<br \/>\n    unsigned int edx;<br \/>\n    unsigned int esi;<br \/>\n    unsigned int edi;<br \/>\n    unsigned int ebp;<br \/>\n    unsigned int esp;   \/\/ \u5173\u952e\u5b57\u6bb5&#xff1a;\u88ab\u5207\u6362\u51fa\u53bb\u90a3\u4e00\u523b\u7684\u6808\u6307\u9488<br \/>\n    unsigned int eip;<br \/>\n};<\/p>\n<p>\/\/ \u8fdb\u7a0b\u63cf\u8ff0\u7b26<br \/>\nstruct task_struct {<br \/>\n    int  pid;<br \/>\n    int  state;<br \/>\n    char comm[16];<br \/>\n    struct context ctx;<br \/>\n};<\/p>\n<p>struct task_struct p1;<br \/>\nstruct task_struct p2;<br \/>\nstruct task_struct init_task;   \/\/ \u5185\u6838\u4e3b\u7ebf\u7a0b&#xff1a;\u7b2c\u4e00\u6b21\u5207\u6362\u65f6\u7684\u201c\u5f53\u524d\u4efb\u52a1\u201d<br \/>\nstruct task_struct *current;<\/p>\n<p>\/\/ \u6bcf\u4e2a\u4efb\u52a1\u72ec\u7acb\u7684\u5185\u6838\u6808\u9876&#xff08;\u6808\u5411\u4e0b\u589e\u957f&#xff09;<br \/>\n#define STACK_P1 0x4000<br \/>\n#define STACK_P2 0x5000<\/p>\n<p>\/\/ cpu_switch \u5728\u6808\u4e0a\u4fdd\u5b58\/\u6062\u590d 7 \u4e2a\u901a\u7528\u5bc4\u5b58\u5668 &#043; 1 \u4e2a\u8fd4\u56de\u5730\u5740<br \/>\n#define CTX_SLOTS 8<\/p>\n<p>\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;- \u663e\u5b58\u8f93\u51fa&#xff08;C \u76f4\u63a5\u5199 0xB8000&#xff09; &#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\nvoid print_str(int row, char *s, char color)<br \/>\n{<br \/>\n    char *v &#061; (char *)VID_MEM &#043; row * 160;<br \/>\n    while (*s) {<br \/>\n        *v&#043;&#043; &#061; *s&#043;&#043;;<br \/>\n        *v&#043;&#043; &#061; color;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ \u628a\u65e0\u7b26\u53f7\u6574\u6570\u6309\u5341\u8fdb\u5236\u5199\u5230\u7b2c row \u884c\u3001\u7b2c col \u5217&#xff0c;\u81f3\u5c11 width \u4f4d&#xff08;\u53f3\u5bf9\u9f50\u8865 0&#xff09;<br \/>\n\/\/ \u6ca1\u6709 libc&#xff0c;\u6240\u4ee5\u81ea\u5df1\u628a\u6574\u6570\u62c6\u6210\u5b57\u7b26<br \/>\nvoid print_uint(int row, int col, unsigned int val, int width, char color)<br \/>\n{<br \/>\n    char *v &#061; (char *)VID_MEM &#043; row * 160 &#043; col * 2;<br \/>\n    char buf[12];<br \/>\n    int n &#061; 0;<\/p>\n<p>    do {<br \/>\n        buf[n&#043;&#043;] &#061; (char)(&#039;0&#039; &#043; val % 10);<br \/>\n        val \/&#061; 10;<br \/>\n    } while (val &amp;&amp; n &lt; (int)sizeof(buf));<br \/>\n    while (n &lt; width &amp;&amp; n &lt; (int)sizeof(buf))<br \/>\n        buf[n&#043;&#043;] &#061; &#039;0&#039;;<\/p>\n<p>    while (n &gt; 0) {<br \/>\n        *v&#043;&#043; &#061; buf[&#8211;n];<br \/>\n        *v&#043;&#043; &#061; color;<br \/>\n    }<br \/>\n}<\/p>\n<p>void clear_screen(void)<br \/>\n{<br \/>\n    char *v &#061; (char *)VID_MEM;<br \/>\n    for (int i &#061; 0; i &lt; 25 * 80; i&#043;&#043;) {<br \/>\n        *v&#043;&#043; &#061; &#039; &#039;;<br \/>\n        *v&#043;&#043; &#061; WHITE_ON_BLACK;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ \u521d\u59cb\u5316\u4efb\u52a1&#xff0c;\u5e76\u6784\u9020\u201c\u4efb\u52a1\u7b2c\u4e00\u6b21\u88ab\u8c03\u5ea6\u201d\u65f6\u7684\u521d\u59cb\u6808\u3002<br \/>\n\/\/ \u6808\u5e03\u5c40&#xff08;\u4f4e\u5730\u5740 -&gt; \u9ad8\u5730\u5740&#xff09;&#xff0c;\u6b63\u597d\u5bf9\u5e94 cpu_switch \u91cc\u7684 pop \u987a\u5e8f&#xff1a;<br \/>\n\/\/   [esp&#043;0]&#061;ebp [esp&#043;4]&#061;edi [esp&#043;8]&#061;esi [esp&#043;12]&#061;edx<br \/>\n\/\/   [esp&#043;16]&#061;ecx [esp&#043;20]&#061;ebx [esp&#043;24]&#061;eax [esp&#043;28]&#061;\u5165\u53e3\u5730\u5740<br \/>\n\/\/ \u8fd9\u6837 switch_to \u6062\u590d\u5b8c\u5bc4\u5b58\u5668\u540e\u6267\u884c ret&#xff0c;\u5c31\u4f1a\u8df3\u5230\u4efb\u52a1\u5165\u53e3\u51fd\u6570\u3002<br \/>\nstatic void task_init(struct task_struct *t, int pid, const char *name,<br \/>\n                      void (*entry)(void), unsigned int stack_top)<br \/>\n{<br \/>\n    unsigned int *sp &#061; (unsigned int *)(stack_top &#8211; CTX_SLOTS * 4);<br \/>\n    int i;<\/p>\n<p>    t-&gt;pid   &#061; pid;<br \/>\n    t-&gt;state &#061; TASK_RUNNING;<br \/>\n    for (i &#061; 0; i &lt; 15 &amp;&amp; name[i]; i&#043;&#043;)<br \/>\n        t-&gt;comm[i] &#061; name[i];<br \/>\n    t-&gt;comm[i] &#061; &#039;\\\\0&#039;;<\/p>\n<p>    for (i &#061; 0; i &lt; CTX_SLOTS &#8211; 1; i&#043;&#043;)<br \/>\n        sp[i] &#061; 0;                             \/\/ 7 \u4e2a\u901a\u7528\u5bc4\u5b58\u5668\u7684\u521d\u503c<br \/>\n    sp[CTX_SLOTS &#8211; 1] &#061; (unsigned int)entry;   \/\/ ret \u7684\u76ee\u6807 &#061; \u4efb\u52a1\u5165\u53e3<\/p>\n<p>    t-&gt;ctx.esp &#061; (unsigned int)sp;             \/\/ \u7b2c\u4e00\u6b21\u5207\u6362\u65f6\u4ece\u8fd9\u91cc\u5f00\u59cb pop<br \/>\n    t-&gt;ctx.eip &#061; (unsigned int)entry;<br \/>\n}<\/p>\n<p>\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;- \u4e0a\u4e0b\u6587\u5207\u6362 &#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n\/\/ \u771f\u6b63\u5e72\u6d3b\u7684\u662f cpu_switch&#xff1a;<br \/>\n\/\/   1) \u628a\u5f53\u524d\u4efb\u52a1\u7684 7 \u4e2a\u901a\u7528\u5bc4\u5b58\u5668\u538b\u5230\u5b83\u81ea\u5df1\u7684\u6808\u4e0a&#xff0c;\u5e76\u4fdd\u5b58\u6b64\u65f6\u7684\u6808\u6307\u9488<br \/>\n\/\/   2) \u6362\u4e0a\u76ee\u6807\u4efb\u52a1\u7684\u6808\u6307\u9488<br \/>\n\/\/   3) \u6062\u590d\u76ee\u6807\u4efb\u52a1\u7684\u5bc4\u5b58\u5668\u5e76 ret \u2014\u2014 \u56de\u5230\u5b83\u4e0a\u6b21\u88ab\u5207\u8d70\u7684\u201c\u4e0b\u4e00\u6761\u6307\u4ee4\u201d<br \/>\n\/\/ \u5173\u952e&#xff1a;cpu_switch \u5fc5\u987b\u662f naked&#xff08;\u65e0\u6808\u5e27&#xff09;\u51fd\u6570\u3002<br \/>\n\/\/   \u666e\u901a C \u51fd\u6570\u4f1a\u5728\u5bc4\u5b58\u5668\u4e0e\u8fd4\u56de\u5730\u5740\u4e4b\u95f4\u63d2\u5165\u7f16\u8bd1\u5668\u81ea\u5df1\u7684\u6808\u5e27&#xff08;push ebp \/ sub esp&#xff09;&#xff0c;<br \/>\n\/\/   \u8fd9\u6837\u4efb\u52a1\u7b2c\u4e00\u6b21\u542f\u52a8\u8fd8\u80fd\u8dd1&#xff0c;\u4f46\u88ab\u201c\u91cd\u65b0\u8c03\u5ea6\u56de\u6765\u201d\u65f6 ret \u4f1a\u5f39\u5230\u6808\u5e27\u91cc\u7684\u5783\u573e\u5730\u5740\u3002<br \/>\n\/\/   task_init \u662f\u6309\u201c\u5bc4\u5b58\u5668\u7d27\u8ddf\u8fd4\u56de\u5730\u5740\u201d\u7684\u5e03\u5c40\u9884\u7f6e\u521d\u59cb\u6808\u7684&#xff0c;\u4e24\u8005\u5fc5\u987b\u4fdd\u6301\u4e00\u81f4\u3002<br \/>\n\/\/ \u6ce8\u610f&#xff1a;naked \u51fd\u6570\u4f53\u53ea\u80fd\u5199\u201c\u57fa\u672c\u6c47\u7f16\u201d&#xff0c;\u5bc4\u5b58\u5668\u76f4\u63a5\u5199 %eax&#xff0c;\u4e0d\u7528\u5199\u6210 %%eax\u3002<br \/>\n__attribute__((naked))<br \/>\nvoid cpu_switch(unsigned int *save_esp, unsigned int new_esp)<br \/>\n{<br \/>\n    __asm__ __volatile__(<br \/>\n        &#034;pushl %ebp\\\\n\\\\t&#034;<br \/>\n        &#034;pushl %edi\\\\n\\\\t&#034;<br \/>\n        &#034;pushl %esi\\\\n\\\\t&#034;<br \/>\n        &#034;pushl %edx\\\\n\\\\t&#034;<br \/>\n        &#034;pushl %ecx\\\\n\\\\t&#034;<br \/>\n        &#034;pushl %ebx\\\\n\\\\t&#034;<br \/>\n        &#034;pushl %eax\\\\n\\\\t&#034;<br \/>\n        &#034;movl  32(%esp), %eax\\\\n\\\\t&#034;  \/* save_esp&#xff08;\u8df3\u8fc7 7 \u4e2a\u5bc4\u5b58\u5668 &#043; \u8fd4\u56de\u5730\u5740&#xff09;*\/<br \/>\n        &#034;movl  %esp, (%eax)\\\\n\\\\t&#034;    \/* *save_esp &#061; \u5f53\u524d\u6808\u6307\u9488 *\/<br \/>\n        &#034;movl  36(%esp), %eax\\\\n\\\\t&#034;  \/* new_esp *\/<br \/>\n        &#034;movl  %eax, %esp\\\\n\\\\t&#034;      \/* \u5207\u5230\u76ee\u6807\u4efb\u52a1\u6808 *\/<br \/>\n        &#034;popl  %eax\\\\n\\\\t&#034;<br \/>\n        &#034;popl  %ebx\\\\n\\\\t&#034;<br \/>\n        &#034;popl  %ecx\\\\n\\\\t&#034;<br \/>\n        &#034;popl  %edx\\\\n\\\\t&#034;<br \/>\n        &#034;popl  %esi\\\\n\\\\t&#034;<br \/>\n        &#034;popl  %edi\\\\n\\\\t&#034;<br \/>\n        &#034;popl  %ebp\\\\n\\\\t&#034;<br \/>\n        &#034;ret\\\\n\\\\t&#034;                   \/* \u56de\u5230\u76ee\u6807\u4efb\u52a1\u4e0a\u6b21\u5207\u8d70\u7684\u8fd4\u56de\u5730\u5740 *\/<br \/>\n    );<br \/>\n}<\/p>\n<p>\/\/ \u8fdb\u7a0b\u4ee3\u7801\u8c03\u7528\u8fd9\u4e2a&#xff1a;\u66f4\u65b0 current&#xff0c;\u518d\u628a\u201c\u5f53\u524d\u6808\u5730\u5740\u201d\u548c\u201c\u76ee\u6807\u6808\u6307\u9488\u201d\u4ea4\u7ed9 cpu_switch<br \/>\nvoid switch_to(struct task_struct *next)<br \/>\n{<br \/>\n    struct task_struct *prev &#061; current;<br \/>\n    current &#061; next;                 \/\/ \u5fc5\u987b\u5728\u5207\u6362\u524d\u66f4\u65b0&#xff0c;\u56e0\u4e3a\u5207\u8d70\u540e\u4e0d\u4f1a\u518d\u56de\u6765\u6267\u884c<br \/>\n    cpu_switch(&amp;prev-&gt;ctx.esp, next-&gt;ctx.esp);<br \/>\n}<\/p>\n<p>\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;- \u4e24\u4e2a\u8fdb\u7a0b &#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n\/\/ counter \u662f\u5404\u81ea\u7684\u5c40\u90e8\u53d8\u91cf&#xff0c;\u5b58\u653e\u5728\u5404\u81ea\u7684\u5185\u6838\u6808\u4e0a&#xff0c;\u6240\u4ee5\u4e24\u4e2a\u8fdb\u7a0b\u4e92\u4e0d\u5f71\u54cd\u3002<br \/>\nvoid proc1(void)<br \/>\n{<br \/>\n    unsigned int counter &#061; 0;<br \/>\n    while (1) {<br \/>\n        print_str(1, &#034;PID1 Running &#034;, GREEN_ON_BLACK);<br \/>\n        print_uint(1, 13, counter, 10, GREEN_ON_BLACK);<br \/>\n        counter&#043;&#043;;<br \/>\n        p1.state &#061; TASK_INTERRUPTIBLE;<br \/>\n        switch_to(&amp;p2);                 \/\/ \u4e3b\u52a8\u8ba9\u51fa CPU \u7ed9 proc2<br \/>\n        p1.state &#061; TASK_RUNNING;        \/\/ \u518d\u6b21\u88ab\u8c03\u5ea6\u56de\u6765\u65f6\u4ece\u8fd9\u91cc\u7ee7\u7eed<br \/>\n    }<br \/>\n}<\/p>\n<p>void proc2(void)<br \/>\n{<br \/>\n    unsigned int counter &#061; 0;<br \/>\n    while (1) {<br \/>\n        print_str(2, &#034;PID2 Running &#034;, RED_ON_BLACK);<br \/>\n        print_uint(2, 13, counter, 10, RED_ON_BLACK);<br \/>\n        counter&#043;&#043;;<br \/>\n        p2.state &#061; TASK_INTERRUPTIBLE;<br \/>\n        switch_to(&amp;p1);                 \/\/ \u4e3b\u52a8\u8ba9\u51fa CPU \u7ed9 proc1<br \/>\n        p2.state &#061; TASK_RUNNING;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;- C \u5185\u6838\u5165\u53e3 &#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\nvoid kernel_main(void)<br \/>\n{<br \/>\n    clear_screen();<\/p>\n<p>    task_init(&amp;p1, 1, &#034;proc1&#034;, proc1, STACK_P1);<br \/>\n    task_init(&amp;p2, 2, &#034;proc2&#034;, proc2, STACK_P2);<\/p>\n<p>    \/\/ \u5185\u6838\u4e3b\u7ebf\u7a0b\u4e5f\u662f\u4e00\u4e2a\u4efb\u52a1&#xff1a;\u7b2c\u4e00\u6b21 switch_to \u9700\u8981\u4e00\u4e2a\u201cfrom\u201d<br \/>\n    init_task.pid   &#061; 0;<br \/>\n    init_task.state &#061; TASK_RUNNING;<br \/>\n    current &#061; &amp;init_task;<\/p>\n<p>    switch_to(&amp;p1);                     \/\/ \u542f\u52a8\u7b2c\u4e00\u4e2a\u8fdb\u7a0b<\/p>\n<p>    \/\/ \u53ea\u6709\u5f53\u5185\u6838\u4e3b\u7ebf\u7a0b\u88ab\u91cd\u65b0\u8c03\u5ea6\u56de\u6765\u624d\u4f1a\u6267\u884c\u5230\u8fd9\u91cc<br \/>\n    while (1)<br \/>\n        __asm__ __volatile__(&#034;hlt&#034;);<br \/>\n}<\/p>\n<p>kernel.ld<\/p>\n<p>\u94fe\u63a5\u811a\u672c\u3002\u6240\u6709\u6bb5\u4ece 0x1000 \u8d77\u8fde\u7eed\u6392\u5e03&#xff0c;\u6574\u4f53\u4fdd\u6301\u5728 0x3000 \u4ee5\u4e0b&#xff0c;<br \/>\n\u907f\u514d\u4e0e\u6808\u3001\u9875\u8868\u51b2\u7a81\u3002<\/p>\n<p>\/* kernel.ld \u94fe\u63a5\u811a\u672c<br \/>\n * \u6240\u6709\u6bb5\u4ece 0x1000 \u5f00\u59cb\u8fde\u7eed\u6392\u5e03&#xff0c;\u6574\u4f53\u4fdd\u6301\u5728 0x3000 \u4ee5\u4e0b&#xff0c;<br \/>\n * \u907f\u514d\u548c\u5185\u6838\u5bf9\u6808(0x3000~0x6000)\u3001\u9875\u76ee\u5f55\/\u9875\u8868(0x10000\/0x11000)\u51b2\u7a81\u3002<br \/>\n *\/<br \/>\nENTRY(start);<\/p>\n<p>SECTIONS {<br \/>\n    . &#061; 0x1000; \/* \u52a0\u8f7d\u5230\u7269\u7406\u5730\u57400x1000&#xff0c;\u548cboot\u7684jmp\u76ee\u6807\u5339\u914d *\/<\/p>\n<p>    .text : {<br \/>\n        *(.boot)<br \/>\n        *(.text)<br \/>\n        *(.text.*)<br \/>\n    }<\/p>\n<p>    .rodata : {<br \/>\n        *(.rodata)<br \/>\n        *(.rodata.*)<br \/>\n    }<\/p>\n<p>    .eh_frame : {<br \/>\n        *(.eh_frame)<br \/>\n    }<\/p>\n<p>    .data : {<br \/>\n        *(.data)<br \/>\n        *(.data.*)<br \/>\n    }<\/p>\n<p>    .bss : {<br \/>\n        *(COMMON)<br \/>\n        *(.bss)<br \/>\n        *(.bss.*)<br \/>\n    }<br \/>\n}<\/p>\n<p>Makefile<\/p>\n<p>\u6784\u5efa\u811a\u672c&#xff1a;\u6c47\u7f16\u3001\u7f16\u8bd1\u3001\u94fe\u63a5\u3001\u6253\u5305\u955c\u50cf&#xff0c;\u4ee5\u53ca\u8fd0\u884c \/ \u8c03\u8bd5 \/ \u6e05\u7406\u3002<\/p>\n<p># Makefile \u2014\u2014 32 \u4f4d\u88f8\u673a\u5185\u6838&#xff08;\u52a0\u6cb9&#xff09;<br \/>\n# \u4f9d\u8d56&#xff1a;nasm \/ gcc(\u652f\u6301 -m32 \u7f16\u8bd1) \/ ld(binutils) \/ make \/ qemu-system-i386<\/p>\n<p>CC      &#061; gcc<br \/>\nAS      &#061; nasm<br \/>\nLD      &#061; ld<br \/>\nQEMU    &#061; qemu-system-i386<\/p>\n<p># freestanding&#xff1a;\u4e0d\u8fde libc&#xff1b;-m32 \u751f\u6210 32 \u4f4d\u4ee3\u7801<br \/>\n# -fno-stack-protector            \u88f8\u673a\u6ca1\u6709 __stack_chk_fail&#xff0c;\u5fc5\u987b\u5173\u6389\u6808\u4fdd\u62a4<br \/>\n# -fno-asynchronous-unwind-tables \u4e0d\u751f\u6210 .eh_frame&#xff0c;\u51cf\u5c0f\u955c\u50cf\u4f53\u79ef<br \/>\nCFLAGS  &#061; -m32 -ffreestanding -c -g -fno-pic -fno-pie -fno-plt \\\\<br \/>\n          -fno-stack-protector -fno-asynchronous-unwind-tables<br \/>\nASFLAGS_BIN   &#061; -f bin<br \/>\nASFLAGS_ELF32 &#061; -f elf32<br \/>\nLDSCRIPT &#061; kernel.ld<\/p>\n<p>OBJS    &#061; loader.o kernel.o<br \/>\nIMG     &#061; os.img<\/p>\n<p># \u6240\u6709\u7531\u6784\u5efa\u751f\u6210\u7684\u4ea7\u7269&#xff08;make clean \u65f6\u4e00\u5e76\u5220\u9664&#xff09;<br \/>\nGENERATED &#061; boot.bin loader.o kernel.o kernel.elf kernel.bin $(IMG)<\/p>\n<p>.PHONY: all clean rebuild run debug<\/p>\n<p>all: $(IMG)<\/p>\n<p>kernel.bin kernel.elf: $(OBJS) $(LDSCRIPT)<br \/>\n$(LD) -m elf_i386 -T $(LDSCRIPT) $(OBJS) -o kernel.elf<br \/>\n$(LD) -m elf_i386 -T $(LDSCRIPT) &#8211;oformat binary $(OBJS) -o kernel.bin<\/p>\n<p>loader.o: loader.asm<br \/>\n$(AS) $(ASFLAGS_ELF32) loader.asm -o loader.o<\/p>\n<p>kernel.o: kernel.c<br \/>\n$(CC) $(CFLAGS) kernel.c -o kernel.o<\/p>\n<p>boot.bin: boot.asm<br \/>\n$(AS) $(ASFLAGS_BIN) boot.asm -o boot.bin<\/p>\n<p>$(IMG): boot.bin kernel.bin<br \/>\ndd if&#061;\/dev\/zero of&#061;$(IMG) bs&#061;512 count&#061;2880<br \/>\ndd if&#061;boot.bin of&#061;$(IMG) conv&#061;notrunc<br \/>\ndd if&#061;kernel.bin of&#061;$(IMG) bs&#061;512 seek&#061;1 conv&#061;notrunc<\/p>\n<p># \u5220\u9664\u5168\u90e8\u7f16\u8bd1\u4ea7\u7269&#xff08;.o \/ .bin \/ .elf \/ os.img&#xff09;<br \/>\nclean:<br \/>\nrm -f $(GENERATED)<\/p>\n<p># \u4e00\u6b65\u5b8c\u6210&#xff1a;\u5148\u6e05\u5e72\u51c0&#xff0c;\u518d\u91cd\u65b0\u7f16\u8bd1<br \/>\nrebuild:<br \/>\n$(MAKE) clean<br \/>\n$(MAKE) all<\/p>\n<p># \u542f\u52a8 QEMU \u8fd0\u884c\u5185\u6838<br \/>\nrun: $(IMG)<br \/>\n$(QEMU) -drive format&#061;raw,file&#061;$(IMG)<\/p>\n<p># \u542f\u52a8 QEMU \u5e76\u505c\u5728\u8d77\u70b9\u7b49\u5f85 gdb \u8fde\u63a5&#xff08;gdb: target remote :1234&#xff09;<br \/>\ndebug: $(IMG)<br \/>\n$(QEMU) -s -S -drive format&#061;raw,file&#061;$(IMG)<\/p>\n<p>\u751f\u6210\u7684\u6587\u4ef6&#xff08;make clean \u4f1a\u5168\u90e8\u5220\u9664&#xff09;<br \/>\n\u00a0 \u00a0 boot.bin \u00a0 \u00a0 \u00a0boot.asm \u6c47\u7f16\u51fa\u7684 512 \u5b57\u8282\u5f15\u5bfc\u6247\u533a\u3002<br \/>\n\u00a0 \u00a0 loader.o \u00a0 \u00a0 \u00a0loader.asm \u7684 32 \u4f4d ELF \u76ee\u6807\u6587\u4ef6\u3002<br \/>\n\u00a0 \u00a0 kernel.o \u00a0 \u00a0 \u00a0kernel.c \u7684 32 \u4f4d\u76ee\u6807\u6587\u4ef6\u3002<br \/>\n\u00a0 \u00a0 kernel.elf \u00a0 \u00a0\u5e26\u7b26\u53f7\u4fe1\u606f\u7684 ELF&#xff0c;\u7528\u4e8e objdump \/ gdb \u8c03\u8bd5\u3002<br \/>\n\u00a0 \u00a0 kernel.bin \u00a0 \u00a0\u7eaf\u4e8c\u8fdb\u5236\u5185\u6838\u955c\u50cf&#xff0c;\u88ab\u5199\u5165\u78c1\u76d8\u3002<br \/>\n\u00a0 \u00a0 os.img \u00a0 \u00a0 \u00a0 \u00a01.44MB \u8f6f\u76d8\u955c\u50cf&#xff1a;\u7b2c 0 \u6247\u533a\u662f boot.bin&#xff0c;\u7b2c 1 \u6247\u533a\u8d77\u662f kernel.bin\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"235\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261003234107-6ac192938ae99.png\" width=\"720\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5185\u6838\u5b66\u4e60\u7b2c\u4e8c\u5377 \u00b7 \u8fdb\u7a0b&#xff08;1.&#xff09;\u6587\u6863\u8bf4\u660e\u672c\u6587\u6863\u662f\u72ec\u7acb\u5b9e\u73b0\u5185\u6838&#xff0c;\u5e76\u4e14\u8bb0\u5f55\u5185\u6838\u5b66\u4e60\u8fc7\u7a0b&#xff0c;\u4ee5\u5e2e\u52a9\u540e\u6765\u7684\u5b66\u4e60\u8005\u6765\u7406\u89e3\u548c\u5b9e\u73b0\u5185\u6838&#xff0c;\u5982\u679c\u6709\u8bb2\u89e3\u4e0d\u6e05\u695a\u7684\u5730\u65b9\u8bf7\u89c1\u8c05\u3002&#xff08;2.&#xff09;\u7ec4\u4ef6\u5206\u6790#ifndef PROCESS_DEFS_H<br \/>\n#define PROCESS_DEFS_H\/\/ \u524d\u7f6e\u58f0\u660e<br \/>\nstruct task_struct;<br \/>\nstruct exec_domain;\/\/ \u5b8c\u6574\u5b9a\u4e49 restart_<\/p>\n","protected":false},"author":2,"featured_media":112604,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[12805,58,16,43,44],"topic":[],"class_list":["post-112606","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-12805","tag-linux","tag-16","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5531\u7740\u6b4c\u8c23\u628a\u5185\u6838\u5b66\uff08\u5377\u4e8c\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/112606.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5531\u7740\u6b4c\u8c23\u628a\u5185\u6838\u5b66\uff08\u5377\u4e8c\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5185\u6838\u5b66\u4e60\u7b2c\u4e8c\u5377 \u00b7 \u8fdb\u7a0b&#xff08;1.&#xff09;\u6587\u6863\u8bf4\u660e\u672c\u6587\u6863\u662f\u72ec\u7acb\u5b9e\u73b0\u5185\u6838&#xff0c;\u5e76\u4e14\u8bb0\u5f55\u5185\u6838\u5b66\u4e60\u8fc7\u7a0b&#xff0c;\u4ee5\u5e2e\u52a9\u540e\u6765\u7684\u5b66\u4e60\u8005\u6765\u7406\u89e3\u548c\u5b9e\u73b0\u5185\u6838&#xff0c;\u5982\u679c\u6709\u8bb2\u89e3\u4e0d\u6e05\u695a\u7684\u5730\u65b9\u8bf7\u89c1\u8c05\u3002&#xff08;2.&#xff09;\u7ec4\u4ef6\u5206\u6790#ifndef PROCESS_DEFS_H #define PROCESS_DEFS_H\/\/ \u524d\u7f6e\u58f0\u660e struct task_struct; struct exec_domain;\/\/ \u5b8c\u6574\u5b9a\u4e49 restart_\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/112606.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-03T23:41:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261003234107-6ac192936433a.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/112606.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/112606.html\",\"name\":\"\u5531\u7740\u6b4c\u8c23\u628a\u5185\u6838\u5b66\uff08\u5377\u4e8c\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-03T23:41:08+00:00\",\"dateModified\":\"2026-10-03T23:41:08+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/112606.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/112606.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/112606.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5531\u7740\u6b4c\u8c23\u628a\u5185\u6838\u5b66\uff08\u5377\u4e8c\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5531\u7740\u6b4c\u8c23\u628a\u5185\u6838\u5b66\uff08\u5377\u4e8c\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/112606.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5531\u7740\u6b4c\u8c23\u628a\u5185\u6838\u5b66\uff08\u5377\u4e8c\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5185\u6838\u5b66\u4e60\u7b2c\u4e8c\u5377 \u00b7 \u8fdb\u7a0b&#xff08;1.&#xff09;\u6587\u6863\u8bf4\u660e\u672c\u6587\u6863\u662f\u72ec\u7acb\u5b9e\u73b0\u5185\u6838&#xff0c;\u5e76\u4e14\u8bb0\u5f55\u5185\u6838\u5b66\u4e60\u8fc7\u7a0b&#xff0c;\u4ee5\u5e2e\u52a9\u540e\u6765\u7684\u5b66\u4e60\u8005\u6765\u7406\u89e3\u548c\u5b9e\u73b0\u5185\u6838&#xff0c;\u5982\u679c\u6709\u8bb2\u89e3\u4e0d\u6e05\u695a\u7684\u5730\u65b9\u8bf7\u89c1\u8c05\u3002&#xff08;2.&#xff09;\u7ec4\u4ef6\u5206\u6790#ifndef PROCESS_DEFS_H #define PROCESS_DEFS_H\/\/ \u524d\u7f6e\u58f0\u660e struct task_struct; struct exec_domain;\/\/ \u5b8c\u6574\u5b9a\u4e49 restart_","og_url":"https:\/\/www.wsisp.com\/helps\/112606.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-03T23:41:08+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261003234107-6ac192936433a.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"17 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/112606.html","url":"https:\/\/www.wsisp.com\/helps\/112606.html","name":"\u5531\u7740\u6b4c\u8c23\u628a\u5185\u6838\u5b66\uff08\u5377\u4e8c\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-03T23:41:08+00:00","dateModified":"2026-10-03T23:41:08+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/112606.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/112606.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/112606.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5531\u7740\u6b4c\u8c23\u628a\u5185\u6838\u5b66\uff08\u5377\u4e8c\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/112606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=112606"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/112606\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/112604"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=112606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=112606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=112606"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=112606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}