home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / asm / 80x0393 / protmode.txt < prev    next >
Encoding:
Text File  |  1994-02-23  |  6.7 KB  |  328 lines

  1. (2831)  Mon 14 Feb 94 12:46p
  2. By: Elad Nachman
  3. To: Maynard Philbrook
  4. Re: PROTECT INSTRUTIONS
  5. St:                                                                       <1848
  6. ---------------------------------------------------------------------------
  7. @MSGID: 2:403/169.4 2d5f72fc
  8. @REPLY: 1:320/42 52f6b466
  9. @PID: GED G1218
  10. Hello Maynard!
  11.  
  12.  On the Tuesday February 08 1994 22:49, Maynard Philbrook Headbanged on my
  13. metal fuses and wrote to Craig Jackson:
  14.  
  15.  MP> EMM386 interface.. But if i Disble EMM386 i can do any of thing
  16.  MP> with out a problem. I have most of the data on the EMM386 and it
  17.  MP> explains some what about the few functions in the VCPI, it
  18.  MP> mentions getting the machine state and getting a LDT but my Docs
  19.  MP> do not explain how to do it.
  20.  
  21. You can go to a raw-like CPL0 protected mode via VCPI using int 67/ax=de01
  22. and then int 67/ax=de0c (You must set the LDT,GDT,IDT,TSS,Page frame and so
  23. on).
  24. Here's a one (Took me fairly long to do, but it works!):
  25.  
  26.  
  27. .radix 16
  28. .386P
  29. code segment USE16
  30. assume cs:code,ds:code,es:code,ss:code
  31. org 100h
  32.  
  33. begin:
  34. jmp start
  35.  
  36. desc struc
  37. Limit dw ? ; Segment Limit, 286/386
  38. Base1 dw ?
  39. base2 db ? ; 24 linear Pointer to start of segment
  40. rights db ? ; Access Rights
  41. dat386 db ? ; limit+other flags
  42. base3 db ? ; 386 Addition
  43. ENDS
  44.  
  45. TSS equ $
  46. previous_tss dd 0 ; only low-word is used
  47. _esp0 dd 0 ; Esp for ring 0
  48. _ss0 dd 028h ; SS for ring 0, only low word used
  49. _esp1 dd 0 ; same for ring 1
  50. _ss1 dd 028h ;   "    "    "  1
  51. _esp2 dd 0 ;  same for ring 2
  52. _ss2 dd 028h ; same for ring 2
  53. _cr3_ dd 0
  54. _eip dd 0
  55. _eflags dd 0
  56. _eax dd 0
  57. _ecx dd 0
  58. _edx dd 0
  59. _ebx dd 0
  60. _esp dd 0 ; Current - After Task Switch
  61. _Ebp dd 0
  62. _esi dd 0
  63. _edi dd 0
  64. _es dd 20h
  65. _cs dd 30h ; Set after task switch
  66. _ss dd 28h ; current
  67. _ds dd 28h
  68. _fs dd 28h
  69. _gs dd 28h
  70. _LDTR_ dd 0 ; All selectors from _es to _ldtr_ are counted only for low word
  71. IO_bitmap dd 00680000h ; I/O premission bitmap - if 0, not I/O allowed
  72. bitmap db 100h dup (0) ; I/O bitmap - most required I/Os allowed
  73.  
  74. pdata equ $
  75. _cr3 dd 0 ; Value for CR3 register - address of PDT
  76. _GDTR dd 0 ; Pointer to GDTR register
  77. _IDTR dd 0 ; Pointer to IDTR register
  78. _LDTR dw 0 ; Selector for LDT
  79. _TSS dw 40h ; Selector for TSS
  80. entry df 003000000000h ; FWORD cs:EIP
  81.  
  82. msg1 db "No Memory Manager Present",'$'
  83. msg2 db "Not in V86 mode!",'$'
  84. msg3 db "No VCPI installed!",'$'
  85.  
  86.  
  87. ServerPtr df 000800000000h
  88.  
  89. pt_seg dw 0  ; Segment for page table
  90. pdt_seg dw 0 ; Segment for Page Directory Table
  91. real_seg dw 0
  92.  
  93. IDTR equ $
  94. IDTR1 dw 0ffh*8
  95. IDTR2 dd ?
  96. IDT dq 0ffh dup (0)
  97.  
  98. GDTR equ $
  99. GDTR1 dw 080h  ; GDT limit (16 descriptors)
  100. GDTR2 dd ?  ; Linear 32 bit pointer to GDT
  101. nope dw 0 ; For compatibility ??!?!?!?
  102. GDT equ $
  103. data_nul dq 4 dup (0) ; null descriptor
  104. data2 desc <0ffffh,8000h,0bh,10010010b,11001111b,0> ; 4GB video segment - 20h
  105. data3 desc <0ffffh,0,0,10010010b,0,0> ; Real Mode style 64KB data segment
  106. data4 desc <0ffffh,0,0,10011010b,0,0> ; Real Mode Style 64kb Code Segment - 30h
  107. data5 desc <0ffffh,0,0,10010010b,11001111b,0> ; 4GB Data Segment - 38h
  108. tss_sel desc <0160h,0,0,10001001b,0,0> ; Selector for Task Segmet = 40h
  109. data_ dq 6 dup (0) ; More descriptors
  110.  
  111. stck db 200h dup (0) ; stack
  112.  
  113. start:
  114. push ds
  115. xor ax,ax
  116. mov ds,ax
  117. mov eax,ds:[67h*4]
  118. pop ds
  119. or eax,eax
  120. jne EMM
  121. mov ah,9h
  122. mov dx,offset msg1
  123. int 21h
  124. mov ah,4ch
  125. int 21h
  126. emm:
  127. smsw ax
  128. test ax,1
  129. jne v86
  130. mov ah,09h
  131. mov dx,offset msg2
  132. int 21h
  133. mov ah,4ch
  134. int 21h
  135. v86:
  136. mov ax,0de00h
  137. int 67h
  138. or ah,ah
  139. je VCPI
  140. mov ah,9
  141. mov dx,offset msg3
  142. int 21h
  143. mov ah,4ch
  144. int 21h
  145. VCPI:
  146. push cs
  147. pop ds
  148. push cs
  149. pop es
  150. cli
  151. mov sp,offset stck+100h
  152. sti
  153. mov bx,offset dummy
  154. mov cl,4
  155. shr bx,cl ; Bytes -> paragraphs
  156. inc bx
  157. add bx,300h ; Makes sure we can align both page table and page table
  158. mov ah,4ah  ; Directory on a 4Kb boundary ( 12 lower bits of page entries/
  159. int 21h     ; Cr3 are not counted in the address )
  160.  
  161. mov ax,cs
  162. mov bx,offset dummy
  163. mov cl,4
  164. shr bx,cl ; Offset -> segment
  165. add bx,ax ; add segment
  166. and bx,0ff00h
  167. add bx,100h ; Align on Page boundary
  168. mov [pdt_seg],bx ; Got it
  169. mov es,bx
  170. add bx,100h ; Align on next page - that's the Page Table
  171. mov [pt_seg],bx
  172. movzx ebx,bx
  173. mov cl,4
  174. shl ebx,4 ; Segment->Linear
  175. or ebx,1 ; Set Present Bit
  176. mov dword ptr Es:[0000],ebx ; Store the needed PDT entry
  177. mov bx,[pt_seg]
  178. mov es,bx
  179. xor di,di ; Aligned on page boundary, remember?
  180. mov si,offset GDT+8
  181. mov ax,0de01h
  182. int 67h
  183. push cs
  184. pop ds
  185. mov dword ptr ds:[serverptr],ebx
  186.  
  187. mov ax,cs
  188. movzx eax,ax
  189. mov cl,04h
  190. shl eax,cl ; Segment -> linear
  191. mov ebx,eax
  192. mov cx,offset GDT
  193. movzx ecx,cx
  194. add eax,ecx
  195. mov [GDTR2],eax ; Store linear GDT address
  196. sub eax,ecx
  197. mov cx,offset IDT
  198. movzx ecx,cx
  199. add eax,ecx
  200. mov [IDTR2],eax
  201. sub eax,ecx
  202. xor ecx,ecx
  203. mov cx,offset GDTR
  204. add eax,ecx
  205. mov [_GDTR],eax
  206. sub eax,ecx
  207. mov cx,offset IDTR
  208. movzx ecx,cx
  209. add eax,ecx
  210. mov [_IDTR],eax
  211. sub eax,ecx
  212.  
  213. mov si,offset data3.base1
  214. mov ecx,02h
  215. set_base:
  216. mov eax,[si]
  217. or eax,ebx
  218. mov [si],eax
  219. add si,08h
  220. loop set_base ; Set base addresses for data/code descriptors
  221. add si,08h
  222. mov eax,[si]
  223. mov cx,offset TSS
  224. movzx ecx,cx
  225. or eax,ebx
  226. add eax,ecx
  227. mov [si],eax     ; same for TSS
  228.  
  229. mov ax,offset start_pmode
  230. movzx eax,ax
  231. mov dword ptr [entry],eax
  232.  
  233. mov dx,[pdt_seg]
  234. mov cl,4
  235. movzx edx,dx
  236. shl edx,4 ; Segment->linear
  237.  
  238. mov [_cr3],edx
  239. mov [_cr3_],edx ; Set cr3 both in data for VCPI and in TSS
  240.  
  241. mov ax,offset start_pmode
  242. movzx eax,ax
  243. mov [_eip],eax
  244.  
  245. mov ax,offset stck+50h
  246. movzx eax,ax
  247. mov [_esp],eax
  248. mov [_esp0],eax
  249. mov [_esp1],eax
  250. mov [_esp2],eax
  251.  
  252. mov ax,cs
  253. mov [real_seg],ax
  254.  
  255. mov ax,offset pdata
  256. movzx eax,ax
  257. add eax,ebx
  258. mov esi,eax
  259. mov ax,0de0ch
  260. cli
  261. int 67 ; Bye bye V86 mode... Will we succeed?
  262. nop
  263. nop
  264.  
  265. start_pmode: ; Here we go (Or not!)
  266. cli
  267. mov ax,20h
  268. mov es,ax
  269. mov edi,0000h ; Video Screen - What else ?
  270. mov ecx,100h ; That'll be enough
  271. mov eax,08c418c41h ; 2 Flashing A's
  272. cld
  273. rep stosd
  274. mov ax,28h
  275. mov ds,ax
  276. mov ss,ax
  277. mov ax,offset stck+100h
  278. movzx esp,ax
  279. mov ax,0de03h
  280. call fword ptr cs:[serverptr]
  281. xor di,di
  282. xor eax,eax
  283. mov ecx,90h
  284. cld
  285. rep stosd
  286. mov ax,cs:[real_seg]
  287. movzx eax,ax
  288. push eax
  289. push eax
  290. push eax
  291. push eax
  292. push eax ; GS,FS,DS,ES,SS register's values (real mode?)
  293. mov ax,offset stck+100h
  294. movzx eax,ax
  295. push eax ; ESP
  296. pushfd
  297. mov ax,cs:[real_seg]
  298. movzx eax,ax
  299. push eax ; Code Segment Selector
  300. mov ax,offset return_v86
  301. movzx eax,ax
  302. push eax ; Offset for return
  303. mov ax,38h
  304. mov ds,ax
  305. mov eax,8c418c41h
  306. mov ds:[0b8000h],eax ; Tests if 4gb segment ok
  307. mov ax,0de0ch
  308. call fword ptr cs:[serverptr]
  309.  
  310.  
  311. return_v86:
  312. sti
  313. mov ax,4c00h
  314. int 21h
  315.  
  316. dummy:
  317. code ends
  318. end begin
  319.  
  320. Fare thee well,
  321.  
  322. Elad
  323.  
  324. ---
  325.  * Origin: None is Listed! (2:403/169.4)
  326.  
  327. @PATH: 403/169 150 170/400 209/209 270/101 260/1 362
  328.