Page 60,132 Title Descriptor Cache Anomalies ;----------------------------------------------------------------------------- ; ; DESCRIPT.ASM ; ; Copyright (c) 1991, 1995-Present Robert Collins ; ; You have my permission to copy and distribute this software for ; non-commercial purposes. Any commercial use of this software or ; source code is allowed, so long as the appropriate copyright ; attributions (to me) are intact, *AND* my email address is properly ; displayed. ; ; Basically, give me credit, where credit is due, and show my email ; address. ; ;----------------------------------------------------------------------------- ; ; Robert R. Collins email: rcollins@x86.org ; ;----------------------------------------------------------------------------- ; ; DESCRIPT.ASM -- Prove that anomalies exist in the real mode definition of ; the descriptor cache registers. Intel states that all of ; these registers get default, fixed values when loaded in ; real mode. This is not the case, and this source code ; will attempt to prove that. ; ;----------------------------------------------------------------------------- ; ; This code was written for, and compiled with Microsoft MASM 5.1 (actually ; 5.10A). MASM 6.0 has some anomalies with respect to equate definitions ; and will not work with this source code. ; ;----------------------------------------------------------------------------- ; ; +-----------------------------------------------+ ; | Descriptor Cache contents: Real-Mode | ; | | ; | Operand size(*)-------------------------+ | ; | Granularity(*)------------------------+ | | ; | Accessed----------------------------+ | | | ; | Read/Write------------------------+ | | | | ; | Expansion direction-------------+ | | | | | ; | Executable--------------------+ | | | | | | ; | Code/Data Segment?----------+ | | | | | | | ; | Privilege level----------++ | | | | | | | | ; | Present----------------+ || | | | | | | | | ; | | || | | | | | | | | ; | Base Addr Limit | || | | | | | | | | ; | ---+------------+---------+-+--+-+-+-+-+-+-+-+| ; | CS |16xSeg. Reg.| Honored |Y| H|Y|0|0|1|Y|-|H|| ; | ---+------------+---------+-+--+-+-+-+-+-+-+-+| ; | SS |16xSeg. Reg.| Honored |H| H|Y|H|H|H|Y|-|-|| ; | ---+------------+---------+-+--+-+-+-+-+-+-+-+| ; | DS |16xSeg. Reg.| Honored |H| H|Y|H|H|H|Y|-|-|| ; | ---+------------+---------+-+--+-+-+-+-+-+-+-+| ; | ES |16xSeg. Reg.| Honored |H| H|Y|H|H|H|Y|-|-|| ; | ===+============+=========+=+==+=+=+=+=+=+=+=+| ; | FS |16xSeg. Reg.| Honored |H| H|Y|H|H|H|Y|-|-|| ; | ---+------------+---------+-+--+-+-+-+-+-+-+-+| ; | GS |16xSeg. Reg.| Honored |H| H|Y|H|H|H|Y|-|-|| ; | ---+------------+---------+-+--+-+-+-+-+-+-+-+| ; | | ; | Y=Yes (1) | ; | N=No (0) | ; | U=Up (0) | ; | B=Byte (0) (*)=386 and 486 only | ; | S=16-bit (0) (*)=386 and 486 only | ; | H=Honored. Whenever the segment gets loaded, | ; | the contents of this field don't | ; | change. | ; | 0=Set to 0 only with a FAR JuMP instruction. | ; | 1=Set to 1 only with a FAR JuMP instruction. | ; | -=Not applicable | ; | | ; +-----------------------------------------------+ ; ; ;----------------------------------------------------------------------------- ; Compiler directives ;----------------------------------------------------------------------------- .Radix 16 .model small .8086 .xlist ;----------------------------------------------------------------------------- ; Public Declarations ;----------------------------------------------------------------------------- Public Loadall_tbl, SSEG_Ptr, CSEG64, DSEG64 Public SSEG64, CSEG32_Ptr, CS_Size ;----------------------------------------------------------------------------- ; External segment definition ;----------------------------------------------------------------------------- ABS0 SEGMENT AT 0 org 0ch * 4 RMInt0C label dword org 0dh * 4 RMInt0D label dword ABS0 ENDS BIOSDATA SEGMENT AT 40h org 67h Shut_Restart label dword BIOSDATA ENDS .386P ;----------------------------------------------------------------------------- ; Include data structures, equates, and local variables ;----------------------------------------------------------------------------- Include Struc.inc ; Include structures Include Macros.inc ; Include macros Include equates.inc ; Include local equates & I/O ports .data .list ;----------------------------------------------------------------------------- ; Loadall table(s) ;----------------------------------------------------------------------------- Loadall_tbl Loadall_struc <> ;----------------------------------------------------------------------------- ; Descriptor Table ;----------------------------------------------------------------------------- GDT_386 Descriptor CSEG64 equ $-Gdt_386 CS_64k Descriptor <0ffffh,0,0,Code_seg_access,00h,0> DSEG64 equ $-Gdt_386 DS_64k Descriptor <0ffffh,0,0,Data_seg_access,00h,0> SSEG64 equ $-Gdt_386 SS_64k Descriptor <0ffffh,0,0,Data_seg_access,00h,0> GDT386_Len equ $-Gdt_386 ;----------------------------------------------------------------------------- ; String messages ;----------------------------------------------------------------------------- DSEG_Desc db "Testing DS, ES, FS, and GS descriptor cache reigsters:" Line_Feed db crlf$ SSEG_Desc db "Testing SS descriptor cache register:",crlf$ CSEG_Desc db "Testing CS descriptor cache register:",crlf$ DS_Limit1 db "Testing DS, ES, FS, GS < 64k (DS=USE16) segment limit Honored: $" DS_Limit2 db "Testing DS, ES, FS, GS > 64k (DS=USE16) segment limit Honored: $" DS_Present db "Testing DS, ES, FS, GS < 64k Present bit Honored: $" DS_RO_UP db "Testing DS, ES, FS, GS < 64k Read-Only Expand UP Honored: $" DS_RO_DWN db "Testing DS, ES, FS, GS < 64k Read-Only Expand DOWN Honored: $" DS_RW_DWN db "Testing DS, ES, FS, GS < 64k Read-Write Expand DOWN Honored: $" AltDS_Pbit1 db "Testing DS, ES, FS, GS < 64k Alt(1) Present bit Honored: $" AltDS_Pbit2 db "Testing DS, ES, FS, GS < 64k Alt(2) Present bit Honored: $" AltDS_RO_UP1 db "Testing DS, ES, FS, GS < 64k Alt(1) R-O Expand UP Honored: $" AltDS_RO_UP2 db "Testing DS, ES, FS, GS < 64k Alt(2) R-O Expand UP Honored: $" DSB_Limit1 db "Testing DS, ES, FS, GS < 64k (DS=USE32) segment limit Honored: $" DSB_Limit2 db "Testing DS, ES, FS, GS > 64k (DS=USE32) segment limit Honored: $" DSB_Present db "Testing DS, ES, FS, GS > 64k Present bit Honored: $" DSB_RO_UP db "Testing DS, ES, FS, GS > 64k Read-Only Expand UP Honored: $" DSB_RO_DWN db "Testing DS, ES, FS, GS > 64k Read-Only Expand DOWN Honored: $" DSB_RW_DWN db "Testing DS, ES, FS, GS > 64k Read-Write Expand DOWN Honored: $" AltDSB_Pbit1 db "Testing DS, ES, FS, GS > 64k Alt(1) Present bit Honored: $" AltDSB_Pbit2 db "Testing DS, ES, FS, GS > 64k Alt(2) Present bit Honored: $" AltDSB_RO_UP1 db "Testing DS, ES, FS, GS > 64k Alt(1) R-O Expand UP Honored: $" AltDSB_RO_UP2 db "Testing DS, ES, FS, GS > 64k Alt(2) R-O Expand UP Honored: $" DPLBit db "Testing CS, DS, ES, FS, GS DPL bits Honored: $" SS_Limit1 db "Testing SS < 64k (SS=USE16) segment limit Honored: $" SS_Limit2 db "Testing SS > 64k (SS=USE16) segment limit Honored: $" SS_Present db "Testing SS < 64k Present Bit causes exception: $" SS_RO_UP db "Testing SS < 64k Read-Only Expand UP Honored: $" SS_RO_DWN db "Testing SS < 64k Read-Only Expand DOWN Honored: $" SS_RW_DWN db "Testing SS < 64k Read-Write Expand DOWN Honored: $" AltSS_Pbit1 db "Testing SS < 64k Alt(1) Present bit Honored: $" AltSS_Pbit2 db "Testing SS < 64k Alt(2) Present bit Honored: $" AltSS_RO_UP1 db "Testing SS < 64k Alt(1) R-O Expand UP Honored: $" AltSS_RO_UP2 db "Testing SS < 64k Alt(2) R-O Expand UP Honored: $" SSB_Limit1 db "Testing SS < 64k (SS=USE32) segment limit Honored: $" SSB_Limit2 db "Testing SS > 64k (SS=USE32) segment limit Honored: $" SSB_Present db "Testing SS > 64k Present Bit causes exception: $" SSB_RO_UP db "Testing SS > 64k Read-Only Expand UP Honored: $" SSB_RO_DWN db "Testing SS > 64k Read-Only Expand DOWN Honored: $" SSB_RW_DWN db "Testing SS > 64k Read-Write Expand DOWN Honored: $" AltSSB_Pbit1 db "Testing SS > 64k Alt(1) Present bit Honored: $" AltSSB_Pbit2 db "Testing SS > 64k Alt(2) Present bit Honored: $" AltSSB_RO_UP1 db "Testing SS > 64k Alt(1) R-O Expand UP Honored: $" AltSSB_RO_UP2 db "Testing SS > 64k Alt(2) R-O Expand UP Honored: $" CS_Limit1 db "Testing CS (USE16) < 64k segment limit Honored: $" CS_Limit2 db "Testing CS (USE16) > 64k segment limit Honored: $" CS_Present db "Testing CS (USE16) < 64k Present Bit causes exception: $" CS_RO_UP db "Testing CS (USE16) < 64k Read-Only Expand UP Honored: $" CS_RO_DWN db "Testing CS (USE16) < 64k Read-Only Expand DOWN Honored: $" CS_RW_DWN db "Testing CS (USE16) < 64k Read-Write Expand DOWN Honored: $" AltCS_Pbit1 db "Testing CS (USE16) < 64k Alt(1) Present bit Honored: $" AltCS_Pbit2 db "Testing CS (USE16) < 64k Alt(2) Present bit Honored: $" AltCS_RO_UP1 db "Testing CS (USE16) < 64k Alt(1) R-O Expand UP Honored: $" AltCS_RO_UP2 db "Testing CS (USE16) < 64k Alt(2) R-O Expand UP Honored: $" CSB_Limit1 db "Testing CS (USE32) < 64k segment limit Honored: $" CSB_Limit2 db "Testing CS (USE32) > 64k segment limit Honored: $" CSB_Present db "Testing CS (USE32) < 64k Present Bit causes exception: $" CSB_RO_UP db "Testing CS (USE32) < 64k Read-Only Expand UP Honored: $" CSB_RO_DWN db "Testing CS (USE32) < 64k Read-Only Expand DOWN Honored: $" CSB_RW_DWN db "Testing CS (USE32) < 64k Read-Write Expand DOWN Honored: $" AltCSB_Pbit1 db "Testing CS (USE32) < 64k Alt(1) Present bit Honored: $" AltCSB_Pbit2 db "Testing CS (USE32) < 64k Alt(2) Present bit Honored: $" AltCSB_RO_UP1 db "Testing CS (USE32) < 64k Alt(1) R-O Expand UP Honored: $" AltCSB_RO_UP2 db "Testing CS (USE32) < 64k Alt(2) R-O Expand UP Honored: $" Passed db " Passed",crlf$ Failed db "==> Failed <==",crlf$ CSEG32_Ptr label fword CSEG_Ptr dd ? dw ? org 2000h dd 90905a5ah .code ASSUME CS:_TEXT, DS:_DATA, ES:_DATA, SS:STACK, FS:Nothing, GS:Nothing ;----------------------------------------------------------------------------- ; A little CS-relative data for the stack pointer. This is ; to avoid using other kludge techniques, caused by using ; LOADALL, that make using the data segment undesirable. ;----------------------------------------------------------------------------- SSEG_Ptr dd 0 SSEG dw 0 DSEG_Ptr dw ? DSEG dw seg _data Include KBC.INC ;----------------------------------------------------------------------------- ; Code starts here ;----------------------------------------------------------------------------- Descriptor_Cache proc far ; Test descriptor cache registers ; ; to varify that contents of these ; ; registers behave differently than ; ; Intel states. ;----------------------------------------------------------------------------- ; Input: None ; Output: ; Register(s) modified: ALL ;----------------------------------------------------------------------------- PUSH DS ; Setup the stack to XOR AX,AX ; return to DOS PUSH AX MOV AX,_Data MOV DS,AX MOV ES,AX ;----------------------------------------------------------------------------- ; Initialize all descriptor table entries ;----------------------------------------------------------------------------- pushf cli enter 20h,0 ; create a small stack frame Init_Descriptor ,,Gdt_386 Init_Descriptor CS,0,CS_64k Init_Descriptor DS,0,DS_64k Init_Descriptor SS,0,SS_64k ;----------------------------------------------------------------------------- ; Prepare the LOADALL table ;----------------------------------------------------------------------------- mov eax,cs ; Prepare a 32-bit physical address mov Loadall_tbl._CS,eax ; that is put in the LOADALL table shl eax,4 ; mov Loadall_tbl.CS_Cache._Addr,eax mov eax,ds ; Prepare a 32-bit physical address mov Loadall_tbl._DS,eax ; that is put in the LOADALL table shl eax,4 ; mov Loadall_tbl.DS_Cache._Addr,eax mov eax,es ; Prepare a 32-bit physical address mov Loadall_tbl._ES,eax ; that is put in the LOADALL table shl eax,4 ; mov Loadall_tbl.ES_Cache._Addr,eax mov eax,ds ; Prepare a 32-bit physical address mov Loadall_tbl._FS,eax ; that is put in the LOADALL table shl eax,4 ; mov Loadall_tbl.FS_Cache._Addr,eax mov eax,ds ; Prepare a 32-bit physical address mov Loadall_tbl._GS,eax ; that is put in the LOADALL table shl eax,4 ; mov Loadall_tbl.GS_Cache._Addr,eax mov eax,ss ; Prepare a 32-bit physical address mov Loadall_tbl._SS,eax ; that is put in the LOADALL table shl eax,4 ; mov Loadall_tbl.SS_Cache._Addr,eax ;----------------------------------------------------------------------------- ; Initialize the GDT & IDT descriptor cache ;----------------------------------------------------------------------------- mov eax,Loadall_tbl.DS_Cache._Addr mov ebx,eax add eax,offset Gdt_386 mov Loadall_tbl.GDT_Cache._Addr,eax mov Loadall_tbl.GDT_Cache._Limit,Gdt386_len-1 mov eax,cr0 ; Initialize CR0 in the and eax,0fffffff0h ; LOADALL data table mov Loadall_tbl._CR0,eax ; DR6, DR7, EIP mov eax,dr6 mov ebx,dr7 mov Loadall_tbl._DR6,eax mov Loadall_tbl._DR7,ebx mov Loadall_tbl._EBP,ebp mov Loadall_tbl._ESP,esp mov Loadall_tbl._EIP,offset @F mov dword ptr cs:SSEG_Ptr,esp ; save SS:ESP mov word ptr cs:SSEG_Ptr[4],ss mov edi,offset loadall_tbl LOADALL ;----------------------------------------------------------------------------- ; All tests have the following general format: ; 1) Load a temporary (applicable) interrupt handler ; 2) Print the message indicating which test ; 3) Set flags, counters used in test ; 4) Load the LOADALL data image with the applicable access rights/limit ; 5) LOADALL to directly manipulate the CPU ; 6) Attempt to generate exception to verify CPU behavior ; ; 6b - 6d are only applicable to 2-part tests ; 6b) Change LOADALL image ; 6c) LOADALL to directly manipulate the CPU ; 6d) Attempt to generate exception to verify CPU behavior ; ; 7) Restore CPU back into a 'real-mode' compatible state ; 8) Get test status/clear test status ; 9) Restore LOADALL image to 'real-mode' compatible state ; 10) Print results of test. ;----------------------------------------------------------------------------- ; Test DS, ES, FS, and GS data segment attributes. ;----------------------------------------------------------------------------- @@: mov INT_SAVE,offset Trap13 mov INT_SAVE[2],cs mov bx,offset RMInt0D call Swap_INT Print_string ;----------------------------------------------------------------------------- ; 1) Test segment limit honored < 64k ; Access Rights = 93h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,93h ; Access attributes mov ah,0 ; SMALL attribute mov bl,00001111b ; Expected results mov ecx,001fffh ; segment limit mov esi,001ffeh ; test withing segment bounds mov edi,002000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 2) Test segment limit honored < 64k ; Access Rights = 93h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,93h ; Access attributes mov ah,40h ; BIG attribute mov bl,00001111b ; Expected results mov ecx,001fffh ; segment limit mov esi,001ffeh ; test withing segment bounds mov edi,002000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 3) Test segment Present bit=0 causes exception ; Access Rights = 13h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,13h ; Access attributes mov ah,0 ; SMALL attribute mov bl,11111111b ; Expected results mov ecx,001fffh ; segment limit mov esi,001ffeh ; test withing segment bounds mov edi,002000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 4) Test R-O expand UP segments aren't affected by segment register loads. ; Access Rights = 90h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,90h ; Access attributes mov ah,0 ; SMALL attribute mov bl,00111111b ; Expected results mov ecx,001fffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,00f000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 5) Test R-O expand DOWN segments aren't affected by segment register loads. ; Access Rights = 94h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,94h ; Access attributes mov ah,0 ; SMALL attribute mov bl,11110011b ; Expected results mov ecx,001fffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,00f000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 6) Test R-W expand DOWN segments aren't affected by segment register loads. ; Access Rights = 96h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,96h ; Access attributes mov ah,0 ; SMALL attribute mov bl,11110000b ; Expected results mov ecx,001fffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,00f000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 7) Test Alternate(1) segment attributes can be set such that the segment ; is inaccessible. ; Access Rights = 98h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,98h ; Access attributes mov ah,0 ; SMALL attribute mov bl,11111111b ; Expected results mov ecx,001fffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,00f000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 8) Test Alternate(1) segment attributes can be set such that the segment ; is the same as R-O expand UP. ; Access Rights = 9Ah ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,9ah ; Access attributes mov ah,0 ; SMALL attribute mov bl,00111111b ; Expected results mov ecx,001fffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,00f000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 9) Test Alternate(2) segment attributes can be set such that the segment ; is inaccessible. ; Access Rights = 9Ch ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,9ch ; Access attributes mov ah,0 ; SMALL attribute mov bl,11111111b ; Expected results mov ecx,001fffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,00f000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 10) Test Alternate(2) segment attributes can be set such that the segment ; is the same as R-O expand UP. ; Access Rights = 9Eh ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,9eh ; Access attributes mov ah,0 ; SMALL attribute mov bl,00111111b ; Expected results mov ecx,001fffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,00f000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 11) Test segment limit honored > 64k ; Access Rights = 93h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,93h ; Access attributes mov ah,00h ; SMALL attribute mov bl,00001111b ; Expected results mov ecx,0fffffh ; segment limit mov esi,0ffffeh ; test withing segment bounds mov edi,100000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 12) Test segment limit honored > 64k ; Access Rights = 93h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,93h ; Access attributes mov ah,40h ; BIG attribute mov bl,00001111b ; Expected results mov ecx,0fffffh ; segment limit mov esi,0ffffeh ; test withing segment bounds mov edi,100000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 13) Test segment Present bit=0 causes exception ; Access Rights = 13h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,13h ; Access attributes mov ah,40h ; BIG attribute mov bl,11111111b ; Expected results mov ecx,0fffffh ; segment limit mov esi,0ffffeh ; test withing segment bounds mov edi,100000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 14) Test R-O expand UP segments aren't affected by segment register loads. ; Access Rights = 90h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,90h ; Access attributes mov ah,40h ; BIG attribute mov bl,00111111b ; Expected results mov ecx,0fffffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,180000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 15) Test R-O expand DOWN segments aren't affected by segment register loads. ; Access Rights = 94h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,94h ; Access attributes mov ah,40h ; BIG attribute mov bl,11110011b ; Expected results mov ecx,0fffffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,180000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 16) Test R-W expand DOWN segments aren't affected by segment register loads. ; Access Rights = 96h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,96h ; Access attributes mov ah,40h ; BIG attribute mov bl,11110000b ; Expected results mov ecx,0fffffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,180000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 17) Test Alternate(1) segment attributes can be set such that the segment ; is inaccessible. ; Access Rights = 98h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,98h ; Access attributes mov ah,40h ; BIG attribute mov bl,11111111b ; Expected results mov ecx,0fffffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,180000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 18) Test Alternate(1) segment attributes can be set such that the segment ; is the same as R-O expand UP. ; Access Rights = 9Ah ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,9ah ; Access attributes mov ah,40h ; BIG attribute mov bl,00111111b ; Expected results mov ecx,0fffffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,180000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 19) Test Alternate(2) segment attributes can be set such that the segment ; is inaccessible. ; Access Rights = 9Ch ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,9ch ; Access attributes mov ah,40h ; BIG attribute mov bl,11111111b ; Expected results mov ecx,0fffffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,180000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; 20) Test Alternate(2) segment attributes can be set such that the segment ; is the same as R-O expand UP. ; Access Rights = 9Eh ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,9eh ; Access attributes mov ah,40h ; BIG attribute mov bl,00111111b ; Expected results mov ecx,0fffffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,180000h ; test beyond segment bounds call Test_DSEG_Attr Pass_Fail 11111111b ;----------------------------------------------------------------------------- ; All data segment access tests are complete, restore the original GP ; exception handler (vector). ;----------------------------------------------------------------------------- mov bx,offset RMInt0D call Swap_INT Print_String ;----------------------------------------------------------------------------- ; Test SS descriptor cache register. ;----------------------------------------------------------------------------- mov bx,offset RMInt0C call Swap_INT Print_string ;----------------------------------------------------------------------------- ; 1) Test segment limit honored < 64k ; Access Rights = 93h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,93h ; Access attributes mov ah,0 ; SMALL attribute mov bl,0011b ; Expected results mov ecx,001fffh ; segment limit mov esi,001ffeh ; test withing segment bounds mov edi,002000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 2) Test segment limit honored < 64k ; Access Rights = 93h ; Big_Segment = 40h (small) ;----------------------------------------------------------------------------- Print_String mov al,93h ; Access attributes mov ah,40h ; BIG attribute mov bl,0011b ; Expected results mov ecx,001fffh ; segment limit mov esi,001ffeh ; test withing segment bounds mov edi,002000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 3) Test segment Present bit=0 causes exception ; Access Rights = 13h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,13h ; Access attributes mov ah,0 ; SMALL attribute mov bl,1111b ; Expected results mov ecx,001fffh ; segment limit mov esi,001ffeh ; test withing segment bounds mov edi,002000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 4) Test R-O expand UP segments aren't affected by segment register loads. ; Access Rights = 90h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,90h ; Access attributes mov ah,0 ; SMALL attribute mov bl,0111b ; Expected results mov ecx,001fffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,00f000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 5) Test R-O expand DOWN segments aren't affected by segment register loads. ; Access Rights = 94h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,94h ; Access attributes mov ah,0 ; SMALL attribute mov bl,1101b ; Expected results mov ecx,001fffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,00f000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 6) Test R-W expand DOWN segments aren't affected by segment register loads. ; Access Rights = 96h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,96h ; Access attributes mov ah,0 ; SMALL attribute mov bl,1100b ; Expected results mov ecx,size stk ; segment limit mov esi,(size stk) / 2 ; test withing segment bounds mov edi,(size stk) * 2 ; test beyond segment bounds movzx edx,sp ; get current stack pointer add edx,size stk ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 7) Test Alternate(1) segment attributes can be set such that the segment ; is inaccessible. ; Access Rights = 98h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,98h ; Access attributes mov ah,0 ; SMALL attribute mov bl,1111b ; Expected results mov ecx,001fffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,00f000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 8) Test Alternate(1) segment attributes can be set such that the segment ; is the same as R-O expand UP. ; Access Rights = 9Ah ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,9ah ; Access attributes mov ah,0 ; SMALL attribute mov bl,0111b ; Expected results mov ecx,001fffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,00f000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 9) Test Alternate(2) segment attributes can be set such that the segment ; is inaccessible. ; Access Rights = 9Ch ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,9ch ; Access attributes mov ah,0 ; SMALL attribute mov bl,1111b ; Expected results mov ecx,001fffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,00f000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 10) Test Alternate(2) segment attributes can be set such that the segment ; is the same as R-O expand UP. ; Access Rights = 9Eh ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,9eh ; Access attributes mov ah,0 ; SMALL attribute mov bl,0111b ; Expected results mov ecx,001fffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,00f000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 11) Test segment limit honored > 64k ; Access Rights = 93h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov al,93h ; Access attributes mov ah,00h ; SMALL attribute mov bl,0011b ; Expected results mov ecx,0fffffh ; segment limit mov esi,0ffffeh ; test withing segment bounds mov edi,100000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 12) Test segment limit honored > 64k ; Access Rights = 93h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,93h ; Access attributes mov ah,40h ; BIG attribute mov bl,0011b ; Expected results mov ecx,0fffffh ; segment limit mov esi,0ffffeh ; test withing segment bounds mov edi,100000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 13) Test segment Present bit=0 causes exception ; Access Rights = 13h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,13h ; Access attributes mov ah,40h ; BIG attribute mov bl,1111b ; Expected results mov ecx,0fffffh ; segment limit mov esi,0ffffeh ; test withing segment bounds mov edi,100000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 14) Test R-O expand UP segments aren't affected by segment register loads. ; Access Rights = 90h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,90h ; Access attributes mov ah,40h ; BIG attribute mov bl,0111b ; Expected results mov ecx,0fffffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,180000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 15) Test R-O expand DOWN segments aren't affected by segment register loads. ; Access Rights = 94h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,94h ; Access attributes mov ah,40h ; BIG attribute mov bl,1101b ; Expected results mov ecx,0fffffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,180000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 16) Test R-W expand DOWN segments aren't affected by segment register loads. ; Access Rights = 96h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,96h ; Access attributes mov ah,40h ; BIG attribute mov bl,1100b ; Expected results mov ecx,size stk ; segment limit mov esi,(size stk) / 2 ; test withing segment bounds mov edi,(size stk)[18000h] ; test beyond segment bounds movzx edx,sp ; get current stack pointer add edx,size stk ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 17) Test Alternate(1) segment attributes can be set such that the segment ; is inaccessible. ; Access Rights = 98h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,98h ; Access attributes mov ah,40h ; BIG attribute mov bl,1111b ; Expected results mov ecx,0fffffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,180000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 18) Test Alternate(1) segment attributes can be set such that the segment ; is the same as R-O expand UP. ; Access Rights = 9Ah ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,9ah ; Access attributes mov ah,40h ; BIG attribute mov bl,0111b ; Expected results mov ecx,0fffffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,180000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 19) Test Alternate(2) segment attributes can be set such that the segment ; is inaccessible. ; Access Rights = 9Ch ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,9ch ; Access attributes mov ah,40h ; BIG attribute mov bl,1111b ; Expected results mov ecx,0fffffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,180000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; 20) Test Alternate(2) segment attributes can be set such that the segment ; is the same as R-O expand UP. ; Access Rights = 9Eh ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov al,9eh ; Access attributes mov ah,40h ; BIG attribute mov bl,0111b ; Expected results mov ecx,0fffffh ; segment limit mov esi,001000h ; test withing segment bounds mov edi,180000h ; test beyond segment bounds mov edx,(size stk) / 2 ; value of ESP within test call Test_SSEG_Attr Pass_Fail 1111b ;----------------------------------------------------------------------------- ; All data segment access tests are complete, restore the original GP ; exception handler (vector). ;----------------------------------------------------------------------------- mov bx,offset RMInt0C call Swap_INT Print_String Print_string ;----------------------------------------------------------------------------- ; Test CS descriptor cache register. ;----------------------------------------------------------------------------- ; 1) Test segment limit honored < 64k ; Access Rights = 93h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,93h ; Access attributes mov ah,0 ; SMALL attribute mov bl,0011b ; Expected results mov cx,CS_Size - 1 ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,CS_Size / 2 ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11111b ;----------------------------------------------------------------------------- ; 2) Test segment limit honored < 64k ; Access Rights = 93h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,93h ; Access attributes mov ah,40h ; LARGE attribute mov bl,0011b ; Expected results mov cx,(CS_Size - 1)+1000h ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,(CS_Size / 2)+1000h ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size+1000h ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11111b ;----------------------------------------------------------------------------- ; 3) Test segment Present bit=0 causes exception ; Access Rights = 13h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,13h ; Access attributes mov ah,0 ; SMALL attribute mov bl,0001b ; Expected results mov cx,CS_Size - 1 ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,CS_Size / 2 ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 00001b ;----------------------------------------------------------------------------- ; 4) Test R-O expand UP segments aren't affected by segment register loads. ; Access Rights = 90h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,90h ; Access attributes mov ah,0 ; SMALL attribute mov bl,0111b ; Expected results mov cx,CS_Size - 1 ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,CS_Size / 2 ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11110b ;----------------------------------------------------------------------------- ; 5) Test R-O expand DOWN segments aren't affected by segment register loads. ; Access Rights = 94h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov ax,-CS_Size movzx eax,ax mov Expansion_BIAS,eax ; not testing expansion direction mov al,94h ; Access attributes mov ah,0 ; SMALL attribute mov bl,1101b ; Expected results mov cx,CS_Size - 1 ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,CS_Size / 2 ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11110b ;----------------------------------------------------------------------------- ; 6) Test R-W expand DOWN segments aren't affected by segment register loads. ; Access Rights = 96h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov ax,-CS_Size movzx eax,ax mov Expansion_BIAS,eax ; not testing expansion direction mov al,96h ; Access attributes mov ah,0 ; SMALL attribute mov bl,1100b ; Expected results mov cx,CS_Size - 1 ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,CS_Size / 2 ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11110b ;----------------------------------------------------------------------------- ; 7) Test Alternate(1) segment attributes can be set such that the segment ; is inaccessible. ; Access Rights = 98h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,98h ; Access attributes mov ah,0 ; SMALL attribute mov bl,1111b ; Expected results mov cx,CS_Size - 1 ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,CS_Size / 2 ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11110b ;----------------------------------------------------------------------------- ; 8) Test Alternate(1) segment attributes can be set such that the segment ; is the same as R-O expand UP. ; Access Rights = 9Ah ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,9ah ; Access attributes mov ah,0 ; SMALL attribute mov bl,0111b ; Expected results mov cx,CS_Size - 1 ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,CS_Size / 2 ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11110b ;----------------------------------------------------------------------------- ; 9) Test Alternate(2) segment attributes can be set such that the segment ; is inaccessible. ; Access Rights = 9Ch ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,9ch ; Access attributes mov ah,0 ; SMALL attribute mov bl,1111b ; Expected results mov cx,CS_Size - 1 ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,CS_Size / 2 ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11110b ;----------------------------------------------------------------------------- ; 10) Test Alternate(2) segment attributes can be set such that the segment ; is the same as R-O expand UP. ; Access Rights = 9Eh ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,9eh ; Access attributes mov ah,0 ; SMALL attribute mov bl,0111b ; Expected results mov cx,CS_Size - 1 ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,CS_Size / 2 ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11110b ;----------------------------------------------------------------------------- ; 11) Test segment limit honored > 64k ; Access Rights = 93h ; Big_Segment = 00h (small) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,93h ; Access attributes mov ah,00h ; small attribute mov bl,0011b ; Expected results mov ecx,0fffffh ; segment limit mov si,CS_Size / 2 ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility lea edi,[edi][100000h] ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11111b ;----------------------------------------------------------------------------- ; 12) Test segment limit honored > 64k ; Access Rights = 93h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,93h ; Access attributes mov ah,40h ; large attribute mov bl,0011b ; Expected results mov ecx,0fffffh ; segment limit mov si,(CS_Size / 2)+1000h ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size+1000h ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility lea edi,[edi][100000h] ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11111b ;----------------------------------------------------------------------------- ; 13) Test segment Present bit=0 causes exception ; Access Rights = 13h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,13h ; Access attributes mov ah,40h ; LARGE attribute mov bl,0001b ; Expected results mov cx,(CS_Size - 1)+1000h ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,(CS_Size / 2)+1000h ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size+1000h ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 00001b ;----------------------------------------------------------------------------- ; 14) Test R-O expand UP segments aren't affected by segment register loads. ; Access Rights = 90h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,90h ; Access attributes mov ah,40h ; LARGE attribute mov bl,0111b ; Expected results mov cx,(CS_Size - 1)+1000h ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,(CS_Size / 2)+1000h ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size+1000h ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11110b ;----------------------------------------------------------------------------- ; 15) Test R-O expand DOWN segments aren't affected by segment register loads. ; Access Rights = 94h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov ax,-(CS_Size+1000h) movzx eax,ax mov Expansion_BIAS,eax ; not testing expansion direction mov al,94h ; Access attributes mov ah,40h ; LARGE attribute mov bl,1101b ; Expected results mov cx,(CS_Size - 1)+1000h ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,(CS_Size / 2)+1000h ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size+1000h ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11110b ;----------------------------------------------------------------------------- ; 16) Test R-W expand DOWN segments aren't affected by segment register loads. ; Access Rights = 96h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov ax,-(CS_Size+1000h) movzx eax,ax mov Expansion_BIAS,eax ; not testing expansion direction mov al,96h ; Access attributes mov ah,40h ; LARGE attribute mov bl,1100b ; Expected results mov cx,(CS_Size - 1)+1000h ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,(CS_Size / 2)+1000h ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size+1000h ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11110b ;----------------------------------------------------------------------------- ; 17) Test Alternate(1) segment attributes can be set such that the segment ; is inaccessible. ; Access Rights = 98h ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,98h ; Access attributes mov ah,40h ; LARGE attribute mov bl,1111b ; Expected results mov cx,(CS_Size - 1)+1000h ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,(CS_Size / 2)+1000h ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size+1000h ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11110b ;----------------------------------------------------------------------------- ; 18) Test Alternate(1) segment attributes can be set such that the segment ; is the same as R-O expand UP. ; Access Rights = 9Ah ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,9ah ; Access attributes mov ah,40h ; LARGE attribute mov bl,0111b ; Expected results mov cx,(CS_Size - 1)+1000h ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,(CS_Size / 2)+1000h ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size+1000h ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11110b ;----------------------------------------------------------------------------- ; 19) Test Alternate(2) segment attributes can be set such that the segment ; is inaccessible. ; Access Rights = 9Ch ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,9ch ; Access attributes mov ah,40h ; LARGE attribute mov bl,1111b ; Expected results mov cx,(CS_Size - 1)+1000h ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,(CS_Size / 2)+1000h ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size+1000h ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11110b ;----------------------------------------------------------------------------- ; 20) Test Alternate(2) segment attributes can be set such that the segment ; is the same as R-O expand UP. ; Access Rights = 9Eh ; Big_Segment = 40h (large) ;----------------------------------------------------------------------------- Print_String mov Expansion_BIAS,0 ; not testing expansion direction mov al,9eh ; Access attributes mov ah,40h ; LARGE attribute mov bl,0111b ; Expected results mov cx,(CS_Size - 1)+1000h ; segment limit -- using two instr. movzx ecx,cx ; for MASM 5.1 compatibility mov si,(CS_Size / 2)+1000h ; test withing segment bounds movzx esi,si ; for MASM 5.1 compatibility mov di,CS_Size+1000h ; test beyond segment bounds movzx edi,di ; for MASM 5.1 compatibility call Test_CSEG16_Attr Pass_Fail 11110b Test_Exit: leave ; restore the stack frame popf retf Descriptor_Cache endp ;----------------------------------------------------------------------------- ; Include segment descriptor test subroutines ;----------------------------------------------------------------------------- Include TestDSEG.inc ; subroutine used to test DS, ES, FS, & GS Include TestSSEG.inc ; subroutine used to test SS Include TestCSEG.inc ; subroutine used to test CS ;----------------------------------------------------------------------------- Trap13: ; INT 0D (GP) fault trap ;----------------------------------------------------------------------------- ; Input: SI = Pointer to return address ; Output: CY ; Register(s) modified: EFLAGS ;----------------------------------------------------------------------------- enter 0,0 ; get pointer to CS:IP mov [bp][2],si stc leave retf 2 ;----------------------------------------------------------------------------- SWAP_INT proc near ; Swap interrupt vectors ;----------------------------------------------------------------------------- ; Input: [BP-4] = New interrupt vector ; BX = Pointer to interrupt vector @ ABS0 ; Output: [BP-4] = Filled in with old interrupt vector ; Register(s) modified: DX ;----------------------------------------------------------------------------- push ds mov dx,seg ABS0 ; save interrupt vector segment mov ds,dx ; make DS=INT vector segment ASSUME DS:ABS0 mov dx,INT_SAVE ; get offset if INT0 handler xchg [bx],dx ; set new INT0 offset mov INT_SAVE,dx mov dx,INT_SAVE[2] ; get segment of INT0 handler xchg [bx][2],dx ; set new INT0 segment mov INT_SAVE[2],dx pop ds ; restore segment register ret ; split ASSUME DS:NOTHING Swap_INT endp CS16_Size equ $-SSEG_Ptr CS_Size equ ((CS16_Size+1000h)/1000h)*1000h .stack ;----------------------------------------------------------------------------- ; Stack segment definition ;----------------------------------------------------------------------------- stk dw 800h dup (0) ; 4k stack segment END DESCRIPTOR_CACHE