//------------------------------------------------------------------- // flagvals.cpp // // This program displays a graphical visualization for values // of the processor's status flags (using gcc inline assembly // language to obtain access to the Pentium EFLAGS register). // // programmer: ALLAN CRUSE // written on: 06 NOV 2003 // revised on: 10 NOV 2003 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for read(), write(), close() #include // for tcgetattr(), tcsetattr() #include // for mmap() #include // for iopl() #define VRAM_BASE_ADDRESS 0xA0000000 #define VGA_MEMORY_LENGTH ( 4 << 20) unsigned char *vram = (unsigned char*)VRAM_BASE_ADDRESS; const int display_mode = 0x4103, hres = 800, vres = 600; unsigned char *c = &vram[ 28*hres + 7 ]; unsigned char *p = &vram[ 28*hres + 256 + 15 ]; unsigned char *a = &vram[ 28*hres + 512 + 23 ]; unsigned char *z = &vram[ 314*hres + 7 ]; unsigned char *s = &vram[ 314*hres + 256 + 15 ]; unsigned char *o = &vram[ 314*hres + 512 + 23 ]; void draw_rectangle( int x, int y, int h, int v, int color ) { int minx = x, miny = y, maxx = x+h-1, maxy = y+v-1; do { vram[ y*hres + x ] = color; ++x; } while ( x < maxx ); do { vram[ y*hres + x ] = color; ++y; } while ( y < maxy ); do { vram[ y*hres + x ] = color; --x; } while ( x > minx ); do { vram[ y*hres + x ] = color; --y; } while ( y > miny ); } int map_system_memory( int base, int size ) { int fd = open( "/dev/vram", O_RDWR ); if ( fd < 0 ) { perror( "/dev/vram" ); return -1; } int prot = PROT_READ | PROT_WRITE; int flag = MAP_FIXED | MAP_SHARED; void *mm = (void*)base; if ( mmap( mm, size, prot, flag, fd, 0 ) == MAP_FAILED ) { perror( "mmap" ); return -1; } close( fd ); } int main( int argc, char **argv ) { if ( iopl( 3 ) ) { perror( "iopl" ); exit(1); } system( "/sbin/insmod vram.o" ); map_system_memory( VRAM_BASE_ADDRESS, VGA_MEMORY_LENGTH ); struct termios otty; tcgetattr( 0, &otty ); struct termios tty = otty; tty.c_lflag &= ~( ICANON | ECHO | ISIG ); tty.c_cc[ VMIN ] = 1; tty.c_cc[ VTIME ] = 0; tcsetattr( 0, TCSAFLUSH, &tty ); char command[ 40 ]; sprintf( command, " clear ; mode3 %d ", display_mode ); system( command ); int color = 15; draw_rectangle( 0, 0, hres, vres, color ); getchar(); short flags[ 256 ][ 256 ]; for (int i = 0; i < 256; i++) for (int j = 0; j < 256; j++) { int status; asm(" movl %0, %%eax " : : "m" (i) ); asm(" movl %0, %%edx " : : "m" (j) ); asm(" addb %al, %dl " ); // asm(" subb %al, %dl " ); // asm(" xorb %al, %dl " ); // asm(" mulb %dl " ); asm(" pushfl ; popl %eax "); asm(" movl %%eax, %0 " : "=m" (status) ); flags[ i ][ j ] = status; } for (int i = 0; i < 256; i++) for (int j = 0; j < 256; j++) { int k = i*hres + j; c[ k ] = ( flags[ i ][ j ] & (1<<0) ) ? 4 : 2; p[ k ] = ( flags[ i ][ j ] & (1<<2) ) ? 4 : 2; a[ k ] = ( flags[ i ][ j ] & (1<<4) ) ? 4 : 2; z[ k ] = ( flags[ i ][ j ] & (1<<6) ) ? 4 : 2; s[ k ] = ( flags[ i ][ j ] & (1<<7) ) ? 4 : 2; o[ k ] = ( flags[ i ][ j ] & (1<<11) ) ? 4 : 2; } getchar(); system( " mode3 3 " ); tcsetattr( 0, TCSAFLUSH, &otty ); }