;----------------------------------------------------------------------------- ; Equates & macros ;----------------------------------------------------------------------------- v86 equ (v86_Context ptr ss:[esp]) CRLF$ equ 0dh,0ah,24h ;----------------------------------------------------------------------------- ENTERPM MACRO ;----------------------------------------------------------------------------- lgdt GDT_386 ; reload GDT mov edx,cr0 ; go into protected mode or dl,1 ; set PE bit mov cr0,edx ; now in protected mode jmp @F ; now out of protected mode @@: ENDM ;----------------------------------------------------------------------------- EXITPM MACRO ;----------------------------------------------------------------------------- mov edx,cr0 ; go into protected mode and dl,not 1 ; kill PE bit mov cr0,edx ; jmp far ptr @F ; now out of protected mode @@: ENDM ICEBP MACRO db 0f1h endm JMPFAR MACRO destination,selector ; dynamic JMP FAR SEG:OFF db 0eah ;; jmp instruction dw offset destination ;; offset word dw selector ;; segment selector word endm ;----------------------------------------------------------------------------- INIT_GDT MACRO ;; Setup descriptor table ;----------------------------------------------------------------------------- mov eax,seg GDT_SEG ; make pointer to GDT table shl eax,4 ; have physical address of segment add eax,offset GDT_386 ; now have physical addr of table mov GDT_PTR.Seg_limit,GDT_Len ; set length mov GDT_PTR.Base_A15_A00,ax shr eax,10h ; get other address bits mov GDT_PTR.Base_A23_A16,al mov GDT_PTR.Access_rights,ah mov eax,cs ; get CS shl eax,4 ; now have physical address mov GDT_CPL0CS.Base_A15_A00,ax shr eax,10h ; get other address bits mov GDT_CPL0CS.Base_A23_A16,al mov GDT_CPL0CS.Base_A31_A24,ah mov eax,seg Code3 ; get CS shl eax,4 ; now have physical address mov GDT_IDTCS.Base_A15_A00,ax shr eax,10h ; get other address bits mov GDT_IDTCS.Base_A23_A16,al mov GDT_IDTCS.Base_A31_A24,ah mov eax,seg IDT_SEG ; get CS shl eax,4 ; now have physical address mov GDT_IDTDS.Base_A15_A00,ax shr eax,10h ; get other address bits mov GDT_IDTDS.Base_A23_A16,al mov GDT_IDTDS.Base_A31_A24,ah mov eax,ds ; get DS shl eax,4 ; now have physical address mov GDT_CPL0DS.Base_A15_A00,ax shr eax,10h ; get other address bits mov GDT_CPL0DS.Base_A23_A16,al mov GDT_CPL0DS.Base_A31_A24,ah mov eax,seg Stack2 ; get SS shl eax,4 ; now have physical address mov GDT_CPL0SS.Base_A15_A00,ax shr eax,10h ; get other address bits mov GDT_CPL0SS.Base_A23_A16,al mov GDT_CPL0SS.Base_A31_A24,ah mov eax,ss ; get SS shl eax,4 ; now have physical address mov GDT_RMSS.Base_A15_A00,ax shr eax,10h ; get other address bits mov GDT_RMSS.Base_A23_A16,al mov GDT_RMSS.Base_A31_A24,ah ENDM ;----------------------------------------------------------------------------- INIT_TSS MACRO ;; Setup TSS ;----------------------------------------------------------------------------- mov eax,seg TSS_SEG ; get DS mov fs,ax ; set segment shl eax,4 ; now have physical address add eax,offset TSS_386 ; get TSS pointer mov GDT_TSS386.Base_A15_A00,ax mov GDT_TSSDS.Base_A15_A00,ax shr eax,10h ; get other address bits mov GDT_TSS386.Base_A23_A16,al mov GDT_TSS386.Base_A31_A24,ah mov GDT_TSSDS.Base_A23_A16,al mov GDT_TSSDS.Base_A31_A24,ah mov GDT_TSS386.Seg_limit,TSS_Len mov GDT_TSSDS.Seg_limit,TSS_Len mov TSS_386.TSS_SS0,SEL_CPL0SS mov TSS_386.TSS_ESP0,Stack2Len - 28h mov eax,offset IOP_MAP shl eax,10h mov TSS_386.TSS_T_IOMAP,eax ENDM ;----------------------------------------------------------------------------- INIT_IDT MACRO ;; Setup IDT ;----------------------------------------------------------------------------- mov eax,seg IDT_SEG ; make pointer to IDT table shl eax,4 ; have physical address of segment add eax,offset IDT_386 ; now have physical addr of table mov dword ptr IDT3_Ptr[2],eax ENDM