stackframe.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-07-16 JasonHu first version
  9. */
  10. #ifndef __STACK_FRAME_H__
  11. #define __STACK_FRAME_H__
  12. #include <rtdef.h>
  13. struct rt_hw_stack_frame
  14. {
  15. rt_uint32_t vec_no;
  16. rt_uint32_t edi;
  17. rt_uint32_t esi;
  18. rt_uint32_t ebp;
  19. rt_uint32_t esp_dummy; /* esp_dummy not used, only use a position */
  20. rt_uint32_t ebx;
  21. rt_uint32_t edx;
  22. rt_uint32_t ecx;
  23. rt_uint32_t eax;
  24. rt_uint32_t gs;
  25. rt_uint32_t fs;
  26. rt_uint32_t es;
  27. rt_uint32_t ds;
  28. rt_uint32_t error_code; /* error code will push into stack if exception has it, or not push 0 by ourself */
  29. rt_uint32_t eip;
  30. rt_uint32_t cs;
  31. rt_uint32_t eflags;
  32. /*
  33. * below will push into stack when from user privilege level enter
  34. * kernel privilege level (syscall/excption/interrupt)
  35. */
  36. rt_uint32_t esp;
  37. rt_uint32_t ss;
  38. } __attribute__((packed));
  39. typedef struct rt_hw_stack_frame rt_hw_stack_frame_t;
  40. typedef void (*hw_thread_func_t)(void *);
  41. /* we use ebp, ebx, edi, esi, eip as context for fork/clone */
  42. #define HW_CONTEXT_MEMBER_NR 5
  43. struct rt_hw_context
  44. {
  45. rt_uint32_t ebp;
  46. rt_uint32_t ebx;
  47. rt_uint32_t edi;
  48. rt_uint32_t esi;
  49. /* first run point to func, other time point to the ret addr of switch_to */
  50. void (*eip) (hw_thread_func_t func, void *arg, void (*texit)());
  51. rt_uint32_t unused;
  52. hw_thread_func_t function;
  53. void *arg;
  54. void *texit; /* thread exit call */
  55. };
  56. typedef struct rt_hw_context rt_hw_context_t;
  57. void rt_hw_stack_frame_dump(rt_hw_stack_frame_t *frame);
  58. #endif /* __STACK_FRAME_H__ */