golang.org/x/sys@v0.20.1-0.20240517151509-673e0f94c16d/unix/bpxsvc_zos.go (about)

     1  // Copyright 2024 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build zos
     6  
     7  package unix
     8  
     9  import (
    10  	"bytes"
    11  	"fmt"
    12  	"unsafe"
    13  )
    14  
    15  //go:noescape
    16  func bpxcall(plist []unsafe.Pointer, bpx_offset int64)
    17  
    18  //go:noescape
    19  func A2e([]byte)
    20  
    21  //go:noescape
    22  func E2a([]byte)
    23  
    24  const (
    25  	BPX4STA = 192  // stat
    26  	BPX4FST = 104  // fstat
    27  	BPX4LST = 132  // lstat
    28  	BPX4OPN = 156  // open
    29  	BPX4CLO = 72   // close
    30  	BPX4CHR = 500  // chattr
    31  	BPX4FCR = 504  // fchattr
    32  	BPX4LCR = 1180 // lchattr
    33  	BPX4CTW = 492  // cond_timed_wait
    34  	BPX4GTH = 1056 // __getthent
    35  	BPX4PTQ = 412  // pthread_quiesc
    36  	BPX4PTR = 320  // ptrace
    37  )
    38  
    39  const (
    40  	//options
    41  	//byte1
    42  	BPX_OPNFHIGH = 0x80
    43  	//byte2
    44  	BPX_OPNFEXEC = 0x80
    45  	//byte3
    46  	BPX_O_NOLARGEFILE = 0x08
    47  	BPX_O_LARGEFILE   = 0x04
    48  	BPX_O_ASYNCSIG    = 0x02
    49  	BPX_O_SYNC        = 0x01
    50  	//byte4
    51  	BPX_O_CREXCL   = 0xc0
    52  	BPX_O_CREAT    = 0x80
    53  	BPX_O_EXCL     = 0x40
    54  	BPX_O_NOCTTY   = 0x20
    55  	BPX_O_TRUNC    = 0x10
    56  	BPX_O_APPEND   = 0x08
    57  	BPX_O_NONBLOCK = 0x04
    58  	BPX_FNDELAY    = 0x04
    59  	BPX_O_RDWR     = 0x03
    60  	BPX_O_RDONLY   = 0x02
    61  	BPX_O_WRONLY   = 0x01
    62  	BPX_O_ACCMODE  = 0x03
    63  	BPX_O_GETFL    = 0x0f
    64  
    65  	//mode
    66  	// byte1 (file type)
    67  	BPX_FT_DIR      = 1
    68  	BPX_FT_CHARSPEC = 2
    69  	BPX_FT_REGFILE  = 3
    70  	BPX_FT_FIFO     = 4
    71  	BPX_FT_SYMLINK  = 5
    72  	BPX_FT_SOCKET   = 6
    73  	//byte3
    74  	BPX_S_ISUID  = 0x08
    75  	BPX_S_ISGID  = 0x04
    76  	BPX_S_ISVTX  = 0x02
    77  	BPX_S_IRWXU1 = 0x01
    78  	BPX_S_IRUSR  = 0x01
    79  	//byte4
    80  	BPX_S_IRWXU2 = 0xc0
    81  	BPX_S_IWUSR  = 0x80
    82  	BPX_S_IXUSR  = 0x40
    83  	BPX_S_IRWXG  = 0x38
    84  	BPX_S_IRGRP  = 0x20
    85  	BPX_S_IWGRP  = 0x10
    86  	BPX_S_IXGRP  = 0x08
    87  	BPX_S_IRWXOX = 0x07
    88  	BPX_S_IROTH  = 0x04
    89  	BPX_S_IWOTH  = 0x02
    90  	BPX_S_IXOTH  = 0x01
    91  
    92  	CW_INTRPT  = 1
    93  	CW_CONDVAR = 32
    94  	CW_TIMEOUT = 64
    95  
    96  	PGTHA_NEXT        = 2
    97  	PGTHA_CURRENT     = 1
    98  	PGTHA_FIRST       = 0
    99  	PGTHA_LAST        = 3
   100  	PGTHA_PROCESS     = 0x80
   101  	PGTHA_CONTTY      = 0x40
   102  	PGTHA_PATH        = 0x20
   103  	PGTHA_COMMAND     = 0x10
   104  	PGTHA_FILEDATA    = 0x08
   105  	PGTHA_THREAD      = 0x04
   106  	PGTHA_PTAG        = 0x02
   107  	PGTHA_COMMANDLONG = 0x01
   108  	PGTHA_THREADFAST  = 0x80
   109  	PGTHA_FILEPATH    = 0x40
   110  	PGTHA_THDSIGMASK  = 0x20
   111  	// thread quiece mode
   112  	QUIESCE_TERM       int32 = 1
   113  	QUIESCE_FORCE      int32 = 2
   114  	QUIESCE_QUERY      int32 = 3
   115  	QUIESCE_FREEZE     int32 = 4
   116  	QUIESCE_UNFREEZE   int32 = 5
   117  	FREEZE_THIS_THREAD int32 = 6
   118  	FREEZE_EXIT        int32 = 8
   119  	QUIESCE_SRB        int32 = 9
   120  )
   121  
   122  type Pgtha struct {
   123  	Pid        uint32 // 0
   124  	Tid0       uint32 // 4
   125  	Tid1       uint32
   126  	Accesspid  byte    // C
   127  	Accesstid  byte    // D
   128  	Accessasid uint16  // E
   129  	Loginname  [8]byte // 10
   130  	Flag1      byte    // 18
   131  	Flag1b2    byte    // 19
   132  }
   133  
   134  type Bpxystat_t struct { // DSECT BPXYSTAT
   135  	St_id           [4]uint8  // 0
   136  	St_length       uint16    // 0x4
   137  	St_version      uint16    // 0x6
   138  	St_mode         uint32    // 0x8
   139  	St_ino          uint32    // 0xc
   140  	St_dev          uint32    // 0x10
   141  	St_nlink        uint32    // 0x14
   142  	St_uid          uint32    // 0x18
   143  	St_gid          uint32    // 0x1c
   144  	St_size         uint64    // 0x20
   145  	St_atime        uint32    // 0x28
   146  	St_mtime        uint32    // 0x2c
   147  	St_ctime        uint32    // 0x30
   148  	St_rdev         uint32    // 0x34
   149  	St_auditoraudit uint32    // 0x38
   150  	St_useraudit    uint32    // 0x3c
   151  	St_blksize      uint32    // 0x40
   152  	St_createtime   uint32    // 0x44
   153  	St_auditid      [4]uint32 // 0x48
   154  	St_res01        uint32    // 0x58
   155  	Ft_ccsid        uint16    // 0x5c
   156  	Ft_flags        uint16    // 0x5e
   157  	St_res01a       [2]uint32 // 0x60
   158  	St_res02        uint32    // 0x68
   159  	St_blocks       uint32    // 0x6c
   160  	St_opaque       [3]uint8  // 0x70
   161  	St_visible      uint8     // 0x73
   162  	St_reftime      uint32    // 0x74
   163  	St_fid          uint64    // 0x78
   164  	St_filefmt      uint8     // 0x80
   165  	St_fspflag2     uint8     // 0x81
   166  	St_res03        [2]uint8  // 0x82
   167  	St_ctimemsec    uint32    // 0x84
   168  	St_seclabel     [8]uint8  // 0x88
   169  	St_res04        [4]uint8  // 0x90
   170  	// end of version 1
   171  	_               uint32    // 0x94
   172  	St_atime64      uint64    // 0x98
   173  	St_mtime64      uint64    // 0xa0
   174  	St_ctime64      uint64    // 0xa8
   175  	St_createtime64 uint64    // 0xb0
   176  	St_reftime64    uint64    // 0xb8
   177  	_               uint64    // 0xc0
   178  	St_res05        [16]uint8 // 0xc8
   179  	// end of version 2
   180  }
   181  
   182  type BpxFilestatus struct {
   183  	Oflag1 byte
   184  	Oflag2 byte
   185  	Oflag3 byte
   186  	Oflag4 byte
   187  }
   188  
   189  type BpxMode struct {
   190  	Ftype byte
   191  	Mode1 byte
   192  	Mode2 byte
   193  	Mode3 byte
   194  }
   195  
   196  // Thr attribute structure for extended attributes
   197  type Bpxyatt_t struct { // DSECT BPXYATT
   198  	Att_id           [4]uint8
   199  	Att_version      uint16
   200  	Att_res01        [2]uint8
   201  	Att_setflags1    uint8
   202  	Att_setflags2    uint8
   203  	Att_setflags3    uint8
   204  	Att_setflags4    uint8
   205  	Att_mode         uint32
   206  	Att_uid          uint32
   207  	Att_gid          uint32
   208  	Att_opaquemask   [3]uint8
   209  	Att_visblmaskres uint8
   210  	Att_opaque       [3]uint8
   211  	Att_visibleres   uint8
   212  	Att_size_h       uint32
   213  	Att_size_l       uint32
   214  	Att_atime        uint32
   215  	Att_mtime        uint32
   216  	Att_auditoraudit uint32
   217  	Att_useraudit    uint32
   218  	Att_ctime        uint32
   219  	Att_reftime      uint32
   220  	// end of version 1
   221  	Att_filefmt uint8
   222  	Att_res02   [3]uint8
   223  	Att_filetag uint32
   224  	Att_res03   [8]uint8
   225  	// end of version 2
   226  	Att_atime64   uint64
   227  	Att_mtime64   uint64
   228  	Att_ctime64   uint64
   229  	Att_reftime64 uint64
   230  	Att_seclabel  [8]uint8
   231  	Att_ver3res02 [8]uint8
   232  	// end of version 3
   233  }
   234  
   235  func BpxOpen(name string, options *BpxFilestatus, mode *BpxMode) (rv int32, rc int32, rn int32) {
   236  	if len(name) < 1024 {
   237  		var namebuf [1024]byte
   238  		sz := int32(copy(namebuf[:], name))
   239  		A2e(namebuf[:sz])
   240  		var parms [7]unsafe.Pointer
   241  		parms[0] = unsafe.Pointer(&sz)
   242  		parms[1] = unsafe.Pointer(&namebuf[0])
   243  		parms[2] = unsafe.Pointer(options)
   244  		parms[3] = unsafe.Pointer(mode)
   245  		parms[4] = unsafe.Pointer(&rv)
   246  		parms[5] = unsafe.Pointer(&rc)
   247  		parms[6] = unsafe.Pointer(&rn)
   248  		bpxcall(parms[:], BPX4OPN)
   249  		return rv, rc, rn
   250  	}
   251  	return -1, -1, -1
   252  }
   253  
   254  func BpxClose(fd int32) (rv int32, rc int32, rn int32) {
   255  	var parms [4]unsafe.Pointer
   256  	parms[0] = unsafe.Pointer(&fd)
   257  	parms[1] = unsafe.Pointer(&rv)
   258  	parms[2] = unsafe.Pointer(&rc)
   259  	parms[3] = unsafe.Pointer(&rn)
   260  	bpxcall(parms[:], BPX4CLO)
   261  	return rv, rc, rn
   262  }
   263  
   264  func BpxFileFStat(fd int32, st *Bpxystat_t) (rv int32, rc int32, rn int32) {
   265  	st.St_id = [4]uint8{0xe2, 0xe3, 0xc1, 0xe3}
   266  	st.St_version = 2
   267  	stat_sz := uint32(unsafe.Sizeof(*st))
   268  	var parms [6]unsafe.Pointer
   269  	parms[0] = unsafe.Pointer(&fd)
   270  	parms[1] = unsafe.Pointer(&stat_sz)
   271  	parms[2] = unsafe.Pointer(st)
   272  	parms[3] = unsafe.Pointer(&rv)
   273  	parms[4] = unsafe.Pointer(&rc)
   274  	parms[5] = unsafe.Pointer(&rn)
   275  	bpxcall(parms[:], BPX4FST)
   276  	return rv, rc, rn
   277  }
   278  
   279  func BpxFileStat(name string, st *Bpxystat_t) (rv int32, rc int32, rn int32) {
   280  	if len(name) < 1024 {
   281  		var namebuf [1024]byte
   282  		sz := int32(copy(namebuf[:], name))
   283  		A2e(namebuf[:sz])
   284  		st.St_id = [4]uint8{0xe2, 0xe3, 0xc1, 0xe3}
   285  		st.St_version = 2
   286  		stat_sz := uint32(unsafe.Sizeof(*st))
   287  		var parms [7]unsafe.Pointer
   288  		parms[0] = unsafe.Pointer(&sz)
   289  		parms[1] = unsafe.Pointer(&namebuf[0])
   290  		parms[2] = unsafe.Pointer(&stat_sz)
   291  		parms[3] = unsafe.Pointer(st)
   292  		parms[4] = unsafe.Pointer(&rv)
   293  		parms[5] = unsafe.Pointer(&rc)
   294  		parms[6] = unsafe.Pointer(&rn)
   295  		bpxcall(parms[:], BPX4STA)
   296  		return rv, rc, rn
   297  	}
   298  	return -1, -1, -1
   299  }
   300  
   301  func BpxFileLStat(name string, st *Bpxystat_t) (rv int32, rc int32, rn int32) {
   302  	if len(name) < 1024 {
   303  		var namebuf [1024]byte
   304  		sz := int32(copy(namebuf[:], name))
   305  		A2e(namebuf[:sz])
   306  		st.St_id = [4]uint8{0xe2, 0xe3, 0xc1, 0xe3}
   307  		st.St_version = 2
   308  		stat_sz := uint32(unsafe.Sizeof(*st))
   309  		var parms [7]unsafe.Pointer
   310  		parms[0] = unsafe.Pointer(&sz)
   311  		parms[1] = unsafe.Pointer(&namebuf[0])
   312  		parms[2] = unsafe.Pointer(&stat_sz)
   313  		parms[3] = unsafe.Pointer(st)
   314  		parms[4] = unsafe.Pointer(&rv)
   315  		parms[5] = unsafe.Pointer(&rc)
   316  		parms[6] = unsafe.Pointer(&rn)
   317  		bpxcall(parms[:], BPX4LST)
   318  		return rv, rc, rn
   319  	}
   320  	return -1, -1, -1
   321  }
   322  
   323  func BpxChattr(path string, attr *Bpxyatt_t) (rv int32, rc int32, rn int32) {
   324  	if len(path) >= 1024 {
   325  		return -1, -1, -1
   326  	}
   327  	var namebuf [1024]byte
   328  	sz := int32(copy(namebuf[:], path))
   329  	A2e(namebuf[:sz])
   330  	attr_sz := uint32(unsafe.Sizeof(*attr))
   331  	var parms [7]unsafe.Pointer
   332  	parms[0] = unsafe.Pointer(&sz)
   333  	parms[1] = unsafe.Pointer(&namebuf[0])
   334  	parms[2] = unsafe.Pointer(&attr_sz)
   335  	parms[3] = unsafe.Pointer(attr)
   336  	parms[4] = unsafe.Pointer(&rv)
   337  	parms[5] = unsafe.Pointer(&rc)
   338  	parms[6] = unsafe.Pointer(&rn)
   339  	bpxcall(parms[:], BPX4CHR)
   340  	return rv, rc, rn
   341  }
   342  
   343  func BpxLchattr(path string, attr *Bpxyatt_t) (rv int32, rc int32, rn int32) {
   344  	if len(path) >= 1024 {
   345  		return -1, -1, -1
   346  	}
   347  	var namebuf [1024]byte
   348  	sz := int32(copy(namebuf[:], path))
   349  	A2e(namebuf[:sz])
   350  	attr_sz := uint32(unsafe.Sizeof(*attr))
   351  	var parms [7]unsafe.Pointer
   352  	parms[0] = unsafe.Pointer(&sz)
   353  	parms[1] = unsafe.Pointer(&namebuf[0])
   354  	parms[2] = unsafe.Pointer(&attr_sz)
   355  	parms[3] = unsafe.Pointer(attr)
   356  	parms[4] = unsafe.Pointer(&rv)
   357  	parms[5] = unsafe.Pointer(&rc)
   358  	parms[6] = unsafe.Pointer(&rn)
   359  	bpxcall(parms[:], BPX4LCR)
   360  	return rv, rc, rn
   361  }
   362  
   363  func BpxFchattr(fd int32, attr *Bpxyatt_t) (rv int32, rc int32, rn int32) {
   364  	attr_sz := uint32(unsafe.Sizeof(*attr))
   365  	var parms [6]unsafe.Pointer
   366  	parms[0] = unsafe.Pointer(&fd)
   367  	parms[1] = unsafe.Pointer(&attr_sz)
   368  	parms[2] = unsafe.Pointer(attr)
   369  	parms[3] = unsafe.Pointer(&rv)
   370  	parms[4] = unsafe.Pointer(&rc)
   371  	parms[5] = unsafe.Pointer(&rn)
   372  	bpxcall(parms[:], BPX4FCR)
   373  	return rv, rc, rn
   374  }
   375  
   376  func BpxCondTimedWait(sec uint32, nsec uint32, events uint32, secrem *uint32, nsecrem *uint32) (rv int32, rc int32, rn int32) {
   377  	var parms [8]unsafe.Pointer
   378  	parms[0] = unsafe.Pointer(&sec)
   379  	parms[1] = unsafe.Pointer(&nsec)
   380  	parms[2] = unsafe.Pointer(&events)
   381  	parms[3] = unsafe.Pointer(secrem)
   382  	parms[4] = unsafe.Pointer(nsecrem)
   383  	parms[5] = unsafe.Pointer(&rv)
   384  	parms[6] = unsafe.Pointer(&rc)
   385  	parms[7] = unsafe.Pointer(&rn)
   386  	bpxcall(parms[:], BPX4CTW)
   387  	return rv, rc, rn
   388  }
   389  func BpxGetthent(in *Pgtha, outlen *uint32, out unsafe.Pointer) (rv int32, rc int32, rn int32) {
   390  	var parms [7]unsafe.Pointer
   391  	inlen := uint32(26) // nothing else will work. Go says Pgtha is 28-byte because of alignment, but Pgtha is "packed" and must be 26-byte
   392  	parms[0] = unsafe.Pointer(&inlen)
   393  	parms[1] = unsafe.Pointer(&in)
   394  	parms[2] = unsafe.Pointer(outlen)
   395  	parms[3] = unsafe.Pointer(&out)
   396  	parms[4] = unsafe.Pointer(&rv)
   397  	parms[5] = unsafe.Pointer(&rc)
   398  	parms[6] = unsafe.Pointer(&rn)
   399  	bpxcall(parms[:], BPX4GTH)
   400  	return rv, rc, rn
   401  }
   402  func ZosJobname() (jobname string, err error) {
   403  	var pgtha Pgtha
   404  	pgtha.Pid = uint32(Getpid())
   405  	pgtha.Accesspid = PGTHA_CURRENT
   406  	pgtha.Flag1 = PGTHA_PROCESS
   407  	var out [256]byte
   408  	var outlen uint32
   409  	outlen = 256
   410  	rv, rc, rn := BpxGetthent(&pgtha, &outlen, unsafe.Pointer(&out[0]))
   411  	if rv == 0 {
   412  		gthc := []byte{0x87, 0xa3, 0x88, 0x83} // 'gthc' in ebcdic
   413  		ix := bytes.Index(out[:], gthc)
   414  		if ix == -1 {
   415  			err = fmt.Errorf("BPX4GTH: gthc return data not found")
   416  			return
   417  		}
   418  		jn := out[ix+80 : ix+88] // we didn't declare Pgthc, but jobname is 8-byte at offset 80
   419  		E2a(jn)
   420  		jobname = string(bytes.TrimRight(jn, " "))
   421  
   422  	} else {
   423  		err = fmt.Errorf("BPX4GTH: rc=%d errno=%d reason=code=0x%x", rv, rc, rn)
   424  	}
   425  	return
   426  }
   427  func Bpx4ptq(code int32, data string) (rv int32, rc int32, rn int32) {
   428  	var userdata [8]byte
   429  	var parms [5]unsafe.Pointer
   430  	copy(userdata[:], data+"        ")
   431  	A2e(userdata[:])
   432  	parms[0] = unsafe.Pointer(&code)
   433  	parms[1] = unsafe.Pointer(&userdata[0])
   434  	parms[2] = unsafe.Pointer(&rv)
   435  	parms[3] = unsafe.Pointer(&rc)
   436  	parms[4] = unsafe.Pointer(&rn)
   437  	bpxcall(parms[:], BPX4PTQ)
   438  	return rv, rc, rn
   439  }
   440  
   441  const (
   442  	PT_TRACE_ME             = 0  // Debug this process
   443  	PT_READ_I               = 1  // Read a full word
   444  	PT_READ_D               = 2  // Read a full word
   445  	PT_READ_U               = 3  // Read control info
   446  	PT_WRITE_I              = 4  //Write a full word
   447  	PT_WRITE_D              = 5  //Write a full word
   448  	PT_CONTINUE             = 7  //Continue the process
   449  	PT_KILL                 = 8  //Terminate the process
   450  	PT_READ_GPR             = 11 // Read GPR, CR, PSW
   451  	PT_READ_FPR             = 12 // Read FPR
   452  	PT_READ_VR              = 13 // Read VR
   453  	PT_WRITE_GPR            = 14 // Write GPR, CR, PSW
   454  	PT_WRITE_FPR            = 15 // Write FPR
   455  	PT_WRITE_VR             = 16 // Write VR
   456  	PT_READ_BLOCK           = 17 // Read storage
   457  	PT_WRITE_BLOCK          = 19 // Write storage
   458  	PT_READ_GPRH            = 20 // Read GPRH
   459  	PT_WRITE_GPRH           = 21 // Write GPRH
   460  	PT_REGHSET              = 22 // Read all GPRHs
   461  	PT_ATTACH               = 30 // Attach to a process
   462  	PT_DETACH               = 31 // Detach from a process
   463  	PT_REGSET               = 32 // Read all GPRs
   464  	PT_REATTACH             = 33 // Reattach to a process
   465  	PT_LDINFO               = 34 // Read loader info
   466  	PT_MULTI                = 35 // Multi process mode
   467  	PT_LD64INFO             = 36 // RMODE64 Info Area
   468  	PT_BLOCKREQ             = 40 // Block request
   469  	PT_THREAD_INFO          = 60 // Read thread info
   470  	PT_THREAD_MODIFY        = 61
   471  	PT_THREAD_READ_FOCUS    = 62
   472  	PT_THREAD_WRITE_FOCUS   = 63
   473  	PT_THREAD_HOLD          = 64
   474  	PT_THREAD_SIGNAL        = 65
   475  	PT_EXPLAIN              = 66
   476  	PT_EVENTS               = 67
   477  	PT_THREAD_INFO_EXTENDED = 68
   478  	PT_REATTACH2            = 71
   479  	PT_CAPTURE              = 72
   480  	PT_UNCAPTURE            = 73
   481  	PT_GET_THREAD_TCB       = 74
   482  	PT_GET_ALET             = 75
   483  	PT_SWAPIN               = 76
   484  	PT_EXTENDED_EVENT       = 98
   485  	PT_RECOVER              = 99  // Debug a program check
   486  	PT_GPR0                 = 0   // General purpose register 0
   487  	PT_GPR1                 = 1   // General purpose register 1
   488  	PT_GPR2                 = 2   // General purpose register 2
   489  	PT_GPR3                 = 3   // General purpose register 3
   490  	PT_GPR4                 = 4   // General purpose register 4
   491  	PT_GPR5                 = 5   // General purpose register 5
   492  	PT_GPR6                 = 6   // General purpose register 6
   493  	PT_GPR7                 = 7   // General purpose register 7
   494  	PT_GPR8                 = 8   // General purpose register 8
   495  	PT_GPR9                 = 9   // General purpose register 9
   496  	PT_GPR10                = 10  // General purpose register 10
   497  	PT_GPR11                = 11  // General purpose register 11
   498  	PT_GPR12                = 12  // General purpose register 12
   499  	PT_GPR13                = 13  // General purpose register 13
   500  	PT_GPR14                = 14  // General purpose register 14
   501  	PT_GPR15                = 15  // General purpose register 15
   502  	PT_FPR0                 = 16  // Floating point register 0
   503  	PT_FPR1                 = 17  // Floating point register 1
   504  	PT_FPR2                 = 18  // Floating point register 2
   505  	PT_FPR3                 = 19  // Floating point register 3
   506  	PT_FPR4                 = 20  // Floating point register 4
   507  	PT_FPR5                 = 21  // Floating point register 5
   508  	PT_FPR6                 = 22  // Floating point register 6
   509  	PT_FPR7                 = 23  // Floating point register 7
   510  	PT_FPR8                 = 24  // Floating point register 8
   511  	PT_FPR9                 = 25  // Floating point register 9
   512  	PT_FPR10                = 26  // Floating point register 10
   513  	PT_FPR11                = 27  // Floating point register 11
   514  	PT_FPR12                = 28  // Floating point register 12
   515  	PT_FPR13                = 29  // Floating point register 13
   516  	PT_FPR14                = 30  // Floating point register 14
   517  	PT_FPR15                = 31  // Floating point register 15
   518  	PT_FPC                  = 32  // Floating point control register
   519  	PT_PSW                  = 40  // PSW
   520  	PT_PSW0                 = 40  // Left half of the PSW
   521  	PT_PSW1                 = 41  // Right half of the PSW
   522  	PT_CR0                  = 42  // Control register 0
   523  	PT_CR1                  = 43  // Control register 1
   524  	PT_CR2                  = 44  // Control register 2
   525  	PT_CR3                  = 45  // Control register 3
   526  	PT_CR4                  = 46  // Control register 4
   527  	PT_CR5                  = 47  // Control register 5
   528  	PT_CR6                  = 48  // Control register 6
   529  	PT_CR7                  = 49  // Control register 7
   530  	PT_CR8                  = 50  // Control register 8
   531  	PT_CR9                  = 51  // Control register 9
   532  	PT_CR10                 = 52  // Control register 10
   533  	PT_CR11                 = 53  // Control register 11
   534  	PT_CR12                 = 54  // Control register 12
   535  	PT_CR13                 = 55  // Control register 13
   536  	PT_CR14                 = 56  // Control register 14
   537  	PT_CR15                 = 57  // Control register 15
   538  	PT_GPRH0                = 58  // GP High register 0
   539  	PT_GPRH1                = 59  // GP High register 1
   540  	PT_GPRH2                = 60  // GP High register 2
   541  	PT_GPRH3                = 61  // GP High register 3
   542  	PT_GPRH4                = 62  // GP High register 4
   543  	PT_GPRH5                = 63  // GP High register 5
   544  	PT_GPRH6                = 64  // GP High register 6
   545  	PT_GPRH7                = 65  // GP High register 7
   546  	PT_GPRH8                = 66  // GP High register 8
   547  	PT_GPRH9                = 67  // GP High register 9
   548  	PT_GPRH10               = 68  // GP High register 10
   549  	PT_GPRH11               = 69  // GP High register 11
   550  	PT_GPRH12               = 70  // GP High register 12
   551  	PT_GPRH13               = 71  // GP High register 13
   552  	PT_GPRH14               = 72  // GP High register 14
   553  	PT_GPRH15               = 73  // GP High register 15
   554  	PT_VR0                  = 74  // Vector register 0
   555  	PT_VR1                  = 75  // Vector register 1
   556  	PT_VR2                  = 76  // Vector register 2
   557  	PT_VR3                  = 77  // Vector register 3
   558  	PT_VR4                  = 78  // Vector register 4
   559  	PT_VR5                  = 79  // Vector register 5
   560  	PT_VR6                  = 80  // Vector register 6
   561  	PT_VR7                  = 81  // Vector register 7
   562  	PT_VR8                  = 82  // Vector register 8
   563  	PT_VR9                  = 83  // Vector register 9
   564  	PT_VR10                 = 84  // Vector register 10
   565  	PT_VR11                 = 85  // Vector register 11
   566  	PT_VR12                 = 86  // Vector register 12
   567  	PT_VR13                 = 87  // Vector register 13
   568  	PT_VR14                 = 88  // Vector register 14
   569  	PT_VR15                 = 89  // Vector register 15
   570  	PT_VR16                 = 90  // Vector register 16
   571  	PT_VR17                 = 91  // Vector register 17
   572  	PT_VR18                 = 92  // Vector register 18
   573  	PT_VR19                 = 93  // Vector register 19
   574  	PT_VR20                 = 94  // Vector register 20
   575  	PT_VR21                 = 95  // Vector register 21
   576  	PT_VR22                 = 96  // Vector register 22
   577  	PT_VR23                 = 97  // Vector register 23
   578  	PT_VR24                 = 98  // Vector register 24
   579  	PT_VR25                 = 99  // Vector register 25
   580  	PT_VR26                 = 100 // Vector register 26
   581  	PT_VR27                 = 101 // Vector register 27
   582  	PT_VR28                 = 102 // Vector register 28
   583  	PT_VR29                 = 103 // Vector register 29
   584  	PT_VR30                 = 104 // Vector register 30
   585  	PT_VR31                 = 105 // Vector register 31
   586  	PT_PSWG                 = 106 // PSWG
   587  	PT_PSWG0                = 106 // Bytes 0-3
   588  	PT_PSWG1                = 107 // Bytes 4-7
   589  	PT_PSWG2                = 108 // Bytes 8-11 (IA high word)
   590  	PT_PSWG3                = 109 // Bytes 12-15 (IA low word)
   591  )
   592  
   593  func Bpx4ptr(request int32, pid int32, addr unsafe.Pointer, data unsafe.Pointer, buffer unsafe.Pointer) (rv int32, rc int32, rn int32) {
   594  	var parms [8]unsafe.Pointer
   595  	parms[0] = unsafe.Pointer(&request)
   596  	parms[1] = unsafe.Pointer(&pid)
   597  	parms[2] = unsafe.Pointer(&addr)
   598  	parms[3] = unsafe.Pointer(&data)
   599  	parms[4] = unsafe.Pointer(&buffer)
   600  	parms[5] = unsafe.Pointer(&rv)
   601  	parms[6] = unsafe.Pointer(&rc)
   602  	parms[7] = unsafe.Pointer(&rn)
   603  	bpxcall(parms[:], BPX4PTR)
   604  	return rv, rc, rn
   605  }
   606  
   607  func copyU8(val uint8, dest []uint8) int {
   608  	if len(dest) < 1 {
   609  		return 0
   610  	}
   611  	dest[0] = val
   612  	return 1
   613  }
   614  
   615  func copyU8Arr(src, dest []uint8) int {
   616  	if len(dest) < len(src) {
   617  		return 0
   618  	}
   619  	for i, v := range src {
   620  		dest[i] = v
   621  	}
   622  	return len(src)
   623  }
   624  
   625  func copyU16(val uint16, dest []uint16) int {
   626  	if len(dest) < 1 {
   627  		return 0
   628  	}
   629  	dest[0] = val
   630  	return 1
   631  }
   632  
   633  func copyU32(val uint32, dest []uint32) int {
   634  	if len(dest) < 1 {
   635  		return 0
   636  	}
   637  	dest[0] = val
   638  	return 1
   639  }
   640  
   641  func copyU32Arr(src, dest []uint32) int {
   642  	if len(dest) < len(src) {
   643  		return 0
   644  	}
   645  	for i, v := range src {
   646  		dest[i] = v
   647  	}
   648  	return len(src)
   649  }
   650  
   651  func copyU64(val uint64, dest []uint64) int {
   652  	if len(dest) < 1 {
   653  		return 0
   654  	}
   655  	dest[0] = val
   656  	return 1
   657  }