NAME

Appendix B : MIPS Assembly Language Information

DESCRIPTION

This section gives helpful information to system programmers who understand MIPS assembly language.

The MIPS Assembly Language Interface is described in relation to the following:

System Call Conventions

System calls to the pSOS+/MIPS kernel are made by executing the system call (syscall) instruction. The pSOS+/MIPS kernel expects all system call arguments, as well as a function code indicating which system call is being made, to be located in the CPU registers before the syscall instruction is executed. Figure 4. ``System Call Argument Transfer" illustrates the argument transfer.

$t0 Function Code
$t1 Number of Parameters
$a0 Argument 1
$a1 Argument 2
$a2 Argument 3
$a3 Argument 4
$t2 Argument 5
$t3 Argument 6
$t4 Argument 7
$t5 Argument 8

Figure 4. System Call Argument Transfer

The CPU register $t0 must contain a code indicating which system call is being made, and register $t1 must contain the number of arguments for the function code. Function codes are listed in "pSOSystem Function Codes" on page B-5. Normally, a special assembly language module (known as a bindings module) sets up the CPU and executes the syscall instruction.

As a result of the syscall instruction, the processor initiates system call exception processing, transferring control to the corresponding vector code. The vector code must allocate a small stack frame, save some registers, and transfer control to the pSOS+ kernel's system call entry point. This is described in detail below.

Component Call Conventions

In contrast to the pSOS+/MIPS kernel, pSOSystem/MIPS components (e.g. pNA+) expect the system call arguments and function code to be located on the stack before the syscall instruction is executed. Figure 5. illustrates the component call stack frame.

sp ------> sp+0 Back chain pointer
sp+4 Return address
sp+8 Function code + component offset
sp+12 Argument list pointer (points to argument 1)
sp+16 Argument 1
sp+20 Argument 2
sp+24 Argument 3
sp+28 Argument 4
sp+32 Argument 5
sp+36 Argument 6
sp+40 Argument 7
sp+44 Argument 8

Figure 5. Component Call Stack Frame

Kernel Entry Points

The pSOS+ kernel is initialized by passing control to its initialization entry point, which is located at offset 0x40 from the start of the kernel code.

When a system call is made, control must be passed to the system call entry point, located at offset 0x48 from the start of the kernel code. Upon entry, the top of the stack must contain a pSOSystem stack frame. The next frame on the stack (pointed to by the back chain pointer) must be set up as described in "System Call Conventions" on page B-1.

Interrupt Entry and Exit

As soon as possible, an interrupt service routine (ISR) should call the pSOS+ i_enter() routine. Normally this is done immediately after allocating a pSOSystem stack frame and saving a few registers in the frame.

Upon return from i_enter(), the ISR should do whatever is necessary to service the interrupt. When the interrupt has been serviced, the ISR must complete by calling the pSOS+ i_return() entry.

I_ENTER

The pSOS+ i_enter() entry point is located at offset 0x60 from the beginning of the pSOS+ kernel code. It should be called via the MIPS jal instruction. The interface is as follows:

INPUT:
none

$ra: return address (address of instruction following the call to i_enter(), plus the delay slot)

OUTPUT:
none

DESTROYS:
none

NOTES:
i_enter() saves all volatile registers ($a0-$a3/$t0-$t9/mdlo/mdhi), that have not been saved by exc_dispatch(), in the standard exception stack frame. The CPU registers $at, $v0, $v1, $gp, $s7, C0_SR, C0_CAUSE and C0_EPC have already been saved by exc_dispatch().

This service routine gives the pSOS+ kernel a chance to perform interrupt entry operations. It must be called at the beginning of an interrupt handler before the interrupt is re-enabled.

The address of i_enter() is kept in a structure called exc_rootptrs, which is set up by pSOSystem on system startup. Register $k0 may be used at all times to access this structure.

I_RETURN

The pSOS+ i_return() entry point is located at offset 0x58 from the start of the pSOS+ kernel code. It provides and establishes a standard exit convention for all ISRs.

Almost without exception, i_return() must be used in place of the rfe instruction (ERET instruction for R4600-compatible processors) to exit an ISR. It is absolutely mandatory to exit an ISR with i_return() if i_enter() has been called on entry. Otherwise, the task's stack will not be restored to the value it had when the interrupt occurred. The actions performed by i_return() depend on the type of code executing when the serviced interrupt occurred.

Upon entry to i_return(), the stack pointer should point to the pSOSystem stack frame that was created by the ISR vector code and i_enter(). All of the saved processor's registers will be restored by this routine. A (j) instruction shall be used to transfer control to i_return().

The address of i_return() is kept in a structure called exc_rootptrs, which is set up by pSOSystem on system startup. Register $k0 may be used at all times to access this structure.

