ºìÁªLinuxÃÅ»§
Linux°ïÖú

LinuxÖжÔÖжϵÄÖ§³Ö

·¢²¼Ê±¼ä:2007-01-13 00:47:53À´Ô´:ºìÁª×÷Õß:fengmayi1
¡¡¡¡LinuxÄÚºËÖÐʹÓõÄÃÅÊÇÔÚi386ƽ̨µÄÃŵĻù´¡ÉÏ×öÁ˸ü½øÒ»²½µÄϸ»¯ºóÐγɵģ¬ÈçÏÂËùʾ£º

¡¡¡¡1¡¢ÖжÏÃÅ£º´¦ÀíÆ÷ÖÐDPL±»ÉèÖÃΪ0µÄÖжÏÃÅ£¬²»ÄÜÓû§Ì¬Ï¶ÔÆä½øÐзÃÎÊ¡£LinuxÏÂËùÓеģ¨Ó²£©Öжϴ¦Àí³ÌÐò¶¼ÊÇÔÚºËÐÄ̬ÏÂͨ¹ýÖжÏÃÅÀ´¼¤»îµÄ¡£

¡¡¡¡2¡¢ÏµÍ³ÃÅ£º´¦ÀíÆ÷ÖÐDPL±»ÉèÖÃΪ3µÄÏÝÚåÃÅ£¬¿ÉÒÔÔÚÓû§Ì¬Ï¶ÔÆä½øÐзÃÎÊ¡£LinuxµÄÈýÖÖÒì³£´¦Àíº¯Êý£¨ÖжϺÅΪ4¡¢5¡¢128£©¶¼ÊÇͨ¹ýϵͳÃÅÀ´µ÷Óõģ¬¼´Ö¸Áîinto¡¢boundºÍint $0x80¿ÉÒÔÔÚÓû§Ì¬Ï±»Ö´ÐС£

¡¡¡¡3¡¢ÏµÍ³ÖжÏÃÅ£º´¦ÀíÆ÷ÖÐDPL±»ÉèÖÃΪ3µÄÖжÏÃÅ£¬¿ÉÒÔÔÚÓû§Ì¬Ï·ÃÎÊ¡£LinuxÖÐÖжÏÏòÁ¿ºÅΪ3µÄÖжϣ¨int3£©ÊÇͨ¹ýϵͳÖжÏÃÅÀ´µ÷Óõģ¬¿ÉÔÚÓû§Ì¬Ï±»Ö´ÐС£

¡¡¡¡4¡¢ÏÝÚåÃÅ£º´¦ÀíÆ÷ÖÐDPL±»ÉèÖóÉ0µÄÏÝÚåÃÅ£¬²»ÄÜÔÚÓû§Ì¬Ï½øÐзÃÎÊ¡£LinuxÖеĴó¶àÊýÒì³£´¦Àíº¯Êý¶¼ÊÇͨ¹ýÏÝÚåÃű»¼¤»îµÄ¡£

¡¡¡¡5¡¢ÈÎÎñÃÅ£º´¦ÀíÆ÷ÖÐDPL±»ÉèÖóÉ0µÄÈÎÎñÃÅ£¬²»ÄÜÔÚÓû§Ì¬Ï½øÐзÃÎÊ¡£LinuxÖнöÓС°Double Fault¡±Òì³£µÄ´¦Àíº¯ÊýÊÇͨ¹ýÈÎÎñÃŽøÐе÷Óõġ£

¡¡¡¡ÔÚϵͳÒýµ¼µÄ¹ý³ÌÖУ¬Äں˵÷ÓÃ/arch/i386/kernel/traps.cÎļþÖеÄtrap_initº¯ÊýÀ´¶ÔÖжϽøÐгõʼ»¯¡£¸Ãº¯Êýͨ¹ýµ÷ÓÃͬһÎļþϵÄset_trap_gateµÈ¶à¸öº¯ÊýÀ´¶ÔÖжÏÃèÊö·û½øÐгõʼ»¯¡£

¡¡¡¡set_trap_gateµÈº¯ÊýµÄ±¾ÖÊÊǵ÷ÓÃinclude/asm-i386/desc.hÎļþÖеÄ_set_gateº¯ÊýÀ´Íê³É¶ÔÖжÏÃèÊö·ûµÄ³õʼ»¯¹¤×÷£¬¸Ãº¯ÊýµÄ´úÂëÈçÏ£º

ÒýÓÃ:
static inline void _set_gate(int gate, unsigned int type, void *addr, unsigned short seg)
{
__u32 a, b;
pack_gate(&a, &b, (unsigned long)addr, seg, type, 0);
write_idt_entry(idt_table, gate, a, b);
}


¡¡¡¡ÆäÖУ¬pack_gateº¯ÊýµÄ´úÂëÈçÏ£º

ÒýÓÃ:
static inline void pack_gate(__u32 *a, __u32 *b,
unsigned long base, unsigned short seg, unsigned char type, unsigned char flags)
{
*a = (seg << 16) | (base & 0xffff);
*b = (base & 0xffff0000) | ((type & 0xff) << 8) | (flags & 0xff);
}


¡¡¡¡write_idt_entryºêÕ¹¿ªºó´úÂëÈçÏ£º

ÒýÓÃ:
#define write_idt_entry(dt, entry, a, b) write_dt_entry(dt, entry, a, b)


static inline void write_dt_entry(void *dt, int entry, __u32 entry_a, __u32 entry_b)
{
__u32 *lp = (__u32 *)((char *)dt + entry*8);
*lp = entry_a;
*(lp+1) = entry_b;
}


¡¡¡¡ÆäÖУ¬pack_gateº¯ÊýµÄÖ÷Òª¹¤×÷ÊÇÉèÖÃÏàÓ¦µÄÖжÏÃèÊö·û£¬aΪµÍ32룬bΪ¸ß32λ¡£write_idt_entryµÄ¹¤×÷ÔòÊǽ«ÔÚpack_gateº¯ÊýÖÐÉèÖúõÄÖжÏÃèÊö·ûÌîÈëµ½ÖжÏÃèÊö·û±íµÄÏàӦλÖá£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