{"id":383,"date":"2023-07-23T16:04:55","date_gmt":"2023-07-23T08:04:55","guid":{"rendered":"https:\/\/blog.taiyang.space\/?p=383"},"modified":"2023-07-26T13:39:39","modified_gmt":"2023-07-26T05:39:39","slug":"l1-%e6%93%8d%e4%bd%9c%e7%b3%bb%e7%bb%9f%e5%90%af%e5%8a%a8","status":"publish","type":"post","link":"https:\/\/blog.taiyang.space\/?p=383","title":{"rendered":"L1-\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8"},"content":{"rendered":"<p>\u672c\u7ae0\u4e3b\u8981\u4ecb\u7ecdLinux0.11\u7684\u542f\u52a8\u8fc7\u7a0b\uff08\u5f00\u59cbmain\u51fd\u6570\u4e4b\u524d\u7684\u8fc7\u7a0b\uff09\uff0c\u4e3b\u8981\u662f\u5bf9bootsect.s\u3001setup.s\u3001head.s\u4e09\u4e2a\u7a0b\u5e8f\u7684\u4ecb\u7ecd\uff0c\u786c\u4ef6\u73af\u5883\u4e3aLinux0.11\u6240\u5728\u73af\u5883\u3002<\/p>\n<p>\u672c\u7ae0\u91cd\u70b9\u5728\u4e8e\u4e86\u89e3\uff0c\u800c\u4e0d\u662f\u7ea0\u7ed3\u5728 CPU \u4e0a\u3002\u64cd\u4f5c\u7cfb\u7edf\u7684\u6838\u5fc3\u4e0d\u5728\u8fd9\u91cc\u3002<\/p>\n<h2 id=\"11-\u8ba1\u7b97\u673a\u4e0a\u7535\">1.1 \u8ba1\u7b97\u673a\u4e0a\u7535<\/h2>\n<p>\u8ba1\u7b97\u673a\u4e0a\u7535\u540e\u8fdb\u884c\u4e86\u5982\u4e0b\u8fc7\u7a0b\uff1a<\/p>\n<ol start=\"\">\n<li>\u5728\u8ba1\u7b97\u673a\u5f00\u673a\u65f6\uff0c \u5185\u5b58\u4e2d\u6ca1\u6709\u5176\u4ed6\u7a0b\u5e8f\uff0c\u53ea\u6709 BIOS \u53ef\u6267\u884c\uff08BISO\u662f\u4e00\u6bb5\u56fa\u5316\u5728\u5185\u5b58\u4e2d\u7684\u7a0b\u5e8f\uff0c\u5b58\u653e\u5728 ROM \u4e2d\uff09\u3002CPU \u5904\u4e8e\u5b9e\u6a21\u5f0f\u72b6\u6001\uff0c\u5373\u5bfb\u5740\u65b9\u5f0f\u548c8086\u4e00\u6837\uff0c\u5bfb\u5740\u8303\u56f4\u53ea\u67091M\u3002CPU \u8bbe\u7f6e CS = 0xFFFF\uff1b IP = 0x0000\uff0c\u5373\u8ba9 PC \u6307\u9488\u6307\u5411 ROM BIOS \u6620\u5c04\u533a\uff08\u8ba1\u7b97\u673a\u521d\u59cb\u5316\u8fc7\u7a0b\u4e2d\u4f1a\u5c06BIOS\u4ee3\u7801\u590d\u5236\u5230ROM BIOS \u6620\u5c04\u533a\uff09\u3002CPU \u9996\u5148\u4ece ROM BIOS \u6620\u5c04\u533a\u7684\u7a0b\u5e8f\u5f00\u59cb\u6267\u884c\u3002<\/li>\n<li>CPU \u6267\u884c ROM BIOS \u6620\u5c04\u533a\u7684\u7a0b\u5e8f\uff0c\u8be5\u7a0b\u5e8f\u4e3b\u8981\u8d1f\u8d23\u68c0\u6d4b\u7cfb\u7edf\u786c\u4ef6\u662f\u5426\u6b63\u5e38\uff0c\u5e76\u5efa\u7acb\u4e2d\u65ad\u5411\u91cf\u8868\uff08\u8fd9\u53ea\u662f\u4f9b\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8\u65f6\u4f7f\u7528\uff0c\u5728\u64cd\u4f5c\u7cfb\u7edf\u5efa\u7acb\u5b8c\u6210\u540e\u4f1a\u5c06\u5b83\u8986\u76d6\u6e05\u7406\uff0c\u5e76\u5efa\u7acb\u65b0\u7684\u4e2d\u65ad\u5411\u91cf\u8868\uff09<\/li>\n<li>\u5728 ROM BIOS \u6620\u5c04\u533a\u7684\u7a0b\u5e8f\u6267\u884c\u7684\u6700\u540e\uff0c\u8be5\u7a0b\u5e8f\u4f1a\u5c06\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8\u7a0b\u5e8f\uff08bootsect.s\uff09\u4ece\u78c1\u76d8\u7b2c1\u4e2a\u6247\u533a\uff080\u78c1\u5934\u30010\u67f1\u9762\u3001\u7b2c1\u6247\u533a\uff09\u590d\u5236\u5230\u5185\u5b58 0X07C00\u5f00\u59cb\u7684\u4f4d\u7f6e\uff0c\u5e76\u8bbe\u7f6e CS = 0x07c0\uff0c IP = 0x0000\u3002\u6700\u540e CPU \u8f6c\u79fb\u5230 bootsect.s\uff080X07C00\u5904\uff09\u5f00\u59cb\u6267\u884c\u3002\u81f3\u6b64CUP\u624d\u6b63\u5f0f\u5f00\u59cb\u6267\u884c\u201c\u6211\u4eec\u81ea\u5df1\u7f16\u5199\u7684\u7a0b\u5e8f\u201d\u3002<\/li>\n<\/ol>\n<p>\u5728bios\u6267\u884c\u7ed3\u675f\u540e\uff0c\u8ba1\u7b97\u673a\u5185\u5b58\u4e2d\u7684\u5185\u5bb9\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/picture.chentaiyang.space\/202307261217658.png\" referrerpolicy=\"no-referrer\" alt=\"img\"><\/p>\n<p>\u5728\u8ba1\u7b97\u673a\u542f\u52a8\u524d\uff0c\u64cd\u4f5c\u7cfb\u7edf\u7684\u7a0b\u5e8f\u5df2\u7ecf\u5b58\u653e\u5728\u4e86\u78c1\u76d8\u4e4b\u4e2d\uff0cLinux0.11\u5185\u6838\u5728\u78c1\u76d8\u4e2d\u7684\u5206\u5e03\u60c5\u51b5\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/picture.chentaiyang.space\/202307261217664.png\" referrerpolicy=\"no-referrer\" alt=\"img\"><\/p>\n<p>\u56fe\u4e2d\u7684 system \u6a21\u5757 \u4e5f\u5c31\u662f Linux0.11 \u5185\u6838\u7684\u5176\u4ed6\u90e8\u5206\uff0c\u5982\uff1ahead.s\u3001main.c \u7b49\u7b49\u3002\u5f53\u65f6\u7684\u78c1\u76d8\u7ed3\u6784\u4e3b\u8981\u662f\u901a\u8fc7\u78c1\u5934\u6570(Heads), \u67f1\u9762\u6570(Cylinders), \u6247\u533a\u6570(Sectors)\u4e09\u4e2a\u53c2\u6570\u8bfb\u5199\u78c1\u76d8\u4fe1\u606f\u3002\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>\u78c1\u5934\u6570(Heads) \u8868\u793a\u786c\u76d8\u603b\u5171\u6709\u51e0\u4e2a\u78c1\u5934,\u4e5f\u5c31\u662f\u6709\u51e0\u4e2a\u76d8\u9762, \u6700\u5927\u4e3a255(\u7528 8 \u4e2a\u4e8c\u8fdb\u5236\u4f4d\u5b58\u50a8)\uff1b<\/li>\n<li>\u67f1\u9762\u6570(Cylinders) \u8868\u793a\u786c\u76d8\u6bcf\u4e00\u9762\u76d8\u7247\u4e0a\u6709\u51e0\u6761\u78c1\u9053\uff0c\u6700\u5927\u4e3a1023(\u7528 10\u4e2a\u4e8c\u8fdb\u5236\u4f4d\u5b58\u50a8)\uff1b<\/li>\n<li>\u6247\u533a\u6570(Sectors) \u8868\u793a\u6bcf\u4e00\u6761\u78c1\u9053\u4e0a\u6709\u51e0\u4e2a\u6247\u533a, \u6700\u5927\u4e3a 63 (\u75286\u4e2a\u4e8c\u8fdb\u5236\u4f4d\u5b58\u50a8)\uff1b\u6bcf\u4e2a\u6247\u533a\u4e00\u822c\u662f512\u4e2a\u5b57\u8282\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2 id=\"12-\u6267\u884cbootsects\">1.2 \u6267\u884cbootsect.s<\/h2>\n<p>bootsect.s\u662f\u64cd\u4f5c\u7cfb\u7edf\u7684\u5f15\u5bfc\u7a0b\u5e8f\uff0c\u662f\u64cd\u4f5c\u7cfb\u7edf\u6267\u884c\u7684\u7b2c\u4e00\u4e2a\u7a0b\u5e8f\u3002bootsect.s\u4e3b\u8981\u8fdb\u884c\u4e86\u4ee5\u4e0b\u5de5\u4f5c\uff1a<\/p>\n<p>1\u3001 \u5c06\u81ea\u5df1\uff08bootsect.s\uff09\u642c\u79fb\u5230\u5185\u5b580X90000 \u5f00\u59cb\u7684\u4f4d\u7f6e\uff0c\u7136\u540e\u8df3\u8f6c\u81f30X90000+go \u5904\u6267\u884c\u7a0b\u5e8f\uff0cbootsect.s \u7684\u5927\u5c0f\u4e0d\u4f1a\u8d85\u8fc71\u4e2a\u6247\u533a\uff0c\u78c1\u76d8\u7684 0\u6247\u533a\u53ea\u7528\u4e8e\u5b58\u653e bootsect.s\u3002\uff08bootsect.s \u7684\u7b2c46\u81f3\u7b2c57\u884c\uff09<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">_start:   \uff01\u7b2c46\u884c\nmov\tax,#BOOTSEG\nmov\tds,ax\nmov\tax,#INITSEG\nmov\tes,ax\nmov\tcx,#256\nsub\tsi,si\nsub\tdi,di\nrep   \nmovw    \uff01\u5c06\u81ea\u5df1\u642c\u52300X90000\u5904\njmpi\tgo,INITSEG    \uff01\u8df3\u8f6c\u81f30X90000+go \u5904\u6267\u884c\u7a0b\u5e8f\ngo:\tmov\tax,cs\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>2\u3001 \u5229\u7528 BIOS \u4e2d\u65ad (int 13) \u5c06 setup.s \u4ece\u78c1\u76d8\u52a0\u8f7d\u5230\u5185\u5b580X90200\u5f00\u59cb\u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u770b\u51fa\u52a0\u8f7d\u81f3\u5185\u5b58\u540esetup.s\u4f9d\u65e7\u7d27\u8ddf\u5728bootsect.s\u4e4b\u540e\u3002\uff08bootsect.s\u7b2c67\u81f3\u7b2c73\u884c\uff09<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">load_setup:     \uff01\u7b2c67\u884c\n\tmov\tdx,#0x0000\t\t! drive 0, head 0\n\tmov\tcx,#0x0002\t\t! sector 2, track 0\n\tmov\tbx,#0x0200\t\t! address = 512, in INITSEG\n\tmov\tax,#0x0200+SETUPLEN\t! service 2, nr of sectors\n\tint\t0x13\t\t\t! read it\n\tjnc\tok_load_setup\t\t! ok - continue\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>3\u3001 \u83b7\u53d6\u78c1\u76d8\u7684\u4fe1\u606f\uff0c\u8fd9\u91cc\u4e0d\u662f\u5f88\u91cd\u8981\uff08bootsect.s\u7b2c83\u81f3\u7b2c85\u884c\uff09<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">mov\tdl,#0x00   \uff01\u7b2c83\u884c\nmov\tax,#0x0800\t! AH=8 is get drive parameters\nint\t0x13\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>4\u3001\u68c0\u6d4b\u6211\u4eec\u8981\u4f7f\u7528\u54ea\u4e00\u4e2a\u6839\u6587\u4ef6\u7cfb\u7edf\u8bbe\u5907\uff08bootsect.s\u7b2c117\u81f3\u7b2c120\u884c\uff09\u3002\u5982\u679c\u5df2\u7ecf\u6307\u5b9a\u4e86\u6839\u6587\u4ef6\u7cfb\u7edf\u6240\u5728\u7684\u8bbe\u5907\uff0c\u90a3\u4e48\u5c31\u76f4\u63a5\u4f7f\u7528\u7ed9\u5b9a\u7684\u8bbe\u5907\u3002<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">\tseg cs    \uff01\u7b2c117\u884c\n\tmov\tax,root_dev   ! root_dev \u5728\u7b2c508\u3001509\u5b57\u8282\u5904\u88ab\u5b9a\u4e49\uff08\u5728bootsect.s\u7684\u7b2c250\u884c\uff09\uff0c\u5176\u503c\u4e3a0x306\uff0c\u8bf4\u660e\u6839\u6587\u4ef6\u7cfb\u7edf\u5728\u7b2c2\u4e2a\u78c1\u76d8\u7684\u7b2c1\u4e2a\u5206\u533a\u3002\n\tcmp\tax,#0         ! \u82e5root_dev \u4e0d\u4e3a0\uff0c\u5219\u8ba4\u4e3a\u6839\u6587\u4ef6\u7cfb\u7edf\u6240\u5728\u7684\u8bbe\u5907\u53f7\u5df2\u7ecf\u88ab\u5b9a\u4e49\u3002\n\tjne\troot_defined\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>5\u3001\u5728\u5c4f\u5e55\u4e0a\u6253\u5370&#8221;Loading system \u2026&#8221;\u3002\uff08bootsect.s\u7b2c98\u81f3\u7b2c102\u884c\uff09<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">mov\tcx,#24   \uff01\u7b2c98\u884c\nmov\tbx,#0x0007\t\t! page 0, attribute 7 (normal)\nmov\tbp,#msg1\nmov\tax,#0x1301\t\t! write string, move cursor\nint\t0x10\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>6\u3001\u5c06 system \u6a21\u5757\u7684\u4ee3\u7801\u4ece\u78c1\u76d8\u642c\u5230\u5185\u5b580x10000\u5f00\u59cb\u7684\u4f4d\u7f6e\u3002SYSSIZE = 0x3000 is 0x30000 bytes = 196kB \u3002Linux0.11\u4e2d\u9ed8\u8ba4\u5185\u6838\u5927\u5c0f\u4e0d\u4f1a\u8d85\u8fc7196KB\u3002<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">mov\tax,#SYSSEG   \uff01\u7b2c107\u884c\nmov\tes,ax\t\t! segment of 0x010000\ncall\tread_it\n...\nread_it:\n...\nread_track:\n...\nmov dx,head  \uff01head.s\u662fsystem\u6a21\u5757\u7684\u7b2c\u4e00\u4e2a\u7a0b\u5e8f\nmov dh,dl\nmov dl,#0\nand dx,#0x0100\nmov ah,#2\nint 0x13   !\u8fd9\u624d\u662f\u6b63\u5f0f\u5f00\u59cb\u642c\u8fd0system\u6a21\u5757\u3002\n...\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>7\u3001 \u8df3\u8f6c\u52300x90200\u5904\u6267\u884c\uff0c\u8f6c\u79fb\u5230 setup.s \u53bb\u6267\u884c\u3002<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">\uff01SETUPSEG = 0x9020\njmpi\t0,SETUPSEG  \uff01\u7b2c139\u884c\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h2 id=\"13-\u6267\u884csetups\">1.3 \u6267\u884csetup.s<\/h2>\n<p>setup.s\u4e3b\u8981\u8fdb\u884c\u4e86\u4ee5\u4e0b\u5de5\u4f5c\uff1a<\/p>\n<ol start=\"\">\n<li>\u5229\u7528BIOS\u7684\u4e2d\u65ad\u83b7\u53d6\u8ba1\u7b97\u673a\u53c2\u6570\uff08\u5185\u5b58\u5927\u5c0f\uff0c\u78c1\u76d8\u53c2\u6570\u3001\u663e\u793a\u5668\u53c2\u6570\u7b49\uff09\uff0c\u5e76\u5c06\u53c2\u6570\u5b58\u51650X90000\u5f00\u59cb\u7684\u4f4d\u7f6e\uff08\u5c06bootsect.s\u8986\u76d6\u6389\uff09\u3002\u6211\u4eec\u53ef\u4ee5\u5148\u4e0d\u7ba1\u8fd9\u4e9b\u53c2\u6570\uff0c\u7b49\u540e\u9762\u7528\u5230\u4e86\u518d\u770b\u3002\u5173\u4e8e setup.s \u7a0b\u5e8f\u5177\u4f53\u8bfb\u53d6\u7684\u7cfb\u7edf\u786c\u4ef6\u53c2\u6570\uff0c\u53ca\u5176\u8fd9\u4e9b\u53c2\u6570\u7684\u5b58\u653e\u4f4d\u7f6e\u8bf7\u53c2\u8003\u300aLinux\u5185\u6838\u5b8c\u5168\u5256\u6790\u2014\u2014\u57fa\u4e8e0.12\u5185\u6838\u300b\u3002<\/li>\n<li>\u5c06system\u6a21\u5757\u4ece\u5185\u5b580x10000 \u5904\u79fb\u5230\u7269\u7406\u5185\u5b58\u8d77\u59cb\u4f4d\u7f6e 0X0000 0000\u3002<strong>\u8fd9\u610f\u5473\u7740\u539f\u6765\u7684 BIOS \u4e2d\u65ad\u5411\u91cf\u8868\u88ab\u8986\u76d6\u4e86\u3002<\/strong><\/li>\n<\/ol>\n<pre><code class=\"language-shell\" lang=\"shell\">do_move:   \uff01\u7b2c114\u884c\n\tmov\tes,ax\t\t! destination segment\n\tadd\tax,#0x1000\n\tcmp\tax,#0x9000\n\tjz\tend_move\n\tmov\tds,ax\t\t! source segment\n\tsub\tdi,di\n\tsub\tsi,si\n\tmov \tcx,#0x8000\n\trep\n\tmovsw\n\tjmp\tdo_move\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<ol start=\"3\">\n<li>\u8bbe\u7f6egdt\u548cidt\u3002\u8fd9\u53ea\u662f\u4e2a\u4e34\u65f6\u8868\uff0c\u4e4b\u540e\u4f1a\u91cd\u65b0\u8bbe\u7f6egdt\u548cidt\uff0c\u8fd9\u91cc\u662f\u4e3a\u4e86\u65b9\u4fbfcpu\u8fdb\u5165\u4fdd\u62a4\u6a21\u5f0f\u65f6\u80fd\u6b63\u786e\u5bfb\u5740\uff08\u8fd9\u91cc\u4e3b\u8981\u662f\u4e3a\u4e86\u4fdd\u8bc1\u80fd\u8df3\u5230system\u6a21\u5757\u6267\u884c\uff09\u3002\u8bbe\u7f6e8259\u82af\u7247\uff0c\u91cd\u65b0\u8bbe\u7f6e\u4e2d\u65ad\u5411\u91cf\u8868\u3002<\/li>\n<\/ol>\n<pre><code class=\"language-shell\" lang=\"shell\">lidt\tidt_48\t\t! load idt with 0,0   \uff01\u7b2c132\u884c\nlgdt\tgdt_48\t\t! load gdt with whatever appropriate\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<ol start=\"4\">\n<li>CPU\u8fdb\u516532\u4f4d\u7684\u4fdd\u62a4\u6a21\u5f0f\uff0c\u7a0b\u5e8f\u8df3\u8f6c\u81f3\u7269\u7406\u5185\u5b58\u8d77\u59cb\u4f4d\u7f6e\u5f00\u59cb\u6267\u884c\uff08head.s\u5904\uff09<\/li>\n<\/ol>\n<pre><code class=\"language-shell\" lang=\"shell\">mov\tax,#0x0001\t! protected mode (PE) bit   \uff01\u7b2c189\u884c\nlmsw\tax\t\t! This is it!\njmpi\t0,8\t\t! jmp offset 0 of segment 8 (cs)\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h2 id=\"14-\u6267\u884cheads\">1.4 \u6267\u884chead.s<\/h2>\n<p>head.s \u91cc\u9762\u7684\u5185\u5bb9\u6709\u70b9\u590d\u6742\uff0c\u8fd8\u6ca1\u5b8c\u5168\u5f04\u61c2\uff0c\u4e0d\u8fc7\u5f71\u54cd\u4e0d\u5927\uff0c\u73b0\u5728\u53ea\u9700\u8981\u4e86\u89e3head.s\u7684\u4e3b\u8981\u5de5\u4f5c\u5373\u53ef\u3002<br \/>\n1\u3001\u8bbe\u7f6e\u6bb5\u9009\u62e9\u5668\u3002\u5c06ds\u3001es\u3001fs\u7b49\u5bc4\u5b58\u5668\u90fd\u8d4b\u503c\u4e3a0x10\u3002\u8fd9\u91cc\u76840x10\u8868\u793a\uff1a\u7279\u6743\u7ea7\u4e3a0\u3001\u4f7f\u7528GDT\u7684\u7b2c2\u9879\u5373\u6570\u636e\u6bb5\u63cf\u8ff0\u7b26\u3002<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">.globl idt,gdt,pg_dir,tmp_floppy_area         #\u7b2c15\u884c\npg_dir:                # \u9875\u76ee\u5f55\u5b58\u653e\u7684\u8d77\u59cb\u4f4d\u7f6e\n.globl startup_32\nstartup_32:\n\tmovl $0x10,%eax \n\tmov %ax,%ds\n\tmov %ax,%es\n\tmov %ax,%fs\n\tmov %ax,%gs\n\tlss stack_start,%esp # \u8bbe\u7f6e\u5806\u6808\u7684\u4f4d\u7f6e\uff0c\u5f53\u7136\u8fd9\u53ea\u662f\u4e2a\u6682\u65f6\u7684\uff0c\u540e\u9762\u8fd8\u4f1a\u4fee\u6539\u3002\n\t                     # stack_start \u5b9a\u4e49\u5728 kernel\/sched.c \u6587\u4ef6\u4e2d\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>2\u3001 \u8bbe\u7f6e IDT \u548c GDT\u3002<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">\tcall setup_idt    #\u7b2c 25 \u884c\n\tcall setup_gdt\n<\/code><\/pre>\n<p>\u5176\u4e2d IDT \u5171\u6709256\u9879\u4e14\u5168\u90e8\u586b\u5145\u4e3a ignore_int \u51fd\u6570\u7684\u504f\u79fb\u5730\u5740\uff0cignore_int\u662f\u4e00\u4e2a\u53ea\u62a5\u9519\u8bef\u7684\u54d1\u4e2d\u65ad\u5b50\u51fd\u6570\u3002\u800c GDT \u4f5c\u6210\u5982\u4e0b\u6837\u5b50\uff0c\u53ef\u4ee5\u770b\u51fa\u8fd9\u65f6\u5019\u8fd8\u6ca1\u6709\u8bbe\u7f6e LDT \uff1a<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">gdt:\t.quad 0x0000000000000000\t\/* NULL descriptor \u7b2c0\u9879\u4e0d\u4f7f\u7528*\/    \/*\u7b2c 236 \u884c*\/\n\t.quad 0x00c09a0000000fff\t\/* 16Mb \u4ee3\u7801\u6bb5\u63cf\u8ff0\u7b26\uff0c\u5176\u4e2d\u4ee3\u7801\u6bb5\u57fa\u5730\u5740\u4e3a0\uff0c\u6bb5\u7684\u957f\u5ea6\u4e3a16MB*\/\n\t.quad 0x00c0920000000fff\t\/* 16Mb \u6570\u636e\u6bb5\u63cf\u8ff0\u7b26\uff0c\u5176\u4e2d\u6570\u636e\u6bb5\u57fa\u5730\u5740\u4e3a0\uff0c\u6bb5\u7684\u957f\u5ea6\u4e3a16MB*\/\n\t.quad 0x0000000000000000\t\/* TEMPORARY - don't use \u4fdd\u7559\uff0c\u6ca1\u6709\u4f7f\u7528*\/\n\t.fill 252,8,0\t\t\t\/* space for LDT's and TSS's etc *\/\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>3\u3001 \u68c0\u6d4bA20\u7ebf\u662f\u5426\u5f00\u542f\uff0c\u68c0\u6d4b\u6570\u5b57\u534f\u5904\u7406\u5668\u7b49\u3002<\/p>\n<p>4\u3001 \u5f00\u542f\u5206\u9875\u673a\u5236\uff0c\u8bbe\u7f6e\u9875\u76ee\u5f55\u7b49\u3002setup_paging \u51fd\u6570\u5c31\u662f\u8bbe\u7f6e\u5206\u9875\u673a\u5236\u7684\u3002\u9875\u8868\u4ece\u5730\u5740 0x0 \u7684\u4f4d\u7f6e\u5f00\u59cb\u5b58\u653e\uff0c\u81f3\u4e8e\u9875\u8868\u88ab\u8bbe\u7f6e\u6210\u4ec0\u4e48\u6837\u5b50\uff0c\u8fd9\u91cc\u53ef\u4ee5\u5148\u4e0d\u7ba1\uff0c\u7b49\u5230\u5b66\u4e60\u5185\u5b58\u7ba1\u7406\u7ae0\u8282\u7684\u65f6\u5019\u518d\u56de\u8fc7\u6765\u770b\u5c31\u597d\u3002head.s\u5728\u6700\u540e\u63a7\u5236\u7a0b\u5e8f\u8fdb\u5165\u4e86main\u51fd\u6570\u3002\u7a0b\u5e8f\u662f\u5229\u7528setup_paging \u4e2d\u7684 ret \u6307\u4ee4\uff08\u51fa\u6808\uff09\u8fdb\u5165main\u51fd\u6570\u7684\u3002<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">after_page_tables:   # \u7b2c137\u884c\uff0c\u5728\u8bbe\u7f6e\u597d\u9875\u8868\u540e\u8fdb\u5165main\u51fd\u6570\u3002\n\tpushl $0\t\t# These are the parameters to main :-)\n\tpushl $0\n\tpushl $0\n\tpushl $L6\t\t\t\t\t# return address for main, if it decides to.\n\tpushl $main     \t# \u5148\u5c06main\u538b\u6808\uff0c\u518d\u5229\u7528 setup_paging \u91cc\u9762\u7684 ret \u8fdb\u5165 main \u51fd\u6570\u3002\n\tjmp setup_paging\t# jmp\u4e0d\u4f1a\u8fdb\u884c\u538b\u6808\u64cd\u4f5c\uff0c\u8fd9\u91cc\u8981\u548ccall\u533a\u522b\u4e00\u4e0b\u3002\nL6:\n\tjmp L6\t\t\t# main should never return here, but\n  \t\t\t\t    # just in case, we know what happens.\n<\/code><\/pre>\n<p>\u8fdb\u5165 main \u51fd\u6570\u4e4b\u540e\u4f1a\u8fdb\u884c\u4e00\u5806\u521d\u59cb\u5316\uff0c\u4e3b\u8981\u662f\u8981\u5efa\u7acb\u8d77\u4e00\u4e9b\u91cd\u8981\u7684\u6570\u636e\u7ed3\u6784\u3002<br \/>\n\u5728head.s\u6267\u884c\u5b8c\u540e\u5185\u5b58\u7684\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/picture.chentaiyang.space\/202307261217689.png\" referrerpolicy=\"no-referrer\" alt=\"img\"><\/p>\n<h2 id=\"15-\u603b\u7ed3\">1.5 \u603b\u7ed3<\/h2>\n<ul>\n<li>bootsect.s\uff1a\u81ea\u4e3e\u5c06\u81ea\u5df1\u79fb\u52300X90000\u5f00\u59cb\u7684\u5730\u65b9\uff1b\u6253\u5370\u5f00\u673a\u4fe1\u606f\uff1b\u642csetup.s\uff1b\u642csystem\u6a21\u5757<\/li>\n<li>setup.s\uff1a\u5229\u7528BIOS\u7684\u4e2d\u65ad\u83b7\u53d6\u8ba1\u7b97\u673a\u53c2\u6570\uff08\u5185\u5b58\u5927\u5c0f\uff0c\u78c1\u76d8\u53c2\u6570\u3001\u663e\u793a\u5668\u53c2\u6570\u7b49\uff09\uff1b\u5207\u6362\u5230\u4fdd\u62a4\u6a21\u5f0f<\/li>\n<li>head.s\uff1a\u521d\u59cb\u5316GDT\u8868\u3001IDT\u8868\u3001\u9875\u8868\u3001\u8df3\u5230mian()<\/li>\n<li>mian()\uff1a\u4e00\u4e9binit()<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7ae0\u4ecb\u7ecd\u8ba1\u7b97\u673a\u4e0a\u7535\u540e\u53d1\u751f\u4e86\u4ec0\u4e48<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[116,118,119,115,117],"class_list":["post-383","post","type-post","status-publish","format-standard","hentry","category-10","tag-bootsect-s","tag-gdt","tag-idt","tag-os","tag-setup-s"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>L1-\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8 - #\u762b\u7537\u65e5\u8bb0<\/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:\/\/blog.taiyang.space\/?p=383\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"L1-\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8 - #\u762b\u7537\u65e5\u8bb0\" \/>\n<meta property=\"og:description\" content=\"\u672c\u7ae0\u4ecb\u7ecd\u8ba1\u7b97\u673a\u4e0a\u7535\u540e\u53d1\u751f\u4e86\u4ec0\u4e48\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.taiyang.space\/?p=383\" \/>\n<meta property=\"og:site_name\" content=\"#\u762b\u7537\u65e5\u8bb0\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-23T08:04:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-26T05:39:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/picture.chentaiyang.space\/202307261217658.png\" \/>\n<meta name=\"author\" content=\"taiyang\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"taiyang\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/blog.taiyang.space\/?p=383#article\",\"isPartOf\":{\"@id\":\"https:\/\/blog.taiyang.space\/?p=383\"},\"author\":{\"name\":\"taiyang\",\"@id\":\"https:\/\/blog.taiyang.space\/#\/schema\/person\/5e3b9567310d4c4a328573992325178c\"},\"headline\":\"L1-\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8\",\"datePublished\":\"2023-07-23T08:04:55+00:00\",\"dateModified\":\"2023-07-26T05:39:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blog.taiyang.space\/?p=383\"},\"wordCount\":202,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/blog.taiyang.space\/#\/schema\/person\/5e3b9567310d4c4a328573992325178c\"},\"keywords\":[\"bootsect.s\",\"GDT\",\"IDT\",\"OS\",\"setup.s\"],\"articleSection\":[\"\u64cd\u4f5c\u7cfb\u7edf\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/blog.taiyang.space\/?p=383#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.taiyang.space\/?p=383\",\"url\":\"https:\/\/blog.taiyang.space\/?p=383\",\"name\":\"L1-\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8 - #\u762b\u7537\u65e5\u8bb0\",\"isPartOf\":{\"@id\":\"https:\/\/blog.taiyang.space\/#website\"},\"datePublished\":\"2023-07-23T08:04:55+00:00\",\"dateModified\":\"2023-07-26T05:39:39+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/blog.taiyang.space\/?p=383#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.taiyang.space\/?p=383\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.taiyang.space\/?p=383#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/blog.taiyang.space\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"L1-\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.taiyang.space\/#website\",\"url\":\"https:\/\/blog.taiyang.space\/\",\"name\":\"#\u762b\u7537\u65e5\u8bb0\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/blog.taiyang.space\/#\/schema\/person\/5e3b9567310d4c4a328573992325178c\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.taiyang.space\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/blog.taiyang.space\/#\/schema\/person\/5e3b9567310d4c4a328573992325178c\",\"name\":\"taiyang\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/blog.taiyang.space\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/blog.taiyang.space\/wp-content\/uploads\/2022\/10\/touxiang.jpg\",\"contentUrl\":\"https:\/\/blog.taiyang.space\/wp-content\/uploads\/2022\/10\/touxiang.jpg\",\"width\":612,\"height\":640,\"caption\":\"taiyang\"},\"logo\":{\"@id\":\"https:\/\/blog.taiyang.space\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/blog.taiyang.space\"],\"url\":\"https:\/\/blog.taiyang.space\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"L1-\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8 - #\u762b\u7537\u65e5\u8bb0","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:\/\/blog.taiyang.space\/?p=383","og_locale":"zh_CN","og_type":"article","og_title":"L1-\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8 - #\u762b\u7537\u65e5\u8bb0","og_description":"\u672c\u7ae0\u4ecb\u7ecd\u8ba1\u7b97\u673a\u4e0a\u7535\u540e\u53d1\u751f\u4e86\u4ec0\u4e48","og_url":"https:\/\/blog.taiyang.space\/?p=383","og_site_name":"#\u762b\u7537\u65e5\u8bb0","article_published_time":"2023-07-23T08:04:55+00:00","article_modified_time":"2023-07-26T05:39:39+00:00","og_image":[{"url":"https:\/\/picture.chentaiyang.space\/202307261217658.png"}],"author":"taiyang","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"taiyang","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.taiyang.space\/?p=383#article","isPartOf":{"@id":"https:\/\/blog.taiyang.space\/?p=383"},"author":{"name":"taiyang","@id":"https:\/\/blog.taiyang.space\/#\/schema\/person\/5e3b9567310d4c4a328573992325178c"},"headline":"L1-\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8","datePublished":"2023-07-23T08:04:55+00:00","dateModified":"2023-07-26T05:39:39+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.taiyang.space\/?p=383"},"wordCount":202,"commentCount":1,"publisher":{"@id":"https:\/\/blog.taiyang.space\/#\/schema\/person\/5e3b9567310d4c4a328573992325178c"},"keywords":["bootsect.s","GDT","IDT","OS","setup.s"],"articleSection":["\u64cd\u4f5c\u7cfb\u7edf"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.taiyang.space\/?p=383#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.taiyang.space\/?p=383","url":"https:\/\/blog.taiyang.space\/?p=383","name":"L1-\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8 - #\u762b\u7537\u65e5\u8bb0","isPartOf":{"@id":"https:\/\/blog.taiyang.space\/#website"},"datePublished":"2023-07-23T08:04:55+00:00","dateModified":"2023-07-26T05:39:39+00:00","breadcrumb":{"@id":"https:\/\/blog.taiyang.space\/?p=383#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.taiyang.space\/?p=383"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.taiyang.space\/?p=383#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/blog.taiyang.space\/"},{"@type":"ListItem","position":2,"name":"L1-\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8"}]},{"@type":"WebSite","@id":"https:\/\/blog.taiyang.space\/#website","url":"https:\/\/blog.taiyang.space\/","name":"#\u762b\u7537\u65e5\u8bb0","description":"","publisher":{"@id":"https:\/\/blog.taiyang.space\/#\/schema\/person\/5e3b9567310d4c4a328573992325178c"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.taiyang.space\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/blog.taiyang.space\/#\/schema\/person\/5e3b9567310d4c4a328573992325178c","name":"taiyang","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/blog.taiyang.space\/#\/schema\/person\/image\/","url":"https:\/\/blog.taiyang.space\/wp-content\/uploads\/2022\/10\/touxiang.jpg","contentUrl":"https:\/\/blog.taiyang.space\/wp-content\/uploads\/2022\/10\/touxiang.jpg","width":612,"height":640,"caption":"taiyang"},"logo":{"@id":"https:\/\/blog.taiyang.space\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/blog.taiyang.space"],"url":"https:\/\/blog.taiyang.space\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/blog.taiyang.space\/index.php?rest_route=\/wp\/v2\/posts\/383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.taiyang.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.taiyang.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.taiyang.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.taiyang.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=383"}],"version-history":[{"count":3,"href":"https:\/\/blog.taiyang.space\/index.php?rest_route=\/wp\/v2\/posts\/383\/revisions"}],"predecessor-version":[{"id":387,"href":"https:\/\/blog.taiyang.space\/index.php?rest_route=\/wp\/v2\/posts\/383\/revisions\/387"}],"wp:attachment":[{"href":"https:\/\/blog.taiyang.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.taiyang.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.taiyang.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}