home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / SDL / gcc346 / !gcc / include / unixlib / internal / s / aof-macros next >
Encoding:
Text File  |  2006-09-17  |  2.5 KB  |  116 lines

  1. ; UnixLib assembler helper macros (AOF version)
  2. ; Copyright (c) 2002, 2003, 2004, 2005, 2006 UnixLib Developers
  3. ;
  4. ; This file and elf-macros.s must be kept in sync with each other.
  5.  
  6.     ; Macro for embedding function names in code, just before
  7.     ; the function prologue.
  8.     MACRO
  9.     NAME    $name
  10.     DCB    "$name",0
  11.     ALIGN
  12.     DCD    &FF000000 + (:LEN: "$name"+3+1) :AND: &FFFFFFFC
  13.     MEND
  14.  
  15.     ; Assembler equivalent of __set_errno in errno.h.
  16.     ; #define __set_errno(val) (errno = (val), -1)
  17.     ; Entry condition
  18.     ;   val = new error code
  19.     ; Exit condition
  20.     ;   val = -1
  21.     ;   Rerrno destroyed
  22.  
  23.     MACRO
  24.     __set_errno    $val,$Rerrno
  25.     ASSERT    $val <> $Rerrno
  26.     [ __UNIXLIB_ERRNO_THREADED > 0
  27.     IMPORT    |__pthread_running_thread|
  28.     LDR    $Rerrno, =|__pthread_running_thread|
  29.     LDR    $Rerrno, [$Rerrno]
  30.     STR    $val, [$Rerrno, #__PTHREAD_ERRNO_OFFSET]
  31.     |
  32.     IMPORT    |errno|
  33.     LDR    $Rerrno, =|errno|
  34.     STR    $val, [$Rerrno]
  35.     ]
  36.     MOV    $val, #-1
  37.     MEND
  38.  
  39.     MACRO
  40.     __get_errno    $val,$Rerrno
  41.     [ __UNIXLIB_ERRNO_THREADED > 0
  42.     IMPORT    |__pthread_running_thread|
  43.     LDR    $Rerrno, =|__pthread_running_thread|
  44.     LDR    $Rerrno, [$Rerrno]
  45.     LDR    $val, [$Rerrno, #__PTHREAD_ERRNO_OFFSET]
  46.     |
  47.     IMPORT    |errno|
  48.     LDR    $Rerrno, =|errno|
  49.     LDR    $val, [$Rerrno]
  50.     ]
  51.     MEND
  52.  
  53.     ; NetSWI, NetSWIsimple, NetSWI0 and NetSWIsimple0 are macros to call
  54.     ; one of the networking (TCP/IP) SWIs.
  55.  
  56.     ; Calls networking (TCP/IP) SWI.
  57.     MACRO
  58.     NetSWI    $swiname
  59.     IMPORT    |__net_error|
  60.     SWI    $swiname
  61.     BLVS    |__net_error|        ; Call net error
  62.     MEND
  63.  
  64.     ; Calls networking (TCP/IP) SWI and returns to lr.
  65.     MACRO
  66.     NetSWIsimple    $swiname
  67.     IMPORT    |__net_error|
  68.     SWI    $swiname
  69.     MOVVC    pc, lr
  70.     B    |__net_error|
  71.     MEND
  72.  
  73.     ; Calls networking (TCP/IP) SWI.
  74.     ; Returns 0 in R0 for success, a non zero errno in R0 when
  75.     ; error happened.
  76.     MACRO
  77.     NetSWI0    $swiname
  78.     IMPORT    |__net_error|
  79.     SWI    $swiname
  80.     MOVVC    a1, #0
  81.     BLVS    |__net_error|        ; Call net error
  82.     MEND
  83.  
  84.     ; Calls networking (TCP/IP) SWI and returns to lr.
  85.     ; Returns 0 in R0 for success, a non zero errno in R0 when
  86.     ; error happened.
  87.     MACRO
  88.     NetSWIsimple0    $swiname
  89.     IMPORT    |__net_error|
  90.     SWI    $swiname
  91.     MOVVC    a1, #0
  92.     MOVVC    pc, lr
  93.     B    |__net_error|
  94.     MEND
  95.  
  96.     ; Macro to change processor modes and interrupt flags
  97.     ; Works in 26bit or 32bit modes, on all architectures
  98.     ; Use e.g. CHGMODE a1, SVC_Mode+IFlag
  99.     MACRO
  100.     CHGMODE    $scratch, $mode
  101.     TEQ    a1, a1    ; Set Z
  102.     TEQ    pc, pc    ; EQ if 32-bit mode
  103.     TEQNEP    pc, #$mode
  104.     MRSEQ    $scratch, CPSR    ; Acts a NOP for TEQP
  105.     BICEQ    $scratch, $scratch, #&cf    ; Preserve 32bit mode bit
  106.     [ $mode <> 0
  107.     ORREQ    $scratch, $scratch, #(($mode) :AND: &f) + (($mode) :SHR: 20)
  108.     ]
  109.     MSREQ    CPSR_c, $scratch
  110.     MOV    a1, a1    ; Avoid StrongARM MSR bug
  111.  
  112.     MEND
  113.  
  114.     END
  115.  
  116.