xo1-wakeup.S 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. .text
  2. #include <linux/linkage.h>
  3. #include <asm/segment.h>
  4. #include <asm/page.h>
  5. #include <asm/pgtable_32.h>
  6. .macro writepost,value
  7. movb $0x34, %al
  8. outb %al, $0x70
  9. movb $\value, %al
  10. outb %al, $0x71
  11. .endm
  12. wakeup_start:
  13. # OFW lands us here, running in protected mode, with a
  14. # kernel-compatible GDT already setup.
  15. # Clear any dangerous flags
  16. pushl $0
  17. popfl
  18. writepost 0x31
  19. # Set up %cr3
  20. movl $initial_page_table - __PAGE_OFFSET, %eax
  21. movl %eax, %cr3
  22. movl saved_cr4, %eax
  23. movl %eax, %cr4
  24. movl saved_cr0, %eax
  25. movl %eax, %cr0
  26. # Control registers were modified, pipeline resync is needed
  27. jmp 1f
  28. 1:
  29. movw $__KERNEL_DS, %ax
  30. movw %ax, %ss
  31. movw %ax, %ds
  32. movw %ax, %es
  33. movw %ax, %fs
  34. movw %ax, %gs
  35. lgdt saved_gdt
  36. lidt saved_idt
  37. lldt saved_ldt
  38. ljmp $(__KERNEL_CS),$1f
  39. 1:
  40. movl %cr3, %eax
  41. movl %eax, %cr3
  42. wbinvd
  43. # Go back to the return point
  44. jmp ret_point
  45. save_registers:
  46. sgdt saved_gdt
  47. sidt saved_idt
  48. sldt saved_ldt
  49. pushl %edx
  50. movl %cr4, %edx
  51. movl %edx, saved_cr4
  52. movl %cr0, %edx
  53. movl %edx, saved_cr0
  54. popl %edx
  55. movl %ebx, saved_context_ebx
  56. movl %ebp, saved_context_ebp
  57. movl %esi, saved_context_esi
  58. movl %edi, saved_context_edi
  59. pushfl
  60. popl saved_context_eflags
  61. ret
  62. restore_registers:
  63. movl saved_context_ebp, %ebp
  64. movl saved_context_ebx, %ebx
  65. movl saved_context_esi, %esi
  66. movl saved_context_edi, %edi
  67. pushl saved_context_eflags
  68. popfl
  69. ret
  70. ENTRY(do_olpc_suspend_lowlevel)
  71. call save_processor_state
  72. call save_registers
  73. # This is the stack context we want to remember
  74. movl %esp, saved_context_esp
  75. pushl $3
  76. call xo1_do_sleep
  77. jmp wakeup_start
  78. .p2align 4,,7
  79. ret_point:
  80. movl saved_context_esp, %esp
  81. writepost 0x32
  82. call restore_registers
  83. call restore_processor_state
  84. ret
  85. .data
  86. saved_gdt: .long 0,0
  87. saved_idt: .long 0,0
  88. saved_ldt: .long 0
  89. saved_cr4: .long 0
  90. saved_cr0: .long 0
  91. saved_context_esp: .long 0
  92. saved_context_edi: .long 0
  93. saved_context_esi: .long 0
  94. saved_context_ebx: .long 0
  95. saved_context_ebp: .long 0
  96. saved_context_eflags: .long 0