del_Kernel_exit	EQU	00000000H       
add_Kernel_exit	EQU	10000000H       
query_Kernel_exit	EQU	20000000H       
NMI_exit	EQU	00000000H       
SFF_exit	EQU	00000001H       
ke_NMI_U_HANDLED	EQU	0ffffffffH       
KX_NMI	EQU	<"KNMI">
KX_SFF	EQU	<"KSFF">
ifdef PMDEBUG
ke_Debug_Krnl	EQU	0fffffff7H     
KX_TRAP_NUM_MIN	EQU	00000000H     
KX_TRAP_NUM_MAX	EQU	00000011H     
KX_SINGLE_STEP_TRAP	EQU	00000001H     
KX_BREAK_POINT_TRAP	EQU	00000003H     
endif
KEXITs_DEFAULT	EQU	2                

_kEDATA	STRUC
next	DD	?
kE_addr	DD	?
kE_DS	DD	?
prev	DD	?
_kEDATA	ENDS


_kExType	STRUC
kEXIT_EYE	DB	4 DUP (?)
addr	DD	?
_kExType	ENDS


_kexitList	STRUC
kExit	DB	SIZE _kExType * KEXITs_DEFAULT DUP (?)
_kexitList	ENDS


TKCallKrnlExit  macro  uEXType
        local   ke_a0, ke_a1, ke_good, ke_1, ke_next, ke_end

        pushf                                      
        SaveReg  <ds,es,fs,gs,ebx,edx,ecx,esi,edi> 
        FlatContext <ds,es>

        nop                                        

 

        mov     ecx,uEXType                        
        cmp     ecx,SFF_exit                       
        ja      ke_end                             

        mov     edx,[_pKExitListHead]              
        or      edx,edx                            
        jz      ke_end                             

        cmp     ecx,NMI_exit                       
        jnz     ke_a1                              

ke_a0:  mov     edx,[edx + 4]                      
        jmp     ke_good                            

ke_a1:  cmp     ecx,SFF_exit                       
        jnz     ke_end                             
        mov     edx,[edx + 12]                     

ke_good:
 
        or      edx,edx                            
        jz      ke_end                             

ke_1:                                              
        push    [edx].next                         
        mov     ecx,[edx].kE_addr                  
        or      ecx,ecx                            
        jz      ke_next                            
        mov     eax,[edx].kE_DS                    
                                                   
        CALL16  Call16bitKrnlExitDD                
        nop                                        

ke_next:                                           
        pop     edx                                
        or      edx,edx                            
        jz      ke_end                             

        mov     ecx,uEXType                        
        cmp     ecx,NMI_exit                       
        jnz     ke_1                               

        cmp     eax,ke_NMI_U_HANDLED               
                                                   
        jnz     ke_1                               

ke_end:                                            
        RestoreReg <edi,esi,ecx,edx,ebx,gs,fs,es,ds> 
        popf                                       

        nop                                        

        endm                                       


