trap.c

00001 /* Trap example for 68HC11
00002    Copyright (C) 1999 Free Software Foundation, Inc.
00003    Written by Stephane Carrez (stcarrez@worldnet.fr)    
00004 
00005 This file is free software; you can redistribute it and/or modify it
00006 under the terms of the GNU General Public License as published by the
00007 Free Software Foundation; either version 2, or (at your option) any
00008 later version.
00009 
00010 In addition to the permissions in the GNU General Public License, the
00011 Free Software Foundation gives you unlimited permission to link the
00012 compiled version of this file with other programs, and to distribute
00013 those programs without any restriction coming from the use of this
00014 file.  (The General Public License restrictions do apply in other
00015 respects; for example, they cover modification of the file, and
00016 distribution when not linked into another program.)
00017 
00018 This file is distributed in the hope that it will be useful, but
00019 WITHOUT ANY WARRANTY; without even the implied warranty of
00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021 General Public License for more details.
00022 
00023 You should have received a copy of the GNU General Public License
00024 along with this program; see the file COPYING.  If not, write to
00025 the Free Software Foundation, 59 Temple Place - Suite 330,
00026 Boston, MA 02111-1307, USA.  */
00027 
00028 #include "trap.h"
00029 
00030 int global_result;
00031 
00032 /* Trap handler to show parameter passing and no result.  */
00033 void
00034 simple_trap_handler(int value)
00035 {
00036   global_result = value * value;
00037 }
00038 
00039 
00040 /* This trap handler returns the sum of all its arguments.  */
00041 int
00042 add_trap_handler(int a, int b, int c, int d)
00043 {
00044   return a + b + c + d;
00045 }
00046 
00047 
00048 /* For this trap handler, the operation parameter identifies the operation to
00049    be executed by the handler.  Further parameters depend on the operation.
00050    This is an example on how to define some OS system calls.  */
00051 int
00052 os_trap_handler(int operation, ...)
00053 {
00054   va_list argp;
00055   int result;
00056   const char* p;
00057   
00058   va_start(argp, operation);
00059   switch (operation)
00060     {
00061       /* A kind of write system call.  */
00062     case 0:
00063       p = va_arg (argp, const char*);
00064       print (p);
00065       result = 0;
00066       break;
00067 
00068       /* A kind of read system call.  */
00069     case 1:
00070       result = serial_recv ();
00071       break;
00072 
00073     case 2:
00074       result = va_arg (argp, int) + va_arg (argp, int);
00075       break;
00076       
00077       /* Invalid call.  */
00078     default:
00079       result = -1;
00080       break;
00081     }
00082   va_end(argp);
00083   return result;
00084 }
00085