OSAINX    IDENT
OSAINX    ALIAS    OSM$INTRINSICS
.
.
. This module contains procedures which
.    externalize machine instructions to the CYBIL programmer.
.    It is hoped that eventually these procedures can be replaced
.    by built-in functions in CYBIL.
.
.
.
. Register equates used thruout this module
.
xj       equ       12
xk       equ       13
aj       equ       12
ak       equ       13
amacscr  equ       15        .scratch a reg used by macros
.
xj       atrib     #regtyp,#xreg
xk       atrib     #regtyp,#xreg
aj       atrib     #regtyp,#areg
ak       atrib     #regtyp,#areg
amacscr  atrib     #regtyp,#areg
.
.  COMMON DECKS FOLLOW:
*copy osa$cybil_interface
*copy osa$basic_register_equates
         page
.
.    i#call_monitor
. Purpose:
.    This procedure is used to call MONITOR. The proc load the monitor
.    request block into the x registers, exchanges to monitor. When
.    monitor returns, the contents of the X registers are restored
.    to memory.
. Input:
.    param_p: Pointer to the monitor request block.
.    param_length: (1 .. 120) Length of the monitor request block in
.                  cells
. Output:
.    The request block may be modified by monitor during request
.    processing.
. Notes:
. -------------------------------------------------------------------"
.
.   PROCEDURE[XREF] i#call_monitor(rb_p:^cell;
.            rb_len:8 .. 120);
.
.   PROC[xdcl, code (ipl)] i#monitor_call (val p: ^cell; "ptr to req block"
.                val len: 1 .. 120);
.
.
.
icall    alias     I#CALL_MONITOR
icall    procedur
rb_p     param     val,pointer
rb_len   param     val,subrange,1
.
         ploada    aj,rb_p
         ploadx    x2,rb_len
         shfx      x2,x2,x0,-3
         addrq     xf,x2,1000(16)
         lmult     xf,aj,0
         exchange
         smult     xf,aj,0
         return
         page
. ---------------------------------------------------------------
. Name:
.    i#test_set_bit
. Purpose:
.    This procedure externalizes the 'Load Bit' instruction
.    Ref 124.
. Input:
.    P : pointer to byte containing the bit to be loaded.
.    bit_num : bit number within byte.Left most bit in the
.             byte is 0.
. Output:
.    This proc returns a boolean value.
.      true - bit was previously set
.      false  - bit was not previously set
. ---------------------------------------------------------------
.
.
.   PROCEDURE [XREF] i#test_set_bit(VAR p:^cell;
.         bit_num: 0 .. 255;
.     VAR bool: boolean);
.
.
.
ilbit    alias     I#TEST_SET_BIT
ilbit    procedur
p        param     val,pointer
bit_num  param     val,integer
bool     param     ref,boolean
.
         ploada    aj,p
         ploadx    x0,bit_num
         lbset     xk,aj,x0
         ents      xk
         pstorxp   xk,bool
         return
.
         page
. -------------------------------------------------------------------
. Name:
.    i#rel
. Purpose:
.    This function calculates the displacement of a pointer from a base
.    pointer. The results of the function are undefined if the segment
.    numbers in the two pointers are not the same.
. Input:
.    ptr: pointer expression
.    base_ptr: pointer expression
. Output:
.    xk: displacement of a pointer froma base pointer
. -------------------------------------------------------------------
.
.   FUNCTION[XREF] i#rel(ptr:^cell;
.           base_ptr:^cell):ost$relative_pointer
.
.
REL      alias    I#REL
rel      function integer
ptr      param    val,pointer
base_ptr param    val,pointer
.
         ploada   aj,ptr
         cpyax    xj,aj
         ploada   aj,base_ptr
         cpyax    xk,aj
         subr     xk,xj
         ents     xk
         freturnx xk
         page
. ------------------------------------------------------------------
. Name:
.    i#ptr
. Purpose:
.    This function calculates a pointer from a base pointer and a byte
.    displacement from the base pointer.
. Input:
.    disp: integer expression that specifies the byte displacement
.          from the base pointer
.    base_ptr: pointer expression
. Output:
.    ak: pointer
. -------------------------------------------------------------------
.
.   FUNCTION[XREF] i#ptr(disp: ost$relative_pointer;
.           base_ptr: ^cell): ^cell
.
.
PTRI     alias     I#PTR
ptri     function  pointer
disp     param     val,integer
baseptr  param     val,pointer
.
         ploada    ak,baseptr
         ploadx    xj,disp
         addax     ak,xj
         cpyax    xk,ak
         freturnx xk
           page
