📄 exctest.c
字号:
/*
* Copyright (c) 1995-2000 by TriMedia Technologies.
*
* +------------------------------------------------------------------+
* | This software is furnished under a license and may only be used |
* | and copied in accordance with the terms and conditions of such |
* | a license and with the inclusion of this copyright notice. This |
* | software or any other copies of this software may not be provided|
* | or otherwise made available to any other person. The ownership |
* | and title of this software is not transferred. |
* | |
* | The information in this software is subject to change without |
* | any prior notice and should not be construed as a commitment by |
* | TriMedia Technologies. |
* | |
* | this code and information is provided "as is" without any |
* | warranty of any kind, either expressed or implied, including but |
* | not limited to the implied warranties of merchantability and/or |
* | fitness for any particular purpose. |
* +------------------------------------------------------------------+
*
* Module name : exctest.c 1.11
*
* Last update : 17:20:01 - 00/11/09
*
* Description :
*
* A test and demonstration for the TriMedia Exceptions library.
*
* This test installs and tests a Divide-By-Zero
* exception handler.
*
* Revision :
* Built for the TCS 1.1f release
*
*
*/
#include <stdio.h>
#include <tm1/tmExceptions.h>
#include <ops/custom_ops.h>
#include <tm1/tmHelp.h>
static volatile Bool ZeroDivideSeen = False;
/*
* This handler prints its magic message upon zero divide:
*/
static void
DBZHandler(UInt32 dpc, UInt32 spc)
{
/*
* Do not do printf's or other calls that rely on
* interrupt being on in an exception handler
*/
ZeroDivideSeen = True;
}
/*
* Macro to do compact error checking on device library calls:
*/
#define E(x) if ((x) != 0) { fprintf(stderr, "Error\n"); exit(-1); }
/*
* Zero- filled variables to get our exception:
*/
UInt x, y;
main()
{
excInstanceSetup_t setup;
printf("Running on "); tmHelpReportSystem(stdout);
/*
* Open the exception; since no handler is yet installed, it is
* disabled by default:
*/
printf("Opening DBZ\n");
E( excOpen(excDBZ) );
/*
* Generate the exception; since it is disabled still, nothing should
* happen yet:
*/
printf("Dividing by zero\n");
x /= y;
/*
* Install a Null handler, but mark it as enabled; the Null handler
* should overrule the enabled flag, and nothing should happen,
* although the exception is still pending:
*/
setup.enabled = True;
setup.handler = Null;
printf("Installing Null\n");
E( excInstanceSetup(excDBZ, &setup) );
/*
* Install a real handler, but mark it as disabled; so nothing should
* happen, although the exception is still pending:
*/
setup.enabled = False;
setup.handler = DBZHandler;
printf("Installing DBZHandler\n");
E( excInstanceSetup(excDBZ, &setup) );
/*
* Enable it; since we have a handler , now the exception should
* fire:
*/
setup.enabled = True;
printf("Enabling it (so here we should see DBZ):\n");
E( excInstanceSetup(excDBZ, &setup) );
microsleep(5);
if (ZeroDivideSeen)
printf("----> zero divide seen\n");
else
printf("---->ERROR: zero divide NOT seen\n");
/*
* Terminate:
*/
printf("Closing DBZ\n");
E( excClose(excDBZ) );
printf("Finished\n");
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -