akaros/kern/arch/x86/setjmp.h
<<
>>
Prefs
   1// Arch specific struct definitions for setjmp/longjmp.
   2
   3#pragma once
   4
   5#include <common.h>
   6
   7#ifdef __x86_64__
   8struct jmpbuf {
   9        uintptr_t retaddr; // return address
  10        uintreg_t rsp;     // post-return rsp
  11        uintreg_t rbp;
  12};
  13
  14static inline void __ros_clobber_callee_regs(void)
  15{
  16        asm volatile ("" : : : "rbx", "r12", "r13", "r14", "r15");
  17}
  18
  19static inline uintptr_t jmpbuf_get_pc(struct jmpbuf *jb)
  20{
  21        return jb->retaddr;
  22}
  23
  24static inline uintptr_t jmpbuf_get_fp(struct jmpbuf *jb)
  25{
  26        return jb->rbp;
  27}
  28
  29#else
  30
  31struct jmpbuf {
  32        uintptr_t retaddr; // return address
  33        uintreg_t esp;     // post-return esp
  34        uintreg_t ebp;
  35};
  36
  37static inline __ros_clobber_callee_regs(void)
  38{
  39        asm volatile ("" : : : "ebx", "esi", "edi");
  40}
  41
  42static inline uintptr_t jmpbuf_get_pc(struct jmpbuf *jb)
  43{
  44        return jb->retaddr;
  45}
  46
  47static inline uintptr_t jmpbuf_get_fp(struct jmpbuf *jb)
  48{
  49        return jb->ebp;
  50}
  51
  52#endif
  53