-- --------------------------------------------------------------------------
-- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS PROVIDED "AS IS" WITHOUT 
-- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
-- TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
-- PARTICULAR PURPOSE.  The user assumes the entire risk as to the accuracy 
-- and the use of this file.  
--  
-- Ada version Copyright (c) P.J.Burwood, 1996
-- Royalty-free, unlimited, worldwide, non-exclusive use, modification, 
-- reproduction and further distribution of this Ada file is permitted. 
--
-- C version contains additional copyrights, see below
-- --------------------------------------------------------------------------

with Interfaces.C;
with System;

package Kernel is

   -- ++
   -- Interface to host OS.
   -- Copyright (C) Acorn Computers Ltd., 1990
   -- --

   subtype void         is System.Address;
   subtype void_ptr     is System.Address;
   subtype void_ptr_ptr is System.Address;

   type vector_of_c_signed_int is                               -- kernel.h:18
      array(integer range <>)
      of Interfaces.C.int;

   type swi_regs is                                             -- kernel.h:19
      record
         r: vector_of_c_signed_int(0..9);                       -- only r0 - r9 matter for swi's 
      end record;
   pragma Convention(C,  swi_regs);

   type oserror is                                              -- kernel.h:36
      record
         errnum : Interfaces.C.int;                             -- error number 
         errmess: Interfaces.C.char_array(0..251);              -- error message (zero terminated) 
      end record;
   pragma Convention(C,  oserror);
   type oserror_access is access all oserror;

   kernel_NONX : constant := 16#80000000#;                      -- kernel.h:83

   -- ++
   -- Generic SWI interface.  Returns NULL if there was no error.
   -- The SWI called normally has the X bit set.  To call a non-X bit set SWI,
   -- kernel_NONX must be orred into no (in which case, if an error occurs,
   -- swi does not return).
   -- --
   function  swi(no   : Interfaces.C.unsigned;
                 r_in : access swi_regs;
                 r_out: access swi_regs)
                        return oserror_access;
   procedure swi(no   : Interfaces.C.unsigned;
                 r_in : access swi_regs;
                 r_out: access swi_regs);

   -- ++
   -- As swi, but for use with SWIs which return status in the C flag.
   -- The int to which carry points is set to reflect the state of the C flag on
   -- exit from the SWI.
   -- --
   function swi_c(no   : Interfaces.C.unsigned;
                  r_in : access swi_regs;
                  r_out: access swi_regs;
                  carry: access Interfaces.C.int)
                         return oserror_access;
   procedure swi_c(no   : Interfaces.C.unsigned;
                   r_in : access swi_regs;
                   r_out: access swi_regs;
                   carry: access Interfaces.C.int);

   -- ++
   -- Returns a pointer to an error block describing the last os error since
   -- last_oserror was last called (or since the program started if there has
   -- been no such call).  If there has been no os error, returns a null
   -- pointer.  Note that occurrence of a further error may overwrite the
   -- contents of the block.
   -- If swi caused the last os error, the error already returned by that call
   -- gets returned by this too.
   -- --
   function last_oserror return oserror_access;                 -- kernel.h:199

private

    pragma Import(C, swi, "_kernel_swi");                       -- kernel.h:84

    pragma Import(C, swi_c, "_kernel_swi_c");                   -- kernel.h:93

    pragma Import(C, last_oserror, "_kernel_last_oserror");     -- kernel.h:199

end Kernel;
