home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / csim / source.lha / source / Threads / GnuThreads / mips.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-14  |  1.9 KB  |  69 lines

  1. /*
  2.  * mips.c -- lightweight process initialisation for mips.
  3.  * Copyright (C) 1991 Stephen Crane.
  4.  *
  5.  * This is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 1, or (at your option)
  8.  * any later version.
  9.  *
  10.  * This software is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * see the file COPYING.  If not, write to
  17.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  * author: Stephen Crane, (jsc@doc.ic.ac.uk), Department of Computing,
  20.  * Imperial College of Science, Technology and Medicine, 180 Queen's
  21.  * Gate, London SW7 2BZ, England.
  22.  */
  23.  
  24. #include "gnulwp.h"
  25.  
  26. /*
  27.  * fake setjmp() and longjmp() because builtin longjmp() checks the
  28.  * stack.
  29.  */
  30. static int jmpresult;
  31.  
  32. int savep (jmp_buf jb)
  33. {
  34.     jmpresult = 0;
  35.     /* save context */
  36.     asm ("sw    $31, 8($4)");    /* return address */
  37.     asm ("sw    $30, 4($4)");    /* frame pointer */
  38.     asm ("sw    $sp, 0($4)");    /* stack pointer */
  39.     asm ("sd    $16, 12($4)");    /* callee save registers */
  40.     asm ("sd    $18, 20($4)");
  41.     asm ("sd    $20, 28($4)");
  42.     asm ("sd    $22, 36($4)");
  43.     return (jmpresult);
  44. }
  45.  
  46. void restorep (jmp_buf jb)
  47. {
  48.     jmpresult = 1;
  49.     /* restore context */
  50.     asm ("lw    $sp, 0($4)");
  51.     asm ("lw    $30, 4($4)");
  52.     asm ("lw    $31, 8($4)");
  53.  
  54.     asm ("ld    $16, 12($4)");
  55.     asm ("ld    $18, 20($4)");
  56.     asm ("ld    $20, 28($4)");
  57.     asm ("ld    $22, 36($4)");
  58. }
  59.  
  60. /*
  61.  * initp -- initialise a new process's context.  Stack pointer in
  62.  * newp->context[0], because it's easier for the SPARC code.
  63.  */
  64. void initp (struct pcb *newp)
  65. {
  66.     newp->context[1] = newp->context[0];
  67.     newp->context[2] = (int)wrapp;
  68. }
  69.