Linux Assembly HOWTO : ¸®´ª½º ¾î¼Àºí¸® ÇÏ¿ìÅõBoldyshevKonstantinRideauFrancois-Rene±è¿µÈÖ$Date: 2004/11/05 13:56:28 $ Copyright © 1999-2000 by Konstantin Boldyshev Copyright © 1996-1999 by Francois-Rene Rideau ÀÌ ¹®¼´Â ¸®´ª½º ¾î¼Àºí¸® ÇÏ¿ìÅõÀÌ´Ù. ÀÌ ¹®¼´Â GNU ÀÇ ÀÚÀ¯ ÇÁ·Î±×·¡¹Ö µµ±¸µéÀ» »ç¿ëÇÏ¿© (ÁÖ·Î) ÀÎÅÚÀÇ 32 ºñÆ® Ç÷§Æû(IA32 ; i386)ÀÇ ¸®´ª½º¿¡¼ ¾î¼Àºí¸® ¾ð¾î·Î ÇÁ·Î±×·¡¹Ö ÇÏ´Â ¹ýÀ» ¼³¸íÇÑ´Ù. ÀÌ ±Û¿¡¼ ¼³¸íÇÏ´Â ³»¿ëµéÀº ´Ù¸¥ Çϵå¿þ¾î³ª ¼ÒÇÁÆ®¿þ¾î Ç÷§Æû¿¡ Àû¿ëµÉ ¼öµµ ÀÖ°í, ±×·¸Áö ¾ÊÀ» ¼öµµ ÀÖ´Ù. (¿ªÁÖ: ÀÌ ¹ø¿ª¹®¼´Â ºÎÁ·ÇÑ ÀúÀÇ ¹®Àå½Ç·ÂÀ¸·Î Çʿ伺¿¡ ÀÇÇÏ¿© ¹ø¿ªÇÑ °á°ú·Î À߸øµÈ ¿À¿ª°ú Àǹ̿¡ ÀÌ»ó¾ø´Â ºÎºÐÀÌ ºüÁú ¼öµµ ÀÖÀ½À» ¹Ì¸® ¾Ë¸³´Ï´Ù. µû¶ó¼ À߸øµÈ ¹ø¿ªÀ¸·Î ¿À´Â Ã¥ÀÓÀº Àú¿¡°Ô ¾øÀ¸¸ç, ¸¸ÀÏ ¼öÁ¤ÇØ¾ß ÇÒ °÷ÀÌ ÀÖ´Ù¸é Àú¿¡°Ô ¿¬¶ôÀ» ÇØÁֽñ⠹ٶó¸ç, ¿øÀúÀÇ ¿À·ù¶ó¸é ¿øÀúÀÚ¿¡°Ô ¿¬¶ôÇØÁֽñ⠹ٶø´Ï´Ù. ºÎÁ·ÇÑ Á¦ ¿µ¾î½Ç·ÂÀ¸·Î ÀÎÇØ ¹ø¿ªÀÌ ¾Ö¸ÅÇÑ ºÎºÐÀº ¿ø¹®À» °°ÀÌ Ç¥±âÇØ µÎ¾ú½À´Ï´Ù.) ÀÌ ¹®¼ÀÇ º¹»ç, ¹èÆ÷ ȤÀº ¼öÁ¤Àº GNU Free Documentation License Version 1.1 ¿¡ µû¸¥´Ù. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1; with no Invariant Sections, with no Front-Cover Texts, and no Back-Cover texts.
1장. ¼Ò°³
1.1. Legal Blurb (¹ýÀû¹®Á¦¿¡ °üÇÑ ÀܼҸ®)ÀÌ ¹®¼ÀÇ º¹»ç, ¹èÆ÷ ȤÀº ¼öÁ¤Àº GNU Free Documentation License Version 1.1 ¿¡ µû¸¥´Ù. with no Invariant Sections, with no Front-Cover Texts, and no Back-Cover texts. A copy of the license is included in the GNU Free Documentation License appendix. ÀÌ ¹®¼ÀÇ °¡Àå ÃÖ±ÙÀÇ °ø½ÄÆÇÀº Linux Assembly ³ª LDP ¿¡¼ ±¸ÇÒ ¼ö ÀÖ´Ù. ¹®¼ÀÇ »õ·Î¿î ¹öÁ¯À» È®ÀÎÇÏ´Â °ÍÀ» ÀØÁö ¹Ð¶ó.
1.2. ¼¹®ÀÌ ¹®¼´Â free ¼ÒÇÁÆ®¿þ¾î¸¦ »ç¿ëÇÑ 32ºñÆ® x86 ¾î¼Àºí¸® ÇÁ·Î±×·¡¹ÖÀ̳ª ÇÁ·Î±×·¥µé¿¡ ´ëÇØ Áú¹®ÇÏ´Â »ç¶÷µé¿¡°Ô ´äº¯Çϱâ À§ÇØ Á¦À۵ǾúÀ¸¸ç, ƯÈ÷ ¸®´ª½º ¿î¿µÃ¼Á¦¸¦ Ÿ°ÙÀ¸·Î »ï°í ¼³¸íÀ» ÁøÇàÇÏ°í ÀÖ´Ù. ¹®¼ÀÇ ¿©·¯ ºÎºÐ¿¡¼ ƯÁ¤ ¼ÒÇÁÆ®¿þ¾î³ª ¹®¼¸¦ ±¸Çϱâ À§ÇÑ url µéÀ» ÀáÁ¶ÇÏ°í, ¾ð±ÞÇÏ°í ÀÖ´Ù. ÀÌ ¹®¼´Â ¶ÇÇÑ ÁÖµÈ ¸ñÀûÀÌ ¾Æ´Ñ ÀÚÀ¯ ¼ÒÇÁÆ®¿þ¾î°¡ ¾Æ´Ï°Å³ª, x86 ±â¹ÝÀÌ ¾Æ´Ï°Å³ª, 32ºñÆ® ¾î¼Àºí·¯°¡ ¾Æ´Ï±âµµ ÇÑ °Íµé¿¡ ´ëÇÑ ¾ð±ÞÀ» Çϱ⵵ ÇÑ´Ù. ¿©·¯ºÐÀÌ ÁÁ¾ÆÇÏ´Â Ç÷§Æû¿¡¼ÀÇ ÇÁ·Î±×·¡¹Ö¿¡ ´ëÇÑ FAQ ¿Í ¹®¼µéÀÌ ÀÖÀ½À» Ç×»ó ±â¾ïÇ϶ó. ¿©·¯ºÐÀÌ ±×¿¡ ´ëÇÑ ³»¿ëÀ» ¹ß°ßÇÏ·Á¸é ±×(ƯÁ¤ Ç÷§Æû¿¡¼ÀÇ)¿¡ °üÇÑ ¹®¼ µéÀ» ÂüÁ¶Çϵµ·Ï Ç϶ó. (¾î¼Àºí¸® ÇÁ·Î±×·¡¹ÖÀ» ¹Ù·Î ãÁö ¸»°í, ƯÁ¤ Ç÷§Æû¿¡ °üÇÑ ¹®¼¸¦ ãÀ¸¸é µÈ´Ù.) ¾î¼Àºí¸® ÇÁ·Î±×·¡¹ÖÀÇ ÁÖµÈ ¸ñÀûÀº ¿î¿µÃ¼Á¦, ÀÎÅÍÇÁ¸®ÅÍ, ÄÄÆÄÀÏ·¯, °ÔÀÓ µî°ú °°Àº ºÐ¾ß¿¡¼ C ·Î ±¸ÇöÇϱâ Èûµç ºÎºÐÀ» (ÆÛÆ÷¸Õ½º°¡ ÁÖµÈ issue °¡ µÇ´Â ºÎºÐ) °Çµå¸®±â À§ÇÑ °ÍÀ̱⠶§¹®¿¡ ÀÌ ¹®¼¿¡¼´Â ±×·¯ÇÑ Á¾·ùÀÇ ¼ÒÇÁÆ®¿þ¾î °³¹ß°ú °ü·ÃµÈ ºÎºÐ¿¡ ÃÐÁ¡À» ¸ÂÃâ °èȹÀÌ´Ù. ¸¸¾à ¿©·¯ºÐÀÌ free ¼ÒÇÁÆ®¿þ¾î°¡ ¹«¾ùÀÎÁö ¸ð¸¥´Ù¸é, GNU General Public License (GPL ȤÀº copyleft) À» ÁÖÀDZíÀÌ Àо±â ¹Ù¶õ´Ù. ¾ÆÁÖ ¸¹Àº free ¼ÒÇÁÆ®¿þ¾î(¿ªÀÚ ÁÖ : ÀÚÀ¯ ¼ÒÇÁÆ®¿þ¾î ¶ó°í ¹ø¿ªÇÏ°Ú´Ù.)µéÀÌ GNU GPL À» µû¸¥´Ù. ¹èÆ÷µÇ´Â ÀÚÀ¯ ¼ÒÇÁÆ®¿þ¾îÀÇ ¼Ò½º Áß¿¡ COPYING(ȤÀº COPYING.LIB) À̶ó´Â À̸§ÀÇ ÆÄÀÏ¿¡¼ Àо ¼ö ÀÖ´Ù. ¶ÇÇÑ, ÀÚÀ¯ ¼ÒÇÁÆ®¿þ¾î Àç´Ü (Free software foundation : FSF) ¿¡¼ Á¦°øÇÏ´Â ¹®¼µéµµ µµ¿òÀÌ µÉ °ÍÀÌ´Ù. ÀÌ·¯ÇÑ ÀÚÀ¯ ¼ÒÇÁÆ®¿þ¾î°¡ ¾ÆÁÖ Èï¹ÌÀÖ´Â(!) ÀÌÀ¯´Â ±× ¼ÒÇÁÆ®¿þ¾îµéÀÌ ¼Ò½ºÄÚµå¿Í ÇÔ²² Á¦°øµÇ±â ´ë¹®ÀÌ´Ù. °Ô´Ù°¡ ¿©·¯ºÐÀº ¼Ò½ºÄڵ带 ¼öÁ¤Çϰųª, ¹ö±×¸¦ Àâ¾Æ¼ ´Ù½Ã ¹èÆ÷ÇÒ ¼öµµ ÀÖÀ¸¸ç, ½ÉÁö¾î ±× Äڵ忡¼ Â÷¿ëÇÑ Äڵ带 °¡Áø ÇÁ·Î±×·¥À» ¸¸µé ¼öµµ ÀÖ´Ù. (Ãâó¸¦ ¹àÈ÷°í, ÀÚ½ÅÀÇ Äڵ带 GNU GPL ÇÏ¿¡ °ø°³ÇÑ´Ù¸é) 1.3. ÀÌ ¹®¼¿¡ ±â¿©ÇÏ´Â ¹ýÀÌ ¹®¼´Â ÁøÈ(!)ÇØ °¡´Â ¹®¼ÀÌ´Ù. ¿©·¯ºÐÀº ÀÚÀ¯·Ó°Ô ÀÌ ¹®¼¿¡¼ ´Ù·ç´Â ÁÖÁ¦¿¡ ´ëÇØ Áú¹®ÇÒ ¼ö ÀÖÀ¸¸ç, ¶ÇÇÑ, ´äµµ ÇØ ÁÙ¼ö ÀÖ´Ù. ¶ÇÇÑ ÁÖ¾îÁø ´äÀÇ ¿À·ù¸¦ Á¤Á¤Çؼ ´Ù½Ã ´äÇØÁÙ ¼öµµ ÀÖ´Ù. »õ·Î¿î ¼ÒÇÁÆ®¿þ¾î¸¦ ¾Ë·ÁÁÙ ¼öµµ ÀÖÀ¸¸ç, ÀÌ ¹®¼ÀÇ ¹ö±×³ª ºñÈ¿À²ÀûÀÎ Á¡À» ÀúÀÚ¿¡°Ô ¾Ë·ÁÁÙ ¼öµµ ÀÖ´Ù. Á¦¹ß!! ±â¿©ÇØ ´Þ¶ó!! ¹®¼ÀÇ ÀúÀÚ¿¡°Ô ¸ÞÀÏÀ» : maintainer.
2장. ¾î¼Àºí¸®°¡ Á¤¸»·Î(!) ÇÊ¿äÇÑ°¡?À½... ¿©·¯ºÐÀÌ ¹«½¼ÀÏÀ» ÇÏ´ÂÁö ³»°¡ ¾Ë ¼ö ÀÖ´Â ¹æ¹ýÀÌ ¾ø±â ¶§¹®¿¡, ¿©·¯ºÐÀÇ ÀÏ¿¡ ¾î¼Àºí¸®°¡ Á¤¸» ÇÊ¿äÇÑÁö ³»°¡ ÆÇ´ÜÇÒ ¼ö´Â ¾ø´Ù. ´ë½Å, °ÅµìµÈ »ðÁú(-_-)ÀÇ °á°ú·Î ¾òÀº ±ÍÁßÇÑ °æÇèÀÇ Á¶¾ðÀ» ¾Æ·¡¿¡ Àû¾î º¸°Ú´Ù. 2.1. Pros and Cons - µæ½Ç(¾î¼Àºí¸®¸¦ »ç¿ëÇÔÀ¸·Î½á »ý±â´Â ÀåÁ¡, ´ÜÁ¡)2.1.1. ¾î¼Àºí¸®ÀÇ ÀåÁ¡¾î¼Àºí¸®´Â ¸Å¿ì Àú±ÞÀÇ(? - very low things, Çϵå¿þ¾î ·¹º§ÀÇ) ÀϵéÀ» ó¸®ÇÒ ¼ö ÀÖ´Ù. :
2.1.2. ¾î¼Àºí¸®ÀÇ ´ÜÁ¡¾î¼Àºí¸®´Â ¸Å¿ì Àú¼öÁØÀÇ ¾ð¾îÀÌ´Ù. (ÀÌÁø ±â°è¾î ÀνºÆ®·°¼ÇÀ» ±×´ë·Î ½Éº¼È ÇÑ°Í¿¡ Áö³ªÁö ¾Ê´Â´Ù.) ÀÌ°ÍÀº ´ÙÀ½°ú °°Àº Àǹ̸¦ °¡Áø´Ù :
2.1.3. °á·Ð¿ä¾àÇÏÀÚ¸é, ¿©·¯ºÐÀº ¾î¼Àºí¸®°¡ ÇÊ¿äÇÑ °æ¿ì¸¦ °¡²û ¹ß°ßÇÒ ¼ö ÀÖÀ» °ÍÀÌ´Ù. ±×¸®°í, ¾î¶² °æ¿ì¿¡´Â ²À ÇÊ¿äÇÏÁö´Â ¾Ê¾Æµµ ¾î¼Àºí¸®·Î ÄÚµùÇÏ´Â °ÍÀÌ À¯¿ëÇÑ °æ¿ì¸¦ ¹ß°ßÇÒ ¼öµµ ÀÖÀ» °ÍÀ̸ç, ¿©·¯ºÐÀÌ ±×·¸°Ô ´À³¤´Ù¸é, ±×·¸°Ô Ç϶ó. ´ÜÁö, ´ÙÀ½ »çÇ×µéÀ» ¸í½ÉÇÏ°í, ±×·¸°Ô ÇÑ´Ù¸é ÁÁÀ» °ÍÀÌ´Ù. :
ºñ·Ï ¿î¿µÃ¼Á¦ °³¹ß°ú °°ÀÌ ¾î¼Àºí¸®°¡ ²À ÇÊ¿äÇÑ °Íó·³ º¸ÀÌ´Â °æ¿ì¶ó ÇÒÁö¶óµµ À§¿¡¼ ¾ð±ÞÇÑ ³»¿ëµéÀ» ÁÖÀDZí°Ô »ý°¢ÇØ º» ÈÄ¿¡ ¾î¼Àºí¸®ÀÇ »ç¿ë ¿©ºÎ¸¦ °áÁ¤ÇÏ¶ó ¸®´ª½ºÀÇ Ä¿³Î ¼Ò½º¸¦ Çѹø º¸µµ·Ï Ç϶ó : ¸®´ª½ºÀÇ Ä¿³ÎÀº ÇÊ¿äÇÑ Á¤¸» ÃÖ¼Ò(!)ÀÇ ¾î¼Àºí¸® Äڵ常 »ç¿ëµÇ¾ú´Ù. ±× °á°ú·Î ºü¸£°í, ½Å·Ú¼ºÀÖ°í, Æ÷ÅͺíÇϸç, À¯Áöº¸¼öÇϱ⠿ëÀÌÇÑ ¿î¿µÃ¼Á¦ÀÇ Äڵ尡 »ý¼ºµÇ°Ô µÇ¾ú´Ù. °Ô´Ù°¡ µÒ°ú °°Àº °ÔÀÓÁ¶Â÷µµ ¼Óµµ Çâ»óÀ» À§ÇÑ ÀϺΠ¸Å¿ì ÀÛÀº ·çƾÀ» Á¦¿ÜÇÏ°í´Â ´ëºÎºÐ c ¸¦ ÀÌ¿ëÇؼ ¸¸µé¾îÁ³´Ù´Â »ç½ÇÀ» Ç×»ó »ó±âÇ϶ó. 2.2. ¾î¼Àºí¸®¸¦ »ç¿ëÇÏÁö ¾Ê´Â ¹æ¹ý2.2.1. È¿À²ÀÌ ³ôÀº Äڵ带 »ý¼ºÇϱâ À§ÇÑ ÀϹÝÀûÀÎ ÀýÂ÷´º½º±×·ì comp.compilers ÀÇ Charles Fiterman ÀÌ »ç¶÷ÀÌ ¼öÀÛ¾÷ÇÑ ¾î¼Àºí¸® ÄÚµå¿Í ÄÄÆÄÀÏ·¯°¡ »ý¼ºÇÑ ¾î¼Àºí¸® Äڵ带 ºñ±³Çؼ ÇÑ ¸»À» ÀοëÇÏ°Ú´Ù.
2.2.2. ÃÖÀûÈµÈ ÁÁÀº Äڵ带 »ý¼ºÇÏ´Â ÄÄÆÄÀÏ·¯¸¦ °¡Áø ¾ð¾îµéObjectiveCAML, SML, CommonLISP, Scheme, ADA, Pascal, C, C++, µî°ú °°Àº ¾ð¾îµéÀº ¸ðµÎ ÁÁÀº free ÄÄÆÄÀÏ·¯¸¦ °¡Áö°í ÀÖÀ¸¸ç, ±×·¯ÇÑ ÄÄÆÄÀÏ·¯¸¦ »ç¿ëÇؼ »ý¼ºÇÑ ÄÚµåµéÀº ¸Å¿ì ÃÖÀûÈµÈ Äڵ带 ¸¸µé¾îÁØ´Ù. °Ô´Ù°¡ Á¾Á¾, ¼öÀÛ¾÷À¸·Î ¸¸µç ¾î¼Àºí¸® Äڵ庸´Ù ´õ ³ªÀº ÃÖÀûȸ¦ º¸¿©Áֱ⵵ ÇÑ´Ù. ±×¿¡ ´õÇÏ¿©, ¿©·¯ºÐÀÌ º¸´Ù ³ôÀº ¼öÁØÀÇ ¼¼ºÎÀûÀÎ °Í¿¡, Áï, ¾Ë°í¸®ÁòÀ̳ª, ÇÁ·Î±×·¥ÀÇ Àüü ¼³°è¿Í °°Àº ºÎºÐ¿¡ º¸´Ù ½Å°æÀ» ¾²µµ·Ï µµ¿ÍÁØ´Ù. ±×¸®°í, ±×ó·³ ¼³°è¿Í °°Àº ºÎºÐ¿¡ º¸´Ù ½Å°æÀ» ¾¸À¸·Î½á, ÀÚÀßÇÑ, ¸î¸î ºÎºÐ¿¡¼ÀÇ ¾à°£ÀÇ ¼öÇà¼ÓµµÀÇ ¼Õ½ÇÀº º¸´Ù ³ªÀº µðÀÚÀο¡ ÀÇÇÑ È¿°ú°¡ ÃæºÐÈ÷ »ó¼â½ÃÄÑ ÁÖ°íµµ ³²´Â´Ù. ¹°·Ð, »ó¿ëÀÇ ¾Õ¼ ¾ð±ÞÇÑ ¾ð¾î¸¦ Áö¿øÇÏ´Â ÈǸ¢ÇÑ ÄÄÆÄÀÏ·¯µéµµ ÀÖ´Ù. LISP, Scheme, Perl µîÀÇ ¾ð¾îÀÇ ÄÄÆÄÀÏ·¯´Â c Äڵ带 »ý¼ºÇϱ⵵ ÇÑ´Ù. ±×·¸°Ô Çؼ »ý¼ºµÈ c ÄÚµå´Â c ÄÄÆÄÀÏ·¯¿¡ ÀÇÇؼ ÃÖÀûȵǸç, ¼Óµµµµ ²Ï ºü¸¥ ÆíÀÌ´Ù. 2.2.3. ¿©·¯ºÐÀÇ ÄÚµåÀÇ ¼öÇà¼Óµµ¸¦ ³ôÀÌ´Â ÀϹÝÀûÀÎ ÀýÂ÷ÄÚµåÀÇ ¼öÇà¼Óµµ¸¦ ³ôÀ̱â À§ÇØ ¿©·¯ºÐÀº ÇÁ·ÎÆÄÀÏ ÅøÀÌ °è¼ÓÀûÀ¸·Î ¼öÇ༺´ÉÀÇ º´¸ñ Çö»óÀÌ ÀϾٰí ÁöÀûÇÏ´Â ºÎºÐÀÇ Äڵ忡 ´ëÇؼ¸¸ ÃÖÀûÈÀÇ ÀÛ¾÷À» ÇØ ÁÖ¸é µÈ´Ù. ¿©·¯ºÐÀÌ ÄÚµåÀÇ ÀϺκÐÀÌ ³Ê¹« ´À¸®´Ù´Â °ÍÀ» ¾Ë¾Æä¸é, ´ÙÀ½°ú °°Àº Á¶Ä¡¸¦ ÃëÇØ º¸¶ó
¸¶Áö¸·À¸·Î, ¿©·¯ºÐÀÌ ¾î¼Àºí¸® ÄÚµåÀÇ ÀÛ¼ºÀ» ¸¶¹«¸®Çϱâ Àü¿¡ »ý¼ºµÈ ÄÚµåµéÀ» °Ë»çÇؼ ÃÖÀûȵÇÁö ¾ÊÀº »óÅ·ΠÄÄÆÄÀÏ·¯°¡ »ý¼ºÇÑ Äڵ尡 Á¤¸» ¹®Á¦°¡ µÇ´ÂÁö¸¦ È®ÀÎÇØ º¸¶ó. ´ëºÎºÐ, ±×·¸Áö ¾ÊÀ» °ÍÀÌ´Ù. ¿ÀÈ÷·Á ÄÄÆÄÀÏ·¯°¡ »ý¼ºÇØ ÁØ Äڵ尡 ¿©·¯ºÐÀÌ Á÷Á¢ ÀÛ¼ºÇÑ Äڵ庸´Ù ´õ ³ªÀ» ¼öµµ ÀÖ´Ù. ƯÈ÷, ¿À´Ã³¯ÀÇ º¹ÀâÇÑ, multi-pipelined ¾ÆÅ°ÅØÃÄ ±â¹ÝÀÇ Çϵå¿þ¾î¸¦ »ç¿ëÇϴ ȯ°æ¿¡¼ÀÇ ÇÁ·Î±×·¥ÀÏ °æ¿ì¿¡´Â ´õ¿í ±×·¯ÇÏ´Ù. ÇÁ·Î±×·¥¿¡¼ ½Ã°£À» ¸¹ÀÌ Àâ¾Æ¸Ô´Â ºÎºÐÀº Á¤¸» ±×·¯Çѵ¥(?-¹ø¿ªÀÌ ÀÌ»óÇÕ´Ï´Ù...-_-;) ¿Ö³ÄÇϸé, ¿À´Ã³¯ÀÇ ÃÊ°í¼Ó :-)ÀÇ ÇÁ·Î¼¼¼µé¿¡¼´Â ½ÇÇà ½Ã°£À» ´ÊÃß´Â ÁÖ ¿øÀÎÀ¸·Î, ¸Þ¸ð¸® Á¢±Ù(¸Þ¸ð¸®¿¡ Á¢±ÙÇϴµ¥ °É¸®´Â ½Ã°£Àº ·¹Áö½ºÅÍ¿¡ Á¢±ÙÇÏ´Â µ¥ °É¸®´Â ½Ã°£ÀÇ ¸î¹è¿¡¼ ¸î½Ê¹è´Â ´õ ±æ´Ù), ij½¬ÀÇ ºÎÀç, TLB (¿ªÀÚÁÖ : Transtate lookaside buffer:ÀÎÅÚ °è¿ÀÇ ÇÁ·Î¼¼¼¿¡¼ ¸Þ¸ð¸® ÁÖ¼ÒÀÇ »óÈ£º¯È¯À» º¸´Ù »¡¸® Çϱâ À§ÇØ descriptor ¸¦ ÀúÀåÇϴ ij½¬¿Í ºñ½ÁÇÑ °Í) ÀÇ ºÎÀç, ÆäÀÌÁö ÆúÆ® µîÀÇ ¿øÀÎÀÌ ÀÖ´Ù. µû¶ó¼, ·¹Áö½ºÅ͸¦ ÃÖÀûÈ Çϴ°ÍÀº Á¡Â÷ º° ¾µ¸ð°¡ ¾ø¾îÁö°Ô µÇ¾ú´Ù. ´ë½Å, ÀÚ·á ±¸Á¶¿Í ¾²·¹µùÀÇ Á¶ÀýÀ» ÅëÇؼ ¸Þ¸ð¸®¿¡ Á¢±ÙÇϴ Ƚ¼ö¸¦ ÁÙÀÌ´Â °ÍÀÌ º¸´Ù ³ªÀº ¼Óµµ¸¦ ¾ò´Âµ¥ ´õ È¿°úÀûÀÌ µÇ¾ú´Ù. ¾Æ¸¶µµ, ¿ÏÀüÈ÷ ´Ù¸¥ ¹æÇâ¿¡¼ÀÇ Á¢±ÙÀÌ µµ¿òÀÌ µÉÁöµµ ¸ð¸¥´Ù. 2.2.4. ÄÄÆÄÀÏ·¯°¡ »ý¼ºÇÑ Äڵ忡 ´ëÇÑ °íÂûÄÄÆÄÀÏ·¯°¡ »ý¼ºÇØ ³½ ¾î¼Àºí¸® Äڵ带 °íÂûÇØ º¸¾Æ¾ß ÇÒ ¸¹Àº ÀÌÀ¯°¡ ÀÖ´Ù. ¿©·¯ºÐÀÌ ÇØ¾ß ÇÒ ÀÏÀº
°á·ÐÀûÀ¸·Î, ¾î¼Àºí¸®·Î ÄÚµùÇϴ ǥÁØ(?)ÀûÀÎ ¹æ¹ýÀº
¿©·¯ºÐÀÇ ÄÄÆÄÀÏ·¯¿¡(gcc ÀÏ °ÍÀ̶ó°í °¡Á¤ÇÏ°í..) 2.3. ¸®´ª½º¿Í ¾î¼Àºí¸®¿©·¯ºÐµµ ´«Ä¡ÃªÀ» Å×Áö¸¸, ÀϹÝÀûÀ¸·Î, ¸®´ª½º¿¡¼ ÇÁ·Î±×·¡¹ÖÀ» ÇÏ¸é¼ ¾î¼Àºí¸®¸¦ »ç¿ëÇÒ ÇÊ¿ä´Â ¾ø´Ù. ¸®´ª½º´Â µµ½º¿Í´Â ´Þ¶ó¼, µå¶óÀ̹ö¿Í °°Àº °ÍµéÀ» ¾î¼Àºí¸®·Î ÀÛ¼ºÇÒ ÇÊ¿ä´Â ¾ø´Ù (À½.. ¸¸¾à ¿©·¯ºÐÀÌ ¾î¼Àºí¸®·Î ¸¸µé°Ú´Ù¸é ÇÒ ¼ö ¾øÁö¸¸ ¸»ÀÌ´Ù) ±×¸®°í, ¿À´Ã³¯ÀÇ ÁÁÀº ÄÄÆÄÀÏ·¯µéÀ» ÀÌ¿ëÇÑ´Ù¸é, ¼·Î ´Ù¸¥ ÇÁ·Î¼¼¼µéÀ» Ÿ°ÙÀ¸·Î °¢°¢ ¼öÇà¼ÓµµÀÇ ÃÖÀûȸ¦ Çϱ⸦ ¿øÇÏ´õ¶óµµ, c ¾ð¾î¸¦ »ç¿ëÇؼ ÇÁ·Î±×·¡¹ÖÇÏ´Â °ÍÀÌ ¾î¼Àºí¸®·Î ÇÏ´Â °Íº¸´Ù ´õ ½±´Ù. ±×·¯³ª... ±×·³¿¡µµ ºÒ±¸ÇÏ°í, c ³ª c++ º¸´Ù ¾î¼Àºí¸®°¡ ´õ ÀûÀýÇÑ °æ¿ì°¡ ÀÖÀ» °ÍÀÌ´Ù. ¿©·¯ºÐÀÌ ¾î¼Àºí¸® ÇÁ·Î±×·¡¹ÖÀ» ÇÊ¿ä·Î Çϰųª, ȤÀº ¾î¼Àºí¸® ¾ð¾î¸¦ »ç¿ëÇϱ⸦ ¿øÇÒÁöµµ ¸ð¸¥´Ù. °£´ÜÈ÷ ¾ê±âÇؼ, ¾î¼Àºí¸®ÀÇ ¹Ì±ÃÀ¸·Î ¶Ù¾îµé¾î¾ß ÇÏ´Â °æ¿ì´Â ¸Å¿ì ÀÛÀº Äڵ尡 ÇÊ¿äÇϰųª libc ¿¡ µ¶¸³ÀûÀÎ, Áï, ¶óÀ̺귯¸®¸¦ ÇÊ¿ä·Î ÇÏÁö ¾Ê´Â ÇÁ·Î±×·¥À» ¸¸µé¾î¾ß ÇÏ´Â Á».. ºñÁ¤»óÀûÀÎ(?) °æ¿ì ¹Û¿¡´Â ¾ø´Ù. ±×¸®°í, °¡Àå ÀÚÁÖ º¸°Ô µÇ´Â ±×·¯ÇÑ °æ¿ì´Â, ½ÅȽôëÀÇ(!) Àü¼³ÀûÀÎ ±¤±âÀÇ ÇØĿó·³ µÇ°í ½Í¾îÇÏ´Â »ç¶÷ÀÇ °æ¿ìÀÌ´Ù. ±×·± »ç¶÷Àº ÁÖ·Î ½º¹«»ì °¡·®ÀÇ, ¸ðµç°ÍÀ» ÀÚ½ÅÀÌ ´Ù ¾Ë¾Æ¾ß ÇÏ°í, ¸ðµç°ÍÀ» ½º½º·Î ÇÏ°í ½Í¾îÇÏ°í, ¸ðµç°ÍÀ» ¾î¼Àºí¸®·Î ÇÏ°í ½Í¾îÇÏ´Â »ç¶÷ÀÌ ¸¹´Ù. :-) (¿ªÀÚ ÁÖ:¿ªÀÚÀÇ ÀÇ¿ªÀÌ ³Ê¹«(!) ¸¹¾Ò½À´Ï´Ù. ¾Æ·¡¿¡ - ±×·¡¿ÔµíÀÌ - ¿ø¹®À» º¸ÀÔ´Ï´Ù. You may need to use assembly, or you may want to use assembly. In short, main practical (need) reasons of diving into the assembly realm are small code and libc independence. Impractical (want), and the most often reason is being just an old crazy hacker, who has twenty years old habit of doing everything in assembly language. ±×·¯³ª, ¿©·¯ºÐÀÌ ¸®´ª½º¸¦ ÀÓº£µðµå ½Ã½ºÅÛ¿¡ Æ÷ÆÃÇÏ·Á´Â °æ¿ì, Àüü ÇÁ·Î±×·¥ÀÇ Å©±â¿¡ »ó´çÈ÷ ¿¹¹ÎÇØ ÁúÅÙµ¥, Áï, Ä¿³Î, libc, À¯Æ¿¸®Æ¼µé(file|find|text|sh|etc.) ÀüºÎ¸¦ ´ÜÁö ¸î¹é kb ÀÇ ÀÛÀº Å©±â¿¡ ¸ÂÃß¾î ³ÖÀ»·Á°í ÇÏ°í, 1ų·Î¹ÙÀÌÆ®°¡ ´Ã¾î³¯ ¶§¸¶´Ù ½Ã½ºÅÛ »ý»ê ºñ¿ëÀÌ ³Ê¹« ¸¹ÀÌ µé ¶§°¡ ÀÖÀ» °ÍÀÌ´Ù. ±×·² °æ¿ì¿¡´Â ½Ã½ºÅÛÀÇ ÀϺΠȤÀº ÀüºÎ¸¦ ¾î¼Àºí¸®·Î ÀçÀÛ¼ºÇÏ´Â °Íµµ ÇÑ ¹æ¹ýÀÌ µÉ ¼ö ÀÖ´Ù. ±×¸®°í, ±×·¸°Ô ÇÑ´Ù¸é, »çÀÌÁî´Â °¨µ¿ÀûÀ¸·Î(! Á¤¸»·Î) ÀÛ¾ÆÁú °ÍÀÌ´Ù. ¿¹¸¦ Çϳª µé¾îº¸ÀÚ. ¾î¼Àºí¸®·Î °£´ÜÇÑ httpd µ¥¸óÀ» ¸¸µé¸é 600¹ÙÀÌÆ® ÀÌÇÏ·Î ¸¸µé¾îÁú ¼ö ÀÖ´Ù. ±×·¯¸é, ¿©·¯ºÐÀº Ä¿³Î°ú, httpd ¸¦ žÀçÇÑ À¥¼¹ö¸¦ 400 kb ȤÀº º¸´Ù ´õ ÀÛÀº »çÀÌÁî·Î ¸¸µé ¼ö ÀÖ°Ô µÈ´Ù. 3장. °¡¿ëÇÑ ¾î¼Àºí·¯µé3.1. GCC ÀζóÀÎ ¾î¼Àºí·¯¾ÆÁÖ À¯¸íÇÑ GNU C/C++ ÄÄÆÄÀÏ·¯ÀÎ GCC ÀÌ´Ù. ÀÌ ÄÄÆÄÀÏ·¯´Â GNU ÇÁ·ÎÁ§Æ®ÀÇ ÇÙ½ÉÀÌ µÇ´Â 32ºñÆ® ÄÄÆÄÀÏ·¯ÀÌ´Ù. ¸Å¿ì, ¸Å¿ì(!) ÁÁÀº Äڵ带 »ý»êÇϸç, x86 ¾ÆÅ°ÅØÃÄÀÇ ÇÁ·Î¼¼¼ ¶ÇÇÑ ¸Å¿ì Àß Áö¿øÇÑ´Ù. ÀÌ ÄÄÆÄÀÏ·¯¿¡´Â C ÇÁ·Î±×·¥ ÄÚµå Áß°£¿¡ ÀζóÀÎ ¾î¼Àºí¸®¸¦ »ðÀÔÇÒ ¼ö ÀÖ´Â ±â´ÉÀ» °¡Áö°í Àִµ¥, À̸¦Å׸é, ·¹Áö½ºÅÍ ÇÒ´ç°ú °°Àº °ÍÀ» gcc °¡ ½º½º·Î ÇÏ°Ô Çϰųª, ¶Ç´Â ÇÁ·Î±×·¡¸Ó°¡ ¿øÇÏ´Â ´ë·Î Á¶Á¤Çؼ, ¿øÇÏ´Â ·¹Áö½ºÅ͸¦ ÇÒ´çÇÏ°Ô ÇÒ ¼öµµ ÀÖ´Ù. °Ô´Ù°¡, gcc ´Â °ÅÀÇ ´ëºÎºÐÀÇ Ç÷§Æû¿¡¼ »ç¿ë°¡´ÉÇÏ´Ù. ¸®´ª½º, *BSD, VSTa, OS/2, *DOS, Win* µî°ú °°ÀÌ ±¤¹üÀ§ÇÑ ¿î¿µÃ¼Á¦¿¡¼ »ç¿ë °¡´ÉÇÏ´Ù. 3.1.1. GCC ¸¦ ¾îµð¼ ±¸ÇÒ °ÍÀΰ¡?°¡Àå ÁÖµÈ »çÀÌÆ®´Â GNU ÀÇ FTP »çÀÌÆ® ( ftp://prep.ai.mit.edu/pub/gnu/gcc/) ÀÌ´Ù. ÀÌ »çÀÌÆ®´Â GNU ÇÁ·ÎÁ§Æ®ÀÇ »ê¹°ÀÎ ¸¹Àº ÀÚÀ¯ ¼ÒÇÁÆ®¿þ¾îµéÀÌ ÄÄÆÄÀÏµÈ ÇüÅ ȤÀº ¼Ò½ºÀÇ ÇüÅ·Π¹ßÇ¥µÇ´Â °÷ÀÌ´Ù. ¸®´ª½º¿¡ ¸ÂÃç¼ ¼³Á¤ ¹× ÄÄÆÄÀÏµÈ ¹öÁ¯µéÀº ftp://metalab.unc.edu/pub/Linux/GCC/ ¿¡¼ ãÀ» ¼ö ÀÖ´Ù. ¶ÇÇÑ, ¼¼°è °¢Ã³¿¡ FTP ¹Ì·¯ »çÀÌÆ®µéÀÌ ÀÖ´Ù. ¿øÇÑ´Ù¸é, CD-ROM À¸·Îµµ ±¸ÇÒ ¼ö ÀÖ´Ù. GCC ÀÇ °³¹ßÀº ÀÏÀü¿¡ GCC2.8 °ú EGCS ÆÐÅ°ÁöÀÇ µÎ°³ÀÇ °¡Áö·Î ³ª´©¾îÁ³¾ú´Ù. ±×·¯³ª ÃÖ±Ù¿¡ ¿Í¼ ÀÌ µÎ ÆÐÅ°Áö´Â ÅëÇÕµÇ¾î¼ °³¹ß ¹× ¹èÆ÷µÇ°í ÀÖ´Ù. ÇöÀç GCC ÀÇ À¥ÆäÀÌÁö´Â http://gcc.gnu.org ÀÌ´Ù. ¿©·¯ºÐÀÌ Áñ°Ü »ç¿ëÇÏ´Â ¿î¿µÃ¼Á¦¸¦ Ÿ°ÙÀ¸·Î ¸¸µé¾îÁø ¼Ò½º³ª ¹ÙÀ̳ʸ® ¶ÇÇÑ ¿©·¯ºÐÀÌ ÀÚÁÖ °¡´Â ¿©·¯ºÐ ¿î¿µÃ¼Á¦ÀÇ FTP »çÀÌÆ®µé¿¡¼ ãÀ» ¼ö ÀÖÀ» °ÍÀÌ´Ù. GCC ÀÇ DOS ¹öÁ¯Àº DJGPP ¶ó°í ºÒ¸®¿ì´Âµ¥, http://www.delorie.com/djgpp/ ¿¡¼ ±¸ÇÒ ¼ö ÀÖ´Ù. ¶ÇÇÑ Win32 ¿ëÀÇ GCC Æ÷Æ®µµ ÀÖ´Ù : cygwin ( http://sourceware.cygnus.com/cygwin/) °ú mingw (http://www.mingw.org) °¡ ±×°ÍÀÌ´Ù. ½ÉÁö¾î OS/2 ¿ëÀÇ GCC Æ÷Æ®µµ ÀÖ´Ù. ÀÌ°ÍÀº EMX ¶ó°í ºÒ¸®¿î´Ù. ±¸ÇÒ ¼ö ÀÖ´Â URL Àº ´ÙÀ½°ú °°´Ù. ftp://ftp-os2.cdrom.com/pub/os2/emx09c/. ¿©±â¼ ±¸ÇÒ ¼ö ÀÖ´Â EMX ´Â µµ½º¿¡¼µµ ÀÛµ¿Çϸç, ÆÐÅ°Áö¿¡´Â À¯´Ð½º ¿¡¹Ä·¹À̼ÇÀ» À§ÇÑ ¸ñÀûÀº ¶óÀ̺귯¸® ·çƾµµ Æ÷ÇԵǾî ÀÖ´Ù. ¾ÕÀÇ »çÀÌÆ®¿¡¼ ¿©±âÀú±â¸¦ µÑ·¯º¸°í ã¾Æ º¸¶ó. There is also an OS/2 port of GCC called EMX; it works under DOS too, and includes lots of unix-emulation library routines. 3.1.2. GCC ÀζóÀÎ ¾î¼Àºí·¯¿¡ °üÇÑ ¹®¼¸¦ ¾îµð¼ ãÀ» ¼ö Àִ°¡GCC ¹®¼´Â TeXinfo Æ÷¸äÀ¸·Î ¹®¼ÆÄÀϵéÀ» Æ÷ÇÔÇÑ´Ù. ¿©·¯ºÐÀº ±× ¹®¼µéÀº TeX À» ÀÌ¿ëÇÏ¿© ÄÄÆÄÀÏÇØ Ãâ·ÂÇØ º¼ ¼öµµ ÀÖ°í, .info ÆÄÀÏ·Î º¯È¯Çؼ emacs ¿¡¼ ºê¶ó¿ì¡ ÇÏ¸é¼ ÀÐÀ»¼öµµ ÀÖ´Ù. ¶Ç´Â, .html ÆÄÀÏ·Î º¯È¯ÇÏ¿© À¥ ºê¶ó¿ìÀú¿¡¼ ÀÐÀ» ¼öµµ ÀÖ°í... ±âŸ ¿©·¯ºÐµéÀÌ ÁÁ¾ÆÇÏ´Â Æ÷¸äÀ¸·Î º¯È¯ÇÒ ¼ö ÀÖ´Ù. .info ÆÄÀÏÀº GCC¸¦ Á¦´ë·Î ¼³Ä¡Çß´Ù¸é ÇÔ²² ¼³Ä¡µÇ¾úÀ» °ÍÀÌ´Ù. ¿©·¯ºÐÀÌ Á¤º¸¸¦ ¾ò±â À§Çؼ ã¾Æ¾ß ÇÒ ¼½¼ÇÀº C Extensions::Extended Asm:: ¼½¼ÇÀÌ´Ù. ¶ÇÇÑ, Invoking GCC::Submodel Options::i386 Options:: ¼½¼Ç¿¡ ÀÖ´Â ³»¿ëµµ »ó´çÈ÷ À¯¿ëÇÒ °ÍÀÌ´Ù. ƯÈ÷³ª ÀÌ ¼½¼ÇÀ» ÀÚ¼¼È÷ »ìÆ캸¸é, i386 °è¿ÀÇ ·¹Áö½ºÅ͸¦ À§ÇØ ±ÔÁ¤µÈ À̸§¿¡ ´ëÇÑ Á¤º¸¸¦ ¾òÀ» ¼ö Àִµ¥ : abcdSDB °¡ °¢°¢ %eax, %ebx, %ecx, %edx, %esi, %edi, %ebp °ú Çϳª¾¿ ÀÏÄ¡ÇÏ°Ô µÈ´Ù. (´Ü %esp ¿¡ ÇØ´çÇÏ´Â °ÍÀº ¾øÀ½), À¥ÀÇ DJGPP °ÔÀÓÁî ¸®¼Ò½º ÆäÀÌÁö¿¡ ¾î¼Àºí¸®¿¡ °üÇÑ ³»¿ëÀÌ ¸Å¿ì ¸¹ÀÌ ÀÖ¾ú´Âµ¥... Áö±ÝÀº ¼¹ö°¡ Á×¾î ÀÖ´Â°Í °°´Ù. ±×·¯³ª, ÀÚ·á´Â DJGPP »çÀÌÆ® ¿¡ º¹±¸µÇ¾î ÀÖ´Ù. ÀÌ »çÀÌÆ®¿¡´Â ´Ù¸¥ À¯¿ëÇÑ Á¤º¸µéµµ ¸¹ÀÌ Á¸ÀçÇÑ´Ù : http://www.delorie.com/djgpp/doc/brennan/, ¶ÇÇÑ, Á¤¸» À¯¿ëÇÑ ÀÚ·áÀÎ DJGPP Quick ASM Programming Guide µµ ã¾Æº¼ ¼ö ÀÖ´Ù. GCC ´Â ¾î¼Àºí¸® ¼Ò½º¸¦ ¾î¼Àºí Çϱâ À§Çؼ GAS ¿¡ ÀÇÁ¸Çϸç, GAS ÀÇ ¹®¹ýÀ» µû¸¥´Ù(¾Æ·¡¸¦ º¸¶ó:) ÀζóÀÎ ¾î¼Àºí¸®¸¦ ¾µ ¶§, ÆÛ¼¾Æ® ¹®ÀÚ´Â µû¿ÈÇ¥·Î µÑ·¯½Î¾ß ÇÑ´Ù´Â °ÍÀ» ¸í½ÉÇ϶ó. ÆÛ¼¾Æ® ¹®ÀÚ´Â GAS ·Î ³Ñ°ÜÁö°Ô µÈ´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº ¾Æ·¡ÀÇ GAS ¿¡ °ü·ÃµÈ ¼½¼ÇÀ» º¸¶ó. ±×¸®°í, Á¤¸» À¯¿ëÇÑ ¿¹Á¦µéÀÇ ÁýÇÕüÀÎ linux/include/asm-i386/ µð·ºÅ丮 ¾Æ·¡¸¦ »ìÆ캸¶ó. ¶ÇÇÑ, ¸®´ª½º Ä¿³ÎÀÇ ¼ºêµð·ºÅ丮µéµµ »ìÆ캸µµ·Ï Ç϶ó. À¯¿ëÇÑ ¿¹Á¦µéÀ» Á¤¸»·Î ¸¹ÀÌ ¾òÀ» ¼ö ÀÖÀ» °ÍÀÌ´Ù. 3.1.3. GCC ¸¦ ÀÌ¿ëÇÏ¿© ÀζóÀÎ ¾î¼Àºí¸® Äڵ带 »ý¼ºÇϱâ Ä¿³Î Çì´õµé¿¡¼ ã¾Æº¼ ¼ö ÀÖ´Â ¾î¼Àºí¸® ·çƾµéÀº
Because assembly routines from the kernel headers (and most likely your own headers, if you try making your assembly programming as clean as it is in the linux kernel) are embedded in extern inline functions, GCC must be invoked with the -O flag (or -O2, -O3, etc), for these routines to be available. If not, your code may compile, but not link properly, since it will be looking for non-inlined extern functions in the libraries against which your program is being linked! Another way is to link against libraries that include fallback versions of the routines. ÀζóÀÎ ¾î¼Àºí¸®°¡ »ç¿ëÇϱ⠽ȴٸé, which will have the compiler die when using extended inline asm syntax,
or else generate calls to an external function named º¸´Ù ÀϹÝÀûÀÎ °ÍÀ¸·Î½á, x86 Ç÷§Æû¿¡¼ ½ÇÇàµÇ´Â gcc ¿¡ ¸Å¿ì À¯¿ëÇÑ Ç÷¡±×°¡ Àִµ¥, ¹Ù·Î gcc -O2 -fomit-frame-pointer -W -Wall ÀÌ´Ù. ¿©·¯ºÐÀº ÀÏ·ÃÀÇ ÇÁ·Î¼¼¼ Á¾¼ÓÀûÀÎ ÃÖÀûÈ ¿É¼ÇÀ» ÁÙ ¼ö Àִµ¥, ¿¹¸¦ µé¸é,
In such settings, it might be useful to stop using C, and use instead a language that favors code factorization, such as a functional language and/or FORTH, and use a bytecode- or wordcode- based implementation. ¿©·¯ºÐÀº ÃÖÀûÈ ¿É¼ÇÀ» ÆÄÀϺ°·Î ´Ù ´Ù¸£°Ô ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù. ±×·¡¼, ¸Å¿ì ÁÁÀº ¼º´ÉÀÌ ¿ä±¸µÇ´Â ·çƾÀ» ´ã°í ÀÖ´Â ÆÄÀÏ¿¡´Â ÃÖ°í ·¹º§ÀÇ ¼Óµµ¸¦ ³¾ ¼ö ÀÖµµ·Ï ÃÖÀûȸ¦ ¼öÇàÇÏ°í, ´Ù¸¥ ÆÄÀÏ¿¡´Â »ý¼ºµÇ´Â ÄÚµåÀÇ Å©±â¸¦ ÀÛ°Ô ÇÏ´Â ¹æÇâÀ¸·Î ÃÖÀûÈÇÒ ¼öµµ ÀÖ´Ù´Â °ÍÀ» À¯³äÇ϶ó. Á» ´õ ³ªÀº ÃÖÀûȸ¦ ½ÃÅ°·Á¸é ¿ÜºÎÀÇ ÇÔ¼öµéÀ» Á¤È®ÇÏ°Ô ¼±¾ðÇØ ÁÜÀ¸·Î½á, ¿Ã¹Ù¸¥ ¼ø¼¿¡ µû¸¥ È£ÃâÀÌ ¹ß»ýÇϵµ·Ï Á¶Á¤ÇØ Áְųª, ¿ÜºÎ ¶óÀ̺귯¸®µéÀ» ¿©·¯ºÐÀÌ ¸¸µç ÇÁ·Î±×·¥°ú °°Àº ·¹Áö½ºÅ͸¦ »ç¿ëÇϴ ȣÃâ ÄÁº¥¼ÇÀ» »ç¿ëÇϵµ·Ï ÀçÄÄÆÄÀÏ ÇØ ÁÜÀ¸·Î½á, ¹®Á¦¸¦ ±Øº¹ÇÒ ¼ö Àֱ⵵ ÇÏ´Ù. There are ways to correctly declare foreign functions so the right call sequences be generated, or you might want to recompile the foreign libraries to use the same register-based calling convention... /usr/lib/gcc-lib/i486-linux/2.7.2.3/specs
À» ÆíÁýÇؼ ¿©·¯ºÐÀÇ make ¿¡ À§¿¡¼ ¼³¸íÇÑ Ç÷¡±×µéÀÌ µðÆúÆ®°¡
µÇµµ·Ï ÇÒ ¼öµµ ÀÖ´Ù.(±×·¯³ª ±× °æ¿ì, 3.1.4. ¸ÅÅ©·ÎÀÇ Áö¿øGCC ´Â ¿©·¯ºÐÀÌ ¿©·¯ºÐÀÇ ÀζóÀÎ ¾î¼Àºí¸® ÄÚµå ³»¿¡ ·¹Áö½ºÅÍ ±Ô¾à(? - constraints)À» ¸í½ÃÇÏ´Â °ÍÀ» °¡´ÉÇÏ°Ô ÇÕ´Ï´Ù. ±×·³À¸·Î½á, ÃÖÀûÈ ÇÒ ¶§ ÄÄÆÄÀÏ·¯°¡ ±× »ç½ÇÀ» Âü°íÇÏ¿© ÀζóÀÎ ¾î¼Àºí¸® Äڵ尡 ÆÐÅϵéÀÇ ÁýÇÕÀ¸·Î »ý¼ºµÇµµ·Ï ÇÕ´Ï´Ù. (-_-; ³Ê¹« ¹ø¿ªÀ» ¸øÇÏ´Â °Å °°±º¿©) GCC allows (and requires) you to specify register constraints in your inline assembly code, so the optimizer always know about it; thus, inline assembly code is really made of patterns, not forcibly exact code. µû¶ó¼ ¿©·¯ºÐÀº ¿©·¯ºÐÀÇ ¾î¼Àºí¸®¸¦ CPP ¸ÅÅ©·Î ¶óµçÁö, ÀζóÀÎÀÇ C ÇÔ¼öµé ³»ºÎ¿¡ Æ÷ÇÔ ½Ãų ¼ö ÀÖ½À´Ï´Ù. ±×·¸°Ô Çϸé, ´©±¸µçÁö, ±× ¾î¼Àºí¸® Äڵ带 Æò¹üÇÑ C ÇÔ¼ö³ª ¸ÅÅ©·Îó·³ »ç¿ëÇÒ ¼ö ÀÖ°Ô µË´Ï´Ù. ÀζóÀÎ ÇÔ¼öµéÀº ¸ÅÅ©·Î¿Í ¸Å¿ì ºñ½ÁÇÏ°Ô º¸ÀÌÁö¸¸, ¶§·Î´Â ´õ¿í ¸íÈ®ÇÏ¿© ¾²±â°¡ ´õ ½±´Ù. ±×·¯³ª, ¸ÅÅ©·Î¸¦ »ç¿ëÇϵç, ÀζóÀÎ ÇÔ¼ö¸¦ ¾²´ø, °è¼Ó Áߺ¹µÈ Äڵ带 ¾²°Ô µÈ´Ù´Â °ÍÀ» ¸í½ÉÇ϶ó. µû¶ó¼, 1: °ú °°Àº ½ºÅ¸ÀÏÀÇ ·ÎÄà ·¹ÀÌºí¸¸ÀÌ ±×·¯ÇÑ ¾î¼Àºí¸® Äڵ忡¼ Á¤Àǵǰí, »ç¿ëµÇ¾î¾ß ÇÑ´Ù. ±×·¯³ª, ¸ÅÅ©·Î´Â ·ÎÄà ·¹À̺í·Î Á¤ÀǵÇÁö ¾ÊÀº ·¹À̺íÀÌ ÆĶó¹ÌÅÍ·Î ³Ñ°ÜÁö´Â °ÍÀ» Çã¿ëÇÑ´Ù. (ȤÀº, ¿©·¯ºÐÀº ºÎ°¡ÀûÀÎ ¸ÞŸ ÇÁ·Î±×·¡¹Ö ±â¹ýÀ» »ç¿ëÇÒ ¼ö ÀÖÀ» °ÍÀÌ´Ù.) ¶ÇÇÑ, ÀζóÀÎ ¾î¼Àºí¸® Äڵ带 È®ÀåÇÏ°Ô µÇ¸é, ±× ÄÚµå ¾ÈÀÇ ÀáÀçÀûÀÎ ¹ö±× ¶ÇÇÑ ³ªÅ¸³¯ ¼ö ÀÖ´Ù. ±×·¯¹Ç·Î, ±×·¯ÇÑ ÀζóÀÎ ¾î¼Àºí¸® Äڵ忡¼ ·¹Áö½ºÅÍ »ç¿ë¹æ¹ýÀ» ÀÌÁßÀ¸·Î °íÂûÇϵµ·Ï Ç϶ó. Thus, you can make put your assembly into CPP macros, and inline C functions, so anyone can use it in as any C function/macro. Inline functions resemble macros very much, but are sometimes cleaner to use. Beware that in all those cases, code will be duplicated, so only local labels (of 1: style) should be defined in that asm code. However, a macro would allow the name for a non local defined label to be passed as a parameter (or else, you should use additional meta-programming methods). Also, note that propagating inline asm code will spread potential bugs in them; so watch out doubly for register constraints in such inline asm code. ¸¶Áö¸·À¸·Î, C ¾ð¾î ±× ÀÚü°¡ ¾î¼Àºí¸® ÇÁ·Î±×·¡¹ÖÀÇ ¸Å¿ì ÁÁÀº Ãß»óȶó´Â °ÍÀ» ¸í½ÉÇÏ°í, C ¸¦ »ç¿ëÇÔÀ¸·Î½á, ¾î¼Àºí¸® ÇÁ·Î±×·¡¹Ö½Ã ¹ß»ýÇÒ ¼ö ÀÖ´Â ¸¹Àº ³Á¡µé ±Øº¹ÇÏ°í, º¸´Ù ½Å·Úµµ ³ôÀº ÇÁ·Î±×·¥À» ¿©·¯ºÐÀÌ ¸¸µé ¼ö ÀÖ°Ô µÉ °ÍÀÌ´Ù. Lastly, the C language itself may be considered as a good abstraction to assembly programming, which relieves you from most of the trouble of assembling. 3.2. GASGAS ´Â GCC °¡ »ç¿ëÇÏ´Â GNU ¾î¼Àºí·¯ÀÌ´Ù. 3.2.1. ¾îµð¿¡¼ GAS ¸¦ ãÀ» ¼ö Àִ°¡GCC ¸¦ ãÀº °÷°ú °°Àº Àå¼Ò¿¡ ÀÖ´Ù. ÆÐÅ°Áö binutils ¾È¿¡ ÆÐŰ¡µÇ¾î ÀÖ´Ù. ÃÖ½ÅÀÇ GAS ¹öÁ¯Àº HJLu ¿¡¼ ±¸ÇÒ ¼ö ÀÖ´Ù. url Àº ´ÙÀ½°ú °°´Ù : ftp://ftp.varesearch.com/pub/support/hjl/binutils/. 3.2.2. AT&T ¹®¹ýGAS °¡ ¿ø·¡ 32-bit ÀÇ À¯´Ð½º ÄÄÆÄÀÏ·¯¸¦ Áö¿øÇϵµ·Ï óÀ½¿¡ °í¾ÈµÇ¾ú±â ¶§¹®¿¡, GAS ´Â Ç¥ÁØ AT&T ¹®¹ýÀ» »ç¿ëÇÑ´Ù. Ç¥ÁØ AT&T ¹®¹ýÀº m68k ¾î¼Àºí·¯ÀÇ ¹®¹ý°ú »ó´çÈ÷ À¯»çÇÏ´Ù. ÇöÀç UNIX °è¿ ¾î¼Àºí¸®ÀÇ Ç¥ÁØ ¹®¹ýÀ̱⵵ ÇÏ´Ù. ÀÌ ¹®¹ýÀº Intel ¹®¹ý¿¡ ºñÇؼ ÁÁÁöµµ ¾Ê°í, ³ª»ÚÁöµµ ¾Ê´Ù. ´ÜÁö ´Ù¸¦ »ÓÀÌ´Ù. ¿©·¯ºÐµéÀÌ ±×°ÍÀ» »ç¿ëÇغ¸°Ô µÇ¸é, ÀÎÅÚ ¹®¹ý¿¡ ºñÇØ Á»´õ ¸¹Àº ±ÔÄ¢ÀÌ ÀÖÀ½ À» ¾Ë°Ô µÉ °ÍÀÌ´Ù. ¾Æ·¡¿¡ GAS ¹®¹ýÀÇ ÁÖ¿ä »çÇ×µéÀ» ³ª¿ÇÏ°Ú´Ù.
ÁÖÀÇ : AT&T ¹®¹ýÀ» ÀÌ¿ëÇÑ ¾î¼Àºí¸® ¼Ò½ºÄÚµå¿Í ÀÎÅÚÀÇ ¹®¹ýÀ» ÀÌ¿ëÇÑ ¼Ò½º ÄÚµå °£¿¡ ¼·Î º¯È¯À» ½ÃÄÑ ÁÖ´Â ÇÁ·Î±×·¥Àº °ÅÀÇ ¾ø´Ù.(few programs) Note: There are few programs which may help you to convert source code between AT&T and Intel assembler syntaxes; some of the are capable of performing conversion in both directions. GAS ´Â ÆÐÅ°Áö¿¡ TeXinfo Çü½ÄÀ¸·Î µÈ ¸Å¿ì ÀÌÇØÇϱ⠽¬¿î ¹®¼¸¦ °¡Áö°í ÀÖ´Ù. .info ÆäÀÌÁö Çü½ÄÀ¸·Î Emacs µî¿¡¼ ºê¶ó¿ì¡ ÇÒ ¼öµµ ÀÖ´Ù. ÆÄÀϸíÀº gas.doc À̰ųª as.doc ÀÏ °ÍÀÌ´Ù. ÀǽÉÀÇ ¿©Áö ¾øÀÌ ÃÖ°íÀÇ ¹®¼´Â ¼Ò½ºÄÚµå ÀÚüÀÌ´Ù. ´Ù½ÃÇѹø, ¸®´ª½ºÀÇ ¼Ò½º°¡ ÃÖ»óÀÇ ¿¹Á¦ÀÓÀ» »ó±âÇ϶ó. linux/arch/i386/ µð·ºÅ丮 ¾Æ·¡¿¡¼ kernel/*.S, boot/compressed/*.S, mathemu/*.S. °ú °°Àº ÆÄÀÏÀ» ¿¾î¼ ÀÐ¾î º¸¾Æ¶ó. ÃÖ°íÀÇ ¿¹Á¦ÀÌ´Ù. ¸¸¾à ¿©·¯ºÐÀÌ ¾ð¾î¸¦ Çϳª °í¾ÈÇÏ°í Àְųª, ¾²·¹µå ÆÐÅ°Áö¸¦ ÇÁ·Î±×·¡¹ÖÇÏ°í ÀÖ´Ù¸é, ´Ù¸¥ ¾ð¾î( OCaml, Gforth, etc.) ³ª ½º·¹µå ÆÐÅ°Áöµé (QuickThreads, MIT pthreads, LinuxThreads, etc) À» »ìÆì º¸±â¸¦ ¿øÇÒ °ÍÀÌ´Ù. ±×¸®°í, »ìÆì º¸¸é µÈ´Ù!!! ¸¶Áö¸·À¸·Î, ´ÜÁö, C ÇÁ·Î±×·¥À» ¾î¼Àºí¸®·Î ÄÄÆÄÀÏ Çϱ⸸À» ¿øÇÑ´Ù¸é, ´ÜÁö, ¿©·¯ºÐÀÌ ¿øÇÏ´Â ÀνºÆ®·°¼ÇÀÇ Á¾·ù¿Í ¹®¹ý¸¸ ¾Ë¸é µÉ °ÍÀÌ´Ù. À§¿¡¼ ¿©·¯ºÐÀÌ Á¤¸» ¾î¼Àºí¸® ÇÁ·Î±×·¡¹ÖÀÌ ÇÊ¿äÇÑ°¡¸¦ ÆÇ´ÜÇϵµ·Ï µ½´Â ¼½¼ÇÀ» º¸µµ·Ï Ç϶ó : See section Do you need assembly? above. 3.2.3. GAS ÀÇ ÀÎÅÚ ¹®¹ý Áö¿øbinutils 2.10 ºÎÅÍ GAS ´Â ÀÎÅÚ °è¿ÀÇ ¹®¹ý ¶ÇÇÑ Áö¿øÇÑ´Ù. .intel_syntax Áö½Ã¾î¸¦ ÀÌ¿ëÇÏ¿© È°¼ºÈ ½ÃŲ´Ù. 3.2.4. 16-ºñÆ® ¸ðµåBinutils (2.9.1.0.25+) ÀÌÈÄÀÇ ¹öÁ¯ºÎÅÍ´Â i386 °è¿ÀÇ ÄÄÇ»Å͵鿡¼ 16ºñÆ® ¸ðµå(·¹Áö½ºÅÍ¿Í ÁÖ¼ÒÁöÁ¤¹æ½Ä)¸¦ ¿Ïº®ÇÏ°Ô Áö¿øÇÑ´Ù. ¾î¼Àºí¸® Äڵ忡¼ 16ºñÆ®¿Í 32ºñÆ® ¸ðµå¸¦ ÀüȯÇÒ ¶§´Â .code16 °ú .code32 Áö½ÃÀÚ¸¦ »ç¿ëÇÏ¸é µÈ´Ù. ¶ÇÇÑ, ¸î¸î »ç¶÷µé(oskit ÀÇ ÀúÀڵ鵵 Æ÷ÇÔ)ÀÌ »ç¿ëÇß´ø ±ò²ûÇÑ Æ®¸¯ÀÌ Àִµ¥, ±×°ÍÀº GCC ·Î ÇÏ¿©±Ý 16 ºñÆ® ¸®¾ó¸ðµå¿ëÀÇ Äڵ带 »ý¼ºÇϵµ·Ï °Á¦ÇÏ´Â °ÍÀε¥, ÀζóÀÎ ¾î¼Àºí¸® ¹®ÀåÀÎ asm(".code16\n") À» ¾¸À¸·Î½á ±×·¸°Ô Çß´Ù. ±× ¹®ÀåÀ» »ç¿ëÇϸé, GCC ´Â ¿©ÀüÈ÷ 32ºñÆ®ÀÇ ÁÖ¼ÒÁöÁ¤ ¹æ½ÄÀ» »ç¿ëÇÑ Äڵ带 »ý»êÇÏÁö¸¸, GAS °¡ Àû´çÇÑ 32ºñÆ®ÀÇ Á¢µÎ¾î¸¦ ºÙ¿©ÁØ´Ù. 3.2.5. ¸ÅÅ©·Î Áö¿øGAS ¿¡´Â ¾ó¸¶ÀÇ ¸ÅÅ©·Î¿Í °ü·ÃµÈ ±â´Éµµ Æ÷ÇԵǾî ÀÖ´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº texinfo ¹®¼¸¦ º¸¶ó. ¸ÅÅ©·Î¿¡ ´õÇÏ¿©, GCC ´Â .s È®ÀåÀÚÀÇ ÆÄÀÏÀ» GAS ¿¡ ¹Ù·Î º¸³»¿©¾ß ÇÒ ¼ø¼öÇÑ ¾î¼Àºí¸® ·Î ÀνÄÇϴµ¥, ¶ÇÇÑ, .S ÀÇ È®ÀåÀÚ¸¦ °¡Áö´Â ÆÄÀÏÀº GAS ·Î ³Ñ±âÁö Àü¿¡ ¸ÕÀú CPP ¸¦ °ÅÄ£ ÈÄ¿¡ ³Ñ°Ü¾ß ÇÒ ÆÄÀÏ·Î ÀνÄÇÑ´Ù. °è¼Ó ¸»ÇÏ´Â °ÍÀÌÁö¸¸, ¸®´ª½ºÀÇ ¼Ò½º¸¦ ¿¹Á¦»ï¾Æ º¸¶ó. GAS ´Â ¶ÇÇÑ, GASP (GAS Preprocessor) ¸¦ °¡Áö°í Àִµ¥, GASP °¡ ÇÏ´Â ÀÏÀº ÀϹÝÀûÀÎ ¸ÅÅ©·Î¾î¼Àºí¸®ÀÇ Æ®¸¯À» GAS ¿¡ ´õÇØÁÖ´Â °ÍÀÌ´Ù. GASP ´Â GNU binutils ÆÐÅ°Áö ¾È¿¡ GAS ¿Í ´õºÒ¾î¼ ¹èÆ÷µÈ´Ù. GASP ´Â CPP ³ª m4 À¯Æ¿¸®Æ¼Ã³·³ ÇÊÅÍ·Î½á µ¿ÀÛÇÑ´Ù. ÀÚ¼¼ÇÑ °ÍÀº ÀúÀÚ°¡ Àß ¸ð¸£°ÚÀ¸³ª, texinfo Çü½ÄÀÇ ¹®¼°¡ µû¶ó¿À¹Ç·Î, ¹®¼¸¦ ÂüÁ¶Çϱ⠹ٶõ´Ù. ÀúÀÚ¿¡°Õ GAS ¿Í GASP ÀÇ Á¶ÇÕÀÌ ÀϹÝÀûÀÎ macro-assembler ó·³ ´À²¸Á³´Ù. 3.3. NASMNetwide Assembler project ´Â ¸Å¿ì ±¦ÂúÀº i386 ¾î¼Àºí·¯¸¦ Á¦°øÇÑ´Ù. ±× ¾î¼Àºí·¯´Â C ·Î ¾²¿©Á³À¸¸ç, ÃæºÐÈ÷ ¸ðµâÈ µÇ¾î ÀÖ´Ù. ±×¸®°í, Áö±ÝÀº °ÅÀÇ ¸ðµç ¾Ë·ÁÁø ¹®¹ý°ú, ¸ñÀû ÆÄÀÏÀÇ Çü½ÄÀ» Áö¿øÇÏ°Ô µÇ¾ú´Ù. 3.3.1. NASMÀ» ¾îµð¼ ±¸ÇÒ ¼ö Àִ°¡http://www.cryogen.com/nasm/, http://nasm.rm-f.net ¿©·¯ºÐÀÌ ÀÚÁÖ °¡´Â metalab ¹Ì·¯ »çÀÌÆ®ÀÇ devel/lang/asm/ µð·ºÅ丮¿¡ ÀÖ´Ù. ¾Æ¸¶µµ rpm À̳ª deb Çü½ÄÀÇ ÆÐÅ°Áö·Îµµ ±¸ÇÒ ¼ö ÀÖÀ» °ÍÀÌ´Ù. 3.3.2. NASM À¸·Î ¹«¾ùÀ» ÇÒ ¼ö Àִ°¡¹®¹ýÀº ÀÎÅÚ ½ºÅ¸ÀÏÀÌ´Ù. ¶ÇÇÑ, ÀÌÇØÇϱ⠽¬¿î ¸ÅÅ©·Î ÇÁ·Î¼¼½Ì¿¡ ´ëÇÑ Áö¿øµµ ÇÑ´Ù. Áö¿øµÇ´Â ¸ñÀû ÄÚµåÀÇ Çü½ÄÀº ´ÙÀ½°ú °°´Ù : bin, aout, coff, elf, as86, obj (DOS), win32, rdf (NASM °íÀ¯ÀÇ Æ÷¸Ë). NASM Àº ¶ÇÇÑ LCC ÄÄÆÄÀÏ·¯ÀÇ ¹é¿£µå·Îµµ »ç¿ëµÉ ¼ö ÀÖ´Ù. ¿©·¯ºÐÀÌ BCC ¸¦ 16ºñÆ® ÄÄÆÄÀÏ·¯·Î »ç¿ëÇÏÁö ¾Ê´Â´Ù¸é ¿©·¯ºÐÀº ¾Æ¸¶µµ, AS86 À̳ª MASM º¸´Ù NASM À» »ç¿ëÇØ¾ß ÇÒ °ÍÀÌ´Ù. NASM Àº ¿Â¶óÀÎÀ¸·Î °è¼Ó Áö¿øÀÌ ÀÌ·ç¾îÁö°í ÀÖ°í, ¶ÇÇÑ, °ÅÀÇ ¸ðµç Ç÷§Æû¿¡¼ µ¹¾Æ°¡±â ¶§¹®ÀÌ´Ù. Note: NASM ¿¡´Â µð½º¾î¼Àºí·¯ÀÎ NDISASM µµ µþ·Á¿Â´Ù. NASM Àº »ç¶÷ÀÇ ¼ÕÀ¸·Î ÀÛ¾÷Çس½ Æļ¸¦ žÀçÇÏ°í Àִµ¥, ±×·Î ÀÎÇØ GAS º¸´Ù ÈξÀ ºü¸£´Ù. (¿ªÀÚ ÁÖ : ±× ÀÌÈÄÀÇ ¸»Àº... Çؼ®ÀÌ Á» Èûµé±º¿ä -_- ¿ø¹®À» ±×´ë·Î µÎ°Ú½À´Ï´Ù.) Its hand-written parser makes it much faster than GAS, though of course, it doesn't support three bazillion different architectures. If you like Intel-style syntax, as opposed to GAS syntax, then it should be the assembler of choice.. 3.4. AS86AS86 Àº 16ºñÆ®¿Í 32ºñÆ® ¸ðµÎ¸¦ Áö¿øÇÏ´Â 80x86 ¿ëÀÇ ¾î¼Àºí·¯ÀÌ´Ù. ÀÌ ÇÁ·Î±×·¥Àº Bruce Evans ÀÇ C ÄÄÆÄÀÏ·¯(BCC) ÆÐÅ°ÁöÀÇ ÀϺÎÀÌ´Ù. °ÅÀÇ ´ëºÎºÐ ÀÎÅÚÀÇ ¹®¹ýÀ» µû¸£Áö¸¸, ÁÖ¼Ò ÁöÁ¤¹æ½Ä µî¿¡¼ ¾à°£ÀÇ Â÷À̸¦ º¸ÀδÙ. 3.4.1. AS86 À» ¾îµð¼ ±¸ÇÒ ¼ö Àִ°¡¿ÏÀüÈ÷ ½Ã´ë¿¡ µÚ¶³¾îÁø AS86 ÀÇ ¹öÁ¯Àº HJLu ¿¡ ÀÇÇØ ¹èÆ÷µÈ´Ù. ¿ëµµ´Â ´ÜÁö ¸®´ª½º Ä¿³ÎÀ» ÄÄÆÄÀÏÇÏ´Â°Í ¹Û¿¡ ¾ø´Ù. bin86 ÆÐÅ°Áö (ÇöÀç ¹öÁ¯ 0.4) ¾È¿¡ Æ÷ÇԵǾî ÀÖ´Ù. ¸®´ª½º GCC ¸¦ ±¸ÇÒ ¼ö ÀÖ´Â °÷ÀÌ¸é ¾îµð¿¡³ª ÀÖ´Ù. ±×·¯³ª, ÀúÀÚ´Â ¸®´ª½º¸¦ ÄÄÆÄÀÏÇÏ´Â ¿ëµµ ¿Ü¿¡´Â ¾Æ¹«µµ AS86 À» ¾²Áö ¾Ê´Â´Ù°í ¸»ÇØÁÖ°í ½Í´Ù. °Ô´Ù°¡ ¸®´ª½º¸¦ ÄÄÆÄÀÏÇϴµ¥¿¡µµ, ¹Ì´Ð½ºÀÇ ¿ÀºêÁ§Æ® ÆÄÀÏ Æ÷¸ËÀ» Áö¿øÇÏ´Â ºÎºÐ ¿Ü¿¡´Â ¾²ÀÌÁö ¾Ê´Â´Ù. ÀÌ ºÐ¾ß´Â GNU binutils µî°ú °°Àº ´Ù¸¥ Åø¿¡¼´Â ÀüÇô Áö¿øÇÏÁö ¾Ê´Â ºÐ¾ßÀÌ´Ù. ±×¸®°í, AS86 Àº 32ºñÆ® ¸ðµå¿¡¼ ¸î°¡Áö ¹ö±×¸¦ ³»Æ÷ÇÏ°í ÀÖ´Ù. ±×³É AS86 À» ¸®´ª½º¸¦ ÄÄÆÄÀÏÇÏ´Â µ¥¿¡¸¸ »ç¿ëÇ϶ó. Bruce Evans ÀÇ ÄÄÆÄÀÏ·¯ÀÇ ÃֽŠ¹öÁ¯Àº Ç×»ó FreeBSD ¿Í ÇÔ²² ¹èÆ÷µÈ´Ù. 2.1 ¹öÁ¯ÀÇ ¹èÆ÷ÆÇ¿¡¼´Â ¼Ò½º¸¦ ãÀ» ¼ö ¾ø¾ú´Ù :( ÀúÀÚÀÇ È¨ÆäÀÌÁö¿¡ ¼Ò½º¸¦ µÎ°Ú´Ù. http://www.tunes.org/~fare/files/asm/bcc-95.3.12.src.tgz ¾î·µç Linux/8086 (aka ELKS) ÇÁ·ÎÁ§Æ®´Â bcc ¸¦ À¯Áö/º¸¼ö ÇÏ°í ÀÖ±â´Â ÇÏ´Ù. (ÀúÀÚ´Â 32 ºñÆ® ÆÐÄ¡°¡ Æ÷ÇԵǾú´Ù°í´Â »ý°¢ÇÏÁö ¾Ê´Â´Ù) http://www.linux.org.uk/ELKS-Home/ (ȤÀº http://www.elks.ecs.soton.ac.uk) ¿Í ftp://linux.mit.edu/pub/linux/ELKS/ ¸¦ µÑ·¯º¸µµ·Ï Ç϶ó. ÀúÀÚ°¡ ¿©±â ¿Ã¶ó¿À´Â °³¹ß ¹öÁ¯µéÀ» ¸ðµÎ È®ÀÎÇØ º¼ ¼ö ¾ø¾ú´Ù. ÀÌ ±ÛÀ» ÀÐÀ¸½Ã´Â ºÐÀÌ °ü½ÉÀÌ ÀÖ´Ù¸é Á¶»çÇØ º¸°í ÀúÀÚ¿¡°Ô À̾߱âÇØ Áشٸé ÁÁ°Ú´Ù. ±×¸®°í, ¹«¾ùº¸´Ù ÀÌ ÅøÀÇ º¸´Ù ÃÖ½ÅÀÇ ¹öÁ¯Àº ¸®´ª½ºÀÇ a.out Æ÷¸ËÀÇ ½ÇÇàÆÄÀÏ Çü½ÄÀ» Áö¿øÇÑ´Ù. ±×·¡¼, ¿©·¯ºÐÀº ¿©·¯ºÐÀÇ Äڵ带 ¸®´ª½º ÇÁ·Î±×·¥¿¡ ¸µÅ©½ÃÄѼ »ç¿ëÇϰųª, GNU binutils ÆÐÅ°ÁöÀÇ ÅøµéÀ» ¿©·¯ºÐÀÇ ÇÁ·Î±×·¥ÀÇ ÀڷḦ À¯ÁöÇϴµ¥ »ç¿ëÇÒ ¼ö ÀÖÀ» °ÍÀÌ´Ù. AS86 ÇÁ·Î±×·¥Àº ÀÌÀü ¹öÁ¯ ȤÀº ´Ù¸¥ ÇÁ·Î±×·¥°ú ¾Æ¹«·± Ãæµ¹ ¾øÀÌ ¿©·¯ºÐÀÇ ½Ã½ºÅÛ¿¡ °øÁ¸ÇÒ ¼ö ÀÖ´Ù. 1995 ³â 3¿ù 12ÀÏ ÀÌÀüÀÇ ¹öÁ¯ÀÇ BCC ´Â ¸ðµç ¼¼±×¸ÕÆ®ÀÇ Çª½Ã/ÆË À» 16ºñÆ®·Î ÇÏ´Â ¿À·ù°¡ Àִµ¥, ±×°ÍÀº 32ºñÆ® ¸ðµå·Î ÇÁ·Î±×·¡¹Ö Çϴµ¥ ÀÖ¾î¼ »ó´çÈ÷ ±ÍÂú°í, °ñÄ¡¾ÆÇ ¹®Á¦ÀÌ´Ù. ÀúÀÚ´Â TUNES ÇÁ·ÎÁ§Æ®°¡ AS86 À» »ç¿ëÇÒ ´ç½Ã ±×¿¡´ëÇÑ ÆÐÄ¡¸¦ Çß¾ú´Ù. http://www.tunes.org/~fare/files/asm/as86.bcc.patch.gz ºê·ç½º ¿¡¹Ý½ºµµ ÀÌ ÆÐÄ¡¸¦ ½ÂÀÎÇÏ¿´´Ù. ±×·¸Áö¸¸, ±×´Â bcc ÀÇ »õ·Î¿î ¸±¸®Áî´Â ¹ßÇ¥ÇÏÁö ¾Ê¾Ò´Ù. 3.4.2. ¾î¼Àºí·¯¸¦ ÀÛµ¿½ÃÅ°´Â ¹æ¹ý : How to invoke the assembler?¾Æ·¡¿¡ BCC ¸¦ »ç¿ëÇؼ .s ÆÄÀϷκÎÅÍ a.out Çü½ÄÀÇ .o ¿ÀºêÁ§Æ® ÄÚµå¿Í .l ÀÇ ¸®½ºÆà ÆÄÀÏÀ» »ý¼º½ÃÅ°´Â »ý¼º½ÃÅ°´Â GNU makefile ÀÇ ¿£Æ®¸®°¡ ÀÖ´Ù.
¿©·¯ºÐÀÌ ¸®½ºÆà ÆÄÀÏÀ» »ý¼ºÇϱ⸦ ¿øÇÏÁö ¾Ê´Â´Ù¸é, %.l °ú -A-l, ±×¸®°í -A$*.l À» »èÁ¦ÇÏ¸é µÈ´Ù. ±×¸®°í, a.out ¸»°í ´Ù¸¥ ÆÄÀÏÀÌ Ãâ·ÂµÇ°Ô ÇÏ·Á¸é, bcc ÀÇ ¹®¼¸¦ ÂüÁ¶ÇÏ¿© ´Ù¸¥ Áö¿øµÇ´Â Çü½ÄÀ» ã¾Æº¸°Å³ª, GNU binutils ÆÐÅ°ÁöÀÇ objcopy À¯Æ¿¸®Æ¼¸¦ »ç¿ëÇ϶ó. 3.4.3. AS86ÀÇ ¹®¼¸¦ ãÀ» ¼ö ÀÖ´Â °÷¹®¼µéÀº bcc ÆÐÅ°Áö ¾È¿¡ Æ÷ÇԵǾî ÀÖ´Ù. FreeBSD »çÀÌÆ®ÀÎ http://www.tunes.org/~fare/files/asm/bcc-95.3.12.src.tgz ¿¡¼ ¸ÇÆäÀÌÁö¸¦ ±¸ÇÒ ¼ö ÀÖ¾ú´Ù. ELKS ÀÇ °³¹ßÀÚµéÀÌ ´õ ¸¹ÀÌ ¾Ë°í ÀÖÀ» °ÍÀÌ´Ù. Èì... ±×¸®°í, Á» ´õ ¾Ë°í ½Í´Ù¸é, AS86 ÀÇ ¼Ò½º ±× ÀÚü°¡ ÁÁÀº ¹®¼°¡ µÉ °ÍÀÌ´Ù. ÁÖ¼®ÀÌ ±×¸® Àß µÇ¾î ÀÖ´Â °ÍÀº ¾Æ´ÏÁö¸¸, ÇÁ·Î±×·¡¹Ö ½ºÅ¸ÀÏÀº ¸Å¿ì Á÷¼±Àû(?)ÀÌ´Ù. ¿©·¯ºÐÀº ELKS ÇÁ·ÎÁ§Æ®³ª TUNES ÇÁ·ÎÁ§Æ® 0.0.0.25 ¿¡¼ AS86 ÀÌ ¾î¶»°Ô ¾²¿´´ÂÁö »ìÆ캼 ¼öµµ ÀÖÀ» °ÍÀÌ´Ù. 3.4.4. ¸ÅÅ©·Î Áö¿øAS86 Àº °£´ÜÇÑ ¸ÅÅ©·Îµµ Áö¿øÇÑ´Ù. ±×·¸Áö¸¸, ÀúÀÚ´Â ±×¿¡´ëÇÑ ¹®¼´Â ãÁö ¸øÇÏ¿´´Ù. AS86ÀÇ ¼Ò½º´Â ¸Å¿ì straightforward ÇÏ°Ô ¾²¿´À¸¹Ç·Î, ¿©·¯ºÐÀÌ ¿øÇÑ´Ù¸é, ¼Ò½º¸¦ »ìÆ캸°í, ¿øÇÏ´Â ºÎºÐÀ» ½±°Ô ÀÌÇØÇÒ ¼ö ÀÖÀ» °ÍÀÌ´Ù. ¿©·¯ºÐÀÌ ´Ü¼øÇÑ ¸ÅÅ©·Î ÀÌ»óÀÇ ´õ ¸¹Àº °ÍÀ» ¿øÇÑ´Ù¸é ¿ÜºÎÀÇ ÇÊÅÍ (µÚ¿¡¼ ¼³¸íÇÑ´Ù)¸¦ ÀÌ¿ëÇÒ ¼öµµ ÀÖ´Ù. 3.4.5. ¸¸¾à ÀÌ »õ·Î¿î ¹öÁ¯À» ÀÌ¿ëÇؼ ¸®´ª½º¸¦ ´õÀÌ»ó ÄÄÆÄÀÏ ÇÒ ¼ö ¾ø´Ù¸é ¾î¶»°Ô ÇØ¾ß Çϴ°¡ : What if I can't compile Linux anymore with this new version?Linus ´Â ½ñ¾ÆÁö´Â ¸ÞÀÏ´õ¹Ì¿¡ ÆĹ¯Çô :) ÀÖ´Ù. ±×¸®°í, HJLu (bin86 ÀÇ °ø½ÄÀû À¯Áö/º¸¼öÀÚ) °¡ as86 ÀÇ as86 ÀÇ ÃֽŠ¹öÁ¯À» »ç¿ëÇÑ ÄÚµåÀÇ Àç ±¸Ãà º¸´Ù ±¸¹öÁ¯ÀÇ ÇØÅ·À» ¼±ÅÃÇ߱⠶§¹®¿¡ ÀúÀÚ°¡ as86 ¿¡ ¸®´ª½º¸¦ ÄÄÆÄÀÏ ÇÒ ¼ö ÀÖµµ·Ï ÇÑ ÆÐÄ¡°¡ Á¦´ë·Î ¹Þ¾Æµé¿©ÁöÁö ¾Ê¾Ò´Ù°í »ý°¢ÇÑ´Ù. (¿ªÀÚÁÖ : ¹ø¿ªÀÌ ÀÌ»óÇؼ ¿ø¹®À» ½Æ½À´Ï´Ù) Linus is buried alive in mail, and since HJLu (official bin86 maintainer) chose to write hacks around an obsolete version of as86 instead of building clean code around the latest version, I don't think my patch for compiling Linux with a modern as86 has any chance to be accepted if resubmitted. ±×·¯³ª, º° ¹®Á¦ ¾ø´Ù. bin86 ÆÐÅ°Áö¿¡¼ as86 À» /usr/bin/ ¿¡ ±×´ë·Î ³öµÎ°í, bcc °¡ ÃÖ½ÅÀÇ as86 À» /usr/local/libexec/i386/bcc/as ·Î ÀνºÅçÇϵµ·Ï ÇØ ÁÖ¸é µÈ´Ù. ¿©·¯ºÐÀº ¸í½ÃÀûÀ¸·Î /ÁÁÀº/ ¹öÁ¯ÀÇ as86 À» È£ÃâÇÒ ÇÊ¿ä´Â ¾ø´Ù. Á¦´ë·Î µÈ ¿É¼Ç°ú ÇÔ²² È£ÃâµÇ¸é, bcc °¡ ¸ðµç°ÍÀ» Á¦´ë·Î Á¶Á¤ÇØ Áֱ⠶§¹®ÀÌ´Ù. ¸®´ª½ºÀÇ a.out Æ÷¸ËÀ¸·ÎÀÇ º¯È¯±îÁö Æ÷ÇÔÇؼ ¸»ÀÌ´Ù. ±×·¡¼, ÆÄÀÏÀ» as86 À» ¹Ù·Î »ç¿ëÇÏÁö ¸»°í, bcc ¸¦ ÇÁ·ÐÆ®¿£µå·Î ÀÌ¿ëÇؼ ¾î¼ÀºíÇ϶ó. Now, this shouldn't matter: just keep your as86 from the bin86 package in /usr/bin/, and let bcc install the good as86 as /usr/local/libexec/i386/bcc/as where it should be. You never need explicitly call this "good" as86, because bcc does everything right, including conversion to Linux a.out, when invoked with the right options; so assemble files exclusively with bcc as a frontend, not directly with as86. Áö±ÝÀº gas µµ 16ºñÆ® Äڵ嵵 Áö¿øÇÏ°í, NASM µµ ±×·¸°Ô ÇÒ ¸ð¾çÀ̹ǷÎ, ¸®´ª½º´Â AS86 ÀÇ ±×´Ã¿¡¼ ¹þ¾î³¯ ¼ö ÀÖÀ» °ÍÀÌ´Ù. ´©°¡ ¾Ë¸®... Since GAS now supports 16-bit code, and NASM looks promising, maybe Linux will get rid of AS86, anyway? Who knows! 3.5. ´Ù¸¥ ¾î¼Àºí·¯µéÁö±ÝºÎÅÍ ¼Ò°³ÇÏ°íÀÚ ÇÏ´Â ¾î¼Àºí·¯µéÀº ÀϹÝÀûÀ¸·Î »ç¿ëÇÏ´Â °ÍÀÌ ¾Æ´Ñ ¾î¼Àºí·¯µéÀÌ´Ù. ¾Õ¼ ¾ð±ÞÇÑ ¾î¼Àºí·¯µéÀÌ ºÒ¸¸Á·½º·´´Ù¸é Áö±ÝºÎÅÍ ¼Ò°³ÇÏ´Â ¾î¼Àºí·¯µéÀ» »ç¿ëÇ϶ó. ±×·¯³ª ¾Õ¼ ¾ð±ÞÇÑ ¾î¼Àºí·¯µéÀÌ ºÒ¸¸Á·½º·¯¿ï ÀÌÀ¯°¡ ¾ø´Ù. :) ±×·¡¼ ÀúÀÚ´Â ¾Õ¼ÀÇ ¾î¼Àºí·¯µéÀ» »ç¿ëÇϱ⸦ ÃßõÇÏ´Â ¹ÙÀÌ´Ù. ÇÏÁö¸¸, ¿©·¯ºÐÀÌ °³¹ßÇÏ´Â ¼ÒÇÁÆ®¿þ¾î¿¡ »ç¿ëÇÏ´Â ¾î¼Àºí·¯¸¦ ÀÏ·üÀûÀ¸·Î °°Àº °ÍÀ¸·Î ÇÒ ÇÊ¿ä´Â ¾ø´Ù. 3.5.1. Win32Forth ¾î¼Àºí·¯Win32Forth ´Â free 32-bit ANS FORTH system ÀÌ´Ù. Win32 ȯ°æ, Áï, À©95, À©NT µî¿¡¼ ¼º°øÀûÀ¸·Î »ç¿ëÇÒ ¼ö ÀÖ´Â ¾î¼Àºí·¯ÀÌ´Ù. ÀÌ ¾î¼Àºí·¯´Â reflective FORTH language ¿¡ Æ÷ÇԵǾî ÀÖ´Â °ø°³ 32ºñÆ® ¾î¼Àºí·¯ÀÌ´Ù. (¹®¹ýÀº prefix ³ª postfix ¸ðµÎ¸¦ Áö¿øÇÑ´Ù) ¸ÅÅ©·Î ÇÁ·Î¼¼½Ìµµ reflective language FORTH ÀÇ ´É·Â ÇÏ¿¡¼ ¼º°øÀûÀ¸·Î Àß Áö¿øµÈ´Ù. ±×·¯³ª, ´ÜÁ¡ÀÌ ÀÖ´Ù¸é, Áö¿øµÇ´Â ÀÔ.Ãâ·Â ³»¿ëÀÌ Win32Forth ¿¡¼¸¸ »ç¿ëÇÒ ¼ö ÀÖ´Ù´Â °ÍÀÌ´Ù. (.obj ÆÄÀÏ·ÎÀÇ ´ýÇÁ´Â ¾ø´Ù. ±×·¯³ª ¿©·¯ºÐÀÌ ÇÊ¿äÇÏ´Ù¸é ±×·¯ÇÑ ±â´ÉÀ» Ãß°¡ÇÒ ¼ö ÀÖ´Ù) ÀÌ ¾î¼Àºí·¯¸¦ ãÀ» ¼ö ÀÖ´Â Àå¼Ò´Â ´ÙÀ½°ú °°´Ù : ftp://ftp.forth.org/pub/Forth/Compilers/native/windows/Win32For/. Win32Forth is a free 32-bit ANS FORTH system that successfully runs under Win32s, Win95, Win/NT. It includes a free 32-bit assembler (either prefix or postfix syntax) integrated into the reflective FORTH language. Macro processing is done with the full power of the reflective language FORTH; however, the only supported input and output contexts is Win32For itself (no dumping of .obj file, but you could add that feature yourself, of course). Find it at ftp://ftp.forth.org/pub/Forth/Compilers/native/windows/Win32For/. 3.5.2. TDASMTDASM (the Table Driven Assembler) Àº ¾î¶² ¾î¼Àºí¸® ¾ð¾î·Îµµ Æ÷ÆÃÀÌ °¡´ÉÇÑ °ø°³ ¾î¼Àºí·¯ÀÌ´Ù. ÀÌ ¾î¼Àºí·¯´Â Ÿ°ÙÀÌ µÇ´Â ¸¶ÀÌÅ©·ÎÇÁ·Î¼¼¼°¡ ¹«¾ùÀÌµç °£¿¡ ±×¿¡ ÇØ´çÇÏ´Â ÄÄÆÄÀÏ ÀÛ¾÷À» Á¤ÀÇÇÏ´Â Å×À̺íÀ» ÀÌ¿ëÇÏ¿©¼ ÇØ´ç ¸¶ÀÌÅ©·ÎÇÁ·Î¼¼¼ÀÇ ÄÄÆÄÀÏ·¯·Î »ç¿ëÀÌ °¡´ÉÇÑ ¾î¼Àºí·¯ÀÌ´Ù. The Table Driven Assembler (TDASM) is a free portable cross assembler for any kind of assembly language. It should be possible to use it as a compiler to any target microprocessor using a table that defines the compilation process. ±¸ÇÒ ¼ö ÀÖ´Â Àå¼Ò´Â http://www.penguin.cz/~niki/tdasm/ ÀÌ´Ù. 3.5.3. TerseTerse ´Â x86 °è¿À» À§ÇÑ °¡Àå ÄÄÆÑÆ®ÇÑ ¾î¼Àºí·¯ ¹®¹ýÀ» °¡Áö°í ÀÖ´Â ÇÁ·Î±×·¡¹Ö ÅøÀÌ´Ù. ÇÏÁö¸¸, ÀÌ ¾î¼Àºí·¯´Â evil proprietary software ÀÌ´Ù (¿ªÀÚÁÖ:¸¶¶¥ÇÑ ¸»À» ¸øã¾Ò½À´Ï´Ù) ÀÌ ¾î¼Àºí·¯ÀÇ °ø°³ Ŭ·ÐÀ» ¸¸µå´Â ÇÁ·ÎÁ§Æ®°¡ ÀÖ¾ú´Ù°í´Â Çϴµ¥, Áö±ÝÀº ´õÀÌ»ó °³¹ßµÇÁö ¾Ê´Â °ÍÀ¸·Î ÇÊÀÚ´Â ¾Ë°í ÀÖ´Ù. ¸¸¾à ¿©·¯ºÐÀÌ terse ¿Í ºñ½ÁÇÑ ¹®¹ýÀ» °¡Áø ¾î¼Àºí·¯¸¦ ã´Â´Ù¸é, NASM ÀÇ ÇÁ·ÐÆ®¿£µå·Î ±× ¹®¹ýÀ» °³¹ßÇÏ¸é µÉ °ÍÀÌ´Ù. °ü½ÉÀÖ´Ù¸é, comp.compilers ¿¡¼ ¿ª»çÀûÀÎ ÅäÀǵé(?)À» ÈȾ ¼ö ÀÖÀ» °ÍÀÌ´Ù. 1999/07/11 19:36:51, the moderator wrote: 3.5.4. HLAHLA ´Â High Level Assembly language ÀÇ ¾àÀÚÀÌ´Ù. ÀÌ ¾î¼Àºí·¯´Â º¯¼ö ¼±¾ðÀ̳ª ÇÔ¼ö ¼±¾ð, ÇÔ¼ö È£Ãâ°ú °°Àº ºÎºÐ¿¡¼ ÆĽºÄ®À̳ª C/C++ °ú °°Àº °í±Þ¾ð¾î¿Í ¸Å¿ì ºñ½ÁÇÑ ¹®¹ýÀ» »ç¿ëÇÑ´Ù. ±×¸®°í ÀÌ ¾î¼Àºí·¯´Â Ç¥ÁØ ¸Ó½Å ÀνºÆ®·°¼ÇÀ» À§ÇÑ ¼öÁ¤µÈ ¾î¼Àºí¸® ¾ð¾î ¹®¹ýÀ» »ç¿ëÇÑ´Ù. ¶ÇÇÑ if, while, repeat, until µî°ú °°Àº °í±Þ¾ð¾î¿¡¼ Á¦°øÇÏ´Â Á¦¾î ±¸Á¶¸¦ °¡Áø´Ù. HLA ´Â free ÀÌÁö¸¸, Win32 ȯ°æ¿¡¼¸¸ µ¿ÀÛÇÑ´Ù. HLA ´Â MASM ¿ëÀÇ Äڵ带 »ý»êÇϱ⠶§¹®¿¡ ¸ñÀûÆÄÀÏÀ» »ý¼ºÇϱâ À§ÇÑ ÃÖÁ¾ ¾î¼Àºí¸µ°ú ¸µÅ·À» À§ÇØ ¿©·¯ºÐÀº MASM °ú MS-link ÀÇ 32ºñÆ® ¹öÁ¯ÀÌ ÇÊ¿äÇÏ´Ù. ±×·¯³ª, HLA ÀÇ MASM ¹öÁ¯ÀÇ Ãâ·ÂÀ» TASM ¿¡¼ ÄÄÆÄÀÏ µÉ ¼ö ÀÖµµ·Ï º¯È¯ÇØÁÖ´Â m2t Æ÷½ºÆ® ÇÁ·Î¼¼¼ ÇÁ·Î±×·¥µµ µû¶ó¿Â´Ù. ºÒÇàÈ÷µµ, NASM Àº Áö¿øµÇÁö ¾Ê´Â´Ù. 3.5.5. TALCTALC ´Â ¶Ç´Ù¸¥ MASM/Win32 ±â¹ÝÀÇ °ø°³ ÄÄÆÄÀÏ·¯ÀÌ´Ù. (±×·³¿¡µµ ºÒ±¸ÇÏ°í, ELF Çü½ÄÀÇ Ãâ·Âµµ Áö¿øÇÏ´Â °Í °°´Ù) TAL Àº Typed Assembly Language ÀÇ ¾àÀÚÀÌ´Ù. (¿ªÀÚÁÖ:Á¤¸».. ¾Æ·¡ÀÇ ¹®ÀåµéÀº Àü¹®ÀûÀÎ ¿ë¾î¶ó.. ¹ø¿ªÀÌ Èûµé±º¿ä.. ´©±º°¡ ¹ø¿ªÇØÁÖ½Ç ºÐÀº... ªÀ¸´Ï±î Àú¿¡°Ô ¸ÞÀÏ ÁֽʽÿÀ. ¹Ý¿µÇÏ°Ú½À´Ï´Ù) It extends traditional untyped assembly languages with typing annotations, memory management primitives, and a sound set of typing rules, to guarantee the memory safety, control flow safety,and type safety of TAL programs. Moreover, the typing constructs are expressive enough to encode most source language programming features including records and structures, arrays, higher-order and polymorphic functions, exceptions, abstract data types, subtyping, and modules. Just as importantly, TAL is flexible enough to admit many low-level compiler optimizations. Consequently, TAL is an ideal target platform for type-directed compilers that want to produce verifiably safe code for use in secure mobile code applications or extensible operating system kernels. 3.5.6. x86 ¿ëÀÇ ÇÁ¸®°¡ ¾Æ´Ï°Å³ª 32ºñÆ®°¡ ¾Æ´Ñ ¾î¼Àºí·¯µé¿©·¯ºÐÀº Raymond Moon's x86 assembly FAQ ¿¡¼ x86 ¾î¼Àºí¸® ÇÁ·Î±×·¡¹ÖÀÇ ±âÃÊÀûÀÎ Áö½Ä°ú ÇÔ²² ±×·¯ÇÑ ¾î¼Àºí¸®¿¡ ´ëÇØ º¸´Ù ¸¹Àº ÀÚ·áµéÀ» ãÀ» ¼ö ÀÖ´Ù. Note : ¸ðµç µµ½º ±â¹ÝÀÇ ¾î¼Àºí·¯µéÀº ¸®´ª½ºÀÇ DOS ¿¡¹Ä·¹ÀÌÅ͸¦ ÅëÇؼ »ç¿ëµÇ¾î¾ß ÇÑ´Ù. ÃÖ±ÙÀÇ µµ½º ±â¹ÝÀÇ ¾î¼Àºí·¯µéÀº GNU BFD ¶óÀ̺귯¸®¿¡¼ Áö¿øÇÏ´Â COFF ³ª ´Ù¸¥ ¸ñÀû ÆÄÀÏ Æ÷¸ËµéÀ» Áö¿øÇϱ⠶§¹®¿¡ ¿©·¯ºÐÀº ±×·¯ÇÑ ¾î¼Àºí·¯µéÀ» ´Ù¸¥ °ø°³ÀÇ 32ºñÆ® Åøµé°ú ÇÔ²² »ç¿ëÇÒ ¼öµµ ÀÖÀ» °ÍÀÌ´Ù. ¾Æ¸¶µµ GNU objcopy(binutils ÆÐÅ°Áö¿¡ ÀÖ´Ù) ¸¦ º¯È¯¿ë ÇÊÅÍ·Î ÀÌ¿ëÇÒ ¼öµµ ÀÖÀ» °ÍÀÌ´Ù. 4장. ¸ÞŸÇÁ·Î±×·¡¹Ö¾î¼Àºí¸® ÇÁ·Î±×·¡¹ÖÀº Áö·çÇÑ ÀÛ¾÷ÀÌ´Ù. ±×·¯³ª, ±×·¸´Ù°í °áÁ¤ÀûÀÎ ºÎºÐ¿¡¼ ¾î¼Àºí¸®¸¦ »ç¿ëÇÏÁö ¾ÊÀ»¼ö´Â ¾ø´Ù. ¿©·¯ºÐÀº Á¦´ë·Î ÀÛ¾÷À» ¼öÇàÇϱâ À§Çؼ ÀûÀýÇÑ ÅøÀ» »ç¿ëÇØ¾ß ÇÒ °ÍÀÌ´Ù.... ´Ù½Ã ¸»ÇÏÀÚ¸é, ¾î¼Àºí¸® ¾ð¾î°¡ ¹Ýµå½Ã ÇÊ¿äÇÏÁö ¾Ê´Ù¸é ¾î¼Àºí¸®¸¦ »ç¿ëÇؼ´Â ¾ÈµÈ´Ù. ´ë½Å, C, OCaml, perl, Scheme, µîÀÇ °í±Þ¾ð¾î¸¦ »ç¿ëÇÏ´Â °ÍÀÌ ´ë°³ÀÇ °æ¿ì ´õ ³ªÀº ¼±ÅÃÀÌ µÉ °ÍÀÌ´Ù. ±×·¯³ª, ¾Õ¼ ¾ð±ÞÇÑ °í±Þ ÇÁ·Î±×·¡¹Ö ¾ð¾î°¡ ±â°è ÀÚü¸¦ ¸¸Á·ÇÒ ¸¸ÇÑ ¼öÁØÀ¸·Î ÄÁÆ®·Ñ ÇÒ ¼ö ÀÖ´Â ±â´ÉÀ» Á¦°øÇÏÁö ¸øÇÏ´Â °æ¿ì°¡ ÀÖ´Ù. ´Ù½Ã ¸»Çؼ, ±×·¯ÇÑ ¾ð¾î°¡ Á¦°øÇÏ´Â ¸Ó½Å¿¡ ´ëÇÑ Á¦¾î±â´É º¸´Ù ´õ ¼¼¹ÐÇÏ°Ô Çϵå¿þ¾î¸¦ ÄÁÆ®·Ñ ÇØ¾ß ÇÏ´Â °æ¿ì¿¡ ¾î¼Àºí¸®°¡ À¯¿ëÇϰųª, ÇÊ¿äÇÒ °ÍÀÌ´Ù. ±×·¯ÇÑ °æ¿ì, ¿©·¯ºÐÀº ¸ÅÅ©·Î ÇÁ·Î¼¼½ÌÀ̳ª ¸ÞŸ ÇÁ·Î±×·¡¹Ö ÅøÀ» À¯¿ëÇÏ°Ô ¾µ ¼ö ÀÖ´Ù. ±×·¯ÇÑ ÅøÀ» »ç¿ëÇϸé, ¿©·¯ºÐÀº ÆÐÅÏÀ» ÀÌ¿ëÇÑ ÇÁ·Î±×·¡¹ÖÀ» ÇÒ ¼ö ÀÖ°Ô µÈ´Ù. ´Ù½Ã ¸»Çؼ, ÇÑ ÆÐÅÏ¿¡ ´ëÇÑ Á¤ÀǸ¦ ³»·Á µÎ¸é, ±×°ÍÀ» ÀÌ¿ëÇÏ¿© ¾ÈÀüÇÏ°Ô, ¶Ç Àç»ç¿ë °¡´ÉÇÏ°Ô ¸ÅÅ©·Î ó·³ »ç¿ëÇÏ¿© ÇÁ·Î±×·¡¹ÖÀ» ÇÒ ¼ö ÀÖ°Ô µÇ´Â °ÍÀÌ´Ù. ±×·¯ÇÑ ¹æ½ÄÀ¸·Î ÇÁ·Î±×·¡¹ÖÀ» ÇÑ´Ù¸é, ¿©·¯ºÐÀÌ ¸¸µç ÄÚµå´Â º¸´Ù ¾ÈÀüÇϸç, ¼öÁ¤ÇÒ ¶§¿¡µµ ÆÐÅÏÀÇ Á¤ÀǸ¸ ¹Ù²ãÁÖ¸é ÀÚµ¿À¸·Î ¼öÁ¤µÈ ¹öÁ¯ÀÇ ¼Ò½º°¡ ´Ù½Ã »ý¼ºµÇ°Ô ÇÏ´Â µîÀÇ ¿©·¯°¡Áö ÀÕÁ¡ÀÌ ÀÖ´Ù. ÀϹÝÀûÀ¸·Î »ç¿ëÇÏ´Â ¾î¼Àºí·¯¸¸ °¡Áö°í´Â ½ÉÁö¾î ÀÛÀº ·çƾÀ» C ¿Í ¿¬°áÇÏ·Á°í ÇÒ ¶§¿¡µµ ÀÌ¿Í°°ÀÌ º¹ÀâÇÑ ±â´ÉÀ» ¼öÇàÇÒ ¼ö ¾ø´Ù. 4.1. ¿ÜºÎ ÇÊÅ͵鿩·¯ºÐÀÌ Áñ°Ü »ç¿ëÇÏ´Â ¾î¼Àºí·¯¿¡¼ Áö¿øÇÏ´Â ¸ÅÅ©·Î°¡ ¹«¾ùÀ̵ç, ¿©·¯ºÐÀÌ ÁÖ·Î »ç¿ëÇÏ´Â ¾ð¾î°¡ ¹«¾ùÀ̵çÁö°£¿¡ (½ÉÁöÀÇ C ÀÏ °æ¿ì¿¡µµ) ±× ¾ð¾î°¡ ¿©·¯ºÐÀÌ »ý°¢Çϱ⿡ ÃæºÐÈ÷ expressive(¸ðµç °ÍÀ» Ç¥ÇöÇÒ ¼ö ÀÖ´Â) ÇÏÁö ¾Ê´Ù¸é, ¿©·¯ºÐÀº ¿©·¯ºÐÀÇ ¼Ò½º ÆÄÀÏÀ» ¿ÜºÎÀÇ ÇÊÅ͸¦ Åë°úÇؼ Àç»ý¼º(?)µÇ°Ô ÇÒ ¼ö ÀÖÀ¸¸ç, Makefile ¿¡¼ ´ÙÀ½¿¡ º¸¿©Áö´Â °Í°ú °°Àº °£´ÜÇÑ ±ÔÄ¢¸¸ Ãß°¡ ÇÔÀ¸·Î¼ ±×·¸°Ô ÇÒ ¼ö ÀÖ´Ù.
4.1.1. CPPCPP ´Â ½ÇÀº ±×¸® Ç¥ÇöÀûÀÌÁö ¸øÇÏ´Ù(is truly not very expressive), ÇÏÁö¸¸, °£´ÜÇÑ ÀÏÀ» Çϱâ À§Çؼ´Â CPP ·Îµµ ÃæºÐÇÏ´Ù. CPP ´Â Ç¥ÁØÀ̸ç, GCC ¿¡ ÀÇÇؼ Åõ¸íÇÏ°Ô È£ÃâµÇ¾îÁø´Ù. CPP ÀÇ ÇÑ°è¿¡ ´ëÇÑ ¿¹¸¦ µéÀÚ¸é, ¿©·¯ºÐÀº ¿©·¯ºÐÀÇ °´Ã¼°¡ ¼±¾ðµÇ¾î¼, »ç¿ëÇÒ ¶§, ±× °´Ã¼°¡ À¯È¿ÇÑ ºÎºÐÀÇ ¸¶Áö¸·¿¡ ÀÚµ¿À¸·Î ¼Ò¸êÀÚ(destructor) °¡ È£ÃâµÇ°Ô ÇÏ´Â ±â´ÉÀ» ±¸ÇöÇÒ ¼ö´Â ¾ø´Ù. As an example of its limitations, you can't declare objects so that destructors are automatically called at the end of the declaring block; you don't have diversions or scoping, etc. CPP ´Â ´ëºÎºÐÀÇ C ÄÄÆÄÀÏ·¯ ÆÐÅ°Áöµé¿¡ Æ÷ÇԵǾî ÀÖ´Ù. ±×·¯³ª, Ưº°È÷ ¶Ù¾î³ª°Å³ª ÇÏÁöµµ ¾Ê´Ù. 4.1.2. M4M4 ´Â ¿©·¯ºÐ¿¡°Ô ¸Å¿ì ÈǸ¢ÇÏ°í, °·ÂÇÑ ¸ÅÅ©·Î ÇÁ·Î¼¼½Ì µµ±¸°¡ µÇ¾î ÁÙ °ÍÀÌ´Ù. °Ô´Ù°¡ Turing °ú °°Àº ¾ð¾î¸¦ Áö¿øÇÏ°í, Àç±Í, Á¤±Ô Ç¥Çö½Ä µîµµ Áö¿øÇÑ´Ù. ¿©·¯ºÐÀº CPP ·Î ÇÏÁö ¸øÇß´ø ¸ðµç °ÍÀ» M4 ¸¦ °¡Áö°í ÇÒ ¼ö ÀÖ°Ô µÉ °ÍÀÌ´Ù. M4 gives you the full power of macroprocessing, with a Turing equivalent language, recursion, regular expressions, etc. You can do with it everything that CPP cannot. m4 ¸¦ »ç¿ëÇÑ ¸ÅÅ©·Î ÇÁ·Î±×·¡¹ÖÀÇ ¿¹Á¦¸¦ ±¸Çϱ⸦ ¿øÇÑ´Ù¸é, macro4th (this4th - ftp://ftp.forth.org/pub/Forth/Compilers/native/unix/this4th.tar.gz) ³ª the Tunes 0.0.0.25 sources(ftp://ftp.tunes.org/pub/tunes/obsolete/dist/tunes.0.0.0/tunes.0.0.0.25.src.zip) À» ÂüÁ¶Çϱ⠹ٶõ´Ù. ±×·¯³ª, However, its disfunctional quoting and unquoting semantics force you to use explicit continuation-passing tail-recursive macro style if you want to do advanced macro programming (which is remindful of TeX -- BTW, has anyone tried to use TeX as a macroprocessor for anything else than typesetting ?). This is NOT worse than CPP that does not allow quoting and recursion anyway. ±¸ÇØ¾ß ÇÒ M4 ÀÇ ¹öÁ¯Àº GNU m4 1.4 ȤÀº ±× ÀÌ»óÀÇ ¹öÁ¯ÀÌ´Ù. °¡Àå ¸¹Àº ±â´É°ú °¡Àå ÀûÀº ¹ö±× ȤÀº Á¦ÇÑÀ» °¡Áö°í ÀÖ´Â ¹öÁ¯À̱⠶§¹®ÀÌ´Ù. m4 ´Â ¼È°èµÉ ¶§, °£ÆíÇÑ »ç¿ëÀ» ¸ñÀûÀ¸·Î ¼³°èµÇ°í, ºü¸¥ ¼Óµµ¸¦ ¸ñÇ¥·Î Çؼ ¼³°èµÇÁö ¾Ê¾Ò±â ¶§¹®¿¡, ¹«¾ùÀ» ÇϵçÁö Á».. ´À¸®´Ù. ±×·¯³ª, ¾î¼Àºí¸® ÇÁ·Î±×·¥À» ¸¸µé¶§¿¡´Â º° ¹®Á¦°¡ µÇÁö ¾Ê´Â´Ù. ¾î¼Àºí¸®·Î ¸î¹é¸¸ ¶óÀÎÀ̳ª µÇ´Â ¾çÀ» ÄÚµùÇÒ °ÍÀΰ¡? ±×·¸Áö ¾Ê´Ù. 4.1.3. ¿©·¯ºÐÀÌ ¸¸µç ÇÊÅ͸¦ ÀÌ¿ëÇÑ ¸ÅÅ©·Î ÇÁ·Î¼¼½Ì¿©·¯ºÐÀº perl À̳ª awk, sed µîÀ» °¡Áö°íµµ ¿©·¯ºÐ ÀÚ½ÅÀÇ °£´ÜÇÑ ¸ÅÅ©·Î È®Àå ÇÊÅ͸¦ ¸¸µé ¼ö ÀÖ´Ù. ¿ÀÈ÷·Á °£´ÜÇÑ °ÍÀº ÀÌ·¯ÇÑ ÅøÀ» °¡Áö°í ¸¸µå´Â °ÍÀÌ ´õ ³ªÀ»Áöµµ ¸ð¸¥´Ù. ±×·¯³ª. ¸ÅÅ©·Î ÇÁ·Î¼¼½ÌÀ̶õ ¸»Àº "the hard way(Á» ´õ Èûµç ¹æ¹ý?)" ¶ó´Â ´µ¾Ó½º¸¦ dz±ä´Ù. You can write your own simple macro-expansion filter with the usual tools: perl, awk, sed, etc. It can be made rather quickly, and you control everything. But, of course, power in macroprocessing implies "the hard way". 4.2. ¸ÞŸÇÁ·Î±×·¡¹Ö¸ÅÅ©·Î¸¦ È®Àå½ÃÄÑ ÁÖ´Â ¿ÜºÎÇÊÅ͸¦ »ç¿ëÇÏ´Â ´ë½Å »ç¿ëÇÒ ¼ö ÀÖ´Â ¶Ç´Ù¸¥ ¹æ¹ýÀÌ Àִµ¥, ±×°ÍÀº ¿©·¯ºÐÀÇ ÇÁ·Î±×·¥ÀÇ ÀϺΠȤÀº Àüü¸¦ ¸¸µé¾îÁÖ´Â ÇÁ·Î±×·¥À» Â¥´Â °ÍÀÌ´Ù. ¹«½¼ ¸»Àΰí ÇÏ´Ï, ¿¹¸¦ µé¾î ¼³¸íÇØ º¸¸é, ¿©·¯ºÐÀº ¼Ò½º Äڵ带 Ãâ·ÂÇØÁÖ´Â ÇÁ·Î±×·¥À» »ç¿ëÇÒ ¼öµµ ÀÖ´Ù. ±×·¯ÇÑ ÇÁ·Î±×·¥ÀÇ ¿¹¸¦ µéÀÚ¸é,
±×·¯ÇÑ ÇÁ·Î±×·¥µéÀ» Çѹø °í·ÁÇØ º¸¶ó! 4.2.1. ÄÄÆÄÀÏ·¯ÀÇ ¹é¿£µå·Î Á¦°øµÇ´Â ¾î¼Àºí·¯ÀÇ ÀÌ¿ëGCC, SML/NJ, Objective CALM, MIT-Scheme, CMUCL µî°ú °°Àº ÄÄÆÄÀÏ·¯µéÀº °íÀ¯ÀÇ ¾î¼Àºí·¯ ¹é¿£µå¸¦ °®Ãß°í ÀÖ´Ù. ¿©·¯ºÐÀº ÀÌ·¯ÇÑ ¹é¿£µå¸¦ ÀÌ¿ëÇؼ ¾î¼Àºí¸® Äڵ带 ¾òÀ» ¼ö ÀÖ´Ù. ¿©·¯ºÐÀÌ »ç¿ëÇÏ´Â ¾ð¾î¸¦ ÀÌ¿ëÇؼ ¸¸µç ÇÁ·Î±×·¥À» ¾Õ¼ ¾ð±ÞÇÑ ÄÄÆÄÀÏ·¯·Î ÄÄÆÄÀÏÇؼ ÈǸ¢ÇÑ ¾î¼Àºí¸® Äڵ带 ¾òÀ» ¼ö ÀÖ°í, ±× Äڵ带 ¿©·¯ºÐÀÌ ´õ ³´°Ô ¼öÁ¤Çؼ ¸¶À½¿¡ µå´Â ¾î¼Àºí¸® Äڵ带 ¾òÀ» ¼ö ÀÖ´Ù. 4.2.2. ´ºÀúÁö ¸Ó½Å-ÄÚµå ÅøŶÇÁ·Î±×·¡¹Ö ¾ð¾î¶ó´Â ¾ÆÀÌÄÜÀ» »ç¿ëÇؼ ±â°è¾î¸¦ ´Ù·ç´Â ÅøŶÀÇ °³¹ß°ú °ü·ÃµÈ ÇÁ·ÎÁ§Æ®°¡ ÀÖ´Ù(½ÇÇèÀûÀÎ ML ¹öÁ¯µµ Á¦°øÇÑ´Ù) http://www.eecs.harvard.edu/~nr/toolkit/À» Çѹø µÑ·¯º¸¶ó 4.2.3. TUNES ÇÁ·ÎÁ§Æ®Free Reflective Computing System À» À§ÇÑ TUNES Project(http://www.tunes.org) ¿¡¼µµ ÀÚüÀûÀÎ ¾î¼Àºí·¯¸¦ Scheme ¾ð¾îÀÇ È®ÀåÀ¸·Î °³¹ßÇÏ°í ÀÖ´Ù. ¾ÆÁ÷ Á¦´ë·Î ½ÇÇàµÇ´Â °ÍÀº ¾Æ´ÏÁö¸¸ ¸»ÀÌ´Ù. tunes ÇÁ·ÎÁ§Æ®¿¡¼ °³¹ßÁßÀÎ ¾î¼Àºí·¯´Â abstract syntax Æ®¸®¸¦ ´Ù·ç´Âµ¥, ±×·¸°Ô ÇÏ¿©, µð½º¾î¼Àºí·¯·Îµµ, ¾î¼Àºí·¯ ¹®¹ý ¹ø¿ª±â·Îµµ, ÄÄÆÄÀÏ·¯³ª ¾î¼Àºí·¯µéÀÇ °øÅëÀûÀÎ ¹é¿£µå·Îµµ »ç¿ëÇÒ ¼ö ÀÖµµ·Ï ÇÏ°í ÀÖ´Ù. ¶ÇÇÑ, Scheme À̶ó´Â ¾ð¾îÀÇ °·ÂÇÔÀº ¸ÅÅ©·Î ÇÁ·Î¼¼½ÌÀ̳ª ¸ÞŸ ÇÁ·Î±×·¡¹Öó·³ µµÀüÇÒ ¸¸ÇÑ ºÐ¾ßÀÌ´Ù.(?) The assembler manipulates abstract syntax trees, so it could equally serve as the basis for a assembly syntax translator, a disassembler, a common assembler/compiler back-end, etc. Also, the full power of a real language, Scheme, make it unchallenged as for macroprocessing/metaprogramming. 5장. ÇÔ¼ö È£Ãâ ±ÔÄ¢5.1. Linux5.1.1. GCC ·ÎÀÇ ¸µÅ· : Linking to GCC¸¸¾à ¿©·¯ºÐÀÌ C ¿Í ¾î¼Àºí¸®°¡ È¥ÇÕµÈ ÇÁ·ÎÁ§Æ®¸¦ ¼öÇàÇÏ°í ÀÖ´Ù¸é, Áö±Ý ¼Ò°³ÇÏ°íÀÚ ÇÏ´Â ¹æ¹ýÀ» ÃßõÇÏ°íÀÚ ÇÑ´Ù. ¸®´ª½º Ä¿³Î¿¡¼ .S ÀÇ È®ÀåÀÚ¸¦ °¡Áø ÆÄÀϵé Áß¿¡¼, gas °¡ ó¸®ÇÏ´Â (as86 ÀÌ Ã³¸®ÇÏ´Â ÆÄÀÏÀÌ ¾Æ´Ô!) ÆÄÀϵéÀ» ÅëÇؼ À¯¿ëÇÑ ¿¹Á¦¸¦ ¹ß°ßÇÒ ¼ö ÀÖ´Ù. 32ºñÆ®ÀÇ argument µéÀº ½ºÅÿ¡ Ǫ½ÃµÉ ¶§, 32ºñÆ®ÀÇ ±Ù°Å¸® ¹Ýȯ ÁÖ¼Ò (32-bit near return address) ÀÇ ÀºÎºÐ¿¡ ¿ª¼øÀ¸·Î Ǫ½ÃµÇ¾îÁø´Ù. µû¶ó¼, ±×°ÍµéÀÌ pop µÉ ¶§¿¡´Â ¿Ã¹Ù¸¥ ¼ø¼·Î pop µÇ¾îÁø´Ù. %ebp, %esi, %edi, %ebx ·¹Áö½ºÅ͵éÀº ÇÇÈ£ÃâÀÚ°¡ ÀúÀåÇÏ°Ô µÇ°í, ´Ù¸¥ ·¹Áö½ºÅ͵éÀº È£ÃâÀÚ°¡ ÀúÀåÇÏ°Ô µÈ´Ù. %eax ´Â °á°ú°¡ 32ºñÆ® À϶§ °á°ú¸¦ ÀúÀåÇÏ´Â ¿ëµµ·Î »ç¿ëµÇ¾îÁö°í, ¸¸¾à, °á°ú°¡ 64ºñÆ®¶ó¸é, ±×¶§´Â %edx:%eax ·¹Áö½ºÅÍ ½ÖÀÌ °á°ú¸¦ ÀúÀåÇϴµ¥ »ç¿ëµÈ´Ù. FP stack ¿¡ ´ëÇؼ´Â È®½ÇÇØ Àß ¸ð¸£°ÚÁö¸¸, ÀúÀÚ´Â °á°ú°¡ st(0) ¿¡ ÀúÀåµÇ°í, ½ºÅà Àüü°¡ È£ÃâÀÚ°¡ ÀúÀåÇÏ´Â ¿ëµµ·Î ¾²ÀÎ´Ù°í »ý°¢ÇÑ´Ù. GCC °¡ ·¹Áö½ºÅ͵éÀÇ ¿ëµµ¸¦ ¹Ì¸® ÁöÁ¤Çؼ À§¿¡¼ ¼³¸íÇÑ È£Ãâ ±ÔÄ¢À» ¼öÁ¤ÇÏ´Â ¿É¼ÇÀ» °¡Áö°í ÀÖ´Ù´Â °ÍÀ» ÀØÁö ¾Êµµ·Ï Ç϶ó. ÀÚ¼¼ÇÑ ³»¿ëÀº i386 .info ÆäÀÌÁö¸¦ ÂüÁ¶Ç϶ó. ¿©·¯ºÐÀº GCC ÀÇ Ç¥ÁØ ÇÔ¼ö È£Ãâ ±ÔÄ¢À» µû¸£´Â ÇÔ¼ö¸¦ À§Çؼ cdecl À̳ª regparm(0) attribute ¸¦ ¼±¾ðÇؾ߸¸ ÇÑ´Ù´Â °ÍÀ» ±â¾ïÇ϶ó. GCC info ÆäÀÌÁöÀÇ C Extensions::Extended Asm:: ¼½¼ÇÀ» ÂüÁ¶Ç϶ó. ¶ÇÇÑ, Linux °¡ asmlinkage ¸ÅÅ©·Î¸¦ ¾î¶»°Ô Á¤ÀÇÇÏ°í ÀÖ´ÂÁöµµ ÂüÁ¶Ç϶ó. 5.1.2. ELF ¿Í a.out ¹®Á¦¸î¸î C ÄÄÆÄÀÏ·¯µéÀº ¹ØÁÙ ¹®ÀÚ¸¦ ´Ù¸¥ ½Éº¼µé º¸´Ù ¸ÕÀú È®ÀåÇÑ´Ù. ´Ù¸¥ ÄÄÆÄÀÏ·¯´Â ±×·¸°Ô ÇÏÁö ¾ÊÁö¸¸ (¿ªÀÚ ÁÖ : ¿ø¹®ÀÇ ³»¿ëÀº Some C compilers prepend an underscore before every symbol, while others do not. ÀÔ´Ï´Ù) Linux ÀÇ a.out GCC ´Â ±×·¯ÇÑ È®ÀåÀ» ÇÑ´Ù. ±×·¸Áö¸¸, ELF GCC ´Â ÇÏÁö ¾Ê´Â´Ù. ¿©·¯ºÐÀÌ ±×·¯ÇÑ Æ¯¼ºÀ» ±Øº¹ÇÒ ÇÊ¿ä°¡ ÀÖ´Ù¸é, ÇöÁ¸ÇÏ´Â ÆÐÅ°ÁöµéÀº ¾î¶»°Ô ÇÏ´ÂÁö¸¦ ÂüÁ¶Ç϶ó. ¿¹¸¦ µé¾î, ¿À·¡µÈ ¸®´ª½ºÀÇ ¼Ò½ºÆ®¸®³ª, ȤÀº Elk, qthreads, OCaml µî°ú °°Àº ÆÐÅ°Áö¸¦ ±¸Çؼ »ìÆ캼 ¼ö ÀÖÀ» °ÍÀÌ´Ù. ¿©·¯ºÐÀº ¶ÇÇÑ, ´ÙÀ½°ú °°Àº ¹®ÀåÀ» »ðÀÔÇÔÀ¸·Î½á ÇÔÃàµÈ(implicit) C -> asm ÀÇ renaming ±ÔÄ¢À» override ÇÒ ¼öµµ ÀÖÀ» °ÍÀÌ´Ù.
foo() C ÇÔ¼ö´Â
½ÇÁ¦·Î ¾î¼Àºí¸®¿¡¼´Â bar À̶ó°í ºÒ¸®¿ì°Ô
µÉ °ÍÀÌ´Ù.binutils ÆÐÅ°ÁöÀÇ objcopy À¯Æ¿¸®Æ¼°¡ ¿©·¯ºÐÀÇ a.out ¿ÀºêÁ§Æ®¸¦ ELF Çü½ÄÀÇ ¿ÀºêÁ§Æ® ÆÄÀÏ·Î º¯È¯ÇØ ÁÙ ¼ö ÀÖÀ½À» ÁÖ¸ñÇ϶ó. ±×¸®°í, ±× ¹Ý´ëÀÇ Àϵµ °¡´ÉÇÒ °ÍÀÌ´Ù. º¸´Ù ÀϹÝÀûÀ¸·Î À̾߱âÇÏÀÚ¸é, ±× À¯Æ¿¸®Æ¼´Â ´õ ¸¹Àº ÇüÅÂÀÇ ÆÄÀÏ Çü½Ä º¯È¯µµ ÇØ ÁÙ °ÍÀÌ´Ù. 5.1.3. Direct Linux syscalls ¿©·¯ºÐÀº Á¾Á¾
C library (libc)
¸¦ »ç¿ëÇÏ´Â °ÍÀÌ À¯ÀÏÇÑ ¹æ¹ýÀ̸ç, Á÷Á¢ÀûÀÎ ½Ã½ºÅÛ ÄÝÀº º°·Î
ÁÁÁö ¾Ê´Ù´Â ¸»À» µéÀ» °ÍÀÌ´Ù.
ÀÌ°ÍÀº »ç½ÇÀÌ´Ù.
±×·¯³ª ÀϹÝÀûÀ¸·Î ¿©·¯ºÐÀº libc °¡
½Å¼º½ÃµÇ°í ÀÖÁö ¾Ê´Ù´Â °Í°ú, ´ëºÎºÐÀÇ °æ¿ì
libc ´Â ¸î°¡Áö üũ¸¸ ÇÏ°í, Ä¿³ÎÀ» È£ÃâÇÑ ÈÄ, errno º¯¼ö¸¦¼¼ÆÃÇÒ »ÓÀ̶ó´Â °ÍÀ»
¾Ë¾Æ¾ß ÇÑ´Ù.
¿©·¯ºÐÀº ¿©·¯ºÐÀÇ ÇÁ·Î±×·¥¿¡¼µµ ÀÌ¿Í °°Àº °ÍÀ» ½±°Ô ÇÒ ¼ö ÀÖ´Ù (¸¸¾à
¿©·¯ºÐÀÌ ±×°ÍÀ» ÇÊ¿ä·Î ÇÑ´Ù¸é). ±×¸®°í ¿©·¯ºÐÀÌ
°øÀ¯ ¶óÀ̺귯¸®¸¦ »ç¿ëÇÏÁö ¾Ê´Â´Ù´Â ÀÌÀ¯¸¸À¸·Îµµ
¿©·¯ºÐÀÇ ÇÁ·Î±×·¥Àº ¸î½Ê¹è ´õ
Å©±â°¡ ÁÙ¾îµé °ÍÀ̸ç, ¼öÇ༺´É ¶ÇÇÑ ´õ ÁÁ¾ÆÁú °ÍÀÌ´Ù.
libc À» ¾î¼Àºí¸® ÇÁ·Î±×·¡¹Ö¿¡¼
»ç¿ëÇϰųª ÇÏÁö ¾Ê°Å³ª ÇÏ´Â ¹®Á¦´Â ½Ç¿ëÀûÀÎ ¹®Á¦¶ó±â º¸´Ù´Â
±âÈ£³ª ½Å³ä¿¡ °üÇÑ ¹®Á¦ÀÌ´Ù.
Linux ´Â POSIX ȣȯÀ» ¸ñÇ¥·Î ÇÏ°í ÀÖ´Ù´Â °ÍÀ» ±â¾ïÇ϶ó. ±×¸®°í,
libc ´Â ±×·¯ÇÑ ¸ñÇ¥¸¦ ¸¸Á·ÇÑ´Ù.
ÀÌ°ÍÀº libc system call ÀÇ °ÅÀÇ ¸ðµç ¹®¹ýÀÌ
Ä¿³ÎÀÇ ½Ã½ºÅÛ ÄÝÀÇ ½ÇÁ¦ ¹®¹ý°ú Á¤È®È÷ ÀÏÄ¡ÇÑ´Ù´Â ¶æÀÌ´Ù.
±×·¯³ª
GNU libc(glibc)
´Â ¹öÁ¯¾÷ÀÌ µÇ¾î °¥¼ö·Ï ´õ ´À·ÁÁö°í ÀÖ´Ù. ¶ÇÇÑ ¸Þ¸ð¸®µµ ´õ ¸¹ÀÌ
Àâ¾Æ¸Ô¾î °¡°í ÀÖ´Ù. ±×·¡¼ Á÷Á¢ÀûÀÎ ½Ã½ºÅÛ ÄÝÀÌ ²Ï³ª ½Ç¿ëÀûÀÎ °ÍÀÌ
µÇ¾î°¡°í ÀÖ´Ù.
±×·¸Áö¸¸... libc ¸¦ »ç¿ëÇÏÁö ¾ÊÀ½À¸·Î½á
»ý±â´Â ÁÖµÈ ºÎÀÛ¿ë(?, drawback) Àº ¾Æ¸¶µµ ¿©·¯ºÐÀÌ
¸î¸îÀÇ libc ÀÇ Æ¯Á¤ ÇÔ¼öµé(½Ã½ºÅÛ ÄÝ wrapper °¡
¾Æ´Ñ)À» Á÷Á¢ ±¸ÇöÇÒ ÇÊ¿ä°¡ »ý±æÁöµµ ¸ð¸¥´Ù´Â °ÍÀÌ´Ù.
(À̸¦Å׸é, ¿©±â¿¡ Á÷Á¢ÀûÀÎ ½Ã½ºÅÛ ÄÝÀ» ÇÏ´Â °ÍÀÇ µæ°ú ½ÇÀÌ ³ª¿µÇ¾î ÀÖ´Ù : À̵æ:
¼ÕÇØ:
¸¸¾à ¿©·¯ºÐÀÌ ¹æ±Ý ¾ð±ÞÇÑ µæ½ÇµéÀ» ½É»ç¼÷°í ÇßÀ¸¸ç, ±×·¡µµ ¿©ÀüÈ÷ direct ½Ã½ºÅÛ ÄÝÀ» »ç¿ëÇϱ⸦ ¿øÇÑ´Ù¸é, ¾Æ·¡¿¡ ¸î°¡Áö Á¶¾ðÀ» ÷ºÎÇØ ÁÖ°Ú´Ù :
±âº»ÀûÀ¸·Î, ½Ã½ºÅÛ ÄÝÀº ¸®ÅÏ°ªÀº eax ·¹Áö½ºÅÍ¿¡ ´ã°ÜÁö°Ô µÇ¸ç, À½¼öÀÇ ¸®ÅÏ°ªÀº ¿¡·¯°¡ ÀÖÀ½À» ³ªÅ¸³½´Ù. libc °¡ errno º¯¼ö¿¡ Áý¾î³Ö´Â °ª°ú ´ëÀÀµÇ´Â °ªÀÌ´Ù. »ç¿ëÀÚ ¿µ¿ªÀÇ ½ºÅÃÀº ¿µÇâÀ» ¹ÞÁö ¾Ê´Â´Ù. ±×·¡¼ ¿©·¯ºÐÀº ½Ã½ºÅÛ ÄÝÀ» ÇàÇÒ µ¿¾È¿¡ À¯È¿ÇÑ °ÍÀ» °¡Áú ÇÊ¿ä´Â ¾ø´Ù(?) ¿ø¹® : Result is returned in eax, negative result being an error, whose opposite is what libc would put into errno. The user-stack is not touched, so you needn't have a valid one when doing a syscall.
Linux Kernel Internals, ¹®¼ÀÇ How System Calls Are Implemented on i386 Architecture? ÀåÀº ¿©·¯ºÐ¿¡°Ô º¸´Ù È®½ÇÇÑ °³³äÀ» Á¦°øÇÒ °ÍÀÌ´Ù. ÇÁ·Î¼¼½º¸¦ óÀ½ ½ÃÀÛÇÒ ¶§ ³Ñ°ÜÁö´Â ÀÎÀڵ鿡 ´ëÇؼ´Â, ÀϹÝÀûÀÎ ¿øÄ¢Àº
½ºÅÃÀÌ ÀÎÀÚÀÇ °¹¼ö¸¦ ÀúÀåÇÏ´Â ¿ø¹® :
As for the invocation arguments passed to a process upon startup,
the general principle is that the stack
originally contains the number of arguments º¸´Ù ÀÚ¼¼ÇÑ Á¤º¸¸¦ ¿øÇÑ´Ù¸é, ¸®¼Ò½º ¸®½ºÆ®¸¦ ÂüÁ¶Çؼ (: Linux assembly resources) libc ÀÇ C ½ºÅ¸Æ®¾÷ ÄÚµåÀÇ ¼Ò½º¸¦ ÀÐ¾î º¸¾Æ¶ó. (crt0.S or crt1.S) ȤÀº ¸®´ª½º Ä¿³ÎÀÇ ¼Ò½º¸¦ ÂüÁ¶Ç϶ó . (exec.c and binfmt_*.c in linux/fs/). 5.1.4. ¸®´ª½º¿¡¼ÀÇ Çϵå¿þ¾î ÀÔÃâ·Â¿©·¯ºÐÀÌ ¸®´ª½º¿¡¼ Á÷Á¢ I/O Æ÷Æ®¿¡ÀÇ ÀÔÃâ·ÂÀ» ¼öÇàÇÏ°íÀÚ ÇÑ´Ù¸é, OS ÀÇ ÁßÀ縦 ÇÊ¿ä·Î ÇÏÁö ¾Ê´Â ¸Å¿ì °£´ÜÇÑ ÀÏÀÌ¾î¼ IO-Port-Programming ¹Ì´Ï ÇÏ¿ìÅõ¸¦ ÂüÁ¶ÇÏ¸é µÉ Á¤µµÀ̰ųª ¾Æ´Ï¸é Ä¿³Î µð¹ÙÀ̽º µå¶óÀ̹ö¸¦ ÇÊ¿ä·Î Çؼ ¿©·¯ºÐÀÌ Ä¿³Î ÇØÅ·À̳ª µð¹ÙÀ̽º µå¶óÀ̹ö °³¹ßÀ̳ª, Ä¿³Î ¸ðµâ°ú °°Àº °Íµé¿¡ ´ëÇؼ ´õ ¸¹Àº °ÍÀ» ½ÀµæÇؾ߸¸ ÇÏ´Â °æ¿ìÀ̰ųª µÑÁß ÇϳªÀÇ °æ¿ìÀÏ °ÍÀÌ´Ù. (Ä¿³Î ¸ðµâÀ̳ª µð¹ÙÀ̽º µå¶óÀ̹ö¿¡ ´ëÇÑ °ÍµéÀº LDP ¿¡ ¸Å¿ì ÈǸ¢ÇÑ ÇÏ¿ìÅõµéÀÌ Á¸ÀçÇÑ´Ù.) Ȥ½Ã ¿©·¯ºÐÀÌ ¿øÇÏ´Â °ÍÀÌ ±×·¡ÇÈ ÇÁ·Î±×·¡¹ÖÀÎ °æ¿ì, ´ÙÀ½ÀÇ ÇÁ·ÎÁ§Æ®µéÀ» ÂüÁ¶Ç϶ó : GGI ȤÀº XFree86 ÇÁ·ÎÁ§Æ® ¾î¶² »ç¶÷µéÀº ÀÛ°í, °ß°íÇÑ XFree86 µå¶óÀ̹öµéÀ» interperted domain-specific language ÀÎ GAL, ·Î °³¹ßÇÔÀ¸·Î½á º¸´Ù È¿°úÀûÀÎ °á°ú¸¦ ¾ò¾ú´Ù. ¿ø¹® : Some people have even done better, writing small and robust XFree86 drivers in an interpreted domain-specific language, GAL, and achieving the efficiency of hand C-written drivers through partial evaluation (drivers not only not in asm, but not even in C!). The problem is that the partial evaluator they used to achieve efficiency is not free software. Any taker for a replacement? ¾î·°Å³ª, ÀÌ ¸ðµç °æ¿ì¿¡µµ, ¿©·¯ºÐÀº linux/asm/*.h ¿¡ ÀÖ´Â GCC ÀζóÀÎ ¾î¼Àºí¸®¿Í ¸ÅÅ©·Î¸¦ »ç¿ëÇÔÀ¸·Î½á Àüü¸¦ ¾î¼Àºí¸®·Î ÄÚµùÇÏ´Â °Íº¸´Ù È¿À²ÀûÀ¸·Î ÀÏÀ» ¼öÇàÇÒ ¼ö ÀÖ´Ù. 5.1.5. Accessing 16-bit drivers from Linux/i386±×·¯ÇÑ ÀϵéÀº ÀÌ·ÐÀûÀ¸·Î °¡´ÉÇÏ´Ù (Áõ¸í : DOSEMU °¡ ÇÁ·Î±×·¥µé¿¡°Ô ¼±ÅÃÀûÀ¸·Î Çϵå¿þ¾î Æ÷Æ® Á¢±Ù ±ÇÇÑÀ» ÁÖ´Â ¹æ¹ýÀ» º¸¶ó) ±×¸®°í, ÀúÀÚ´Â ¾îµò°¡ÀÇ ´©±º°¡°¡ ½ÇÁ¦·Î ±×·¯ÇÑ ÀÏÀ» Çß´Ù´Â ¼Ò¹®À» µé¾ú´Ù. (PCI µå¶óÀ̹ö¿¡¼Àΰ¡? ¾Æ´Ï¸é, VESA µå¶óÀ̹ö¿¡¼Àΰ¡... À½... ISA PnP ¿´´ø°¡... Àß ¸ð¸£°Ú´Ù) ¸¸¾à ¿©·¯ºÐÀÌ º¸´Ù Á¤È®ÇÑ Á¤º¸¸¦ °¡Áö°í ÀÖ´Ù¸é ȯ¿µÇÑ´Ù. (¿ªÀÚÁÖ : ¸ÞÀÏÀ» ´Þ¶ó´Â ¶æÀεí) ¾î·µç, Á¤º¸¸¦ ã±â ¸Å¿ì ÁÁÀº °÷Àº ¸®´ª½ºÀÇ Ä¿³Î ¼Ò½º¿Í DOSEMU ÀÇ ¼Ò½ºÀÌ´Ù. (±×¸®°í, DOSEMU repository ÀÇ ´Ù¸¥ ¸¹Àº ÇÁ·Î±×·¥µéÀÌ´Ù.) ¶ÇÇÑ, ¿©·¯°¡ÁöÀÇ ¸®´ª½ºÀÇ low-level ÇÁ·Î±×·¥µéÀÇ ¼Ò½ºµéµµ µµ¿òÀÌ µÉ °ÍÀÌ´Ù. (perhaps GGI if it supports VESA) ±âº»ÀûÀ¸·Î ¿©·¯ºÐÀº 16ºñÆ® º¸È£¸ðµå³ª ȤÀº vm86 ¸ðµå¸¦ ÀÌ¿ëÇؾ߸¸ ÇÒ °ÍÀÌ´Ù. ÀüÀÚ(16ºñÆ® º¸È£¸ðµå) ´Â ¼Â¾÷Àº ºñ±³Àû ½¬¿ì³ª ¼¼±×¸ÕÆ® Á¶ÀÛÀ̳ª Àý´ë ¼¼±×¸ÕÆ® ÁÖ¼ÒÁöÁ¤(segment 0 À» ÁÖ¼ÒÁöÁ¤ÇÏ´Â °Í°ú°°Àº) ÀÌ ¾ø´Â Àß µ¿ÀÛÇÏ´Â Äڵ带 ¸¸µé¾î¾ß¸¸ µ¿ÀÛÇÑ´Ù. ¿ì¿¬ÀÌ¶óµµ ¸ðµç »ç¿ëÇÏ´Â ¼¼±×¸ÕÆ®°¡ LDT(¿ªÀÚÁÖ : Local Descriptor Table, ÀÎÅÚ ¾ÆÅ°ÅØÃÄ¿¡¼ ¼¼±×¸ÕÆ®¿Í ³í¸® ÁÖ¼Ò, ¹°¸® ÁÖ¼ÒµéÀ» º¯È¯ÇÏ´Â µ¥ »ç¿ëµÇ´Â ÀڷᱸÁ¶) ¸¦ ¸¶¸® ¼Â¾÷ÇØ ¹ö¸®Áö ¾Ê´Â ÇÑÀº ±×·¯ÇÏ´Ù ¿ø¹® : The first is simpler to setup, but only works with well-behaved code that won't do any kind of segment arithmetics or absolute segment addressing (particularly addressing segment 0), unless by chance it happens that all segments used can be setup in advance in the LDT. ÈÄÀÚ(vm86 ¸ðµå) ´Â 'vanilla 16-bit ȯ°æ' ¿¡¼ º¸´Ù ¸¹Àº ȣȯ¼ºÀ» Á¦°øÇϱâ´Â ÇÏÁö¸¸, ´õ º¹ÀâÇÑ Çڵ鸵ÀÌ ÇÊ¿äÇÏ´Ù. µÎ °æ¿ì ¸ðµÎ ¿©·¯ºÐÀÌ 16ºñÆ® Äڵ带 »ç¿ëÇϱâ Àü¿¡ ¹Ýµå½Ã ÇØ¾ß ÇÒ ÀϵéÀÌ ÀÖ´Ù :
´Ù½ÃÇѹø DOSEMU ÇÁ·ÎÁ§Æ®ÀÇ ¼Ò½ºµé¿¡ ³ª¿À´Â ³»¿ëµéÀ» ÁÖÀDZíÀÌ Àеµ·Ï ÇÏ¿©¶ó. ƯÈ÷, ¸®´ª½º/i386 ¿¡¼ ELKS ¿Í °£´ÜÇÑ .COM ÇÁ·Î±×·¥µéÀ» µ¹¸± ¼ö ÀÖ´Â mini-emulator µéÀÇ ¼Ò½º¸¦ ÀÚ¼¼È÷ º¸µµ·Ï Ç϶ó. 5.2. DOS and Windows ´ëºÎºÐÀÇ µµ½º È®ÀåÀÚµéÀº µµ½º ¼ºñ½º¿¡ ´ëÇÑ ÀÎÅÍÆäÀ̽º¸¦ Á¦°øÇÑ´Ù.
±×µéÀÇ ¹®¼¿¡¼ °ü·ÃµÈ ³»¿ëµéÀ» ÀÐ¾î º¸µµ·Ï Ç϶ó.
±×·¯³ª Á¾Á¾ ±×µéÀº DPMI ¿Í °ü·ÃµÈ ¹®¼µéÀÌ ´ÙÀ½ÀÇ ¸µÅ©µé¿¡ Á¸ÀçÇÑ´Ù : ftp://x2ftp.oulu.fi/pub/msdos/programming/ (¿ø·¡ÀÇ x2ftp »çÀÌÆ®°¡ ¹®µé ´Ý¾Ò±â ¶§¹®¿¡ ´ÙÀ½ÀÇ ¸µÅ©¸¦ ÀÌ¿ëÇ϶ó : mirror site). DJGPP ´Â ÀÚüÀÇ(Á¦ÇѹöÁ¯ÀÓ) glibc À¯»çÇ°(?) À» Á¦°øÇÑ´Ù. Linux ¿¡¼ DOS ¿ëÀÇ ¹ÙÀ̳ʸ®·Î Å©·Î½º ÄÄÆÄÀÏ ÇÏ´Â °Íµµ °¡´ÉÇÏ´Ù. ¿©·¯ºÐ Áö¿ªÀÇ metalab.unc.edu ÀÇ FTP ¹Ì·¯ÀÇ devel/msdos/ µð·ºÅ丮¸¦ º¸¶ó. ¶ÇÇÑ, MOSS DOS-È®ÀåÀÚ¸¦ Utah ´ëÇÐÀÇ Flux project ¿¡¼ ±¸ÇÒ ¼ö ÀÖ´Ù. ´Ù¸¥ ¹®¼µéÀ̳ª faq µéÀº º¸´Ù µµ½º Áß½ÉÀÌ´Ù. ¿ì¸®´Â µµ½ºÈ¯°æÀÇ °³¹ßÀ» ÃßõÇÏÁö ¾Ê´Â´Ù. Windows and Co. ÀÌ ¹®¼´Â À©µµ¿ìÁî ÇÁ·Î±×·¡¹Ö¿¡ °üÇÑ ¹®¼°¡ ¾Æ´Ï´Ù. ´ç½ÅÀº ´Ù¸¥ °÷¿¡¼ ±×¿¡ °ü·ÃµÈ ¸¹Àº °ÍµéÀ» ãÀ» ¼ö ÀÖ´Ù. ´ç½ÅÀÌ ¾Ë¾Æ¾ß ÇÒ °ÍÀº Cygnus Solutions °¡ cygwin32.dll library ¸¦ Win32 Ç÷§Æû¿¡¼ GNU ÇÁ·Î±×·¥µéÀ» ½ÇÇà½ÃÅ°±â À§Çؼ °³¹ßÇß´Ù´Â °ÍÀÌ´Ù. µû¶ó¼, ´ç½ÅÀº gcc, gas, ±×¸®°í ±× ¿ÜÀÇ gnu ÅøµéÀ» ´Ù¸¥ ¸¹Àº À¯´Ð½º ÀÀ¿ë ÇÁ·Î±×·¥Ã³·³ À©µµ¿ì¿¡¼ ½ÇÇà½Ãų ¼ö ÀÖ´Ù. 5.3. ¿©·¯ºÐÀÌ ¸¸µç OS½Ã½ºÅÛ¿¡ ´ëÇÑ ¿ÏÀüÇÑ Á¦¾î ¶ó´Â Ư¼ºÀº ¸¹Àº OS °³¹ßÀÚµéÀ» ¾î¼Àºí¸®·Î À¯È¤Çϴ Ư¼ºÀÌ´Ù. self-development ¸¦ Çã¿ëÇÏ´Â ½Ã½ºÅÛÀº, ºñ·Ï, ±×°ÍÀÌ ´Ù¸¥ ½Ã½ºÅÛÀÇ 'À§¿¡¼' ¿î¿µµÉÁö¶óµµ (Linux over Mach ³ª OpenGenera over Unix ó·³) "OS" ¶ó°í ºÎ¸¦ ¼ö ÀÖÀ½À» ±â¾ïÇ϶ó. µû¶ó¼, º¸´Ù ½¬¿î µð¹ö±ëÀ» À§ÇØ ¿©·¯ºÐÀº ¸®´ª½º¿¡¼ ½ÇÇàµÇ´Â ÇÁ·Î¼¼½º·Î¼ÀÇ ¿©·¯ºÐÀÇ "OS" ¸¦ ¸ÕÀú °³¹ßÇÏ°íÀÚ ÇÒÁöµµ ¸ð¸¥´Ù. (´À¸±Áö´Â ¸ð¸£Áö¸¸) ±×¸®°í ³ª¼ Flux OS kit (Linux ¿Í BSD µå¶óÀ̹öµéÀ» ¿©·¯ºÐ ÀÚ½ÅÀÇ OS ¿¡¼ »ç¿ëÇÒ ¼ö ÀÖ°Ô ÇØ ÁÖ´Â À¯Æ¿¸®Æ¼) ¸¦ »ç¿ëÇؼ ±×°ÍÀ» stand-alone À¸·Î ¸¸µé°íÀÚ ÇÒÁöµµ ¸ð¸£°Ú´Ù. ¿©·¯ºÐÀÇ OS °¡ stable ÇÏ°í, ¿©·¯ºÐÀÌ ÁøÁ¤À¸·Î ¿©·¯ºÐÀÇ Ã¢Á¶¹°À» »ç¶ûÇÑ´Ù¸é ±×¶§¿¡¾ß ¿©·¯ºÐÀÇ Çϵå¿þ¾î µå¶óÀ̹öµéÀ» ¸¸µé ½Ã±â°¡ ¿Â °ÍÀÌ´Ù. ÀÌ ÇÏ¿ìÅõ´Â ºÎÆ®·Î´õÀÇ Äڵ峪, 32-ºñÆ® ¸ðµå·Î ÁøÀÔÇÏ´Â ¹ýÀ̶óµçÁö, ÀÎÅÍ·´Æ®¸¦ ´Ù·ç´Â ¹ýÀ̳ª, ÀÎÅÚÀÇ º¸È£¸ðµå, ȤÀº °¡»ó/¸®¾ó 86 ¸ðµå¶óµçÁö ¿©·¯ºÐÀÇ ¿ÀºêÁ§Æ® ÆÄÀÏ Æ÷¸ËÀ̳ª È£Ãâ ±ÔÄ¢¿¡ °üÇÑ °ÍµéÀº ´Ù·çÁö ¾Ê´Â´Ù. ¿©·¯ºÐÀÌ ±×·¯ÇÑ °Íµé¿¡ °üÇÑ ¹ÏÀ»¸¸ÇÑ Á¤º¸¸¦ ãÀ» ¼ö ÀÖ´Â ÁÖµÈ Àå¼Ò´Â ÇöÁ¸ÇÏ´Â OS µé°ú ºÎÆ®·Î´õµéÀÇ ¼Ò½ºÄÚµåÀÌ´Ù. ´ÙÀ½ÀÇ À¥ÆäÀÌÁö¿¡ ¸¹Àº ¸µÅ©µéÀÌ ÀÖÀ» °ÍÀÌ´Ù : http://www.tunes.org/Review/OSes.html 6장. ÀÏ´Ü µû¶óÇغ¸ÀÚ(Quick Start)6.1. ¼Ò°³¸¶Ä§³» ¶§°¡ ¿Ô´Ù. ¿©·¯ºÐÀÌ ¾ÆÁ÷µµ ÀÌ ¹®¼¸¦ Àаí ÀÖÀ¸¸ç, ¿©ÀüÈ÷ ¾î¼Àºí¸®·Î ¹«¾ð°¡¸¦ ¸¸µé°Ú´Ù´Â ±¤±â¾î¸°(!) »ý°¢À» °¡Áö°í ÀÖ´Ù¸é (¿©±â±îÁö ÀÐÀº »ç¶÷À̶ó¸é, Á¤¸» ¾î¼Àºí¸® ÆÒÀÓ¿¡ Ʋ¸²¾ø´Ù), ÀÌÁ¦ºÎÅÍ ½ÃÀÛÇϴµ¥¿¡ ÇÊ¿äÇÑ °ÍÀ» ¾Ë·ÁÁÖ°Ú´Ù. ¿©·¯ºÐÀÌ ¾Õ¼ ÀÐÀº ¹Ù¿Í °°ÀÌ ¿©·¯ºÐÀº ¸®´ª½º ¿î¿µÃ¼Á¦¿¡¼ ¿©·¯°¡Áö ¹æ¹ýÀ¸·Î ÇÁ·Î±×·¡¹ÖÀ» ÇÒ ¼ö ÀÖ´Ù. ÀÌÁ¦ºÎÅÍ º» ÀúÀÚ´Â Ä¿³ÎÀÇ ½Ã½ºÅÛ ÄÝÀ» Á÷Á¢ È£ÃâÇÏ´Â ¹æ¹ýÀ» º¸¿©ÁÖ·Á ÇÑ´Ù. ¿Ö! Á÷Á¢ Ä¿³ÎÀ» È£ÃâÇϴ°¡? ±×·¸°Ô ÇÏ´Â °ÍÀÌ Ä¿³ÎÀÌ Á¦°øÇÏ´Â ¼ºñ½º¸¦ È£ÃâÇÏ´Â °¡Àå ºü¸¥(!) ¹æ¹ýÀ̱⠴빮ÀÌ´Ù. ÀÌ ¹æ¹ýÀ» »ç¿ëÇϸé, ¿ì¸®ÀÇ ÄÚµå´Â ´Ù¸¥ ¶óÀ̺귯¸®¿¡ ¸µÅ©µÉ ÇÊ¿ä°¡ ¾ø´Ù. ELF ÀÎÅÍÇÁ¸®Å͸¦ »ç¿ëÇÒ ÇÊ¿äµµ ¾ø´Ù.´ÜÁö, Ä¿³Î°ú Á÷Á¢ ÀÇ»ç¼ÒÅëÇÒ µû¸§ÀÌ´Ù. ÀúÀÚ´Â µ¿ÀÏÇÑ ÀÏÀ» ÇÏ´Â »ùÇà ÇÁ·Î±×·¥À» nasm °ú gas, ÀÌ µÎ°³ÀÇ ¾î¼Àºí·¯¸¦ »ç¿ëÇؼ °¢°¢ ÇÁ·Î±×·¡¹Ö ÇÑ ¼Ò½º¸¦ º¸¿©ÁÖ°Ú´Ù. ÀÚ¼¼È÷ º¸¸é, ÀÎÅÚ°è¿°ú AT&T À¯´Ð½º °è¿ÀÇ ¹®¹ýÀÇ Â÷À̸¦ ¾Ë.. ¼öµµ ÀÖÀ»±î? ¿©·¯ºÐÀº ¶ÇÇÑ, À¯´Ð½º ¾î¼Àºí¸® ÇÁ·Î±×·¡¹Ö Æ©Å丮¾ó(UNIX assembly programming tutorial - http://linuxassembly.org/intro.html)ÀÇ ¼Ò°³¸¦ Àо ¼ö ÀÖ´Ù. °Å±â¿¡´Â ¸®´ª½º ÀÌ¿Ü¿¡µµ, ´Ù¸¥ À¯´Ð½º °è¿ÀÇ ¿î¿µÃ¼Á¦¸¦ À§ÇÑ »ùÇà ÄÚµåµéÀÌ ÀÖ´Ù.(¿ªÀÚ ÁÖ : FreeBSD, BeOS µî) 6.1.1. ÇÊ¿äÇÑ µµ±¸µé´ç¿¬È÷ ¾î¼Àºí·¯°¡ ÇÊ¿äÇÏ´Ù. -- nasm À̳ª gas. ±×¸®°í, ¸µÄ¿°¡ ÇÊ¿äÇÏ´Ù. -- ld ¿Ö³ÄÇϸé, ¾î¼Àºí·¯´Â ´ÜÁö ¸ñÀûÄÚµå(object code)¸¸À» ¸¸µé¾î³»±â ¶§¹®ÀÌ´Ù. ´ëºÎºÐÀÇ ¹èÆ÷º»¿¡´Â gas ¿Í ld °¡ Æ÷ÇԵǾî ÀÖ´Ù. binutils ÆÐÅ°Áö¿¡ ÆÐŰ¡µÇ¾î ÀÖ´Ù. nasm ÀÇ °æ¿ì, ¸®´ª½º¿ëÀÇ ¹®¼¿Í ¹ÙÀ̳ʸ® ÆÐÅ°Áö¸¦ ´Ù¿î·ÎµåÇؼ ¼³Ä¡ÇØ¾ß ÇÑ´Ù. ´Ù¿î·Îµå ÇÒ ¼ö ÀÖ´Â »çÀÌÆ®´Â ´ÙÀ½°ú °°´Ù : nasm site; ¸Çµå·¹ÀÌÅ©, ¼ö¼¼, Stampede, µ¥ºñ¾È µîÀÇ ÆÐÅ°Áö¿¡´Â Æ÷ÇԵǾî ÀÖ´Ù. ¸ÕÀú, È®ÀÎÇ϶ó. Á¤¸» ±íÀÌ ÆÄ°íµé·Á¸é, ¿©·¯ºÐÀÇ ¿î¿µÃ¼Á¦ÀÇ include ÆÄÀϵéÀ» ¼³Ä¡ÇØ¾ß ÇÏ°í, °¡´ÉÇÏ´Ù¸é, Ä¿³Î ¼Ò½º±îÁö ¼³Ä¡Ç϶ó (¿©·¯ºÐÀÇ ¿î¿µÃ¼Á¦°¡ °ø°³ ¿î¿µÃ¼Á¦ÀÌ¸é °¡´ÉÇÏ´Ù.) 6.2. Hello, world!6.2.1. Program layout¸®´ª½º´Â 32ºñÆ® ÇÁ·ÎÅØƼµå ¸ðµå¿¡¼ µ¿ÀÛÇϸç, ¼±Çü ¸Þ¸ð¸® ¸ðµ¨(flat memory model)À» °¡Áø´Ù. ±×¸®°í, ÀÌÁø ½ÇÇàÆÄÀÏ¿¡ ELF Æ÷¸ËÀ» °¡Áø´Ù. ÇÁ·Î±×·¥Àº ¿©·¯ºÐÀÌ ÀÛ¼ºÇÑ Äڵ尡 ÀÖ´Â .text ¼½¼Ç°ú (ÀÌ ºÎºÐÀº Àбâ Àü¿ëÀÌ´Ù) ¿©·¯ºÐÀÇ ÃʱâȵÈ(!) data °¡ ÀúÀåµÇ¾î ÀÖ´Â .data ¼½¼Ç, ÃʱâȵÇÁö ¾ÊÀº(!) µ¥ÀÌŸ°¡ ÀúÀåµÇ´Â .bss ¼½¼Ç ¹× ´Ù¸¥ Ç¥ÁØÀûÀÎ ¼½¼Çµé·Î ³ª´¶´Ù. Å©°Ô º¸¸é, .text ¿Í .data ÀÇ µÎ°³ÀÇ ¼½¼ÇÀ¸·Î ³ª´¶´Ù. (Áï, ÄÚµå¿Í µ¥ÀÌŸ) ±×·¯³ª, ´Ù¸¥ ¼½¼Ç ¾øÀÌ .text ¼½¼Ç¸¸À¸·Îµµ ÇÁ·Î±×·¥ÀÌ °¡´ÉÇÏ´Ù. .text ¼½¼ÇÀº ÇÁ·Î±×·¥¿¡ ¹Ýµå½Ã ÀÖ¾î¾ß ÇÏ´Â ¼½¼ÇÀÌ´Ù. (¿ªÀÚÁÖ : »ó»óÇغ¸¶ó! ÄÚµå ¾ø´Â ÇÁ·Î±×·¥ -- ¸»µµ ¾ÈµÈ´Ù.) ÀÌÁ¦, ù¹ø° ÇÁ·Î±×·¥À» ÀÛ¼ºÇØ º¸ÀÚ (¿ªÀÚÁÖ : ¿ª½Ã³ª.. Çï·Î¿ùµå ÇÁ·Î±×·¥ÀÌ´Ù ¤Ñ.¤Ñ) 6.2.2. NASM (hello.asm)
6.2.3. GAS (hello.S)
6.3. ½ÇÇàÆÄÀÏ ¸¸µé±â6.3.1. ¸ñÀû ÄÚµå »ý¼º½ÇÇàÆÄÀÏÀ» ¸¸µé±â À§ÇÑ Ã¹¹ø° ´Ü°è´Â ¼Ò½ºÆÄÀÏÀ» ÄÄÆÄÀÏ È¤Àº ¾î¼Àºí¸µ Çؼ ¸ñÀû Äڵ尡 ´ã±ä ÆÄÀÏÀ» ¸¸µå´Â °ÍÀÌ´Ù. nasm À» »ç¿ëÇÑ´Ù¸é,
gas ¸¦ »ç¿ëÇÑ´Ù¸é,
¿Í °°ÀÌ ÇÏ¸é ¸ñÀû Äڵ尡 ´ã°Ü ÀÖ´Â hello.o ¸¦ »ý¼ºÇÏ°Ô µÈ´Ù. 6.3.2. ½ÇÇàÆÄÀÏÀÇ »ý¼ºµÎ¹ø° ´Ü°è·Î½á, ¸ñÀûÄڵ尡 ´ã±ä ÆÄÀϷκÎÅÍ ¸µÄ¿¸¦ È£ÃâÇÏ¿© ½ÇÇà°¡´ÉÇÑ ÆÄÀÏÀ» ¸¸µé¾î³»°Ô µÈ´Ù.
À§¿Í °°ÀÌ ÇÏ¸é µÈ´Ù. ±×·¸°Ô ÇÏ°í ³ª¸é, ¸¶Ä§³», hello ¶ó´Â ½ÇÇàÆÄÀÏÀ» º¼ ¼ö ÀÖ°Ô µÈ´Ù. Çѹø ½ÇÇà½ÃÄÑ º¸¾Æ¶ó. Á¦´ë·Î µ¿ÀÛÇϴ°¡? ³¡ÀÌ´Ù. ÀÌ°Ô ÀüºÎÀÌ´Ù. ¸Å¿ì °£´ÜÇÏÁö ¾ÊÀº°¡? ³Ê¹«³ª °£´ÜÇؼ µÇ·Á Ȳ´çÇÏÁö ¾ÊÀº°¡?!?!
7장. Resources7.1. PointersYour main resource for Linux/UNIX assembly programming material is: Do visit it, and get plenty of pointers to assembly projects, tools, tutorials, documentation, guides, etc, concerning different UNIX operating systems and CPUs. Because it evolves quickly, I will no longer duplicate it here. If you are new to assembly in general, here are few starting pointers:
7.2. Mailing listIf you're are interested in Linux/UNIX assembly programming (or have questions, or are just curious) I especially invite you to join Linux assembly programming mailing list. This is an open discussion of assembly programming under Linux, *BSD, BeOS, or any other UNIX/POSIX like OS; also it is not limited to x86 assembly (Alpha, Sparc, PPC and other hackers are welcome too!). To subscribe send a blank message to List address is List archives are available at http://www.egroups.com/list/linux-assembly/. 8장. Frequently Asked QuestionsHere are frequently asked questions (with answers) about Linux assembly programming. Some of the questions (and the answers) were taken from the the linux-assembly mailing list.
An answer from Paul Furber:
There's an early version of the Assembly Language Debugger, which is designed to work with assembly code, and is portable enough to run on Linux and *BSD. It is already functional and should be the right choice, check it out! You can also try gdb ;). Although it is source-level debugger, it can be used to debug pure assembly code, and with some trickery you can make gdb to do what you need. Here's an answer from Dmitry Bakhvalov:
An additional note from ???:
If you want to set breakpoints across your code, you can just use
If you're using gas, you should consult gas and gdb related tutorials. Definitely strace can help a lot (ktrace and kdump on FreeBSD), it is used to trace system calls and signals. Read its manual page (man strace) and strace --help output for details. Noway. This is protected mode, use OS services instead.
Again, you can't use Yes, indeed it is. While in general it is not a good idea (it hardly will speedup anything), there may be a need of such wizardy. The process of writing a module itself is not that hard -- a module must have some predefined global function, it may also need to call some external functions from the kernel. Examine kernel source code (that can be built as module) for details. Meanwhile, here's an example of a minimum dumb kernel module (module.asm) (source is based on example by mammon_ from APJ #8):
The only thing this example does is reporting its actions. Modify kernel_version to match yours, and build module with:
Now you can play with it using insmod/rmmod/lsmod (root privilidged are required); a lot of fun, huh? That's all for now, folks. 부록 A. HistoryEach version includes a few fixes and minor corrections, that need not to be repeatedly mentioned every time.
부록 B. AcknowledgementsI would like to thank all the people who have contributed ideas, answers, remarks, and moral support, and additionally the following persons, by order of appearance:
부록 C. EndorsementsThis version of the document is endorsed by Konstantin Boldyshev. Modifications (including translations) must remove this appendix according to the license agreement included below. $Id: DocbookSgml_2fAssembly_2dHOWTO,v 1.3 2004/11/05 13:56:28 kss Exp kss $ 부록 D. GNU Free Documentation LicenseGNU Free Documentation License
|