context.S 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * File : context.S
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2006-09-15 QiuYi The first version
  13. * 2006-10-09 Bernard add rt_hw_context_switch_to implementation
  14. */
  15. /**
  16. * @addtogroup ia32
  17. */
  18. /*@{*/
  19. /*
  20. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  21. */
  22. .globl rt_hw_context_switch
  23. rt_hw_context_switch:
  24. pushfl /*pushed eflags*/
  25. push %cs /*push cs register*/
  26. pushl 0x8(%esp) /*pushed eip register*/
  27. pushl $0 /*fill irqno*/
  28. push %ds /*push ds register*/
  29. push %es /*push es register*/
  30. pushal /*push eax,ecx,edx,ebx,esp,ebp,esp,edi registers*/
  31. movl 0x40(%esp), %eax /*to thread TCB*/
  32. movl 0x3c(%esp), %ebx /*from thread TCB*/
  33. movl %esp, (%ebx) /*store esp in preempted tasks TCB*/
  34. movl (%eax), %esp /*get new task stack pointer*/
  35. popal /*restore new task TCB*/
  36. pop %es
  37. pop %ds
  38. add $4,%esp /*skip irqno*/
  39. iret
  40. /*
  41. * void rt_hw_context_switch_to(rt_uint32 to);
  42. */
  43. .globl rt_hw_context_switch_to
  44. rt_hw_context_switch_to:
  45. push %ebp
  46. movl %esp, %ebp
  47. movl 0x8(%ebp), %eax /* to thread TCB */
  48. movl (%eax), %esp /* get new task stack pointer */
  49. popal /* restore new task TCB*/
  50. pop %es
  51. pop %ds
  52. add $4, %esp /* skip irqno */
  53. iret
  54. /*
  55. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  56. */
  57. .globl rt_thread_switch_interrput_flag
  58. .globl rt_interrupt_from_thread
  59. .globl rt_interrupt_to_thread
  60. .globl rt_hw_context_switch_interrupt
  61. rt_hw_context_switch_interrupt:
  62. pushl %ebp
  63. movl %esp, %ebp
  64. movl 0xc(%ebp), %eax
  65. movl 0x8(%ebp), %ebx
  66. movl $rt_thread_switch_interrput_flag, %ecx
  67. movl (%ecx), %edx
  68. cmp $0x1, %edx
  69. jz _reswitch
  70. movl $0x1, %edx /*set rt_thread_switch_interrput_flag to 1*/
  71. movl %edx, (%ecx)
  72. movl $rt_interrupt_from_thread, %edx /*set rt_interrupt_from_thread*/
  73. movl %ebx, (%edx)
  74. _reswitch:
  75. movl $rt_interrupt_to_thread, %edx /*set rt_interrupt_to_thread*/
  76. movl %eax, (%edx)
  77. leave
  78. ret