. -------------------------------------------------------------------
. Name:
.   i#real_memory_address
. Purpose:
.   This function externalizes the TPAGE instruction (REF 126).
. Input:
.   pva: pointer expression
. Output:
.   This instruction translates a PVA into a RMA and sets the 'used'
.   bit in the page table entry for the page. If the PVA can not be
.   translated because the page is not in real memory, the function
.   returns a negative number.
. -------------------------------------------------------------------
.
.   FUNCTION[XREF] i#real_memory_address(p:^cell):integer
.
tpva     alias     i#real_memory_address
tpva     procedur
pva      param     val,pointer
rma      param     ref,integer
.
         ploada    aj,pva
         tpage     xk,aj
         ents      xk
         pstorxp   xk,rma
         return
          page
. -------------------------------------------------------------------
. Name:
.   i#store_bit
. Purpose:
.   This procedure externalizes the SBIT instruction (REF 015).
. Input:
.   bit_value - boolean expression which specifies the value of the
.     bit to be written to memory
.   pointer - pointer to variable on which the SBIT instruction
.     performs the write operation
.   disp - displacement to the variable
. ___________________________________________________________________
.   PROCEDURE[XREF] i#store_bit(bitval: boolean;
.            p:^cell;  disp: integer);
.
STRBIT    alias      I#STORE_BIT
strbit    procedur
bitval    param       val,boolean
pt        param       val,pointer
disp      param       val,integer
.
          ploada      aj,pt
          ploadx      x0,disp
          ploadx      xk,bitval
          sbit        xk,aj,0,x0
          return
          page
. -------------------------------------------------------------------
. Name:
.   i#program_error
. Purpose:
.   This procedure is used to gererate a program error instruction.
.   (REF 121)
. -------------------------------------------------------------------
.
.   PROCEDURE[XREF] i#program_error;
.
.
phalt    alias   i#program_error
phalt    procedur
.
         halt
         return
         page
. -------------------------------------------------------------------
. Name:
.   i#sync
. Purpose:
.   This procedure is used to gererate a scope loop sync instruction.
.   (REF 194)
. -------------------------------------------------------------------
.
.   PROCEDURE [XREF] i#sync;
.
.
psync    alias   i#sync
psync    procedur
.
         sync
         return
         page
. --------------------------------------------------------------------
. Name:
.   i#compare
. Purpose:
.   This function compares two byte strings from left to right and
.   returns integer result that specifies the result of the comparison.
.   (REF 084)
. Input:
.   two byte strings with lengths and maximum of 256 bytes for each
. Notes:
.   when lengths are unequal, trailing space characters are used for
.   the shorter
. --------------------------------------------------------------------
.
.   FUNCTION[XREF] i#compare(p1, p2: ^string(*)):-1..1
.
comps     alias   i#compare
comps     function  integer
string1   param   val,astring
string2   param   val,astring
.
          pstring  aj,x0,string1
          pstring  ak,x1,string2
          CMPB,aj,x0  ak,x1   1,9,0,0   1,9,0,0
          shfx    x1,x1,x0,32
          shfx    x1,x1,x0,-62
          freturnx  x1
        page
. -------------------------------------------------------------------
. Name:
.   i#compare_collated
. Purpose:
.   This function does a collated comparison of two strings and
.   returns an integer result that specifies the result of the
.   comparison. (REF 085)
. Input:
.   Two byte strings with lengths and maximum of 256 bytes for each.
. -------------------------------------------------------------------
.
.   FUNCTION[XREF] i#compare_collated(p1,p2:^string(* <= 256);
.           table:^string(256)):-1..1
.
compcs   alias    i#compare_collated
compcs   function  integer
string1   param   val,astring
string2   param   val,astring
string3   param   val,string,256
.
          pstring  aj,x0,string1
          pstring  ak,x1,string2
          ploada  a3,string3
          CMPC,aj,x0  ak,x1,a3,0   1,9,0,0   1,9,0,0
          shfx    x1,x1,x0,32
          shfx    x1,x1,x0,-62
          freturnx  x1
         page
