Advertisement
Guest User

back in real mode

a guest
Sep 28th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. TOP             equ     0xc000 ;0xbf80
  3.  
  4.                 org     TOP             ; right after himemx.sys+sysskel.sys
  5.         bits            16
  6.  
  7. _main:
  8.                 jmp     callpoint       ; 0x0000:0xc000
  9. _done:          retf
  10. ;               jmp     _done           ; was a measure to have a table here
  11. ;               jmp     start
  12.                 jmp     loadall         ; 0x0000:0xc004
  13.                 nop
  14.         bits            32
  15.                 jmp     _emx            ; 0x0000:0xc008
  16.                 nop
  17.         bits            16
  18.  
  19. ; ------data---------------------------------------------------------------
  20. runstack        dw      0
  21. runseg          dw      0
  22. newstack        dw      0xffee-0x800 ; 0xffee ; 0xfffe
  23.                 dw      0
  24. data01:
  25. cseg            dd      0,0             ; eip,cs of indirect jmp as cs = 0
  26.  
  27. data02:
  28. gdt:            dw      0x0048,gdt   ,0x0000,0x0000
  29.                 dw      0xffff,0x0000,0x9a00,0x0011
  30.                 dw      0xffff,0x0000,0x9200,0x0000
  31.                 dw      0x0000,0x0000,0x9200,0x0011
  32.                 dw      0x0048,gdt   ,0x8200,0x0010
  33.                 dw      tss_lt,tss   ,0x8900,0x0010
  34. ldt:            dw      0x0010,ldt0  ,0x8200,0x0010
  35.                 dw      0xffff,0x0000,0x9a00,0x00cf     ; 0x38
  36.                 dw      0x1000,0x0000,0x9200,0x00d0
  37.  
  38. idtp:           dw      0x0800,idt0,0x0000
  39. idtr:           dw      0x03ff,0x0000,0x0000 ; to return to real mode...!
  40. gdtr:           dw      0x0048,gdt,0x0000               ;dw limit dd base
  41.  
  42. ldt0:           dw      0x0000,0x0000,0x0000,0x0000
  43.                 dw      0x0010,ldt0  ,0x8400,0x0010     ; 0x30
  44.  
  45. sseg:           dd      0x0000ffee-0x800,0x18 ; 0xfffe (?) fill in before using
  46.  
  47. _emx_gdtr:      dd      0,0             ; this table is at 0:0xc090
  48. _emx_idtr:      dd      0,0
  49. _emx_cs:        dw      0
  50. _emx_cseg:      dw      0
  51. _emx_ds:        dw      0
  52. _emx_dseg:      dw      0
  53. _emx_ldt:       dw      0
  54. _emx_tr:        dw      0
  55. _emx_zs:        dw      0
  56. _emx_zseg:      dw      0
  57. _emx_stack:     dd      0
  58. _emx_ss:        dd      0
  59.  
  60. ; ------frm to rm----------------------------------------------------------
  61. ; gdt: (see .lst file for gdt info)
  62.  
  63. sseg_rm:        dw      0,0
  64.  
  65. code:
  66.                 movzx   eax,ax
  67.                 add dword [cseg],next01
  68.                 jmp dword far [cseg]
  69. next01:
  70.                 push dword 0x00000000
  71.                 push dword next015
  72.         o32     retf
  73. next015:
  74.                 mov     [sseg_rm],sp
  75. ;               jmp     _ret
  76. ;               jmp     next03
  77.  
  78.                 mov     [sseg],esp
  79.  
  80.  
  81. callpoint:
  82.                 mov     ax,0x0000       ; preserve flags
  83.                 mov     ds,ax
  84.                 mov     si,es
  85.                 mov     es,ax
  86.                 pushfd                  ; assuming ss valid since we are called
  87.                 cli
  88.                 mov     edx,cr0
  89.                 or      dl,0x01
  90.                 mov     cr0,edx
  91.         o32     lgdt    [gdtr]          ; indirect as *
  92.                 push dword 0x00000008
  93.                 push dword pmodepoint
  94.         o32     retf
  95. pmodepoint:
  96.  
  97.                 mov     ax,0x0010
  98.                 mov     ds,ax
  99.                 mov     [sseg_rm],sp
  100.                 mov     bp,ss
  101.                 mov     [sseg_rm+2],bp
  102.                 mov     es,ax
  103.                 mov     fs,ax
  104.                 mov     gs,ax
  105.                 lss     esp,[sseg]
  106.                 push dword 0x00000008
  107.                 push dword next02
  108.         o32     retf
  109. next02:
  110.                 xor     eax,eax
  111.                 mov     cr3,eax
  112.  
  113.                 mov     ax,0x0038
  114.         o32     lidt    [idtp]
  115. jmppoint:
  116.                 lidt    [idtr]
  117.                 mov     edx,cr0
  118.                 and     dl,0xfe
  119.                 mov     cr0,edx
  120.  
  121.                 push dword 0x0000        ; cs
  122.                 push dword next03
  123.         o32     retf
  124. next03:
  125.                 xor     ax,ax
  126.                 mov     ds,ax
  127.                 mov     es,ax
  128.                 lss     sp,[sseg_rm]
  129.  
  130.  
  131.  
  132.                 popfd
  133.                 mov     es,si
  134. retpoint:       jmp     _done
  135. ;                retf
  136. ; ------
  137.  
  138.  
  139.                 sti
  140.                 jmp     _ret
  141.  
  142. f
  143. ; -------------------------------------------------------------------------
  144. _timer_handler:
  145.                 push    eax
  146.                 push    edx
  147.                 mov     al,0x20
  148.                 mov     dx,0x0020
  149.                 out     dx,al
  150.                 pop     edx
  151.                 pop     eax
  152.                 iret
  153. _high_handler:
  154.                 push    eax
  155.                 push    edx
  156.                 mov     al,0x20
  157.                 mov     dx,0x00a0
  158.                 out     dx,al
  159.                 mov     dx,0x0020
  160.                 out     dx,al
  161.                 pop     edx
  162.                 pop     eax
  163.                 iret
  164. ; -------------------------------------------------------------------------
  165. _emx_frm_interface:
  166.                 mov     ax,0x1234
  167.                 call    wordhexout
  168.                 xor     eax,eax
  169.                 mov     ebx,eax
  170.                 mov     ecx,eax
  171.                 mov     edx,eax
  172.                 mov     esi,eax
  173.                 mov     edi,eax
  174.                 mov     ebp,eax
  175.                 cld
  176.                 mov     edi,ivt_backup
  177.                 mov     cx,0x100
  178.                 rep     movsd
  179.                 mov     si,di
  180.                 xor     di,di
  181.                 mov     cx,0x100
  182.                 rep     movsd
  183.                 mov     edi,8*4
  184.                 mov     eax,_timer_handler
  185.                 mov     ecx,8
  186.                 rep     stosb
  187.                 mov     edi,0x70*4
  188.                 mov     eax,_high_handler
  189.                 mov     ecx,8
  190.                 rep     stosb
  191.                 sti
  192.                 ;xor     ax,ax
  193.                 ;int     0x16
  194. ; --------------
  195.                 hlt
  196. ; --------------
  197.                 cli
  198.                 mov     si,ivt_backup
  199.                 xor     di,di
  200.                 mov     cx,0x100
  201.                 rep     movsd
  202.                 ;sti
  203.                 ;int     0x16
  204.                 ;cli
  205.                 ret
  206.  
  207. pos:            dw      80*2*6,0
  208.  
  209. byteout:
  210.                 push    ebx
  211.                 ;mov     ah,al
  212.                 mov     ah,7
  213.                 mov     ebx,[pos]
  214.                 inc word [pos]
  215.                 inc word [pos]
  216.                 add     ebx,0xb8000
  217.                 mov     [ebx],ax
  218.                 pop     ebx
  219.                 ret
  220. nybblehexout:
  221.                 push    ax
  222.                 cmp     al,0xa
  223.                 jb      bcdhexout
  224.                 add     al,7
  225. bcdhexout:      add     al,0x30
  226.                 call    byteout
  227.                 pop     ax
  228.                 ret
  229. bytehexout:
  230.                 push    ax
  231.                 push    ax
  232.                 shr     al,4
  233.                 call    nybblehexout
  234.                 pop     ax
  235.                 and     al,0x0f
  236.                 call    nybblehexout
  237.                 pop     ax
  238.                 ret
  239. wordhexout:
  240.                 push    ax
  241.                 push    ax
  242.                 shr     ax,8
  243.                 call    bytehexout
  244.                 pop     ax
  245.                 call    bytehexout
  246.                 pop     ax
  247.                 ret
  248. dwordhexout:
  249.                 push    eax
  250.                 push    eax
  251.                 shr     eax,0x10
  252.                 call    wordhexout
  253.                 pop     eax
  254.                 and     eax,0x0000ffff
  255.                 call    wordhexout
  256.                 pop     eax
  257.                 ret
  258.  
  259. ; ------main---------------------------------------------------------------
  260.         bits            32
  261. _emx:
  262.                                         ; retf: 0x8 stack bytes
  263.                 pushad                  ; 0x20 stack bytes
  264.                 str     ax
  265.                 sldt    cx
  266.                 mov     dx,ds
  267.  
  268.                 mov     ebp,esp
  269.                 add     ebp,0x8+0x20
  270.                 push    ds
  271.                 push    es
  272.                 push    es              ; es is zeroed upon entry
  273.                 pop     ds
  274.                 mov     ebx,[ss:ebp]    ; idt
  275.                 mov     [_emx_idtr+2],ebx
  276.                 mov     bx,[ss:ebp+4]   ; limit
  277.                 mov     [_emx_idtr],bx
  278.                 mov     ebx,[ss:ebp+6]  ; gdt
  279.                 mov     [_emx_gdtr+2],ebx
  280.                 mov     bx,[ss:bp+0x0a] ; limit
  281.                 mov     [_emx_gdtr],bx
  282.                 mov     [_emx_tr],ax
  283.                 mov     [_emx_ldt],cx
  284.                 mov     ax,cs
  285.                 mov     [_emx_cseg],ax
  286.                 mov     ax,dx
  287.                 mov     [_emx_dseg],ax
  288.                 mov     ax,es
  289.                 mov     [_emx_zseg],ax
  290.                 push    fs
  291.                 push    gs
  292.  
  293.                 mov     eax,ss
  294.                 mov     [_emx_ss],eax
  295.                 mov     eax,esp
  296.                 mov     [_emx_stack],eax
  297.  
  298.                 lgdt    [gdtr];z          ; indirect as *
  299.                 push dword 0x00000008;z
  300.                 push dword _emx_pmodepoint;z
  301.                 retf;z
  302.         bits            16;z
  303. _emx_pmodepoint:
  304. ; will do a lot more here
  305.                 mov     ax,0x00000010;z
  306.                 mov     ds,ax;z
  307.  
  308.                 mov     es,ax
  309.                 mov     fs,ax
  310.                 mov     gs,ax
  311.  
  312.                 mov     esi,ebp
  313.                 sub     ebp,8+0x20
  314.                 mov     ecx,0x0a
  315.                 cld
  316.                 mov     edi,[sseg]
  317.                 sub     edi,0x8+0x20
  318.                 rep     movsd
  319.  
  320.                 lss     esp,[sseg]
  321.                 sub     esp,8+0x20
  322.  
  323.                 mov     edx,cr0
  324.                 and     dl,0xfe
  325.                 mov     cr0,edx
  326.                 push dword 0x0000        ; cs
  327.                 push dword _emx_rmode
  328.         o32     retf
  329. _emx_rmode:
  330.                 mov     ax,0
  331.                 mov     ds,ax
  332.                 mov     es,ax
  333.                 mov     fs,ax
  334.                 mov     gs,ax
  335.                 lss     esp,[newstack]
  336.                 sub     esp,0x20 ;8+0x20
  337.                 ;add     esp,8
  338.                 popad
  339.                 call    _emx_frm_interface
  340.  
  341.  
  342.                 mov     edx,cr0
  343.                 or      dl,1
  344.                 mov     cr0,edx
  345.                 push dword 0x00000008        ; cs
  346.                 push dword _emx_pmode
  347.         o32     retf
  348. _emx_pmode:
  349.  
  350.  
  351.                 mov     bx,[_emx_zseg]
  352.                 mov     cx,[_emx_cseg]
  353.                 movzx   ecx,cx
  354. ;                lgdt    [_emx_gdtr]             ;
  355.         o32     lgdt    [_emx_gdtr];z
  356.                 push dword ecx
  357.                 push dword _emx_pmode2
  358.         o32     retf;z
  359. ;                retf
  360.         bits            32
  361. _emx_pmode2:
  362.                 mov     ds,bx;,[_emx_zs]            ; which one first?
  363.                 lss     esp,[_emx_stack]
  364.                 pop     gs
  365.                 pop     fs
  366.                 les     bx,[_emx_zs]
  367.                 lidt    [_emx_idtr]
  368.                 mov     ax,[_emx_ldt]
  369.                 lldt    ax
  370.                 mov     ax,[_emx_tr]
  371. ;                ;ltr     ax            ; freezes, note: paging is off.
  372.                 lds     bx,[_emx_ds]
  373.  
  374.                 pop     es
  375.                 pop     ds
  376.                 popad
  377.                 jmp     _done
  378.  
  379.         bits            16
  380. start:
  381.                 push    ax
  382.                 xor     ax,ax
  383.                 mov     ds,ax
  384.                 mov     ax,ss
  385.                 mov     [runseg],ax     ; should be 0x0000
  386.                 pop     ax
  387.                 mov     [runstack],sp   ; esp for flat real mode?
  388.                 lss     sp,[newstack]
  389.  
  390.                 pushad                   ; no way to pushaq nor o64
  391.                 xor     ax,ax
  392.                 mov     es,ax
  393. ;                call near 0xbe32        ; wordhexout, see 11.lst for 11.sys
  394.                 ;mov     ax,offset       ; 0x002c (varies)
  395. ;                mov     ax,$            ; 0xbf9e
  396.                 mov     ax,idt_limit
  397.                 call near 0xbe32        ; wordhexout
  398.                 jmp     code
  399.  
  400. _ret:
  401.                 popad
  402.                 lss     sp,[runstack]
  403.                 jmp     _done
  404.  
  405.  
  406. ; -------------------------------------------------------------------------
  407. loadall:
  408. ;                sub     esp,4
  409.                 ;rol     edi,0x10
  410.                 call word 0:callpoint   ; ds=0 es?
  411.                 ;mov     ax,di
  412. ;                call near 0xbe32        ; wordhexout
  413.                 ;rol     edi,0x10
  414.                 ;mov     ax,di
  415. ;                call near 0xbe32        ; wordhexout
  416.                 mov     ax,es
  417. ;                call near 0xbe32        ; wordhexout
  418.  
  419.                 mov     ds,ax           ; not 0; reserved space after load tbl
  420.                 mov     esi,edi
  421.                 mov     ecx,20+22+(6*10)
  422.  
  423. ;loop_data1:
  424. ;                lodsw
  425. ;                push    ecx
  426. ;                call near 0xbe32        ; wordhexout
  427. ;                pop     ecx
  428. ;                loop    loop_data1
  429.  
  430.                 mov     eax,[esi]
  431.                 and     al,1
  432.                 jz      _load_noret
  433.                 jmp     _load_ret
  434. _load_noret:
  435.                 add     esi,84          ; also sub esi,84
  436.                 add     edi,ecx
  437.                 add     edi,ecx
  438.                 mov     eax,ds
  439.                 shl     eax,4
  440.                 add     eax,edi         ; not a seg (was ???please fix ds:esi)
  441.                 mov     ebx,ds ; is ds read-only???
  442.                 ;shl     ebx,4
  443.                 ;mov     dx,0
  444.                 ;mov     ds,dx          ; replaced by callpoint
  445.  
  446.                 ;xor     bx,bx  ; eax unused?
  447.                 mov     ds,bx ; reloaded?
  448.                 mov     [edi+2],eax     ; gdt base
  449.                 ;mov     esi,edi
  450.                 mov     cx,0x0058*8
  451.                 mov word [edi],0x0058*8 ; gdt current limit
  452.  
  453.                 mov     eax,[esi+((12*0)+4)]
  454.                 mov     [edi+2+(8*1)],ax
  455.                 shr     eax,0x10
  456.                 mov     [edi+6+(8*1)],al
  457.                 mov byte [edi+5+(8*1)],0x00
  458.                 mov     ax,[esi+((12*0)+8)]
  459.                 mov     [edi+(8*1)],ax
  460.                 mov     al,[esi+((12*0)+1)]
  461.                 mov     [edi+5+(8*1)],al ; 0x08 tr/tss
  462.  
  463.                 mov     eax,[esi+((12*3)+4)]
  464.                 mov     [edi+2+(8*2)],ax
  465.                 shr     eax,0x10
  466.                 mov     [edi+6+(8*2)],al
  467.                 mov byte [edi+5+(8*2)],0x00
  468.                 mov     ax,[esi+((12*3)+8)]
  469.                 mov     [edi+(8*2)],ax
  470.                 mov     al,[esi+((12*3)+1)]
  471.                 mov     [edi+5+(8*2)],al ; 0x10 ldt
  472.  
  473.                 mov     eax,[esi+((12*4)+4)]
  474.                 mov     [edi+2+(8*3)],ax
  475.                 shr     eax,0x10
  476.                 mov     [edi+6+(8*3)],al
  477.                 mov byte [edi+5+(8*3)],0x00
  478.                 mov     ax,[esi+((12*4)+8)]
  479.                 mov     [edi+(8*3)],ax
  480.                 mov     al,[esi+((12*4)+1)]
  481.                 mov     [edi+5+(8*3)],al ; 0x18 gs
  482.                 or byte [edi+5+(8*3)],0x82
  483.  
  484.                 mov     eax,[esi+((12*5)+4)]
  485.                 mov     [edi+2+(8*4)],ax
  486.                 shr     eax,0x10
  487.                 mov     [edi+6+(8*4)],al
  488.                 mov byte [edi+5+(8*4)],0x00
  489.                 mov     ax,[esi+((12*5)+8)]
  490.                 mov     [edi+(8*4)],ax
  491.                 mov     al,[esi+((12*5)+1)]
  492.                 mov     [edi+5+(8*4)],al ; 0x20 fs
  493.                 or byte [edi+5+(8*4)],0x82
  494.  
  495.                 mov     eax,[esi+((12*6)+4)]
  496.                 mov     [edi+2+(8*5)],ax
  497.                 shr     eax,0x10
  498.                 mov     [edi+6+(8*5)],al
  499.                 mov byte [edi+5+(8*5)],0x00
  500.                 mov     ax,[esi+((12*6)+8)]
  501.                 mov     [edi+(8*5)],ax
  502.                 mov     al,[esi+((12*6)+1)]
  503.                 and     al,0xfb
  504.                 mov     [edi+5+(8*5)],al ; 0x28 ds
  505.                 or byte [edi+5+(8*5)],0x80
  506.                 test    al,0x02
  507.                 jnz     load_no_gdt
  508.                 mov     bp,0x0013
  509.                 test    al,0x08
  510.                 jz      load_no_gdt
  511.                 or byte [edi+5+(8*5)],0x02 ; at least a readable exec seg
  512. load_no_gdt:
  513.                 mov     eax,[esi+((12*7)+4)]
  514.                 mov     [edi+2+(8*6)],ax
  515.                 shr     eax,0x10
  516.                 mov     [edi+6+(8*6)],al
  517.                 mov byte [edi+5+(8*6)],0x00
  518.                 mov     ax,[esi+((12*7)+8)]
  519.                 mov     [edi+(8*6)],ax
  520.                 mov     al,[esi+((12*7)+1)]
  521.                 mov     [edi+5+(8*6)],al ; 0x30 ss
  522.                 or byte [edi+5+(8*6)],0x82
  523.  
  524.                 mov     eax,[esi+((12*8)+4)]
  525.                 mov     [edi+2+(8*7)],ax
  526.                 shr     eax,0x10
  527.                 mov     [edi+6+(8*7)],al ; *1?
  528.                 mov byte [edi+5+(8*7)],0x00
  529.                 mov     ax,[esi+((12*8)+8)]
  530.                 mov     [edi+(8*7)],ax
  531.                 mov     al,[esi+((12*8)+1)]
  532.                 mov     [edi+5+(8*7)],al ; 0x38 cs
  533.                 or byte [edi+5+(8*7)],0x82
  534.  
  535.                 mov     eax,[esi+((12*9)+4)]
  536.                 mov     [edi+2+(8*8)],ax
  537.                 shr     eax,0x10
  538.                 mov     [edi+6+(8*8)],al ; *1?
  539.                 mov byte [edi+5+(8*8)],0x00
  540.                 mov     ax,[esi+((12*9)+8)]
  541.                 mov     [edi+(8*8)],ax
  542.                 mov     al,[esi+((12*9)+1)]
  543.                 mov     [edi+5+(8*8)],al ; 0x40 es
  544.                 or byte [edi+5+(8*8)],0x82
  545.  
  546.                 mov     eax,0
  547.                 mov     [edi+2+(8*9)],ax
  548.                 shr     eax,0x10
  549.                 mov     [edi+6+(8*9)],al
  550.                 mov byte [edi+5+(8*9)],0x00
  551.                 mov     ax,0xffff
  552.                 mov     [edi+(8*9)],ax
  553.                 mov     al,0x9a
  554.                 mov     [edi+5+(8*9)],al ; 0x48 cs-pmode
  555.  
  556.                 mov     eax,[esi+((12*6)+4)] ; same as ds
  557.                 mov     [edi+2+(8*10)],ax
  558.                 shr     eax,0x10
  559.                 mov     [edi+6+(8*10)],al
  560.                 mov byte [edi+5+(8*10)],0x00
  561.                 mov     ax,[esi+((12*6)+8)]
  562.                 mov     [edi+(8*10)],ax
  563.                 mov     al,0x92         ; with permission to read
  564.                 mov     [edi+5+(8*10)],al ; 0x50 cs-pmode
  565.  
  566.                 push    edi
  567. ;loop_data1:
  568. ;               lodsw
  569. ;;              push    ecx
  570. ;               call near 0xbe32
  571. ;;              pop     ecx
  572. ;               loop    loop_data1
  573.                 pop     edi
  574.  
  575.                 push    esi
  576.                 xor     eax,eax
  577.                 mov     es,ax
  578.                 mov     eax,[esi+((12*1)+4)]
  579.                 mov     [es:idt_anew+0x02],eax
  580.                 ;call near 0xbe32       ; wordhexout
  581.                 ;shr    eax,0x10
  582.                 ;call near 0xbe32       ; wordhexout
  583.                 mov     eax,[esi+((12*1)+8)]
  584.                 mov     [es:idt_anew],ax ; limit
  585.                 ;call near 0xbe32       ; wordhexout
  586.                 mov     esi,edi
  587.                 mov     edi,idt_limit
  588.                 rep     movsb
  589.                 pop     esi
  590.                 push word [esi+(12*2)+8] ; stabilize gdt
  591.                 pop word [esi+(12*2)+2] ; (overwrote the ret in the .exe)
  592.  
  593. ;               mov     eax,ds
  594. ;               shl     eax,4
  595. ;               add     edi,eax
  596.                 xor     eax,eax
  597.                 mov     bx,ds
  598.                 mov     ds,ax           ; zero sooner, check ds+e?i above
  599.  
  600. ;               mov     ax,0x0058       ; not yet, update gdt limit above
  601.                 cli
  602.                 mov     eax,cr0
  603.                 or      al,1
  604.                 mov     cr0,eax
  605. ;               mov     ax,0x0050
  606. ;               mov     ds,ax
  607.         o32     lgdt    [idt_limit]
  608.                 push dword 0x00000048
  609.                 push dword _load_pmode
  610.         o32     retf
  611. _load_pmode:
  612.         o32     lidt    [cs:idt_anew] ; no problem with rcollins' idt_base
  613.                 mov     ax,0x0008
  614.                 movzx   eax,ax
  615.                 ltr     ax
  616.                 mov     ax,0x0010
  617.                 lldt    ax
  618.                 mov     ax,0x0018
  619.                 mov     gs,ax
  620.                 mov     ax,0x0020
  621.                 mov     fs,ax
  622.                 mov     ax,0x0028
  623.                 mov     ds,ax
  624.                 mov     ax,0x0040
  625.                 mov     es,ax
  626.                 mov     di,ss
  627.                 ;mov    edi,esp
  628.                 mov     ax,0x0018;30
  629.                 mov     ss,ax
  630.                 mov     esp,esp
  631.                 rcl     dl,1
  632.  
  633.                 cmp     bp,0x0013
  634.                 je      load_not_gdt
  635.                 ;mov    ecx,[esi-84+52]
  636.                 ;mov    eax,[esi-84+56]
  637.         o32     lgdt    [esi+(12*2)+2]
  638. load_not_gdt:
  639. ;               ltr     cx ; rcollins' gdt doesn't carry this selector?
  640. ;               lldt    ax ; rcollins' gdt doesn't carry this selector?
  641.  
  642. ;??     o32     lidt    [cs:idtr]       ; this looks about the same
  643. ;       o32     lidt    [cs:idt_anew]   ; no problems with rcollins' IDT base
  644. ;               jmp     loaded_pmode
  645. ;loaded_pmode:
  646.                 mov     eax,cr0
  647.                 and     al,0xfe
  648.                 mov     cr0,eax
  649.                 push dword 0x00000000
  650.                 push dword load_rmode
  651.         o32     retf
  652. load_rmode:
  653.                 mov     ss,di           ; yes di is frobbed, see above? wait bp
  654.                 mov     esp,esp
  655.                 mov     ds,bx
  656.                 sub     esi,84
  657.                 mov     ax,[esi+72]
  658.                 push dword [esi+04]     ; ss??
  659.                 popfd
  660.                 rcr     dl,1
  661. ;               add     esp,4           ; o32 retf should suffice
  662.                 mov     ss,eax
  663.                 mov     esp,[esi+24]
  664.                 sti
  665.                 mov     eax,[esi+80]
  666.                 mov     es,eax
  667.                 mov     eax,[esi+64]
  668.                 mov     fs,eax
  669.                 mov     eax,[esi+76]
  670.                 mov     gs,eax
  671.                 mov     [cs:load_jmpbuf+0x04],ax ; ds not loaded yet; cs == 0
  672.                 mov     eax,[esi+60]
  673.                 mov     gs,eax
  674.                 mov     eax,[esi+44]
  675.                 mov     dr6,eax
  676.                 mov     eax,[esi+48]
  677.                 mov     dr7,eax
  678.                 mov     eax,[esi+68]
  679.                 mov     ds,eax
  680.                 mov     eax,[esi+40]
  681.                 mov     ecx,[esi+36]
  682.                 mov     edx,[esi]
  683.                 mov     cr0,edx
  684.                 mov     edx,[esi+32]
  685.                 mov     ebx,[esi+28]
  686.                 mov     ebp,[esi+20]
  687.                 mov     edi,load_jmpbuf
  688.                 mov     edi,[esi+08]
  689.                 mov     [cs:load_jmpbuf],edi
  690.                 mov     edi,[esi+12]
  691.                 mov     esi,[esi+16]
  692.                 jmp far dword [cs:load_jmpbuf]
  693. load_jmpbuf:    dw      0,0,0
  694.  
  695. ; see .lst file to make sure each register is accounted for as loadall
  696.  
  697. ;loop_data1:
  698. ;               lodsw
  699. ;               push    ecx
  700. ;               call near 0xbe32        ; wordhexout
  701. ;               pop     ecx
  702. ;               loop    loop_data1
  703. _load_ret:
  704.                 mov     ah,0x4c
  705.                 int     0x21
  706.  
  707. ; 1. break if cr0 contains a pmode value (&1)
  708. ; 2. jmp to pmode (descript.asm?)
  709. ; 3. load descriptors
  710. ; 4. load gdt,idt
  711. ; 5. ldt, tr, fs, gs, ds, es, ss
  712. ; 6. load cr0 (real mode)
  713. ; 7. load real mode segment values
  714. ; 8. load gp registers
  715. ; n. far jmp
  716.  
  717. ; -------------------------------------------------------------------------
  718. queer_task:
  719.                 hlt
  720.                 jmp     queer_task
  721.  
  722.         bits            32
  723. h:
  724.                 pushad
  725.                 push    es
  726.                 push dword 0x00000040
  727.                 pop     es
  728. ;;              push word 0x0010
  729.                 mov     edi,0x000b8000
  730.                 mov     cx,80*25
  731.                 mov     ax,0x0707
  732.                 rep     stosw
  733.                 pop     es
  734.                 popad
  735.                 sti
  736.                 iret
  737.  
  738.         bits            16              ; prolly superfluous as data follows
  739.  
  740. ; ------stack--------------------------------------------------------------
  741. tss:
  742.                 dd      0
  743.                 dd      0xfffffffe
  744.                 dw      0x18,0
  745.                 dd      0xfffffffe
  746.                 dw      0x18,0
  747.                 dd      0xfffffffe
  748.                 dw      0x18,0
  749.                 dd      0xfffffffe
  750.                 dw      0x18,0
  751.                 dw      0,0
  752.                 dd      queer_task      ; eip
  753.                 dd      0x00207206      ; eflags
  754.                 dd      0,0,0,0,0,0,0,0 ; regs
  755.  
  756.  
  757.                 dw      0x10,0          ; dcsddd(ldt)io
  758.                 dw      0x08,0
  759.                 dw      0x18,0
  760.                 dw      0x10,0
  761.                 dw      0x10,0
  762.                 dw      0x10,0
  763.                 dw      0x0000,io_offset ; 0x0001 for debug exceptions
  764. io_offset:      dd      0x0, 0,0, 0,0, 0,0
  765.                 dd      0x0, 0,0, 0,0, 0,0 ; 128 bytes == 65536 bits
  766. tss_lt          equ     $-tss
  767.  
  768.         align           0x10
  769.  
  770.  ;9&5/6/7/e/f
  771. idt0:
  772.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000
  773.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000
  774.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000
  775.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000
  776.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000
  777.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000
  778.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000
  779.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000 ; 0x0f
  780.  
  781.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000
  782.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000
  783.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000
  784.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000
  785.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000
  786.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000
  787.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000
  788.                 dw      h,0x38,0x8e00,0x0000, h,0x38,0x8e00,0x0000 ; 0x1f
  789.  
  790.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  791.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  792.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  793.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  794.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  795.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  796.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  797.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000 ; 0x2f
  798.  
  799.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  800.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  801.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  802.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  803.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  804.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  805.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  806.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000 ; 0x3f
  807.  
  808.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  809.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  810.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  811.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  812.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  813.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  814.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  815.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000 ; 0x4f
  816.  
  817.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  818.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  819.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  820.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  821.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  822.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  823.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  824.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000 ; 0x5f
  825.  
  826.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  827.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  828.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  829.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  830.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  831.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  832.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  833.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000 ; 0x6f
  834.  
  835.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  836.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  837.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  838.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  839.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  840.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  841.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  842.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000 ; 0x7f
  843.  
  844.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  845.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  846.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  847.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  848.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  849.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  850.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  851.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000 ; 0x8f
  852.  
  853.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  854.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  855.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  856.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  857.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  858.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  859.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  860.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000 ; 0x9f
  861.  
  862.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  863.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  864.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  865.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  866.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  867.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  868.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  869.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000 ; 0xaf
  870.  
  871.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  872.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  873.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  874.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  875.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  876.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  877.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  878.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000 ; 0xbf
  879.  
  880.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  881.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  882.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  883.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  884.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  885.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  886.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  887.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000 ; 0xcf
  888.  
  889.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  890.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  891.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  892.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  893.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  894.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  895.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  896.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000 ; 0xdf
  897.  
  898.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  899.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  900.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  901.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  902.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  903.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  904.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  905.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000 ; 0xef
  906.  
  907.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  908.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  909.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  910.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  911.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  912.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  913.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000
  914.                 dw      h,8,0x8e00,0x0000, h,8,0x8e00,0x0000 ; 0xff
  915. idt_anew        dw      0,0,0 ; selector first
  916. idt_limit:
  917. offset          equ     $-$$
  918. completion      equ     0x10000-0x810-TOP-offset
  919. stack           equ     completion-2
  920.         times completion db 0x90
  921. ivt_backup:
  922. ;
  923. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement