Advertisement
rnort

REAL-PROTECTED

Nov 19th, 2012
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .386
  2.  
  3. descr struc
  4. lim     dw 0
  5. base_l  dw 0
  6. base_m  db 0
  7. attr_1  db 0
  8. attr_2  db 0
  9. base_h  db 0
  10. descr   ends
  11.  
  12. ; DATA segment
  13. data segment use16
  14.  
  15. gdt_null    descr   <0,0,0,0,0,0>
  16. gdt_data    descr   <data_size-1, 0,0,92h, 0,0>
  17. gdt_code    descr   <code_size-1, 0,0, 98h, 0,0>
  18. gdt_stack   descr   <255, 0,0,92h,0,0>
  19. gdt_screen  descr   <3999,8000h, 0Bh, 92h, 0,0,>
  20. gdr_size = $-gdt_null
  21.  
  22. pdescr  df 0
  23. sym     db 1
  24. attr    db 1Eh
  25. msg     db 27,'Returned to real mode!',27,'$'
  26. data_size=$-gdt_null
  27. data ends
  28.  
  29. text segment use16
  30.     assume CS:text, CS:data
  31. main proc
  32.     xor eax, eax
  33.     mov ax, data
  34.     mov ds, ax
  35.  
  36.     shl eax, 4
  37.     mov ebp, eax
  38.     mov bx, offset gdt_data
  39.     mov [bx].base_l, ax
  40.     shr eax, 16
  41.     mov [bx].base_m, AL
  42.  
  43.     xor eax, eax
  44.     mov ax, CS
  45.     shl eax, 4
  46.     mov BX, offset gdt_code
  47.     mov [bx].base_l, ax
  48.     shr eax, 16
  49.     mov [bx].base_m, al
  50.  
  51.     xor eax, eax
  52.     mov ax, ss
  53.     shl eax, 4
  54.     mov bx, offset gdt_stack
  55.     mov [bx].base_l, ax
  56.     shr eax, 16
  57.     mov [bx].base_m, al
  58.  
  59.     mov dword ptr pdescr+2, ebp
  60.     mov word ptr pdescr, gdt_size-1
  61.     lgdt pdescr
  62.  
  63.     mov ax, 40h
  64.     mov es, ax
  65.     mov word ptr es:[67h], offset return
  66.     mov es:[69h], cs
  67.     mov al, 0Fh
  68.     out 70h, al
  69.     mov al, 0Ah
  70.     out 71h, al
  71.     cli
  72.  
  73.     mov eax, cr0
  74.     or eax, 1
  75.     mov cr0, eax
  76.  
  77. ;; Now in protected mode ;;
  78.  
  79.     db 0EAh
  80.     dw offset continue
  81.     dw 16
  82.  
  83. continue:
  84.  
  85.     mov ax, 8
  86.     mov ds, ax
  87.  
  88.     mov ax, 24
  89.     mov ss, ax
  90.  
  91.     mov ax, 32
  92.     mov es, ax
  93.  
  94.     mov di, 1920
  95.     mov cx, 80
  96.     mov ax, word ptr sym
  97.  
  98. scrn:
  99.     swosw
  100.     inc al
  101.     loop scrn
  102.  
  103.     mov al, 0FEh
  104.     out 64h, al
  105.     hlt
  106.  
  107. ;; Now in real mode ;;
  108.  
  109. return:
  110.     mov ax, data
  111.     mov ds, ax
  112.     mov ax, stk
  113.     mov ss, ax
  114.     mov sp, 256
  115.     sti
  116.  
  117.     mov ah, 09h
  118.     mov dx, offset msg
  119.     int 21h
  120.     mov ax, 4c00h
  121.     int 21h
  122. main endp
  123.  
  124. code_size=$-main
  125. text    ends
  126.  
  127. stk segment stack use16
  128.     db 256 dup('^')
  129. stck ends
  130.     end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement