cpcmd.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *  arch/s390/kernel/cpcmd.c
  3.  *
  4.  *  S390 version
  5.  *    Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6.  *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  7.  */
  8. #include <linux/string.h>
  9. #include <linux/spinlock.h>
  10. #include <asm/cpcmd.h>
  11. #include <asm/ebcdic.h>
  12. #include <asm/system.h>
  13. static spinlock_t cpcmd_lock = SPIN_LOCK_UNLOCKED;
  14. static char cpcmd_buf[128];
  15. void cpcmd(char *cmd, char *response, int rlen)
  16. {
  17.         const int mask = 0x40000000L;
  18. unsigned long flags;
  19.         int cmdlen;
  20. spin_lock_irqsave(&cpcmd_lock, flags);
  21.         cmdlen = strlen(cmd);
  22.         strcpy(cpcmd_buf, cmd);
  23.         ASCEBC(cpcmd_buf, cmdlen);
  24.         if (response != NULL && rlen > 0) {
  25.                 asm volatile ("   lrag  2,0(%0)n"
  26.                               "   lgr   4,%1n"
  27.                               "   o     4,%4n"
  28.                               "   lrag  3,0(%2)n"
  29.                               "   lgr   5,%3n"
  30.                               "   sam31n"
  31.                               "   .long 0x83240008 # Diagnose 83n"
  32.                               "   sam64"
  33.                               : /* no output */
  34.                               : "a" (cpcmd_buf), "d" (cmdlen),
  35.                                 "a" (response), "d" (rlen), "m" (mask)
  36.                               : "2", "3", "4", "5" );
  37.                 EBCASC(response, rlen);
  38.         } else {
  39.                 asm volatile ("   lrag  2,0(%0)n"
  40.                               "   lgr   3,%1n"
  41.                               "   sam31n"
  42.                               "   .long 0x83230008 # Diagnose 83n"
  43.                               "   sam64"
  44.                               : /* no output */
  45.                               : "a" (cpcmd_buf), "d" (cmdlen)
  46.                               : "2", "3"  );
  47.         }
  48. spin_unlock_irqrestore(&cpcmd_lock, flags);
  49. }