home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / SDL / gcc346 / !gcc / include / libscl / h / kernel < prev    next >
Encoding:
Text File  |  2006-09-17  |  9.0 KB  |  269 lines

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