psl.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %
  4. % File: psl.h
  5. % Description: Common header for PSL kernel C code
  6. % Author: Arthur Norman
  7. % Status: Open Source: BSD License
  8. %
  9. % (c) Copyright 2018, Arthur Norman
  10. %
  11. % Redistribution and use in source and binary forms, with or without
  12. % modification, are permitted provided that the following conditions are met:
  13. %
  14. % * Redistributions of source code must retain the relevant copyright
  15. % notice, this list of conditions and the following disclaimer.
  16. % * Redistributions in binary form must reproduce the above copyright
  17. % notice, this list of conditions and the following disclaimer in the
  18. % documentation and/or other materials provided with the distribution.
  19. %
  20. % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22. % THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. % PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNERS OR
  24. % CONTRIBUTORS
  25. % BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. % CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. % POSSIBILITY OF SUCH DAMAGE.
  32. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  33. */
  34. #include <stdio.h>
  35. /*
  36. * The functions here are (just) called from compiled code. In the
  37. * assembly code for the kernel the code is written with the names
  38. * having a leading underscore. For Linux that underscore remains
  39. * visible here in the C code that is linked to, while under Cygwin
  40. * or on a Macintosh it is not. So here I define functions whose names
  41. * have leading underscores if I am on Linux but not otherwise. This is
  42. * a bit messy and ugly but is still about the neatest I can think of
  43. * at present if I want one body of code to apply everywhere.
  44. */
  45. #if defined __linux__ || defined __CYGWIN__
  46. #define _(x) _ ## x
  47. #else
  48. #define _(x) x
  49. #endif
  50. /*
  51. * NDEBUG can be used to disable checking of assertions. At least for
  52. * now I will arrange that when it is NOT defined that there is some
  53. * trace output generated almost every time that the C parts of the
  54. * PSL kernel get invoked.
  55. */
  56. #ifdef NDEBUG
  57. #define TR
  58. #define TR1(name)
  59. #else
  60. #define TR TR_printer(__LINE__, __FILE__)
  61. #define TR1(name) TR1_printer(name, __LINE__, __FILE__)
  62. static inline void TR_printer(int line, const char *file)
  63. { fprintf(stderr, "Trace at line %d of file %s\n", line, file);
  64. }
  65. static inline void TR1_printer(const char *name, int line, const char *file)
  66. { fprintf(stderr, "Trace %s at line %d of file %s\n", name, line, file);
  67. }
  68. #endif
  69. /*
  70. * The intent is to put declarations for all the various C functions used
  71. * within PSL here, so that (a) this represents collected documentation of
  72. * their names and arguments and (b) so that compilers can check for
  73. * consistent use.
  74. */
  75. /* end of psl.h */