Advertisement
Guest User

Untitled

a guest
Jan 6th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. .text
  2.  
  3. .globl enter_longmode
  4. .type enter_longmode,@function
  5. enter_longmode:
  6. call 1f
  7. 1: popl %ebx
  8. addl $_GLOBAL_OFFSET_TABLE_ + (. - 1b), %ebx
  9.  
  10. cli
  11.  
  12. inb $0x70, %al
  13. orb $0x80, %al
  14. outb %al, $0x70
  15.  
  16. movl $exception_handler, %eax
  17. movl %eax, %edx
  18. andl $0x0000FFFF, %eax
  19. orl $0x00180000, %eax
  20.  
  21. andl $0xFFFF0000, %edx
  22. orl $0x00008E00, %edx
  23.  
  24. movl $256, %ecx
  25. movl $idt, %esi
  26. 1:
  27. movl %eax, 0(%esi)
  28. movl %edx, 4(%esi)
  29. addl $8, %esi
  30. loopl 1b
  31.  
  32. lidt (idtr)
  33.  
  34. movl $(tss_end - tss), %ecx
  35. movl $tss, %edx
  36.  
  37. movw %cx, _tss_dsc
  38. movw %dx, _tss_dsc + 2
  39. shrl $16, %edx
  40. movb %dl, _tss_dsc + 4
  41. movb %dh, _tss_dsc + 7
  42.  
  43. lgdt (gdtr)
  44. ljmp $0x18, $1f
  45.  
  46. 1:
  47. movl $0x10, %eax
  48. movw %ax, %ds
  49. movw %ax, %es
  50. movw %ax, %fs
  51. movw %ax, %gs
  52. movw %ax, %ss
  53.  
  54. movw $0x20, %ax
  55. ltr %ax
  56.  
  57. movl $(1 << 5), %eax
  58. movl %eax, %cr4
  59.  
  60. movl $0xC0000080, %ecx
  61. rdmsr
  62. orl $(1 << 8), %eax
  63. wrmsr
  64.  
  65. movl %cr0, %eax
  66. orl $(1 << 31), %eax
  67. movl %eax, %cr0
  68.  
  69. leal long_exchange@GOTOFF(%ebx), %eax
  70.  
  71. lidt (null_idtr)
  72.  
  73. ljmp $0x08, $long_mode
  74.  
  75. .size enter_longmode, . -enter_longmode
  76.  
  77. .section ".rodata", "a"
  78.  
  79. .balign 8
  80. .type null_idtr,@object
  81. null_idtr:
  82. .word 0
  83. .long 0
  84. .size null_idtr, . - null_idtr
  85.  
  86. .balign 8
  87. .type idtr,@object
  88. idtr:
  89. .word idt_end - idt
  90. .long idt
  91. .size idtr, . - idtr
  92.  
  93. .balign 8
  94. .type gdtr,@object
  95. gdtr:
  96. .word gdt_end - gdt
  97. .long gdt
  98. .size gdtr, . - gdtr
  99.  
  100. .balign 8
  101. .type gdt,@object
  102. gdt:
  103. .word 0x0000, 0, 0x0000, 0x00
  104. // 64-bit code segment
  105. .word 0xFFFF, 0, 0x9A00, 0xAF
  106. // Data segment
  107. .word 0xFFFF, 0, 0x9200, 0xAF
  108. // 32-bit code segment
  109. .word 0xFFFF, 0, 0x9A00, 0xCF
  110. // Dummy TSS
  111. _tss_dsc:
  112. .word 0x0000, 0x0000, 0x8900, 0x40
  113. gdt_end:
  114. .size gdt, . - gdt
  115.  
  116. .bss
  117.  
  118. .balign 8
  119. .type tss,@object
  120. tss:
  121. .fill 104
  122. tss_end:
  123. .size tss, . - tss
  124.  
  125.  
  126. .balign 8
  127. .type idt,@object
  128. idt:
  129. .rept 256
  130. .quad 0
  131. .endr
  132. idt_end:
  133. .size idt, . - idt
  134.  
  135. .code64
  136. .text
  137.  
  138. .balign 16
  139. .globl long_mode
  140. .type long_mode,%function
  141. long_mode:
  142. xorq %rbx, %rbx
  143. movl %eax, %ebx
  144.  
  145. movq 8(%rbx), %rax
  146. movq 0(%rbx), %rbx
  147.  
  148. jmp *%rbx
  149.  
  150. .size long_mode,. - long_mode
  151.  
  152. .bss
  153. .balign 8
  154. .globl long_exchange
  155. .type long_exchange,object
  156. long_exchange:
  157. .quad 0
  158. .quad 0
  159. .size long_exchange,. - long_exchange
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement