⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validate.c

📁 针对linux休眠suspend显卡状态保存恢复的一个办法
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************						Realmode X86 Emulator Library**            	Copyright (C) 1996-1999 SciTech Software, Inc.* 				     Copyright (C) David Mosberger-Tang* 					   Copyright (C) 1999 Egbert Eich**  ========================================================================**  Permission to use, copy, modify, distribute, and sell this software and*  its documentation for any purpose is hereby granted without fee,*  provided that the above copyright notice appear in all copies and that*  both that copyright notice and this permission notice appear in*  supporting documentation, and that the name of the authors not be used*  in advertising or publicity pertaining to distribution of the software*  without specific, written prior permission.  The authors makes no*  representations about the suitability of this software for any purpose.*  It is provided "as is" without express or implied warranty.**  THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,*  INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO*  EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR*  CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF*  USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR*  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR*  PERFORMANCE OF THIS SOFTWARE.**  ========================================================================** Language:     Watcom C 10.6 or later* Environment:  32-bit DOS* Developer:    Kendall Bennett** Description:  Program to validate the x86 emulator library for*               correctness. We run the emulator primitive operations*               functions against the real x86 CPU, and compare the result*               and flags to ensure correctness.**               We use inline assembler to compile and build this program.*****************************************************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdarg.h>#include "x86emu.h"#include "x86emu/prim_asm.h"/*-------------------------- Implementation -------------------------------*/#define true 1#define false 0#define ALL_FLAGS   (F_CF | F_PF | F_AF | F_ZF | F_SF | F_OF)#define VAL_START_BINARY(parm_type,res_type,dmax,smax,dincr,sincr)  \{                                                                   \    parm_type   d,s;                                                \    res_type    r,r_asm;                                            \	ulong     	flags,inflags;                                      \	int         f,failed = false;                                   \    char        buf1[80],buf2[80];                                  \    for (d = 0; d < dmax; d += dincr) {                             \        for (s = 0; s < smax; s += sincr) {                         \            M.x86.R_EFLG = inflags = flags = def_flags;             \            for (f = 0; f < 2; f++) {#define VAL_TEST_BINARY(name)                                           \                r_asm = name##_asm(&flags,d,s);                         \                r = name(d,s);                                  \                if (r != r_asm || M.x86.R_EFLG != flags)                \                    failed = true;                                      \                if (failed || trace) {#define VAL_TEST_BINARY_VOID(name)                                      \                name##_asm(&flags,d,s);                                 \                name(d,s);                                      \                r = r_asm = 0;                                          \                if (M.x86.R_EFLG != flags)                              \                    failed = true;                                      \                if (failed || trace) {#define VAL_FAIL_BYTE_BYTE_BINARY(name)                                                                 \                    if (failed)                                                                         \                        printk("fail\n");                                                               \                    printk("0x%02X = %-15s(0x%02X,0x%02X), flags = %s -> %s\n",                         \                        r, #name, d, s, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG));     \                    printk("0x%02X = %-15s(0x%02X,0x%02X), flags = %s -> %s\n",                         \                        r_asm, #name"_asm", d, s, print_flags(buf1,inflags), print_flags(buf2,flags));#define VAL_FAIL_WORD_WORD_BINARY(name)                                                                 \                    if (failed)                                                                         \                        printk("fail\n");                                                               \                    printk("0x%04X = %-15s(0x%04X,0x%04X), flags = %s -> %s\n",                         \                        r, #name, d, s, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG));   \                    printk("0x%04X = %-15s(0x%04X,0x%04X), flags = %s -> %s\n",                         \                        r_asm, #name"_asm", d, s, print_flags(buf1,inflags), print_flags(buf2,flags));#define VAL_FAIL_LONG_LONG_BINARY(name)                                                                 \                    if (failed)                                                                         \                        printk("fail\n");                                                               \                    printk("0x%08X = %-15s(0x%08X,0x%08X), flags = %s -> %s\n",                         \                        r, #name, d, s, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \                    printk("0x%08X = %-15s(0x%08X,0x%08X), flags = %s -> %s\n",                         \                        r_asm, #name"_asm", d, s, print_flags(buf1,inflags), print_flags(buf2,flags));#define VAL_END_BINARY()                                                    \                    }                                                       \                M.x86.R_EFLG = inflags = flags = def_flags | (ALL_FLAGS & ~F_OF);   \                if (failed)                                                 \                    break;                                                  \                }                                                           \            if (failed)                                                     \                break;                                                      \            }                                                               \        if (failed)                                                         \            break;                                                          \        }                                                                   \    if (!failed)                                                            \        printk("passed\n");                                                 \}#define VAL_BYTE_BYTE_BINARY(name)          \    printk("Validating %s ... ", #name);    \    VAL_START_BINARY(u8,u8,0xFF,0xFF,1,1)   \    VAL_TEST_BINARY(name)                   \    VAL_FAIL_BYTE_BYTE_BINARY(name)         \    VAL_END_BINARY()#define VAL_WORD_WORD_BINARY(name)                      \    printk("Validating %s ... ", #name);                \    VAL_START_BINARY(u16,u16,0xFF00,0xFF00,0x100,0x100) \    VAL_TEST_BINARY(name)                               \    VAL_FAIL_WORD_WORD_BINARY(name)                     \    VAL_END_BINARY()#define VAL_LONG_LONG_BINARY(name)                                      \    printk("Validating %s ... ", #name);                                \    VAL_START_BINARY(u32,u32,0xFF000000,0xFF000000,0x1000000,0x1000000) \    VAL_TEST_BINARY(name)                                               \    VAL_FAIL_LONG_LONG_BINARY(name)                                     \    VAL_END_BINARY()#define VAL_VOID_BYTE_BINARY(name)          \    printk("Validating %s ... ", #name);    \    VAL_START_BINARY(u8,u8,0xFF,0xFF,1,1)   \    VAL_TEST_BINARY_VOID(name)              \    VAL_FAIL_BYTE_BYTE_BINARY(name)         \    VAL_END_BINARY()#define VAL_VOID_WORD_BINARY(name)                      \    printk("Validating %s ... ", #name);                \    VAL_START_BINARY(u16,u16,0xFF00,0xFF00,0x100,0x100) \    VAL_TEST_BINARY_VOID(name)                          \    VAL_FAIL_WORD_WORD_BINARY(name)                     \    VAL_END_BINARY()#define VAL_VOID_LONG_BINARY(name)                                      \    printk("Validating %s ... ", #name);                                \    VAL_START_BINARY(u32,u32,0xFF000000,0xFF000000,0x1000000,0x1000000) \    VAL_TEST_BINARY_VOID(name)                                          \    VAL_FAIL_LONG_LONG_BINARY(name)                                     \    VAL_END_BINARY()#define VAL_BYTE_ROTATE(name)               \    printk("Validating %s ... ", #name);    \    VAL_START_BINARY(u8,u8,0xFF,8,1,1)      \    VAL_TEST_BINARY(name)                   \    VAL_FAIL_BYTE_BYTE_BINARY(name)         \    VAL_END_BINARY()#define VAL_WORD_ROTATE(name)                           \    printk("Validating %s ... ", #name);                \    VAL_START_BINARY(u16,u16,0xFF00,16,0x100,1)         \    VAL_TEST_BINARY(name)                               \    VAL_FAIL_WORD_WORD_BINARY(name)                     \    VAL_END_BINARY()#define VAL_LONG_ROTATE(name)                                           \    printk("Validating %s ... ", #name);                                \    VAL_START_BINARY(u32,u32,0xFF000000,32,0x1000000,1)                 \    VAL_TEST_BINARY(name)                                               \    VAL_FAIL_LONG_LONG_BINARY(name)                                     \    VAL_END_BINARY()#define VAL_START_TERNARY(parm_type,res_type,dmax,smax,dincr,sincr,maxshift)\{                                                                   \    parm_type   d,s;                                                \    res_type    r,r_asm;                                            \    u8          shift;                                              \	u32         flags,inflags;                                      \    int         f,failed = false;                                   \    char        buf1[80],buf2[80];                                  \    for (d = 0; d < dmax; d += dincr) {                             \        for (s = 0; s < smax; s += sincr) {                         \            for (shift = 0; shift < maxshift; shift += 1) {        \                M.x86.R_EFLG = inflags = flags = def_flags;         \                for (f = 0; f < 2; f++) {#define VAL_TEST_TERNARY(name)                                          \                    r_asm = name##_asm(&flags,d,s,shift);               \                    r = name(d,s,shift);                           \                    if (r != r_asm || M.x86.R_EFLG != flags)            \                        failed = true;                                  \                    if (failed || trace) {#define VAL_FAIL_WORD_WORD_TERNARY(name)                                                                \                        if (failed)                                                                         \                            printk("fail\n");                                                               \                        printk("0x%04X = %-15s(0x%04X,0x%04X,%d), flags = %s -> %s\n",                      \                            r, #name, d, s, shift, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG));   \                        printk("0x%04X = %-15s(0x%04X,0x%04X,%d), flags = %s -> %s\n",                      \                            r_asm, #name"_asm", d, s, shift, print_flags(buf1,inflags), print_flags(buf2,flags));#define VAL_FAIL_LONG_LONG_TERNARY(name)                                                                \                        if (failed)                                                                         \                            printk("fail\n");                                                               \                        printk("0x%08X = %-15s(0x%08X,0x%08X,%d), flags = %s -> %s\n",                      \                            r, #name, d, s, shift, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG));  \                        printk("0x%08X = %-15s(0x%08X,0x%08X,%d), flags = %s -> %s\n",                      \                            r_asm, #name"_asm", d, s, shift, print_flags(buf1,inflags), print_flags(buf2,flags));#define VAL_END_TERNARY()                                                   \                        }                                                       \                    M.x86.R_EFLG = inflags = flags = def_flags | (ALL_FLAGS & ~F_OF);   \                    if (failed)                                                 \                        break;                                                  \                    }                                                           \                if (failed)                                                     \                    break;                                                      \                }                                                               \            if (failed)                                                     \                break;                                                      \            }                                                               \        if (failed)                                                         \            break;                                                          \        }                                                                   \    if (!failed)                                                            \        printk("passed\n");                                                 \}#define VAL_WORD_ROTATE_DBL(name)                           \    printk("Validating %s ... ", #name);                    \    VAL_START_TERNARY(u16,u16,0xFF00,0xFF00,0x100,0x100,16) \    VAL_TEST_TERNARY(name)                                  \    VAL_FAIL_WORD_WORD_TERNARY(name)                        \    VAL_END_TERNARY()#define VAL_LONG_ROTATE_DBL(name)                                           \    printk("Validating %s ... ", #name);                                    \    VAL_START_TERNARY(u32,u32,0xFF000000,0xFF000000,0x1000000,0x1000000,32) \    VAL_TEST_TERNARY(name)                                                  \    VAL_FAIL_LONG_LONG_TERNARY(name)                                        \    VAL_END_TERNARY()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -