target_arch_thread.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * RISC-V thread support
  3. *
  4. * Copyright (c) 2019 Mark Corbin
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef TARGET_ARCH_THREAD_H
  20. #define TARGET_ARCH_THREAD_H
  21. /* Compare with cpu_set_upcall() in riscv/riscv/vm_machdep.c */
  22. static inline void target_thread_set_upcall(CPURISCVState *regs,
  23. abi_ulong entry, abi_ulong arg, abi_ulong stack_base,
  24. abi_ulong stack_size)
  25. {
  26. abi_ulong sp;
  27. sp = ROUND_DOWN(stack_base + stack_size, 16);
  28. regs->gpr[xSP] = sp;
  29. regs->pc = entry;
  30. regs->gpr[xA0] = arg;
  31. }
  32. /* Compare with exec_setregs() in riscv/riscv/machdep.c */
  33. static inline void target_thread_init(struct target_pt_regs *regs,
  34. struct image_info *infop)
  35. {
  36. regs->sepc = infop->entry;
  37. regs->regs[xRA] = infop->entry;
  38. regs->regs[xA0] = infop->start_stack;
  39. regs->regs[xSP] = ROUND_DOWN(infop->start_stack, 16);
  40. }
  41. #endif /* TARGET_ARCH_THREAD_H */