context.h 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef i386_CONTEXT_H
  2. #define i386_CONTEXT_H
  3. #include <stdint.h>
  4. struct context {
  5. /* Stack Segment, placed here because of the alignment issue... */
  6. uint16_t ss;
  7. /* Used with sgdt/lgdt */
  8. uint16_t gdt_limit;
  9. uint32_t gdt_base;
  10. /* General registers, accessed with pushal/popal */
  11. uint32_t edi;
  12. uint32_t esi;
  13. uint32_t ebp;
  14. uint32_t esp; /* points just below eax */
  15. uint32_t ebx;
  16. uint32_t edx;
  17. uint32_t ecx;
  18. uint32_t eax;
  19. #define ESP_LOC(ctx) (&(ctx)->gs)
  20. /* Segment registers */
  21. uint32_t gs;
  22. uint32_t fs;
  23. uint32_t es;
  24. uint32_t ds;
  25. /* Flags */
  26. uint32_t eflags;
  27. /* Code segment:offset */
  28. uint32_t eip;
  29. uint32_t cs;
  30. /* Optional stack contents */
  31. uint32_t return_addr;
  32. uint32_t param[0];
  33. };
  34. /* Create a new context in the given stack */
  35. struct context *
  36. init_context(uint8_t *stack, uint32_t stack_size, int num_param);
  37. /* Switch context */
  38. struct context *switch_to(struct context *);
  39. /* Holds physical address of boot context */
  40. extern unsigned long __boot_ctx;
  41. /* This can always be safely used to refer to the boot context */
  42. #define boot_ctx ((struct context *) phys_to_virt(__boot_ctx))
  43. #endif /* i386_CONTEXT_H */