src/emu/cpu/i386/i386op16.c
| r10379 | r10380 | |
| 2814 | 2814 | UINT32 address, ea; |
| 2815 | 2815 | UINT8 modrm = FETCH(cpustate); |
| 2816 | 2816 | I386_SREG seg; |
| 2817 | UINT8 result; |
| 2817 | 2818 | |
| 2818 | 2819 | switch( (modrm >> 3) & 0x7 ) |
| 2819 | 2820 | { |
| r10379 | r10380 | |
| 2903 | 2904 | } |
| 2904 | 2905 | break; |
| 2905 | 2906 | |
| 2907 | case 4: /* VERR */ |
| 2908 | if ( PROTECTED_MODE && !V8086_MODE ) |
| 2909 | { |
| 2910 | result = 1; |
| 2911 | if( modrm >= 0xc0 ) { |
| 2912 | address = LOAD_RM16(modrm); |
| 2913 | CYCLES(cpustate,CYCLES_VERR_REG); |
| 2914 | } else { |
| 2915 | ea = GetEA(cpustate,modrm); |
| 2916 | address = READ16(cpustate,ea); |
| 2917 | CYCLES(cpustate,CYCLES_VERR_MEM); |
| 2918 | } |
| 2919 | memset(&seg, 0, sizeof(seg)); |
| 2920 | seg.selector = address; |
| 2921 | i386_load_protected_mode_segment(cpustate,&seg); |
| 2922 | // check if the segment is within the bounds of the GDT or LDT |
| 2923 | if(seg.selector & 0x04) |
| 2924 | { // LDT |
| 2925 | if((seg.selector & 0xf8) > cpustate->ldtr.limit) |
| 2926 | { |
| 2927 | result = 0; |
| 2928 | } |
| 2929 | } |
| 2930 | else |
| 2931 | { // GDT |
| 2932 | if((seg.selector & 0xf8) > cpustate->gdtr.limit) |
| 2933 | { |
| 2934 | result = 0; |
| 2935 | } |
| 2936 | } |
| 2937 | // check if the segment is a code or data segment (not a special segment type, like a TSS, gate, LDT...) |
| 2938 | if(!(seg.flags & 0x10)) |
| 2939 | result = 0; |
| 2940 | // check that the segment is readable |
| 2941 | if(seg.flags & 0x10) // is code or data segment |
| 2942 | { |
| 2943 | if(seg.flags & 0x08) // is code segment, so check if it's readable |
| 2944 | { |
| 2945 | if(!(seg.flags & 0x02)) |
| 2946 | { |
| 2947 | result = 0; |
| 2948 | } |
| 2949 | else |
| 2950 | { // check if conforming, these are always readable, regardless of privilege |
| 2951 | if(!(seg.flags & 0x04)) |
| 2952 | { |
| 2953 | // if not conforming, then we must check privilege levels (TODO: current privilege level check) |
| 2954 | if(((seg.flags >> 5) & 0x03) < (address & 0x03)) |
| 2955 | result = 0; |
| 2956 | } |
| 2957 | } |
| 2958 | } |
| 2959 | } |
| 2960 | // check that the descriptor privilege is greater or equal to the selector's privilege level and the current privilege (TODO) |
| 2961 | SetZF(result); |
| 2962 | } |
| 2963 | else |
| 2964 | { |
| 2965 | i386_trap(cpustate,6, 0); |
| 2966 | logerror("i386: VERR: Exception - Running in real mode or virtual 8086 mode.\n"); |
| 2967 | } |
| 2968 | break; |
| 2969 | |
| 2970 | case 5: /* VERW */ |
| 2971 | if ( PROTECTED_MODE && !V8086_MODE ) |
| 2972 | { |
| 2973 | result = 1; |
| 2974 | if( modrm >= 0xc0 ) { |
| 2975 | address = LOAD_RM16(modrm); |
| 2976 | CYCLES(cpustate,CYCLES_VERW_REG); |
| 2977 | } else { |
| 2978 | ea = GetEA(cpustate,modrm); |
| 2979 | address = READ16(cpustate,ea); |
| 2980 | CYCLES(cpustate,CYCLES_VERW_MEM); |
| 2981 | } |
| 2982 | memset(&seg, 0, sizeof(seg)); |
| 2983 | seg.selector = address; |
| 2984 | i386_load_protected_mode_segment(cpustate,&seg); |
| 2985 | // check if the segment is within the bounds of the GDT or LDT |
| 2986 | if(seg.selector & 0x04) |
| 2987 | { // LDT |
| 2988 | if((seg.selector & 0xf8) > cpustate->ldtr.limit) |
| 2989 | { |
| 2990 | result = 0; |
| 2991 | } |
| 2992 | } |
| 2993 | else |
| 2994 | { // GDT |
| 2995 | if((seg.selector & 0xf8) > cpustate->gdtr.limit) |
| 2996 | { |
| 2997 | result = 0; |
| 2998 | } |
| 2999 | } |
| 3000 | // check if the segment is a code or data segment (not a special segment type, like a TSS, gate, LDT...) |
| 3001 | if(!(seg.flags & 0x10)) |
| 3002 | result = 0; |
| 3003 | // check that the segment is writable |
| 3004 | if(seg.flags & 0x10) // is code or data segment |
| 3005 | { |
| 3006 | if(seg.flags & 0x08) // is code segment (and thus, not writable) |
| 3007 | { |
| 3008 | result = 0; |
| 3009 | } |
| 3010 | else |
| 3011 | { // is data segment |
| 3012 | if(!(seg.flags & 0x02)) |
| 3013 | result = 0; |
| 3014 | } |
| 3015 | } |
| 3016 | // check that the descriptor privilege is greater or equal to the selector's privilege level and the current privilege (TODO) |
| 3017 | if(((seg.flags >> 5) & 0x03) < (address & 0x03)) |
| 3018 | result = 0; |
| 3019 | SetZF(result); |
| 3020 | } |
| 3021 | else |
| 3022 | { |
| 3023 | i386_trap(cpustate,6, 0); |
| 3024 | logerror("i386: VERW: Exception - Running in real mode or virtual 8086 mode.\n"); |
| 3025 | } |
| 3026 | break; |
| 3027 | |
| 2906 | 3028 | default: |
| 2907 | 3029 | fatalerror("i386: group0F00_16 /%d unimplemented", (modrm >> 3) & 0x7); |
| 2908 | 3030 | break; |
| r10379 | r10380 | |
| 2987 | 3109 | case 6: /* LMSW */ |
| 2988 | 3110 | { |
| 2989 | 3111 | // TODO: Check for protection fault |
| 2990 | | UINT8 b; |
| 3112 | UINT16 b; |
| 2991 | 3113 | if( modrm >= 0xc0 ) { |
| 2992 | | b = LOAD_RM8(modrm); |
| 3114 | b = LOAD_RM16(modrm); |
| 2993 | 3115 | CYCLES(cpustate,CYCLES_LMSW_REG); |
| 2994 | 3116 | } else { |
| 2995 | 3117 | ea = GetEA(cpustate,modrm); |
| 2996 | 3118 | CYCLES(cpustate,CYCLES_LMSW_MEM); |
| 2997 | | b = READ8(cpustate,ea); |
| 3119 | b = READ16(cpustate,ea); |
| 2998 | 3120 | } |
| 2999 | | cpustate->cr[0] &= ~0x03; |
| 3000 | | cpustate->cr[0] |= b & 0x03; |
| 3121 | if(PROTECTED_MODE) |
| 3122 | b |= 0x0001; // cannot return to real mode using this instruction. |
| 3123 | cpustate->cr[0] &= ~0x0000ffff; |
| 3124 | cpustate->cr[0] |= b & 0x0000ffff; |
| 3001 | 3125 | break; |
| 3002 | 3126 | } |
| 3003 | 3127 | default: |
| r10379 | r10380 | |
| 3126 | 3250 | } |
| 3127 | 3251 | } |
| 3128 | 3252 | |
| 3253 | static void I386OP(lar_r16_rm16)(i386_state *cpustate) // Opcode 0x0f 0x02 |
| 3254 | { |
| 3255 | UINT8 modrm = FETCH(cpustate); |
| 3256 | I386_SREG seg; |
| 3257 | UINT8 type; |
| 3258 | |
| 3259 | if(PROTECTED_MODE && !V8086_MODE) |
| 3260 | { |
| 3261 | memset(&seg,0,sizeof(seg)); |
| 3262 | if(modrm >= 0xc0) |
| 3263 | { |
| 3264 | seg.selector = LOAD_RM16(modrm); |
| 3265 | CYCLES(cpustate,CYCLES_LAR_REG); |
| 3266 | } |
| 3267 | else |
| 3268 | { |
| 3269 | UINT32 ea = GetEA(cpustate,modrm); |
| 3270 | seg.selector = READ16(cpustate,ea); |
| 3271 | CYCLES(cpustate,CYCLES_LAR_MEM); |
| 3272 | } |
| 3273 | if(seg.selector == 0) |
| 3274 | { |
| 3275 | SetZF(0); // not a valid segment |
| 3276 | logerror("i386: LAR: Selector %04x is invalid type.\n",seg.selector); |
| 3277 | } |
| 3278 | else |
| 3279 | { |
| 3280 | i386_load_protected_mode_segment(cpustate,&seg); |
| 3281 | if(!(seg.flags & 0x10)) // special segment |
| 3282 | { |
| 3283 | // check for invalid segment types |
| 3284 | type = seg.flags & 0x000f; |
| 3285 | if(type == 0x00 || type == 0x08 || type == 0x0a || type == 0x0d) |
| 3286 | { |
| 3287 | SetZF(0); // invalid segment type |
| 3288 | } |
| 3289 | else |
| 3290 | { |
| 3291 | // TODO: check current privilege level |
| 3292 | STORE_REG16(modrm,(seg.flags << 8) & 0xff00); |
| 3293 | SetZF(1); |
| 3294 | } |
| 3295 | } |
| 3296 | else |
| 3297 | { // data or code segment (both are valid for LAR) |
| 3298 | // TODO: check current privilege level |
| 3299 | STORE_REG16(modrm,(seg.flags << 8) & 0xff00); |
| 3300 | SetZF(1); |
| 3301 | } |
| 3302 | } |
| 3303 | } |
| 3304 | else |
| 3305 | { |
| 3306 | // illegal opcode |
| 3307 | i386_trap(cpustate,6,0); |
| 3308 | logerror("i386: LAR: Exception - running in real mode or virtual 8086 mode.\n"); |
| 3309 | } |
| 3310 | } |
| 3311 | |
| 3129 | 3312 | static void I386OP(lsl_r16_rm16)(i386_state *cpustate) // Opcode 0x0f 0x03 |
| 3130 | 3313 | { |
| 3131 | 3314 | UINT8 modrm = FETCH(cpustate); |
src/emu/cpu/i386/i386ops.h
| r10379 | r10380 | |
| 287 | 287 | { 0x00, OP_2BYTE|OP_I386, I386OP(group0F00_16), I386OP(group0F00_32), }, |
| 288 | 288 | { 0x01, OP_2BYTE|OP_I386, I386OP(group0F01_16), I386OP(group0F01_32), }, |
| 289 | 289 | { 0x01, OP_2BYTE|OP_I486, I486OP(group0F01_16), I486OP(group0F01_32), }, |
| 290 | | { 0x02, OP_2BYTE|OP_I386, I386OP(unimplemented), I386OP(unimplemented), }, |
| 290 | { 0x02, OP_2BYTE|OP_I386, I386OP(lar_r16_rm16), I386OP(lar_r32_rm32), }, |
| 291 | 291 | { 0x03, OP_2BYTE|OP_I386, I386OP(lsl_r16_rm16), I386OP(lsl_r32_rm32), }, |
| 292 | 292 | { 0x06, OP_2BYTE|OP_I386, I386OP(clts), I386OP(clts), }, |
| 293 | 293 | { 0x08, OP_2BYTE|OP_I486, I486OP(invd), I486OP(invd), }, |
src/emu/cpu/i386/i386op32.c
| r10379 | r10380 | |
| 2653 | 2653 | UINT32 address, ea; |
| 2654 | 2654 | UINT8 modrm = FETCH(cpustate); |
| 2655 | 2655 | I386_SREG seg; |
| 2656 | UINT8 result; |
| 2656 | 2657 | |
| 2657 | 2658 | switch( (modrm >> 3) & 0x7 ) |
| 2658 | 2659 | { |
| r10379 | r10380 | |
| 2742 | 2743 | } |
| 2743 | 2744 | break; |
| 2744 | 2745 | |
| 2746 | case 4: /* VERR */ |
| 2747 | if ( PROTECTED_MODE && !V8086_MODE ) |
| 2748 | { |
| 2749 | result = 1; |
| 2750 | if( modrm >= 0xc0 ) { |
| 2751 | address = LOAD_RM32(modrm); |
| 2752 | CYCLES(cpustate,CYCLES_VERR_REG); |
| 2753 | } else { |
| 2754 | ea = GetEA(cpustate,modrm); |
| 2755 | address = READ32(cpustate,ea); |
| 2756 | CYCLES(cpustate,CYCLES_VERR_MEM); |
| 2757 | } |
| 2758 | memset(&seg, 0, sizeof(seg)); |
| 2759 | seg.selector = address; |
| 2760 | i386_load_protected_mode_segment(cpustate,&seg); |
| 2761 | // check if the segment is within the bounds of the GDT or LDT |
| 2762 | if(seg.selector & 0x04) |
| 2763 | { // LDT |
| 2764 | if((seg.selector & 0xf8) > cpustate->ldtr.limit) |
| 2765 | { |
| 2766 | result = 0; |
| 2767 | } |
| 2768 | } |
| 2769 | else |
| 2770 | { // GDT |
| 2771 | if((seg.selector & 0xf8) > cpustate->gdtr.limit) |
| 2772 | { |
| 2773 | result = 0; |
| 2774 | } |
| 2775 | } |
| 2776 | // check if the segment is a code or data segment (not a special segment type, like a TSS, gate, LDT...) |
| 2777 | if(!(seg.flags & 0x10)) |
| 2778 | result = 0; |
| 2779 | // check that the segment is readable |
| 2780 | if(seg.flags & 0x10) // is code or data segment |
| 2781 | { |
| 2782 | if(seg.flags & 0x08) // is code segment, so check if it's readable |
| 2783 | { |
| 2784 | if(!(seg.flags & 0x02)) |
| 2785 | { |
| 2786 | result = 0; |
| 2787 | } |
| 2788 | else |
| 2789 | { // check if conforming, these are always readable, regardless of privilege |
| 2790 | if(!(seg.flags & 0x04)) |
| 2791 | { |
| 2792 | // if not conforming, then we must check privilege levels (TODO: current privilege level check) |
| 2793 | if(((seg.flags >> 5) & 0x03) < (address & 0x03)) |
| 2794 | result = 0; |
| 2795 | } |
| 2796 | } |
| 2797 | } |
| 2798 | } |
| 2799 | // check that the descriptor privilege is greater or equal to the selector's privilege level and the current privilege (TODO) |
| 2800 | SetZF(result); |
| 2801 | } |
| 2802 | else |
| 2803 | { |
| 2804 | i386_trap(cpustate,6, 0); |
| 2805 | logerror("i386: VERR: Exception - Running in real mode or virtual 8086 mode.\n"); |
| 2806 | } |
| 2807 | break; |
| 2808 | |
| 2809 | case 5: /* VERW */ |
| 2810 | if ( PROTECTED_MODE && !V8086_MODE ) |
| 2811 | { |
| 2812 | result = 1; |
| 2813 | if( modrm >= 0xc0 ) { |
| 2814 | address = LOAD_RM16(modrm); |
| 2815 | CYCLES(cpustate,CYCLES_VERW_REG); |
| 2816 | } else { |
| 2817 | ea = GetEA(cpustate,modrm); |
| 2818 | address = READ16(cpustate,ea); |
| 2819 | CYCLES(cpustate,CYCLES_VERW_MEM); |
| 2820 | } |
| 2821 | memset(&seg, 0, sizeof(seg)); |
| 2822 | seg.selector = address; |
| 2823 | i386_load_protected_mode_segment(cpustate,&seg); |
| 2824 | // check if the segment is within the bounds of the GDT or LDT |
| 2825 | if(seg.selector & 0x04) |
| 2826 | { // LDT |
| 2827 | if((seg.selector & 0xf8) > cpustate->ldtr.limit) |
| 2828 | { |
| 2829 | result = 0; |
| 2830 | } |
| 2831 | } |
| 2832 | else |
| 2833 | { // GDT |
| 2834 | if((seg.selector & 0xf8) > cpustate->gdtr.limit) |
| 2835 | { |
| 2836 | result = 0; |
| 2837 | } |
| 2838 | } |
| 2839 | // check if the segment is a code or data segment (not a special segment type, like a TSS, gate, LDT...) |
| 2840 | if(!(seg.flags & 0x10)) |
| 2841 | result = 0; |
| 2842 | // check that the segment is writable |
| 2843 | if(seg.flags & 0x10) // is code or data segment |
| 2844 | { |
| 2845 | if(seg.flags & 0x08) // is code segment (and thus, not writable) |
| 2846 | { |
| 2847 | result = 0; |
| 2848 | } |
| 2849 | else |
| 2850 | { // is data segment |
| 2851 | if(!(seg.flags & 0x02)) |
| 2852 | result = 0; |
| 2853 | } |
| 2854 | } |
| 2855 | // check that the descriptor privilege is greater or equal to the selector's privilege level and the current privilege (TODO) |
| 2856 | if(((seg.flags >> 5) & 0x03) < (address & 0x03)) |
| 2857 | result = 0; |
| 2858 | SetZF(result); |
| 2859 | } |
| 2860 | else |
| 2861 | { |
| 2862 | i386_trap(cpustate,6, 0); |
| 2863 | logerror("i386: VERW: Exception - Running in real mode or virtual 8086 mode.\n"); |
| 2864 | } |
| 2865 | break; |
| 2866 | |
| 2745 | 2867 | default: |
| 2746 | 2868 | fatalerror("i386: group0F00_32 /%d unimplemented", (modrm >> 3) & 0x7); |
| 2747 | 2869 | break; |
| r10379 | r10380 | |
| 2936 | 3058 | } |
| 2937 | 3059 | } |
| 2938 | 3060 | |
| 3061 | static void I386OP(lar_r32_rm32)(i386_state *cpustate) // Opcode 0x0f 0x02 |
| 3062 | { |
| 3063 | UINT8 modrm = FETCH(cpustate); |
| 3064 | I386_SREG seg; |
| 3065 | UINT8 type; |
| 3066 | |
| 3067 | if(PROTECTED_MODE && !V8086_MODE) |
| 3068 | { |
| 3069 | memset(&seg,0,sizeof(seg)); |
| 3070 | if(modrm >= 0xc0) |
| 3071 | { |
| 3072 | seg.selector = LOAD_RM32(modrm); |
| 3073 | CYCLES(cpustate,CYCLES_LAR_REG); |
| 3074 | } |
| 3075 | else |
| 3076 | { |
| 3077 | UINT32 ea = GetEA(cpustate,modrm); |
| 3078 | seg.selector = READ32(cpustate,ea); |
| 3079 | CYCLES(cpustate,CYCLES_LAR_MEM); |
| 3080 | } |
| 3081 | if(seg.selector == 0) |
| 3082 | { |
| 3083 | SetZF(0); // not a valid segment |
| 3084 | } |
| 3085 | else |
| 3086 | { |
| 3087 | i386_load_protected_mode_segment(cpustate,&seg); |
| 3088 | if(!(seg.flags & 0x10)) // special segment |
| 3089 | { |
| 3090 | // check for invalid segment types |
| 3091 | type = seg.flags & 0x000f; |
| 3092 | if(type == 0x00 || type == 0x08 || type == 0x0a || type == 0x0d) |
| 3093 | { |
| 3094 | SetZF(0); // invalid segment type |
| 3095 | } |
| 3096 | else |
| 3097 | { |
| 3098 | // TODO: check current privilege level |
| 3099 | STORE_REG32(modrm,(seg.flags << 8) & 0x00ffff00); |
| 3100 | SetZF(1); |
| 3101 | } |
| 3102 | } |
| 3103 | else |
| 3104 | { |
| 3105 | // TODO: check current privilege level |
| 3106 | STORE_REG32(modrm,(seg.flags << 8) & 0x00ffff00); |
| 3107 | SetZF(1); |
| 3108 | } |
| 3109 | } |
| 3110 | } |
| 3111 | else |
| 3112 | { |
| 3113 | // illegal opcode |
| 3114 | i386_trap(cpustate,6,0); |
| 3115 | logerror("i386: LAR: Exception - running in real mode or virtual 8086 mode.\n"); |
| 3116 | } |
| 3117 | } |
| 3118 | |
| 2939 | 3119 | static void I386OP(lsl_r32_rm32)(i386_state *cpustate) // Opcode 0x0f 0x03 |
| 2940 | 3120 | { |
| 2941 | 3121 | UINT8 modrm = FETCH(cpustate); |