Subversion Repositories Kolibri OS

Rev

Rev 998 | Rev 1269 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. format binary
  2. include '../../macros.inc'
  3. use32
  4.         db      'MENUET01'
  5.         dd      1
  6.         dd      start
  7.         dd      i_end
  8.         dd      used_mem
  9.         dd      used_mem
  10.         dd      i_param
  11.         dd      0
  12.  
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GUI ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16.  
  17. data_width equ 80
  18. data_x_pos equ 12
  19. data_x_size equ data_width*6
  20.  
  21. title_x_pos equ 30
  22. title_y_pos equ 32
  23. title_y_size equ 10
  24.  
  25. registers_x_pos equ data_x_pos
  26. registers_y_pos equ (title_y_pos + title_y_size)
  27. registers_y_size equ 30
  28.  
  29. dump_y_pos equ (registers_y_pos + registers_y_size + 5)
  30. dump_height equ 4
  31. dump_y_size equ (dump_height*10)
  32.  
  33. disasm_y_pos equ (dump_y_pos + dump_y_size + 4)
  34. disasm_height equ 16
  35. disasm_y_size equ (disasm_height*10)
  36.  
  37. messages_width equ data_width
  38. messages_height equ 12
  39. messages_x_pos equ data_x_pos
  40. messages_y_pos equ (disasm_y_pos + disasm_y_size + 4)
  41. messages_x_size equ messages_width*6
  42. messages_y_size equ messages_height*10
  43.  
  44. cmdline_width equ data_width
  45. cmdline_x_pos equ data_x_pos
  46. cmdline_y_pos equ (messages_y_pos + messages_y_size + 10)
  47. cmdline_x_size equ messages_x_size
  48. cmdline_y_size equ 10
  49.  
  50. wnd_x_size equ (data_x_pos + messages_x_size + data_x_pos)
  51. wnd_y_size equ (cmdline_y_pos + cmdline_y_size + data_x_pos)
  52.  
  53. start:
  54.         mcall   68, 11
  55.         mov     edi, messages
  56.         mov     ecx, messages_width*messages_height
  57.         mov     al, ' '
  58.         rep     stosb
  59.         xor     eax, eax
  60.         mov     [messages_pos], eax
  61.         mov     [cmdline_len], eax
  62.         mov     [cmdline_pos], eax
  63.         mov     edi, needzerostart
  64.         mov     ecx, (needzeroend-needzerostart+3)/4
  65.         rep     stosd
  66.         mov     esi, begin_str
  67.         call    put_message_nodraw
  68. ; set event mask - default events and debugging events
  69.         push    40
  70.         pop     eax
  71.         mov     ebx, 0x107
  72.         mcall
  73. ; set debug messages buffer
  74.         mov     ecx, dbgbufsize
  75.         mov     dword [ecx], 256
  76.         xor     ebx, ebx
  77.         mov     [ecx+4], ebx
  78.         mov     al, 69
  79.         mcall
  80.         mov     esi, i_param
  81.         call    skip_spaces
  82.         test    al, al
  83.         jz      dodraw
  84.         push    esi
  85.         call    draw_window
  86.         pop     esi
  87.         call    OnLoadInit
  88.         jmp     waitevent
  89. dodraw:
  90.         call    draw_window
  91. waitevent:
  92.         push    10
  93.         pop     eax
  94.         mcall
  95.         cmp     al, 9
  96.         jz      debugmsg
  97.         dec     eax
  98.         jz      dodraw
  99.         dec     eax
  100.         jz      keypressed
  101.         dec     eax
  102.         jnz     waitevent
  103. ; button pressed - we have only one button (close)
  104.         push    -1
  105.         pop     eax
  106.         mcall
  107. keypressed:
  108.         mov     al, 2
  109.         mcall
  110.         shr     eax, 8
  111.         cmp     al, 8
  112.         jz      .backspace
  113.         cmp     al, 0xB0
  114.         jz      .left
  115.         cmp     al, 0xB3
  116.         jz      .right
  117.         cmp     al, 0x0D
  118.         jz      .enter
  119.         cmp     al, 0xB6
  120.         jz      .del
  121.         cmp     al, 0xB4
  122.         jz      .home
  123.         cmp     al, 0xB5
  124.         jz      .end
  125.         cmp     al, 0xB1
  126.         jz      .down
  127.         cmp     al, 0xB2
  128.         jz      .up
  129.         cmp     al, 0xD8
  130.         jz      CtrlF7
  131.         cmp     al, 0xD9
  132.         jz      CtrlF8
  133.         cmp     [cmdline_len], cmdline_width
  134.         jae     waitevent
  135.         push    eax
  136.         call    clear_cmdline_end
  137.         pop     eax
  138.         mov     edi, cmdline
  139.         mov     ecx, [cmdline_len]
  140.         add     edi, ecx
  141.         lea     esi, [edi-1]
  142.         sub     ecx, [cmdline_pos]
  143.         std
  144.         rep     movsb
  145.         cld
  146.         stosb
  147.         inc     [cmdline_len]
  148.         call    draw_cmdline_end
  149.         inc     [cmdline_pos]
  150.         call    draw_cursor
  151.         jmp     waitevent
  152. .backspace:
  153.         cmp     [cmdline_pos], 0
  154.         jz      waitevent
  155.         dec     [cmdline_pos]
  156. .delchar:
  157.         call    clear_cmdline_end
  158.         mov     edi, [cmdline_pos]
  159.         dec     [cmdline_len]
  160.         mov     ecx, [cmdline_len]
  161.         sub     ecx, edi
  162.         add     edi, cmdline
  163.         lea     esi, [edi+1]
  164.         rep     movsb
  165.         call    draw_cmdline_end
  166.         call    draw_cursor
  167.         jmp     waitevent
  168. .del:
  169.         mov     eax, [cmdline_pos]
  170.         cmp     eax, [cmdline_len]
  171.         jae     waitevent
  172.         jmp     .delchar
  173. .left:
  174.         cmp     [cmdline_pos], 0
  175.         jz      waitevent
  176.         call    hide_cursor
  177.         dec     [cmdline_pos]
  178.         call    draw_cursor
  179.         jmp     waitevent
  180. .right:
  181.         mov     eax, [cmdline_pos]
  182.         cmp     eax, [cmdline_len]
  183.         jae     waitevent
  184.         call    hide_cursor
  185.         inc     [cmdline_pos]
  186.         call    draw_cursor
  187.         jmp     waitevent
  188. .home:
  189.         call    hide_cursor
  190.         and     [cmdline_pos], 0
  191.         call    draw_cursor
  192.         jmp     waitevent
  193. .end:
  194.         call    hide_cursor
  195.         mov     eax, [cmdline_len]
  196.         mov     [cmdline_pos], eax
  197.         call    draw_cursor
  198. .up:
  199. .down:
  200.         jmp     waitevent
  201. .enter:
  202.         mov     ecx, [cmdline_len]
  203.         test    ecx, ecx
  204.         jz      waitevent
  205.         mov     esi, cmdline
  206.         mov     byte [esi+ecx], 0
  207.         and     [cmdline_pos], 0
  208.         push    esi
  209.         call    clear_cmdline_end
  210.         call    draw_cursor
  211.         pop     esi
  212.         and     [cmdline_len], 0
  213. ; skip leading spaces
  214.         call    skip_spaces
  215.         cmp     al, 0
  216.         jz      waitevent
  217. ; now esi points to command
  218.         push    esi
  219.         mov     esi, prompt
  220.         call    put_message_nodraw
  221.         pop     esi
  222.         push    esi
  223.         call    put_message_nodraw
  224. z1:     mov     esi, newline
  225.         call    put_message
  226.         pop     esi
  227.         push    esi
  228.         call    get_arg
  229.         mov     [curarg], esi
  230.         pop     edi
  231.         mov     esi, commands
  232.         call    find_cmd
  233.         mov     eax, aUnknownCommand
  234.         jc      .x11
  235. ; check command requirements
  236. ; flags field:
  237. ; &1: command may be called without parameters
  238. ; &2: command may be called with parameters
  239. ; &4: command may be called without loaded program
  240. ; &8: command may be called with loaded program
  241.         mov     eax, [esi+8]
  242.         mov     ecx, [curarg]
  243.         cmp     byte [ecx], 0
  244.         jz      .noargs
  245.         test    byte [esi+16], 2
  246.         jz      .x11
  247.         jmp     @f
  248. .noargs:
  249.         test    byte [esi+16], 1
  250.         jz      .x11
  251. @@:
  252.         cmp     [debuggee_pid], 0
  253.         jz      .nodebuggee
  254.         mov     eax, aAlreadyLoaded
  255.         test    byte [esi+16], 8
  256.         jz      .x11
  257.         jmp     .x9
  258. .nodebuggee:
  259.         mov     eax, need_debuggee
  260.         test    byte [esi+16], 4
  261.         jnz     .x9
  262. .x11:
  263.         xchg    esi, eax
  264.         call    put_message
  265. .x10:
  266.         jmp     waitevent
  267. .x9:
  268.         call    dword [esi+4]
  269.         jmp     .x10
  270.  
  271. find_cmd:
  272. ; all commands are case-insensitive
  273.         push    edi
  274. .x4:
  275.         mov     al, [edi]
  276.         cmp     al, 0
  277.         jz      .x5
  278.         cmp     al, 'A'
  279.         jb      @f
  280.         cmp     al, 'Z'
  281.         ja      @f
  282.         or      al, 20h
  283. @@:
  284.         stosb
  285.         jmp     .x4
  286. .x5:
  287. ; find command
  288.         pop     edi
  289. .x6:
  290.         cmp     dword [esi], 0
  291.         jz      .x7
  292.         push    esi
  293.         mov     esi, [esi]
  294.         lodsb
  295.         movzx   ecx, al
  296.         push    edi
  297.         repz    cmpsb
  298.         pop     edi
  299.         pop     esi
  300.         jz      .x8
  301.         add     esi, 17
  302.         jmp     .x6
  303. .x7:
  304.         stc
  305. .x8:
  306.         ret
  307.  
  308. get_arg:
  309.         lodsb
  310.         cmp     al, ' '
  311.         ja      get_arg
  312.         mov     byte [esi-1], 0
  313.         cmp     al, 0
  314.         jnz     skip_spaces
  315.         dec     esi
  316. skip_spaces:
  317.         lodsb
  318.         cmp     al, 0
  319.         jz      @f
  320.         cmp     al, ' '
  321.         jbe     skip_spaces
  322. @@:     dec     esi
  323.         ret
  324.  
  325. clear_cmdline_end:
  326.         mov     ebx, [cmdline_pos]
  327.         mov     ecx, [cmdline_len]
  328.         sub     ecx, ebx
  329.         push    13
  330.         pop     eax
  331.         imul    ebx, 6
  332.         imul    ecx, 6
  333.         inc     ecx
  334.         add     ebx, cmdline_x_pos
  335.         shl     ebx, 16
  336.         or      ebx, ecx
  337.         mov     ecx, cmdline_y_pos*10000h + cmdline_y_size
  338.         mov     edx, 0xFFFFFF
  339.         mcall
  340.         ret
  341.  
  342. draw_cmdline:
  343.         xor     ebx, ebx
  344.         jmp     @f
  345. draw_cmdline_end:
  346.         mov     ebx, [cmdline_pos]
  347. @@:
  348.         mov     esi, [cmdline_len]
  349.         sub     esi, ebx
  350.         push    4
  351.         pop     eax
  352.         xor     ecx, ecx
  353.         lea     edx, [cmdline+ebx]
  354.         imul    ebx, 6
  355.         add     ebx, cmdline_x_pos
  356.         shl     ebx, 16
  357.         or      ebx, cmdline_y_pos+1
  358.         mcall
  359.         ret
  360.  
  361. put_message_nodraw:
  362. ; in: esi->ASCIZ message
  363.         mov     edx, [messages_pos]
  364. .m:
  365.         lea     edi, [messages+edx]
  366. .l:
  367.         lodsb
  368.         cmp     al, 0
  369.         jz      .done
  370.         call    test_scroll
  371.         cmp     al, 10
  372.         jz      .newline
  373.         cmp     al, '%'
  374.         jnz     @f
  375.         cmp     dword [esp], z1
  376.         jnz     .format
  377. @@:
  378.         stosb
  379.         inc     edx
  380.         jmp     .l
  381. .newline:
  382.         push    edx
  383.         mov     ecx, messages_width
  384.         xor     eax, eax
  385.         xchg    eax, edx
  386.         div     ecx
  387.         xchg    eax, edx
  388.         pop     edx
  389.         test    eax, eax
  390.         jz      .m
  391.         sub     edx, eax
  392.         add     edx, ecx
  393.         jmp     .m
  394. .done:
  395.         mov     [messages_pos], edx
  396.         ret
  397. .format:
  398. ; at moment all format specs must be %<digit>X
  399.         lodsb   ; get <digit>
  400.         sub     al, '0'
  401.         movzx   ecx, al
  402.         lodsb
  403.         pop     eax
  404.         pop     ebp
  405.         push    eax
  406. ; write number in ebp with ecx digits
  407.         dec     ecx
  408.         shl     ecx, 2
  409. .writenibble:
  410.         push    ecx
  411.         call    test_scroll
  412.         pop     ecx
  413.         mov     eax, ebp
  414.         shr     eax, cl
  415.         and     al, 0xF
  416.         cmp     al, 10
  417.         sbb     al, 69h
  418.         das
  419.         stosb
  420.         inc     edx
  421.         sub     ecx, 4
  422.         jns     .writenibble
  423.         jmp     .l
  424.  
  425. test_scroll:
  426.         cmp     edx, messages_width*messages_height
  427.         jnz     .ret
  428.         push    esi
  429.         mov     edi, messages
  430.         lea     esi, [edi+messages_width]
  431.         mov     ecx, (messages_height-1)*messages_width/4
  432.         rep     movsd
  433.         push    eax
  434.         mov     al, ' '
  435.         push    edi
  436.         push    messages_width
  437.         pop     ecx
  438.         sub     edx, ecx
  439.         rep     stosb
  440.         pop     edi
  441.         pop     eax
  442.         pop     esi
  443. .ret:   ret
  444.  
  445. put_message:
  446.         call    put_message_nodraw
  447.  
  448. draw_messages:
  449.         push    13
  450.         pop     eax
  451.         mov     edx, 0xFFFFFF
  452.         mov     ebx, messages_x_pos*10000h+messages_x_size
  453.         mov     ecx, messages_y_pos*10000h+messages_y_size
  454.         mcall
  455.         mov     edx, messages
  456.         push    messages_width
  457.         pop     esi
  458.         xor     ecx, ecx
  459.         mov     al, 4
  460.         mov     ebx, messages_x_pos*10000h+messages_y_pos
  461. @@:
  462.         mcall
  463.         add     edx, esi
  464.         add     ebx, 10
  465.         cmp     edx, messages+messages_width*messages_height
  466.         jb      @b
  467.         ret
  468.  
  469. draw_cursor:
  470.         push    38
  471.         pop     eax
  472.         mov     ecx, cmdline_y_pos*10001h+cmdline_y_size-1
  473.         mov     ebx, [cmdline_pos]
  474.         imul    ebx, 6
  475.         add     ebx, cmdline_x_pos
  476.         mov     edx, ebx
  477.         shl     ebx, 16
  478.         or      ebx, edx
  479.         xor     edx, edx
  480.         mcall
  481.         ret
  482. hide_cursor:
  483.         mov     ebx, [cmdline_pos]
  484.         push    13
  485.         pop     eax
  486.         imul    ebx, 6
  487.         add     ebx, cmdline_x_pos
  488.         shl     ebx, 16
  489.         inc     ebx
  490.         mov     ecx, cmdline_y_pos*10000h + cmdline_y_size
  491.         mov     edx, 0xFFFFFF
  492.         mcall
  493.         mov     ebx, [cmdline_pos]
  494.         cmp     ebx, [cmdline_len]
  495.         jae     .ret
  496.         mov     al, 4
  497.         xor     ecx, ecx
  498.         lea     edx, [cmdline+ebx]
  499.         imul    ebx, 6
  500.         add     ebx, cmdline_x_pos
  501.         shl     ebx, 16
  502.         or      ebx, cmdline_y_pos+1
  503.         push    1
  504.         pop     esi
  505.         mcall
  506. .ret:
  507.         ret
  508.  
  509. redraw_title:
  510.         push    13
  511.         pop     eax
  512.         mov     edx, 0xFFFFFF
  513.         mov     ebx, title_x_pos*10000h + data_x_pos+data_x_size-title_x_pos
  514.         mov     ecx, title_y_pos*10000h + title_y_size
  515.         mcall
  516. draw_title:
  517.         mov     al, 38
  518.         mov     ebx, (data_x_pos-2)*10000h + title_x_pos-5
  519.         mov     ecx, (title_y_pos+5)*10001h
  520.         xor     edx, edx
  521.         mcall
  522.         push    NoPrgLoaded_len
  523.         pop     esi
  524.         cmp     [debuggee_pid], 0
  525.         jz      @f
  526.         mov     esi, [prgname_len]
  527. @@:     imul    ebx, esi, 6
  528.         add     ebx, title_x_pos+4
  529.         shl     ebx, 16
  530.         mov     bx, data_x_pos+data_x_size-10-5-6*7
  531.         cmp     [bSuspended], 0
  532.         jz      @f
  533.         add     ebx, 6
  534. @@:
  535.         mcall
  536.         mov     ebx, (data_x_pos+data_x_size-10+4)*0x10000 + data_x_pos+data_x_size+2
  537.         mcall
  538.         mov     al, 4
  539.         mov     ebx, title_x_pos*10000h+title_y_pos
  540.         xor     ecx, ecx
  541.         mov     edx, NoPrgLoaded_str
  542.         cmp     [debuggee_pid], 0
  543.         jz      @f
  544.         mov     edx, [prgname_ptr]
  545. @@:
  546.         mcall
  547.         cmp     [debuggee_pid], 0
  548.         jz      .nodebuggee
  549.         mov     ebx, (data_x_pos+data_x_size-10-6*7)*10000h + title_y_pos
  550.         mov     edx, aRunning
  551.         push    7
  552.         pop     esi
  553.         cmp     [bSuspended], 0
  554.         jz      @f
  555.         add     ebx, 6*10000h
  556.         mov     edx, aPaused
  557.         dec     esi
  558. @@:
  559.         mcall
  560.         ret
  561. .nodebuggee:
  562.         mov     al, 38
  563.         mov     ebx, (data_x_pos+data_x_size-10-6*7-5)*0x10000 + data_x_pos+data_x_size+2
  564.         mov     ecx, (title_y_pos+5)*10001h
  565.         xor     edx, edx
  566.         jmp     @b
  567.  
  568. draw_register:
  569. ; in: esi->value, edx->string, ecx=string len, ebx=coord
  570.         push    edx
  571.         push    ecx
  572.         push    esi
  573.         mov     eax, esi
  574.         mov     esi, ecx
  575. ; color
  576.         mov     ecx, 40808080h
  577.         cmp     [debuggee_pid], 0
  578.         jz      .cd
  579.         cmp     [bSuspended], 0
  580.         jz      .cd
  581.         mov     ecx, 40000000h
  582.         push    edi
  583.         mov     edi, [eax]
  584.         cmp     dword [eax+oldcontext-context], edi
  585.         pop     edi
  586.         jz      .cd
  587.         mov     ecx, 0x4000AA00
  588. .cd:
  589.         push    4
  590.         pop     eax
  591.         mcall
  592.         imul    esi, 60000h
  593.         lea     edx, [ebx+esi]
  594.         mov     al, 47
  595.         mov     ebx, 80101h
  596.         mov     esi, ecx
  597.         pop     ecx
  598.         mcall
  599.         lea     ebx, [edx+60000h*18]
  600.         mov     esi, ecx
  601.         pop     ecx
  602.         pop     edx
  603.         add     edx, ecx
  604.         ret
  605. draw_flag:
  606.         movzx   edi, byte [edx+7]
  607.         bt      [_eflags], edi
  608.         jc      .on
  609.         or      byte [edx], 20h
  610.         jmp     .onoff
  611. .on:
  612.         and     byte [edx], not 20h
  613. .onoff:
  614.         mov     ecx, 40808080h
  615.         cmp     [debuggee_pid], 0
  616.         jz      .doit
  617.         cmp     [bSuspended], 0
  618.         jz      .doit
  619.         mov     ecx, 40000000h
  620.         bt      [_eflags], edi
  621.         lahf
  622.         bt      dword [_eflags + oldcontext - context], edi
  623.         rcl     ah, 1
  624.         test    ah, 3
  625.         jp      .doit
  626.         mov     ecx, 0x4000AA00
  627. .doit:
  628.         mov     ah, 0
  629.         mov     edi, 0xFFFFFF
  630.         mcall
  631.         ret
  632.  
  633. draw_registers:
  634.         push    13
  635.         pop     eax
  636.         mov     edx, 0xFFFFFF
  637.         mov     ebx, data_x_pos*10000h + data_x_size
  638.         mov     ecx, registers_y_pos*10000h + registers_y_size
  639.         mcall
  640. redraw_registers:
  641.         mov     edi, 0xFFFFFF
  642.         mov     esi, _eax
  643.         push    4
  644.         pop     ecx
  645.         mov     edx, regs_strs
  646.         mov     ebx, registers_x_pos*10000h+registers_y_pos
  647.         call    draw_register
  648.         add     esi, _ebx-_eax
  649.         call    draw_register
  650.         add     esi, _ecx-_ebx
  651.         call    draw_register
  652.         add     esi, _edx-_ecx
  653.         call    draw_register
  654.         mov     ebx, registers_x_pos*10000h+registers_y_pos+10
  655.         add     esi, _esi-_edx
  656.         call    draw_register
  657.         add     esi, _edi-_esi
  658.         call    draw_register
  659.         add     esi, _ebp-_edi
  660.         call    draw_register
  661.         add     esi, _esp-_ebp
  662.         call    draw_register
  663.         mov     ebx, registers_x_pos*10000h+registers_y_pos+20
  664.         add     esi, _eip-_esp
  665.         call    draw_register
  666.         mov     cl, 7
  667.         add     esi, _eflags-_eip
  668.         call    draw_register
  669.         mov     al, 4
  670.         mov     ecx, 808080h
  671.         cmp     [debuggee_pid], 0
  672.         jz      @f
  673.         cmp     [bSuspended], 0
  674.         jz      @f
  675.         xor     ecx, ecx
  676. @@:
  677.         mov     edx, aColon
  678.         xor     esi, esi
  679.         inc     esi
  680.         mov     ebx, (registers_x_pos+37*6)*10000h + registers_y_pos+20
  681.         mcall
  682.         mov     edx, flags
  683. @@:
  684.         add     ebx, 2*6*10000h
  685.         call    draw_flag
  686.         inc     edx
  687.         cmp     dl, flags_bits and 0xFF
  688.         jnz     @b
  689.         ret
  690.  
  691. draw_dump:
  692.         push    13
  693.         pop     eax
  694.         mov     edx, 0xFFFFFF
  695.         mov     ebx, data_x_pos*10000h + data_x_size
  696.         mov     ecx, dump_y_pos*10000h + dump_y_size
  697.         mcall
  698. redraw_dump:
  699. ; addresses
  700.         mov     al, 47
  701.         mov     ebx, 80100h
  702.         mov     edx, data_x_pos*10000h + dump_y_pos
  703.         mov     ecx, [dumppos]
  704.         mov     edi, 0xFFFFFF
  705.         mov     esi, 40808080h
  706.         cmp     [debuggee_pid], 0
  707.         jz      @f
  708.         cmp     [bSuspended], 0
  709.         jz      @f
  710.         mov     esi, 40000000h
  711. @@:
  712.         mcall
  713.         add     ecx, 10h
  714.         add     edx, 10
  715.         cmp     dl, dump_y_pos + dump_y_size
  716.         jb      @b
  717. ; hex dump of data
  718.         mov     ecx, dumpdata
  719.         push    ecx
  720.         xor     ebx, ebx
  721.         mov     edx, (data_x_pos+12*6)*10000h + dump_y_pos
  722.         cmp     [dumpread], ebx
  723.         jz      .hexdumpdone1
  724. .hexdumploop1:
  725.         push    ebx
  726.         mov     ebx, 20101h
  727.         mcall
  728.         pop     ebx
  729.         add     edx, 3*6*10000h
  730.         inc     ecx
  731.         inc     ebx
  732.         test    bl, 15
  733.         jz      .16
  734.         test    bl, 7
  735.         jnz     @f
  736.         add     edx, 2*6*10000h - 10 + 6*(3*10h+2)*10000h
  737. .16:
  738.         add     edx, 10 - 6*(3*10h+2)*10000h
  739. @@:
  740.         cmp     ebx, [dumpread]
  741.         jb      .hexdumploop1
  742. .hexdumpdone1:
  743.         mov     al, 4
  744.         mov     ecx, esi
  745.         xchg    ebx, edx
  746.         push    2
  747.         pop     esi
  748. .hexdumploop2:
  749.         cmp     edx, dump_height*10h
  750.         jae     .hexdumpdone2
  751.         push    edx
  752.         mov     edx, aQuests
  753.         mcall
  754.         pop     edx
  755.         add     ebx, 3*6*10000h
  756.         inc     edx
  757.         test    dl, 15
  758.         jz      .16x
  759.         test    dl, 7
  760.         jnz     .hexdumploop2
  761.         add     ebx, 2*6*10000h - 10 + 6*(3*10h+2)*10000h
  762. .16x:
  763.         add     ebx, 10 - 6*(3*10h+2)*10000h
  764.         jmp     .hexdumploop2
  765. .hexdumpdone2:
  766.         dec     esi
  767. ; colon, minus signs
  768.         mov     ebx, (data_x_pos+8*6)*10000h + dump_y_pos
  769.         mov     edx, aColon
  770. @@:
  771.         mcall
  772.         add     ebx, 10
  773.         cmp     bl, dump_y_pos+dump_height*10
  774.         jb      @b
  775.         mov     ebx, (data_x_pos+(12+3*8)*6)*10000h + dump_y_pos
  776.         mov     edx, aMinus
  777. @@:
  778.         mcall
  779.         add     ebx, 10
  780.         cmp     bl, dump_y_pos+dump_height*10
  781.         jb      @b
  782. ; ASCII data
  783.         mov     ebx, (data_x_pos+(12+3*10h+2+2)*6)*10000h + dump_y_pos
  784.         pop     edx
  785.         push    dump_height*10h
  786. .asciiloop:
  787.         push    edx
  788.         cmp     byte [edx], 20h
  789.         jae     @f
  790.         mov     edx, aPoint
  791. @@:
  792.         mcall
  793.         pop     edx
  794.         inc     edx
  795.         add     ebx, 6*10000h
  796.         dec     dword [esp]
  797.         jz      .asciidone
  798.         test    byte [esp], 15
  799.         jnz     .asciiloop
  800.         add     ebx, 10 - 6*10h*10000h
  801.         jmp     .asciiloop
  802. .asciidone:
  803.         pop     ecx
  804.         ret
  805.  
  806. redraw_disasm:
  807. ;       push    13
  808. ;       pop     eax
  809. ;       mov     edx, 0xFFFFFF
  810. ;       mov     ebx, data_x_pos*10000h + data_x_size
  811. ;       mov     ecx, (disasm_y_pos-1)*10000h + (disasm_y_size+1)
  812. ;       mcall
  813. draw_disasm:
  814.         mov     eax, [disasm_start_pos]
  815.         mov     [disasm_cur_pos], eax
  816.         and     [disasm_cur_str], 0
  817. .loop:
  818.         mov     eax, [disasm_cur_pos]
  819.         call    find_symbol
  820.         jc      .nosymb
  821.         mov     ebx, [disasm_cur_str]
  822.         imul    ebx, 10
  823.         add     ebx, (data_x_pos+6*2)*10000h + disasm_y_pos
  824.         mov     edx, esi
  825. @@:     lodsb
  826.         test    al, al
  827.         jnz     @b
  828.         mov     byte [esi-1], ':'
  829.         sub     esi, edx
  830.         mov     ecx, 40000000h
  831.         mov     edi, 0xFFFFFF
  832.         push    4
  833.         pop     eax
  834.         mcall
  835.         mov     byte [esi+edx-1], 0
  836.         lea     esi, [esi*3]
  837.         movzx   ecx, bx
  838.         shr     ebx, 16
  839.         lea     ebx, [ebx+esi*2]
  840.         shl     ecx, 16
  841.         mov     cl, 10
  842.         imul    ebx, 10001h
  843.         sub     bx, data_x_pos+data_x_size
  844.         neg     bx
  845.         mov     al, 13
  846.         mov     edx, edi
  847.         mcall
  848.         inc     [disasm_cur_str]
  849.         cmp     [disasm_cur_str], disasm_height
  850.         jae     .loopend
  851. .nosymb:
  852.         push    [disasm_cur_pos]
  853.         call    disasm_instr
  854.         pop     ebp
  855.         jc      .loopend
  856.         xor     esi, esi        ; default color: black
  857.         mov     edx, 0xFFFFFF   ; default background: white
  858.         mov     ebx, data_x_pos*10000h + data_x_size
  859.         mov     ecx, [disasm_cur_str]
  860.         imul    ecx, 10*10000h
  861.         add     ecx, (disasm_y_pos-1)*10000h + 10
  862.         mov     eax, ebp
  863.         pushad
  864.         call    find_enabled_breakpoint
  865.         popad
  866.         jnz     .nored
  867.         mov     edx, 0xFF0000   ; use background: red
  868. .nored:
  869.         mov     eax, [_eip]
  870.         cmp     eax, ebp
  871.         jnz     .noblue
  872.         mov     edx, 0x0000FF   ; use background: blue
  873.         mov     esi, 0xFFFFFF   ; on blue bgr, use white color
  874. .noblue:
  875.         push    13
  876.         pop     eax
  877.         mcall
  878.         mov     al, 47
  879.         mov     ebx, 80100h
  880.         mov     edx, [disasm_cur_str]
  881.         imul    edx, 10
  882.         add     edx, data_x_pos*10000h + disasm_y_pos
  883.         mov     ecx, ebp
  884.         mcall
  885.         mov     al, 4
  886.         lea     ebx, [edx+8*6*10000h]
  887.         mov     ecx, esi
  888.         push    2
  889.         pop     esi
  890.         mov     edx, aColon
  891.         mcall
  892.         push    9
  893.         pop     edi
  894.         lea     edx, [ebx+2*6*10000h]
  895.         mov     esi, ecx
  896.         mov     ecx, ebp
  897.         sub     ecx, [disasm_start_pos]
  898.         add     ecx, disasm_buffer
  899. .drawhex:
  900.         mov     al, 47
  901.         mov     ebx, 20101h
  902.         mcall
  903.         add     edx, 6*3*10000h
  904.         inc     ecx
  905.         inc     ebp
  906.         cmp     ebp, [disasm_cur_pos]
  907.         jae     .hexdone
  908.         dec     edi
  909.         jnz     .drawhex
  910.         push    esi
  911.         mov     esi, [disasm_cur_pos]
  912.         dec     esi
  913.         cmp     esi, ebp
  914.         pop     esi
  915.         jbe     .drawhex
  916.         mov     al, 4
  917.         lea     ebx, [edx-6*10000h]
  918.         mov     ecx, esi
  919.         push    3
  920.         pop     esi
  921.         mov     edx, aDots
  922.         mcall
  923.         mov     esi, ecx
  924. .hexdone:
  925.         xor     eax, eax
  926.         mov     edi, disasm_string
  927.         mov     edx, edi
  928.         or      ecx, -1
  929.         repnz   scasb
  930.         not     ecx
  931.         dec     ecx
  932.         xchg    ecx, esi
  933.         mov     ebx, [disasm_cur_str]
  934.         imul    ebx, 10
  935.         add     ebx, (data_x_pos+6*40)*10000h+disasm_y_pos
  936.         mov     al, 4
  937.         mcall
  938.         inc     [disasm_cur_str]
  939.         cmp     [disasm_cur_str], disasm_height
  940.         jb      .loop
  941. .loopend:
  942.         mov     ecx, disasm_height
  943.         sub     ecx, [disasm_cur_str]
  944.         jz      @f
  945.         imul    ecx, 10
  946.         mov     eax, disasm_y_pos + disasm_y_size
  947.         sub     eax, ecx
  948.         shl     eax, 16
  949.         add     ecx, eax
  950.         push    13
  951.         pop     eax
  952.         mov     ebx, data_x_pos*65536 + data_x_size
  953.         mov     edx, 0xFFFFFF
  954.         mcall
  955. @@:
  956.         ret
  957.  
  958. update_disasm_eip:
  959. ; test if instruction at eip is showed
  960.         mov     ecx, disasm_height
  961.         mov     eax, [disasm_start_pos]
  962.         mov     [disasm_cur_pos], eax
  963. .l:
  964.         mov     eax, [disasm_cur_pos]
  965.         call    find_symbol
  966.         jc      @f
  967.         dec     ecx
  968.         jz      .m
  969. @@:
  970.         cmp     [_eip], eax
  971.         jz      redraw_disasm
  972.         push    ecx
  973.         call    disasm_instr
  974.         pop     ecx
  975.         jc      .m
  976.         loop    .l
  977. .m:
  978. update_disasm_eip_force:
  979.         mov     eax, [_eip]
  980.         mov     [disasm_start_pos], eax
  981. update_disasm:
  982.         cmp     [debuggee_pid], 0
  983.         jz      .no
  984.         push    69
  985.         pop     eax
  986.         push    6
  987.         pop     ebx
  988.         mov     ecx, [debuggee_pid]
  989.         mov     edi, disasm_buffer
  990.         mov     edx, 256
  991.         mov     esi, [disasm_start_pos]
  992.         mcall
  993.         cmp     eax, -1
  994.         jnz     @f
  995.         mov     esi, read_mem_err
  996.         call    put_message
  997. .no:
  998.         xor     eax, eax
  999. @@:
  1000.         mov     [disasm_buf_size], eax
  1001.         call    restore_from_breaks
  1002.         jmp     redraw_disasm
  1003.  
  1004. draw_window:
  1005. ; start redraw
  1006.         push    12
  1007.         pop     eax
  1008.         push    1
  1009.         pop     ebx
  1010.         mcall
  1011. ; define window
  1012.         xor     eax, eax
  1013.         mov     ebx, wnd_x_size
  1014.         mov     ecx, wnd_y_size
  1015.         mov     edx, 54FFFFFFh
  1016.         mov     edi, caption_str
  1017.         mcall
  1018. ; clear unused areas
  1019.         mov     al, 48
  1020.         push    4
  1021.         pop     ebx
  1022.         mcall
  1023.         cmp     eax, title_y_pos
  1024.         jb      @f
  1025.         push    registers_y_pos
  1026.         pop     eax
  1027. @@:
  1028.         push    registers_y_pos
  1029.         pop     ecx
  1030.         push    eax
  1031.         sub     ecx, eax
  1032.         shl     eax, 16
  1033.         add     ecx, eax
  1034.         mov     ebx, 5*10000h + (wnd_x_size-9)
  1035.         push    13
  1036.         pop     eax
  1037.         mcall
  1038.         mov     ecx, (registers_y_pos+registers_y_size)*10000h + (dump_y_pos-registers_y_pos-registers_y_size)
  1039.         mcall
  1040.         mov     ecx, (dump_y_pos+dump_y_size)*10000h + (disasm_y_pos-dump_y_pos-dump_y_size)
  1041.         mcall
  1042.         mov     ecx, (disasm_y_pos+disasm_y_size)*10000h + (messages_y_pos-disasm_y_pos-disasm_y_size)
  1043.         mcall
  1044.         mov     ecx, (messages_y_pos+messages_y_size)*10000h + (wnd_y_size-messages_y_pos-messages_y_size-4)
  1045.         mcall
  1046.         mov     ebx, 5*10000h + (data_x_pos-5)
  1047.         pop     ecx
  1048.         imul    ecx, 10001h
  1049.         sub     cx, wnd_y_size-4
  1050.         neg     cx
  1051.         mcall
  1052.         mov     ebx, (data_x_pos+data_x_size)*10000h + (wnd_x_size-data_x_pos-data_x_size-4)
  1053.         mcall
  1054. ; messages frame
  1055.         mov     al, 38
  1056.         mov     ebx, (messages_x_pos-2)*10000h + (messages_x_pos+messages_x_size+2)
  1057.         push    ebx
  1058.         mov     ecx, (messages_y_pos-2)*10001h
  1059.         xor     edx, edx
  1060.         mcall
  1061.         mov     ecx, (messages_y_pos+messages_y_size+2)*10001h
  1062.         mcall
  1063.         mov     ebx, (messages_x_pos-2)*10001h
  1064.         push    ebx
  1065.         mov     ecx, (messages_y_pos-2)*10000h + (messages_y_pos+messages_y_size+2)
  1066.         mcall
  1067.         mov     ebx, (messages_x_pos+messages_x_size+2)*10001h
  1068.         push    ebx
  1069.         mcall
  1070. ; command line frame
  1071.         mov     ecx, (cmdline_y_pos-2)*10000h + (cmdline_y_pos+cmdline_y_size+2)
  1072.         pop     ebx
  1073.         mcall
  1074.         pop     ebx
  1075.         mcall
  1076.         pop     ebx
  1077.         mov     ecx, (cmdline_y_pos+cmdline_y_size+2)*10001h
  1078.         mcall
  1079.         mov     ecx, (cmdline_y_pos-2)*10001h
  1080.         mcall
  1081. ; messages
  1082.         call    draw_messages
  1083. ; command line & cursor
  1084.         call    draw_cmdline
  1085.         call    draw_cursor
  1086. ; title & registers & dump & disasm
  1087.         mov     al, 38
  1088.         mov     ebx, (data_x_pos-2)*10001h
  1089.         mov     ecx, (title_y_pos+5)*10000h + (messages_y_pos-2)
  1090.         mcall
  1091.         mov     ebx, (data_x_pos+data_x_size+2)*10001h
  1092.         mcall
  1093.         mov     ebx, (data_x_pos-2)*10000h + (data_x_pos+data_x_size+2)
  1094.         mov     ecx, (dump_y_pos-3)*10001h
  1095.         mcall
  1096.         mov     ecx, (disasm_y_pos-4)*10001h
  1097.         mcall
  1098.         call    redraw_title
  1099.         call    draw_registers
  1100.         call    draw_dump
  1101.         call    redraw_disasm
  1102. ; end redraw
  1103.         push    12
  1104.         pop     eax
  1105.         push    2
  1106.         pop     ebx
  1107.         mcall
  1108.         ret
  1109.  
  1110. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1111. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DEBUGGING ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1112. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1113.  
  1114. OnHelp:
  1115.         mov     esi, help_msg
  1116.         mov     edi, [curarg]
  1117.         cmp     byte [edi], 0
  1118.         jz      .x
  1119.         mov     esi, help_groups
  1120.         call    find_cmd
  1121.         jc      .nocmd
  1122.         mov     esi, [esi+12]
  1123. .x:
  1124.         jmp     put_message
  1125. .nocmd:
  1126.         mov     esi, aUnknownCommand
  1127.         jmp     .x
  1128.  
  1129. OnQuit:
  1130.         push    -1
  1131.         pop     eax
  1132.         mcall
  1133.  
  1134. get_new_context:
  1135.         mov     esi, context
  1136.         mov     edi, oldcontext
  1137.         mov     ecx, 10
  1138.         rep     movsd
  1139. get_context:
  1140.         push    1
  1141.         pop     ebx
  1142.         push    69
  1143.         pop     eax
  1144.         mov     ecx, [debuggee_pid]
  1145.         mov     esi, context
  1146.         push    28h
  1147.         pop     edx
  1148.         mcall
  1149.         ret
  1150. set_context:
  1151.         push    2
  1152.         pop     ebx
  1153.         push    69
  1154.         pop     eax
  1155.         mov     ecx, [debuggee_pid]
  1156.         mov     esi, context
  1157.         push    28h
  1158.         pop     edx
  1159.         mcall
  1160.         ret
  1161.  
  1162. get_dump:
  1163.         mov     edi, dumpdata
  1164.         mov     esi, [edi-4]
  1165.         mov     edx, dump_height*10h
  1166.         mov     ecx, edx
  1167.         xor     eax, eax
  1168.         push    edi
  1169.         rep     stosb
  1170.         pop     edi
  1171.         mov     ecx, [debuggee_pid]
  1172.         mov     al, 69
  1173.         push    6
  1174.         pop     ebx
  1175.         mcall
  1176.         cmp     eax, -1
  1177.         jnz     @f
  1178.         mov     esi, read_mem_err
  1179.         call    put_message
  1180.         xor     eax, eax
  1181. @@:
  1182.         mov     [edi-8], eax
  1183. ;       call    restore_from_breaks
  1184. ;       ret
  1185. restore_from_breaks:
  1186. ; in: edi=buffer,eax=size,esi=address
  1187.         mov     ebx, breakpoints
  1188. @@:
  1189.         test    byte [ebx+4], 1
  1190.         jz      .cont           ; ignore invalid
  1191.         test    byte [ebx+4], 2 or 8
  1192.         jnz     .cont           ; ignore disabled and memory breaks
  1193.         mov     ecx, [ebx]
  1194.         sub     ecx, esi
  1195.         cmp     ecx, eax
  1196.         jae     .cont
  1197.         mov     dl, [ebx+5]
  1198.         mov     [edi+ecx], dl
  1199. .cont:
  1200.         add     ebx, 6
  1201.         cmp     ebx, breakpoints+breakpoints_n*6
  1202.         jb      @b
  1203.         ret
  1204.  
  1205. OnLoad:
  1206.         mov     esi, [curarg]
  1207. OnLoadInit:
  1208.         mov     edi, loadname
  1209.         or      [prgname_len], -1
  1210.         mov     [prgname_ptr], edi
  1211. .copyname:
  1212.         lodsb
  1213.         stosb
  1214.         inc     [prgname_len]
  1215.         cmp     al, '/'
  1216.         jnz     @f
  1217.         or      [prgname_len], -1
  1218.         mov     [prgname_ptr], edi
  1219. @@:
  1220.         cmp     al, ' '
  1221.         ja      .copyname
  1222.         mov     byte [edi-1], 0
  1223.         and     [load_params], 0
  1224.         dec     esi
  1225.         call    skip_spaces
  1226.         cmp     al, 0
  1227.         jz      @f
  1228.         mov     [load_params], esi
  1229. @@:
  1230.         and     [dumppos], 0
  1231.         mov     ecx, [symbols]
  1232.         jecxz   do_reload
  1233.         mcall   68, 13
  1234.         and     [symbols], 0
  1235.         and     [num_symbols], 0
  1236. do_reload:
  1237.         push    18
  1238.         pop     eax
  1239.         push    7
  1240.         pop     ebx
  1241.         mcall
  1242.         mov     [dbgwnd], eax
  1243.         xchg    ecx, eax
  1244.         push    70
  1245.         pop     eax
  1246.         mov     ebx, fn70_load_block
  1247.         mcall
  1248.         test    eax, eax
  1249.         jns     .load_ok
  1250. .load_err:
  1251.         push    eax
  1252.         mov     esi, load_err_msg
  1253.         call    put_message
  1254.         pop     eax
  1255.         not     eax
  1256.         cmp     eax, 0x20
  1257.         jae     .unk_err
  1258.         mov     esi, [load_err_msgs+eax*4]
  1259.         test    esi, esi
  1260.         jnz     put_message
  1261. .unk_err:
  1262.         mov     esi, unk_err_msg
  1263.         inc     eax
  1264.         push    eax
  1265.         call    put_message_nodraw
  1266.         jmp     draw_messages
  1267. .load_ok:
  1268.         mov     [debuggee_pid], eax
  1269.         mov     [bSuspended], 1
  1270.         push    ecx
  1271.         call    get_context
  1272.         mov     edi, oldcontext
  1273.         mov     ecx, 10
  1274.         rep     movsd
  1275. ; activate debugger window
  1276.         pop     ecx
  1277.         mov     bl, 3
  1278.         push    18
  1279.         pop     eax
  1280.         mcall
  1281.         call    redraw_title
  1282.         call    redraw_registers
  1283.         call    get_dump
  1284.         call    redraw_dump
  1285.         call    update_disasm_eip_force
  1286.         mov     esi, load_succ_msg
  1287.         push    [debuggee_pid]
  1288.         call    put_message_nodraw
  1289.         call    draw_messages
  1290. ; try to load symbols
  1291.         mov     esi, loadname
  1292.         mov     edi, symbolsfile
  1293.         push    edi
  1294. @@:
  1295.         lodsb
  1296.         stosb
  1297.         test    al, al
  1298.         jnz     @b
  1299.         lea     ecx, [edi-1]
  1300. @@:
  1301.         dec     edi
  1302.         cmp     edi, symbolsfile
  1303.         jb      @f
  1304.         cmp     byte [edi], '/'
  1305.         jz      @f
  1306.         cmp     byte [edi], '.'
  1307.         jnz     @b
  1308.         mov     ecx, edi
  1309. @@:
  1310.         mov     dword [ecx], '.dbg'
  1311.         mov     byte [ecx+4], 0
  1312.         pop     esi
  1313.         mov     ebp, esi
  1314.         call    OnLoadSymbols.silent
  1315. ; now test for packed progs
  1316.         cmp     [disasm_buf_size], 100h
  1317.         jz      @f
  1318.         ret
  1319. @@:
  1320.         mov     esi, mxp_nrv_sig
  1321.         mov     ebp, disasm_buffer
  1322.         mov     edi, ebp
  1323.         push    3
  1324.         pop     ecx
  1325.         repz    cmpsb
  1326.         jnz     .not_mxp_nrv
  1327.         cmpsb
  1328.         mov     cl, mxp_nrv_sig_size-4
  1329.         repz    cmpsb
  1330.         mov     esi, mxp_nrv_name
  1331.         jz      .packed
  1332. .not_mxp_nrv:
  1333.         mov     esi, mxp_sig
  1334.         mov     edi, ebp
  1335.         mov     cl, mxp_sig_size
  1336.         repz    cmpsb
  1337.         mov     esi, mxp_name
  1338.         jz      .packed
  1339. .not_mxp:
  1340.         mov     esi, mxp_lzo_sig1
  1341.         mov     edi, ebp
  1342.         mov     cl, mxp_lzo_sig1_size
  1343.         repz    cmpsb
  1344.         mov     esi, mxp_lzo_name
  1345.         jz      .packed
  1346.         mov     esi, mxp_lzo_sig2
  1347.         mov     edi, ebp
  1348.         mov     cl, 8
  1349.         repz    cmpsb
  1350.         jnz     .not_mxp_lzo
  1351.         cmpsb
  1352.         mov     cl, mxp_lzo_sig2_size - 9
  1353.         repz    cmpsb
  1354.         mov     esi, mxp_lzo_name
  1355.         jz      .packed
  1356. .not_mxp_lzo:
  1357.         mov     esi, mtappack_name
  1358.         cmp     dword [ebp], 0xBF5E246A
  1359.         jnz     .not_mtappack
  1360.         cmp     dword [ebp+8], 0xEC4E8B57
  1361.         jnz     .not_mtappack1
  1362.         cmp     dword [ebp+12], 0x8D5EA4F3
  1363.         jnz     .not_mtappack1
  1364.         cmp     byte [ebp+12h], 0xE9
  1365.         jz      .packed
  1366. .not_mtappack1:
  1367.         cmp     word [ebp+8], 0xB957
  1368.         jnz     .not_mtappack
  1369.         cmp     dword [ebp+14], 0x575EA4F3
  1370.         jnz     .not_mtappack2
  1371.         cmp     byte [ebp+17h], 0xE9
  1372.         jz      .packed
  1373. .not_mtappack2:
  1374.         cmp     dword [ebp+14], 0x5F8DA4F3
  1375.         jnz     .not_mtappack3
  1376.         cmp     word [ebp+18], 0xE9FC
  1377.         jz      .packed
  1378. .not_mtappack3:
  1379.         cmp     word [ebp+14], 0xA4F3
  1380.         jnz     .not_mtappack
  1381.         cmp     byte [ebp+15h], 0xE9
  1382.         jz      .packed
  1383. .not_mtappack:
  1384.         ret
  1385. .packed:
  1386.         push    esi
  1387.         mov     esi, aPacked1
  1388.         call    put_message_nodraw
  1389.         pop     esi
  1390.         call    put_message_nodraw
  1391.         mov     esi, aPacked2
  1392.         call    put_message
  1393.         call    hide_cursor
  1394.         push    40
  1395.         pop     eax
  1396.         push    7
  1397.         pop     ebx
  1398.         mcall
  1399. .wait:
  1400.         push    10
  1401.         pop     eax
  1402.         mcall
  1403.         dec     eax
  1404.         jz      .redraw
  1405.         dec     eax
  1406.         jz      .key
  1407.         or      eax, -1
  1408.         mcall
  1409. .redraw:
  1410.         call    draw_window
  1411.         call    hide_cursor
  1412.         jmp     .wait
  1413. .key:
  1414.         mov     al, 2
  1415.         mcall
  1416.         cmp     ah, 'y'
  1417.         jz      .yes
  1418.         cmp     ah, 'Y'
  1419.         jz      .yes
  1420.         cmp     ah, 0xD
  1421.         jz      .yes
  1422.         cmp     ah, 'n'
  1423.         jz      .no
  1424.         cmp     ah, 'N'
  1425.         jnz     .wait
  1426. .no:
  1427.         push    40
  1428.         pop     eax
  1429.         mov     ebx, 0x107
  1430.         mcall
  1431.         call    draw_cursor
  1432.         mov     esi, aN_str
  1433.         jmp     put_message
  1434. .yes:
  1435.         push    40
  1436.         pop     eax
  1437.         mov     ebx, 0x107
  1438.         mcall
  1439.         call    draw_cursor
  1440.         mov     esi, aY_str
  1441.         call    put_message
  1442.         call    OnUnpack
  1443.         ret
  1444.  
  1445. mxp_nrv_sig:
  1446.         xor     eax, eax
  1447.         mov     ecx, 0x95       ; 0xA1 for programs with parameters
  1448.         mov     [eax], ecx
  1449.         add     ecx, [eax+24h]
  1450.         push    40h
  1451.         pop     esi
  1452.         mov     edi, [eax+20h]
  1453.         push    edi
  1454.         rep     movsb
  1455.         jmp     dword [esp]
  1456.         pop     esi
  1457.         add     esi, [eax]
  1458.         xor     edi, edi
  1459. mxp_nrv_sig_size = $ - mxp_nrv_sig
  1460.  
  1461. mxp_sig:
  1462.         mov     ecx, 1CBh
  1463.         push    46h
  1464.         pop     esi
  1465.         mov     edi, [20h]
  1466.         rep     movsb
  1467.         mov     ecx, [24h]
  1468.         rep     movsb
  1469.         jmp     dword [20h]
  1470.         mov     eax, [20h]
  1471.         add     eax, 1CBh
  1472.         push    eax
  1473.         push    dword [24h]
  1474.         push    0
  1475.         push    8
  1476.         call    $+0x25
  1477. mxp_sig_size = $ - mxp_sig
  1478.  
  1479. mxp_lzo_sig1:
  1480.         xor     eax, eax
  1481.         mov     ebp, 0FFh
  1482.         mov     ecx, 175h
  1483.         mov     [eax], ecx
  1484.         add     ecx, [eax+24h]
  1485.         push    45h
  1486.         pop     esi
  1487.         mov     edi, [eax+20h]
  1488.         push    edi
  1489.         rep     movsb
  1490.         jmp     dword [esp]
  1491.         pop     ebx
  1492.         add     ebx, [eax]
  1493.         xor     edi, edi
  1494.         cmp     byte [ebx], 11h
  1495.         jbe     $+0x1A
  1496. mxp_lzo_sig1_size = $ - mxp_lzo_sig1
  1497. mxp_lzo_sig2:
  1498.         xor     eax, eax
  1499.         mov     ebp, 0FFh
  1500.         mov     ecx, 188h       ; or 177h
  1501.         mov     [eax], ecx
  1502.         add     ecx, [eax+24h]
  1503.         push    44h
  1504.         pop     esi
  1505.         mov     edi, [eax+20h]
  1506.         rep     movsb
  1507.         jmp     dword [eax+20h]
  1508.         mov     ebx, [eax+20h]
  1509.         add     ebx, [eax]
  1510. mxp_lzo_sig2_size = $ - mxp_lzo_sig2
  1511.  
  1512. OnReload:
  1513.         cmp     [debuggee_pid], 0
  1514.         jnz     terminate_reload
  1515.         mov     esi, need_debuggee
  1516.         cmp     byte [loadname], 0
  1517.         jnz     do_reload
  1518.         jz      put_message
  1519. terminate_reload:
  1520.         mov     [bReload], 1
  1521. OnTerminate:
  1522.         mov     ecx, [debuggee_pid]
  1523.         push    8
  1524.         pop     ebx
  1525.         push    69
  1526.         pop     eax
  1527.         mcall
  1528.         ret
  1529.  
  1530. AfterSuspend:
  1531.         mov     [bSuspended], 1
  1532.         call    get_new_context
  1533.         call    get_dump
  1534.         call    redraw_title
  1535.         call    redraw_registers
  1536.         call    redraw_dump
  1537.         call    update_disasm_eip
  1538.         ret
  1539.  
  1540. OnSuspend:
  1541.         mov     ecx, [debuggee_pid]
  1542.         push    4
  1543.         pop     ebx
  1544.         push    69
  1545.         pop     eax
  1546.         mcall
  1547.         call    AfterSuspend
  1548.         mov     esi, aSuspended
  1549.         jmp     put_message
  1550. DoResume:
  1551.         mov     ecx, [debuggee_pid]
  1552.         push    5
  1553.         pop     ebx
  1554.         push    69
  1555.         pop     eax
  1556.         mcall
  1557.         mov     [bSuspended], 0
  1558.         ret
  1559. OnResume:
  1560.         mov     esi, [curarg]
  1561.         cmp     byte [esi], 0
  1562.         jz      GoOn
  1563.         call    calc_expression
  1564.         jc      .ret
  1565.         mov     eax, ebp
  1566.         push    eax
  1567.         call    find_enabled_breakpoint
  1568.         pop     eax
  1569.         jz      GoOn
  1570.         mov     bl, 5   ; valid enabled one-shot
  1571.         call    add_breakpoint
  1572.         jnc     GoOn
  1573.         mov     esi, aBreakpointLimitExceeded
  1574.         call    put_message
  1575. .ret:
  1576.         ret
  1577. GoOn:
  1578. ; test for enabled breakpoint at eip
  1579.         mov     eax, [_eip]
  1580.         call    find_enabled_breakpoint
  1581.         jnz     .nobreak
  1582. ; temporarily disable breakpoint, make step, enable breakpoint, continue
  1583.         inc     eax
  1584.         mov     [temp_break], eax
  1585.         mov     [bAfterGo], 1
  1586.         dec     eax
  1587.         call    disable_breakpoint
  1588.         call    get_context
  1589.         or      byte [_eflags+1], 1             ; set TF
  1590.         call    set_context
  1591.         and     byte [_eflags+1], not 1
  1592.         call    DoResume
  1593.         ret
  1594. .nobreak:
  1595.         call    DoResume
  1596.         call    redraw_title
  1597.         call    redraw_registers
  1598.         call    redraw_dump
  1599.         ret
  1600. OnDetach:
  1601.         mov     ecx, [debuggee_pid]
  1602.         push    3
  1603.         pop     ebx
  1604.         push    69
  1605.         pop     eax
  1606.         mcall
  1607.         and     [debuggee_pid], 0
  1608.         call    redraw_title
  1609.         call    redraw_registers
  1610.         call    redraw_dump
  1611.         call    free_symbols
  1612.         mov     esi, aContinued
  1613.         jmp     put_message
  1614.  
  1615. after_go_exception:
  1616.         push    eax
  1617.         mov     eax, [temp_break]
  1618.         dec     eax
  1619.         push    esi
  1620.         call    enable_breakpoint
  1621. ; in any case, clear TF and RF
  1622.         call    get_new_context
  1623.         and     [_eflags], not 10100h           ; clear TF,RF
  1624.         call    set_context
  1625.         xor     edx, edx
  1626.         mov     [temp_break], edx
  1627.         xchg    dl, [bAfterGo]
  1628.         pop     esi
  1629.         pop     eax
  1630.         cmp     dl, 2
  1631.         jnz     @f
  1632.         lodsd
  1633.         push    esi
  1634.         call    get_dump
  1635.         jmp     exception.done
  1636. @@:     test    eax, eax
  1637.         jz      .notint1
  1638. ; if exception is result of single step, simply ignore it and continue
  1639.         test    dword [esi], 0xF
  1640.         jnz     dbgmsgstart.5
  1641.         lodsd
  1642.         push    esi
  1643.         mov     esi, oldcontext
  1644.         mov     edi, context
  1645.         mov     ecx, 28h/4
  1646.         rep     movsd
  1647.         call    DoResume
  1648.         jmp     dbgmsgend
  1649. .notint1:
  1650. ; in other case, work as without temp_break
  1651.         lodsd
  1652.         push    esi
  1653.         push    eax
  1654.         jmp     exception.4
  1655. .notour:
  1656.  
  1657. debugmsg:
  1658.         neg     [dbgbufsize]
  1659.         mov     esi, dbgbuf
  1660. dbgmsgstart:
  1661.         lodsd
  1662. ;       push    eax esi
  1663. ;       push    dword [esi]
  1664. ;       mov     esi, dbgmsg_str
  1665. ;       call    put_message_nodraw
  1666. ;       pop     esi eax
  1667.         add     esi, 4
  1668.         dec     eax
  1669.         jz      exception
  1670.         dec     eax
  1671.         jz      terminated
  1672.         mov     [bSuspended], 1
  1673.         cmp     [bAfterGo], 0
  1674.         jnz     after_go_exception
  1675.         push    esi
  1676.         call    get_new_context
  1677.         and     [_eflags], not 10100h           ; clear TF,RF
  1678.         call    set_context
  1679.         pop     esi
  1680. .5:
  1681.         push    esi
  1682.         call    get_dump
  1683.         pop     esi
  1684.         lodsd
  1685.         xor     ecx, ecx
  1686. .6:
  1687.         bt      eax, ecx
  1688.         jnc     .7
  1689.         mov     ebx, [drx_break+ecx*4]
  1690.         test    ebx, ebx
  1691.         jz      .7
  1692.         pushad
  1693.         dec     ebx
  1694.         push    ebx
  1695.         mov     esi, aBreakStop
  1696.         call    put_message_nodraw
  1697.         popad
  1698. .7:
  1699.         inc     ecx
  1700.         cmp     cl, 4
  1701.         jb      .6
  1702.         push    esi
  1703.         jmp     exception.done_draw
  1704. terminated:
  1705.         push    esi
  1706.         mov     esi, terminated_msg
  1707.         call    put_message
  1708.         and     [debuggee_pid], 0
  1709.         and     [temp_break], 0
  1710.         mov     [bAfterGo], 0
  1711.         xor     eax, eax
  1712.         mov     ecx, breakpoints_n*6/4+4
  1713.         mov     edi, breakpoints
  1714.         rep     stosd
  1715.         cmp     [bReload], 1
  1716.         sbb     [bReload], -1
  1717.         jnz     exception.done
  1718.         call    free_symbols
  1719.         jmp     exception.done
  1720. exception:
  1721.         mov     [bSuspended], 1
  1722.         cmp     [bAfterGo], 0
  1723.         jnz     after_go_exception
  1724.         lodsd
  1725.         push    esi
  1726.         push    eax
  1727.         call    get_new_context
  1728.         and     [_eflags], not 10100h           ; clear TF,RF
  1729.         call    set_context
  1730. .4:
  1731.         call    get_dump
  1732.         pop     eax
  1733. ; int3 command generates exception 0D, #GP
  1734.         push    eax
  1735.         cmp     al, 0Dh
  1736.         jnz     .notdbg
  1737. ; check for 0xCC byte at eip
  1738.         push    0
  1739.         push    69
  1740.         pop     eax
  1741.         push    6
  1742.         pop     ebx
  1743.         mov     ecx, [debuggee_pid]
  1744.         mov     edi, esp
  1745.         mov     esi, [_eip]
  1746.         push    1
  1747.         pop     edx
  1748.         mcall
  1749.         pop     eax
  1750.         cmp     al, 0xCC
  1751.         jnz     .notdbg
  1752. ; this is either dbg breakpoint or int3 cmd in debuggee
  1753.         mov     eax, [_eip]
  1754.         call    find_enabled_breakpoint
  1755.         jnz     .user_int3
  1756. ; dbg breakpoint; clear if one-shot
  1757.         pop     ecx
  1758.         push    eax
  1759.         mov     esi, aBreakStop
  1760.         test    byte [edi+4], 4
  1761.         jz      .put_msg_eax
  1762.         pop     ecx
  1763.         call    clear_breakpoint
  1764.         jmp     .done
  1765. .user_int3:
  1766.         mov     eax, [_eip]
  1767.         inc     [_eip]
  1768.         pop     ecx
  1769.         push    eax
  1770.         call    set_context
  1771.         mov     esi, aUserBreak
  1772.         jmp     .put_msg_eax
  1773. .notdbg:
  1774.         mov     esi, aException
  1775. .put_msg_eax:
  1776.         call    put_message_nodraw
  1777. .done_draw:
  1778.         call    draw_messages
  1779. .done:
  1780.         push    18
  1781.         pop     eax
  1782.         push    3
  1783.         pop     ebx
  1784.         mov     ecx, [dbgwnd]
  1785.         mcall   ; activate dbg window
  1786.         call    redraw_title
  1787.         call    redraw_registers
  1788.         call    redraw_dump
  1789.         call    update_disasm_eip
  1790. dbgmsgend:
  1791.         pop     esi
  1792.         mov     ecx, [dbgbuflen]
  1793.         add     ecx, dbgbuf
  1794.         cmp     esi, ecx
  1795.         jnz     dbgmsgstart
  1796.         and     [dbgbuflen], 0
  1797.         neg     [dbgbufsize]
  1798.         cmp     [bReload], 2
  1799.         jnz     @f
  1800.         mov     [bReload], 0
  1801.         call    do_reload
  1802. @@:
  1803.         jmp     waitevent
  1804.  
  1805. CtrlF7:
  1806.         cmp     [debuggee_pid], 0
  1807.         jz      .no
  1808.         call    OnStep
  1809. .no:
  1810.         jmp     waitevent
  1811. CtrlF8:
  1812.         cmp     [debuggee_pid], 0
  1813.         jz      CtrlF7.no
  1814.         call    OnProceed
  1815.         jmp     CtrlF7.no
  1816.  
  1817. OnStep:
  1818.         cmp     [bSuspended], 0
  1819.         jz      .running
  1820.         call    get_context
  1821.         or      byte [_eflags+1], 1             ; set TF
  1822.         call    set_context
  1823.         and     byte [_eflags+1], not 1
  1824. ; if instruction at eip is "int xx", set one-shot breakpoint immediately after
  1825.         mov     eax, [_eip]
  1826.         call    find_enabled_breakpoint
  1827.         jnz     @f
  1828.         cmp     byte [edi+5], 0xCD
  1829.         jz      .int
  1830. @@:
  1831.         push    0
  1832.         push    69
  1833.         pop     eax
  1834.         push    6
  1835.         pop     ebx
  1836.         mov     ecx, [debuggee_pid]
  1837.         push    3
  1838.         pop     edx
  1839.         mov     edi, esp
  1840.         mov     esi, [_eip]
  1841.         mcall
  1842.         cmp     eax, edx
  1843.         pop     eax
  1844.         jnz     .doit
  1845.         cmp     al, 0xCD
  1846.         jz      .int
  1847.         cmp     ax, 0x050F
  1848.         jz      .syscall
  1849.         cmp     ax, 0x340F
  1850.         jz      .sysenter
  1851. ; resume process
  1852. .doit:
  1853.         call    GoOn
  1854.         cmp     [bAfterGo], 0
  1855.         jz      @f
  1856.         mov     [bAfterGo], 2
  1857. @@:
  1858.         ret
  1859. .sysenter:      ; return address is [ebp-4]
  1860.         push    0
  1861.         push    69
  1862.         pop     eax
  1863.         inc     edx     ; read 4 bytes
  1864.         mov     esi, [_ebp]
  1865.         sub     esi, 4
  1866.         mcall
  1867.         cmp     eax, edx
  1868.         pop     eax
  1869.         jnz     .syscall
  1870.         push    eax
  1871.         and     byte [_eflags+1], not 1
  1872.         call    set_context
  1873.         pop     eax
  1874.         jmp     @f
  1875. .syscall:
  1876.         and     byte [_eflags+1], not 1 ; clear TF - avoid system halt (!)
  1877.         call    set_context
  1878. .int:
  1879.         mov     eax, [_eip]
  1880.         inc     eax
  1881.         inc     eax
  1882. @@:
  1883.         push    eax
  1884.         call    find_enabled_breakpoint
  1885.         pop     eax
  1886.         jz      .doit
  1887. ; there is no enabled breakpoint yet; set temporary breakpoint
  1888.         mov     bl, 5
  1889.         call    add_breakpoint
  1890.         jmp     .doit
  1891. .running:
  1892.         mov     esi, aRunningErr
  1893.         jmp     put_message
  1894.  
  1895. OnProceed:
  1896.         cmp     [bSuspended], 0
  1897.         jz      OnStep.running
  1898.         mov     esi, [_eip]
  1899. @@:
  1900.         call    get_byte_nobreak
  1901.         jc      OnStep
  1902.         inc     esi
  1903. ; skip prefixes
  1904.         call    is_prefix
  1905.         jz      @b
  1906.         cmp     al, 0xE8        ; call
  1907.         jnz     @f
  1908.         add     esi, 4
  1909.         jmp     .doit
  1910. @@:     ; A4,A5 = movs, A6,A7=cmps
  1911.         cmp     al, 0xA4
  1912.         jb      @f
  1913.         cmp     al, 0xA8
  1914.         jb      .doit
  1915. @@:     ; AA,AB=stos, AC,AD=lods, AE,AF=scas
  1916.         cmp     al, 0xAA
  1917.         jb      @f
  1918.         cmp     al, 0xB0
  1919.         jb      .doit
  1920. @@:     ; E0=loopnz,E1=loopz,E2=loop
  1921.         cmp     al, 0xE0
  1922.         jb      .noloop
  1923.         cmp     al, 0xE2
  1924.         ja      .noloop
  1925.         inc     esi
  1926.         jmp     .doit
  1927. .noloop:        ; FF /2 = call
  1928.         cmp     al, 0xFF
  1929.         jnz     OnStep
  1930.         call    get_byte_nobreak
  1931.         jc      OnStep
  1932.         inc     esi
  1933.         mov     cl, al
  1934.         and     al, 00111000b
  1935.         cmp     al, 00010000b
  1936.         jnz     OnStep
  1937. ; skip instruction
  1938.         mov     al, cl
  1939.         and     eax, 7
  1940.         shr     cl, 6
  1941.         jz      .mod0
  1942.         jp      .doit
  1943.         cmp     al, 4
  1944.         jnz     @f
  1945.         inc     esi
  1946. @@:
  1947.         inc     esi
  1948.         dec     cl
  1949.         jz      @f
  1950.         add     esi, 3
  1951. @@:
  1952.         jmp     .doit
  1953. .mod0:
  1954.         cmp     al, 4
  1955.         jnz     @f
  1956.         call    get_byte_nobreak
  1957.         jc      OnStep
  1958.         inc     esi
  1959.         and     al, 7
  1960. @@:
  1961.         cmp     al, 5
  1962.         jnz     .doit
  1963.         add     esi, 4
  1964. .doit:
  1965. ; insert one-shot breakpoint at esi and resume
  1966.         call    get_byte_nobreak
  1967.         jc      OnStep
  1968.         mov     eax, esi
  1969.         call    find_enabled_breakpoint
  1970.         jz      .ret
  1971.         mov     eax, esi
  1972.         mov     bl, 5
  1973.         call    add_breakpoint
  1974.         jmp     OnStep.doit
  1975. .ret:
  1976.         ret
  1977.  
  1978. get_byte_nobreak:
  1979.         mov     eax, esi
  1980.         call    find_enabled_breakpoint
  1981.         jnz     .nobreak
  1982.         mov     al, [edi+5]
  1983.         clc
  1984.         ret
  1985. .nobreak:
  1986.         push    69
  1987.         pop     eax
  1988.         push    6
  1989.         pop     ebx
  1990.         mov     ecx, [debuggee_pid]
  1991.         xor     edx, edx
  1992.         push    edx
  1993.         inc     edx
  1994.         mov     edi, esp
  1995.         mcall
  1996.         dec     eax
  1997.         clc
  1998.         jz      @f
  1999.         stc
  2000. @@:     pop     eax
  2001.         ret
  2002.  
  2003. is_prefix:
  2004.         cmp     al, 0x64        ; fs:
  2005.         jz      .ret
  2006.         cmp     al, 0x65        ; gs:
  2007.         jz      .ret
  2008.         cmp     al, 0x66        ; use16/32
  2009.         jz      .ret
  2010.         cmp     al, 0x67        ; addr16/32
  2011.         jz      .ret
  2012.         cmp     al, 0xF0        ; lock
  2013.         jz      .ret
  2014.         cmp     al, 0xF2        ; repnz
  2015.         jz      .ret
  2016.         cmp     al, 0xF3        ; rep(z)
  2017.         jz      .ret
  2018.         cmp     al, 0x2E        ; cs:
  2019.         jz      .ret
  2020.         cmp     al, 0x36        ; ss:
  2021.         jz      .ret
  2022.         cmp     al, 0x3E        ; ds:
  2023.         jz      .ret
  2024.         cmp     al, 0x26        ; es:
  2025. .ret:   ret
  2026.  
  2027. token_end       equ     1
  2028. token_reg       equ     2
  2029. token_hex       equ     3
  2030. token_add       equ     4
  2031. token_sub       equ     5
  2032. token_mul       equ     6
  2033. token_div       equ     7
  2034. token_lp        equ     8
  2035. token_rp        equ     9
  2036. token_err       equ     -1
  2037.  
  2038. is_hex_digit:
  2039.         cmp     al, '0'
  2040.         jb      .no
  2041.         cmp     al, '9'
  2042.         jbe     .09
  2043.         cmp     al, 'A'
  2044.         jb      .no
  2045.         cmp     al, 'F'
  2046.         jbe     .AF
  2047.         cmp     al, 'a'
  2048.         jb      .no
  2049.         cmp     al, 'f'
  2050.         jbe     .af
  2051. .no:
  2052.         stc
  2053.         ret
  2054. .09:
  2055.         sub     al, '0'
  2056. ;       clc
  2057.         ret
  2058. .AF:
  2059.         sub     al, 'A'-10
  2060. ;       clc
  2061.         ret
  2062. .af:
  2063.         sub     al, 'a'-10
  2064. ;       clc
  2065.         ret
  2066.  
  2067. find_reg:
  2068.         mov     edi, reg_table
  2069. .findreg:
  2070.         movzx   ecx, byte [edi]
  2071.         stc
  2072.         jecxz   .regnotfound
  2073.         inc     edi
  2074.         push    esi edi ecx
  2075. @@:
  2076.         lodsb
  2077.         or      al, 20h
  2078.         scasb
  2079.         loopz   @b
  2080.         pop     ecx edi esi
  2081.         lea     edi, [edi+ecx+1]
  2082.         jnz     .findreg
  2083.         movzx   edi, byte [edi-1]
  2084.         add     esi, ecx
  2085. .regnotfound:
  2086.         ret
  2087.  
  2088. expr_get_token:
  2089.         lodsb
  2090.         cmp     al, 0
  2091.         jz      .end_token
  2092.         cmp     al, ' '
  2093.         jbe     expr_get_token
  2094.         cmp     al, '+'
  2095.         jz      .add
  2096.         cmp     al, '-'
  2097.         jz      .sub
  2098.         cmp     al, '*'
  2099.         jz      .mul
  2100.         cmp     al, '/'
  2101.         jz      .div
  2102.         cmp     al, '('
  2103.         jz      .lp
  2104.         cmp     al, ')'
  2105.         jnz     .notsign
  2106. .rp:
  2107.         mov     al, token_rp
  2108.         ret
  2109. .div:
  2110.         mov     al, token_div
  2111.         ret
  2112. .end_token:
  2113.         mov     al, token_end
  2114.         ret
  2115. .add:
  2116.         mov     al, token_add
  2117.         ret
  2118. .sub:
  2119.         mov     al, token_sub
  2120.         ret
  2121. .mul:
  2122.         mov     al, token_mul
  2123.         ret
  2124. .lp:
  2125.         mov     al, token_lp
  2126.         ret
  2127. .notsign:
  2128.         dec     esi
  2129.         call    find_reg
  2130.         jc      .regnotfound
  2131.         mov     al, token_reg
  2132.         ret
  2133. .regnotfound:
  2134. ; test for symbol
  2135.         push    esi
  2136. @@:
  2137.         lodsb
  2138.         cmp     al, ' '
  2139.         ja      @b
  2140.         push    eax
  2141.         mov     byte [esi], 0
  2142.         xchg    esi, [esp+4]
  2143.         call    find_symbol_name
  2144.         mov     edi, eax
  2145.         pop     eax
  2146.         xchg    esi, [esp]
  2147.         mov     byte [esi], al
  2148.         jc      @f
  2149.         add     esp, 4
  2150.         mov     al, token_hex
  2151.         ret
  2152. @@:
  2153.         pop     esi
  2154. ; test for hex number
  2155.         xor     ecx, ecx
  2156.         xor     edi, edi
  2157.         xor     eax, eax
  2158. @@:
  2159.         lodsb
  2160.         call    is_hex_digit
  2161.         jc      @f
  2162.         shl     edi, 4
  2163.         or      edi, eax
  2164.         inc     ecx
  2165.         jmp     @b
  2166. @@:
  2167.         dec     esi
  2168.         jecxz   .err
  2169.         cmp     ecx, 8
  2170.         ja      .err
  2171.         mov     al, token_hex
  2172.         ret
  2173. .err:
  2174.         mov     al, token_err
  2175.         mov     esi, aParseError
  2176.         ret
  2177.  
  2178. expr_read2:
  2179.         cmp     al, token_hex
  2180.         jz      .hex
  2181.         cmp     al, token_reg
  2182.         jz      .reg
  2183.         cmp     al, token_lp
  2184.         jz      .lp
  2185.         mov     al, token_err
  2186.         mov     esi, aParseError
  2187.         ret
  2188. .hex:
  2189.         mov     ebp, edi
  2190. .ret:
  2191.         jmp     expr_get_token
  2192. .reg:
  2193.         cmp     edi, 24
  2194.         jz      .eip
  2195.         sub     edi, 4
  2196.         jb      .8lo
  2197.         sub     edi, 4
  2198.         jb      .8hi
  2199.         sub     edi, 8
  2200.         jb      .16
  2201.         mov     ebp, [_eax+edi*4]
  2202.         jmp     .ret
  2203. .16:
  2204.         movzx   ebp, word [_eax+(edi+8)*4]
  2205.         jmp     .ret
  2206. .8lo:
  2207.         movzx   ebp, byte [_eax+(edi+4)*4]
  2208.         jmp     .ret
  2209. .8hi:
  2210.         movzx   ebp, byte [_eax+(edi+4)*4+1]
  2211.         jmp     .ret
  2212. .eip:
  2213.         mov     ebp, [_eip]
  2214.         jmp     .ret
  2215. .lp:
  2216.         call    expr_get_token
  2217.         call    expr_read0
  2218.         cmp     al, token_err
  2219.         jz      @f
  2220.         cmp     al, token_rp
  2221.         jz      expr_get_token
  2222.         mov     al, token_err
  2223.         mov     esi, aParseError
  2224. @@:     ret
  2225.  
  2226. expr_read1:
  2227.         call    expr_read2
  2228. .1:
  2229.         cmp     al, token_mul
  2230.         jz      .mul
  2231.         cmp     al, token_div
  2232.         jz      .div
  2233.         ret
  2234. .mul:
  2235.         push    ebp
  2236.         call    expr_get_token
  2237.         call    expr_read2
  2238.         pop     edx
  2239. ; ebp := edx*ebp
  2240.         imul    ebp, edx
  2241.         jmp     .1
  2242. .div:
  2243.         push    ebp
  2244.         call    expr_get_token
  2245.         call    expr_read2
  2246.         pop     edx
  2247. ; ebp := edx/ebp
  2248.         test    ebp, ebp
  2249.         jz      .div0
  2250.         push    eax
  2251.         xor     eax, eax
  2252.         xchg    eax, edx
  2253.         div     ebp
  2254.         xchg    eax, ebp
  2255.         pop     eax
  2256.         jmp     .1
  2257. .div0:
  2258.         mov     al, token_err
  2259.         mov     esi, aDivByZero
  2260.         ret
  2261.  
  2262. expr_read0:
  2263.         xor     ebp, ebp
  2264.         cmp     al, token_add
  2265.         jz      .add
  2266.         cmp     al, token_sub
  2267.         jz      .sub
  2268.         call    expr_read1
  2269. .1:
  2270.         cmp     al, token_add
  2271.         jz      .add
  2272.         cmp     al, token_sub
  2273.         jz      .sub
  2274.         ret
  2275. .add:
  2276.         push    ebp
  2277.         call    expr_get_token
  2278.         call    expr_read1
  2279.         pop     edx
  2280. ; ebp := edx+ebp
  2281.         add     ebp, edx
  2282.         jmp     .1
  2283. .sub:
  2284.         push    ebp
  2285.         call    expr_get_token
  2286.         call    expr_read1
  2287.         pop     edx
  2288. ; ebp := edx-ebp
  2289.         xchg    edx, ebp
  2290.         sub     ebp, edx
  2291.         jmp     .1
  2292.  
  2293. calc_expression:
  2294. ; in: esi->expression
  2295. ; out: CF=1 if error
  2296. ;      CF=0 and ebp=value if ok
  2297.         call    expr_get_token
  2298.         call    expr_read0
  2299.         cmp     al, token_end
  2300.         jz      .end
  2301.         cmp     al, token_err
  2302.         jz      @f
  2303.         mov     esi, aParseError
  2304. @@:
  2305.         call    put_message
  2306.         stc
  2307.         ret
  2308. .end:
  2309.         clc
  2310.         ret
  2311.  
  2312. OnCalc:
  2313.         mov     esi, [curarg]
  2314.         call    calc_expression
  2315.         jc      .ret
  2316.         push    ebp
  2317.         mov     esi, calc_string
  2318.         call    put_message_nodraw
  2319.         jmp     draw_messages
  2320. .ret:
  2321.         ret
  2322.  
  2323. OnDump:
  2324.         mov     esi, [curarg]
  2325.         cmp     byte [esi], 0
  2326.         jnz     .param
  2327.         add     [dumppos], dump_height*10h
  2328.         jmp     .doit
  2329. .param:
  2330.         call    calc_expression
  2331.         jc      .ret
  2332.         mov     [dumppos], ebp
  2333. .doit:
  2334.         call    get_dump
  2335.         call    redraw_dump
  2336. .ret:
  2337.         ret
  2338.  
  2339. OnUnassemble:
  2340.         mov     esi, [curarg]
  2341.         cmp     byte [esi], 0
  2342.         jnz     .param
  2343.         mov     eax, [disasm_start_pos]
  2344.         mov     ecx, disasm_height
  2345.         mov     [disasm_cur_pos], eax
  2346. .l:
  2347.         mov     eax, [disasm_cur_pos]
  2348.         call    find_symbol
  2349.         jc      @f
  2350.         dec     ecx
  2351.         jz      .m
  2352. @@:
  2353.         push    ecx
  2354.         call    disasm_instr
  2355.         pop     ecx
  2356.         jc      .err
  2357.         loop    .l
  2358. .m:
  2359.         mov     eax, [disasm_cur_pos]
  2360.         jmp     .doit
  2361. .param:
  2362.         call    calc_expression
  2363.         jc      .ret
  2364.         mov     eax, ebp
  2365. .doit:
  2366.         push    eax
  2367.         push    [disasm_start_pos]
  2368.         mov     [disasm_start_pos], eax
  2369.         call    update_disasm
  2370.         pop     [disasm_start_pos]
  2371.         pop     eax
  2372.         cmp     [disasm_cur_str], 0
  2373.         jz      @f
  2374.         mov     [disasm_start_pos], eax
  2375. .ret:
  2376.         ret
  2377. @@:
  2378.         call    update_disasm
  2379. .err:
  2380.         mov     esi, aInvAddr
  2381.         jmp     put_message
  2382.  
  2383. OnReg:
  2384.         mov     esi, [curarg]
  2385.         call    skip_spaces
  2386.         call    find_reg
  2387.         jnc     @f
  2388. .err:
  2389.         mov     esi, RSyntax
  2390.         jmp     put_message
  2391. @@:
  2392.         call    skip_spaces
  2393.         test    al, al
  2394.         jz      .err
  2395.         cmp     al, '='
  2396.         jnz     @f
  2397.         inc     esi
  2398.         call    skip_spaces
  2399.         test    al, al
  2400.         jz      .err
  2401. @@:
  2402.         push    edi
  2403.         call    calc_expression
  2404.         pop     edi
  2405.         jc      .ret
  2406. ; now edi=register id, ebp=value
  2407.         cmp     [bSuspended], 0
  2408.         mov     esi, aRunningErr
  2409.         jz      put_message
  2410.         xchg    eax, ebp
  2411.         cmp     edi, 24
  2412.         jz      .eip
  2413.         sub     edi, 4
  2414.         jb      .8lo
  2415.         sub     edi, 4
  2416.         jb      .8hi
  2417.         sub     edi, 8
  2418.         jb      .16
  2419.         mov     [_eax+edi*4], eax
  2420.         jmp     .ret
  2421. .16:
  2422.         mov     word [_eax+(edi+8)*4], ax
  2423.         jmp     .ret
  2424. .8lo:
  2425.         mov     byte [_eax+(edi+4)*4], al
  2426.         jmp     .ret
  2427. .8hi:
  2428.         mov     byte [_eax+(edi+4)*4+1], al
  2429.         jmp     .ret
  2430. .eip:
  2431.         mov     [_eip], eax
  2432.         call    update_disasm_eip
  2433. .ret:
  2434.         call    set_context
  2435.         jmp     redraw_registers
  2436.  
  2437. ; Breakpoints manipulation
  2438. OnBp:
  2439.         mov     esi, [curarg]
  2440.         call    calc_expression
  2441.         jc      .ret
  2442.         xchg    eax, ebp
  2443.         push    eax
  2444.         call    find_breakpoint
  2445.         inc     eax
  2446.         pop     eax
  2447.         jz      .notfound
  2448.         mov     esi, aDuplicateBreakpoint
  2449.         jmp     .sayerr
  2450. .notfound:
  2451.         mov     bl, 1
  2452.         call    add_breakpoint
  2453.         jnc     .ret
  2454.         mov     esi, aBreakpointLimitExceeded
  2455. .sayerr:
  2456.         call    put_message
  2457. .ret:
  2458.         jmp     redraw_disasm
  2459.  
  2460. OnBpmb:
  2461.         mov     dh, 0011b
  2462.         jmp     DoBpm
  2463. OnBpmw:
  2464.         mov     dh, 0111b
  2465.         jmp     DoBpm
  2466. OnBpmd:
  2467.         mov     dh, 1111b
  2468. DoBpm:
  2469.         mov     esi, [curarg]
  2470.         cmp     byte [esi], 'w'
  2471.         jnz     @f
  2472.         and     dh, not 2
  2473.         inc     esi
  2474. @@:
  2475.         push    edx
  2476.         call    calc_expression
  2477.         pop     edx
  2478.         jnc     @f
  2479.         ret
  2480. @@:
  2481. ; ebp=expression, dh=flags
  2482.         movzx   eax, dh
  2483.         shr     eax, 2
  2484.         test    ebp, eax
  2485.         jz      @f
  2486.         mov     esi, aUnaligned
  2487.         jmp     put_message
  2488. @@:
  2489.         mov     eax, ebp
  2490.         mov     bl, 0Bh
  2491.         call    add_breakpoint
  2492.         jnc     @f
  2493.         mov     esi, aBreakpointLimitExceeded
  2494.         jmp     put_message
  2495. @@:
  2496. ; now find index
  2497.         push    eax
  2498.         xor     ecx, ecx
  2499. .l1:
  2500.         cmp     [drx_break+ecx*4], 0
  2501.         jnz     .l2
  2502.         push    69
  2503.         pop     eax
  2504.         push    ecx
  2505.         mov     dl, cl
  2506.         mov     ecx, [debuggee_pid]
  2507.         mov     esi, ebp
  2508.         push    9
  2509.         pop     ebx
  2510.         mcall
  2511.         test    eax, eax
  2512.         jz      .ok
  2513.         pop     ecx
  2514. .l2:
  2515.         inc     ecx
  2516.         cmp     ecx, 4
  2517.         jb      .l1
  2518.         pop     eax
  2519.         call    clear_breakpoint
  2520.         mov     esi, aBreakpointLimitExceeded
  2521.         jmp     put_message
  2522. .ok:
  2523.         pop     ecx
  2524.         pop     eax
  2525.         and     byte [edi], not 2       ; breakpoint is enabled
  2526.         shl     dl, 6
  2527.         or      dl, dh
  2528.         mov     byte [edi+1], dl
  2529.         inc     eax
  2530.         mov     [drx_break+ecx*4], eax
  2531.         ret
  2532.  
  2533. OnBc:
  2534.         mov     esi, [curarg]
  2535. @@:     call    get_hex_number
  2536.         jc      OnBp.ret
  2537.         call    clear_breakpoint
  2538.         jmp     @b
  2539.  
  2540. OnBd:
  2541.         mov     esi, [curarg]
  2542. @@:     call    get_hex_number
  2543.         jc      OnBp.ret
  2544.         call    disable_breakpoint
  2545.         jmp     @b
  2546.  
  2547. OnBe:
  2548.         mov     esi, [curarg]
  2549. @@:     call    get_hex_number
  2550.         jc      OnBp.ret
  2551.         push    eax
  2552.         call    find_enabled_breakpoint
  2553.         pop     eax
  2554.         jz      .err
  2555.         call    enable_breakpoint
  2556.         jmp     @b
  2557. .err:
  2558.         mov     esi, OnBeErrMsg
  2559.         jmp     put_message
  2560.  
  2561. get_hex_number:
  2562.         call    skip_spaces
  2563.         xor     ecx, ecx
  2564.         xor     edx, edx
  2565. @@:
  2566.         lodsb
  2567.         call    is_hex_digit
  2568.         jc      .ret
  2569.         shl     edx, 4
  2570.         or      dl, al
  2571.         inc     ecx
  2572.         jmp     @b
  2573. .ret:
  2574.         dec     esi
  2575.         cmp     ecx, 1
  2576.         xchg    eax, edx
  2577.         ret
  2578.  
  2579. OnBl:
  2580.         mov     esi, [curarg]
  2581.         cmp     byte [esi], 0
  2582.         jz      .listall
  2583.         call    get_hex_number
  2584.         jc      .ret
  2585.         cmp     eax, breakpoints_n
  2586.         jae     .err
  2587.         push    eax
  2588.         add     eax, eax
  2589.         lea     edi, [breakpoints + eax + eax*2]
  2590.         pop     eax
  2591.         test    byte [edi+4], 1
  2592.         jz      .err
  2593.         call    show_break_info
  2594. .ret:
  2595.         ret
  2596. .err:
  2597.         mov     esi, aInvalidBreak
  2598.         jmp     put_message
  2599. .listall:
  2600.         mov     edi, breakpoints
  2601.         xor     eax, eax
  2602. @@:
  2603.         test    byte [edi+4], 1
  2604.         jz      .cont
  2605.         push    edi eax
  2606.         call    show_break_info
  2607.         pop     eax edi
  2608. .cont:
  2609.         add     edi, 6
  2610.         inc     eax
  2611.         cmp     eax, breakpoints_n
  2612.         jb      @b
  2613.         ret
  2614.  
  2615. show_break_info:
  2616.         push    edi
  2617.         test    byte [edi+4], 8
  2618.         jnz     .dr
  2619.         push    dword [edi]
  2620.         push    eax
  2621.         mov     esi, aBreakNum
  2622.         call    put_message_nodraw
  2623.         jmp     .cmn
  2624. .dr:
  2625.         push    eax
  2626.         mov     esi, aMemBreak1
  2627.         call    put_message_nodraw
  2628.         pop     edi
  2629.         push    edi
  2630.         mov     esi, aMemBreak2
  2631.         test    byte [edi+5], 2
  2632.         jz      @f
  2633.         mov     esi, aMemBreak3
  2634. @@:
  2635.         call    put_message_nodraw
  2636.         pop     edi
  2637.         push    edi
  2638.         mov     esi, aMemBreak6
  2639.         test    byte [edi+5], 8
  2640.         jnz     @f
  2641.         mov     esi, aMemBreak5
  2642.         test    byte [edi+5], 4
  2643.         jnz     @f
  2644.         mov     esi, aMemBreak4
  2645. @@:
  2646.         call    put_message_nodraw
  2647.         pop     edi
  2648.         push    edi
  2649.         push    dword [edi]
  2650.         mov     esi, aMemBreak7
  2651.         call    put_message_nodraw
  2652. .cmn:
  2653.         pop     edi
  2654.         test    byte [edi+4], 2
  2655.         jz      @f
  2656.         push    edi
  2657.         mov     esi, aDisabled
  2658.         call    put_message_nodraw
  2659.         pop     edi
  2660. @@:
  2661.         test    byte [edi+4], 4
  2662.         jz      @f
  2663.         mov     esi, aOneShot
  2664.         call    put_message_nodraw
  2665. @@:
  2666.         mov     esi, newline
  2667.         jmp     put_message
  2668.  
  2669. add_breakpoint:
  2670. ; in: eax=address, bl=flags
  2671. ; out: CF=1 => error, CF=0 => eax=breakpoint number
  2672.         xor     ecx, ecx
  2673.         mov     edi, breakpoints
  2674. @@:
  2675.         test    byte [edi+4], 1
  2676.         jz      .found
  2677.         add     edi, 6
  2678.         inc     ecx
  2679.         cmp     ecx, breakpoints_n
  2680.         jb      @b
  2681.         stc
  2682.         ret
  2683. .found:
  2684.         stosd
  2685.         xchg    eax, ecx
  2686.         mov     [edi], bl
  2687.         test    bl, 2
  2688.         jnz     @f
  2689.         or      byte [edi], 2
  2690.         push    eax
  2691.         call    enable_breakpoint
  2692.         pop     eax
  2693. @@:
  2694.         clc
  2695.         ret
  2696.  
  2697. clear_breakpoint:
  2698.         cmp     eax, breakpoints_n
  2699.         jae     .ret
  2700.         mov     ecx, 4
  2701.         inc     eax
  2702. .1:
  2703.         cmp     [drx_break-4+ecx*4], eax
  2704.         jnz     @f
  2705.         and     [drx_break-4+ecx*4], 0
  2706. @@:     loop    .1
  2707.         dec     eax
  2708.         push    eax
  2709.         add     eax, eax
  2710.         lea     edi, [breakpoints + eax + eax*2 + 4]
  2711.         test    byte [edi], 1
  2712.         pop     eax
  2713.         jz      .ret
  2714.         push    edi
  2715.         call    disable_breakpoint
  2716.         pop     edi
  2717.         mov     byte [edi], 0
  2718. .ret:
  2719.         ret
  2720.  
  2721. disable_breakpoint:
  2722.         cmp     eax, breakpoints_n
  2723.         jae     .ret
  2724.         add     eax, eax
  2725.         lea     edi, [breakpoints + eax + eax*2 + 5]
  2726.         test    byte [edi-1], 1
  2727.         jz      .ret
  2728.         test    byte [edi-1], 2
  2729.         jnz     .ret
  2730.         or      byte [edi-1], 2
  2731.         test    byte [edi-1], 8
  2732.         jnz     .dr
  2733.         push    esi
  2734.         push    7
  2735.         pop     ebx
  2736.         push    69
  2737.         pop     eax
  2738.         mov     ecx, [debuggee_pid]
  2739.         xor     edx, edx
  2740.         inc     edx
  2741.         mov     esi, [edi-5]
  2742.         mcall
  2743.         pop     esi
  2744. .ret:
  2745.         ret
  2746. .dr:
  2747.         mov     dl, [edi]
  2748.         shr     dl, 6
  2749.         mov     dh, 80h
  2750.         push    69
  2751.         pop     eax
  2752.         push    9
  2753.         pop     ebx
  2754.         mov     ecx, [debuggee_pid]
  2755.         mcall
  2756.         ret
  2757.  
  2758. enable_breakpoint:
  2759.         push    esi
  2760.         cmp     eax, breakpoints_n
  2761.         jae     .ret
  2762.         add     eax, eax
  2763.         lea     edi, [breakpoints + eax + eax*2 + 5]
  2764.         test    byte [edi-1], 1
  2765.         jz      .ret
  2766.         test    byte [edi-1], 2
  2767.         jz      .ret
  2768.         and     byte [edi-1], not 2
  2769.         test    byte [edi-1], 8
  2770.         jnz     .dr
  2771.         push    6
  2772.         pop     ebx
  2773.         push    69
  2774.         pop     eax
  2775.         mov     esi, [edi-5]
  2776.         mov     ecx, [debuggee_pid]
  2777.         xor     edx, edx
  2778.         inc     edx
  2779.         mcall
  2780.         dec     eax
  2781.         jnz     .err
  2782.         mov     al, 69
  2783.         push    0xCC
  2784.         mov     edi, esp
  2785.         inc     ebx
  2786.         mcall
  2787.         pop     eax
  2788. .ret:
  2789.         pop     esi
  2790.         ret
  2791. .err:
  2792.         or      byte [edi-1], 2
  2793.         mov     esi, aBreakErr
  2794.         call    put_message
  2795.         pop     esi
  2796.         ret
  2797. .dr:
  2798.         push    9
  2799.         pop     ebx
  2800.         push    69
  2801.         pop     eax
  2802.         mov     esi, [edi-5]
  2803.         mov     ecx, [debuggee_pid]
  2804.         mov     dl, [edi]
  2805.         shr     dl, 6
  2806.         mov     dh, [edi]
  2807.         and     dh, 0xF
  2808.         mcall
  2809.         test    eax, eax
  2810.         jnz     .err
  2811.         pop     esi
  2812.         ret
  2813.  
  2814. find_breakpoint:
  2815.         xor     ecx, ecx
  2816.         xchg    eax, ecx
  2817.         mov     edi, breakpoints
  2818. @@:
  2819.         test    byte [edi+4], 1
  2820.         jz      .cont
  2821.         test    byte [edi+4], 8
  2822.         jnz     .cont
  2823.         cmp     [edi], ecx
  2824.         jz      .found
  2825. .cont:
  2826.         add     edi, 6
  2827.         inc     eax
  2828.         cmp     eax, breakpoints_n
  2829.         jb      @b
  2830.         or      eax, -1
  2831. .found:
  2832.         ret
  2833.  
  2834. find_enabled_breakpoint:
  2835.         xor     ecx, ecx
  2836.         xchg    eax, ecx
  2837.         mov     edi, breakpoints
  2838. @@:
  2839.         test    byte [edi+4], 1
  2840.         jz      .cont
  2841.         test    byte [edi+4], 2 or 8
  2842.         jnz     .cont
  2843.         cmp     [edi], ecx
  2844.         jz      .found
  2845. .cont:
  2846.         add     edi, 6
  2847.         inc     eax
  2848.         cmp     eax, breakpoints_n
  2849.         jb      @b
  2850.         or      eax, -1
  2851. .found:
  2852.         ret
  2853.  
  2854. OnUnpack:
  2855. ; program must be loaded - checked when command was parsed
  2856. ; program must be stopped
  2857.         mov     esi, aRunningErr
  2858.         cmp     [bSuspended], 0
  2859.         jz      put_message
  2860. ; all breakpoints must be disabled
  2861.         mov     edi, breakpoints
  2862. @@:
  2863.         test    byte [edi+4], 1
  2864.         jz      .cont
  2865.         test    byte [edi+4], 2
  2866.         jnz     .cont
  2867.         mov     esi, aEnabledBreakErr
  2868.         jmp     put_message
  2869. .cont:
  2870.         add     edi, 6
  2871.         cmp     edi, breakpoints+breakpoints_n*6
  2872.         jb      @b
  2873. ; ok, now do it
  2874. ; set breakpoint on 0xC dword access
  2875.         push    9
  2876.         pop     ebx
  2877.         mov     ecx, [debuggee_pid]
  2878.         mov     dx, 1111b*256
  2879.         push    0xC
  2880.         pop     esi
  2881. @@:
  2882.         push    69
  2883.         pop     eax
  2884.         mcall
  2885.         test    eax, eax
  2886.         jz      .breakok
  2887.         inc     edx
  2888.         cmp     dl, 4
  2889.         jb      @b
  2890. .breakok:
  2891.         call    GoOn
  2892. ; now wait for event
  2893. .wait:
  2894.         push    10
  2895.         pop     eax
  2896.         mcall
  2897.         dec     eax
  2898.         jz      .redraw
  2899.         dec     eax
  2900.         jz      .key
  2901.         dec     eax
  2902.         jnz     .debug
  2903. ; button; we have only one button, close
  2904.         or      eax, -1
  2905.         mcall
  2906. .redraw:
  2907.         call    draw_window
  2908.         jmp     .wait
  2909. .key:
  2910.         mov     al, 2
  2911.         mcall
  2912.         cmp     ah, 3   ; Ctrl+C
  2913.         jnz     .wait
  2914. .userbreak:
  2915.         mov     esi, aInterrupted
  2916. .x1:
  2917.         push    edx esi
  2918.         call    put_message
  2919.         pop     esi edx
  2920.         or      dh, 80h
  2921.         push    69
  2922.         pop     eax
  2923.         push    9
  2924.         pop     ebx
  2925.         mov     ecx, [debuggee_pid]
  2926.         mcall
  2927.         cmp     esi, aUnpacked
  2928.         jnz     OnSuspend
  2929.         jmp     AfterSuspend
  2930. .debug:
  2931.         cmp     [dbgbuflen], 4*3
  2932.         jnz     .notour
  2933.         cmp     dword [dbgbuf], 3
  2934.         jnz     .notour
  2935.         test    byte [dbgbuf+8], 1
  2936.         jnz     .our
  2937. .notour:
  2938.         mov     esi, aInterrupted
  2939.         push    edx
  2940.         call    put_message
  2941.         pop     edx
  2942.         or      dh, 80h
  2943.         push    69
  2944.         pop     eax
  2945.         push    9
  2946.         pop     ebx
  2947.         mov     ecx, [debuggee_pid]
  2948.         mcall
  2949.         jmp     debugmsg
  2950. .our:
  2951.         and     [dbgbuflen], 0
  2952.         push    edx
  2953.         call    get_context
  2954.         push    eax
  2955.         mov     al, 69
  2956.         mov     bl, 6
  2957.         mov     ecx, [debuggee_pid]
  2958.         mov     edi, esp
  2959.         push    4
  2960.         pop     edx
  2961.         push    0xC
  2962.         pop     esi
  2963.         mcall
  2964.         pop     eax
  2965.         pop     edx
  2966.         cmp     eax, [_eip]
  2967.         jz      .done
  2968.         call    DoResume
  2969.         jmp     .wait
  2970. .done:
  2971.         mov     esi, aUnpacked
  2972.         jmp     .x1
  2973.  
  2974. include 'sort.inc'
  2975. compare:
  2976.         cmpsd
  2977.         jnz     @f
  2978.         cmp     esi, edi
  2979. @@:     ret
  2980. compare2:
  2981.         cmpsd
  2982. @@:
  2983.         cmpsb
  2984.         jnz     @f
  2985.         cmp     byte [esi-1], 0
  2986.         jnz     @b
  2987.         cmp     esi, edi
  2988. @@:
  2989.         ret
  2990.  
  2991. free_symbols:
  2992.         mov     ecx, [symbols]
  2993.         jecxz   @f
  2994.         mcall   68, 13
  2995.         and     [symbols], 0
  2996.         and     [num_symbols], 0
  2997. @@:
  2998.         ret
  2999.  
  3000. OnLoadSymbols.fileerr:
  3001.         test    ebp, ebp
  3002.         jz      @f
  3003.         mcall   68, 13, edi
  3004.         ret
  3005. @@:
  3006.         push    eax
  3007.         mcall   68, 13, edi
  3008.         mov     esi, aCannotLoadFile
  3009.         call    put_message_nodraw
  3010.         pop     eax
  3011.         cmp     eax, 0x20
  3012.         jae     .unk
  3013.         mov     esi, [load_err_msgs + eax*4]
  3014.         test    esi, esi
  3015.         jnz     put_message
  3016. .unk:
  3017.         mov     esi, unk_err_msg2
  3018.         jmp     put_message
  3019.  
  3020. OnLoadSymbols:
  3021.         xor     ebp, ebp
  3022. ; load input file
  3023.         mov     esi, [curarg]
  3024.         call    free_symbols
  3025. .silent:
  3026.         xor     edi, edi
  3027.         cmp     [num_symbols], edi
  3028.         jz      @f
  3029.         ret
  3030. @@:
  3031.         mov     ebx, fn70_attr_block
  3032.         mov     [ebx+21], esi
  3033.         mcall   70
  3034.         test    eax, eax
  3035.         jnz     .fileerr
  3036.         cmp     dword [fileattr+36], edi
  3037.         jnz     .memerr
  3038.         mov     ecx, dword [fileattr+32]
  3039.         mcall   68, 12
  3040.         test    eax, eax
  3041.         jz      .memerr
  3042.         mov     edi, eax
  3043.         mov     ebx, fn70_read_block
  3044.         mov     [ebx+12], ecx
  3045.         mov     [ebx+16], edi
  3046.         mov     [ebx+21], esi
  3047.         mcall   70
  3048.         test    eax, eax
  3049.         jnz     .fileerr
  3050. ; calculate memory requirements
  3051.         lea     edx, [ecx+edi-1]        ; edx = EOF-1
  3052.         mov     esi, edi
  3053.         xor     ecx, ecx
  3054. .calcloop:
  3055.         cmp     esi, edx
  3056.         jae     .calcdone
  3057.         cmp     word [esi], '0x'
  3058.         jnz     .skipline
  3059.         inc     esi
  3060.         inc     esi
  3061. @@:
  3062.         cmp     esi, edx
  3063.         jae     .calcdone
  3064.         lodsb
  3065.         or      al, 20h
  3066.         sub     al, '0'
  3067.         cmp     al, 9
  3068.         jbe     @b
  3069.         sub     al, 'a'-'0'-10
  3070.         cmp     al, 15
  3071.         jbe     @b
  3072.         dec     esi
  3073. @@:
  3074.         cmp     esi, edx
  3075.         ja      .calcdone
  3076.         lodsb
  3077.         cmp     al, 20h
  3078.         jz      @b
  3079.         jb      .calcloop
  3080.         cmp     al, 9
  3081.         jz      @b
  3082.         add     ecx, 12+1
  3083.         inc     [num_symbols]
  3084. @@:
  3085.         inc     ecx
  3086.         cmp     esi, edx
  3087.         ja      .calcdone
  3088.         lodsb
  3089.         cmp     al, 0xD
  3090.         jz      .calcloop
  3091.         cmp     al, 0xA
  3092.         jz      .calcloop
  3093.         jmp     @b
  3094. .skipline:
  3095.         cmp     esi, edx
  3096.         jae     .calcdone
  3097.         lodsb
  3098.         cmp     al, 0xD
  3099.         jz      .calcloop
  3100.         cmp     al, 0xA
  3101.         jz      .calcloop
  3102.         jmp     .skipline
  3103. .calcdone:
  3104.         mcall   68, 12
  3105.         test    eax, eax
  3106.         jnz     .memok
  3107.         inc     ebx
  3108.         mov     ecx, edi
  3109.         mov     al, 68
  3110.         mcall
  3111. .memerr:
  3112.         mov     esi, aNoMemory
  3113.         jmp     put_message
  3114. .memok:
  3115.         mov     [symbols], eax
  3116.         mov     ebx, eax
  3117.         push    edi
  3118.         mov     esi, edi
  3119.         mov     edi, [num_symbols]
  3120.         lea     ebp, [eax+edi*4]
  3121.         lea     edi, [eax+edi*8]
  3122. ; parse input data, esi->input, edx->EOF, ebx->ptrs, edi->names
  3123. .readloop:
  3124.         cmp     esi, edx
  3125.         jae     .readdone
  3126.         cmp     word [esi], '0x'
  3127.         jnz     .readline
  3128.         inc     esi
  3129.         inc     esi
  3130.         xor     eax, eax
  3131.         xor     ecx, ecx
  3132. @@:
  3133.         shl     ecx, 4
  3134.         add     ecx, eax
  3135.         cmp     esi, edx
  3136.         jae     .readdone
  3137.         lodsb
  3138.         or      al, 20h
  3139.         sub     al, '0'
  3140.         cmp     al, 9
  3141.         jbe     @b
  3142.         sub     al, 'a'-'0'-10
  3143.         cmp     al, 15
  3144.         jbe     @b
  3145.         dec     esi
  3146. @@:
  3147.         cmp     esi, edx
  3148.         ja      .readdone
  3149.         lodsb
  3150.         cmp     al, 20h
  3151.         jz      @b
  3152.         jb      .readloop
  3153.         cmp     al, 9
  3154.         jz      @b
  3155.         mov     dword [ebx], edi
  3156.         add     ebx, 4
  3157.         mov     dword [ebp], edi
  3158.         add     ebp, 4
  3159.         mov     dword [edi], ecx
  3160.         add     edi, 4
  3161.         stosb
  3162. @@:
  3163.         xor     eax, eax
  3164.         stosb
  3165.         cmp     esi, edx
  3166.         ja      .readdone
  3167.         lodsb
  3168.         cmp     al, 0xD
  3169.         jz      .readloop
  3170.         cmp     al, 0xA
  3171.         jz      .readloop
  3172.         mov     byte [edi-1], al
  3173.         jmp     @b
  3174. .readline:
  3175.         cmp     esi, edx
  3176.         jae     .readdone
  3177.         lodsb
  3178.         cmp     al, 0xD
  3179.         jz      .readloop
  3180.         cmp     al, 0xA
  3181.         jz      .readloop
  3182.         jmp     .readline
  3183. .readdone:
  3184.         pop     ecx
  3185.         mcall   68, 13
  3186.         mov     ecx, [num_symbols]
  3187.         mov     edx, [symbols]
  3188.         mov     ebx, compare
  3189.         call    sort
  3190.         mov     ecx, [num_symbols]
  3191.         lea     edx, [edx+ecx*4]
  3192.         mov     ebx, compare2
  3193.         call    sort
  3194.         mov     esi, aSymbolsLoaded
  3195.         call    put_message
  3196.         jmp     redraw_disasm
  3197.  
  3198. find_symbol:
  3199. ; in: eax=address
  3200. ; out: esi, CF
  3201.         cmp     [num_symbols], 0
  3202.         jnz     @f
  3203. .ret0:
  3204.         xor     esi, esi
  3205.         stc
  3206.         ret
  3207. @@:
  3208.         push    ebx ecx edx
  3209.         xor     edx, edx
  3210.         mov     esi, [symbols]
  3211.         mov     ecx, [num_symbols]
  3212.         mov     ebx, [esi]
  3213.         cmp     [ebx], eax
  3214.         jz      .donez
  3215.         jb      @f
  3216.         pop     edx ecx ebx
  3217.         jmp     .ret0
  3218. @@:
  3219. ; invariant: symbols_addr[edx] < eax < symbols_addr[ecx]
  3220. .0:
  3221.         push    edx
  3222. .1:
  3223.         add     edx, ecx
  3224.         sar     edx, 1
  3225.         cmp     edx, [esp]
  3226.         jz      .done2
  3227.         mov     ebx, [esi+edx*4]
  3228.         cmp     [ebx], eax
  3229.         jz      .done
  3230.         ja      .2
  3231.         mov     [esp], edx
  3232.         jmp     .1
  3233. .2:
  3234.         mov     ecx, edx
  3235.         pop     edx
  3236.         jmp     .0
  3237. .donecont:
  3238.         dec     edx
  3239. .done:
  3240.         test    edx, edx
  3241.         jz      @f
  3242.         mov     ebx, [esi+edx*4-4]
  3243.         cmp     [ebx], eax
  3244.         jz      .donecont
  3245. @@:
  3246.         pop     ecx
  3247. .donez:
  3248.         mov     esi, [esi+edx*4]
  3249.         add     esi, 4
  3250.         pop     edx ecx ebx
  3251.         clc
  3252.         ret
  3253. .done2:
  3254.         lea     esi, [esi+edx*4]
  3255.         pop     ecx edx ecx ebx
  3256.         stc
  3257.         ret
  3258.  
  3259. find_symbol_name:
  3260. ; in: esi->name
  3261. ; out: if found: CF clear, eax=value
  3262. ;      otherwise CF set
  3263.         cmp     [num_symbols], 0
  3264.         jnz     @f
  3265. .stc_ret:
  3266.         stc
  3267.         ret
  3268. @@:
  3269.         push    ebx ecx edx edi
  3270.         push    -1
  3271.         pop     edx
  3272.         mov     ebx, [symbols]
  3273.         mov     ecx, [num_symbols]
  3274.         lea     ebx, [ebx+ecx*4]
  3275. ; invariant: symbols_name[edx] < name < symbols_name[ecx]
  3276. .0:
  3277.         push    edx
  3278. .1:
  3279.         add     edx, ecx
  3280.         sar     edx, 1
  3281.         cmp     edx, [esp]
  3282.         jz      .done2
  3283.         call    .cmp
  3284.         jz      .done
  3285.         jb      .2
  3286.         mov     [esp], edx
  3287.         jmp     .1
  3288. .2:
  3289.         mov     ecx, edx
  3290.         pop     edx
  3291.         jmp     .0
  3292. .done:
  3293.         pop     ecx
  3294. .donez:
  3295.         mov     eax, [ebx+edx*4]
  3296.         mov     eax, [eax]
  3297.         pop     edi edx ecx ebx
  3298.         clc
  3299.         ret
  3300. .done2:
  3301.         pop     edx edi edx ecx ebx
  3302.         stc
  3303.         ret
  3304.  
  3305. .cmp:
  3306.         mov     edi, [ebx+edx*4]
  3307.         push    esi
  3308.         add     edi, 4
  3309. @@:
  3310.         cmpsb
  3311.         jnz     @f
  3312.         cmp     byte [esi-1], 0
  3313.         jnz     @b
  3314. @@:
  3315.         pop     esi
  3316.         ret
  3317.  
  3318. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3319. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DISASSEMBLER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3320. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3321.  
  3322. disasm_get_byte:
  3323. ; out: al=byte
  3324.         push    ecx
  3325.         mov     ecx, [disasm_cur_pos]
  3326.         sub     ecx, [disasm_start_pos]
  3327.         cmp     ecx, [disasm_buf_size]
  3328.         jae     disasm_err
  3329.         mov     al, [disasm_buffer+ecx]
  3330.         pop     ecx
  3331.         inc     [disasm_cur_pos]
  3332.         ret
  3333. disasm_get_word:
  3334.         push    ecx
  3335.         mov     ecx, [disasm_cur_pos]
  3336.         sub     ecx, [disasm_start_pos]
  3337.         inc     ecx
  3338.         cmp     ecx, [disasm_buf_size]
  3339.         jae     disasm_err
  3340.         mov     ax, word [disasm_buffer-1+ecx]
  3341.         pop     ecx
  3342.         add     [disasm_cur_pos], 2
  3343.         ret
  3344. disasm_get_dword:
  3345.         push    ecx
  3346.         mov     ecx, [disasm_cur_pos]
  3347.         sub     ecx, [disasm_start_pos]
  3348.         add     ecx, 3
  3349.         cmp     ecx, [disasm_buf_size]
  3350.         jae     disasm_err
  3351.         mov     eax, dword [disasm_buffer-3+ecx]
  3352.         pop     ecx
  3353.         add     [disasm_cur_pos], 4
  3354.         ret
  3355.  
  3356. disasm_err:
  3357.         mov     esp, ebp
  3358. stc_ret:
  3359.         stc
  3360.         ret
  3361. disasm_ret:
  3362.         mov     esp, ebp
  3363.         and     byte [edi], 0
  3364.         ret
  3365.  
  3366. disasm_instr:
  3367.         mov     ebp, esp
  3368.         cmp     [debuggee_pid], 0
  3369.         jz      stc_ret
  3370.         mov     edi, disasm_string
  3371.         xor     ecx, ecx
  3372. ; ecx=flags
  3373. disasm_loop1:
  3374.         xor     eax, eax
  3375.         call    disasm_get_byte
  3376.         jmp     dword [disasm_table_1 + eax*4]
  3377.  
  3378. cop0:
  3379. clock:
  3380. csegcs:
  3381. csegds:
  3382. cseges:
  3383. csegss:
  3384. csegfs:
  3385. cseggs:
  3386.         mov     esi, cmd1
  3387. iglobal
  3388. cmd1:
  3389.         db      0x2E,3,'cs:'
  3390.         db      0x36,3,'ss:'
  3391.         db      0x3E,3,'ds:'
  3392.         db      0x26,3,'es:'
  3393.         db      0x64,3,'fs:'
  3394.         db      0x65,3,'gs:'
  3395.         db      0x06,10,'push    es'
  3396.         db      0x07,10,'pop     es'
  3397.         db      0x0E,10,'push    cs'
  3398.         db      0x16,10,'push    ss'
  3399.         db      0x17,10,'pop     ss'
  3400.         db      0x1E,10,'push    ds'
  3401.         db      0x1F,10,'pop     ds'
  3402.         db      0x27,3,'daa'
  3403.         db      0x2F,3,'das'
  3404.         db      0x37,3,'aaa'
  3405.         db      0x3F,3,'aas'
  3406.         db      0x60,6,0,'pusha'
  3407.         db      0x61,5,0,'popa'
  3408.         db      0x90,3,'nop'
  3409.         db      0x9B,5,'fwait'
  3410.         db      0x9C,6,0,'pushf'
  3411.         db      0x9D,5,0,'popf'
  3412.         db      0x9E,4,'sahf'
  3413.         db      0x9F,4,'lahf'
  3414.         db      0xA4,5,'movsb'
  3415.         db      0xA5,5,0,'movs'
  3416.         db      0xA6,5,'cmpsb'
  3417.         db      0xA7,5,0,'cmps'
  3418.         db      0xAA,5,'stosb'
  3419.         db      0xAB,5,0,'stos'
  3420.         db      0xAC,5,'lodsb'
  3421.         db      0xAD,5,0,'lods'
  3422.         db      0xAE,5,'scasb'
  3423.         db      0xAF,5,0,'scas'
  3424.         db      0xC3,3,'ret'
  3425.         db      0xC9,5,'leave'
  3426.         db      0xCC,4,'int3'
  3427.         db      0xF0,4,'lock'
  3428.         db      0xF5,3,'cmc'
  3429.         db      0xF8,3,'clc'
  3430.         db      0xF9,3,'stc'
  3431.         db      0xFA,3,'cli'
  3432.         db      0xFB,3,'sti'
  3433.         db      0xFC,3,'cld'
  3434.         db      0xFD,3,'std'
  3435. cmd2:
  3436.         db      0x05,7,'syscall'
  3437.         db      0x06,4,'clts'
  3438.         db      0x31,5,'rdtsc'
  3439.         db      0x34,8,'sysenter'
  3440.         db      0xA2,5,'cpuid'
  3441.         db      0x77,4,'emms'
  3442. endg
  3443.         jmp     @f
  3444. ccpuid:
  3445. crdtsc:
  3446. cemms:
  3447. cop0_F:
  3448.         mov     esi, cmd2
  3449. @@:
  3450.         cmp     al, [esi]
  3451.         jz      .found
  3452.         inc     esi
  3453.         movzx   edx, byte [esi]
  3454.         inc     esi
  3455.         add     esi, edx
  3456.         jmp     @b
  3457. .found:
  3458.         inc     esi
  3459.         lodsb
  3460.         cmp     byte [esi], 0
  3461.         jz      @f
  3462.         movzx   ecx, al
  3463. disasm_1:
  3464.         rep     movsb
  3465.         and     byte [edi], 0
  3466.         ret
  3467. @@:
  3468.         mov     dl, ch
  3469.         movzx   ecx, al
  3470.         dec     ecx
  3471.         inc     esi
  3472.         rep     movsb
  3473.         test    dl, 1
  3474.         mov     al, 'w'
  3475.         jnz     @f
  3476.         mov     al, 'd'
  3477. @@:     stosb
  3478.         and     byte [edi], 0
  3479.         ret
  3480.  
  3481. c67:
  3482.         or      ch, 2
  3483.         jmp     disasm_loop1
  3484. c66:
  3485.         or      ch, 1
  3486.         jmp     disasm_loop1
  3487.  
  3488. cxlat:
  3489. cunk:
  3490. cerr:
  3491.         mov     eax, '???'
  3492.         stosd
  3493.         clc
  3494.         ret
  3495.  
  3496. cF:
  3497.         call    disasm_get_byte
  3498.         jmp     dword [disasm_table_2 + eax*4]
  3499.  
  3500. crep:
  3501.         push    [disasm_cur_pos]
  3502.         call    disasm_get_byte
  3503.         cmp     al, 0x0F
  3504.         jz      .sse
  3505.         mov     dl, al
  3506.         mov     eax, 'rep '
  3507.         stosd
  3508.         mov     al, dl
  3509. @@:
  3510.         and     eax, not 1
  3511.         cmp     al, 0x66
  3512.         jnz     @f
  3513.         call    disasm_get_byte
  3514.         mov     dl, al
  3515.         jmp     @b
  3516. @@:
  3517.         cmp     al, 0xA6
  3518.         jz      .repz
  3519.         cmp     al, 0xAE
  3520.         jz      .repz
  3521.         cmp     al, 0xA4
  3522.         jz      .prefix
  3523.         cmp     al, 0xAA
  3524.         jz      .prefix
  3525.         cmp     al, 0xAC
  3526.         jz      .prefix
  3527.         cmp     al, 0x6C
  3528.         jz      .prefix
  3529.         cmp     al, 0x6E
  3530.         jz      .prefix
  3531. .noprefix:
  3532.         pop     [disasm_cur_pos]
  3533.         and     byte [edi-1], 0
  3534.         ret
  3535. .repz:
  3536.         mov     byte [edi-1], 'z'
  3537.         mov     al, ' '
  3538.         stosb
  3539. .prefix:
  3540.         pop     [disasm_cur_pos]
  3541.         jmp     disasm_loop1
  3542. .sse:
  3543.         pop     eax
  3544.         call    disasm_get_byte
  3545. iglobal
  3546. rep_sse_cmds:
  3547.         db      0x58,3,'add'
  3548.         db      0xC2,3,'cmp'
  3549.         db      0,0
  3550. endg
  3551.         mov     esi, rep_sse_cmds+1
  3552. @@:
  3553.         movzx   edx, byte [esi]
  3554.         cmp     al, [esi-1]
  3555.         jz      @f
  3556.         lea     esi, [esi+edx+2]
  3557.         cmp     byte [esi], 0
  3558.         jnz     @b
  3559.         sub     [disasm_cur_pos], 2
  3560.         mov     eax, 'rep'
  3561.         stosd
  3562.         ret
  3563. @@:
  3564.         push    ecx
  3565.         mov     ecx, edx
  3566.         inc     esi
  3567.         rep     movsb
  3568.         pop     ecx
  3569.         mov     al, 's'
  3570.         stosb
  3571.         jmp     rep_sse_final
  3572.  
  3573. crepnz:
  3574.         call    disasm_get_byte
  3575.         cmp     al, 0x0F
  3576.         jz      .sse
  3577.         mov     dl, al
  3578.         mov     eax, 'repn'
  3579.         stosd
  3580.         mov     al, 'z'
  3581.         stosb
  3582.         mov     al, ' '
  3583.         stosb
  3584.         movzx   eax, dl
  3585.         cmp     al, 0x6C
  3586.         jb      crep.noprefix
  3587.         cmp     al, 0x6F
  3588.         jbe     .prefix
  3589.         cmp     al, 0xA4
  3590.         jb      crep.noprefix
  3591.         cmp     al, 0xA7
  3592.         jbe     .prefix
  3593.         cmp     al, 0xAA
  3594.         jb      crep.noprefix
  3595.         cmp     al, 0xAF
  3596.         ja      crep.noprefix
  3597. .prefix:
  3598.         jmp     cop0
  3599. .sse:
  3600.         call    disasm_get_byte
  3601.         mov     esi, rep_sse_cmds+1
  3602. @@:
  3603.         movzx   edx, byte [esi]
  3604.         cmp     al, [esi-1]
  3605.         jz      .found0
  3606.         lea     esi, [esi+edx+2]
  3607.         cmp     byte [esi], 0
  3608.         jnz     @b
  3609.         mov     esi, sse_cmds2+1
  3610. @@:
  3611.         movzx   edx, byte [esi]
  3612.         cmp     al, [esi-1]
  3613.         jz      .found1
  3614.         lea     esi, [esi+edx+2]
  3615.         cmp     byte [esi], 0
  3616.         jnz     @b
  3617.         sub     [disasm_cur_pos], 2
  3618.         mov     eax, 'repn'
  3619.         stosd
  3620.         mov     al, 'z'
  3621.         stosb
  3622.         and     byte [edi], 0
  3623.         ret
  3624. .found0:
  3625.         push    ecx
  3626.         mov     ecx, edx
  3627.         inc     esi
  3628.         rep     movsb
  3629.         pop     ecx
  3630.         mov     al, 's'
  3631.         stosb
  3632.         mov     al, 'd'
  3633.         jmp     rep_sse_final
  3634. .found1:
  3635.         push    ecx
  3636.         mov     ecx, edx
  3637.         inc     esi
  3638.         rep     movsb
  3639.         pop     ecx
  3640.         mov     al, 'p'
  3641.         stosb
  3642.         mov     al, 's'
  3643. rep_sse_final:
  3644.         stosb
  3645.         push    ecx
  3646.         push    5
  3647.         pop     ecx
  3648.         sub     ecx, edx
  3649.         adc     ecx, 1
  3650.         mov     al, ' '
  3651.         rep     stosb
  3652.         pop     ecx
  3653.         or      ch, 1
  3654.         jmp     disasm_mmx1
  3655.  
  3656. macro disasm_set_modew
  3657. {
  3658.         test    al, 1
  3659.         jz      @f
  3660.         or      ch, 80h
  3661. @@:
  3662. }
  3663.  
  3664. cmov2:
  3665.         disasm_set_modew
  3666. ; mov r/m,i
  3667.         call    disasm_get_byte
  3668.         dec     [disasm_cur_pos]
  3669.         test    al, 00111000b
  3670.         jnz     cunk
  3671.         mov     eax, 'mov '
  3672.         stosd
  3673.         mov     eax, '    '
  3674.         stosd
  3675.         call    disasm_readrmop
  3676.         mov     ax, ', '
  3677.         stosw
  3678.         xor     eax, eax
  3679.         test    ch, 80h
  3680.         jnz     .1
  3681.         call    disasm_get_byte
  3682.         jmp     .3
  3683. .1:
  3684.         test    ch, 1
  3685.         jnz     .2
  3686.         call    disasm_get_dword
  3687.         jmp     .3
  3688. .2:
  3689.         call    disasm_get_word
  3690. .3:
  3691.         call    disasm_write_num
  3692.         and     byte [edi], 0
  3693.         ret
  3694.  
  3695. cret2:
  3696.         mov     eax, 'ret '
  3697.         stosd
  3698.         mov     eax, '    '
  3699.         stosd
  3700.         xor     eax, eax
  3701.         jmp     cmov2.2
  3702.  
  3703. disasm_write_num:
  3704.         push    esi
  3705.         cmp     eax, 0x80
  3706.         jl      .nosymb
  3707.         lea     esi, [eax-1]
  3708.         test    eax, esi
  3709.         jz      .nosymb
  3710.         call    find_symbol
  3711.         jc      .nosymb
  3712. @@:
  3713.         lodsb
  3714.         test    al, al
  3715.         jz      @f
  3716.         stosb
  3717.         jmp     @b
  3718. @@:
  3719.         pop     esi
  3720.         ret
  3721. .nosymb:
  3722.         pop     esi
  3723.         push    ecx eax
  3724.         inc     edi
  3725. @@:
  3726.         mov     ecx, eax
  3727.         shr     eax, 4
  3728.         jz      @f
  3729.         inc     edi
  3730.         jmp     @b
  3731. @@:
  3732.         pop     eax
  3733.         cmp     ecx, 10
  3734.         jb      @f
  3735.         inc     edi
  3736. @@:
  3737.         push    edi eax
  3738. @@:
  3739.         mov     ecx, eax
  3740.         and     al, 0xF
  3741.         cmp     al, 10
  3742.         sbb     al, 69h
  3743.         das
  3744.         dec     edi
  3745.         mov     [edi], al
  3746.         mov     eax, ecx
  3747.         shr     eax, 4
  3748.         jnz     @b
  3749.         cmp     ecx, 10
  3750.         jb      @f
  3751.         mov     byte [edi-1], '0'
  3752. @@:
  3753.         pop     eax edi ecx
  3754.         cmp     eax, 10
  3755.         jb      @f
  3756.         mov     byte [edi], 'h'
  3757.         inc     edi
  3758. @@:
  3759.         ret
  3760.  
  3761. iglobal
  3762. label disasm_regs32 dword
  3763. label disasm_regs dword
  3764.         db      'eax',0
  3765.         db      'ecx',0
  3766.         db      'edx',0
  3767.         db      'ebx',0
  3768.         db      'esp',0
  3769.         db      'ebp',0
  3770.         db      'esi',0
  3771.         db      'edi',0
  3772. disasm_regs16   dw      'ax','cx','dx','bx','sp','bp','si','di'
  3773. disasm_regs8    dw      'al','cl','dl','bl','ah','ch','dh','bh'
  3774. disasm_scale    db      '1248'
  3775. endg
  3776. disasm_readrmop:
  3777.         call    disasm_get_byte
  3778.         test    ch, 40h
  3779.         jnz     .skip_size
  3780.         push    eax
  3781.         and     al, 0xC0
  3782.         cmp     al, 0xC0
  3783.         pop     eax
  3784.         jz      .skip_size
  3785.         test    ch, 80h
  3786.         jz      .byte
  3787.         test    ch, 1
  3788.         jnz     .word
  3789.         mov     dword [edi], 'dwor'
  3790.         mov     byte [edi+4], 'd'
  3791.         inc     edi
  3792.         jmp     @f
  3793. .byte:
  3794.         test    ch, 20h
  3795.         jz      .qb
  3796.         mov     byte [edi], 't'
  3797.         inc     edi
  3798. .qb:
  3799.         mov     dword [edi], 'byte'
  3800.         jmp     @f
  3801. .word:
  3802.         test    ch, 20h
  3803.         jz      .qw
  3804.         mov     byte [edi], 'q'
  3805.         inc     edi
  3806. .qw:
  3807.         mov     dword [edi], 'word'
  3808. @@:
  3809.         mov     byte [edi+4], ' '
  3810.         add     edi, 5
  3811. .skip_size:
  3812.         test    ch, 2
  3813.         jnz     disasm_readrmop16
  3814.         push    ecx
  3815.         movzx   ecx, al
  3816.         and     eax, 7
  3817.         shr     ecx, 6
  3818.         jz      .vmod0
  3819.         jp      .vmod3
  3820.         mov     byte [edi], '['
  3821.         inc     edi
  3822.         cmp     al, 4
  3823.         jz      .sib1
  3824.         mov     eax, [disasm_regs+eax*4]
  3825.         stosd
  3826.         dec     edi
  3827.         jmp     @f
  3828. .sib1:
  3829.         call    .parse_sib
  3830. @@:
  3831.         mov     al, '+'
  3832.         stosb
  3833.         dec     ecx
  3834.         jz      .vmod1
  3835.         call    disasm_get_dword
  3836.         jmp     @f
  3837. .vmod1:
  3838.         call    disasm_get_byte
  3839.         movsx   eax, al
  3840. @@:
  3841.         test    eax, eax
  3842.         jns     .2
  3843.         neg     eax
  3844.         mov     byte [edi-1], '-'
  3845. .2:
  3846.         call    disasm_write_num
  3847. .2a:
  3848.         mov     al, ']'
  3849.         stosb
  3850.         pop     ecx
  3851.         ret
  3852. .vmod3:
  3853.         pop     ecx
  3854.         test    ch, 10h
  3855.         jnz     .vmod3_mmi
  3856.         test    ch, 80h
  3857.         jz      .vmod3_byte
  3858.         test    ch, 1
  3859.         jnz     .vmod3_word
  3860.         test    ch, 20h
  3861.         jnz     .vmod3_sti
  3862.         mov     eax, [disasm_regs32+eax*4]
  3863.         stosd
  3864.         dec     edi
  3865.         ret
  3866. .vmod3_byte:
  3867.         mov     ax, [disasm_regs8+eax*2]
  3868. @@:
  3869.         stosw
  3870.         ret
  3871. .vmod3_word:
  3872.         mov     ax, [disasm_regs16+eax*2]
  3873.         jmp     @b
  3874. .vmod3_sti:
  3875.         mov     word [edi], 'st'
  3876.         add     al, '0'
  3877.         mov     byte [edi+2], al
  3878.         add     edi, 3
  3879.         ret
  3880. .vmod3_mmi:
  3881. disasm_write_mmreg = $
  3882.         test    ch, 1
  3883.         jz      @f
  3884.         mov     byte [edi], 'x'
  3885.         inc     edi
  3886. @@:
  3887.         mov     word [edi], 'mm'
  3888.         add     al, '0'
  3889.         mov     byte [edi+2], al
  3890.         add     edi, 3
  3891.         ret
  3892. .vmod0:
  3893.         mov     byte [edi], '['
  3894.         inc     edi
  3895.         cmp     al, 4
  3896.         jz      .sib2
  3897.         cmp     al, 5
  3898.         jz      .ofs32
  3899.         mov     eax, [disasm_regs+eax*4]
  3900.         stosd
  3901.         mov     byte [edi-1], ']'
  3902.         pop     ecx
  3903.         ret
  3904. .ofs32:
  3905.         call    disasm_get_dword
  3906.         jmp     .2
  3907. .sib2:
  3908.         call    .parse_sib
  3909.         mov     al, ']'
  3910.         stosb
  3911.         pop     ecx
  3912.         ret
  3913. .parse_sib:
  3914.         call    disasm_get_byte
  3915.         push    edx
  3916.         mov     dl, al
  3917.         mov     dh, 0
  3918.         and     eax, 7
  3919.         cmp     al, 5
  3920.         jnz     @f
  3921.         jecxz   .sib0
  3922. @@:
  3923.         mov     eax, [disasm_regs+eax*4]
  3924.         stosd
  3925.         dec     edi
  3926.         mov     dh, 1
  3927. .sib0:
  3928.         mov     al, dl
  3929.         shr     eax, 3
  3930.         and     eax, 7
  3931.         cmp     al, 4
  3932.         jz      .sibret
  3933.         test    dh, dh
  3934.         jz      @f
  3935.         mov     byte [edi], '+'
  3936.         inc     edi
  3937. @@:
  3938.         mov     eax, [disasm_regs+eax*4]
  3939.         stosd
  3940.         dec     edi
  3941.         shr     dl, 6
  3942.         jz      @f
  3943.         mov     al, '*'
  3944.         stosb
  3945.         movzx   eax, dl
  3946.         mov     al, [disasm_scale+eax]
  3947.         stosb
  3948. @@:
  3949. .sibret:
  3950.         test    dh, dh
  3951.         jnz     .sibret2
  3952.         call    disasm_get_dword
  3953.         cmp     byte [edi-1], '['
  3954.         jz      @f
  3955.         mov     byte [edi], '+'
  3956.         test    eax, eax
  3957.         jns     .sibns
  3958.         neg     eax
  3959.         mov     byte [edi], '-'
  3960. .sibns:
  3961.         inc     edi
  3962. @@:
  3963.         call    disasm_write_num
  3964. .sibret2:
  3965.         pop     edx
  3966.         ret
  3967.  
  3968. iglobal
  3969. disasm_rm16_1   dd      'bxsi','bxdi','bpsi','bpdi'
  3970. disasm_rm16_2   dw      'si','di','bp','bx'
  3971. endg
  3972. disasm_readrmop16:
  3973.         push    ecx
  3974.         movzx   ecx, al
  3975.         and     eax, 7
  3976.         shr     ecx, 6
  3977.         jz      .vmod0
  3978.         jp      disasm_readrmop.vmod3   ; mod=3 is the same in 16- and 32-bit code
  3979. ; 1 or 2
  3980.         mov     byte [edi], '['
  3981.         inc     edi
  3982.         cmp     al, 4
  3983.         jae     @f
  3984.         mov     eax, [disasm_rm16_1+eax*4]
  3985.         stosw
  3986.         mov     al, '+'
  3987.         stosb
  3988.         shr     eax, 16
  3989.         jmp     .1
  3990. @@:
  3991.         mov     eax, dword [disasm_rm16_2+eax*2-4*2]
  3992. .1:
  3993.         stosw
  3994.         mov     al, '+'
  3995.         stosb
  3996.         xor     eax, eax
  3997.         dec     ecx
  3998.         jnz     .2
  3999.         call    disasm_get_byte
  4000.         cbw
  4001.         jmp     @f
  4002. .2:
  4003.         call    disasm_get_word
  4004. @@:
  4005.         test    ax, ax
  4006.         jns     @f
  4007.         mov     byte [edi-1], '-'
  4008.         neg     ax
  4009. @@:
  4010.         call    disasm_write_num
  4011. .done1:
  4012.         mov     al, ']'
  4013.         stosb
  4014.         pop     ecx
  4015.         ret
  4016. .vmod0:
  4017.         mov     byte [edi], '['
  4018.         inc     edi
  4019.         cmp     al, 6
  4020.         jz      .ofs16
  4021.         cmp     al, 4
  4022.         jae     @f
  4023.         mov     eax, [disasm_rm16_1+eax*4]
  4024.         stosw
  4025.         mov     al, '+'
  4026.         stosb
  4027.         shr     eax, 16
  4028.         jmp     .3
  4029. @@:
  4030.         mov     eax, dword [disasm_rm16_2+eax*2-4*2]
  4031. .3:
  4032.         stosw
  4033.         jmp     .done1
  4034. .ofs16:
  4035.         xor     eax, eax
  4036.         call    disasm_get_word
  4037.         call    disasm_write_num
  4038.         jmp     .done1
  4039.  
  4040. cpush21:
  4041.         mov     eax, 'push'
  4042.         stosd
  4043.         mov     eax, '    '
  4044.         stosd
  4045. disasm_i32:
  4046.         call    disasm_get_dword
  4047.         call    disasm_write_num
  4048.         and     byte [edi], 0
  4049.         ret
  4050.  
  4051. cpush22:
  4052.         mov     eax, 'push'
  4053.         stosd
  4054.         mov     eax, '    '
  4055.         stosd
  4056.         call    disasm_get_byte
  4057.         movsx   eax, al
  4058. @@:
  4059.         call    disasm_write_num
  4060.         and     byte [edi], 0
  4061.         ret
  4062.  
  4063. center:
  4064.         mov     eax, 'ente'
  4065.         stosd
  4066.         mov     eax, 'r   '
  4067.         stosd
  4068.         xor     eax, eax
  4069.         call    disasm_get_word
  4070.         call    disasm_write_num
  4071.         mov     al, ','
  4072.         stosb
  4073.         mov     al, ' '
  4074.         stosb
  4075.         xor     eax, eax
  4076.         call    disasm_get_byte
  4077.         jmp     @b
  4078.  
  4079. cinc1:
  4080. ; inc reg32
  4081. cdec1:
  4082. ; dec reg32
  4083. cpush1:
  4084. ; push reg32
  4085. cpop1:
  4086. ; pop reg32
  4087. cbswap:
  4088. ; bswap reg32
  4089.         mov     edx, eax
  4090.         and     edx, 7
  4091.         shr     eax, 3
  4092.         sub     al, 8
  4093.         mov     esi, 'inc '
  4094.         jz      @f
  4095.         mov     esi, 'dec '
  4096.         dec     al
  4097.         jz      @f
  4098.         mov     esi, 'push'
  4099.         dec     al
  4100.         jz      @f
  4101.         mov     esi, 'pop '
  4102.         dec     al
  4103.         jz      @f
  4104.         mov     esi, 'bswa'
  4105. @@:
  4106.         xchg    eax, esi
  4107.         stosd
  4108.         mov     eax, '    '
  4109.         jz      @f
  4110.         mov     al, 'p'
  4111. @@:
  4112.         stosd
  4113.         xchg    eax, edx
  4114.         call    disasm_write_reg1632
  4115.         and     byte [edi], 0
  4116.         ret
  4117.  
  4118. cxchg1:
  4119. ; xchg eax,reg32
  4120.         and     eax, 7
  4121.         xchg    eax, edx
  4122.         mov     eax, 'xchg'
  4123.         stosd
  4124.         mov     eax, '    '
  4125.         stosd
  4126.         xor     eax, eax
  4127.         call    disasm_write_reg1632
  4128.         mov     ax, ', '
  4129.         stosw
  4130.         xchg    eax, edx
  4131.         call    disasm_write_reg1632
  4132.         and     byte [edi], 0
  4133.         ret
  4134.  
  4135. cint:
  4136.         mov     eax, 'int '
  4137.         stosd
  4138.         mov     eax, '    '
  4139.         stosd
  4140. disasm_i8u:
  4141.         xor     eax, eax
  4142.         call    disasm_get_byte
  4143.         call    disasm_write_num
  4144.         and     byte [edi], 0
  4145.         ret
  4146.  
  4147. cmov11:
  4148. ; mov r8,i8
  4149.         mov     ecx, eax
  4150.         mov     eax, 'mov '
  4151.         stosd
  4152.         mov     eax, '    '
  4153.         stosd
  4154.         and     ecx, 7
  4155.         mov     ax, [disasm_regs8+ecx*2]
  4156.         stosw
  4157.         mov     ax, ', '
  4158.         stosw
  4159.         jmp     disasm_i8u
  4160.  
  4161. cmov12:
  4162. ; mov r32,i32
  4163.         xchg    eax, edx
  4164.         mov     eax, 'mov '
  4165.         stosd
  4166.         mov     eax, '    '
  4167.         stosd
  4168.         xchg    eax, edx
  4169.         and     eax, 7
  4170.         call    disasm_write_reg1632
  4171.         mov     ax, ', '
  4172.         stosw
  4173.         jmp     cmov2.1
  4174.  
  4175. iglobal
  4176. disasm_shifts   dd      'rol ','ror ','rcl ','rcr ','shl ','shr ','sal ','sar '
  4177. endg
  4178. cshift2:
  4179. ; shift r/m,1 = D0/D1
  4180. cshift3:
  4181. ; shift r/m,cl = D2/D3
  4182.         disasm_set_modew
  4183.         mov     dl, al
  4184.         call    disasm_get_byte
  4185.         dec     [disasm_cur_pos]
  4186.         shr     al, 3
  4187.         and     eax, 7
  4188.         mov     eax, [disasm_shifts+eax*4]
  4189.         stosd
  4190.         mov     eax, '    '
  4191.         stosd
  4192.         call    disasm_readrmop
  4193.         cmp     dl, 0xD2
  4194.         jb      .s1
  4195.         mov     eax, ', cl'
  4196.         stosd
  4197.         and     byte [edi], 0
  4198.         ret
  4199. .s1:
  4200.         mov     eax, ', 1'
  4201.         stosd
  4202.         clc
  4203.         ret
  4204.  
  4205. cshift1:
  4206. ; shift r/m,i8 = C0/C1
  4207.         disasm_set_modew
  4208.         call    disasm_get_byte
  4209.         dec     [disasm_cur_pos]
  4210.         shr     al, 3
  4211.         and     eax, 7
  4212.         mov     eax, [disasm_shifts+eax*4]
  4213.         stosd
  4214.         mov     eax, '    '
  4215.         stosd
  4216.         call    disasm_readrmop
  4217.         mov     ax, ', '
  4218.         stosw
  4219.         jmp     disasm_i8u
  4220.  
  4221. caam:
  4222.         mov     eax, 'aam '
  4223.         jmp     @f
  4224. caad:
  4225.         mov     eax, 'aad '
  4226. @@:
  4227.         stosd
  4228.         mov     eax, '    '
  4229.         stosd
  4230.         xor     eax, eax
  4231.         call    disasm_get_byte
  4232.         cmp     al, 10
  4233.         jz      @f
  4234.         call    disasm_write_num
  4235. @@:
  4236.         and     byte [edi], 0
  4237.         ret
  4238.  
  4239. cmov3:
  4240. ; A0: mov al,[ofs32]
  4241. ; A1: mov ax/eax,[ofs32]
  4242. ; A2: mov [ofs32],al
  4243. ; A3: mov [ofs32],ax/eax
  4244.         mov     edx, 'mov '
  4245.         xchg    eax, edx
  4246.         stosd
  4247.         mov     eax, '    '
  4248.         stosd
  4249.         test    dl, 2
  4250.         jnz     .1
  4251.         call    .write_acc
  4252.         mov     ax, ', '
  4253.         stosw
  4254.         call    .write_ofs32
  4255.         jmp     .2
  4256. .1:
  4257.         call    .write_ofs32
  4258.         mov     ax, ', '
  4259.         stosw
  4260.         call    .write_acc
  4261. .2:     and     byte [edi], 0
  4262.         ret
  4263. .write_acc:
  4264.         test    dl, 1
  4265.         jz      .8bit
  4266.         test    ch, 1
  4267.         jnz     .16bit
  4268.         mov     eax, 'eax'
  4269.         stosd
  4270.         dec     edi
  4271.         ret
  4272. .16bit:
  4273.         mov     ax, 'ax'
  4274.         stosw
  4275.         ret
  4276. .8bit:
  4277.         mov     ax, 'al'
  4278.         stosw
  4279.         ret
  4280. .write_ofs32:
  4281.         mov     al, '['
  4282.         stosb
  4283.         call    disasm_get_dword
  4284.         call    disasm_write_num
  4285.         mov     al, ']'
  4286.         stosb
  4287.         ret
  4288.  
  4289. disasm_write_reg:
  4290.         test    ch, 80h
  4291.         jnz     disasm_write_reg1632
  4292.         mov     ax, [disasm_regs8+eax*2]
  4293.         stosw
  4294.         ret
  4295. disasm_write_reg1632:
  4296.         test    ch, 1
  4297.         jnz     @f
  4298.         mov     eax, [disasm_regs32+eax*4]
  4299.         stosd
  4300.         dec     edi
  4301.         ret
  4302. @@:
  4303.         mov     ax, [disasm_regs16+eax*2]
  4304.         stosw
  4305.         ret
  4306.  
  4307. cmovzx:         ; 0F B6/B7
  4308. cmovsx:         ; 0F BE/BF
  4309.         mov     edx, eax
  4310.         disasm_set_modew
  4311.         mov     eax, 'movz'
  4312.         cmp     dl, 0xB8
  4313.         jb      @f
  4314.         mov     eax, 'movs'
  4315. @@:
  4316.         stosd
  4317.         mov     eax, 'x   '
  4318.         stosd
  4319.         call    disasm_get_byte
  4320.         dec     [disasm_cur_pos]
  4321.         shr     al, 3
  4322.         and     eax, 7
  4323.         call    disasm_write_reg1632
  4324.         mov     ax, ', '
  4325.         stosw
  4326.         or      ch, 1   ; 2nd operand - 8 or 16 bits
  4327.         call    disasm_readrmop
  4328.         and     byte [edi], 0
  4329.         ret
  4330.  
  4331. iglobal
  4332. disasm_op2cmds  dd 'add ','or  ','adc ','sbb ','and ','sub ','xor ','cmp '
  4333. endg
  4334. cop21:
  4335.         disasm_set_modew
  4336.         mov     esi, 'test'
  4337.         cmp     al, 0A8h
  4338.         jae     @f
  4339.         shr     al, 3
  4340.         and     eax, 7
  4341.         mov     esi, [disasm_op2cmds+eax*4]
  4342. @@:
  4343.         xchg    eax, esi
  4344.         stosd
  4345.         mov     eax, '    '
  4346.         stosd
  4347.         test    ch, 80h
  4348.         jnz     .1632
  4349.         mov     eax, 'al, '
  4350.         stosd
  4351.         jmp     disasm_i8u
  4352. .1632:
  4353.         test    ch, 1
  4354.         jnz     .16
  4355.         mov     eax, 'eax,'
  4356.         stosd
  4357.         mov     al, ' '
  4358.         stosb
  4359.         call    disasm_get_dword
  4360.         jmp     .x
  4361. .16:
  4362.         mov     eax, 'ax, '
  4363.         stosd
  4364.         xor     eax, eax
  4365.         call    disasm_get_word
  4366. .x:
  4367.         call    disasm_write_num
  4368.         and     byte [edi], 0
  4369.         ret
  4370.  
  4371. carpl:
  4372.         xor     edx, edx
  4373.         or      ch, 0C1h
  4374.         mov     eax, 'arpl'
  4375.         jmp     cop22.d2
  4376.  
  4377. ccmpxchg:
  4378.         xor     edx, edx
  4379.         disasm_set_modew
  4380.         or      ch, 40h
  4381.         mov     eax, 'cmpx'
  4382.         stosd
  4383.         mov     eax, 'chg '
  4384.         jmp     cop22.d1
  4385.  
  4386. cbsf:
  4387. cbsr:
  4388.         or      ch, 80h
  4389.  
  4390. cop22:
  4391.         disasm_set_modew
  4392.         or      ch, 40h
  4393.         mov     edx, eax
  4394.         mov     esi, 'lea '
  4395.         cmp     al, 8Dh
  4396.         jz      @f
  4397.         mov     esi, 'imul'
  4398.         cmp     al, 0xAF
  4399.         jz      @f
  4400.         mov     esi, 'bsf '
  4401.         cmp     al, 0BCh
  4402.         jz      @f
  4403.         mov     esi, 'bsr '
  4404.         cmp     al, 0BDh
  4405.         jz      @f
  4406.         mov     esi, 'mov '
  4407.         cmp     al, 88h
  4408.         jae     @f
  4409.         mov     esi, 'xchg'
  4410.         cmp     al, 86h
  4411.         jae     @f
  4412.         mov     esi, 'test'
  4413.         cmp     al, 84h
  4414.         jae     @f
  4415.         shr     al, 3
  4416.         and     eax, 7
  4417.         mov     esi, [disasm_op2cmds+eax*4]
  4418. @@:
  4419.         xchg    eax, esi
  4420. .d2:
  4421.         stosd
  4422.         mov     eax, '    '
  4423. .d1:
  4424.         stosd
  4425.         call    disasm_get_byte
  4426.         dec     [disasm_cur_pos]
  4427.         shr     al, 3
  4428.         and     eax, 7
  4429.         cmp     dl, 0x8D
  4430.         jz      @f
  4431.         cmp     dl, 0x86
  4432.         jz      @f
  4433.         cmp     dl, 0x87
  4434.         jz      @f
  4435.         cmp     dl, 0xBC
  4436.         jz      @f
  4437.         cmp     dl, 0xBD
  4438.         jz      @f
  4439.         test    dl, 2
  4440.         jz      .d0
  4441. @@:
  4442.         call    disasm_write_reg
  4443.         mov     ax, ', '
  4444.         stosw
  4445.         call    disasm_readrmop
  4446.         and     byte [edi], 0
  4447.         ret
  4448. .d0:
  4449.         push    eax
  4450.         call    disasm_readrmop
  4451.         mov     ax, ', '
  4452.         stosw
  4453.         pop     eax
  4454.         call    disasm_write_reg
  4455.         and     byte [edi], 0
  4456.         ret
  4457.  
  4458. cbound:
  4459.         mov     edx, eax
  4460.         mov     eax, 'boun'
  4461.         stosd
  4462.         mov     eax, 'd   '
  4463.         or      ch, 0xC0
  4464.         jmp     cop22.d1
  4465.  
  4466. cop23:
  4467.         disasm_set_modew
  4468.         xchg    eax, edx
  4469.         call    disasm_get_byte
  4470.         dec     [disasm_cur_pos]
  4471.         shr     eax, 3
  4472.         and     eax, 7
  4473.         mov     eax, [disasm_op2cmds+eax*4]
  4474. ctest:
  4475.         stosd
  4476.         mov     eax, '    '
  4477.         stosd
  4478.         call    disasm_readrmop
  4479.         mov     ax, ', '
  4480.         stosw
  4481.         test    ch, 80h
  4482.         jz      .i8
  4483.         cmp     dl, 83h
  4484.         jz      .i8
  4485.         test    ch, 1
  4486.         jnz     .i16
  4487.         call    disasm_get_dword
  4488.         jmp     .ic
  4489. .i8:
  4490.         xor     eax, eax
  4491.         call    disasm_get_byte
  4492.         cmp     dl, 83h
  4493.         jnz     .ic
  4494.         movsx   eax, al
  4495.         jmp     .ic
  4496. .i16:
  4497.         xor     eax, eax
  4498.         call    disasm_get_word
  4499. .ic:
  4500.         call    disasm_write_num
  4501.         and     byte [edi], 0
  4502.         ret
  4503.  
  4504. cmovcc:
  4505.         or      ch, 0C0h
  4506.         and     eax, 0xF
  4507.         mov     ax, [disasm_jcc_codes + eax*2]
  4508.         mov     dword [edi], 'cmov'
  4509.         add     edi, 4
  4510.         stosw
  4511.         mov     ax, '  '
  4512.         stosw
  4513.         call    disasm_get_byte
  4514.         dec     [disasm_cur_pos]
  4515.         shr     eax, 3
  4516.         and     eax, 7
  4517.         call    disasm_write_reg1632
  4518.         mov     ax, ', '
  4519.         stosw
  4520.         call    disasm_readrmop
  4521.         and     byte [edi], 0
  4522.         ret
  4523.  
  4524. cbtx1:
  4525. ; btx r/m,i8 = 0F BA
  4526.         or      ch, 80h
  4527.         call    disasm_get_byte
  4528.         dec     [disasm_cur_pos]
  4529.         shr     al, 3
  4530.         and     eax, 7
  4531.         cmp     al, 4
  4532.         jb      cunk
  4533.         mov     eax, [btx1codes+eax*4-4*4]
  4534.         stosd
  4535.         mov     eax, '    '
  4536.         stosd
  4537.         call    disasm_readrmop
  4538.         mov     ax, ', '
  4539.         stosw
  4540.         jmp     disasm_i8u
  4541. iglobal
  4542. btx1codes       dd      'bt  ','bts ','btr ','btc '
  4543. endg
  4544. cbtx2:
  4545. ; btx r/m,r = 0F 101xx011 (A3,AB,B3,BB)
  4546.         shr     al, 3
  4547.         and     eax, 3
  4548.         mov     eax, [btx1codes+eax*4]
  4549.         stosd
  4550.         mov     eax, '    '
  4551.         stosd
  4552.         or      ch, 0xC0
  4553.         call    disasm_get_byte
  4554.         dec     [disasm_cur_pos]
  4555.         shr     al, 3
  4556.         and     eax, 7
  4557.         push    eax
  4558.         call    disasm_readrmop
  4559.         mov     ax, ', '
  4560.         stosw
  4561.         pop     eax
  4562.         call    disasm_write_reg1632
  4563.         and     byte [edi], 0
  4564.         ret
  4565.  
  4566. csetcc:
  4567.         and     eax, 0xF
  4568.         mov     ax, [disasm_jcc_codes + eax*2]
  4569.         mov     dword [edi], 'setc'
  4570.         add     edi, 3
  4571.         stosw
  4572.         mov     ax, '  '
  4573.         stosw
  4574.         stosb
  4575.         call    disasm_readrmop
  4576.         and     byte [edi], 0
  4577.         ret
  4578.  
  4579. iglobal
  4580. disasm_jcc_codes dw 'o ','no','b ','ae','z ','nz','be','a ','s ','ns','p ','np','l ','ge','le','g '
  4581. endg
  4582. cjcc1:
  4583. cjmp2:
  4584.         cmp     al, 0xEB
  4585.         jz      .1
  4586.         and     eax, 0xF
  4587.         mov     ax, [disasm_jcc_codes + eax*2]
  4588.         jmp     .2
  4589. .1:
  4590.         mov     ax, 'mp'
  4591. .2:
  4592.         mov     byte [edi], 'j'
  4593.         inc     edi
  4594.         stosw
  4595.         mov     eax, '    '
  4596.         stosb
  4597.         stosd
  4598.         call    disasm_get_byte
  4599.         movsx   eax, al
  4600. disasm_rva:
  4601.         add     eax, [disasm_cur_pos]
  4602.         call    disasm_write_num
  4603.         and     byte [edi], 0
  4604.         ret
  4605.  
  4606. ccall1:
  4607. cjmp1:
  4608. cjcc2:
  4609.         mov     edx, 'call'
  4610.         cmp     al, 0xE8
  4611.         jz      @f
  4612.         mov     edx, 'jmp '
  4613.         cmp     al, 0xE9
  4614.         jz      @f
  4615.         mov     edx, '    '
  4616.         and     eax, 0xF
  4617.         mov     dx, [disasm_jcc_codes+eax*2]
  4618.         shl     edx, 8
  4619.         mov     dl, 'j'
  4620. @@:
  4621.         xchg    eax, edx
  4622.         stosd
  4623.         mov     eax, '    '
  4624.         stosd
  4625.         test    ch, 1
  4626.         jnz     @f
  4627.         call    disasm_get_dword
  4628.         jmp     disasm_rva
  4629. @@:
  4630.         call    disasm_get_word
  4631.         add     eax, [disasm_cur_pos]
  4632.         and     eax, 0xFFFF
  4633.         call    disasm_write_num
  4634.         and     byte [edi], 0
  4635.         ret
  4636.  
  4637. ccallf:
  4638.         mov     eax, 'call'
  4639.         stosd
  4640.         mov     eax, '    '
  4641.         stosd
  4642.         mov     al, 'd'
  4643.         test    ch, 1
  4644.         jnz     @f
  4645.         mov     al, 'p'
  4646. @@:
  4647.         stosb
  4648.         mov     eax, 'word'
  4649.         stosd
  4650.         mov     al, ' '
  4651.         stosb
  4652.         test    ch, 1
  4653.         jnz     .1
  4654.         call    disasm_get_dword
  4655.         jmp     .2
  4656. .1:
  4657.         xor     eax, eax
  4658.         call    disasm_get_word
  4659. .2:
  4660.         push    eax
  4661.         xor     eax, eax
  4662.         call    disasm_get_word
  4663.         call    disasm_write_num
  4664.         mov     al, ':'
  4665.         stosb
  4666.         pop     eax
  4667.         call    disasm_write_num
  4668.         and     byte [edi], 0
  4669.         ret
  4670.  
  4671. iglobal
  4672. op11codes       dd      'test',0,'not ','neg ','mul ','imul','div ','idiv'
  4673. op12codes       dd      'inc ','dec ','call',0,'jmp ',0,'push',0
  4674. endg
  4675. cop1:
  4676.         disasm_set_modew
  4677.         xchg    eax, edx
  4678.         call    disasm_get_byte
  4679.         movzx   esi, al
  4680.         dec     [disasm_cur_pos]
  4681.         shr     al, 3
  4682.         and     eax, 7
  4683.         cmp     dl, 0xFE
  4684.         jnz     @f
  4685.         cmp     al, 1
  4686.         jbe     @f
  4687. .0:
  4688.         inc     [disasm_cur_pos]
  4689.         jmp     cunk
  4690. @@:
  4691.         and     edx, 8
  4692.         add     eax, edx
  4693.         cmp     al, 11
  4694.         jz      .callfar
  4695.         cmp     al, 13
  4696.         jz      .jmpfar
  4697.         mov     eax, [op11codes+eax*4]
  4698.         test    eax, eax
  4699.         jz      .0
  4700.         cmp     eax, 'test'
  4701.         jz      ctest
  4702. .2:
  4703.         stosd
  4704.         mov     eax, '    '
  4705.         stosd
  4706.         call    disasm_readrmop
  4707.         and     byte [edi], 0
  4708.         ret
  4709. .callfar:
  4710.         mov     eax, 'call'
  4711. .1:
  4712.         cmp     esi, 0xC0
  4713.         jae     .0
  4714.         stosd
  4715.         mov     eax, '    '
  4716.         stosd
  4717.         mov     eax, 'far '
  4718.         stosd
  4719.         mov     al, 'd'
  4720.         test    ch, 1
  4721.         jnz     @f
  4722.         mov     al, 'p'
  4723. @@:
  4724.         stosb
  4725.         or      ch, 1
  4726.         call    disasm_readrmop
  4727.         and     byte [edi], 0
  4728.         ret
  4729. .jmpfar:
  4730.         mov     eax, 'jmp '
  4731.         jmp     .1
  4732.  
  4733. cpop2:
  4734.         or      ch, 80h
  4735.         call    disasm_get_byte
  4736.         dec     [disasm_cur_pos]
  4737.         test    al, 00111000b
  4738.         jnz     cunk
  4739.         mov     eax, 'pop '
  4740.         jmp     cop1.2
  4741.  
  4742. cloopnz:
  4743.         mov     eax, 'loop'
  4744.         stosd
  4745.         mov     eax, 'nz  '
  4746.         test    ch, 2
  4747.         jz      @f
  4748.         mov     ah, 'w'
  4749. @@:     jmp     cloop.cmn
  4750. cloopz:
  4751.         mov     eax, 'loop'
  4752.         stosd
  4753.         mov     eax, 'z   '
  4754.         test    ch, 2
  4755.         jz      @f
  4756.         mov     eax, 'zw  '
  4757. @@:     jmp     cloop.cmn
  4758.  
  4759. cjcxz:
  4760. cloop:
  4761.         cmp     al, 0xE2
  4762.         jz      .loop
  4763.         test    ch, 2
  4764.         jnz     .jcxz
  4765.         mov     eax, 'jecx'
  4766.         stosd
  4767.         mov     eax, 'z   '
  4768.         jmp     .cmn
  4769. .jcxz:
  4770.         mov     eax, 'jcxz'
  4771.         stosd
  4772.         mov     eax, '    '
  4773.         jmp     .cmn
  4774. .loop:
  4775.         mov     eax, 'loop'
  4776.         stosd
  4777.         mov     eax, '    '
  4778.         test    ch, 2
  4779.         jz      .cmn
  4780.         mov     al, 'w'
  4781. .cmn:
  4782.         stosd
  4783.         call    disasm_get_byte
  4784.         movsx   eax, al
  4785.         add     eax, [disasm_cur_pos]
  4786.         test    ch, 1
  4787.         jz      @f
  4788.         and     eax, 0xFFFF
  4789. @@:
  4790. disasm_write_num_done:
  4791.         call    disasm_write_num
  4792.         and     byte [edi], 0
  4793.         ret
  4794.  
  4795. cimul1:
  4796. ; imul r,r/m,i
  4797.         or      ch, 80h         ; 32bit operation
  4798.         xchg    eax, edx
  4799.         mov     eax, 'imul'
  4800.         stosd
  4801.         mov     eax, '    '
  4802.         stosd
  4803.         call    disasm_get_byte
  4804.         dec     [disasm_cur_pos]
  4805.         shr     al, 3
  4806.         and     eax, 7
  4807.         call    disasm_write_reg1632
  4808.         mov     ax, ', '
  4809.         stosw
  4810.         call    disasm_readrmop
  4811.         mov     ax, ', '
  4812.         stosw
  4813.         test    ch, 1
  4814.         jnz     .16
  4815.         cmp     dl, 0x69
  4816.         jz      .op32
  4817.         call    disasm_get_byte
  4818.         movsx   eax, al
  4819.         jmp     disasm_write_num_done
  4820. .op32:
  4821.         call    disasm_get_dword
  4822.         jmp     disasm_write_num_done
  4823. .16:
  4824.         cmp     dl, 0x69
  4825.         jz      .op16
  4826.         call    disasm_get_byte
  4827.         cbw
  4828.         jmp     disasm_write_num_done
  4829. .op16:
  4830.         xor     eax, eax
  4831.         call    disasm_get_word
  4832.         jmp     disasm_write_num_done
  4833.  
  4834. cshld:
  4835. cshrd:
  4836.         mov     edx, 'shld'
  4837.         test    al, 8
  4838.         jz      @f
  4839.         mov     edx, 'shrd'
  4840. @@:
  4841.         xchg    eax, edx
  4842.         stosd
  4843.         mov     eax, '    '
  4844.         stosd
  4845.         call    disasm_get_byte
  4846.         dec     [disasm_cur_pos]
  4847.         shr     al, 3
  4848.         and     eax, 7
  4849.         push    eax
  4850.         or      ch, 80h
  4851.         call    disasm_readrmop
  4852.         mov     ax, ', '
  4853.         stosw
  4854.         pop     eax
  4855.         call    disasm_write_reg1632
  4856.         mov     ax, ', '
  4857.         stosw
  4858.         test    dl, 1
  4859.         jz      disasm_i8u
  4860.         mov     ax, 'cl'
  4861.         stosw
  4862.         and     byte [edi], 0
  4863.         ret
  4864.  
  4865. ccbw:
  4866.         mov     eax, 'cbw '
  4867.         test    ch, 1
  4868.         jnz     @f
  4869.         mov     eax, 'cwde'
  4870. @@:     stosd
  4871.         and     byte [edi], 0
  4872.         ret
  4873. ccwd:
  4874.         mov     eax, 'cwd '
  4875.         test    ch, 1
  4876.         jnz     @b
  4877.         mov     eax, 'cdq '
  4878.         jmp     @b
  4879.  
  4880. ccmpxchg8b:
  4881.         call    disasm_get_byte
  4882.         cmp     al, 0xC0
  4883.         jae     cerr
  4884.         shr     al, 3
  4885.         and     al, 7
  4886.         cmp     al, 1
  4887.         jnz     cerr
  4888.         dec     [disasm_cur_pos]
  4889.         mov     eax, 'cmpx'
  4890.         stosd
  4891.         mov     eax, 'chg8'
  4892.         stosd
  4893.         mov     al, 'b'
  4894.         stosb
  4895.         mov     al, ' '
  4896.         stosb
  4897.         or      ch, 40h
  4898.         call    disasm_readrmop
  4899.         and     byte [edi], 0
  4900.         ret
  4901.  
  4902. iglobal
  4903. fpuD8   dd      'add ','mul ','com ','comp','sub ','subr','div ','divr'
  4904. endg
  4905.  
  4906. cD8:
  4907.         call    disasm_get_byte
  4908.         dec     [disasm_cur_pos]
  4909.         push    eax
  4910.         shr     al, 3
  4911.         and     eax, 7
  4912.         mov     byte [edi], 'f'
  4913.         inc     edi
  4914.         xchg    eax, edx
  4915.         mov     eax, [fpuD8+edx*4]
  4916.         stosd
  4917.         mov     ax, '  '
  4918.         stosw
  4919.         stosb
  4920.         pop     eax
  4921.         cmp     dl, 2
  4922.         jb      .1
  4923.         cmp     dl, 3
  4924.         jbe     .2
  4925. .1:
  4926.         cmp     al, 0xC0
  4927.         jb      .2
  4928.         mov     eax, 'st0,'
  4929.         stosd
  4930.         mov     al, ' '
  4931.         stosb
  4932. .2:
  4933.         or      ch, 80h or 20h
  4934.         and     ch, not 1
  4935.         call    disasm_readrmop
  4936.         and     byte [edi], 0
  4937.         ret
  4938.  
  4939. iglobal
  4940. fpuD9_2:
  4941.         dq      'fchs    ','fabs    ',0,0,'ftst    ','fxam    ',0,0
  4942.         db      'fld1    fldl2t  fldl2e  fldpi   fldlg2  fldln2  fldz    '
  4943.         dq      0
  4944.         db      'f2xm1   fyl2x   fptan   fpatan  fxtract fprem1  fdecstp fincstp '
  4945.         db      'fprem   fyl2xp1 fsqrt   fsincos frndint fscale  fsin    fcos    '
  4946. fpuD9_fnop      db      'fnop    '
  4947. endg
  4948. cD9:
  4949.         call    disasm_get_byte
  4950.         sub     al, 0xC0
  4951.         jae     .l1
  4952.         dec     [disasm_cur_pos]
  4953.         shr     al, 3
  4954.         and     eax, 7
  4955.         cmp     al, 7
  4956.         jnz     @f
  4957.         mov     eax, 'fnst'
  4958.         stosd
  4959.         mov     eax, 'cw  '
  4960.         jmp     .x1
  4961. @@:
  4962.         cmp     al, 5
  4963.         jnz     @f
  4964.         mov     eax, 'fldc'
  4965.         stosd
  4966.         mov     eax, 'w   '
  4967. .x1:
  4968.         stosd
  4969.         or      ch, 0C1h
  4970.         jmp     .cmn
  4971. @@:
  4972.         mov     edx, 'fld '
  4973.         test    al, al
  4974.         jz      @f
  4975.         mov     edx, 'fst '
  4976.         cmp     al, 2
  4977.         jz      @f
  4978.         mov     edx, 'fstp'
  4979.         cmp     al, 3
  4980.         jnz     cunk
  4981. @@:
  4982.         xchg    eax, edx
  4983.         stosd
  4984.         mov     eax, '    '
  4985.         stosd
  4986.         or      ch, 80h
  4987.         and     ch, not 1
  4988. .cmn:
  4989.         call    disasm_readrmop
  4990.         and     byte [edi], 0
  4991.         ret
  4992. .l1:
  4993.         cmp     al, 10h
  4994.         jae     .l2
  4995.         mov     edx, 'fld '
  4996.         cmp     al, 8
  4997.         jb      @f
  4998.         mov     edx, 'fxch'
  4999. @@:
  5000.         xchg    eax, edx
  5001.         stosd
  5002.         mov     eax, '    '
  5003.         stosd
  5004.         xchg    eax, edx
  5005.         and     al, 7
  5006.         add     al, '0'
  5007.         shl     eax, 16
  5008.         mov     ax, 'st'
  5009.         stosd
  5010.         clc
  5011.         ret
  5012. .l2:
  5013.         cmp     al, 0x10
  5014.         jnz     @f
  5015.         mov     esi, fpuD9_fnop
  5016.         jmp     .l3
  5017. @@:
  5018.         sub     al, 0x20
  5019.         jb      cerr
  5020.         lea     esi, [fpuD9_2+eax*8]
  5021.         cmp     byte [esi], 0
  5022.         jz      cerr
  5023. .l3:
  5024.         movsd
  5025.         movsd
  5026.         and     byte [edi-1], 0
  5027.         ret
  5028.  
  5029. cDA:
  5030.         call    disasm_get_byte
  5031.         cmp     al, 0xC0
  5032.         jae     cunk
  5033.         dec     [disasm_cur_pos]
  5034.         shr     al, 3
  5035.         and     eax, 7
  5036.         mov     word [edi], 'fi'
  5037.         inc     edi
  5038.         inc     edi
  5039.         mov     eax, [fpuD8+eax*4]
  5040.         stosd
  5041.         mov     ax, '  '
  5042.         stosw
  5043.         or      ch, 80h
  5044.         and     ch, not 1       ; 32-bit operand
  5045.         call    disasm_readrmop
  5046.         and     byte [edi], 0
  5047.         ret
  5048.  
  5049. iglobal
  5050. fpuDB   dd      'ild ',0,'ist ','istp',0,'ld  ',0,'stp '
  5051. endg
  5052. cDB:
  5053.         call    disasm_get_byte
  5054.         cmp     al, 0xC0
  5055.         jae     .1
  5056.         dec     [disasm_cur_pos]
  5057.         shr     al, 3
  5058.         and     eax, 7
  5059.         xchg    eax, edx
  5060.         mov     eax, [fpuDB+edx*4]
  5061.         test    eax, eax
  5062.         jz      cerr
  5063.         mov     byte [edi], 'f'
  5064.         inc     edi
  5065.         stosd
  5066.         mov     ax, '  '
  5067.         stosw
  5068.         stosb
  5069.         or      ch, 80h
  5070.         and     ch, not 1       ; 32-bit operand
  5071.         cmp     dl, 4
  5072.         jb      @f
  5073.         or      ch, 20h
  5074.         and     ch, not 80h     ; 80-bit operand
  5075. @@:
  5076.         call    disasm_readrmop
  5077.         and     byte [edi], 0
  5078.         ret
  5079. .1:
  5080.         cmp     al, 0xE3
  5081.         jnz     cunk
  5082.         mov     eax, 'fnin'
  5083.         stosd
  5084.         mov     eax, 'it'
  5085.         stosd
  5086.         dec     edi
  5087.         ret             ; CF cleared
  5088.  
  5089. iglobal
  5090. fpuDC   dd      'add ','mul ',0,0,'subr','sub ','divr','div '
  5091. endg
  5092. cDC:
  5093.         call    disasm_get_byte
  5094.         cmp     al, 0xC0
  5095.         jae     .1
  5096.         dec     [disasm_cur_pos]
  5097.         shr     al, 3
  5098.         and     eax, 7
  5099.         mov     byte [edi], 'f'
  5100.         inc     edi
  5101.         mov     eax, [fpuD8+eax*4]
  5102.         stosd
  5103.         mov     ax, '  '
  5104.         stosw
  5105.         stosb
  5106.         or      ch, 0A1h        ; qword
  5107.         call    disasm_readrmop
  5108.         and     byte [edi], 0
  5109.         ret
  5110. .1:
  5111.         mov     dl, al
  5112.         shr     al, 3
  5113.         and     eax, 7
  5114.         mov     eax, [fpuDC+eax*4]
  5115.         test    eax, eax
  5116.         jz      cerr
  5117.         mov     byte [edi], 'f'
  5118.         inc     edi
  5119.         stosd
  5120.         mov     eax, '   s'
  5121.         stosd
  5122.         mov     al, 't'
  5123.         stosb
  5124.         and     edx, 7
  5125.         lea     eax, [edx+'0']
  5126.         stosb
  5127.         mov     eax, ', st'
  5128.         stosd
  5129.         mov     ax, '0'
  5130.         stosw
  5131.         ret     ; CF cleared
  5132.  
  5133. iglobal
  5134. fpuDD   dd      'fld ',0,'fst ','fstp',0,0,0,0
  5135. fpuDD_2 dq      'ffree   ',0,'fst     ','fstp    ','fucom   ','fucomp  ',0,0
  5136. endg
  5137. cDD:
  5138.         call    disasm_get_byte
  5139.         cmp     al, 0xC0
  5140.         jae     .1
  5141.         dec     [disasm_cur_pos]
  5142.         shr     al, 3
  5143.         and     eax, 7
  5144.         xchg    eax, edx
  5145.         mov     eax, [fpuDD+edx*4]
  5146.         test    eax, eax
  5147.         jz      cunk
  5148.         stosd
  5149.         mov     eax, '    '
  5150.         stosd
  5151.         or      ch, 0A1h        ; qword operand
  5152.         call    disasm_readrmop
  5153.         and     byte [edi], 0
  5154.         ret
  5155. .1:
  5156.         push    eax
  5157.         shr     al, 3
  5158.         and     eax, 7
  5159.         xchg    eax, edx
  5160.         mov     eax, dword [fpuDD_2+edx*8]
  5161.         test    eax, eax
  5162.         jz      cerr
  5163.         stosd
  5164.         mov     eax, dword [fpuDD_2+4+edx*8]
  5165.         stosd
  5166.         mov     ax, 'st'
  5167.         stosw
  5168.         pop     eax
  5169.         and     al, 7
  5170.         add     al, '0'
  5171.         stosb
  5172.         and     byte [edi], 0
  5173.         ret
  5174.  
  5175. iglobal
  5176. fpuDE   dd      'add ','mul ',0,0,'subr','sub ','divr','div '
  5177. endg
  5178. cDE:
  5179.         call    disasm_get_byte
  5180.         cmp     al, 0xC0
  5181.         jae     .1
  5182.         dec     [disasm_cur_pos]
  5183.         mov     word [edi], 'fi'
  5184.         inc     edi
  5185.         inc     edi
  5186.         shr     al, 3
  5187.         and     eax, 7
  5188.         mov     eax, [fpuD8+eax*4]
  5189.         stosd
  5190.         mov     ax, '  '
  5191.         stosw
  5192.         or      ch, 81h         ; force 16-bit
  5193.         call    disasm_readrmop
  5194.         and     byte [edi], 0
  5195.         ret
  5196. .1:
  5197.         push    eax
  5198.         shr     al, 3
  5199.         and     eax, 7
  5200.         xchg    eax, edx
  5201.         mov     eax, [fpuDE+edx*4]
  5202.         test    eax, eax
  5203.         jz      .fcompp
  5204.         mov     byte [edi], 'f'
  5205.         inc     edi
  5206.         stosd
  5207.         mov     al, 'p'
  5208.         cmp     byte [edi-1], ' '
  5209.         jnz     @f
  5210.         mov     byte [edi-1], al
  5211.         mov     al, ' '
  5212. @@:     stosb
  5213.         mov     eax, '  st'
  5214.         stosd
  5215.         pop     eax
  5216.         and     al, 7
  5217.         add     al, '0'
  5218.         stosb
  5219.         mov     ax, ', '
  5220.         stosw
  5221.         mov     eax, 'st0'
  5222.         stosd
  5223.         ret     ; CF cleared
  5224. .fcompp:
  5225.         pop     eax
  5226.         cmp     al, 0xD9
  5227.         jnz     cerr
  5228.         mov     eax, 'fcom'
  5229.         stosd
  5230.         mov     ax, 'pp'
  5231.         stosw
  5232.         and     byte [edi], 0
  5233.         ret
  5234.  
  5235. iglobal
  5236. fpuDF   dd      'ild ',0,'ist ','istp','bld ','ild ','bstp','istp'
  5237. endg
  5238.  
  5239. cDF:
  5240.         call    disasm_get_byte
  5241.         cmp     al, 0xC0
  5242.         jae     .1
  5243.         dec     [disasm_cur_pos]
  5244.         shr     al, 3
  5245.         and     eax, 7
  5246.         xchg    eax, edx
  5247.         mov     eax, [fpuDF+edx*4]
  5248.         test    eax, eax
  5249.         jz      cerr
  5250.         mov     byte [edi], 'f'
  5251.         inc     edi
  5252.         stosd
  5253.         mov     ax, '  '
  5254.         stosw
  5255.         stosb
  5256.         or      ch, 81h         ; force 16-bit operand
  5257.         cmp     dl, 4
  5258.         jb      @f
  5259.         or      ch, 20h
  5260.         test    dl, 1
  5261.         jnz     @f
  5262.         or      ch, 40h
  5263. @@:
  5264.         call    disasm_readrmop
  5265.         and     byte [edi], 0
  5266.         ret
  5267. .1:
  5268.         cmp     al, 0xE0
  5269.         jnz     cunk
  5270.         mov     eax, 'fnst'
  5271.         stosd
  5272.         mov     eax, 'sw  '
  5273.         stosd
  5274.         mov     ax, 'ax'
  5275.         stosw
  5276.         and     byte [edi], 0
  5277.         ret
  5278.  
  5279. cmovd1:
  5280.         mov     eax, 'movd'
  5281.         stosd
  5282.         mov     eax, '    '
  5283.         stosd
  5284.         call    disasm_get_byte
  5285.         dec     [disasm_cur_pos]
  5286.         shr     al, 3
  5287.         and     eax, 7
  5288.         call    disasm_write_mmreg
  5289.         mov     ax, ', '
  5290.         stosw
  5291.         or      ch, 0C0h
  5292.         and     ch, not 1
  5293.         call    disasm_readrmop
  5294.         and     byte [edi], 0
  5295.         ret
  5296. cmovd2:
  5297.         mov     eax, 'movd'
  5298.         stosd
  5299.         mov     eax, '    '
  5300.         stosd
  5301.         call    disasm_get_byte
  5302.         dec     [disasm_cur_pos]
  5303.         shr     al, 3
  5304.         and     eax, 7
  5305.         push    eax ecx
  5306.         or      ch, 0C0h
  5307.         and     ch, not 1
  5308.         call    disasm_readrmop
  5309.         mov     ax, ', '
  5310.         stosw
  5311.         pop     ecx eax
  5312.         call    disasm_write_mmreg
  5313.         and     byte [edi], 0
  5314.         ret
  5315.  
  5316. cmovq1:
  5317.         test    ch, 1
  5318.         jz      .mm
  5319.         mov     eax, 'movd'
  5320.         stosd
  5321.         mov     eax, 'qa  '
  5322.         stosd
  5323.         jmp     disasm_mmx1
  5324. .mm:
  5325.         mov     eax, 'movq'
  5326.         stosd
  5327.         mov     eax, '    '
  5328.         stosd
  5329.         jmp     disasm_mmx1
  5330. cmovq2:
  5331.         test    ch, 1
  5332.         jz      .mm
  5333.         mov     eax, 'movd'
  5334.         stosd
  5335.         mov     eax, 'qa  '
  5336.         stosd
  5337.         jmp     disasm_mmx3
  5338. .mm:
  5339.         mov     eax, 'movq'
  5340. disasm_mmx2:
  5341.         stosd
  5342.         mov     eax, '    '
  5343.         stosd
  5344. disasm_mmx3:
  5345.         or      ch, 50h
  5346.         call    disasm_get_byte
  5347.         dec     [disasm_cur_pos]
  5348.         push    eax
  5349.         call    disasm_readrmop
  5350.         mov     ax, ', '
  5351.         stosw
  5352.         pop     eax
  5353.         shr     al, 3
  5354.         and     eax, 7
  5355.         call    disasm_write_mmreg
  5356.         and     byte [edi], 0
  5357.         ret
  5358.  
  5359. iglobal
  5360. mmx_cmds:
  5361.         db      0x60,'unpcklbw'
  5362.         db      0x61,'unpcklwd'
  5363.         db      0x62,'unpckldq'
  5364.         db      0x63,'packsswb'
  5365.         db      0x64,'pcmpgtb '
  5366.         db      0x65,'pcmpgtw '
  5367.         db      0x66,'pcmpgtd '
  5368.         db      0x67,'packuswb'
  5369.         db      0x68,'unpckhbw'
  5370.         db      0x69,'unpckhwd'
  5371.         db      0x6A,'unpckhdq'
  5372.         db      0x6B,'packssdw'
  5373.         db      0x74,'pcmpeqb '
  5374.         db      0x75,'pcmpeqw '
  5375.         db      0x76,'pcmpeqd '
  5376.         db      0xD4,'paddq   '
  5377.         db      0xD5,'pmullw  '
  5378.         db      0xD8,'psubusb '
  5379.         db      0xD9,'psubusw '
  5380.         db      0xDA,'pminub  '
  5381.         db      0xDB,'pand    '
  5382.         db      0xDC,'paddusb '
  5383.         db      0xDD,'paddusw '
  5384.         db      0xDE,'pmaxub  '
  5385.         db      0xDF,'pandn   '
  5386.         db      0xE0,'pavgb   '
  5387.         db      0xE3,'pavgw   '
  5388.         db      0xE4,'pmulhuw '
  5389.         db      0xE5,'pmulhw  '
  5390.         db      0xE8,'psubsb  '
  5391.         db      0xE9,'psubsw  '
  5392.         db      0xEA,'pminsw  '
  5393.         db      0xEB,'por     '
  5394.         db      0xEC,'paddsb  '
  5395.         db      0xED,'paddsw  '
  5396.         db      0xEE,'pmaxsw  '
  5397.         db      0xEF,'pxor    '
  5398.         db      0xF4,'pmuludq '
  5399.         db      0xF5,'pmaddwd '
  5400.         db      0xF6,'psadbw  '
  5401.         db      0xF8,'psubb   '
  5402.         db      0xF9,'psubw   '
  5403.         db      0xFA,'psubd   '
  5404.         db      0xFB,'psubq   '
  5405.         db      0xFC,'paddb   '
  5406.         db      0xFD,'paddw   '
  5407.         db      0xFE,'paddd   '
  5408. endg
  5409. cpcmn:
  5410.         mov     esi, mmx_cmds
  5411. @@:
  5412.         cmp     al, [esi]
  5413.         jz      @f
  5414.         add     esi, 9
  5415.         jmp     @b
  5416. @@:
  5417.         inc     esi
  5418.         mov     al, 'p'
  5419.         cmp     byte [esi], al
  5420.         jz      @f
  5421.         stosb
  5422. @@:
  5423.         movsd
  5424.         movsd
  5425.         cmp     byte [edi-1], ' '
  5426.         jz      @f
  5427.         mov     al, ' '
  5428.         stosb
  5429. @@:
  5430.  
  5431. disasm_mmx1:
  5432.         or      ch, 50h
  5433.         call    disasm_get_byte
  5434.         dec     [disasm_cur_pos]
  5435.         shr     al, 3
  5436.         and     eax, 7
  5437.         call    disasm_write_mmreg
  5438.         mov     ax, ', '
  5439.         stosw
  5440.         call    disasm_readrmop
  5441.         cmp     word [disasm_string], 'cm'
  5442.         jz      .cmp
  5443.         and     byte [edi], 0
  5444.         ret
  5445. .cmp:
  5446.         call    disasm_get_byte
  5447.         and     eax, 7
  5448.         mov     dx, 'eq'
  5449.         dec     eax
  5450.         js      @f
  5451.         mov     dx, 'lt'
  5452.         jz      @f
  5453.         mov     dh, 'e'
  5454.         dec     eax
  5455.         jnz     .no2
  5456. @@:
  5457.         xchg    dx, word [disasm_string+3]
  5458.         mov     word [disasm_string+5], dx
  5459.         and     byte [edi], 0
  5460.         ret
  5461. .no2:
  5462.         dec     eax
  5463.         jnz     @f
  5464.         add     edi, 2
  5465.         push    edi
  5466.         lea     esi, [edi-3]
  5467.         lea     ecx, [esi-(disasm_string+8)+2]
  5468.         std
  5469.         rep     movsb
  5470.         cld
  5471.         mov     cx, word [esi-3]
  5472.         mov     dword [esi-3], 'unor'
  5473.         mov     byte [esi+1], 'd'
  5474.         mov     word [esi+2], cx
  5475.         pop     edi
  5476.         and     byte [edi+1], 0
  5477.         ret
  5478. @@:
  5479.         mov     edx, 'neq'
  5480.         dec     eax
  5481.         jz      @f
  5482.         mov     edx, 'nlt'
  5483.         dec     eax
  5484.         jz      @f
  5485.         mov     edx, 'nle'
  5486.         dec     eax
  5487.         jz      @f
  5488.         mov     edx, 'ord'
  5489. @@:
  5490.         push    edi
  5491.         lea     esi, [edi-1]
  5492.         lea     ecx, [esi-(disasm_string+8)+2]
  5493.         std
  5494.         rep     movsb
  5495.         cld
  5496.         mov     cx, word [esi-3]
  5497.         mov     dword [esi-3], edx
  5498.         mov     word [esi], cx
  5499.         pop     edi
  5500.         and     byte [edi+1], 0
  5501.         ret
  5502.  
  5503. cpsrlw:
  5504.         mov     eax, 'psrl'
  5505.         jmp     @f
  5506. cpsraw:
  5507.         mov     eax, 'psra'
  5508.         jmp     @f
  5509. cpsllw:
  5510.         mov     eax, 'psll'
  5511. @@:
  5512.         stosd
  5513.         mov     eax, 'w   '
  5514.         stosd
  5515.         jmp     disasm_mmx1
  5516. cpsrld:
  5517.         mov     eax, 'psrl'
  5518.         jmp     @f
  5519. cpsrad:
  5520.         mov     eax, 'psra'
  5521.         jmp     @f
  5522. cpslld:
  5523.         mov     eax, 'psll'
  5524. @@:
  5525.         stosd
  5526.         mov     eax, 'd   '
  5527.         stosd
  5528.         jmp     disasm_mmx1
  5529. cpsrlq:
  5530.         mov     eax, 'psrl'
  5531.         jmp     @f
  5532. cpsllq:
  5533.         mov     eax, 'psll'
  5534. @@:
  5535.         stosd
  5536.         mov     eax, 'q   '
  5537.         stosd
  5538.         jmp     disasm_mmx1
  5539.  
  5540. csse1:
  5541. iglobal
  5542. sse_cmds1:
  5543.         db      0x2F,4,'comi'
  5544.         db      0x54,3,'and'
  5545.         db      0x55,4,'andn'
  5546.         db      0x58,3,'add'
  5547.         db      0xC2,3,'cmp'
  5548. endg
  5549.         mov     esi, sse_cmds1+1
  5550. .1:
  5551. @@:
  5552.         movzx   edx, byte [esi]
  5553.         cmp     al, [esi-1]
  5554.         jz      @f
  5555.         lea     esi, [esi+edx+2]
  5556.         jmp     @b
  5557. @@:
  5558.         push    ecx
  5559.         mov     ecx, edx
  5560.         inc     esi
  5561.         rep     movsb
  5562.         pop     ecx
  5563.         mov     al, 's'
  5564.         cmp     byte [edi-1], 'i'
  5565.         jz      @f
  5566.         mov     al, 'p'
  5567. @@:
  5568.         stosb
  5569.         mov     al, 'd'
  5570.         test    ch, 1
  5571.         jnz     @f
  5572.         mov     al, 's'
  5573. @@:
  5574.         stosb
  5575.         push    ecx
  5576.         push    5
  5577.         pop     ecx
  5578.         sub     ecx, edx
  5579.         adc     ecx, 1
  5580.         mov     al, ' '
  5581.         rep     stosb
  5582.         pop     ecx
  5583.         or      ch, 1           ; force XMM reg
  5584.         jmp     disasm_mmx1
  5585.  
  5586. csse2:
  5587. iglobal
  5588. sse_cmds2:
  5589.         db      0xD0,6,'addsub'
  5590.         db      0,0
  5591. endg
  5592.         test    ch, 1
  5593.         jz      cerr
  5594.         mov     esi, sse_cmds2+1
  5595.         jmp     csse1.1
  5596.  
  5597. cpshift:
  5598.         mov     dl, al
  5599.         mov     ax, 'ps'
  5600.         stosw
  5601.         call    disasm_get_byte
  5602.         push    eax
  5603.         and     al, 0xC0
  5604.         cmp     al, 0xC0
  5605.         jnz     .pop_cunk
  5606.         pop     eax
  5607.         push    eax
  5608.         shr     al, 3
  5609.         and     eax, 7
  5610.         cmp     al, 2
  5611.         jz      .rl
  5612.         cmp     al, 4
  5613.         jz      .ra
  5614.         cmp     al, 6
  5615.         jz      .ll
  5616. .pop_cunk:
  5617.         pop     eax
  5618.         jmp     cunk
  5619. .ll:
  5620.         mov     ax, 'll'
  5621.         jmp     @f
  5622. .rl:
  5623.         mov     ax, 'rl'
  5624.         jmp     @f
  5625. .ra:
  5626.         cmp     dl, 0x73
  5627.         jz      .pop_cunk
  5628.         mov     ax, 'ra'
  5629. @@:
  5630.         stosw
  5631.         mov     al, 'w'
  5632.         cmp     dl, 0x71
  5633.         jz      @f
  5634.         mov     al, 'd'
  5635.         cmp     dl, 0x72
  5636.         jz      @f
  5637.         mov     al, 'q'
  5638. @@:
  5639.         stosb
  5640.         mov     ax, '  '
  5641.         stosw
  5642.         stosb
  5643.         pop     eax
  5644.         and     eax, 7
  5645.         call    disasm_write_mmreg
  5646.         mov     ax, ', '
  5647.         stosw
  5648.         xor     eax, eax
  5649.         call    disasm_get_byte
  5650.         call    disasm_write_num
  5651.         and     byte [edi], 0
  5652.         ret
  5653.  
  5654. iglobal
  5655. grp15c1 dq      'fxsave  ','fxrstor ','ldmxcsr ','stmxcsr ',0,0,0,'clflush '
  5656. endg
  5657. cgrp15:
  5658.         call    disasm_get_byte
  5659.         cmp     al, 0xC0
  5660.         jae     cunk
  5661.         shr     al, 3
  5662.         and     eax, 7
  5663.         mov     edx, eax
  5664.         mov     eax, dword [grp15c1+eax*8]
  5665.         test    eax, eax
  5666.         jz      cerr
  5667.         dec     [disasm_cur_pos]
  5668.         stosd
  5669.         mov     eax, dword [grp15c1+4+edx*8]
  5670.         stosd
  5671.         or      ch, 40h
  5672.         call    disasm_readrmop
  5673.         and     byte [edi], 0
  5674.         ret
  5675.  
  5676. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5677. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5678. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5679.  
  5680. caption_str db 'Kolibri Debugger',0
  5681. caption_len = $ - caption_str
  5682. begin_str db    'Kolibri Debugger, version 0.32',10
  5683.         db      'Hint: type "help" for help, "quit" for quit'
  5684. newline db      10,0
  5685. prompt  db      '> ',0
  5686.  
  5687. help_groups:
  5688.         dd      aControl, 0, 0, help_control_msg
  5689.         db      0
  5690.         dd      aData, 0, 0, help_data_msg
  5691.         db      0
  5692.         dd      aBreakpoints, 0, 0, help_breaks_msg
  5693.         db      0
  5694. ; flags field:
  5695. ; &1: command may be called without parameters
  5696. ; &2: command may be called with parameters
  5697. ; &4: command may be called without loaded program
  5698. ; &8: command may be called with loaded program
  5699. commands:
  5700.         dd      _aH, OnHelp, HelpSyntax, HelpHelp
  5701.         db      0Fh
  5702.         dd      aHelp, OnHelp, HelpSyntax, HelpHelp
  5703.         db      0Fh
  5704.         dd      aQuit, OnQuit, QuitSyntax, QuitHelp
  5705.         db      0Dh
  5706.         dd      aLoad, OnLoad, LoadSyntax, LoadHelp
  5707.         db      6
  5708.         dd      aReload, OnReload, ReloadSyntax, ReloadHelp
  5709.         db      0Dh
  5710.         dd      aTerminate, OnTerminate, TerminateSyntax, TerminateHelp
  5711.         db      9
  5712.         dd      aDetach, OnDetach, DetachSyntax, DetachHelp
  5713.         db      9
  5714.         dd      aSuspend, OnSuspend, SuspendSyntax, SuspendHelp
  5715.         db      9
  5716.         dd      aResume, OnResume, ResumeSyntax, ResumeHelp
  5717.         db      0Bh
  5718.         dd      aStep, OnStep, StepSyntax, StepHelp
  5719.         db      9
  5720.         dd      aProceed, OnProceed, ProceedSyntax, ProceedHelp
  5721.         db      9
  5722.         dd      aCalc, OnCalc, CalcSyntax, CalcHelp
  5723.         db      0Eh
  5724.         dd      aDump, OnDump, DumpSyntax, DumpHelp
  5725.         db      0Bh
  5726.         dd      aUnassemble, OnUnassemble, UnassembleSyntax, UnassembleHelp
  5727.         db      0Bh
  5728.         dd      aBp, OnBp, BpSyntax, BpHelp
  5729.         db      0Ah
  5730.         dd      aBpm, OnBpmb, BpmSyntax, BpmHelp
  5731.         db      0Ah
  5732.         dd      aBpmb, OnBpmb, BpmSyntax, BpmHelp
  5733.         db      0Ah
  5734.         dd      aBpmw, OnBpmw, BpmSyntax, BpmHelp
  5735.         db      0Ah
  5736.         dd      aBpmd, OnBpmd, BpmSyntax, BpmHelp
  5737.         db      0Ah
  5738.         dd      aBl, OnBl, BlSyntax, BlHelp
  5739.         db      0Bh
  5740.         dd      aBc, OnBc, BcSyntax, BcHelp
  5741.         db      0Ah
  5742.         dd      aBd, OnBd, BdSyntax, BdHelp
  5743.         db      0Ah
  5744.         dd      aBe, OnBe, BeSyntax, BeHelp
  5745.         db      0Ah
  5746.         dd      aReg, OnReg, RSyntax, RHelp
  5747.         db      0Ah
  5748.         dd      aUnpack, OnUnpack, UnpackSyntax, UnpackHelp
  5749.         db      9
  5750.         dd      aLoadSymbols, OnLoadSymbols, LoadSymbolsSyntax, LoadSymbolsHelp
  5751.         db      0Ah
  5752.         dd      0
  5753. aHelp   db      5,'help',0
  5754. _aH     db      2,'h',0
  5755. HelpHelp db     'Help on specified function',10
  5756. HelpSyntax db   'Usage: h or help [group | command]',10,0
  5757.  
  5758. help_msg db     'List of known command groups:',10
  5759.         db      '"help control"     - display list of control commands',10
  5760.         db      '"help data"        - display list of commands concerning data',10
  5761.         db      '"help breakpoints" - display list of commands concerning breakpoints',10,0
  5762. aControl db     8,'control',0
  5763. help_control_msg db     'List of control commands:',10
  5764.         db      'h = help             - help',10
  5765.         db      'quit                 - exit from debugger',10
  5766.         db      'load <name> [params] - load program for debugging',10
  5767.         db      'reload               - reload debugging program',10
  5768.         db      'load-symbols <name>  - load information on symbols for program',10
  5769.         db      'terminate            - terminate loaded program',10
  5770.         db      'detach               - detach from debugging program',10
  5771.         db      'stop                 - suspend execution of debugging program',10
  5772.         db      'g [<expression>]     - go on (resume execution of debugging program)',10
  5773.         db      's = <Ctrl+F7>        - program step',10
  5774.         db      'p = <Ctrl+F8>        - program wide step',10
  5775.         db      'unpack               - try to bypass unpacker code (heuristic)',10,0
  5776. aData   db      5,'data',0
  5777. help_data_msg db        'List of data commands:',10
  5778.         db      '? <expression>       - calculate value of expression',10
  5779.         db      'd [<expression>]     - dump data at given address',10
  5780.         db      'u [<expression>]     - unassemble instructions at given address',10
  5781.         db      'r <register> <expression> or',10
  5782.         db      'r <register>=<expression> - set register value',10,0
  5783. aBreakpoints db 12,'breakpoints',0
  5784. help_breaks_msg db      'List of breakpoints commands:',10
  5785.         db      'bp <expression>      - set breakpoint on execution',10
  5786.         db      'bpm[b|w|d] <type> <expression> - set breakpoint on memory access',10
  5787.         db      'bl [<number>]        - breakpoint(s) info',10
  5788.         db      'bc <number>...       - clear breakpoint',10
  5789.         db      'bd <number>...       - disable breakpoint',10
  5790.         db      'be <number>...       - enable breakpoint',10,0
  5791.  
  5792. aQuit   db      5,'quit',0
  5793. QuitHelp db     'Quit from debugger',10
  5794. QuitSyntax db   'Usage: quit',10,0
  5795.  
  5796. aLoad   db      5,'load',0
  5797. LoadHelp db     'Load program for debugging',10
  5798. LoadSyntax db   'Usage: load <program-name> [parameters]',10,0
  5799.  
  5800. aReload db      7,'reload',0
  5801. ReloadHelp db   'Reload debugging program (restart debug session)',10
  5802. ReloadSyntax db 'Usage: reload',10,0
  5803.  
  5804. aTerminate db   10,'terminate',0
  5805. TerminateHelp db 'Terminate debugged program',10
  5806. TerminateSyntax db 'Usage: terminate',10,0
  5807.  
  5808. aDetach db      7,'detach',0
  5809. DetachHelp db   'Detach from debugged program',10
  5810. DetachSyntax db 'Usage: detach',10,0
  5811.  
  5812. aSuspend db     5,'stop',0
  5813. SuspendHelp db  'Suspend execution of debugged program',10
  5814. SuspendSyntax db 'Usage: stop',10,0
  5815.  
  5816. aResume db      2,'g',0
  5817. ResumeHelp db   'Go (resume execution of debugged program)',10
  5818. ResumeSyntax db 'Usage: g',10
  5819.         db      '   or: g <expression> - wait until specified address is reached',10,0
  5820.  
  5821. aStep   db      2,'s',0
  5822. StepHelp db     'Make step in debugged program',10
  5823. StepSyntax db   'Usage: s',10,0
  5824.  
  5825. aProceed db     2,'p',0
  5826. ProceedHelp db  'Make wide step in debugged program (step over CALL, REPxx, LOOP)',10
  5827. ProceedSyntax db 'Usage: p',10,0
  5828.  
  5829. aDump   db      2,'d',0
  5830. DumpHelp db     'Dump data of debugged program',10
  5831. DumpSyntax db   'Usage: d <expression> - dump data at specified address',10
  5832.         db      '   or: d              - continue current dump',10,0
  5833.  
  5834. aCalc   db      2,'?',0
  5835. CalcHelp db     'Calculate value of expression',10
  5836. CalcSyntax db   'Usage: ? <expression>',10,0
  5837.  
  5838. aUnassemble db  2,'u',0
  5839. UnassembleHelp db 'Unassemble',10
  5840. UnassembleSyntax:
  5841.         db      'Usage: u <expression> - unassemble instructions at specified address',10
  5842.         db      '   or: u              - continue current unassemble screen',10,0
  5843.  
  5844. aReg    db      2,'r',0
  5845. RHelp   db      'Set register value',10
  5846. RSyntax:
  5847.         db      'Usage: r <register> <expression>',10
  5848.         db      '   or: r <register>=<expression> - set value of <register> to <expression>',10,0
  5849.  
  5850. aBp     db      3,'bp',0
  5851. BpHelp  db      'set BreakPoint on execution',10
  5852. BpSyntax db     'Usage: bp <expression>',10,0
  5853.  
  5854. aBpm    db      4,'bpm',0
  5855. aBpmb   db      5,'bpmb',0
  5856. aBpmw   db      5,'bpmw',0
  5857. aBpmd   db      5,'bpmd',0
  5858. BpmHelp db      'set BreakPoint on Memory access',10
  5859.         db      'Maximum 4 breakpoints of this type are allowed',10
  5860.         db      'Note that for this breaks debugger is activated after access',10
  5861. BpmSyntax db    'Usage: bpmb [w] <expression>',10
  5862.         db      '       bpmw [w] <expression>',10
  5863.         db      '       bpmd [w] <expression>',10
  5864.         db      '       bpm is synonym for bpmd',10
  5865.         db      '"w" means break only on writes (default is on read/write)',10,0
  5866.  
  5867. aBl     db      3,'bl',0
  5868. BlHelp  db      'Breakpoint List',10
  5869. BlSyntax db     'Usage: bl          - list all breakpoints',10
  5870.         db      '       bl <number> - display info on particular breakpoint',10,0
  5871.  
  5872. aBc     db      3,'bc',0
  5873. BcHelp  db      'Breakpoint Clear',10
  5874. BcSyntax db     'Usage: bc <number-list>',10
  5875.         db      'Examples: bc 2',10
  5876.         db      '          bc 1 3 4 A',10,0
  5877.  
  5878. aBd     db      3,'bd',0
  5879. BdHelp  db      'Breakpoint Disable',10
  5880. BdSyntax db     'Usage: bd <number-list>',10
  5881.         db      'Examples: bd 2',10
  5882.         db      '          bd 1 3 4 A',10,0
  5883.  
  5884. aBe     db      3,'be',0
  5885. BeHelp  db      'Breakpoint Enable',10
  5886. BeSyntax db     'Usage: be <number-list>',10
  5887.         db      'Examples: be 2',10
  5888.         db      '          be 1 3 4 A',10,0
  5889.  
  5890. aUnpack db      7,'unpack',0
  5891. UnpackHelp db   'Try to bypass unpacker code',10
  5892. UnpackSyntax db 'Usage: unpack',10,0
  5893.  
  5894. aLoadSymbols db 13,'load-symbols',0
  5895. LoadSymbolsHelp db 'Load symbolic information for executable',10
  5896. LoadSymbolsSyntax db 'Usage: load-symbols <symbols-file-name>',10,0
  5897.  
  5898. aUnknownCommand db 'Unknown command',10,0
  5899.  
  5900. load_err_msg    db      'Cannot load program. ',0
  5901. unk_err_msg     db      'Unknown error code -%4X',10,0
  5902. aCannotLoadFile db      'Cannot load file. ',0
  5903. unk_err_msg2    db      'Unknown error code %4X.',10,0
  5904. load_err_msgs:
  5905.         dd      .1, 0, .3, 0, .5, .6, 0, 0, .9, .A, 0, 0, 0, 0, 0, 0
  5906.         dd      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, .1E, .1F, .20
  5907. .1              db      'HD undefined.',10,0
  5908. .3              db      'Unknown FS.',10,0
  5909. .5              db      'File not found.',10,0
  5910. .6              db      'Unexpected EOF.',10,0
  5911. .9              db      'FAT table corrupted.',10,0
  5912. .A              db      'Access denied.',10,0
  5913. .1E             db      'No memory.',10,0
  5914. .1F             db      'Not Menuet/Kolibri executable.',10,0
  5915. .20             db      'Too many processes.',10,0
  5916. load_succ_msg   db      'Program loaded successfully! PID=%4X. Use "g" to run.',10,0
  5917. need_debuggee   db      'No program loaded. Use "load" command.',10,0
  5918. aAlreadyLoaded  db      'Program is already loaded. Use "terminate" or "detach" commands',10,0
  5919. terminated_msg  db      'Program terminated.',10,0
  5920. aException      db      'Debugged program caused an exception %2X. '
  5921. aSuspended      db      'Suspended',10,0
  5922. aContinued      db      'Continuing',10,0
  5923. aRunningErr     db      'Program is running',10,0
  5924. read_mem_err    db      'ERROR: cannot read process memory!!!',10,0
  5925. aBreakpointLimitExceeded db 'Breakpoint limit exceeded',10,0
  5926. aBreakErr       db      'Cannot activate breakpoint, it will be disabled',10,0
  5927. aDuplicateBreakpoint db 'Duplicate breakpoint',10,0
  5928. aInvalidBreak   db      'Invalid breakpoint number',10,0
  5929. OnBeErrMsg      db      'There is already enabled breakpoint on this address',10,0
  5930. aBreakNum       db      '%2X: at %8X',0
  5931. aMemBreak1      db      '%2X: on ',0
  5932. aMemBreak2      db      'read from ',0
  5933. aMemBreak3      db      'access of ',0
  5934. aMemBreak4      db      'byte',0
  5935. aMemBreak5      db      'word',0
  5936. aMemBreak6      db      'dword',0
  5937. aMemBreak7      db      ' at %8X',0
  5938. aOneShot        db      ', one-shot',0
  5939. aDisabled       db      ', disabled',0
  5940. aBreakStop      db      'Breakpoint #%2X',10,0
  5941. aUserBreak      db      'int3 command at %8X',10,0
  5942. ;dbgmsg_str     db      'Debug message for process %4X.',10,0
  5943. aInvAddr        db      'Invalid address',10,0
  5944. NoPrgLoaded_str db      'No program loaded'
  5945. NoPrgLoaded_len = $ - NoPrgLoaded_str
  5946. aRunning        db      'Running'
  5947. aPaused         db      'Paused'
  5948. aPoint          db      0x1C
  5949. aMinus          db      '-'
  5950. aColon          db      ':'
  5951. aSpace          db      ' '
  5952. aQuests         db      '??'
  5953. aDots           db      '...'
  5954. aParseError     db      'Parse error',10,0
  5955. aDivByZero      db      'Division by 0',10,0
  5956. calc_string     db      '%8X',10,0
  5957. aNoMemory       db      'No memory',10,0
  5958. aSymbolsLoaded  db      'Symbols loaded',10,0
  5959. aUnaligned      db      'Unaligned address',10,0
  5960. aEnabledBreakErr db     'Enabled breakpoints are not allowed',10,0
  5961. aInterrupted    db      'Interrupted',10,0
  5962. aUnpacked       db      'Unpacked successful!',10,0
  5963. aPacked1        db      'Program is probably packed with ',0
  5964. aPacked2        db      '.',10,'Try to unpack automatically? [y/n]: ',0
  5965. aY_str          db      'y',10,0
  5966. aN_str          db      'n',10,0
  5967. mxp_nrv_name    db      'mxp_nrv',0
  5968. mxp_name        db      'mxp',0
  5969. mxp_lzo_name    db      'mxp_lzo',0
  5970. mtappack_name   db      'mtappack',0
  5971. flags           db      'CPAZSDO'
  5972. flags_bits      db      0,2,4,6,7,10,11
  5973. regs_strs:
  5974.         db      'EAX='
  5975.         db      'EBX='
  5976.         db      'ECX='
  5977.         db      'EDX='
  5978.         db      'ESI='
  5979.         db      'EDI='
  5980.         db      'EBP='
  5981.         db      'ESP='
  5982.         db      'EIP='
  5983.         db      'EFLAGS='
  5984.  
  5985. debuggee_pid    dd      0
  5986. bSuspended      db      0
  5987. bAfterGo        db      0
  5988. temp_break      dd      0
  5989.  
  5990. disasm_table_1:
  5991.         dd      cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cop0           ; 0x
  5992.         dd      cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cF
  5993.         dd      cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cop0           ; 1x
  5994.         dd      cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cop0
  5995.         dd      cop22, cop22, cop22, cop22, cop21, cop21, cseges,cop0           ; 2x
  5996.         dd      cop22, cop22, cop22, cop22, cop21, cop21, csegcs,cop0
  5997.         dd      cop22, cop22, cop22, cop22, cop21, cop21, csegss,cop0           ; 3x
  5998.         dd      cop22, cop22, cop22, cop22, cop21, cop21, csegds,cop0
  5999.         dd      cinc1, cinc1, cinc1, cinc1, cinc1, cinc1, cinc1, cinc1          ; 4x
  6000.         dd      cdec1, cdec1, cdec1, cdec1, cdec1, cdec1, cdec1, cdec1
  6001.         dd      cpush1,cpush1,cpush1,cpush1,cpush1,cpush1,cpush1,cpush1         ; 5x
  6002.         dd      cpop1, cpop1, cpop1, cpop1, cpop1, cpop1, cpop1, cpop1
  6003.         dd      cop0,  cop0,  cbound,carpl, csegfs,cseggs,c66,   c67            ; 6x
  6004.         dd      cpush21,cimul1,cpush22,cimul1,cunk,cunk,  cunk,  cunk
  6005.         dd      cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1          ; 7x
  6006.         dd      cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1
  6007.         dd      cop23, cop23, cop23, cop23, cop22, cop22, cop22, cop22          ; 8x
  6008.         dd      cop22, cop22, cop22, cop22, cunk,  cop22, cunk,  cpop2
  6009.         dd      cop0,  cxchg1,cxchg1,cxchg1,cxchg1,cxchg1,cxchg1,cxchg1         ; 9x
  6010.         dd      ccbw,  ccwd,  ccallf,cop0,  cop0,  cop0,  cop0,  cop0
  6011.         dd      cmov3, cmov3, cmov3, cmov3, cop0,  cop0,  cop0,  cop0           ; Ax
  6012.         dd      cop21, cop21, cop0,  cop0,  cop0,  cop0,  cop0,  cop0
  6013.         dd      cmov11,cmov11,cmov11,cmov11,cmov11,cmov11,cmov11,cmov11         ; Bx
  6014.         dd      cmov12,cmov12,cmov12,cmov12,cmov12,cmov12,cmov12,cmov12
  6015.         dd      cshift1,cshift1,cret2,cop0, cunk,  cunk,  cmov2, cmov2          ; Cx
  6016.         dd      center,cop0,  cunk,  cunk,  cop0,  cint,  cunk,  cunk
  6017.         dd      cshift2,cshift2,cshift3,cshift3,caam,caad,cunk,  cxlat          ; Dx
  6018.         dd      cD8,   cD9,   cDA,   cDB,   cDC,   cDD,   cDE,   cDF
  6019.         dd      cloopnz,cloopz,cloop,cjcxz, cunk,  cunk,  cunk,  cunk           ; Ex
  6020.         dd      ccall1,cjmp1, cunk,  cjmp2, cunk,  cunk,  cunk,  cunk
  6021.         dd      clock, cunk,  crepnz,crep,  cunk,  cop0,  cop1,  cop1           ; Fx
  6022.         dd      cop0,  cop0,  cop0,  cop0,  cop0,  cop0,  cop1,  cop1
  6023.  
  6024. disasm_table_2:
  6025.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cop0_F,cop0_F,cunk           ; 0x
  6026.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  6027.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk           ; 1x
  6028.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  6029.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk           ; 2x
  6030.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  csse1
  6031.         dd      cunk,  crdtsc,cunk,  cunk,  cop0_F,cunk,  cunk,  cunk           ; 3x
  6032.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  6033.         dd      cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc         ; 4x
  6034.         dd      cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc
  6035.         dd      cunk,  cunk,  cunk,  cunk,  csse1, csse1, cunk,  cunk           ; 5x
  6036.         dd      csse1, cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  6037.         dd      cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn          ; 6x
  6038.         dd      cpcmn, cpcmn, cpcmn, cpcmn, cunk,  cunk,  cmovd1,cmovq1
  6039.         dd      cunk,  cpshift,cpshift,cpshift,cpcmn,cpcmn,cpcmn,cemms          ; 7x
  6040.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cmovd2,cmovq2
  6041.         dd      cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2          ; 8x
  6042.         dd      cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2
  6043.         dd      csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc         ; 9x
  6044.         dd      csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc
  6045.         dd      cunk,  cunk,  ccpuid,cbtx2, cshld, cshld, cunk,  cunk           ; Ax
  6046.         dd      cunk,  cunk,  cunk,  cbtx2, cshrd, cshrd, cgrp15,cop22
  6047.         dd      ccmpxchg,ccmpxchg,cunk,cbtx2,cunk, cunk,  cmovzx,cmovzx         ; Bx
  6048.         dd      cunk,  cunk,  cbtx1, cbtx2, cbsf,  cbsr,  cmovsx,cmovsx
  6049.         dd      cunk,  cunk,  csse1, cunk,  cunk,  cunk,  cunk,  ccmpxchg8b     ; Cx
  6050.         dd      cbswap,cbswap,cbswap,cbswap,cbswap,cbswap,cbswap,cbswap
  6051.         dd      csse2, cpsrlw,cpsrlw,cpsrlq,cpcmn, cpcmn, cunk,  cunk           ; Dx
  6052.         dd      cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn
  6053.         dd      cpcmn, cpsraw,cpsrad,cpcmn, cpcmn, cpcmn, cunk,  cunk           ; Ex
  6054.         dd      cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn
  6055.         dd      cunk,  cpsllw,cpslld,cpsllq,cpcmn, cpcmn, cpcmn, cunk           ; Fx
  6056.         dd      cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cunk
  6057.  
  6058. reg_table:
  6059.         db      2,'al',0
  6060.         db      2,'cl',1
  6061.         db      2,'dl',2
  6062.         db      2,'bl',3
  6063.         db      2,'ah',4
  6064.         db      2,'ch',5
  6065.         db      2,'dh',6
  6066.         db      2,'bh',7
  6067.         db      2,'ax',8
  6068.         db      2,'cx',9
  6069.         db      2,'dx',10
  6070.         db      2,'bx',11
  6071.         db      2,'sp',12
  6072.         db      2,'bp',13
  6073.         db      2,'si',14
  6074.         db      2,'di',15
  6075.         db      3,'eax',16
  6076.         db      3,'ecx',17
  6077.         db      3,'edx',18
  6078.         db      3,'ebx',19
  6079.         db      3,'esp',20
  6080.         db      3,'ebp',21
  6081.         db      3,'esi',22
  6082.         db      3,'edi',23
  6083.         db      3,'eip',24
  6084.         db      0
  6085.  
  6086. IncludeIGlobals
  6087.  
  6088. fn70_read_block:
  6089.         dd      0
  6090.         dq      0
  6091.         dd      ?
  6092.         dd      ?
  6093.         db      0
  6094.         dd      ?
  6095.  
  6096. fn70_attr_block:
  6097.         dd      5
  6098.         dd      0,0,0
  6099.         dd      fileattr
  6100.         db      0
  6101.         dd      ?
  6102.  
  6103. fn70_load_block:
  6104.         dd      7
  6105.         dd      1
  6106. load_params dd  0
  6107.         dd      0
  6108.         dd      0
  6109. i_end:
  6110. loadname:
  6111.         db      0
  6112.         rb      255
  6113.  
  6114. symbolsfile     rb      260
  6115.  
  6116. prgname_ptr dd ?
  6117. prgname_len dd ?
  6118.  
  6119. IncludeUGlobals
  6120.  
  6121. dbgwnd          dd      ?
  6122.  
  6123. messages        rb      messages_height*messages_width
  6124. messages_pos    dd      ?
  6125.  
  6126. cmdline         rb      cmdline_width+1
  6127. cmdline_len     dd      ?
  6128. cmdline_pos     dd      ?
  6129. curarg          dd      ?
  6130.  
  6131. was_temp_break  db      ?
  6132.  
  6133. dbgbufsize      dd      ?
  6134. dbgbuflen       dd      ?
  6135. dbgbuf          rb      256
  6136.  
  6137. fileattr        rb      40
  6138.  
  6139. needzerostart:
  6140.  
  6141. context:
  6142. _eip    dd      ?
  6143. _eflags dd      ?
  6144. _eax    dd      ?
  6145. _ecx    dd      ?
  6146. _edx    dd      ?
  6147. _ebx    dd      ?
  6148. _esp    dd      ?
  6149. _ebp    dd      ?
  6150. _esi    dd      ?
  6151. _edi    dd      ?
  6152.  
  6153. oldcontext rb $-context
  6154.  
  6155. dumpread dd     ?
  6156. dumppos dd      ?
  6157. dumpdata rb     dump_height*10h
  6158.  
  6159. ; breakpoint structure:
  6160. ; dword +0: address
  6161. ; byte +4: flags
  6162. ; bit 0: 1 <=> breakpoint valid
  6163. ; bit 1: 1 <=> breakpoint disabled
  6164. ; bit 2: 1 <=> one-shot breakpoint
  6165. ; bit 3: 1 <=> DRx breakpoint
  6166. ; byte +5: overwritten byte
  6167. ;          for DRx breaks: flags + (index shl 6)
  6168. breakpoints_n = 256
  6169. breakpoints     rb      breakpoints_n*6
  6170. drx_break       rd      4
  6171.  
  6172. disasm_buf_size         dd      ?
  6173.  
  6174. symbols         dd      ?
  6175. num_symbols     dd      ?
  6176.  
  6177. bReload                 db      ?
  6178.  
  6179. needzeroend:
  6180.  
  6181. disasm_buffer           rb      256
  6182. disasm_start_pos        dd      ?
  6183. disasm_cur_pos          dd      ?
  6184. disasm_cur_str          dd      ?
  6185. disasm_string           rb      256
  6186.  
  6187. i_param         rb      256
  6188.  
  6189. ; stack
  6190.         align   400h
  6191.         rb      400h
  6192. used_mem:
  6193.