home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !gcc / include / libscl / h / kernel < prev    next >
Encoding:
Text File  |  2004-09-05  |  7.6 KB  |  248 lines

  1. /* kernel.h
  2.  
  3.    For use with the GNU compilers and the SharedCLibrary.
  4.    (c) Copyright 1997, Nick Burrett.  */
  5.  
  6. #ifndef __KERNEL_H
  7. #define __KERNEL_H
  8.  
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12.  
  13. /* GCC has various useful declarations that can be made with the
  14.    __attribute__ syntax.  Disable its use for other compilers.  */
  15. #ifndef __GNUC__
  16. #ifndef __attribute__
  17. #define __attribute__(x) /* Ignore.  */
  18. #endif
  19. #endif
  20.  
  21. typedef struct
  22. {
  23.   int errnum;
  24.   char errmess[252];
  25. } _kernel_oserror;
  26.  
  27. /* Stack management functions.  */
  28.  
  29. typedef struct stack_chunk
  30. {
  31.   unsigned long sc_mark; /* == 0xf60690ff */
  32.   struct stack_chunk *sc_next, *sc_prev;
  33.   unsigned long sc_size;
  34.   int (*sc_deallocate)(void);
  35. } _kernel_stack_chunk;
  36.  
  37. /* Return a pointer to the current stack chunk.  */
  38. extern _kernel_stack_chunk *_kernel_current_stack_chunk (void);
  39.  
  40. typedef struct
  41. {
  42.   int r4, r5, r6, r7, r8, r9;
  43.   int fp, sp, pc, sl;
  44.   int f4[3], f5[3], f6[3], f7[3];
  45. } _kernel_unwindblock;
  46.  
  47. /* Unwind the call stack one level. Return: >0 on success,
  48.    0 if stack end has been reached, <0 any other failures.  */
  49. extern int _kernel_unwind (_kernel_unwindblock *__inout, char **__language);
  50.  
  51. /* Program environment functions.  */
  52.  
  53. /* Return a pointer to the name of the function that contains the
  54.    address 'pc' (or zero if no name can be found).  */
  55. extern char *_kernel_procname (int __pc);
  56.  
  57. /* Return a pointer to the name of the language that the address
  58.    'pc' lies within. Zero if the language is unknown. */
  59. extern char *_kernel_language (int __pc);
  60.  
  61. /* Return a pointer to the command string used to run the program.  */
  62. extern char *_kernel_command_string (void);
  63.  
  64. /* Set the return code to be used by _kernel_exit.  */
  65. extern void _kernel_setreturncode (unsigned __code);
  66.  
  67. /* Call OS_Exit. Use the return code set by _kernel_setreturncode.  */
  68. extern void _kernel_exit (int __value) __attribute__ ((__noreturn__));
  69.  
  70. /* Generates an external error.  */
  71. extern void _kernel_raise_error (_kernel_oserror *);
  72.  
  73. /* Reset the InTrapHandler flag to prevent recursive traps.  */
  74. extern void _kernel_exittraphandler (void);
  75.  
  76. /* Returns 6 for RISC OS.  */
  77. extern int _kernel_hostos (void);
  78.  
  79. /* Return non-zero if floating point instructions are available.  */
  80. extern int _kernel_fpavailable (void);
  81.  
  82. /* Return the last OS error since the last time _kernel_last_oserror
  83.    was called. Return zero if no errors have occurred.  */
  84. extern _kernel_oserror *_kernel_last_oserror (void);
  85.  
  86. /* Read the value of system variable 'name', placing the result in 'buffer'.  */
  87. extern _kernel_oserror *_kernel_getenv (const char *__name,
  88.                     char *__buffer, unsigned __size);
  89.  
  90. /* Set the system variable 'name' with 'value'. If 'value == 0' then
  91.    'name' is deleted.  */
  92. extern _kernel_oserror *_kernel_setenv (const char *__name,
  93.                     const char *__value);
  94.  
  95. /* Return 1 if there has been an Escape since the previous call to
  96.    _kernel_escape_seen.  */
  97. extern int _kernel_escape_seen (void);
  98.  
  99. /* Enable IRQ interrupts.  This can only be executed within SVC mode.  */
  100. extern void _kernel_irqs_on (void);
  101.  
  102. /* Disable IRQ interrupts.  This can only be executed within SVC mode.  */
  103. extern void _kernel_irqs_off (void);
  104.  
  105. /* Return non-zero if IRQs are disabled.  */
  106. extern int _kernel_irqs_disabled (void);
  107.  
  108. /* General utility functions.  */
  109.  
  110. typedef struct
  111. {
  112.   int r[10];
  113. } _kernel_swi_regs;
  114.  
  115. /* Call the SWI specified by 'no'. 'in' points to a register block for SWI
  116.    entry.  'out' points to a register block for SWI exit. The X bit is set
  117.    by _kernel_swi unless bit 31 is set.  */
  118. extern _kernel_oserror *_kernel_swi (int __no, _kernel_swi_regs *__in,
  119.                      _kernel_swi_regs *__out);
  120.  
  121.  
  122. /* Similar to _kernel_swi but the carry flag status is returned in
  123.    'carry'.  */
  124. extern _kernel_oserror *_kernel_swi_c (int __no, _kernel_swi_regs *__in,
  125.                        _kernel_swi_regs *__out,
  126.                        int *__carry);
  127.  
  128. /* Perform an OS_Byte operation.
  129.    R1 is returned in the bottom byte, R2 in the second byte,
  130.    if carry set, then third byte = 1.  */
  131. extern int _kernel_osbyte (int __operation, int __x, int __y);
  132.  
  133. /* Read a character from the OS input stream.  */
  134. extern int _kernel_osrdch (void);
  135.  
  136. /* Write a character to the OS output streams.  The return value indicates
  137.    success or failure.  */
  138. extern int _kernel_oswrch (int __ch);
  139.  
  140. /* Return the next byte from the file 'handle'. Return -1 on EOF.  */
  141. extern int _kernel_osbget (unsigned __handle);
  142.  
  143. /* Write the byte 'ch' to the file 'handle'. Return success or failure.  */
  144. extern int _kernel_osbput (int __ch, unsigned __handle);
  145.  
  146. typedef struct
  147. {
  148.   void * dataptr;
  149.   int nbytes, fileptr;
  150.   int buf_len;
  151.   char *wild_fld;
  152. } _kernel_osgbpb_block;
  153.  
  154. /* Read/write a number of bytes on file 'handle'. */
  155. extern int _kernel_osgbpb (int __operation, unsigned __handle,
  156.                _kernel_osgbpb_block *__inout);
  157.  
  158. /* Perform an OS_Word operation.  */
  159. extern int _kernel_osword (int __operation, int *__data);
  160.  
  161. /* Open or close a file. Open returns a file handle, close just
  162.    indicates success/failure.  */
  163. extern int _kernel_osfind (int __operation, char *__name);
  164.  
  165. typedef struct
  166. {
  167.   int load, exec;
  168.   int start, end;
  169. } _kernel_osfile_block;
  170.  
  171. /* Perform an OS_File operation. The _kernel_osfile_block provides
  172.    values for registers R2-R5.  */
  173. extern int _kernel_osfile (int __operation, const char *__name,
  174.                _kernel_osfile_block *__inout);
  175.  
  176. /* Perform an OS_Args operation. Generally returns the value in R2, unless
  177.    op = 0.  */
  178. extern int _kernel_osargs (int __operation, unsigned __handle, int __arg);
  179.  
  180. /* Call OS_CLI with the string 's'. If another application is called,
  181.    the current application will be closed down.      */
  182. extern int _kernel_oscli (const char *__s);
  183.  
  184. /* Call OS_CLI with the string 's'. If chain == 0, then the current
  185.    application is copied away and the new application executed as
  186.    a subprogram. Control will return to the main application once the
  187.    subprogram has completed.
  188.  
  189.    If chain == 1, then _kernel_system will not return.  */
  190. extern int _kernel_system (const char *__string, int __chain);
  191.  
  192. /* Memory allocation functions.  */
  193.  
  194. /* Tries to allocate a block of size 'words' words. If it fails,
  195.    it allocates the largest possible block.  */
  196. extern unsigned _kernel_alloc (unsigned __words, void **__block);
  197.  
  198.  
  199. /* Register procedures to be used by the SharedCLibrary when it
  200.    creates to frees memory e.g. on creation of stack chunks.  */
  201. typedef void freeproc (void *);
  202. typedef void *allocproc (unsigned);
  203.  
  204. extern void _kernel_register_allocs (allocproc *__malloc, freeproc *__free);
  205.  
  206. /* If the heap limit != application limit, then the procedure
  207.    registered here is used to request n bytes from the memory
  208.    allocation routine.  */
  209. typedef int _kernel_ExtendProc (int __n, void **__p);
  210.  
  211. _kernel_ExtendProc *_kernel_register_slotextend (_kernel_ExtendProc *__proc);
  212.  
  213. /* Language support.  */
  214.  
  215. /* Unsigned divide and remainder function. Returns the remainder in R1. */
  216. extern unsigned
  217. _kernel_udiv (unsigned __divisor,
  218.           unsigned __dividend) __attribute__ ((__const__));
  219.  
  220. /* Unsigned remainder function.  */
  221. extern unsigned
  222. _kernel_urem (unsigned __divisor,
  223.           unsigned __dividend) __attribute__ ((__const__));
  224.  
  225. /* Unsigned divide and remainder function by 10.
  226.    Returns the remainder in R1. */
  227. extern unsigned
  228. _kernel_udiv10 (unsigned __dividend) __attribute__ ((__const__));
  229.  
  230. /* Signed divide and remainder function. Returns the remainder in R1. */
  231. extern int
  232. _kernel_sdiv (int __divisor, int __dividend) __attribute__ ((__const__));
  233.  
  234. /* Signed remainder function.  */
  235. extern int
  236. _kernel_srem (int __divisor, int __dividend) __attribute__ ((__const__));
  237.  
  238. /* Signed divide and remainder function by 10.
  239.    Returns the remainder in R1. */
  240. extern int
  241. _kernel_sdiv10 (int __dividend) __attribute__ ((__const__));
  242.  
  243. #ifdef __cplusplus
  244. }
  245. #endif
  246.  
  247. #endif
  248.