//------------------------------------------------------------------- // seestack.cpp // // This program displays a hexadecimal and ascii dump of the // application's stack as it existed upon entry to 'main()', // and it illustrates the use of "inline" assembly language. // // (A student's question prompted the writing of this demo.) // // Suggestion: try executing this program with some command- // line arguments, and see where they show up in the output: // // Example: $ ./seestack xx yyyy zzzz // // programmer: ALLAN CRUSE // written on: 07 OCT 2003 //------------------------------------------------------------------- #include // for printf() #define KERNEL_BASE_ADDRESS 0xC0000000 unsigned long tos, len; unsigned char *where = (unsigned char *)KERNEL_BASE_ADDRESS; unsigned char ch; int i, j; int main( int argc, char **argv ) { // insert statement that copies %esp-value to a variable asm(" movl %esp, tos "); // calculate the size of the active stack area (in bytes) len = KERNEL_BASE_ADDRESS - tos; // loop to display the contents of the active stack area for (i = 0; i < len; i += 16) { where -= 16; printf( "\n%08X: ", where ); for (j = 0; j < 16; j++) printf( "%02X ", where[j] ); for (j = 0; j < 16; j++) { ch = where[ j ]; if (( ch < 0x20 )||( ch > 0x7E )) ch = '.'; printf( "%c", ch ); } } printf( "\n\n tos=%08X ", tos ); printf( "\n&argc=%08X argc=%08X ", &argc, argc ); printf( "\n&argv=%08X argv=%08X ", &argv, argv ); printf( "\n\n" ); }