Guest User

Untitled

a guest
Aug 13th, 2014
287
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. org 7c00h
  2.  
  3. use16
  4.  
  5. cli
  6. lgdt[gdt]
  7. mov eax,cr4
  8. or al,1
  9. mov cr4,eax
  10. mov eax,cr0
  11. or al,1
  12. mov cr0,eax
  13. jmp gdt_code-gdt_table:pmode
  14.  
  15. vm86:
  16. mov ax,0e41h
  17. mov bx,7
  18. int 10h
  19.  
  20. ;which interrupt trigger to end the virtual 8086 mode?
  21.  
  22. jmp $
  23.  
  24. use32
  25.  
  26. pmode:
  27. mov ax,gdt_data-gdt_table
  28. mov gs,ax
  29. mov fs,ax
  30. mov ds,ax
  31. mov es,ax
  32. mov ss,ax
  33. mov esp,9fffch
  34. mov ax,18h
  35. ltr ax
  36. mov al,11h
  37. out 20h,al
  38. mov al,20h
  39. out 21h,al
  40. mov al,4
  41. out 21h,al
  42. mov al,1
  43. out 21h,al
  44. mov al,255-1 shl 6
  45. out 21h,al
  46. mov edi,idt_table
  47. mov edx,8e00h
  48. mov eax,(gdt_code-gdt_table) shl 16
  49. mov ecx,20h
  50. interrupts1:
  51. mov [edi],eax
  52. mov [edi+4],edx
  53. add edi,8
  54. loop interrupts1
  55. mov edx,8f00h
  56. mov eax,(gdt_code-gdt_table) shl 16
  57. add ecx,8
  58. interrupts2:
  59. mov [edi],eax
  60. mov [edi+4],edx
  61. add edi,8
  62. loop interrupts2
  63. mov edx,8f00h
  64. mov eax,(gdt_code-gdt_table) shl 16
  65. mov ecx,256-8-32
  66. interrupts3:
  67. mov [edi],eax
  68. mov [edi+4],edx
  69. add edi,8
  70. loop interrupts3
  71. mov word[idt_table+20h*8+6*8],second_sector
  72. mov word[idt_table+49*8],function_floppy
  73. lidt[idt]
  74. sti
  75. push 0
  76. push 0
  77. push 0
  78. push 0
  79. push 0
  80. push 0fffeh
  81. push 20000h
  82. push 0
  83. push vm86
  84. iretd
  85. int 49
  86. jmp $
  87.  
  88. function_floppy:
  89. mov dx,3f2h
  90. mov al,1ch
  91. out dx,al
  92. mov al,6
  93. out 0ah,al
  94. mov al,0ffh
  95. out 0ch,al
  96. mov al,0
  97. out 4,al
  98. mov ax,second_sector
  99. out 81h,al
  100. mov al,ah
  101. out 4,al
  102. mov al,0ffh
  103. out 5,al
  104. mov al,1
  105. out 5,al
  106. mov al,2
  107. out 0ah,al
  108. call readmsr
  109. mov dx,3f5h
  110. mov al,66h
  111. out dx,al
  112. mov al,0
  113. out dx,al
  114. mov al,0
  115. out dx,al
  116. mov al,0
  117. out dx,al
  118. mov al,2
  119. out dx,al
  120. mov al,2
  121. out dx,al
  122. mov al,18
  123. out dx,al
  124. mov al,27
  125. out dx,al
  126. mov al,0ffh
  127. out dx,al
  128. iret
  129.  
  130. readmsr:
  131. mov dx,3f4h
  132. in al,dx
  133. and al,0c0h
  134. cmp al,80h
  135. jne readmsr
  136. ret
  137.  
  138. gdt:
  139. dw gdt_end-gdt_table-1
  140. dd gdt_table
  141.  
  142. gdt_table:
  143. dq 0
  144.  
  145. gdt_code:
  146. dw 0ffffh
  147. dw 0
  148. db 0
  149. db 9ah
  150. db 0cfh
  151. db 0
  152.  
  153. gdt_data:
  154. dw 0ffffh
  155. dw 0
  156. db 0
  157. db 92h
  158. db 0cfh
  159. db 0
  160.  
  161. gdt_tss:
  162. dw 0ffffh
  163. dw 0
  164. db 0
  165. db 89h
  166. db 8fh
  167. db 0
  168.  
  169. gdt_end:
  170.  
  171. idt:
  172. dw idt_end-256*8-1
  173. dd idt_table
  174.  
  175. idt_table=256*4
  176.  
  177. idt_end:
  178.  
  179. times 510-($-$$) db 0
  180. dw 0aa55h
  181.  
  182. second_sector:
  183. mov byte[0b8000h],43h
  184. mov byte[0b8000h+1],0ch
  185. mov byte[0b8000h+2],69h
  186. mov byte[0b8000h+3],0ch
  187. mov byte[0b8000h+4],61h
  188. mov byte[0b8000h+5],0ch
  189. mov byte[0b8000h+6],6fh
  190. mov byte[0b8000h+7],0ch
  191. mov byte[0b8000h+8],21h
  192. mov byte[0b8000h+9],0ch
  193. mov byte[0b8000h+10],20h
  194. mov byte[0b8000h+11],0ch
  195. mov byte[0b8000h+12],3ah
  196. mov byte[0b8000h+13],0ch
  197. mov byte[0b8000h+14],29h
  198. mov byte[0b8000h+15],0ch
  199. jmp $
  200.  
  201. times 512-($-second_sector) db 0
RAW Paste Data