. -------------------------------------------------------------------
. Name:
.    i#build_adaptable_seq_pointer
. Purpose:
.    This proc builds a pointer to an adaptable seq. The caller supplies the
.    ring, segment, offset, and fixer sizes.
. Input:
.    rn: Ring number
.    sn: Segment number
.    bn: Byte number
.    seq_length: Length of the seq
.    next: offset to next entry
. Output:
.     seq_pointer: pointer to the adaptable seq
. -------------------------------------------------------------------
.
.   PROCEDURE[XREF] i#build_adaptable_seq_pointer (rn:0 .. 15;
.     SN:0 .. 4095;
.     bn:0 ..0FFFFFFFF(16);
.     seq_length: 0 .. 7fffffff(16);
.     next: 0 .. 7fffffff(16);
.   VAR seq_p: ^SEQ(*));
.
.
.
.
iseq     alias     I#BUILD_ADAPTABLE_SEQ_POINTER
iseq     procedur
rn       param     val,subrange,1
sn       param     val,subrange,2
bn       param     val,integer
len      param     val,integer
next     param     val,integer
ptr      param     ref,pointer
.
         ploadx    x1,rn
         ploadx    x2,sn
         ploadx    x3,bn
         insb     x3,x2,x0,2413(8)
         insb     x3,x1,x0,2003(8)
         ploadx    x5,len
         ploadx    x4,next
         insb   x4,x5,x0,0037(8)
         pstorxp   x3,ptr
         sbyts,8   x4,amacscr,x0,6
         return
         page
. -------------------------------------------------------------------
. Name:
.    i#current_sequence_position
. Purpose:
.    This function returns the current position in a sequence given an
.    adaptable sequence pointer.
. Input:
.    seq_p:^seq(*)
. Output:
.    current position in sequence
. -------------------------------------------------------------------
. Note:
.    The interface deck for this function now contains an INLINE
.    implementation.  The version of the function in this module is
.    being retained in support of any modules that have not recompiled
.    with the INLINE version.
. -------------------------------------------------------------------
.
.   FUNCTION [XREF] i#current_sequence_position (seq_p: ^seq(*)):integer;
.
.
icseqp   alias     I#CURRENT_SEQUENCE_POSITION
icseqp   function  integer
seq_p    param     val,pointer

         la        ak,a_plist,0
         lbyts,4   xk,ak,x0,10         .Current sequence position
         freturnx  xk
         page
. -------------------------------------------------------------------
. Name:
.    i#build_adaptable_heap_pointer
. Purpose:
.    This proc builds a pointer to an adaptable heap. The caller supplies the
.    ring, segment, offset, and fixer sizes.
. Input:
.    rn: Ring number
.    sn: Segment number
.    bn: Byte number
.    heap_length: Length of the heap
. Output:
.     heap_pointer: pointer to the adaptable heap
. -------------------------------------------------------------------
.
.   PROCEDURE[XREF] i#build_adaptable_heap_pointer (rn:0 .. 15;
.     SN:0 .. 4095;
.     bn:0 ..0FFFFFFFF(16);
.     heap_length: 0 .. 7fffffff(16);
.   VAR heap_p: ^SEQ(*));
.
.
.
.
iheap    alias     I#BUILD_ADAPTABLE_HEAP_POINTER
iheap    procedur
rn       param     val,subrange,1
sn       param     val,subrange,2
bn       param     val,integer
len      param     val,integer
ptr      param     ref,pointer
.
         ploadx    x1,rn
         ploadx    x2,sn
         ploadx    x3,bn
         insb     x3,x2,x0,2413(8)
         insb     x3,x1,x0,2003(8)
         ploadx    x4,len
         pstorxp   x3,ptr
         sbyts,4   x4,amacscr,x0,6
         return
         page
