{"id":167,"date":"2017-08-11T14:14:35","date_gmt":"2017-08-11T06:14:35","guid":{"rendered":"http:\/\/www.sinkland.cn\/?p=167"},"modified":"2019-08-17T15:04:49","modified_gmt":"2019-08-17T07:04:49","slug":"smlos%e5%85%ad-%e4%b8%ad%e6%96%ad%e6%8e%a7%e5%88%b6%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"http:\/\/www.sinkland.cn\/?p=167","title":{"rendered":"SmlOS\u516d-\u4e2d\u65ad\u63a7\u5236\u5b9e\u73b0"},"content":{"rendered":"<h4>\u8bbe\u7f6e\u5904\u7406\u51fd\u6570<\/h4>\n<p>\u4e2d\u65ad\u7684\u6765\u81ea\u4e8ePIC\uff0c\u9996\u5148\u9700\u8981\u5bf9PIC\u8fdb\u884c\u521d\u59cb\u5316\u3002PIC\u662f\u4e00\u4e2a\u96c6\u6210\u4e868\u4e2a\u4e2d\u65ad\u4fe1\u53f7\u5230\u4e00\u4e2a\u4e2d\u65ad\u4fe1\u53f7\u88c5\u7f6e\u3002<\/p>\n<p>\u81f3\u4e8ePIC\u7684\u4ecb\u7ecd\uff0c\u5df2\u7ecf\u5728<strong>\u7cfb\u7edf\u542f\u52a8\u524d\u671f\u5904\u7406<\/strong>\u7ae0\u8282\u505a\u4e86\u4ecb\u7ecd\u3002<\/p>\n<p>IDT\u51fd\u6570\u8868\u8bbe\u7f6e\uff0c\u4e5f\u5df2\u7ecf\u5728<strong>GDT\u548cIDT\u521d\u59cb\u5316<\/strong>\u4e2d\u505a\u4e86\u4ecb\u7ecd\u3002<\/p>\n<p>\u5176\u4e2d\u6709\u4e9b\u5e8f\u53f7\u662f\u56fa\u5b9a\u7684:<\/p>\n<table>\n<thead>\n<tr>\n<th>\u4e2d\u65ad\u5e8f\u53f7<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>IRQ0<\/td>\n<td>\u65f6\u949f<\/td>\n<\/tr>\n<tr>\n<td>IRQ1<\/td>\n<td>\u952e\u76d8<\/td>\n<\/tr>\n<tr>\n<td>IRQ2<\/td>\n<td>\u63a5\u8fdeint<\/td>\n<\/tr>\n<tr>\n<td>IRQ3<\/td>\n<td>\u4e32\u884c\u53e32<\/td>\n<\/tr>\n<tr>\n<td>IRQ4<\/td>\n<td>\u4e32\u884c\u53e31<\/td>\n<\/tr>\n<tr>\n<td>IRQ5<\/td>\n<td>\u5e76\u884c\u53e32<\/td>\n<\/tr>\n<tr>\n<td>IRQ6<\/td>\n<td>\u8f6f\u76d8<\/td>\n<\/tr>\n<tr>\n<td>IRQ7<\/td>\n<td>\u5e76\u884c\u53e31<\/td>\n<\/tr>\n<tr>\n<td>IRQ8<\/td>\n<td>\u5b9e\u65f6\u949f<\/td>\n<\/tr>\n<tr>\n<td>IRQ9<\/td>\n<td>INTOAH<\/td>\n<\/tr>\n<tr>\n<td>IRQ10<\/td>\n<td>\u4fdd\u7559<\/td>\n<\/tr>\n<tr>\n<td>IRQ11<\/td>\n<td>\u4fdd\u7559<\/td>\n<\/tr>\n<tr>\n<td>IRQ12<\/td>\n<td>PS2\u9f20\u6807<\/td>\n<\/tr>\n<tr>\n<td>IRQ13<\/td>\n<td>\u534f\u5904\u7406\u5668<\/td>\n<\/tr>\n<tr>\n<td>IRQ14<\/td>\n<td>\u786c\u76d8<\/td>\n<\/tr>\n<tr>\n<td>IRQ15<\/td>\n<td>\u4fdd\u7559<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e2d\u65ad\u529f\u80fd\u7684\u5b9e\u73b0\uff0c\u9700\u8981\u6ee1\u8db3\u4ee5\u4e0b\u51e0\u4e2a\u6761\u4ef6\u3002<\/p>\n<ul>\n<li>1.\u5f00\u542f\u76f8\u5e94\u7684IRQ\u3002<\/li>\n<li>2.\u6ce8\u518c\u76f8\u5e94\u7684IDT\u3002<\/li>\n<li>3.\u5b9e\u73b0\u76f8\u5e94\u7684\u4e2d\u65ad\u51fd\u6570\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>\u521d\u59cb\u5316PIC\uff0c\u5f00\u542fIRQ<\/h4>\n<pre><code class=\"language-c \">\/\/ \u521d\u59cb\u5316PIC \nvoid Init_PIC(void)\n{\n    io_out8(PIC0_IMR,  0xff  ); \/\/\u7981\u6b62\u4e3bPIC\u6240\u6709\u4e2d\u65ad \n    io_out8(PIC1_IMR,  0xff  ); \/\/\u7981\u6b62\u4ecePIC\u6240\u6709\u4e2d\u65ad \n\n    io_out8(PIC0_ICW1, 0x11  ); \/\/\u9700\u8981ICW4\uff0c \u591a\u7247\u7ea7\u8054\uff0c \u8fb9\u6cbf\u89e6\u53d1\u65b9\u5f0f \n    io_out8(PIC0_ICW2, 0x20  ); \/\/IRQ0-7\u7531\u4e8eINT 0x20~0x27\u63a5\u6536 \n    io_out8(PIC0_ICW3, 1 &lt;&lt; 2); \/\/ PIC1\u7531IRQ2\u8fde\u63a5 \n    io_out8(PIC0_ICW4, 0x01  ); \/\/\u666e\u901a\u5168\u5d4c\u5957 \u975e\u7f13\u51b2 \u975e\u81ea\u52a8\u7ed3\u675f\u4e2d\u65ad\u65b9\u5f0f \n\n    io_out8(PIC1_ICW1, 0x11  ); \/\/\u9700\u8981ICW4\uff0c \u591a\u7247\u7ea7\u8054\uff0c \u8fb9\u6cbf\u89e6\u53d1\u65b9\u5f0f \n    io_out8(PIC1_ICW2, 0x28  ); \/\/IRQ8-15\u7531\u4e8eINT 0x28~0x2f\u63a5\u6536 \n    io_out8(PIC1_ICW3, 2     ); \/\/PIC1\u7531IRQ2\u8fde\u63a5 \n    io_out8(PIC1_ICW4, 0x01  ); \/\/\u666e\u901a\u5168\u5d4c\u5957 \u975e\u7f13\u51b2 \u975e\u81ea\u52a8\u7ed3\u675f\u4e2d\u65ad\u65b9\u5f0f \n\n    io_out8(PIC0_IMR,  0xfb  ); \/\/11111011 PIC1\u4ee5\u5916\u5168\u90e8\u7981\u6b62 \n    io_out8(PIC1_IMR,  0xff  ); \/\/11111111 \u7981\u6b62\u4ecePIC\u6240\u6709\u4e2d\u65ad \n\n    return;\n}\n\n<\/code><\/pre>\n<p>\u5728\u5bf9\u4e2d\u65ad\u8bbe\u5b9a\u8fdb\u884c\u66f4\u6539\u65f6\uff0c\u5982\u679c\u518d\u63a5\u6536\u5176\u4ed6\u7684\u4e2d\u65ad\u4f1a\u5f15\u8d77\u6df7\u4e71\uff0c\u6240\u4ee5\u8981\u5c4f\u853d\u4e2d\u65ad\u3002<\/p>\n<p>\u8fd9\u91cc\u5bf9PIC \u7684\u8bbe\u5b9a\u4f7f\u7528OUT\u6307\u4ee4\u5b9e\u73b0\uff0c\u5bf9\u4e8e\u6211\u4eec\u8981\u5f00\u7684\u4e2d\u65ad\u800c\u8a00\uff0c\u8fd9\u91cc\u53ea\u5f00\u542f\u4e86PIC1\u5c31\u591f\u7528\u4e86.<\/p>\n<hr \/>\n<h3>\u8bbe\u7f6eIDT<\/h3>\n<p>\u521d\u59cb\u5316PIC\u540e\uff0c\u5c31\u80fd\u4ea7\u751f\u4e2d\u65ad\u4e86<\/p>\n<p>\u4f46\u662f\u4e2d\u65ad\u4f1a\u8c03\u7528\u54ea\u4e2a\u51fd\u6570\uff0c\u5219\u9700\u8981\u8bbe\u7f6eIDT\u4e86<\/p>\n<p>\u8bf7\u53c2\u8003<strong>GDT\u548cIDT\u521d\u59cb\u5316<\/strong>\u4e2dIDT\u8bbe\u7f6e\u76f8\u5173\u5185\u5bb9<\/p>\n<p>\u5177\u4f53\u4ee3\u7801:<\/p>\n<pre><code class=\"language-c \">\/\/\u65f6\u949f\u4e2d\u65ad\nset_gatedesc(idt + 0x20, (int) asm_inthandler20, 2 * 8, AR_INTGATE32);\n\/\/\u952e\u76d8\u4e2d\u65ad\nset_gatedesc(idt + 0x21, (int) asm_inthandler21, 2 * 8, AR_INTGATE32);\n\/\/\u9f20\u6807\u4e2d\u65ad\nset_gatedesc(idt + 0x2c, (int) asm_inthandler2c, 2 * 8, AR_INTGATE32);\n\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u4e3b\u8981\u5904\u7406\u4e86\uff1a\u65f6\u949f\u4e2d\u65ad\uff08IRQ0\uff09\uff0c\u952e\u76d8\u4e2d\u65ad\uff08IRQ1\uff09\uff0c\u9f20\u6807\u4e2d\u65ad(IRQ12)<\/p>\n<hr \/>\n<h4>\u5b9e\u73b0\u4e2d\u65ad\u5904\u7406\u51fd\u6570<\/h4>\n<p>\u4e2d\u65ad\u51fd\u6570\u9700\u8981\u4fdd\u5b58\u73b0\u573a\uff0c\u5373\u4fdd\u5b58\u76f8\u5e94\u5bc4\u5b58\u5668\u5185\u5bb9\uff0c\u9700\u8981\u628a\u76f8\u5e94\u5bc4\u5b58\u5668\u503c\u5165\u6808\u5728\u7a0b\u5e8f\u7ed3\u675f\u540e\u5728\u8fdb\u884c\u51fa\u6808\u64cd\u4f5c\u3002<\/p>\n<p>\u5728\u8c03\u7528\u5b8cc\u5b9e\u73b0\u7684\u5904\u7406\u540e\uff0c\u518d\u6062\u590d\u5bc4\u5b58\u5668\u7684\u503c\u3002<\/p>\n<p>\u4ee5\u65f6\u949f\u4e2d\u65ad\u4e3a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-erlang \">_asm_inthandler20:  ; IRQ0  \u65f6\u949f\n    PUSH    ES\n    PUSH    DS\n    PUSHAD                  ; \u4fdd\u5b58\u5bc4\u5b58\u5668\n    MOV     EAX,ESP\n    PUSH    EAX\n    MOV     AX,SS           ; \u4fee\u6539DS ES SS\n    MOV     DS,AX\n    MOV     ES,AX\n    CALL    _inthandler20   ; \u8c03\u7528\u5904\u7406\u51fd\u6570\n    POP     EAX             ; \u6062\u590d\u5404\u4e2a\u5bc4\u5b58\u5668\u7684\u503c\n    POPAD\n    POP     DS\n    POP     ES\n    IRETD\n<\/code><\/pre>\n<p>\u81f3\u4e8e_inthandler20\u5904\u7406\u51fd\u6570\u505a\u4e86\u4ec0\u4e48\u5177\u4f53\u64cd\u4f5c\uff0c\u5c06\u5728\u540e\u9762\u7ae0\u8282\u8fdb\u884c\u4ecb\u7ecd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bbe\u7f6e\u5904\u7406\u51fd\u6570 \u4e2d\u65ad\u7684\u6765\u81ea\u4e8ePIC\uff0c\u9996\u5148\u9700\u8981\u5bf9PIC\u8fdb\u884c\u521d\u59cb\u5316\u3002PIC\u662f\u4e00\u4e2a\u96c6\u6210\u4e868\u4e2a\u4e2d\u65ad\u4fe1\u53f7\u5230\u4e00\u4e2a\u4e2d\u65ad\u4fe1\u53f7\u88c5\u7f6e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=\/wp\/v2\/posts\/167"}],"collection":[{"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167"}],"version-history":[{"count":5,"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions"}],"predecessor-version":[{"id":196,"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions\/196"}],"wp:attachment":[{"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}