spl.c 551 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <ureg.h>
  4. #include "encoding.h"
  5. /* these are declared in this file as we do not want them externally visible.
  6. * inline assembly is not allowed in harvey.
  7. */
  8. i64 _splhi(void);
  9. i64 _spllo(void);
  10. // splhi and spllo return 1 if we were at splhi. This is used in splx, below.
  11. int
  12. splhi(void)
  13. {
  14. u64 cur;
  15. cur = read_csr(sstatus);
  16. _splhi();
  17. return !(cur & 2);
  18. }
  19. int
  20. spllo(void)
  21. {
  22. u64 cur;
  23. cur = read_csr(sstatus);
  24. _spllo();
  25. return !(cur & 2);
  26. }
  27. void
  28. splx(int s)
  29. {
  30. if(s)
  31. _splhi();
  32. else
  33. _spllo();
  34. }