. -------------------------------------------------------------------
. Please note the following procedure will not compile with
. the CYBIL compiler version 88.1. The procedure
. i#build_adaptable_array_ptr will replace this
. procedure. It is functionally the same; however, the pointer
. parameter has become a reference parameter. Callers of the new
. procedure need to pass #LOC (pointer) instead of pointer.
.
. Name:
.    i#build_adaptable_array_pointer
. Purpose:
.    This proc builds a pointer to an adaptable array. The caller supplies the
.    ring, segment, offset, and fixer sizes.
. Input:
.    rn: Ring number
.    sn: Segment number
.    bn: Byte number
.    array_length: Length of the array
.    element_size: size of each element in the array
.    lower_bound: lower bound
. Output:
.     array_pointer: pointer to the adaptable array
. -------------------------------------------------------------------
.
.   PROCEDURE[XREF] i#build_adaptable_array_pointer (rn:0 .. 15;
.     SN:0 .. 4095;
.     bn:0 ..0FFFFFFFF(16);
.     array_length: 0 .. 7fffffff(16);
.     lower_bound: 0 .. 7fffffff(16);
.     element_size: 0 .. 7fffffff(16);
.     VAR array_p: ^cell);
.
.   PROC[xdcl] i#build_adaptable_array_pointer (val rn: 0 .. 15;
.   val sn: 0..4095; val bn: syt#halfword
.   val array_length: 0 .. 7fffffff(16);
.   val lower_bound: 0 .. 7fffffff(16);
.   val element_size: 0 .. 7fffffff(16);
.   ref array_p: ^cell);
.
.
iarray     alias     I#BUILD_ADAPTABLE_ARRAY_POINTER
iarray     procedur
rn       param     val,subrange,1
sn       param     val,subrange,2
bn       param     val,integer
as       param     val,integer
lb       param     val,integer
es       param     val,integer
ptr      param     ref,pointer
.
         ploadx    x1,rn
         ploadx    x2,sn
         ploadx    x3,bn
         insb     x3,x2,x0,2413(8)
         insb     x3,x1,x0,2003(8)
         ploadx    x4,as
         ploadx    x5,lb
         ploadx    x6,es
         pstorxp    x3,ptr
         sbyts,4   x4,amacscr,x0,6
         sbyts,4   x5,amacscr,x0,10
         sbyts,4   x6,amacscr,x0,14
         return
. -------------------------------------------------------------------
. Name:
.    i#build_adaptable_array_ptr
. Purpose:
.    This proc builds a pointer to an adaptable array. The caller supplies the
.    ring, segment, offset, and fixer sizes.
. Input:
.    rn: Ring number
.    sn: Segment number
.    bn: Byte number
.    array_length: Length of the array
.    element_size: size of each element in the array
.    lower_bound: lower bound
. Output:
.     array_pointer: pointer to the adaptable array
. -------------------------------------------------------------------
.
.   PROCEDURE[XREF] i#build_adaptable_array_ptr (rn:0 .. 15;
.     SN:0 .. 4095;
.     bn:0 ..0FFFFFFFF(16);
.     array_length: 0 .. 7fffffff(16);
.     lower_bound: 0 .. 7fffffff(16);
.     element_size: 0 .. 7fffffff(16);
.     array_p: ^^cell);
.
.   PROC[xdcl] i#build_adaptable_array_ptr (val rn: 0 .. 15;
.   val sn: 0..4095; val bn: syt#halfword
.   val array_length: 0 .. 7fffffff(16);
.   val lower_bound: 0 .. 7fffffff(16);
.   val element_size: 0 .. 7fffffff(16);
.   val array_p: ^^cell);
.
.
iarray2    alias     I#BUILD_ADAPTABLE_ARRAY_PTR
iarray2    procedur
rn       param     val,subrange,1
sn       param     val,subrange,2
bn       param     val,integer
as       param     val,integer
lb       param     val,integer
es       param     val,integer
ptr      param     val,pointer
.
         ploadx    x1,rn
         ploadx    x2,sn
         ploadx    x3,bn
         insb     x3,x2,x0,2413(8)
         insb     x3,x1,x0,2003(8)
         ploadx    x4,as
         ploadx    x5,lb
         ploadx    x6,es
         ploada    ak,ptr
         sbyts,6   x3,ak,x0,0
         sbyts,4   x4,ak,x0,6
         sbyts,4   x5,ak,x0,10
         sbyts,4   x6,ak,x0,14
         return
         end