The Exception Root Pointers

pSOSystem maintains a structure called exc_rootptrs, containing the addresses of routines that are essential for the MIPS exception processing. Also, a copy of pSOSystem's PIC and PID global pointers are kept within this structure. The layout of this structure is shown below.

struct exc_rootptrs {
   void (*pSOSIEnter)();   /* Address of pSOS+ i_enter() entry */
  void (*pSOSIReturn)();  /* Address of pSOS+ i_return() entry */
 void (*pMontIEnter)();  /* Address of pMONT+ i_enter() entry */
 void (*pMontIReturn)();  /* Address of pMONT+ i_return() entry */
       ulong PICbase;  /* PIC relocation register value */
     ulong PIDbase;  /* PID relocation register value */
     };

The pSOSystem Standard Stack Frame

Upon occurrence of any MIPS exception, either a hardware interrupt or an instruction- caused exception, a piece of special code called an exception dispatcher is executed. The dispatcher allocates a stack frame, saves some minimum number of registers, and then transfers control to the appropriate exception handler. The format of the stack frame it creates is shown in Figure 6. ``pSOSystem Standard Stack Frame", below.

sp ------> ZERO Reserved for interaction between pSOS+ and pROBE+
$AT Save value in $at
$V0...$V1 Save values in $v0...$v1
$A0...$A3 Save values in $a0...$a3
$T0...$T7 Save values in $t0...$t7
$S0...$S7 Save values in $s0...$s7
$T8...$T9 Save values in $t8...$t9
$K0...$K1 Save values in $k0...$k1
$GP Save value in $gp
$SP Save value in $sp
$FP Save value in $fp
$RA Save value in $ra
$MDLO Save value in $mdlo
$MDHI Save value in $mdhi
ASRLINK Used for ASR-management
ASRERRNO Used for ASR-management
ASRMODE Used for ASR-management
UNUSED Unused
EXCTYPE Save exception type
CAUSE Save value in cause register
SR Save value in $sr
EPC Save value in EPC register
BADVADDR Save value in BADVADDR

Figure 6. pSOSystem Standard Stack Frame

The exception dispatch code saves $sp, $sr, $at, $a0, $a1, $s7, $gp, $ra, and also the contents of the CAUSE, EPC, and BADVADDR registers. The exception type, tlb-miss or general, is also saved here.

pSOSystem Function Codes

The following pages contain a list of pSOSystem function codes.

