trap.h

00001 /* Trap example for 68HC11
00002    Copyright (C) 1999, 2000 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 #ifndef _TRAP_H
00029 #define _TRAP_H
00030 
00031 #include <sys/interrupts.h>
00032 #include <sys/sio.h>
00033 #include <stdarg.h>
00034 
00035 /* The trap handler must be installed either in the SWI interrupt
00036    vector or in the ILLEGAL opcode vector.  Arguments can be passed
00037    as a normal C function call: gcc takes into account the different stack
00038    frame for the trap handler.  The trap handler can return a value: gcc
00039    generates code to save the result on the stack so that 'rti' will pop
00040    the expected return value.
00041 
00042    To invoke a trap handler, just call the function.  Gcc will generate a
00043    swi instead of a bsr.  It is possible to define several trap handlers.
00044    However since only one of them can be installed, it's necessary to be
00045    very careful.  Gcc does not install/switch trap handlers while you are
00046    invoking them.
00047 
00048    The difference between a trap handler and an interrupt handler is that
00049    you can pass arguments to a trap handler and the trap handler can return
00050    a value.  The interrupt handler can be invoked asynchronously, therefore
00051    some additional registers are saved by gcc.
00052    
00053    */
00054 
00055 /* Trap handler to show parameter passing and no result.  */
00056 extern void simple_trap_handler (int value) __attribute__((trap));
00057 
00058 /* This trap handler returns the sum of all its arguments.  */
00059 extern int add_trap_handler(int a, int b, int c, int d) __attribute__ ((trap));
00060 
00061 /* For this trap handler, the operation parameter identifies the operation to
00062    be executed by the handler.  Further parameters depend on the operation.
00063    This is an example on how to define some OS system calls.  */
00064 extern int os_trap_handler (int operation, ...) __attribute__ ((trap));
00065 
00066 typedef int (* handler)(int, ...);
00067 
00068 inline static void
00069 print (const char* msg)
00070 {
00071   serial_print (msg);
00072 }
00073 
00074 
00075 #endif