Function Code
ACCEPT 0x506
ACCESS_F 0x213
ADD_NI 0x517
ANNEX_F 0x211
AS_CATCH 0x2F
AS_RETURN 0x31
AS_SEND 0x30
ATOF 0x301
ATOI 0x302
ATOL 0x303
BIND 0x503
BSEARCH 0x364
CALLOC 0x304
CHANGE_DIR 0x20C
CHMOD_F 0x225
CHNG_ROUTE 0x518
CHOWN_F 0x227
CLEARERR 0x305
CLOSE 0x502
CLOSE_DIR 0x218
CLOSE_F 0x214
CONNECT 0x504
CREATE_F 0x208
CTYPE 0x3C8
DE_CLOSE 0x5D
DE_CNTRL 0x60
DE_INIT 0x5B
DE_OPEN 0x5C
DE_READ 0x5E
DE_WRITE 0x5F
ERRNO_ADDR 0x0C
EV_ASEND 0x4A
EV_RECEIVE 0x2D
EV_SEND 0x2C
F_ADDR 0x31D
FCHMOD_F 0x226
FCHOWN_F 0x228
FCLOSE 0x308
FEOF 0x309
FERROR 0x30A
FFLUSH 0x30B
FGETC 0x30C
FGETPOS 0x30E
FGETS 0x30D
FILBUF 0x30F
FLSBUF 0x310
FOPEN 0x311
FPRINTF 0x312
FPUTC 0x313
FPUTS 0x314
FREAD 0x315
FREE 0x316
FREOPEN 0x317
FSCANF 0x318
FSEEK 0x319
FSETPOS 0x31A
FSTAT_F 0x222
FSTAT_VFS 0x21D
FTELL 0x31B
FTRUNCATE_F 0x220
FWRITE 0x31C
GET_ERRNO 0x378
GET_FN 0x219
GET_ID 0x51B
GETC 0x31E
GETCHAR 0x31F
GETPEERNAME 0x510
GETS 0x320
GETSOCKNAME 0x50F
GETSOCKOPT 0x50E
INIT_VOL 0x201
IOCTL 0x516
K_FATAL 0x43
K_TERMINATE 0x44
LINK_F 0x229
LISTEN 0x505
LOCK_F 0x212
LSEEK_F 0x20E
LSTAT_F 0x223
M_EXT2INT 0x45
M_INT2EXT 0x46
MAKE_DIR 0x209
MALLOC 0x322
MEMCHR 0x365
MEMCMP 0x366
MEMMOVE 0x368
MEMSET 0x369
MM_L2P 0x1B
MM_P2L 0x1C
MM_PMAP 0x1D
MM_PREAD 0x1F
MM_PWRITE 0x20
MM_SPROTECT 0x21
MM_UNMAP 0x1E
MOUNT_VOL 0x202
MOVE_F 0x20B
NFSMOUNT_VOL 0x224
OPEN_DIR 0x216
OPEN_F 0x20D
OPEN_FN 0x21A
PCINIT_VOL 0x21B
PCMOUNT_VOL 0x21C
PERROR 0x323
PNA_ALLOCB 0x528
PNA_ERRNO 0x515
PNA_FREEMSG 0x529
PNA_INIT 0x514
PRINTF 0x324
PT_CREATE 0x14
PT_DELETE 0x16
PT_GETBUF 0x17
PT_IDENT 0x15
PT_RETBUF 0x18
PT_SGETBUF 0x19
PUTC 0x325
PUTCHAR 0x326
PUTS 0x327
Q_ASEND 0x4B
Q_AURGENT 0x4C
Q_AVSEND 0x54
Q_AVURGENT 0x55
Q_BROADCAST 0x29
Q_CREATE 0x24
Q_DELETE 0x26
Q_IDENT 0x25
Q_RECEIVE 0x2A
Q_SEND 0x27
Q_URGENT 0x28
Q_VBROADCAST 0x52
Q_VCREATE 0x4D
Q_VDELETE 0x4F
Q_VIDENT 0x4E
Q_VRECEIVE 0x53
Q_VSEND 0x50
Q_VURGENT 0x51
QSORT 0x36A
RAND 0x328
READ_DIR 0x217
READ_F 0x20F
READ_LINK 0x22B
READ_VOL 0x205
REALLOC 0x329
RECV 0x50A
RECVFROM 0x50C
RECVMSG 0x50B
REMOVE 0x32A
REMOVE_F 0x20A
RENAME 0x32B
REWIND 0x32C
RN_CREATE 0x0E
RN_DELETE 0x10
RN_GETSEG 0x11
RN_IDENT 0x0F
RN_RETSEG 0x12
SCANF 0x32D
SELECT 0x511
SEND 0x507
SENDMSG 0x508
SENDTO 0x509
SET_ID 0x51A
SETBUF 0x32E
SETSOCKOPT 0x50D
SETVBUF 0x32F
SHR_SOCKET 0x519
SHUTDOWN 0x512
SM_AV 0x49
SM_CREATE 0x33
SM_DELETE 0x35
SM_IDENT 0x34
SM_P 0x36
SM_V 0x37
SOCKET 0x501
SPRINTF 0x330
SRAND 0x331
SSCANF 0x332
STAT_F 0x221
STAT_VFS 0x215
STRCAT 0x36B
STRCHR 0x36C
STRCMP 0x36D
STRCPY 0x36E
STRCSPN 0x36F
STRLEN 0x370
STRNCAT 0x371
STRNCMP 0x372
STRNCPY 0x373
STRPBRK 0x374
STRRCHR 0x375
STRSPN 0x376
STRSTR 0x377
STRTOD 0x333
STRTOK 0x334
STRTOL 0x335
STRTOUL 0x336
SYMLINK_F 0x22A
SYNC_VOL 0x203
T_CREATE 0x01
T_DELETE 0x05
T_GETREG 0x0A
T_IDENT 0x02
T_MODE 0x09
T_RESTART 0x04
T_RESUME 0x07
T_SETPRI 0x08
T_SETREG 0x0B
T_START 0x03
T_SUSPEND 0x06
TM_CANCEL 0x40
TM_EVAFTER 0x3E
TM_EVEVERY 0x41
TM_EVWHEN 0x3F
TM_GET 0x3B
TM_SET 0x3A
TM_TICK 0x39
TM_WKAFTER 0x3C
TM_WKWHEN 0x3D
TMPFILE 0x337
TMPNAM 0x338
TRUNCATE_F 0x21F
UNGETC 0x339
UNMOUNT_VOL 0x204
UTIME_F 0x207
VERIFY_VOL 0x21E
VFPRINTF 0x33A
VPRINTF 0x33B
VSPRINTF 0x33C
WRITE_F 0x210
WRITE_VOL 0x206





psos_support@isi.com

Copyright © 1996, Integrated Systems, Inc. All rights reserved.