Subversion Repositories Kolibri OS

Rev

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

  1. format binary
  2. use32
  3.         db      'MENUET01'
  4.         dd      1
  5.         dd      start
  6.         dd      i_end
  7.         dd      used_mem
  8.         dd      used_mem
  9.         dd      i_param
  10.         dd      0
  11.  
  12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GUI ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15.  
  16. data_width equ 80
  17. data_x_pos equ 12
  18. data_x_size equ data_width*6
  19.  
  20. title_x_pos equ 30
  21. title_y_pos equ 32
  22. title_y_size equ 10
  23.  
  24. registers_x_pos equ data_x_pos
  25. registers_y_pos equ (title_y_pos + title_y_size)
  26. registers_y_size equ 30
  27.  
  28. dump_y_pos equ (registers_y_pos + registers_y_size + 5)
  29. dump_height equ 4
  30. dump_y_size equ (dump_height*10)
  31.  
  32. disasm_y_pos equ (dump_y_pos + dump_y_size + 4)
  33. disasm_height equ 16
  34. disasm_y_size equ (disasm_height*10)
  35.  
  36. messages_width equ data_width
  37. messages_height equ 12
  38. messages_x_pos equ data_x_pos
  39. messages_y_pos equ (disasm_y_pos + disasm_y_size + 4)
  40. messages_x_size equ messages_width*6
  41. messages_y_size equ messages_height*10
  42.  
  43. cmdline_width equ data_width
  44. cmdline_x_pos equ data_x_pos
  45. cmdline_y_pos equ (messages_y_pos + messages_y_size + 10)
  46. cmdline_x_size equ messages_x_size
  47. cmdline_y_size equ 10
  48.  
  49. wnd_x_size equ (data_x_pos + messages_x_size + data_x_pos)
  50. wnd_y_size equ (cmdline_y_pos + cmdline_y_size + data_x_pos)
  51.  
  52. start:
  53.         mov     edi, messages
  54.         mov     ecx, messages_width*messages_height
  55.         mov     al, ' '
  56.         rep     stosb
  57.         xor     eax, eax
  58.         mov     [messages_pos], eax
  59.         mov     [cmdline_len], eax
  60.         mov     [cmdline_pos], eax
  61.         mov     edi, needzerostart
  62.         mov     ecx, (needzeroend-needzerostart+3)/4
  63.         rep     stosd
  64.         mov     esi, begin_str
  65.         call    put_message_nodraw
  66. ; set event mask - default events and debugging events
  67.         push    40
  68.         pop     eax
  69.         mov     ebx, 0x107
  70.         int     40h
  71. ; set debug messages buffer
  72.         mov     ecx, dbgbufsize
  73.         mov     dword [ecx], 256
  74.         xor     ebx, ebx
  75.         mov     [ecx+4], ebx
  76.         mov     al, 69
  77.         int     40h
  78.         mov     esi, i_param
  79.         call    skip_spaces
  80.         test    al, al
  81.         jz      dodraw
  82.         push    esi
  83.         call    draw_window
  84.         pop     esi
  85.         call    OnLoadInit
  86.         jmp     waitevent
  87. dodraw:
  88.         call    draw_window
  89. waitevent:
  90.         push    10
  91.         pop     eax
  92.         int     40h
  93.         cmp     al, 9
  94.         jz      debugmsg
  95.         dec     eax
  96.         jz      dodraw
  97.         dec     eax
  98.         jz      keypressed
  99.         dec     eax
  100.         jnz     waitevent
  101. ; button pressed - we have only one button (close)
  102.         push    -1
  103.         pop     eax
  104.         int     40h
  105. keypressed:
  106.         mov     al, 2
  107.         int     40h
  108.         shr     eax, 8
  109.         cmp     al, 8
  110.         jz      .backspace
  111.         cmp     al, 0xB0
  112.         jz      .left
  113.         cmp     al, 0xB3
  114.         jz      .right
  115.         cmp     al, 0x0D
  116.         jz      .enter
  117.         cmp     al, 0xB6
  118.         jz      .del
  119.         cmp     al, 0xB4
  120.         jz      .home
  121.         cmp     al, 0xB5
  122.         jz      .end
  123.         cmp     al, 0xB1
  124.         jz      .down
  125.         cmp     al, 0xB2
  126.         jz      .up
  127.         cmp     al, 0xD8
  128.         jz      CtrlF7
  129.         cmp     al, 0xD9
  130.         jz      CtrlF8
  131.         cmp     [cmdline_len], cmdline_width
  132.         jae     waitevent
  133.         push    eax
  134.         call    clear_cmdline_end
  135.         pop     eax
  136.         mov     edi, cmdline
  137.         mov     ecx, [cmdline_len]
  138.         add     edi, ecx
  139.         lea     esi, [edi-1]
  140.         sub     ecx, [cmdline_pos]
  141.         std
  142.         rep     movsb
  143.         cld
  144.         stosb
  145.         inc     [cmdline_len]
  146.         call    draw_cmdline_end
  147.         inc     [cmdline_pos]
  148.         call    draw_cursor
  149.         jmp     waitevent
  150. .backspace:
  151.         cmp     [cmdline_pos], 0
  152.         jz      waitevent
  153.         dec     [cmdline_pos]
  154. .delchar:
  155.         call    clear_cmdline_end
  156.         mov     edi, [cmdline_pos]
  157.         dec     [cmdline_len]
  158.         mov     ecx, [cmdline_len]
  159.         sub     ecx, edi
  160.         add     edi, cmdline
  161.         lea     esi, [edi+1]
  162.         rep     movsb
  163.         call    draw_cmdline_end
  164.         call    draw_cursor
  165.         jmp     waitevent
  166. .del:
  167.         mov     eax, [cmdline_pos]
  168.         cmp     eax, [cmdline_len]
  169.         jae     waitevent
  170.         jmp     .delchar
  171. .left:
  172.         cmp     [cmdline_pos], 0
  173.         jz      waitevent
  174.         call    hide_cursor
  175.         dec     [cmdline_pos]
  176.         call    draw_cursor
  177.         jmp     waitevent
  178. .right:
  179.         mov     eax, [cmdline_pos]
  180.         cmp     eax, [cmdline_len]
  181.         jae     waitevent
  182.         call    hide_cursor
  183.         inc     [cmdline_pos]
  184.         call    draw_cursor
  185.         jmp     waitevent
  186. .home:
  187.         call    hide_cursor
  188.         and     [cmdline_pos], 0
  189.         call    draw_cursor
  190.         jmp     waitevent
  191. .end:
  192.         call    hide_cursor
  193.         mov     eax, [cmdline_len]
  194.         mov     [cmdline_pos], eax
  195.         call    draw_cursor
  196. .up:
  197. .down:
  198.         jmp     waitevent
  199. .enter:
  200.         mov     ecx, [cmdline_len]
  201.         test    ecx, ecx
  202.         jz      waitevent
  203.         mov     esi, cmdline
  204.         mov     byte [esi+ecx], 0
  205.         and     [cmdline_pos], 0
  206.         push    esi
  207.         call    clear_cmdline_end
  208.         call    draw_cursor
  209.         pop     esi
  210.         and     [cmdline_len], 0
  211. ; skip leading spaces
  212.         call    skip_spaces
  213.         cmp     al, 0
  214.         jz      waitevent
  215. ; now esi points to command
  216.         push    esi
  217.         mov     esi, prompt
  218.         call    put_message_nodraw
  219.         pop     esi
  220.         push    esi
  221.         call    put_message_nodraw
  222. z1:     mov     esi, newline
  223.         call    put_message
  224.         pop     esi
  225.         push    esi
  226.         call    get_arg
  227.         mov     [curarg], esi
  228.         pop     edi
  229.         mov     esi, commands
  230.         call    find_cmd
  231.         mov     eax, aUnknownCommand
  232.         jc      .x11
  233. ; check command requirements
  234. ; flags field:
  235. ; &1: command may be called without parameters
  236. ; &2: command may be called with parameters
  237. ; &4: command may be called without loaded program
  238. ; &8: command may be called with loaded program
  239.         mov     eax, [esi+8]
  240.         mov     ecx, [curarg]
  241.         cmp     byte [ecx], 0
  242.         jz      .noargs
  243.         test    byte [esi+16], 2
  244.         jz      .x11
  245.         jmp     @f
  246. .noargs:
  247.         test    byte [esi+16], 1
  248.         jz      .x11
  249. @@:
  250.         cmp     [debuggee_pid], 0
  251.         jz      .nodebuggee
  252.         mov     eax, aAlreadyLoaded
  253.         test    byte [esi+16], 8
  254.         jz      .x11
  255.         jmp     .x9
  256. .nodebuggee:
  257.         mov     eax, need_debuggee
  258.         test    byte [esi+16], 4
  259.         jnz     .x9
  260. .x11:
  261.         xchg    esi, eax
  262.         call    put_message
  263. .x10:
  264.         jmp     waitevent
  265. .x9:
  266.         call    dword [esi+4]
  267.         jmp     .x10
  268.  
  269. find_cmd:
  270. ; all commands are case-insensitive
  271.         push    edi
  272. .x4:
  273.         mov     al, [edi]
  274.         cmp     al, 0
  275.         jz      .x5
  276.         cmp     al, 'A'
  277.         jb      @f
  278.         cmp     al, 'Z'
  279.         ja      @f
  280.         or      al, 20h
  281. @@:
  282.         stosb
  283.         jmp     .x4
  284. .x5:
  285. ; find command
  286.         pop     edi
  287. .x6:
  288.         cmp     dword [esi], 0
  289.         jz      .x7
  290.         push    esi
  291.         mov     esi, [esi]
  292.         lodsb
  293.         movzx   ecx, al
  294.         push    edi
  295.         repz    cmpsb
  296.         pop     edi
  297.         pop     esi
  298.         jz      .x8
  299.         add     esi, 17
  300.         jmp     .x6
  301. .x7:
  302.         stc
  303. .x8:
  304.         ret
  305.  
  306. get_arg:
  307.         lodsb
  308.         cmp     al, ' '
  309.         ja      get_arg
  310.         mov     byte [esi-1], 0
  311.         cmp     al, 0
  312.         jnz     skip_spaces
  313.         dec     esi
  314. skip_spaces:
  315.         lodsb
  316.         cmp     al, 0
  317.         jz      @f
  318.         cmp     al, ' '
  319.         jbe     skip_spaces
  320. @@:     dec     esi
  321.         ret
  322.  
  323. clear_cmdline_end:
  324.         mov     ebx, [cmdline_pos]
  325.         mov     ecx, [cmdline_len]
  326.         sub     ecx, ebx
  327.         push    13
  328.         pop     eax
  329.         imul    ebx, 6
  330.         imul    ecx, 6
  331.         inc     ecx
  332.         add     ebx, cmdline_x_pos
  333.         shl     ebx, 16
  334.         or      ebx, ecx
  335.         mov     ecx, cmdline_y_pos*10000h + cmdline_y_size
  336.         mov     edx, 0xFFFFFF
  337.         int     40h
  338.         ret
  339.  
  340. draw_cmdline:
  341.         xor     ebx, ebx
  342.         jmp     @f
  343. draw_cmdline_end:
  344.         mov     ebx, [cmdline_pos]
  345. @@:
  346.         mov     esi, [cmdline_len]
  347.         sub     esi, ebx
  348.         push    4
  349.         pop     eax
  350.         xor     ecx, ecx
  351.         lea     edx, [cmdline+ebx]
  352.         imul    ebx, 6
  353.         add     ebx, cmdline_x_pos
  354.         shl     ebx, 16
  355.         or      ebx, cmdline_y_pos+1
  356.         int     40h
  357.         ret
  358.  
  359. put_message_nodraw:
  360. ; in: esi->ASCIZ message
  361.         mov     edx, [messages_pos]
  362. .m:
  363.         lea     edi, [messages+edx]
  364. .l:
  365.         lodsb
  366.         cmp     al, 0
  367.         jz      .done
  368.         call    test_scroll
  369.         cmp     al, 10
  370.         jz      .newline
  371.         cmp     al, '%'
  372.         jnz     @f
  373.         cmp     dword [esp], z1
  374.         jnz     .format
  375. @@:
  376.         stosb
  377.         inc     edx
  378.         jmp     .l
  379. .newline:
  380.         push    edx
  381.         mov     ecx, messages_width
  382.         xor     eax, eax
  383.         xchg    eax, edx
  384.         div     ecx
  385.         xchg    eax, edx
  386.         pop     edx
  387.         test    eax, eax
  388.         jz      .m
  389.         sub     edx, eax
  390.         add     edx, ecx
  391.         jmp     .m
  392. .done:
  393.         mov     [messages_pos], edx
  394.         ret
  395. .format:
  396. ; at moment all format specs must be %<digit>X
  397.         lodsb   ; get <digit>
  398.         sub     al, '0'
  399.         movzx   ecx, al
  400.         lodsb
  401.         pop     eax
  402.         pop     ebp
  403.         push    eax
  404. ; write number in ebp with ecx digits
  405.         dec     ecx
  406.         shl     ecx, 2
  407. .writenibble:
  408.         push    ecx
  409.         call    test_scroll
  410.         pop     ecx
  411.         mov     eax, ebp
  412.         shr     eax, cl
  413.         and     al, 0xF
  414.         cmp     al, 10
  415.         sbb     al, 69h
  416.         das
  417.         stosb
  418.         inc     edx
  419.         sub     ecx, 4
  420.         jns     .writenibble
  421.         jmp     .l
  422.  
  423. test_scroll:
  424.         cmp     edx, messages_width*messages_height
  425.         jnz     .ret
  426.         push    esi
  427.         mov     edi, messages
  428.         lea     esi, [edi+messages_width]
  429.         mov     ecx, (messages_height-1)*messages_width/4
  430.         rep     movsd
  431.         push    eax
  432.         mov     al, ' '
  433.         push    edi
  434.         push    messages_width
  435.         pop     ecx
  436.         sub     edx, ecx
  437.         rep     stosb
  438.         pop     edi
  439.         pop     eax
  440.         pop     esi
  441. .ret:   ret
  442.  
  443. put_message:
  444.         call    put_message_nodraw
  445.  
  446. draw_messages:
  447.         push    13
  448.         pop     eax
  449.         mov     edx, 0xFFFFFF
  450.         mov     ebx, messages_x_pos*10000h+messages_x_size
  451.         mov     ecx, messages_y_pos*10000h+messages_y_size
  452.         int     40h
  453.         mov     edx, messages
  454.         push    messages_width
  455.         pop     esi
  456.         xor     ecx, ecx
  457.         mov     al, 4
  458.         mov     ebx, messages_x_pos*10000h+messages_y_pos
  459. @@:
  460.         int     40h
  461.         add     edx, esi
  462.         add     ebx, 10
  463.         cmp     edx, messages+messages_width*messages_height
  464.         jb      @b
  465.         ret
  466.  
  467. draw_cursor:
  468.         push    38
  469.         pop     eax
  470.         mov     ecx, cmdline_y_pos*10001h+cmdline_y_size-1
  471.         mov     ebx, [cmdline_pos]
  472.         imul    ebx, 6
  473.         add     ebx, cmdline_x_pos
  474.         mov     edx, ebx
  475.         shl     ebx, 16
  476.         or      ebx, edx
  477.         xor     edx, edx
  478.         int     40h
  479.         ret
  480. hide_cursor:
  481.         mov     ebx, [cmdline_pos]
  482.         push    13
  483.         pop     eax
  484.         imul    ebx, 6
  485.         add     ebx, cmdline_x_pos
  486.         shl     ebx, 16
  487.         inc     ebx
  488.         mov     ecx, cmdline_y_pos*10000h + cmdline_y_size
  489.         mov     edx, 0xFFFFFF
  490.         int     40h
  491.         mov     ebx, [cmdline_pos]
  492.         cmp     ebx, [cmdline_len]
  493.         jae     .ret
  494.         mov     al, 4
  495.         xor     ecx, ecx
  496.         lea     edx, [cmdline+ebx]
  497.         imul    ebx, 6
  498.         add     ebx, cmdline_x_pos
  499.         shl     ebx, 16
  500.         or      ebx, cmdline_y_pos+1
  501.         push    1
  502.         pop     esi
  503.         int     40h
  504. .ret:
  505.         ret
  506.  
  507. redraw_title:
  508.         push    13
  509.         pop     eax
  510.         mov     edx, 0xFFFFFF
  511.         mov     ebx, title_x_pos*10000h + data_x_pos+data_x_size-title_x_pos
  512.         mov     ecx, title_y_pos*10000h + title_y_size
  513.         int     40h
  514. draw_title:
  515.         mov     al, 38
  516.         mov     ebx, (data_x_pos-2)*10000h + title_x_pos-5
  517.         mov     ecx, (title_y_pos+5)*10001h
  518.         xor     edx, edx
  519.         int     40h
  520.         push    NoPrgLoaded_len
  521.         pop     esi
  522.         cmp     [debuggee_pid], 0
  523.         jz      @f
  524.         mov     esi, [prgname_len]
  525. @@:     imul    ebx, esi, 6
  526.         add     ebx, title_x_pos+4
  527.         shl     ebx, 16
  528.         mov     bx, data_x_pos+data_x_size-10-5-6*7
  529.         cmp     [bSuspended], 0
  530.         jz      @f
  531.         add     ebx, 6
  532. @@:
  533.         int     40h
  534.         mov     ebx, (data_x_pos+data_x_size-10+4)*0x10000 + data_x_pos+data_x_size+2
  535.         int     40h
  536.         mov     al, 4
  537.         mov     ebx, title_x_pos*10000h+title_y_pos
  538.         xor     ecx, ecx
  539.         mov     edx, NoPrgLoaded_str
  540.         cmp     [debuggee_pid], 0
  541.         jz      @f
  542.         mov     edx, [prgname_ptr]
  543. @@:
  544.         int     40h
  545.         cmp     [debuggee_pid], 0
  546.         jz      .nodebuggee
  547.         mov     ebx, (data_x_pos+data_x_size-10-6*7)*10000h + title_y_pos
  548.         mov     edx, aRunning
  549.         push    7
  550.         pop     esi
  551.         cmp     [bSuspended], 0
  552.         jz      @f
  553.         add     ebx, 6*10000h
  554.         mov     edx, aPaused
  555.         dec     esi
  556. @@:
  557.         int     40h
  558.         ret
  559. .nodebuggee:
  560.         mov     al, 38
  561.         mov     ebx, (data_x_pos+data_x_size-10-6*7-5)*0x10000 + data_x_pos+data_x_size+2
  562.         mov     ecx, (title_y_pos+5)*10001h
  563.         xor     edx, edx
  564.         jmp     @b
  565.  
  566. draw_register:
  567. ; in: esi->value, edx->string, ecx=string len, ebx=coord
  568.         push    edx
  569.         push    ecx
  570.         push    esi
  571.         mov     eax, esi
  572.         mov     esi, ecx
  573. ; color
  574.         mov     ecx, 808080h
  575.         cmp     [debuggee_pid], 0
  576.         jz      .cd
  577.         cmp     [bSuspended], 0
  578.         jz      .cd
  579.         xor     ecx, ecx
  580.         mov     edi, [eax]
  581.         cmp     dword [eax+oldcontext-context], edi
  582.         jz      .cd
  583.         mov     ecx, 0x00AA00
  584. .cd:
  585.         push    4
  586.         pop     eax
  587.         int     40h
  588.         imul    esi, 60000h
  589.         lea     edx, [ebx+esi]
  590.         mov     al, 47
  591.         mov     ebx, 80101h
  592.         mov     esi, ecx
  593.         pop     ecx
  594.         int     40h
  595.         lea     ebx, [edx+60000h*18]
  596.         mov     esi, ecx
  597.         pop     ecx
  598.         pop     edx
  599.         add     edx, ecx
  600.         ret
  601. draw_flag:
  602.         movzx   edi, byte [edx+7]
  603.         bt      [_eflags], edi
  604.         jc      .on
  605.         or      byte [edx], 20h
  606.         jmp     .onoff
  607. .on:
  608.         and     byte [edx], not 20h
  609. .onoff:
  610.         mov     ecx, 808080h
  611.         cmp     [debuggee_pid], 0
  612.         jz      .doit
  613.         cmp     [bSuspended], 0
  614.         jz      .doit
  615.         xor     ecx, ecx
  616.         bt      [_eflags], edi
  617.         lahf
  618.         bt      dword [_eflags + oldcontext - context], edi
  619.         rcl     ah, 1
  620.         test    ah, 3
  621.         jp      .doit
  622.         mov     ecx, 0x00AA00
  623. .doit:
  624.         mov     ah, 0
  625.         int     40h
  626.         ret
  627.  
  628. redraw_registers:
  629.         push    13
  630.         pop     eax
  631.         mov     edx, 0xFFFFFF
  632.         mov     ebx, data_x_pos*10000h + data_x_size
  633.         mov     ecx, registers_y_pos*10000h + registers_y_size
  634.         int     40h
  635. draw_registers:
  636.         mov     esi, _eax
  637.         push    4
  638.         pop     ecx
  639.         mov     edx, regs_strs
  640.         mov     ebx, registers_x_pos*10000h+registers_y_pos
  641.         call    draw_register
  642.         add     esi, _ebx-_eax
  643.         call    draw_register
  644.         add     esi, _ecx-_ebx
  645.         call    draw_register
  646.         add     esi, _edx-_ecx
  647.         call    draw_register
  648.         mov     ebx, registers_x_pos*10000h+registers_y_pos+10
  649.         add     esi, _esi-_edx
  650.         call    draw_register
  651.         add     esi, _edi-_esi
  652.         call    draw_register
  653.         add     esi, _ebp-_edi
  654.         call    draw_register
  655.         add     esi, _esp-_ebp
  656.         call    draw_register
  657.         mov     ebx, registers_x_pos*10000h+registers_y_pos+20
  658.         add     esi, _eip-_esp
  659.         call    draw_register
  660.         mov     cl, 7
  661.         add     esi, _eflags-_eip
  662.         call    draw_register
  663.         mov     al, 4
  664.         mov     ecx, 808080h
  665.         cmp     [debuggee_pid], 0
  666.         jz      @f
  667.         cmp     [bSuspended], 0
  668.         jz      @f
  669.         xor     ecx, ecx
  670. @@:
  671.         mov     edx, aColon
  672.         xor     esi, esi
  673.         inc     esi
  674.         mov     ebx, (registers_x_pos+37*6)*10000h + registers_y_pos+20
  675.         int     40h
  676.         mov     edx, flags
  677. @@:
  678.         add     ebx, 2*6*10000h
  679.         call    draw_flag
  680.         inc     edx
  681.         cmp     dl, flags_bits and 0xFF
  682.         jnz     @b
  683.         ret
  684.  
  685. redraw_dump:
  686.         push    13
  687.         pop     eax
  688.         mov     edx, 0xFFFFFF
  689.         mov     ebx, data_x_pos*10000h + data_x_size
  690.         mov     ecx, dump_y_pos*10000h + dump_y_size
  691.         int     40h
  692. draw_dump:
  693. ; addresses
  694.         mov     al, 47
  695.         mov     ebx, 80100h
  696.         mov     edx, data_x_pos*10000h + dump_y_pos
  697.         mov     ecx, [dumppos]
  698.         mov     esi, 808080h
  699.         cmp     [debuggee_pid], 0
  700.         jz      @f
  701.         cmp     [bSuspended], 0
  702.         jz      @f
  703.         xor     esi, esi
  704. @@:
  705.         int     40h
  706.         add     ecx, 10h
  707.         add     edx, 10
  708.         cmp     dl, dump_y_pos + dump_y_size
  709.         jb      @b
  710. ; hex dump of data
  711.         mov     ebx, 20101h
  712.         mov     ecx, dumpdata
  713.         push    ecx
  714.         xor     edi, edi
  715.         mov     edx, (data_x_pos+12*6)*10000h + dump_y_pos
  716.         cmp     [dumpread], edi
  717.         jz      .hexdumpdone1
  718. .hexdumploop1:
  719.         int     40h
  720.         add     edx, 3*6*10000h
  721.         inc     ecx
  722.         inc     edi
  723.         test    edi, 15
  724.         jz      .16
  725.         test    edi, 7
  726.         jnz     @f
  727.         add     edx, 2*6*10000h - 10 + 6*(3*10h+2)*10000h
  728. .16:
  729.         add     edx, 10 - 6*(3*10h+2)*10000h
  730. @@:
  731.         cmp     edi, [dumpread]
  732.         jb      .hexdumploop1
  733. .hexdumpdone1:
  734.         mov     al, 4
  735.         mov     ecx, esi
  736.         mov     ebx, edx
  737.         push    2
  738.         pop     esi
  739.         mov     edx, aQuests
  740. .hexdumploop2:
  741.         cmp     edi, dump_height*10h
  742.         jae     .hexdumpdone2
  743.         int     40h
  744.         add     ebx, 3*6*10000h
  745.         inc     edi
  746.         test    edi, 15
  747.         jz      .16x
  748.         test    edi, 7
  749.         jnz     .hexdumploop2
  750.         add     ebx, 2*6*10000h - 10 + 6*(3*10h+2)*10000h
  751. .16x:
  752.         add     ebx, 10 - 6*(3*10h+2)*10000h
  753.         jmp     .hexdumploop2
  754. .hexdumpdone2:
  755.         dec     esi
  756. ; colon, minus signs
  757.         mov     ebx, (data_x_pos+8*6)*10000h + dump_y_pos
  758.         mov     edx, aColon
  759. @@:
  760.         int     40h
  761.         add     ebx, 10
  762.         cmp     bl, dump_y_pos+dump_height*10
  763.         jb      @b
  764.         mov     ebx, (data_x_pos+(12+3*8)*6)*10000h + dump_y_pos
  765.         mov     edx, aMinus
  766. @@:
  767.         int     40h
  768.         add     ebx, 10
  769.         cmp     bl, dump_y_pos+dump_height*10
  770.         jb      @b
  771. ; ASCII data
  772.         mov     ebx, (data_x_pos+(12+3*10h+2+2)*6)*10000h + dump_y_pos
  773.         mov     edi, dump_height*10h
  774.         pop     edx
  775. .asciiloop:
  776.         push    edx
  777.         cmp     byte [edx], 20h
  778.         jae     @f
  779.         mov     edx, aPoint
  780. @@:
  781.         int     40h
  782.         pop     edx
  783.         inc     edx
  784.         add     ebx, 6*10000h
  785.         dec     edi
  786.         jz      .asciidone
  787.         test    edi, 15
  788.         jnz     .asciiloop
  789.         add     ebx, 10 - 6*10h*10000h
  790.         jmp     .asciiloop
  791. .asciidone:
  792.         ret
  793.  
  794. redraw_disasm:
  795.         push    13
  796.         pop     eax
  797.         mov     edx, 0xFFFFFF
  798.         mov     ebx, data_x_pos*10000h + data_x_size
  799.         mov     ecx, (disasm_y_pos-1)*10000h + (disasm_y_size+1)
  800.         int     40h
  801. draw_disasm:
  802.         mov     eax, [disasm_start_pos]
  803.         mov     [disasm_cur_pos], eax
  804.         and     [disasm_cur_str], 0
  805. .loop:
  806.         push    [disasm_cur_pos]
  807.         call    disasm_instr
  808.         pop     ebp
  809.         jc      .loopend
  810.         xor     esi, esi        ; default color: black
  811.         mov     ebx, data_x_pos*10000h + data_x_size
  812.         mov     ecx, [disasm_cur_str]
  813.         imul    ecx, 10*10000h
  814.         add     ecx, (disasm_y_pos-1)*10000h + 10
  815.         mov     eax, ebp
  816.         pushad
  817.         call    find_enabled_breakpoint
  818.         popad
  819.         jnz     .nored
  820.         push    13
  821.         pop     eax
  822.         mov     edx, 0xFF0000
  823.         int     40h
  824. .nored:
  825.         mov     eax, [_eip]
  826.         cmp     eax, ebp
  827.         jnz     .noblue
  828.         push    13
  829.         pop     eax
  830.         mov     edx, 0x0000FF
  831.         int     40h
  832.         mov     esi, 0xFFFFFF   ; on blue bgr, use white color
  833. .noblue:
  834.         push    47
  835.         pop     eax
  836.         mov     ebx, 80100h
  837.         mov     edx, [disasm_cur_str]
  838.         imul    edx, 10
  839.         add     edx, data_x_pos*10000h + disasm_y_pos
  840.         mov     ecx, ebp
  841.         int     40h
  842.         mov     al, 4
  843.         lea     ebx, [edx+8*6*10000h]
  844.         mov     ecx, esi
  845.         push    1
  846.         pop     esi
  847.         mov     edx, aColon
  848.         int     40h
  849.         push    9
  850.         pop     edi
  851.         lea     edx, [ebx+2*6*10000h]
  852.         mov     esi, ecx
  853.         mov     al, 47
  854.         mov     ebx, 20101h
  855.         mov     ecx, ebp
  856.         sub     ecx, [disasm_start_pos]
  857.         add     ecx, disasm_buffer
  858. .drawhex:
  859.         int     40h
  860.         add     edx, 6*3*10000h
  861.         inc     ecx
  862.         inc     ebp
  863.         cmp     ebp, [disasm_cur_pos]
  864.         jae     .hexdone
  865.         dec     edi
  866.         jnz     .drawhex
  867.         push    esi
  868.         mov     esi, [disasm_cur_pos]
  869.         dec     esi
  870.         cmp     esi, ebp
  871.         pop     esi
  872.         jbe     .drawhex
  873.         mov     al, 4
  874.         lea     ebx, [edx-6*10000h]
  875.         mov     ecx, esi
  876.         push    3
  877.         pop     esi
  878.         mov     edx, aDots
  879.         int     40h
  880.         mov     esi, ecx
  881. .hexdone:
  882.         xor     eax, eax
  883.         mov     edi, disasm_string
  884.         mov     edx, edi
  885.         or      ecx, -1
  886.         repnz   scasb
  887.         not     ecx
  888.         dec     ecx
  889.         xchg    ecx, esi
  890.         mov     ebx, [disasm_cur_str]
  891.         imul    ebx, 10
  892.         add     ebx, (data_x_pos+6*40)*10000h+disasm_y_pos
  893.         mov     al, 4
  894.         int     40h
  895.         inc     [disasm_cur_str]
  896.         cmp     [disasm_cur_str], disasm_height
  897.         jb      .loop
  898. .loopend:
  899.         ret
  900.  
  901. update_disasm_eip:
  902. ; test if instruction at eip is showed
  903.         mov     ecx, disasm_height
  904.         mov     eax, [disasm_start_pos]
  905.         mov     [disasm_cur_pos], eax
  906. @@:
  907.         mov     eax, [_eip]
  908.         cmp     [disasm_cur_pos], eax
  909.         jz      redraw_disasm
  910.         push    ecx
  911.         call    disasm_instr
  912.         pop     ecx
  913.         jc      @f
  914.         loop    @b
  915. @@:
  916. update_disasm_eip_force:
  917.         mov     eax, [_eip]
  918.         mov     [disasm_start_pos], eax
  919. update_disasm:
  920.         cmp     [debuggee_pid], 0
  921.         jz      .no
  922.         push    69
  923.         pop     eax
  924.         push    6
  925.         pop     ebx
  926.         mov     ecx, [debuggee_pid]
  927.         mov     edi, disasm_buffer
  928.         mov     edx, 256
  929.         mov     esi, [disasm_start_pos]
  930.         int     40h
  931.         cmp     eax, -1
  932.         jnz     @f
  933.         mov     esi, read_mem_err
  934.         call    put_message
  935. .no:
  936.         xor     eax, eax
  937. @@:
  938.         mov     [disasm_buf_size], eax
  939.         call    restore_from_breaks
  940.         jmp     redraw_disasm
  941.  
  942. draw_window:
  943. ; start redraw
  944.         push    12
  945.         pop     eax
  946.         push    1
  947.         pop     ebx
  948.         int     40h
  949. ; define window
  950.         xor     eax, eax
  951.         mov     ebx, wnd_x_size
  952.         mov     ecx, wnd_y_size
  953.         mov     edx, 3FFFFFFh
  954.         int     40h
  955. ; caption
  956.         mov     al, 4
  957.         mov     ecx, 0xFFFFFF
  958.         mov     ebx, 80008h
  959.         mov     edx, caption_str
  960.         push    caption_len
  961.         pop     esi
  962.         int     40h
  963. ; messages frame
  964.         mov     al, 38
  965.         mov     ebx, (messages_x_pos-2)*10000h + (messages_x_pos+messages_x_size+2)
  966.         push    ebx
  967.         mov     ecx, (messages_y_pos-2)*10001h
  968.         xor     edx, edx
  969.         int     40h
  970.         mov     ecx, (messages_y_pos+messages_y_size+2)*10001h
  971.         int     40h
  972.         mov     ebx, (messages_x_pos-2)*10001h
  973.         push    ebx
  974.         mov     ecx, (messages_y_pos-2)*10000h + (messages_y_pos+messages_y_size+2)
  975.         int     40h
  976.         mov     ebx, (messages_x_pos+messages_x_size+2)*10001h
  977.         push    ebx
  978.         int     40h
  979. ; command line frame
  980.         mov     ecx, (cmdline_y_pos-2)*10000h + (cmdline_y_pos+cmdline_y_size+2)
  981.         pop     ebx
  982.         int     40h
  983.         pop     ebx
  984.         int     40h
  985.         pop     ebx
  986.         mov     ecx, (cmdline_y_pos+cmdline_y_size+2)*10001h
  987.         int     40h
  988.         mov     ecx, (cmdline_y_pos-2)*10001h
  989.         int     40h
  990. ; messages
  991.         call    draw_messages
  992. ; command line & cursor
  993.         call    draw_cmdline
  994.         call    draw_cursor
  995. ; title & registers & dump & disasm
  996.         mov     al, 38
  997.         mov     ebx, (data_x_pos-2)*10001h
  998.         mov     ecx, (title_y_pos+5)*10000h + (messages_y_pos-2)
  999.         int     40h
  1000.         mov     ebx, (data_x_pos+data_x_size+2)*10001h
  1001.         int     40h
  1002.         mov     ebx, (data_x_pos-2)*10000h + (data_x_pos+data_x_size+2)
  1003.         mov     ecx, (dump_y_pos-3)*10001h
  1004.         int     40h
  1005.         mov     ecx, (disasm_y_pos-4)*10001h
  1006.         int     40h
  1007.         call    draw_title
  1008.         call    draw_registers
  1009.         call    draw_dump
  1010.         call    draw_disasm
  1011. ; end redraw
  1012.         mov     al, 12
  1013.         push    2
  1014.         pop     ebx
  1015.         int     40h
  1016.         ret
  1017.  
  1018. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1019. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DEBUGGING ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1020. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1021.  
  1022. OnHelp:
  1023.         mov     esi, help_msg
  1024.         mov     edi, [curarg]
  1025.         cmp     byte [edi], 0
  1026.         jz      .x
  1027.         mov     esi, help_groups
  1028.         call    find_cmd
  1029.         jc      .nocmd
  1030.         mov     esi, [esi+12]
  1031. .x:
  1032.         jmp     put_message
  1033. .nocmd:
  1034.         mov     esi, aUnknownCommand
  1035.         jmp     .x
  1036.  
  1037. OnQuit:
  1038.         xor     eax, eax
  1039.         dec     eax
  1040.         int     40h
  1041.  
  1042. get_new_context:
  1043.         mov     esi, context
  1044.         mov     edi, oldcontext
  1045.         mov     ecx, 10
  1046.         rep     movsd
  1047. get_context:
  1048.         push    1
  1049.         pop     ebx
  1050.         push    69
  1051.         pop     eax
  1052.         mov     ecx, [debuggee_pid]
  1053.         mov     esi, context
  1054.         push    28h
  1055.         pop     edx
  1056.         int     40h
  1057.         ret
  1058. set_context:
  1059.         push    2
  1060.         pop     ebx
  1061.         push    69
  1062.         pop     eax
  1063.         mov     ecx, [debuggee_pid]
  1064.         mov     esi, context
  1065.         push    28h
  1066.         pop     edx
  1067.         int     40h
  1068.         ret
  1069.  
  1070. get_dump:
  1071.         mov     edi, dumpdata
  1072.         mov     esi, [edi-4]
  1073.         mov     edx, dump_height*10h
  1074.         mov     ecx, edx
  1075.         xor     eax, eax
  1076.         push    edi
  1077.         rep     stosb
  1078.         pop     edi
  1079.         mov     ecx, [debuggee_pid]
  1080.         mov     al, 69
  1081.         push    6
  1082.         pop     ebx
  1083.         int     40h
  1084.         cmp     eax, -1
  1085.         jnz     @f
  1086.         mov     esi, read_mem_err
  1087.         call    put_message
  1088.         xor     eax, eax
  1089. @@:
  1090.         mov     [edi-8], eax
  1091. ;       call    restore_from_breaks
  1092. ;       ret
  1093. restore_from_breaks:
  1094. ; in: edi=buffer,eax=size,esi=address
  1095.         mov     ebx, breakpoints
  1096. @@:
  1097.         test    byte [ebx+4], 1
  1098.         jz      .cont           ; ignore invalid
  1099.         test    byte [ebx+4], 2 or 8
  1100.         jnz     .cont           ; ignore disabled and memory breaks
  1101.         mov     ecx, [ebx]
  1102.         sub     ecx, esi
  1103.         cmp     ecx, eax
  1104.         jae     .cont
  1105.         mov     dl, [ebx+5]
  1106.         mov     [edi+ecx], dl
  1107. .cont:
  1108.         add     ebx, 6
  1109.         cmp     ebx, breakpoints+breakpoints_n*6
  1110.         jb      @b
  1111.         ret
  1112.  
  1113. OnLoad:
  1114.         mov     esi, [curarg]
  1115. OnLoadInit:
  1116.         mov     edi, loadname
  1117.         or      [prgname_len], -1
  1118.         mov     [prgname_ptr], edi
  1119. .copyname:
  1120.         lodsb
  1121.         stosb
  1122.         inc     [prgname_len]
  1123.         cmp     al, '/'
  1124.         jnz     @f
  1125.         or      [prgname_len], -1
  1126.         mov     [prgname_ptr], edi
  1127. @@:
  1128.         cmp     al, ' '
  1129.         ja      .copyname
  1130.         mov     byte [edi-1], 0
  1131.         and     [load_params], 0
  1132.         dec     esi
  1133.         call    skip_spaces
  1134.         cmp     al, 0
  1135.         jz      @f
  1136.         mov     [load_params], esi
  1137. @@:
  1138.         and     [dumppos], 0
  1139. do_reload:
  1140.         push    18
  1141.         pop     eax
  1142.         push    7
  1143.         pop     ebx
  1144.         int     40h
  1145.         mov     [dbgwnd], eax
  1146.         xchg    ecx, eax
  1147.         push    70
  1148.         pop     eax
  1149.         mov     ebx, fn70_load_block
  1150.         int     40h
  1151.         test    eax, eax
  1152.         jns     .load_ok
  1153. .load_err:
  1154.         push    eax
  1155.         mov     esi, load_err_msg
  1156.         call    put_message
  1157.         pop     eax
  1158.         not     eax
  1159.         cmp     eax, 0x20
  1160.         jae     .unk_err
  1161.         mov     esi, [load_err_msgs+eax*4]
  1162.         test    esi, esi
  1163.         jnz     put_message
  1164. .unk_err:
  1165.         mov     esi, unk_err_msg
  1166.         inc     eax
  1167.         push    eax
  1168.         call    put_message_nodraw
  1169.         jmp     draw_messages
  1170. .load_ok:
  1171.         mov     [debuggee_pid], eax
  1172.         mov     [bSuspended], 1
  1173.         push    ecx
  1174.         call    get_context
  1175.         mov     edi, oldcontext
  1176.         mov     ecx, 10
  1177.         rep     movsd
  1178. ; activate debugger window
  1179.         pop     ecx
  1180.         mov     bl, 3
  1181.         push    18
  1182.         pop     eax
  1183.         int     40h
  1184.         call    redraw_title
  1185.         call    redraw_registers
  1186.         call    get_dump
  1187.         call    redraw_dump
  1188.         call    update_disasm_eip_force
  1189.         mov     esi, load_succ_msg
  1190.         push    [debuggee_pid]
  1191.         call    put_message_nodraw
  1192.         call    draw_messages
  1193. ; now test for packed progs
  1194.         cmp     [disasm_buf_size], 100h
  1195.         jz      @f
  1196.         ret
  1197. @@:
  1198.         mov     esi, mxp_nrv_sig
  1199.         mov     ebp, disasm_buffer
  1200.         mov     edi, ebp
  1201.         push    3
  1202.         pop     ecx
  1203.         repz    cmpsb
  1204.         jnz     .not_mxp_nrv
  1205.         cmpsb
  1206.         mov     cl, mxp_nrv_sig_size-4
  1207.         repz    cmpsb
  1208.         mov     esi, mxp_nrv_name
  1209.         jz      .packed
  1210. .not_mxp_nrv:
  1211.         mov     esi, mxp_sig
  1212.         mov     edi, ebp
  1213.         mov     cl, mxp_sig_size
  1214.         repz    cmpsb
  1215.         mov     esi, mxp_name
  1216.         jz      .packed
  1217. .not_mxp:
  1218.         mov     esi, mxp_lzo_sig1
  1219.         mov     edi, ebp
  1220.         mov     cl, mxp_lzo_sig1_size
  1221.         repz    cmpsb
  1222.         mov     esi, mxp_lzo_name
  1223.         jz      .packed
  1224.         mov     esi, mxp_lzo_sig2
  1225.         mov     edi, ebp
  1226.         mov     cl, 8
  1227.         repz    cmpsb
  1228.         jnz     .not_mxp_lzo
  1229.         cmpsb
  1230.         mov     cl, mxp_lzo_sig2_size - 9
  1231.         repz    cmpsb
  1232.         mov     esi, mxp_lzo_name
  1233.         jz      .packed
  1234. .not_mxp_lzo:
  1235.         mov     esi, mtappack_name
  1236.         cmp     dword [ebp], 0xBF5E246A
  1237.         jnz     .not_mtappack
  1238.         cmp     dword [ebp+8], 0xEC4E8B57
  1239.         jnz     .not_mtappack1
  1240.         cmp     dword [ebp+12], 0x8D5EA4F3
  1241.         jnz     .not_mtappack1
  1242.         cmp     byte [ebp+12h], 0xE9
  1243.         jz      .packed
  1244. .not_mtappack1:
  1245.         cmp     word [ebp+8], 0xB957
  1246.         jnz     .not_mtappack
  1247.         cmp     dword [ebp+14], 0x575EA4F3
  1248.         jnz     .not_mtappack2
  1249.         cmp     byte [ebp+17h], 0xE9
  1250.         jz      .packed
  1251. .not_mtappack2:
  1252.         cmp     dword [ebp+14], 0x5F8DA4F3
  1253.         jnz     .not_mtappack3
  1254.         cmp     word [ebp+18], 0xE9FC
  1255.         jz      .packed
  1256. .not_mtappack3:
  1257.         cmp     word [ebp+14], 0xA4F3
  1258.         jnz     .not_mtappack
  1259.         cmp     byte [ebp+15h], 0xE9
  1260.         jz      .packed
  1261. .not_mtappack:
  1262.         ret
  1263. .packed:
  1264.         push    esi
  1265.         mov     esi, aPacked1
  1266.         call    put_message_nodraw
  1267.         pop     esi
  1268.         call    put_message_nodraw
  1269.         mov     esi, aPacked2
  1270.         call    put_message
  1271.         call    hide_cursor
  1272.         push    40
  1273.         pop     eax
  1274.         push    7
  1275.         pop     ebx
  1276.         int     40h
  1277. .wait:
  1278.         push    10
  1279.         pop     eax
  1280.         int     40h
  1281.         dec     eax
  1282.         jz      .redraw
  1283.         dec     eax
  1284.         jz      .key
  1285.         or      eax, -1
  1286.         int     40h
  1287. .redraw:
  1288.         call    draw_window
  1289.         call    hide_cursor
  1290.         jmp     .wait
  1291. .key:
  1292.         mov     al, 2
  1293.         int     40h
  1294.         cmp     ah, 'y'
  1295.         jz      .yes
  1296.         cmp     ah, 'Y'
  1297.         jz      .yes
  1298.         cmp     ah, 0xD
  1299.         jz      .yes
  1300.         cmp     ah, 'n'
  1301.         jz      .no
  1302.         cmp     ah, 'N'
  1303.         jnz     .wait
  1304. .no:
  1305.         push    40
  1306.         pop     eax
  1307.         mov     ebx, 0x107
  1308.         int     40h
  1309.         call    draw_cursor
  1310.         mov     esi, aN_str
  1311.         jmp     put_message
  1312. .yes:
  1313.         push    40
  1314.         pop     eax
  1315.         mov     ebx, 0x107
  1316.         int     40h
  1317.         call    draw_cursor
  1318.         mov     esi, aY_str
  1319.         call    put_message
  1320.         call    OnUnpack
  1321.         ret
  1322.  
  1323. mxp_nrv_sig:
  1324.         xor     eax, eax
  1325.         mov     ecx, 0x95       ; 0xA1 for programs with parameters
  1326.         mov     [eax], ecx
  1327.         add     ecx, [eax+24h]
  1328.         push    40h
  1329.         pop     esi
  1330.         mov     edi, [eax+20h]
  1331.         push    edi
  1332.         rep     movsb
  1333.         jmp     dword [esp]
  1334.         pop     esi
  1335.         add     esi, [eax]
  1336.         xor     edi, edi
  1337. mxp_nrv_sig_size = $ - mxp_nrv_sig
  1338.  
  1339. mxp_sig:
  1340.         mov     ecx, 1CBh
  1341.         push    46h
  1342.         pop     esi
  1343.         mov     edi, [20h]
  1344.         rep     movsb
  1345.         mov     ecx, [24h]
  1346.         rep     movsb
  1347.         jmp     dword [20h]
  1348.         mov     eax, [20h]
  1349.         add     eax, 1CBh
  1350.         push    eax
  1351.         push    dword [24h]
  1352.         push    0
  1353.         push    8
  1354.         call    $+0x25
  1355. mxp_sig_size = $ - mxp_sig
  1356.  
  1357. mxp_lzo_sig1:
  1358.         xor     eax, eax
  1359.         mov     ebp, 0FFh
  1360.         mov     ecx, 175h
  1361.         mov     [eax], ecx
  1362.         add     ecx, [eax+24h]
  1363.         push    45h
  1364.         pop     esi
  1365.         mov     edi, [eax+20h]
  1366.         push    edi
  1367.         rep     movsb
  1368.         jmp     dword [esp]
  1369.         pop     ebx
  1370.         add     ebx, [eax]
  1371.         xor     edi, edi
  1372.         cmp     byte [ebx], 11h
  1373.         jbe     $+0x1A
  1374. mxp_lzo_sig1_size = $ - mxp_lzo_sig1
  1375. mxp_lzo_sig2:
  1376.         xor     eax, eax
  1377.         mov     ebp, 0FFh
  1378.         mov     ecx, 188h       ; or 177h
  1379.         mov     [eax], ecx
  1380.         add     ecx, [eax+24h]
  1381.         push    44h
  1382.         pop     esi
  1383.         mov     edi, [eax+20h]
  1384.         rep     movsb
  1385.         jmp     dword [eax+20h]
  1386.         mov     ebx, [eax+20h]
  1387.         add     ebx, [eax]
  1388. mxp_lzo_sig2_size = $ - mxp_lzo_sig2
  1389.  
  1390. OnReload:
  1391.         cmp     [debuggee_pid], 0
  1392.         jnz     terminate_reload
  1393.         mov     esi, need_debuggee
  1394.         cmp     byte [loadname], 0
  1395.         jnz     do_reload
  1396.         jz      put_message
  1397. terminate_reload:
  1398.         mov     [bReload], 1
  1399. OnTerminate:
  1400.         mov     ecx, [debuggee_pid]
  1401.         push    8
  1402.         pop     ebx
  1403.         push    69
  1404.         pop     eax
  1405.         int     40h
  1406.         ret
  1407.  
  1408. AfterSuspend:
  1409.         mov     [bSuspended], 1
  1410.         call    get_new_context
  1411.         call    get_dump
  1412.         call    redraw_title
  1413.         call    redraw_registers
  1414.         call    redraw_dump
  1415.         call    update_disasm_eip
  1416.         ret
  1417.  
  1418. OnSuspend:
  1419.         mov     ecx, [debuggee_pid]
  1420.         push    4
  1421.         pop     ebx
  1422.         push    69
  1423.         pop     eax
  1424.         int     40h
  1425.         call    AfterSuspend
  1426.         mov     esi, aSuspended
  1427.         jmp     put_message
  1428. DoResume:
  1429.         mov     ecx, [debuggee_pid]
  1430.         push    5
  1431.         pop     ebx
  1432.         push    69
  1433.         pop     eax
  1434.         int     40h
  1435.         mov     [bSuspended], 0
  1436.         ret
  1437. OnResume:
  1438.         mov     esi, [curarg]
  1439.         cmp     byte [esi], 0
  1440.         jz      GoOn
  1441.         call    calc_expression
  1442.         jc      .ret
  1443.         mov     eax, ebp
  1444.         push    eax
  1445.         call    find_enabled_breakpoint
  1446.         pop     eax
  1447.         jz      GoOn
  1448.         mov     bl, 5   ; valid enabled one-shot
  1449.         call    add_breakpoint
  1450.         jnc     GoOn
  1451.         mov     esi, aBreakpointLimitExceeded
  1452.         call    put_message
  1453. .ret:
  1454.         ret
  1455. GoOn:
  1456. ; test for enabled breakpoint at eip
  1457.         mov     eax, [_eip]
  1458.         call    find_enabled_breakpoint
  1459.         jnz     .nobreak
  1460. ; temporarily disable breakpoint, make step, enable breakpoint, continue
  1461.         inc     eax
  1462.         mov     [temp_break], eax
  1463.         mov     [bAfterGo], 1
  1464.         dec     eax
  1465.         call    disable_breakpoint
  1466.         call    get_context
  1467.         or      byte [_eflags+1], 1             ; set TF
  1468.         call    set_context
  1469.         and     byte [_eflags+1], not 1
  1470.         call    DoResume
  1471.         ret
  1472. .nobreak:
  1473.         call    DoResume
  1474.         call    redraw_title
  1475.         call    redraw_registers
  1476.         call    redraw_dump
  1477.         ret
  1478. OnDetach:
  1479.         mov     ecx, [debuggee_pid]
  1480.         push    3
  1481.         pop     ebx
  1482.         push    69
  1483.         pop     eax
  1484.         int     40h
  1485.         and     [debuggee_pid], 0
  1486.         call    redraw_title
  1487.         call    redraw_registers
  1488.         call    redraw_dump
  1489.         mov     esi, aContinued
  1490.         jmp     put_message
  1491.  
  1492. after_go_exception:
  1493.         push    eax
  1494.         mov     eax, [temp_break]
  1495.         dec     eax
  1496.         push    esi
  1497.         call    enable_breakpoint
  1498. ; in any case, clear TF and RF
  1499.         call    get_new_context
  1500.         and     [_eflags], not 10100h           ; clear TF,RF
  1501.         call    set_context
  1502.         xor     edx, edx
  1503.         mov     [temp_break], edx
  1504.         xchg    dl, [bAfterGo]
  1505.         pop     esi
  1506.         pop     eax
  1507.         cmp     dl, 2
  1508.         jnz     @f
  1509.         lodsd
  1510.         push    esi
  1511.         call    get_dump
  1512.         jmp     exception.done
  1513. @@:     test    eax, eax
  1514.         jz      .notint1
  1515. ; if exception is result of single step, simply ignore it and continue
  1516.         test    dword [esi], 0xF
  1517.         jnz     dbgmsgstart.5
  1518.         lodsd
  1519.         push    esi
  1520.         mov     esi, oldcontext
  1521.         mov     edi, context
  1522.         mov     ecx, 28h/4
  1523.         rep     movsd
  1524.         call    DoResume
  1525.         jmp     dbgmsgend
  1526. .notint1:
  1527. ; in other case, work as without temp_break
  1528.         lodsd
  1529.         push    esi
  1530.         push    eax
  1531.         jmp     exception.4
  1532. .notour:
  1533.  
  1534. debugmsg:
  1535.         neg     [dbgbufsize]
  1536.         mov     esi, dbgbuf
  1537. dbgmsgstart:
  1538.         lodsd
  1539. ;       push    eax esi
  1540. ;       push    dword [esi]
  1541. ;       mov     esi, dbgmsg_str
  1542. ;       call    put_message_nodraw
  1543. ;       pop     esi eax
  1544.         add     esi, 4
  1545.         dec     eax
  1546.         jz      exception
  1547.         dec     eax
  1548.         jz      terminated
  1549.         mov     [bSuspended], 1
  1550.         cmp     [bAfterGo], 0
  1551.         jnz     after_go_exception
  1552.         push    esi
  1553.         call    get_new_context
  1554.         and     [_eflags], not 10100h           ; clear TF,RF
  1555.         call    set_context
  1556.         pop     esi
  1557. .5:
  1558.         push    esi
  1559.         call    get_dump
  1560.         pop     esi
  1561.         lodsd
  1562.         xor     ecx, ecx
  1563. .6:
  1564.         bt      eax, ecx
  1565.         jnc     .7
  1566.         mov     ebx, [drx_break+ecx*4]
  1567.         test    ebx, ebx
  1568.         jz      .7
  1569.         pushad
  1570.         dec     ebx
  1571.         push    ebx
  1572.         mov     esi, aBreakStop
  1573.         call    put_message_nodraw
  1574.         popad
  1575. .7:
  1576.         inc     ecx
  1577.         cmp     cl, 4
  1578.         jb      .6
  1579.         push    esi
  1580.         jmp     exception.done_draw
  1581. terminated:
  1582.         push    esi
  1583.         mov     esi, terminated_msg
  1584.         call    put_message
  1585.         and     [debuggee_pid], 0
  1586.         and     [temp_break], 0
  1587.         mov     [bAfterGo], 0
  1588.         xor     eax, eax
  1589.         mov     ecx, breakpoints_n*6/4+4
  1590.         mov     edi, breakpoints
  1591.         rep     stosd
  1592.         cmp     [bReload], 1
  1593.         sbb     [bReload], -1
  1594.         jmp     exception.done
  1595. exception:
  1596.         mov     [bSuspended], 1
  1597.         cmp     [bAfterGo], 0
  1598.         jnz     after_go_exception
  1599.         lodsd
  1600.         push    esi
  1601.         push    eax
  1602.         call    get_new_context
  1603.         and     [_eflags], not 10100h           ; clear TF,RF
  1604.         call    set_context
  1605. .4:
  1606.         call    get_dump
  1607.         pop     eax
  1608. ; int3 command generates exception 0D, #GP
  1609.         push    eax
  1610.         cmp     al, 0Dh
  1611.         jnz     .notdbg
  1612. ; check for 0xCC byte at eip
  1613.         push    0
  1614.         push    69
  1615.         pop     eax
  1616.         push    6
  1617.         pop     ebx
  1618.         mov     ecx, [debuggee_pid]
  1619.         mov     edi, esp
  1620.         mov     esi, [_eip]
  1621.         push    1
  1622.         pop     edx
  1623.         int     40h
  1624.         pop     eax
  1625.         cmp     al, 0xCC
  1626.         jnz     .notdbg
  1627. ; this is either dbg breakpoint or int3 cmd in debuggee
  1628.         mov     eax, [_eip]
  1629.         call    find_enabled_breakpoint
  1630.         jnz     .user_int3
  1631. ; dbg breakpoint; clear if one-shot
  1632.         pop     ecx
  1633.         push    eax
  1634.         mov     esi, aBreakStop
  1635.         test    byte [edi+4], 4
  1636.         jz      .put_msg_eax
  1637.         pop     ecx
  1638.         call    clear_breakpoint
  1639.         jmp     .done
  1640. .user_int3:
  1641.         mov     eax, [_eip]
  1642.         inc     [_eip]
  1643.         pop     ecx
  1644.         push    eax
  1645.         call    set_context
  1646.         mov     esi, aUserBreak
  1647.         jmp     .put_msg_eax
  1648. .notdbg:
  1649.         mov     esi, aException
  1650. .put_msg_eax:
  1651.         call    put_message_nodraw
  1652. .done_draw:
  1653.         call    draw_messages
  1654. .done:
  1655.         push    18
  1656.         pop     eax
  1657.         push    3
  1658.         pop     ebx
  1659.         mov     ecx, [dbgwnd]
  1660.         int     40h     ; activate dbg window
  1661.         call    redraw_title
  1662.         call    redraw_registers
  1663.         call    redraw_dump
  1664.         call    update_disasm_eip
  1665. dbgmsgend:
  1666.         pop     esi
  1667.         mov     ecx, [dbgbuflen]
  1668.         add     ecx, dbgbuf
  1669.         cmp     esi, ecx
  1670.         jnz     dbgmsgstart
  1671.         and     [dbgbuflen], 0
  1672.         neg     [dbgbufsize]
  1673.         cmp     [bReload], 2
  1674.         jnz     @f
  1675.         mov     [bReload], 0
  1676.         call    do_reload
  1677. @@:
  1678.         jmp     waitevent
  1679.  
  1680. CtrlF7:
  1681.         cmp     [debuggee_pid], 0
  1682.         jz      .no
  1683.         call    OnStep
  1684. .no:
  1685.         jmp     waitevent
  1686. CtrlF8:
  1687.         cmp     [debuggee_pid], 0
  1688.         jz      CtrlF7.no
  1689.         call    OnProceed
  1690.         jmp     CtrlF7.no
  1691.  
  1692. OnStep:
  1693.         cmp     [bSuspended], 0
  1694.         jz      .running
  1695.         call    get_context
  1696.         or      byte [_eflags+1], 1             ; set TF
  1697.         call    set_context
  1698.         and     byte [_eflags+1], not 1
  1699. ; if instruction at eip is "int xx", set one-shot breakpoint immediately after
  1700.         mov     eax, [_eip]
  1701.         call    find_enabled_breakpoint
  1702.         jnz     @f
  1703.         cmp     byte [edi+5], 0xCD
  1704.         jz      .int
  1705. @@:
  1706.         push    0
  1707.         push    69
  1708.         pop     eax
  1709.         push    6
  1710.         pop     ebx
  1711.         mov     ecx, [debuggee_pid]
  1712.         push    3
  1713.         pop     edx
  1714.         mov     edi, esp
  1715.         mov     esi, [_eip]
  1716.         int     40h
  1717.         cmp     eax, edx
  1718.         pop     eax
  1719.         jnz     .doit
  1720.         cmp     al, 0xCD
  1721.         jz      .int
  1722.         cmp     ax, 0x050F
  1723.         jz      .syscall_enter
  1724.         cmp     ax, 0x340F
  1725.         jz      .syscall_enter
  1726. ; resume process
  1727. .doit:
  1728.         call    GoOn
  1729.         cmp     [bAfterGo], 0
  1730.         jz      @f
  1731.         mov     [bAfterGo], 2
  1732. @@:
  1733.         ret
  1734. .syscall_enter:
  1735.         and     byte [_eflags+1], not 1 ; clear TF - avoid system halt (!)
  1736.         call    set_context
  1737. .int:
  1738.         mov     eax, [_eip]
  1739.         inc     eax
  1740.         inc     eax
  1741.         push    eax
  1742.         call    find_enabled_breakpoint
  1743.         pop     eax
  1744.         jz      .doit
  1745. ; there is no enabled breakpoint yet; set temporary breakpoint
  1746.         mov     bl, 5
  1747.         call    add_breakpoint
  1748.         jmp     .doit
  1749. .running:
  1750.         mov     esi, aRunningErr
  1751.         jmp     put_message
  1752.  
  1753. OnProceed:
  1754.         cmp     [bSuspended], 0
  1755.         jz      OnStep.running
  1756.         mov     esi, [_eip]
  1757. @@:
  1758.         call    get_byte_nobreak
  1759.         jc      OnStep
  1760.         inc     esi
  1761. ; skip prefixes
  1762.         call    is_prefix
  1763.         jz      @b
  1764.         cmp     al, 0xE8        ; call
  1765.         jnz     @f
  1766.         add     esi, 4
  1767.         jmp     .doit
  1768. @@:     ; A4,A5 = movs, A6,A7=cmps
  1769.         cmp     al, 0xA4
  1770.         jb      @f
  1771.         cmp     al, 0xA8
  1772.         jb      .doit
  1773. @@:     ; AA,AB=stos, AC,AD=lods, AE,AF=scas
  1774.         cmp     al, 0xAA
  1775.         jb      @f
  1776.         cmp     al, 0xB0
  1777.         jb      .doit
  1778. @@:     ; E0=loopnz,E1=loopz,E2=loop
  1779.         cmp     al, 0xE0
  1780.         jb      .noloop
  1781.         cmp     al, 0xE2
  1782.         ja      .noloop
  1783.         inc     esi
  1784.         jmp     .doit
  1785. .noloop:        ; FF /2 = call
  1786.         cmp     al, 0xFF
  1787.         jnz     OnStep
  1788.         call    get_byte_nobreak
  1789.         jc      OnStep
  1790.         inc     esi
  1791.         mov     cl, al
  1792.         and     al, 00111000b
  1793.         cmp     al, 00010000b
  1794.         jnz     OnStep
  1795. ; skip instruction
  1796.         mov     al, cl
  1797.         and     eax, 7
  1798.         shr     cl, 6
  1799.         jz      .mod0
  1800.         jp      .doit
  1801.         cmp     al, 4
  1802.         jnz     @f
  1803.         inc     esi
  1804. @@:
  1805.         inc     esi
  1806.         dec     cl
  1807.         jz      @f
  1808.         add     esi, 3
  1809. @@:
  1810.         jmp     .doit
  1811. .mod0:
  1812.         cmp     al, 4
  1813.         jnz     @f
  1814.         call    get_byte_nobreak
  1815.         jc      OnStep
  1816.         inc     esi
  1817.         and     al, 7
  1818. @@:
  1819.         cmp     al, 5
  1820.         jnz     .doit
  1821.         add     esi, 4
  1822. .doit:
  1823. ; insert one-shot breakpoint at esi and resume
  1824.         call    get_byte_nobreak
  1825.         jc      OnStep
  1826.         mov     eax, esi
  1827.         call    find_enabled_breakpoint
  1828.         jz      .ret
  1829.         mov     eax, esi
  1830.         mov     bl, 5
  1831.         call    add_breakpoint
  1832.         jmp     OnStep.doit
  1833. .ret:
  1834.         ret
  1835.  
  1836. get_byte_nobreak:
  1837.         mov     eax, esi
  1838.         call    find_enabled_breakpoint
  1839.         jnz     .nobreak
  1840.         mov     al, [edi+5]
  1841.         clc
  1842.         ret
  1843. .nobreak:
  1844.         push    69
  1845.         pop     eax
  1846.         push    6
  1847.         pop     ebx
  1848.         mov     ecx, [debuggee_pid]
  1849.         xor     edx, edx
  1850.         push    edx
  1851.         inc     edx
  1852.         mov     edi, esp
  1853.         int     40h
  1854.         dec     eax
  1855.         clc
  1856.         jz      @f
  1857.         stc
  1858. @@:     pop     eax
  1859.         ret
  1860.  
  1861. is_prefix:
  1862.         cmp     al, 0x64        ; fs:
  1863.         jz      .ret
  1864.         cmp     al, 0x65        ; gs:
  1865.         jz      .ret
  1866.         cmp     al, 0x66        ; use16/32
  1867.         jz      .ret
  1868.         cmp     al, 0x67        ; addr16/32
  1869.         jz      .ret
  1870.         cmp     al, 0xF0        ; lock
  1871.         jz      .ret
  1872.         cmp     al, 0xF2        ; repnz
  1873.         jz      .ret
  1874.         cmp     al, 0xF3        ; rep(z)
  1875.         jz      .ret
  1876.         cmp     al, 0x2E        ; cs:
  1877.         jz      .ret
  1878.         cmp     al, 0x36        ; ss:
  1879.         jz      .ret
  1880.         cmp     al, 0x3E        ; ds:
  1881.         jz      .ret
  1882.         cmp     al, 0x26        ; es:
  1883. .ret:   ret
  1884.  
  1885. token_end       equ     1
  1886. token_reg       equ     2
  1887. token_hex       equ     3
  1888. token_add       equ     4
  1889. token_sub       equ     5
  1890. token_mul       equ     6
  1891. token_div       equ     7
  1892. token_lp        equ     8
  1893. token_rp        equ     9
  1894. token_err       equ     -1
  1895.  
  1896. is_hex_digit:
  1897.         cmp     al, '0'
  1898.         jb      .no
  1899.         cmp     al, '9'
  1900.         jbe     .09
  1901.         cmp     al, 'A'
  1902.         jb      .no
  1903.         cmp     al, 'F'
  1904.         jbe     .AF
  1905.         cmp     al, 'a'
  1906.         jb      .no
  1907.         cmp     al, 'f'
  1908.         jbe     .af
  1909. .no:
  1910.         stc
  1911.         ret
  1912. .09:
  1913.         sub     al, '0'
  1914. ;       clc
  1915.         ret
  1916. .AF:
  1917.         sub     al, 'A'-10
  1918. ;       clc
  1919.         ret
  1920. .af:
  1921.         sub     al, 'a'-10
  1922. ;       clc
  1923.         ret
  1924.  
  1925. find_reg:
  1926.         mov     edi, reg_table
  1927. .findreg:
  1928.         movzx   ecx, byte [edi]
  1929.         stc
  1930.         jecxz   .regnotfound
  1931.         inc     edi
  1932.         push    esi edi ecx
  1933. @@:
  1934.         lodsb
  1935.         or      al, 20h
  1936.         scasb
  1937.         loopz   @b
  1938.         pop     ecx edi esi
  1939.         lea     edi, [edi+ecx+1]
  1940.         jnz     .findreg
  1941.         movzx   edi, byte [edi-1]
  1942.         add     esi, ecx
  1943. .regnotfound:
  1944.         ret
  1945.  
  1946. expr_get_token:
  1947.         lodsb
  1948.         cmp     al, 0
  1949.         jz      .end_token
  1950.         cmp     al, ' '
  1951.         jbe     expr_get_token
  1952.         cmp     al, '+'
  1953.         jz      .add
  1954.         cmp     al, '-'
  1955.         jz      .sub
  1956.         cmp     al, '*'
  1957.         jz      .mul
  1958.         cmp     al, '/'
  1959.         jz      .div
  1960.         cmp     al, '('
  1961.         jz      .lp
  1962.         cmp     al, ')'
  1963.         jnz     .notsign
  1964. .rp:
  1965.         mov     al, token_rp
  1966.         ret
  1967. .div:
  1968.         mov     al, token_div
  1969.         ret
  1970. .end_token:
  1971.         mov     al, token_end
  1972.         ret
  1973. .add:
  1974.         mov     al, token_add
  1975.         ret
  1976. .sub:
  1977.         mov     al, token_sub
  1978.         ret
  1979. .mul:
  1980.         mov     al, token_mul
  1981.         ret
  1982. .lp:
  1983.         mov     al, token_lp
  1984.         ret
  1985. .notsign:
  1986.         dec     esi
  1987.         call    find_reg
  1988.         jc      .regnotfound
  1989.         mov     al, token_reg
  1990.         ret
  1991. .regnotfound:
  1992. ; test for hex number
  1993.         xor     ecx, ecx
  1994.         xor     edi, edi
  1995.         xor     eax, eax
  1996. @@:
  1997.         lodsb
  1998.         call    is_hex_digit
  1999.         jc      @f
  2000.         shl     edi, 4
  2001.         or      edi, eax
  2002.         inc     ecx
  2003.         jmp     @b
  2004. @@:
  2005.         dec     esi
  2006.         jecxz   .err
  2007.         cmp     ecx, 8
  2008.         ja      .err
  2009.         mov     al, token_hex
  2010.         ret
  2011. .err:
  2012.         mov     al, token_err
  2013.         mov     esi, aParseError
  2014.         ret
  2015.  
  2016. expr_read2:
  2017.         cmp     al, token_hex
  2018.         jz      .hex
  2019.         cmp     al, token_reg
  2020.         jz      .reg
  2021.         cmp     al, token_lp
  2022.         jz      .lp
  2023.         mov     al, token_err
  2024.         mov     esi, aParseError
  2025.         ret
  2026. .hex:
  2027.         mov     ebp, edi
  2028. .ret:
  2029.         jmp     expr_get_token
  2030. .reg:
  2031.         cmp     edi, 24
  2032.         jz      .eip
  2033.         sub     edi, 4
  2034.         jb      .8lo
  2035.         sub     edi, 4
  2036.         jb      .8hi
  2037.         sub     edi, 8
  2038.         jb      .16
  2039.         mov     ebp, [_eax+edi*4]
  2040.         jmp     .ret
  2041. .16:
  2042.         movzx   ebp, word [_eax+(edi+8)*4]
  2043.         jmp     .ret
  2044. .8lo:
  2045.         movzx   ebp, byte [_eax+(edi+4)*4]
  2046.         jmp     .ret
  2047. .8hi:
  2048.         movzx   ebp, byte [_eax+(edi+4)*4+1]
  2049.         jmp     .ret
  2050. .eip:
  2051.         mov     ebp, [_eip]
  2052.         jmp     .ret
  2053. .lp:
  2054.         call    expr_get_token
  2055.         call    expr_read0
  2056.         cmp     al, token_err
  2057.         jz      @f
  2058.         cmp     al, token_rp
  2059.         jz      expr_get_token
  2060.         mov     al, token_err
  2061.         mov     esi, aParseError
  2062. @@:     ret
  2063.  
  2064. expr_read1:
  2065.         call    expr_read2
  2066. .1:
  2067.         cmp     al, token_mul
  2068.         jz      .mul
  2069.         cmp     al, token_div
  2070.         jz      .div
  2071.         ret
  2072. .mul:
  2073.         push    ebp
  2074.         call    expr_get_token
  2075.         call    expr_read2
  2076.         pop     edx
  2077. ; ebp := edx*ebp
  2078.         imul    ebp, edx
  2079.         jmp     .1
  2080. .div:
  2081.         push    ebp
  2082.         call    expr_get_token
  2083.         call    expr_read2
  2084.         pop     edx
  2085. ; ebp := edx/ebp
  2086.         test    ebp, ebp
  2087.         jz      .div0
  2088.         push    eax
  2089.         xor     eax, eax
  2090.         xchg    eax, edx
  2091.         div     ebp
  2092.         xchg    eax, ebp
  2093.         pop     eax
  2094.         jmp     .1
  2095. .div0:
  2096.         mov     al, token_err
  2097.         mov     esi, aDivByZero
  2098.         ret
  2099.  
  2100. expr_read0:
  2101.         xor     ebp, ebp
  2102.         cmp     al, token_add
  2103.         jz      .add
  2104.         cmp     al, token_sub
  2105.         jz      .sub
  2106.         call    expr_read1
  2107. .1:
  2108.         cmp     al, token_add
  2109.         jz      .add
  2110.         cmp     al, token_sub
  2111.         jz      .sub
  2112.         ret
  2113. .add:
  2114.         push    ebp
  2115.         call    expr_get_token
  2116.         call    expr_read1
  2117.         pop     edx
  2118. ; ebp := edx+ebp
  2119.         add     ebp, edx
  2120.         jmp     .1
  2121. .sub:
  2122.         push    ebp
  2123.         call    expr_get_token
  2124.         call    expr_read1
  2125.         pop     edx
  2126. ; ebp := edx-ebp
  2127.         xchg    edx, ebp
  2128.         sub     ebp, edx
  2129.         jmp     .1
  2130.  
  2131. calc_expression:
  2132. ; in: esi->expression
  2133. ; out: CF=1 if error
  2134. ;      CF=0 and ebp=value if ok
  2135.         call    expr_get_token
  2136.         call    expr_read0
  2137.         cmp     al, token_end
  2138.         jz      .end
  2139.         cmp     al, token_err
  2140.         jz      @f
  2141.         mov     esi, aParseError
  2142. @@:
  2143.         call    put_message
  2144.         stc
  2145.         ret
  2146. .end:
  2147.         clc
  2148.         ret
  2149.  
  2150. OnCalc:
  2151.         mov     esi, [curarg]
  2152.         call    calc_expression
  2153.         jc      .ret
  2154.         push    ebp
  2155.         mov     esi, calc_string
  2156.         call    put_message_nodraw
  2157.         jmp     draw_messages
  2158. .ret:
  2159.         ret
  2160.  
  2161. OnDump:
  2162.         mov     esi, [curarg]
  2163.         cmp     byte [esi], 0
  2164.         jnz     .param
  2165.         add     [dumppos], dump_height*10h
  2166.         jmp     .doit
  2167. .param:
  2168.         call    calc_expression
  2169.         jc      .ret
  2170.         mov     [dumppos], ebp
  2171. .doit:
  2172.         call    get_dump
  2173.         call    redraw_dump
  2174. .ret:
  2175.         ret
  2176.  
  2177. OnUnassemble:
  2178.         mov     esi, [curarg]
  2179.         cmp     byte [esi], 0
  2180.         jnz     .param
  2181.         mov     eax, [disasm_start_pos]
  2182.         mov     ecx, disasm_height
  2183.         mov     [disasm_cur_pos], eax
  2184. @@:
  2185.         push    ecx
  2186.         call    disasm_instr
  2187.         pop     ecx
  2188.         jc      .err
  2189.         loop    @b
  2190.         mov     eax, [disasm_cur_pos]
  2191.         jmp     .doit
  2192. .param:
  2193.         call    calc_expression
  2194.         jc      .ret
  2195.         mov     eax, ebp
  2196. .doit:
  2197.         push    eax
  2198.         push    [disasm_start_pos]
  2199.         mov     [disasm_start_pos], eax
  2200.         call    update_disasm
  2201.         pop     [disasm_start_pos]
  2202.         pop     eax
  2203.         cmp     [disasm_cur_str], 0
  2204.         jz      @f
  2205.         mov     [disasm_start_pos], eax
  2206. .ret:
  2207.         ret
  2208. @@:
  2209.         call    update_disasm
  2210. .err:
  2211.         mov     esi, aInvAddr
  2212.         jmp     put_message
  2213.  
  2214. OnReg:
  2215.         mov     esi, [curarg]
  2216.         call    skip_spaces
  2217.         call    find_reg
  2218.         jnc     @f
  2219. .err:
  2220.         mov     esi, RSyntax
  2221.         jmp     put_message
  2222. @@:
  2223.         call    skip_spaces
  2224.         test    al, al
  2225.         jz      .err
  2226.         cmp     al, '='
  2227.         jnz     @f
  2228.         inc     esi
  2229.         call    skip_spaces
  2230.         test    al, al
  2231.         jz      .err
  2232. @@:
  2233.         push    edi
  2234.         call    calc_expression
  2235.         pop     edi
  2236.         jc      .ret
  2237. ; now edi=register id, ebp=value
  2238.         cmp     [bSuspended], 0
  2239.         mov     esi, aRunningErr
  2240.         jz      put_message
  2241.         xchg    eax, ebp
  2242.         cmp     edi, 24
  2243.         jz      .eip
  2244.         sub     edi, 4
  2245.         jb      .8lo
  2246.         sub     edi, 4
  2247.         jb      .8hi
  2248.         sub     edi, 8
  2249.         jb      .16
  2250.         mov     [_eax+edi*4], eax
  2251.         jmp     .ret
  2252. .16:
  2253.         mov     word [_eax+(edi+8)*4], ax
  2254.         jmp     .ret
  2255. .8lo:
  2256.         mov     byte [_eax+(edi+4)*4], al
  2257.         jmp     .ret
  2258. .8hi:
  2259.         mov     byte [_eax+(edi+4)*4+1], al
  2260.         jmp     .ret
  2261. .eip:
  2262.         mov     [_eip], eax
  2263.         call    update_disasm_eip
  2264. .ret:
  2265.         call    set_context
  2266.         jmp     redraw_registers
  2267.  
  2268. ; Breakpoints manipulation
  2269. OnBp:
  2270.         mov     esi, [curarg]
  2271.         call    calc_expression
  2272.         jc      .ret
  2273.         xchg    eax, ebp
  2274.         push    eax
  2275.         call    find_breakpoint
  2276.         inc     eax
  2277.         pop     eax
  2278.         jz      .notfound
  2279.         mov     esi, aDuplicateBreakpoint
  2280.         jmp     .sayerr
  2281. .notfound:
  2282.         mov     bl, 1
  2283.         call    add_breakpoint
  2284.         jnc     .ret
  2285.         mov     esi, aBreakpointLimitExceeded
  2286. .sayerr:
  2287.         call    put_message
  2288. .ret:
  2289.         jmp     redraw_disasm
  2290.  
  2291. OnBpmb:
  2292.         mov     dh, 0011b
  2293.         jmp     DoBpm
  2294. OnBpmw:
  2295.         mov     dh, 0111b
  2296.         jmp     DoBpm
  2297. OnBpmd:
  2298.         mov     dh, 1111b
  2299. DoBpm:
  2300.         mov     esi, [curarg]
  2301.         cmp     byte [esi], 'w'
  2302.         jnz     @f
  2303.         and     dh, not 2
  2304.         inc     esi
  2305. @@:
  2306.         push    edx
  2307.         call    calc_expression
  2308.         pop     edx
  2309.         jnc     @f
  2310.         ret
  2311. @@:
  2312. ; ebp=expression, dh=flags
  2313.         movzx   eax, dh
  2314.         shr     eax, 2
  2315.         test    ebp, eax
  2316.         jz      @f
  2317.         mov     esi, aUnaligned
  2318.         jmp     put_message
  2319. @@:
  2320.         mov     eax, ebp
  2321.         mov     bl, 0Bh
  2322.         call    add_breakpoint
  2323.         jnc     @f
  2324.         mov     esi, aBreakpointLimitExceeded
  2325.         jmp     put_message
  2326. @@:
  2327. ; now find index
  2328.         push    eax
  2329.         xor     ecx, ecx
  2330. .l1:
  2331.         cmp     [drx_break+ecx*4], 0
  2332.         jnz     .l2
  2333.         push    69
  2334.         pop     eax
  2335.         push    ecx
  2336.         mov     dl, cl
  2337.         mov     ecx, [debuggee_pid]
  2338.         mov     esi, ebp
  2339.         push    9
  2340.         pop     ebx
  2341.         int     40h
  2342.         test    eax, eax
  2343.         jz      .ok
  2344.         pop     ecx
  2345. .l2:
  2346.         inc     ecx
  2347.         cmp     ecx, 4
  2348.         jb      .l1
  2349.         pop     eax
  2350.         call    clear_breakpoint
  2351.         mov     esi, aBreakpointLimitExceeded
  2352.         jmp     put_message
  2353. .ok:
  2354.         pop     ecx
  2355.         pop     eax
  2356.         and     byte [edi], not 2       ; breakpoint is enabled
  2357.         shl     dl, 6
  2358.         or      dl, dh
  2359.         mov     byte [edi+1], dl
  2360.         inc     eax
  2361.         mov     [drx_break+ecx*4], eax
  2362.         ret
  2363.  
  2364. OnBc:
  2365.         mov     esi, [curarg]
  2366. @@:     call    get_hex_number
  2367.         jc      OnBp.ret
  2368.         call    clear_breakpoint
  2369.         jmp     @b
  2370.  
  2371. OnBd:
  2372.         mov     esi, [curarg]
  2373. @@:     call    get_hex_number
  2374.         jc      OnBp.ret
  2375.         call    disable_breakpoint
  2376.         jmp     @b
  2377.  
  2378. OnBe:
  2379.         mov     esi, [curarg]
  2380. @@:     call    get_hex_number
  2381.         jc      OnBp.ret
  2382.         push    eax
  2383.         call    find_enabled_breakpoint
  2384.         pop     eax
  2385.         jz      .err
  2386.         call    enable_breakpoint
  2387.         jmp     @b
  2388. .err:
  2389.         mov     esi, OnBeErrMsg
  2390.         jmp     put_message
  2391.  
  2392. get_hex_number:
  2393.         call    skip_spaces
  2394.         xor     ecx, ecx
  2395.         xor     edx, edx
  2396. @@:
  2397.         lodsb
  2398.         call    is_hex_digit
  2399.         jc      .ret
  2400.         shl     edx, 4
  2401.         or      dl, al
  2402.         inc     ecx
  2403.         jmp     @b
  2404. .ret:
  2405.         dec     esi
  2406.         cmp     ecx, 1
  2407.         xchg    eax, edx
  2408.         ret
  2409.  
  2410. OnBl:
  2411.         mov     esi, [curarg]
  2412.         cmp     byte [esi], 0
  2413.         jz      .listall
  2414.         call    get_hex_number
  2415.         jc      .ret
  2416.         cmp     eax, breakpoints_n
  2417.         jae     .err
  2418.         push    eax
  2419.         add     eax, eax
  2420.         lea     edi, [breakpoints + eax + eax*2]
  2421.         pop     eax
  2422.         test    byte [edi+4], 1
  2423.         jz      .err
  2424.         call    show_break_info
  2425. .ret:
  2426.         ret
  2427. .err:
  2428.         mov     esi, aInvalidBreak
  2429.         jmp     put_message
  2430. .listall:
  2431.         mov     edi, breakpoints
  2432.         xor     eax, eax
  2433. @@:
  2434.         test    byte [edi+4], 1
  2435.         jz      .cont
  2436.         push    edi eax
  2437.         call    show_break_info
  2438.         pop     eax edi
  2439. .cont:
  2440.         add     edi, 6
  2441.         inc     eax
  2442.         cmp     eax, breakpoints_n
  2443.         jb      @b
  2444.         ret
  2445.  
  2446. show_break_info:
  2447.         push    edi
  2448.         test    byte [edi+4], 8
  2449.         jnz     .dr
  2450.         push    dword [edi]
  2451.         push    eax
  2452.         mov     esi, aBreakNum
  2453.         call    put_message_nodraw
  2454.         jmp     .cmn
  2455. .dr:
  2456.         push    eax
  2457.         mov     esi, aMemBreak1
  2458.         call    put_message_nodraw
  2459.         pop     edi
  2460.         push    edi
  2461.         mov     esi, aMemBreak2
  2462.         test    byte [edi+5], 2
  2463.         jz      @f
  2464.         mov     esi, aMemBreak3
  2465. @@:
  2466.         call    put_message_nodraw
  2467.         pop     edi
  2468.         push    edi
  2469.         mov     esi, aMemBreak6
  2470.         test    byte [edi+5], 8
  2471.         jnz     @f
  2472.         mov     esi, aMemBreak5
  2473.         test    byte [edi+5], 4
  2474.         jnz     @f
  2475.         mov     esi, aMemBreak4
  2476. @@:
  2477.         call    put_message_nodraw
  2478.         pop     edi
  2479.         push    edi
  2480.         push    dword [edi]
  2481.         mov     esi, aMemBreak7
  2482.         call    put_message_nodraw
  2483. .cmn:
  2484.         pop     edi
  2485.         test    byte [edi+4], 2
  2486.         jz      @f
  2487.         push    edi
  2488.         mov     esi, aDisabled
  2489.         call    put_message_nodraw
  2490.         pop     edi
  2491. @@:
  2492.         test    byte [edi+4], 4
  2493.         jz      @f
  2494.         mov     esi, aOneShot
  2495.         call    put_message_nodraw
  2496. @@:
  2497.         mov     esi, newline
  2498.         jmp     put_message
  2499.  
  2500. add_breakpoint:
  2501. ; in: eax=address, bl=flags
  2502. ; out: CF=1 => error, CF=0 => eax=breakpoint number
  2503.         xor     ecx, ecx
  2504.         mov     edi, breakpoints
  2505. @@:
  2506.         test    byte [edi+4], 1
  2507.         jz      .found
  2508.         add     edi, 6
  2509.         inc     ecx
  2510.         cmp     ecx, breakpoints_n
  2511.         jb      @b
  2512.         stc
  2513.         ret
  2514. .found:
  2515.         stosd
  2516.         xchg    eax, ecx
  2517.         mov     [edi], bl
  2518.         test    bl, 2
  2519.         jnz     @f
  2520.         or      byte [edi], 2
  2521.         push    eax
  2522.         call    enable_breakpoint
  2523.         pop     eax
  2524. @@:
  2525.         clc
  2526.         ret
  2527.  
  2528. clear_breakpoint:
  2529.         cmp     eax, breakpoints_n
  2530.         jae     .ret
  2531.         mov     ecx, 4
  2532.         inc     eax
  2533. .1:
  2534.         cmp     [drx_break-4+ecx*4], eax
  2535.         jnz     @f
  2536.         and     [drx_break-4+ecx*4], 0
  2537. @@:     loop    .1
  2538.         dec     eax
  2539.         push    eax
  2540.         add     eax, eax
  2541.         lea     edi, [breakpoints + eax + eax*2 + 4]
  2542.         test    byte [edi], 1
  2543.         pop     eax
  2544.         jz      .ret
  2545.         push    edi
  2546.         call    disable_breakpoint
  2547.         pop     edi
  2548.         mov     byte [edi], 0
  2549. .ret:
  2550.         ret
  2551.  
  2552. disable_breakpoint:
  2553.         cmp     eax, breakpoints_n
  2554.         jae     .ret
  2555.         add     eax, eax
  2556.         lea     edi, [breakpoints + eax + eax*2 + 5]
  2557.         test    byte [edi-1], 1
  2558.         jz      .ret
  2559.         test    byte [edi-1], 2
  2560.         jnz     .ret
  2561.         or      byte [edi-1], 2
  2562.         test    byte [edi-1], 8
  2563.         jnz     .dr
  2564.         push    esi
  2565.         push    7
  2566.         pop     ebx
  2567.         push    69
  2568.         pop     eax
  2569.         mov     ecx, [debuggee_pid]
  2570.         xor     edx, edx
  2571.         inc     edx
  2572.         mov     esi, [edi-5]
  2573.         int     40h
  2574.         pop     esi
  2575. .ret:
  2576.         ret
  2577. .dr:
  2578.         mov     dl, [edi]
  2579.         shr     dl, 6
  2580.         mov     dh, 80h
  2581.         push    69
  2582.         pop     eax
  2583.         push    9
  2584.         pop     ebx
  2585.         mov     ecx, [debuggee_pid]
  2586.         int     40h
  2587.         ret
  2588.  
  2589. enable_breakpoint:
  2590.         push    esi
  2591.         cmp     eax, breakpoints_n
  2592.         jae     .ret
  2593.         add     eax, eax
  2594.         lea     edi, [breakpoints + eax + eax*2 + 5]
  2595.         test    byte [edi-1], 1
  2596.         jz      .ret
  2597.         test    byte [edi-1], 2
  2598.         jz      .ret
  2599.         and     byte [edi-1], not 2
  2600.         test    byte [edi-1], 8
  2601.         jnz     .dr
  2602.         push    6
  2603.         pop     ebx
  2604.         push    69
  2605.         pop     eax
  2606.         mov     esi, [edi-5]
  2607.         mov     ecx, [debuggee_pid]
  2608.         xor     edx, edx
  2609.         inc     edx
  2610.         int     40h
  2611.         dec     eax
  2612.         jnz     .err
  2613.         mov     al, 69
  2614.         push    0xCC
  2615.         mov     edi, esp
  2616.         inc     ebx
  2617.         int     40h
  2618.         pop     eax
  2619. .ret:
  2620.         pop     esi
  2621.         ret
  2622. .err:
  2623.         or      byte [edi-1], 2
  2624.         mov     esi, aBreakErr
  2625.         call    put_message
  2626.         pop     esi
  2627.         ret
  2628. .dr:
  2629.         push    9
  2630.         pop     ebx
  2631.         push    69
  2632.         pop     eax
  2633.         mov     esi, [edi-5]
  2634.         mov     ecx, [debuggee_pid]
  2635.         mov     dl, [edi]
  2636.         shr     dl, 6
  2637.         mov     dh, [edi]
  2638.         and     dh, 0xF
  2639.         int     40h
  2640.         test    eax, eax
  2641.         jnz     .err
  2642.         pop     esi
  2643.         ret
  2644.  
  2645. find_breakpoint:
  2646.         xor     ecx, ecx
  2647.         xchg    eax, ecx
  2648.         mov     edi, breakpoints
  2649. @@:
  2650.         test    byte [edi+4], 1
  2651.         jz      .cont
  2652.         test    byte [edi+4], 8
  2653.         jnz     .cont
  2654.         cmp     [edi], ecx
  2655.         jz      .found
  2656. .cont:
  2657.         add     edi, 6
  2658.         inc     eax
  2659.         cmp     eax, breakpoints_n
  2660.         jb      @b
  2661.         or      eax, -1
  2662. .found:
  2663.         ret
  2664.  
  2665. find_enabled_breakpoint:
  2666.         xor     ecx, ecx
  2667.         xchg    eax, ecx
  2668.         mov     edi, breakpoints
  2669. @@:
  2670.         test    byte [edi+4], 1
  2671.         jz      .cont
  2672.         test    byte [edi+4], 2 or 8
  2673.         jnz     .cont
  2674.         cmp     [edi], ecx
  2675.         jz      .found
  2676. .cont:
  2677.         add     edi, 6
  2678.         inc     eax
  2679.         cmp     eax, breakpoints_n
  2680.         jb      @b
  2681.         or      eax, -1
  2682. .found:
  2683.         ret
  2684.  
  2685. OnUnpack:
  2686. ; program must be loaded - checked when command was parsed
  2687. ; program must be stopped
  2688.         mov     esi, aRunningErr
  2689.         cmp     [bSuspended], 0
  2690.         jz      put_message
  2691. ; all breakpoints must be disabled
  2692.         mov     edi, breakpoints
  2693. @@:
  2694.         test    byte [edi+4], 1
  2695.         jz      .cont
  2696.         test    byte [edi+4], 2
  2697.         jnz     .cont
  2698.         mov     esi, aEnabledBreakErr
  2699.         jmp     put_message
  2700. .cont:
  2701.         add     edi, 6
  2702.         cmp     edi, breakpoints+breakpoints_n*6
  2703.         jb      @b
  2704. ; ok, now do it
  2705. ; set breakpoint on 0xC dword access
  2706.         push    9
  2707.         pop     ebx
  2708.         mov     ecx, [debuggee_pid]
  2709.         mov     dx, 1111b*256
  2710.         push    0xC
  2711.         pop     esi
  2712. @@:
  2713.         push    69
  2714.         pop     eax
  2715.         int     40h
  2716.         test    eax, eax
  2717.         jz      .breakok
  2718.         inc     edx
  2719.         cmp     dl, 4
  2720.         jb      @b
  2721. .breakok:
  2722.         call    GoOn
  2723. ; now wait for event
  2724. .wait:
  2725.         push    10
  2726.         pop     eax
  2727.         int     40h
  2728.         dec     eax
  2729.         jz      .redraw
  2730.         dec     eax
  2731.         jz      .key
  2732.         dec     eax
  2733.         jnz     .debug
  2734. ; button; we have only one button, close
  2735.         or      eax, -1
  2736.         int     40h
  2737. .redraw:
  2738.         call    draw_window
  2739.         jmp     .wait
  2740. .key:
  2741.         mov     al, 2
  2742.         int     40h
  2743.         cmp     ah, 3   ; Ctrl+C
  2744.         jnz     .wait
  2745. .userbreak:
  2746.         mov     esi, aInterrupted
  2747. .x1:
  2748.         push    edx esi
  2749.         call    put_message
  2750.         pop     esi edx
  2751.         or      dh, 80h
  2752.         push    69
  2753.         pop     eax
  2754.         push    9
  2755.         pop     ebx
  2756.         mov     ecx, [debuggee_pid]
  2757.         int     40h
  2758.         cmp     esi, aUnpacked
  2759.         jnz     OnSuspend
  2760.         jmp     AfterSuspend
  2761. .debug:
  2762.         cmp     [dbgbuflen], 4*3
  2763.         jnz     .notour
  2764.         cmp     dword [dbgbuf], 3
  2765.         jnz     .notour
  2766.         test    byte [dbgbuf+8], 1
  2767.         jnz     .our
  2768. .notour:
  2769.         mov     esi, aInterrupted
  2770.         push    edx
  2771.         call    put_message
  2772.         pop     edx
  2773.         or      dh, 80h
  2774.         push    69
  2775.         pop     eax
  2776.         push    9
  2777.         pop     ebx
  2778.         mov     ecx, [debuggee_pid]
  2779.         int     40h
  2780.         jmp     debugmsg
  2781. .our:
  2782.         and     [dbgbuflen], 0
  2783.         push    edx
  2784.         call    get_context
  2785.         push    eax
  2786.         mov     al, 69
  2787.         mov     bl, 6
  2788.         mov     ecx, [debuggee_pid]
  2789.         mov     edi, esp
  2790.         push    4
  2791.         pop     edx
  2792.         push    0xC
  2793.         pop     esi
  2794.         int     40h
  2795.         pop     eax
  2796.         pop     edx
  2797.         cmp     eax, [_eip]
  2798.         jz      .done
  2799.         call    DoResume
  2800.         jmp     .wait
  2801. .done:
  2802.         mov     esi, aUnpacked
  2803.         jmp     .x1
  2804.  
  2805. disasm_get_byte:
  2806. ; out: al=byte
  2807.         push    ecx
  2808.         mov     ecx, [disasm_cur_pos]
  2809.         sub     ecx, [disasm_start_pos]
  2810.         cmp     ecx, [disasm_buf_size]
  2811.         jae     disasm_err
  2812.         mov     al, [disasm_buffer+ecx]
  2813.         pop     ecx
  2814.         inc     [disasm_cur_pos]
  2815.         ret
  2816. disasm_get_word:
  2817.         push    ecx
  2818.         mov     ecx, [disasm_cur_pos]
  2819.         sub     ecx, [disasm_start_pos]
  2820.         inc     ecx
  2821.         cmp     ecx, [disasm_buf_size]
  2822.         jae     disasm_err
  2823.         mov     ax, word [disasm_buffer-1+ecx]
  2824.         pop     ecx
  2825.         add     [disasm_cur_pos], 2
  2826.         ret
  2827. disasm_get_dword:
  2828.         push    ecx
  2829.         mov     ecx, [disasm_cur_pos]
  2830.         sub     ecx, [disasm_start_pos]
  2831.         add     ecx, 3
  2832.         cmp     ecx, [disasm_buf_size]
  2833.         jae     disasm_err
  2834.         mov     eax, dword [disasm_buffer-3+ecx]
  2835.         pop     ecx
  2836.         add     [disasm_cur_pos], 4
  2837.         ret
  2838.  
  2839. disasm_err:
  2840.         mov     esp, ebp
  2841. stc_ret:
  2842.         stc
  2843.         ret
  2844. disasm_ret:
  2845.         mov     esp, ebp
  2846.         and     byte [edi], 0
  2847.         ret
  2848.  
  2849. disasm_instr:
  2850.         mov     ebp, esp
  2851.         cmp     [debuggee_pid], 0
  2852.         jz      stc_ret
  2853.         mov     edi, disasm_string
  2854.         xor     ecx, ecx
  2855. ; ecx=flags
  2856. disasm_loop1:
  2857.         xor     eax, eax
  2858.         call    disasm_get_byte
  2859.         jmp     dword [disasm_table_1 + eax*4]
  2860.  
  2861. cop0:
  2862. clock:
  2863. crepnz:
  2864. crep:
  2865. csegcs:
  2866. csegds:
  2867. cseges:
  2868. csegss:
  2869. csegfs:
  2870. cseggs:
  2871.         call    @f
  2872.         db      0x2E,3,'cs:'
  2873.         db      0x36,3,'ss:'
  2874.         db      0x3E,3,'ds:'
  2875.         db      0x26,3,'es:'
  2876.         db      0x64,3,'fs:'
  2877.         db      0x65,3,'gs:'
  2878.         db      0x06,10,'push    es'
  2879.         db      0x07,10,'pop     es'
  2880.         db      0x0E,10,'push    cs'
  2881.         db      0x16,10,'push    ss'
  2882.         db      0x17,10,'pop     ss'
  2883.         db      0x1E,10,'push    ds'
  2884.         db      0x1F,10,'pop     ds'
  2885.         db      0x27,3,'daa'
  2886.         db      0x2F,3,'das'
  2887.         db      0x37,3,'aaa'
  2888.         db      0x3F,3,'aas'
  2889.         db      0x60,6,0,'pusha'
  2890.         db      0x61,5,0,'popa'
  2891.         db      0x90,3,'nop'
  2892.         db      0x9B,5,'fwait'
  2893.         db      0x9C,6,0,'pushf'
  2894.         db      0x9D,5,0,'popf'
  2895.         db      0x9E,4,'sahf'
  2896.         db      0x9F,4,'lahf'
  2897.         db      0xA4,5,'movsb'
  2898.         db      0xA5,5,0,'movs'
  2899.         db      0xA6,5,'cmpsb'
  2900.         db      0xA7,5,0,'cmps'
  2901.         db      0xAA,5,'stosb'
  2902.         db      0xAB,5,0,'stos'
  2903.         db      0xAC,5,'lodsb'
  2904.         db      0xAD,5,0,'lods'
  2905.         db      0xAE,5,'scasb'
  2906.         db      0xAF,5,0,'scas'
  2907.         db      0xC3,3,'ret'
  2908.         db      0xC9,5,'leave'
  2909.         db      0xCC,4,'int3'
  2910.         db      0xF0,4,'lock'
  2911.         db      0xF2,5,'repnz'
  2912.         db      0xF3,6,'rep(z)'
  2913.         db      0xF5,3,'cmc'
  2914.         db      0xF8,3,'clc'
  2915.         db      0xF9,3,'stc'
  2916.         db      0xFA,3,'cli'
  2917.         db      0xFB,3,'sti'
  2918.         db      0xFC,3,'cld'
  2919.         db      0xFD,3,'std'
  2920. csysenter:
  2921. csyscall:
  2922. ccpuid:
  2923. crdtsc:
  2924.         call    @f
  2925.         db      0x05,7,'syscall'
  2926.         db      0x31,5,'rdtsc'
  2927.         db      0x34,8,'sysenter'
  2928.         db      0xA2,5,'cpuid'
  2929. @@:
  2930.         pop     esi
  2931. @@:
  2932.         cmp     al, [esi]
  2933.         jz      .found
  2934.         inc     esi
  2935.         movzx   edx, byte [esi]
  2936.         inc     esi
  2937.         add     esi, edx
  2938.         jmp     @b
  2939. .found:
  2940.         inc     esi
  2941.         lodsb
  2942.         cmp     byte [esi], 0
  2943.         jz      @f
  2944.         movzx   ecx, al
  2945. disasm_1:
  2946.         rep     movsb
  2947.         and     byte [edi], 0
  2948.         ret
  2949. @@:
  2950.         mov     dl, ch
  2951.         movzx   ecx, al
  2952.         dec     ecx
  2953.         inc     esi
  2954.         rep     movsb
  2955.         test    dl, 1
  2956.         mov     al, 'w'
  2957.         jnz     @f
  2958.         mov     al, 'd'
  2959. @@:     stosb
  2960.         and     byte [edi], 0
  2961.         ret
  2962.  
  2963. c67:
  2964.         or      ch, 2
  2965.         jmp     disasm_loop1
  2966. c66:
  2967.         or      ch, 1
  2968.         jmp     disasm_loop1
  2969.  
  2970. center:
  2971. caam:
  2972. cxlat:
  2973. ccmpxchg:
  2974. cbsf:
  2975. cbsr:
  2976. ccmpxchg8b:
  2977. cunk:
  2978. cerr:
  2979.         mov     eax, '???'
  2980.         stosd
  2981.         clc
  2982.         ret
  2983.  
  2984. cF:
  2985.         call    disasm_get_byte
  2986.         jmp     dword [disasm_table_2 + eax*4]
  2987.  
  2988. macro disasm_set_modew
  2989. {
  2990.         test    al, 1
  2991.         jz      @f
  2992.         or      ch, 80h
  2993. @@:
  2994. }
  2995.  
  2996. cmov2:
  2997.         disasm_set_modew
  2998. ; mov r/m,i
  2999.         call    disasm_get_byte
  3000.         dec     [disasm_cur_pos]
  3001.         test    al, 00111000b
  3002.         jnz     cunk
  3003.         mov     eax, 'mov '
  3004.         stosd
  3005.         mov     eax, '    '
  3006.         stosd
  3007.         call    disasm_readrmop
  3008.         mov     ax, ', '
  3009.         stosw
  3010.         xor     eax, eax
  3011.         test    ch, 80h
  3012.         jnz     .1
  3013.         call    disasm_get_byte
  3014.         jmp     .3
  3015. .1:
  3016.         test    ch, 1
  3017.         jnz     .2
  3018.         call    disasm_get_dword
  3019.         jmp     .3
  3020. .2:
  3021.         call    disasm_get_word
  3022. .3:
  3023.         call    disasm_write_num
  3024.         and     byte [edi], 0
  3025.         ret
  3026.  
  3027. cret2:
  3028.         mov     eax, 'ret '
  3029.         stosd
  3030.         mov     eax, '    '
  3031.         stosd
  3032.         xor     eax, eax
  3033.         jmp     cmov2.2
  3034.  
  3035. disasm_write_num:
  3036.         push    ecx eax
  3037.         inc     edi
  3038. @@:
  3039.         mov     ecx, eax
  3040.         shr     eax, 4
  3041.         jz      @f
  3042.         inc     edi
  3043.         jmp     @b
  3044. @@:
  3045.         pop     eax
  3046.         cmp     ecx, 10
  3047.         jb      @f
  3048.         inc     edi
  3049. @@:
  3050.         push    edi eax
  3051. @@:
  3052.         mov     ecx, eax
  3053.         and     al, 0xF
  3054.         cmp     al, 10
  3055.         sbb     al, 69h
  3056.         das
  3057.         dec     edi
  3058.         mov     [edi], al
  3059.         mov     eax, ecx
  3060.         shr     eax, 4
  3061.         jnz     @b
  3062.         cmp     ecx, 10
  3063.         jb      @f
  3064.         mov     byte [edi-1], '0'
  3065. @@:
  3066.         pop     eax edi ecx
  3067.         cmp     eax, 10
  3068.         jb      @f
  3069.         mov     byte [edi], 'h'
  3070.         inc     edi
  3071. @@:
  3072.         ret
  3073.  
  3074. label disasm_regs32 dword
  3075. label disasm_regs dword
  3076.         db      'eax',0
  3077.         db      'ecx',0
  3078.         db      'edx',0
  3079.         db      'ebx',0
  3080.         db      'esp',0
  3081.         db      'ebp',0
  3082.         db      'esi',0
  3083.         db      'edi',0
  3084. disasm_regs16   dw      'ax','cx','dx','bx','sp','bp','si','di'
  3085. disasm_regs8    dw      'al','cl','dl','bl','ah','ch','dh','bh'
  3086. disasm_scale    db      '1248'
  3087. disasm_readrmop:
  3088.         call    disasm_get_byte
  3089.         test    ch, 40h
  3090.         jnz     .skip_size
  3091.         push    eax
  3092.         and     al, 0xC0
  3093.         cmp     al, 0xC0
  3094.         pop     eax
  3095.         jz      .skip_size
  3096.         test    ch, 80h
  3097.         jz      .byte
  3098.         test    ch, 1
  3099.         jnz     .word
  3100.         mov     dword [edi], 'dwor'
  3101.         mov     byte [edi+4], 'd'
  3102.         inc     edi
  3103.         jmp     @f
  3104. .byte:
  3105.         test    ch, 20h
  3106.         jz      .qb
  3107.         mov     byte [edi], 't'
  3108.         inc     edi
  3109. .qb:
  3110.         mov     dword [edi], 'byte'
  3111.         jmp     @f
  3112. .word:
  3113.         test    ch, 20h
  3114.         jz      .qw
  3115.         mov     byte [edi], 'q'
  3116.         inc     edi
  3117. .qw:
  3118.         mov     dword [edi], 'word'
  3119. @@:
  3120.         mov     byte [edi+4], ' '
  3121.         add     edi, 5
  3122. .skip_size:
  3123.         test    ch, 2
  3124.         jnz     disasm_readrmop16
  3125.         push    ecx
  3126.         movzx   ecx, al
  3127.         and     eax, 7
  3128.         shr     ecx, 6
  3129.         jz      .vmod0
  3130.         jp      .vmod3
  3131.         mov     byte [edi], '['
  3132.         inc     edi
  3133.         cmp     al, 4
  3134.         jz      .sib1
  3135.         mov     eax, [disasm_regs+eax*4]
  3136.         stosd
  3137.         dec     edi
  3138.         jmp     @f
  3139. .sib1:
  3140.         call    .parse_sib
  3141. @@:
  3142.         mov     al, '+'
  3143.         stosb
  3144.         dec     ecx
  3145.         jz      .vmod1
  3146.         call    disasm_get_dword
  3147.         jmp     @f
  3148. .vmod1:
  3149.         call    disasm_get_byte
  3150.         movsx   eax, al
  3151. @@:
  3152.         test    eax, eax
  3153.         jns     .2
  3154.         neg     eax
  3155.         mov     byte [edi-1], '-'
  3156. .2:
  3157.         call    disasm_write_num
  3158.         mov     al, ']'
  3159.         stosb
  3160.         pop     ecx
  3161.         ret
  3162. .vmod3:
  3163.         pop     ecx
  3164.         test    ch, 80h
  3165.         jz      .vmod3_byte
  3166.         test    ch, 1
  3167.         jnz     .vmod3_word
  3168.         test    ch, 20h
  3169.         jnz     .vmod3_sti
  3170.         mov     eax, [disasm_regs32+eax*4]
  3171.         stosd
  3172.         dec     edi
  3173.         ret
  3174. .vmod3_byte:
  3175.         mov     ax, [disasm_regs8+eax*2]
  3176. @@:
  3177.         stosw
  3178.         ret
  3179. .vmod3_word:
  3180.         mov     ax, [disasm_regs16+eax*2]
  3181.         jmp     @b
  3182. .vmod3_sti:
  3183.         mov     word [edi], 'st'
  3184.         add     al, '0'
  3185.         mov     byte [edi+2], al
  3186.         add     edi, 3
  3187.         ret
  3188. .vmod0:
  3189.         mov     byte [edi], '['
  3190.         inc     edi
  3191.         cmp     al, 4
  3192.         jz      .sib2
  3193.         cmp     al, 5
  3194.         jz      .ofs32
  3195.         mov     eax, [disasm_regs+eax*4]
  3196.         stosd
  3197.         mov     byte [edi-1], ']'
  3198.         pop     ecx
  3199.         ret
  3200. .ofs32:
  3201.         call    disasm_get_dword
  3202.         jmp     .2
  3203. .sib2:
  3204.         call    .parse_sib
  3205.         mov     al, ']'
  3206.         stosb
  3207.         pop     ecx
  3208.         ret
  3209. .parse_sib:
  3210.         call    disasm_get_byte
  3211.         push    edx
  3212.         mov     dl, al
  3213.         mov     dh, 0
  3214.         and     eax, 7
  3215.         cmp     al, 5
  3216.         jnz     @f
  3217.         jecxz   .sib0
  3218. @@:
  3219.         mov     eax, [disasm_regs+eax*4]
  3220.         stosd
  3221.         dec     edi
  3222.         mov     dh, 1
  3223. .sib0:
  3224.         mov     al, dl
  3225.         shr     eax, 3
  3226.         and     eax, 7
  3227.         cmp     al, 4
  3228.         jz      .sibret
  3229.         test    dh, dh
  3230.         jz      @f
  3231.         mov     byte [edi], '+'
  3232.         inc     edi
  3233. @@:
  3234.         mov     eax, [disasm_regs+eax*4]
  3235.         stosd
  3236.         dec     edi
  3237.         shr     dl, 6
  3238.         jz      @f
  3239.         mov     al, '*'
  3240.         stosb
  3241.         movzx   eax, dl
  3242.         mov     al, [disasm_scale+eax]
  3243.         stosb
  3244. @@:
  3245. .sibret:
  3246.         test    dh, dh
  3247.         jnz     .sibret2
  3248.         call    disasm_get_dword
  3249.         cmp     byte [edi-1], '['
  3250.         jz      @f
  3251.         mov     byte [edi], '+'
  3252.         test    eax, eax
  3253.         jns     .sibns
  3254.         neg     eax
  3255.         mov     byte [edi], '-'
  3256. .sibns:
  3257.         inc     edi
  3258. @@:
  3259.         call    disasm_write_num
  3260. .sibret2:
  3261.         pop     edx
  3262.         ret
  3263.  
  3264. disasm_rm16_1   dd      'bxsi','bxdi','bpsi','bpdi'
  3265. disasm_rm16_2   dw      'si','di','bp','bx'
  3266. disasm_readrmop16:
  3267.         push    ecx
  3268.         movzx   ecx, al
  3269.         and     eax, 7
  3270.         shr     ecx, 6
  3271.         jz      .vmod0
  3272.         jp      disasm_readrmop.vmod3   ; mod=3 is the same in 16- and 32-bit code
  3273. ; 1 or 2
  3274.         mov     byte [edi], '['
  3275.         inc     edi
  3276.         cmp     al, 4
  3277.         jae     @f
  3278.         mov     eax, [disasm_rm16_1+eax*4]
  3279.         stosw
  3280.         mov     al, '+'
  3281.         stosb
  3282.         shr     eax, 16
  3283.         jmp     .1
  3284. @@:
  3285.         mov     eax, dword [disasm_rm16_2+eax*2-4*2]
  3286. .1:
  3287.         stosw
  3288.         mov     al, '+'
  3289.         stosb
  3290.         xor     eax, eax
  3291.         dec     ecx
  3292.         jnz     .2
  3293.         call    disasm_get_byte
  3294.         cbw
  3295.         jmp     @f
  3296. .2:
  3297.         call    disasm_get_word
  3298. @@:
  3299.         test    ax, ax
  3300.         jns     @f
  3301.         mov     byte [edi-1], '-'
  3302.         neg     ax
  3303. @@:
  3304.         call    disasm_write_num
  3305. .done1:
  3306.         mov     al, ']'
  3307.         stosb
  3308.         pop     ecx
  3309.         ret
  3310. .vmod0:
  3311.         mov     byte [edi], '['
  3312.         inc     edi
  3313.         cmp     al, 6
  3314.         jz      .ofs16
  3315.         cmp     al, 4
  3316.         jae     @f
  3317.         mov     eax, [disasm_rm16_1+eax*4]
  3318.         stosw
  3319.         mov     al, '+'
  3320.         stosb
  3321.         shr     eax, 16
  3322.         jmp     .3
  3323. @@:
  3324.         mov     eax, dword [disasm_rm16_2+eax*2-4*2]
  3325. .3:
  3326.         stosw
  3327.         jmp     .done1
  3328. .ofs16:
  3329.         xor     eax, eax
  3330.         call    disasm_get_word
  3331.         call    disasm_write_num
  3332.         jmp     .done1
  3333.  
  3334. cpush21:
  3335.         mov     eax, 'push'
  3336.         stosd
  3337.         mov     eax, '    '
  3338.         stosd
  3339. disasm_i32:
  3340.         call    disasm_get_dword
  3341.         call    disasm_write_num
  3342.         and     byte [edi], 0
  3343.         ret
  3344.  
  3345. cpush22:
  3346.         mov     eax, 'push'
  3347.         stosd
  3348.         mov     eax, '    '
  3349.         stosd
  3350.         call    disasm_get_byte
  3351.         movsx   eax, al
  3352.         call    disasm_write_num
  3353.         and     byte [edi], 0
  3354.         ret
  3355.  
  3356. cinc1:
  3357. ; inc reg32
  3358. cdec1:
  3359. ; dec reg32
  3360. cpush1:
  3361. ; push reg32
  3362. cpop1:
  3363. ; pop reg32
  3364. cbswap:
  3365. ; bswap reg32
  3366.         mov     edx, eax
  3367.         and     edx, 7
  3368.         shr     eax, 3
  3369.         sub     al, 8
  3370.         mov     esi, 'inc '
  3371.         jz      @f
  3372.         mov     esi, 'dec '
  3373.         dec     al
  3374.         jz      @f
  3375.         mov     esi, 'push'
  3376.         dec     al
  3377.         jz      @f
  3378.         mov     esi, 'pop '
  3379.         dec     al
  3380.         jz      @f
  3381.         mov     esi, 'bswa'
  3382. @@:
  3383.         xchg    eax, esi
  3384.         stosd
  3385.         mov     eax, '    '
  3386.         jz      @f
  3387.         mov     al, 'p'
  3388. @@:
  3389.         stosd
  3390.         xchg    eax, edx
  3391.         call    disasm_write_reg1632
  3392.         and     byte [edi], 0
  3393.         ret
  3394.  
  3395. cxchg1:
  3396. ; xchg eax,reg32
  3397.         and     eax, 7
  3398.         xchg    eax, edx
  3399.         mov     eax, 'xchg'
  3400.         stosd
  3401.         mov     eax, '    '
  3402.         stosd
  3403.         xor     eax, eax
  3404.         call    disasm_write_reg1632
  3405.         mov     ax, ', '
  3406.         stosw
  3407.         xchg    eax, edx
  3408.         call    disasm_write_reg1632
  3409.         and     byte [edi], 0
  3410.         ret
  3411.  
  3412. cint:
  3413.         mov     eax, 'int '
  3414.         stosd
  3415.         mov     eax, '    '
  3416.         stosd
  3417. disasm_i8u:
  3418.         xor     eax, eax
  3419.         call    disasm_get_byte
  3420.         call    disasm_write_num
  3421.         and     byte [edi], 0
  3422.         ret
  3423.  
  3424. cmov11:
  3425. ; mov r8,i8
  3426.         mov     ecx, eax
  3427.         mov     eax, 'mov '
  3428.         stosd
  3429.         mov     eax, '    '
  3430.         stosd
  3431.         and     ecx, 7
  3432.         mov     ax, [disasm_regs8+ecx*2]
  3433.         stosw
  3434.         mov     ax, ', '
  3435.         stosw
  3436.         jmp     disasm_i8u
  3437.  
  3438. cmov12:
  3439. ; mov r32,i32
  3440.         xchg    eax, edx
  3441.         mov     eax, 'mov '
  3442.         stosd
  3443.         mov     eax, '    '
  3444.         stosd
  3445.         xchg    eax, edx
  3446.         and     eax, 7
  3447.         call    disasm_write_reg1632
  3448.         mov     ax, ', '
  3449.         stosw
  3450.         jmp     cmov2.1
  3451.  
  3452. disasm_shifts   dd      'rol ','ror ','rcl ','rcr ','shl ','shr ','sal ','sar '
  3453. cshift2:
  3454. ; shift r/m,1 = D0/D1
  3455. cshift3:
  3456. ; shift r/m,cl = D2/D3
  3457.         disasm_set_modew
  3458.         mov     dl, al
  3459.         call    disasm_get_byte
  3460.         dec     [disasm_cur_pos]
  3461.         shr     al, 3
  3462.         and     eax, 7
  3463.         mov     eax, [disasm_shifts+eax*4]
  3464.         stosd
  3465.         mov     eax, '    '
  3466.         stosd
  3467.         call    disasm_readrmop
  3468.         cmp     dl, 0xD2
  3469.         jb      .s1
  3470.         mov     eax, ', cl'
  3471.         stosd
  3472.         and     byte [edi], 0
  3473.         ret
  3474. .s1:
  3475.         mov     eax, ', 1'
  3476.         stosd
  3477.         clc
  3478.         ret
  3479.  
  3480. cshift1:
  3481. ; shift r/m,i8 = C0/C1
  3482.         disasm_set_modew
  3483.         call    disasm_get_byte
  3484.         dec     [disasm_cur_pos]
  3485.         shr     al, 3
  3486.         and     eax, 7
  3487.         mov     eax, [disasm_shifts+eax*4]
  3488.         stosd
  3489.         mov     eax, '    '
  3490.         stosd
  3491.         call    disasm_readrmop
  3492.         mov     ax, ', '
  3493.         stosw
  3494.         jmp     disasm_i8u
  3495.  
  3496.  
  3497. cmov3:
  3498. ; A0: mov al,[ofs32]
  3499. ; A1: mov ax/eax,[ofs32]
  3500. ; A2: mov [ofs32],al
  3501. ; A3: mov [ofs32],ax/eax
  3502.         mov     edx, 'mov '
  3503.         xchg    eax, edx
  3504.         stosd
  3505.         mov     eax, '    '
  3506.         stosd
  3507.         test    dl, 2
  3508.         jnz     .1
  3509.         call    .write_acc
  3510.         mov     ax, ', '
  3511.         stosw
  3512.         call    .write_ofs32
  3513.         jmp     .2
  3514. .1:
  3515.         call    .write_ofs32
  3516.         mov     ax, ', '
  3517.         stosw
  3518.         call    .write_acc
  3519. .2:     and     byte [edi], 0
  3520.         ret
  3521. .write_acc:
  3522.         test    dl, 1
  3523.         jz      .8bit
  3524.         test    ch, 1
  3525.         jnz     .16bit
  3526.         mov     eax, 'eax'
  3527.         stosd
  3528.         dec     edi
  3529.         ret
  3530. .16bit:
  3531.         mov     ax, 'ax'
  3532.         stosw
  3533.         ret
  3534. .8bit:
  3535.         mov     ax, 'al'
  3536.         stosw
  3537.         ret
  3538. .write_ofs32:
  3539.         mov     al, '['
  3540.         stosb
  3541.         call    disasm_get_dword
  3542.         call    disasm_write_num
  3543.         mov     al, ']'
  3544.         stosb
  3545.         ret
  3546.  
  3547. disasm_write_reg:
  3548.         test    ch, 80h
  3549.         jnz     disasm_write_reg1632
  3550.         mov     ax, [disasm_regs8+eax*2]
  3551.         stosw
  3552.         ret
  3553. disasm_write_reg1632:
  3554.         test    ch, 1
  3555.         jnz     @f
  3556.         mov     eax, [disasm_regs32+eax*4]
  3557.         stosd
  3558.         dec     edi
  3559.         ret
  3560. @@:
  3561.         mov     ax, [disasm_regs16+eax*2]
  3562.         stosw
  3563.         ret
  3564.  
  3565. cmovzx:         ; 0F B6/B7
  3566. cmovsx:         ; 0F BE/BF
  3567.         mov     edx, eax
  3568.         disasm_set_modew
  3569.         mov     eax, 'movz'
  3570.         cmp     dl, 0xB8
  3571.         jb      @f
  3572.         mov     eax, 'movs'
  3573. @@:
  3574.         stosd
  3575.         mov     eax, 'x   '
  3576.         stosd
  3577.         call    disasm_get_byte
  3578.         dec     [disasm_cur_pos]
  3579.         shr     al, 3
  3580.         and     eax, 7
  3581.         call    disasm_write_reg1632
  3582.         mov     ax, ', '
  3583.         stosw
  3584.         or      ch, 1   ; 2nd operand - 8 or 16 bits
  3585.         call    disasm_readrmop
  3586.         and     byte [edi], 0
  3587.         ret
  3588.  
  3589. disasm_op2cmds  dd 'add ','or  ','adc ','sbb ','and ','sub ','xor ','cmp '
  3590. cop21:
  3591.         disasm_set_modew
  3592.         mov     esi, 'test'
  3593.         cmp     al, 0A8h
  3594.         jae     @f
  3595.         shr     al, 3
  3596.         and     eax, 7
  3597.         mov     esi, [disasm_op2cmds+eax*4]
  3598. @@:
  3599.         xchg    eax, esi
  3600.         stosd
  3601.         mov     eax, '    '
  3602.         stosd
  3603.         test    ch, 80h
  3604.         jnz     .1632
  3605.         mov     eax, 'al, '
  3606.         stosd
  3607.         jmp     disasm_i8u
  3608. .1632:
  3609.         test    ch, 1
  3610.         jnz     .16
  3611.         mov     eax, 'eax,'
  3612.         stosd
  3613.         mov     al, ' '
  3614.         stosb
  3615.         call    disasm_get_dword
  3616.         jmp     .x
  3617. .16:
  3618.         mov     eax, 'ax, '
  3619.         stosd
  3620.         xor     eax, eax
  3621.         call    disasm_get_word
  3622. .x:
  3623.         call    disasm_write_num
  3624.         and     byte [edi], 0
  3625.         ret
  3626.  
  3627. cop22:
  3628.         disasm_set_modew
  3629.         or      ch, 40h
  3630.         mov     edx, eax
  3631.         mov     esi, 'lea '
  3632.         cmp     al, 8Dh
  3633.         jz      @f
  3634.         mov     esi, 'imul'
  3635.         cmp     al, 0xAF
  3636.         jz      @f
  3637.         mov     esi, 'mov '
  3638.         cmp     al, 88h
  3639.         jae     @f
  3640.         mov     esi, 'xchg'
  3641.         cmp     al, 86h
  3642.         jae     @f
  3643.         mov     esi, 'test'
  3644.         cmp     al, 84h
  3645.         jae     @f
  3646.         shr     al, 3
  3647.         and     eax, 7
  3648.         mov     esi, [disasm_op2cmds+eax*4]
  3649. @@:
  3650.         xchg    eax, esi
  3651.         stosd
  3652.         mov     eax, '    '
  3653.         stosd
  3654.         call    disasm_get_byte
  3655.         dec     [disasm_cur_pos]
  3656.         shr     al, 3
  3657.         and     eax, 7
  3658.         cmp     dl, 0x8D
  3659.         jz      @f
  3660.         cmp     dl, 0x86
  3661.         jz      @f
  3662.         cmp     dl, 0x87
  3663.         jz      @f
  3664.         test    dl, 2
  3665.         jz      .d0
  3666. @@:
  3667.         call    disasm_write_reg
  3668.         mov     ax, ', '
  3669.         stosw
  3670.         call    disasm_readrmop
  3671.         and     byte [edi], 0
  3672.         ret
  3673. .d0:
  3674.         push    eax
  3675.         call    disasm_readrmop
  3676.         mov     ax, ', '
  3677.         stosw
  3678.         pop     eax
  3679.         call    disasm_write_reg
  3680.         and     byte [edi], 0
  3681.         ret
  3682.  
  3683. cop23:
  3684.         disasm_set_modew
  3685.         xchg    eax, edx
  3686.         call    disasm_get_byte
  3687.         dec     [disasm_cur_pos]
  3688.         shr     eax, 3
  3689.         and     eax, 7
  3690.         mov     eax, [disasm_op2cmds+eax*4]
  3691. ctest:
  3692.         stosd
  3693.         mov     eax, '    '
  3694.         stosd
  3695.         call    disasm_readrmop
  3696.         mov     ax, ', '
  3697.         stosw
  3698.         test    ch, 80h
  3699.         jz      .i8
  3700.         cmp     dl, 83h
  3701.         jz      .i8
  3702.         test    ch, 1
  3703.         jnz     .i16
  3704.         call    disasm_get_dword
  3705.         jmp     .ic
  3706. .i8:
  3707.         xor     eax, eax
  3708.         call    disasm_get_byte
  3709.         cmp     dl, 83h
  3710.         jnz     .ic
  3711.         movsx   eax, al
  3712.         jmp     .ic
  3713. .i16:
  3714.         xor     eax, eax
  3715.         call    disasm_get_word
  3716. .ic:
  3717.         call    disasm_write_num
  3718.         and     byte [edi], 0
  3719.         ret
  3720.  
  3721. cbtx1:
  3722. ; btx r/m,i8 = 0F BA
  3723.         or      ch, 80h
  3724.         call    disasm_get_byte
  3725.         dec     [disasm_cur_pos]
  3726.         shr     al, 3
  3727.         and     eax, 7
  3728.         cmp     al, 4
  3729.         jb      cunk
  3730.         mov     eax, [btx1codes+eax*4-4*4]
  3731.         stosd
  3732.         mov     eax, '    '
  3733.         stosd
  3734.         call    disasm_readrmop
  3735.         mov     ax, ', '
  3736.         stosw
  3737.         jmp     disasm_i8u
  3738. btx1codes       dd      'bt  ','bts ','btr ','btc '
  3739. cbtx2:
  3740. ; btx r/m,r = 0F 101xx011 (A3,AB,B3,BB)
  3741.         shr     al, 3
  3742.         and     eax, 3
  3743.         mov     eax, [btx1codes+eax*4]
  3744.         stosd
  3745.         mov     eax, '    '
  3746.         stosd
  3747.         or      ch, 0xC0
  3748.         call    disasm_get_byte
  3749.         dec     [disasm_cur_pos]
  3750.         shr     al, 3
  3751.         and     eax, 7
  3752.         push    eax
  3753.         call    disasm_readrmop
  3754.         mov     ax, ', '
  3755.         stosw
  3756.         pop     eax
  3757.         call    disasm_write_reg1632
  3758.         and     byte [edi], 0
  3759.         ret
  3760.  
  3761. csetcc:
  3762.         and     eax, 0xF
  3763.         mov     ax, [disasm_jcc_codes + eax*2]
  3764.         mov     dword [edi], 'setc'
  3765.         add     edi, 3
  3766.         stosw
  3767.         mov     ax, '  '
  3768.         stosw
  3769.         stosb
  3770.         call    disasm_readrmop
  3771.         and     byte [edi], 0
  3772.         ret
  3773.  
  3774. disasm_jcc_codes dw 'o ','no','b ','ae','z ','nz','be','a ','s ','ns','p ','np','l ','ge','le','g '
  3775. cjcc1:
  3776. cjmp2:
  3777.         cmp     al, 0xEB
  3778.         jz      .1
  3779.         and     eax, 0xF
  3780.         mov     ax, [disasm_jcc_codes + eax*2]
  3781.         jmp     .2
  3782. .1:
  3783.         mov     ax, 'mp'
  3784. .2:
  3785.         mov     byte [edi], 'j'
  3786.         inc     edi
  3787.         stosw
  3788.         mov     eax, '    '
  3789.         stosb
  3790.         stosd
  3791.         call    disasm_get_byte
  3792.         movsx   eax, al
  3793. disasm_rva:
  3794.         add     eax, [disasm_cur_pos]
  3795.         call    disasm_write_num
  3796.         and     byte [edi], 0
  3797.         ret
  3798.  
  3799. ccall1:
  3800. cjmp1:
  3801. cjcc2:
  3802.         mov     edx, 'call'
  3803.         cmp     al, 0xE8
  3804.         jz      @f
  3805.         mov     edx, 'jmp '
  3806.         cmp     al, 0xE9
  3807.         jz      @f
  3808.         mov     edx, '    '
  3809.         and     eax, 0xF
  3810.         mov     dx, [disasm_jcc_codes+eax*2]
  3811.         shl     edx, 8
  3812.         mov     dl, 'j'
  3813. @@:
  3814.         xchg    eax, edx
  3815.         stosd
  3816.         mov     eax, '    '
  3817.         stosd
  3818.         call    disasm_get_dword
  3819.         jmp     disasm_rva
  3820.  
  3821. op11codes       dd      'test',0,'not ','neg ','mul ','imul','div ','idiv'
  3822. op12codes       dd      'inc ','dec ','call',0,'jmp ',0,'push',0
  3823. cop1:
  3824.         disasm_set_modew
  3825.         xchg    eax, edx
  3826.         call    disasm_get_byte
  3827.         dec     [disasm_cur_pos]
  3828.         shr     al, 3
  3829.         and     eax, 7
  3830.         cmp     dl, 0xFE
  3831.         jnz     @f
  3832.         cmp     al, 1
  3833.         ja      cunk
  3834. @@:
  3835.         and     edx, 8
  3836.         add     eax, edx
  3837.         mov     eax, [op11codes+eax*4]
  3838.         test    eax, eax
  3839.         jz      cunk
  3840.         cmp     eax, 'test'
  3841.         jz      ctest
  3842. @@:
  3843.         stosd
  3844.         mov     eax, '    '
  3845.         stosd
  3846.         call    disasm_readrmop
  3847.         and     byte [edi], 0
  3848.         ret
  3849.  
  3850. cpop2:
  3851.         or      ch, 80h
  3852.         call    disasm_get_byte
  3853.         dec     [disasm_cur_pos]
  3854.         test    al, 00111000b
  3855.         jnz     cunk
  3856.         mov     eax, 'pop '
  3857.         jmp     @b
  3858.  
  3859. cloopnz:
  3860.         mov     eax, 'loop'
  3861.         stosd
  3862.         mov     eax, 'nz  '
  3863.         test    ch, 2
  3864.         jz      @f
  3865.         mov     ah, 'w'
  3866. @@:     jmp     cloop.cmn
  3867. cloopz:
  3868.         mov     eax, 'loop'
  3869.         stosd
  3870.         mov     eax, 'z   '
  3871.         test    ch, 2
  3872.         jz      @f
  3873.         mov     eax, 'zw  '
  3874. @@:     jmp     cloop.cmn
  3875.  
  3876. cjcxz:
  3877. cloop:
  3878.         cmp     al, 0xE2
  3879.         jz      .loop
  3880.         test    ch, 2
  3881.         jnz     .jcxz
  3882.         mov     eax, 'jecx'
  3883.         stosd
  3884.         mov     eax, 'z   '
  3885.         jmp     .cmn
  3886. .jcxz:
  3887.         mov     eax, 'jcxz'
  3888.         stosd
  3889.         mov     eax, '    '
  3890.         jmp     .cmn
  3891. .loop:
  3892.         mov     eax, 'loop'
  3893.         stosd
  3894.         mov     eax, '    '
  3895.         test    ch, 2
  3896.         jz      .cmn
  3897.         mov     al, 'w'
  3898. .cmn:
  3899.         stosd
  3900.         call    disasm_get_byte
  3901.         movsx   eax, al
  3902.         add     eax, [disasm_cur_pos]
  3903.         test    ch, 1
  3904.         jz      @f
  3905.         and     eax, 0xFFFF
  3906. @@:
  3907. disasm_write_num_done:
  3908.         call    disasm_write_num
  3909.         and     byte [edi], 0
  3910.         ret
  3911.  
  3912. cimul1:
  3913. ; imul r,r/m,i
  3914.         or      ch, 80h         ; 32bit operation
  3915.         xchg    eax, edx
  3916.         mov     eax, 'imul'
  3917.         stosd
  3918.         mov     eax, '    '
  3919.         stosd
  3920.         call    disasm_get_byte
  3921.         dec     [disasm_cur_pos]
  3922.         shr     al, 3
  3923.         and     eax, 7
  3924.         call    disasm_write_reg1632
  3925.         mov     ax, ', '
  3926.         stosw
  3927.         call    disasm_readrmop
  3928.         mov     ax, ', '
  3929.         stosw
  3930.         test    ch, 1
  3931.         jnz     .16
  3932.         cmp     dl, 0x69
  3933.         jz      .op32
  3934.         call    disasm_get_byte
  3935.         movsx   eax, al
  3936.         jmp     disasm_write_num_done
  3937. .op32:
  3938.         call    disasm_get_dword
  3939.         jmp     disasm_write_num_done
  3940. .16:
  3941.         cmp     dl, 0x69
  3942.         jz      .op16
  3943.         call    disasm_get_byte
  3944.         cbw
  3945.         jmp     disasm_write_num_done
  3946. .op16:
  3947.         xor     eax, eax
  3948.         call    disasm_get_word
  3949.         jmp     disasm_write_num_done
  3950.  
  3951. cshld:
  3952. cshrd:
  3953.         mov     edx, 'shld'
  3954.         test    al, 8
  3955.         jz      @f
  3956.         mov     edx, 'shrd'
  3957. @@:
  3958.         xchg    eax, edx
  3959.         stosd
  3960.         mov     eax, '    '
  3961.         stosd
  3962.         call    disasm_get_byte
  3963.         dec     [disasm_cur_pos]
  3964.         shr     al, 3
  3965.         and     eax, 7
  3966.         push    eax
  3967.         or      ch, 80h
  3968.         call    disasm_readrmop
  3969.         mov     ax, ', '
  3970.         stosw
  3971.         pop     eax
  3972.         call    disasm_write_reg1632
  3973.         mov     ax, ', '
  3974.         stosw
  3975.         test    dl, 1
  3976.         jz      disasm_i8u
  3977.         mov     ax, 'cl'
  3978.         stosw
  3979.         and     byte [edi], 0
  3980.         ret
  3981.  
  3982. ccbw:
  3983.         mov     eax, 'cbw '
  3984.         test    ch, 1
  3985.         jnz     @f
  3986.         mov     eax, 'cwde'
  3987. @@:     stosd
  3988.         and     byte [edi+1], 0
  3989.         ret
  3990. ccwd:
  3991.         mov     eax, 'cwd '
  3992.         test    ch, 1
  3993.         jnz     @b
  3994.         mov     eax, 'cdq '
  3995.         jmp     @b
  3996.  
  3997. fpuD8   dd      'add ','mul ','com ','comp','sub ','subr','div ','divr'
  3998.  
  3999. cD8:
  4000.         call    disasm_get_byte
  4001.         dec     [disasm_cur_pos]
  4002.         push    eax
  4003.         shr     al, 3
  4004.         and     eax, 7
  4005.         mov     byte [edi], 'f'
  4006.         inc     edi
  4007.         xchg    eax, edx
  4008.         mov     eax, [fpuD8+edx*4]
  4009.         stosd
  4010.         mov     ax, '  '
  4011.         stosw
  4012.         stosb
  4013.         pop     eax
  4014.         cmp     dl, 2
  4015.         jb      .1
  4016.         cmp     dl, 3
  4017.         jbe     .2
  4018. .1:
  4019.         cmp     al, 0xC0
  4020.         jb      .2
  4021.         mov     eax, 'st0,'
  4022.         stosd
  4023.         mov     al, ' '
  4024.         stosb
  4025. .2:
  4026.         or      ch, 80h or 20h
  4027.         and     ch, not 1
  4028.         call    disasm_readrmop
  4029.         and     byte [edi], 0
  4030.         ret
  4031.  
  4032. fpuD9_2:
  4033.         dq      'fchs    ','fabs    ',0,0,'ftst    ','fxam    ',0,0
  4034.         db      'fld1    fldl2t  fldl2e  fldpi   fldlg2  fldln2  fldz    '
  4035.         dq      0
  4036.         db      'f2xm1   fyl2x   fptan   fpatan  fxtract fprem1  fdecstp fincstp '
  4037.         db      'fprem   fyl2xp1 fsqrt   fsincos frndint fscale  fsin    fcos    '
  4038. fpuD9_fnop      db      'fnop    '
  4039. cD9:
  4040.         call    disasm_get_byte
  4041.         sub     al, 0xC0
  4042.         jae     .l1
  4043.         dec     [disasm_cur_pos]
  4044.         shr     al, 3
  4045.         and     eax, 7
  4046.         cmp     al, 7
  4047.         jnz     @f
  4048.         mov     eax, 'fnst'
  4049.         stosd
  4050.         mov     eax, 'cw  '
  4051.         jmp     .x1
  4052. @@:
  4053.         cmp     al, 5
  4054.         jnz     @f
  4055.         mov     eax, 'fldc'
  4056.         stosd
  4057.         mov     eax, 'w   '
  4058. .x1:
  4059.         stosd
  4060.         or      ch, 0C1h
  4061.         jmp     .cmn
  4062. @@:
  4063.         mov     edx, 'fld '
  4064.         test    al, al
  4065.         jz      @f
  4066.         mov     edx, 'fst '
  4067.         cmp     al, 2
  4068.         jz      @f
  4069.         mov     edx, 'fstp'
  4070.         cmp     al, 3
  4071.         jnz     cunk
  4072. @@:
  4073.         xchg    eax, edx
  4074.         stosd
  4075.         mov     eax, '    '
  4076.         stosd
  4077.         or      ch, 80h
  4078.         and     ch, not 1
  4079. .cmn:
  4080.         call    disasm_readrmop
  4081.         and     byte [edi], 0
  4082.         ret
  4083. .l1:
  4084.         cmp     al, 10h
  4085.         jae     .l2
  4086.         mov     edx, 'fld '
  4087.         cmp     al, 8
  4088.         jb      @f
  4089.         mov     edx, 'fxch'
  4090. @@:
  4091.         xchg    eax, edx
  4092.         stosd
  4093.         mov     eax, '    '
  4094.         stosd
  4095.         xchg    eax, edx
  4096.         and     al, 7
  4097.         add     al, '0'
  4098.         shl     eax, 16
  4099.         mov     ax, 'st'
  4100.         stosd
  4101.         clc
  4102.         ret
  4103. .l2:
  4104.         cmp     al, 0x10
  4105.         jnz     @f
  4106.         mov     esi, fpuD9_fnop
  4107.         jmp     .l3
  4108. @@:
  4109.         sub     al, 0x20
  4110.         jb      cerr
  4111.         lea     esi, [fpuD9_2+eax*8]
  4112.         cmp     byte [esi], 0
  4113.         jz      cerr
  4114. .l3:
  4115.         movsd
  4116.         movsd
  4117.         and     byte [edi-1], 0
  4118.         ret
  4119.  
  4120. cDA:
  4121.         call    disasm_get_byte
  4122.         cmp     al, 0xC0
  4123.         jae     cunk
  4124.         dec     [disasm_cur_pos]
  4125.         shr     al, 3
  4126.         and     eax, 7
  4127.         mov     word [edi], 'fi'
  4128.         inc     edi
  4129.         inc     edi
  4130.         mov     eax, [fpuD8+eax*4]
  4131.         stosd
  4132.         mov     ax, '  '
  4133.         stosw
  4134.         or      ch, 80h
  4135.         and     ch, not 1       ; 32-bit operand
  4136.         call    disasm_readrmop
  4137.         and     byte [edi], 0
  4138.         ret
  4139.  
  4140. fpuDB   dd      'ild ',0,'ist ','istp',0,'ld  ',0,'stp '
  4141. cDB:
  4142.         call    disasm_get_byte
  4143.         cmp     al, 0xC0
  4144.         jae     .1
  4145.         dec     [disasm_cur_pos]
  4146.         shr     al, 3
  4147.         and     eax, 7
  4148.         xchg    eax, edx
  4149.         mov     eax, [fpuDB+edx*4]
  4150.         test    eax, eax
  4151.         jz      cerr
  4152.         mov     byte [edi], 'f'
  4153.         inc     edi
  4154.         stosd
  4155.         mov     ax, '  '
  4156.         stosw
  4157.         stosb
  4158.         or      ch, 80h
  4159.         and     ch, not 1       ; 32-bit operand
  4160.         cmp     dl, 4
  4161.         jb      @f
  4162.         or      ch, 20h
  4163.         and     ch, not 80h     ; 80-bit operand
  4164. @@:
  4165.         call    disasm_readrmop
  4166.         and     byte [edi], 0
  4167.         ret
  4168. .1:
  4169.         cmp     al, 0xE3
  4170.         jnz     cunk
  4171.         mov     eax, 'fnin'
  4172.         stosd
  4173.         mov     eax, 'it'
  4174.         stosd
  4175.         dec     edi
  4176.         ret             ; CF cleared
  4177.  
  4178. fpuDC   dd      'add ','mul ',0,0,'subr','sub ','divr','div '
  4179. cDC:
  4180.         call    disasm_get_byte
  4181.         cmp     al, 0xC0
  4182.         jae     .1
  4183.         dec     [disasm_cur_pos]
  4184.         shr     al, 3
  4185.         and     eax, 7
  4186.         mov     byte [edi], 'f'
  4187.         inc     edi
  4188.         mov     eax, [fpuD8+eax*4]
  4189.         stosd
  4190.         mov     ax, '  '
  4191.         stosw
  4192.         stosb
  4193.         or      ch, 0A1h        ; qword
  4194.         call    disasm_readrmop
  4195.         and     byte [edi], 0
  4196.         ret
  4197. .1:
  4198.         mov     dl, al
  4199.         shr     al, 3
  4200.         and     eax, 7
  4201.         mov     eax, [fpuDC+eax*4]
  4202.         test    eax, eax
  4203.         jz      cerr
  4204.         mov     byte [edi], 'f'
  4205.         inc     edi
  4206.         stosd
  4207.         mov     eax, '   s'
  4208.         stosd
  4209.         mov     al, 't'
  4210.         stosb
  4211.         and     edx, 7
  4212.         lea     eax, [edx+'0']
  4213.         stosb
  4214.         mov     eax, ', st'
  4215.         stosd
  4216.         mov     ax, '0'
  4217.         stosw
  4218.         ret     ; CF cleared
  4219.  
  4220. fpuDD   dd      'fld ',0,'fst ','fstp',0,0,0,0
  4221. fpuDD_2 dq      'ffree   ',0,'fst     ','fstp    ','fucom   ','fucomp  ',0,0
  4222. cDD:
  4223.         call    disasm_get_byte
  4224.         cmp     al, 0xC0
  4225.         jae     .1
  4226.         dec     [disasm_cur_pos]
  4227.         shr     al, 3
  4228.         and     eax, 7
  4229.         xchg    eax, edx
  4230.         mov     eax, [fpuDD+edx*4]
  4231.         test    eax, eax
  4232.         jz      cunk
  4233.         stosd
  4234.         mov     eax, '    '
  4235.         stosd
  4236.         or      ch, 0A1h        ; qword operand
  4237.         call    disasm_readrmop
  4238.         and     byte [edi], 0
  4239.         ret
  4240. .1:
  4241.         push    eax
  4242.         shr     al, 3
  4243.         and     eax, 7
  4244.         xchg    eax, edx
  4245.         mov     eax, dword [fpuDD_2+edx*8]
  4246.         test    eax, eax
  4247.         jz      cerr
  4248.         stosd
  4249.         mov     eax, dword [fpuDD_2+4+edx*8]
  4250.         stosd
  4251.         mov     ax, 'st'
  4252.         stosw
  4253.         pop     eax
  4254.         and     al, 7
  4255.         add     al, '0'
  4256.         stosb
  4257.         and     byte [edi], 0
  4258.         ret
  4259.  
  4260. fpuDE   dd      'add ','mul ',0,0,'subr','sub ','divr','div '
  4261. cDE:
  4262.         call    disasm_get_byte
  4263.         cmp     al, 0xC0
  4264.         jae     .1
  4265.         dec     [disasm_cur_pos]
  4266.         mov     word [edi], 'fi'
  4267.         inc     edi
  4268.         inc     edi
  4269.         shr     al, 3
  4270.         and     eax, 7
  4271.         mov     eax, [fpuD8+eax*4]
  4272.         stosd
  4273.         mov     ax, '  '
  4274.         stosw
  4275.         or      ch, 81h         ; force 16-bit
  4276.         call    disasm_readrmop
  4277.         and     byte [edi], 0
  4278.         ret
  4279. .1:
  4280.         push    eax
  4281.         shr     al, 3
  4282.         and     eax, 7
  4283.         xchg    eax, edx
  4284.         mov     eax, [fpuDE+edx*4]
  4285.         test    eax, eax
  4286.         jz      .fcompp
  4287.         mov     byte [edi], 'f'
  4288.         inc     edi
  4289.         stosd
  4290.         mov     al, 'p'
  4291.         cmp     byte [edi-1], ' '
  4292.         jnz     @f
  4293.         mov     byte [edi-1], al
  4294.         mov     al, ' '
  4295. @@:     stosb
  4296.         mov     eax, '  st'
  4297.         stosd
  4298.         pop     eax
  4299.         and     al, 7
  4300.         add     al, '0'
  4301.         stosb
  4302.         mov     ax, ', '
  4303.         stosw
  4304.         mov     eax, 'st0'
  4305.         stosd
  4306.         ret     ; CF cleared
  4307. .fcompp:
  4308.         pop     eax
  4309.         cmp     al, 0xD9
  4310.         jnz     cerr
  4311.         mov     eax, 'fcom'
  4312.         stosd
  4313.         mov     ax, 'pp'
  4314.         stosw
  4315.         and     byte [edi], 0
  4316.         ret
  4317.  
  4318. fpuDF   dd      'ild ',0,'ist ','istp','bld ','ild ','bstp','istp'
  4319.  
  4320. cDF:
  4321.         call    disasm_get_byte
  4322.         cmp     al, 0xC0
  4323.         jae     .1
  4324.         dec     [disasm_cur_pos]
  4325.         shr     al, 3
  4326.         and     eax, 7
  4327.         xchg    eax, edx
  4328.         mov     eax, [fpuDF+edx*4]
  4329.         test    eax, eax
  4330.         jz      cerr
  4331.         mov     byte [edi], 'f'
  4332.         inc     edi
  4333.         stosd
  4334.         mov     ax, '  '
  4335.         stosw
  4336.         stosb
  4337.         or      ch, 81h         ; force 16-bit operand
  4338.         cmp     dl, 4
  4339.         jb      @f
  4340.         or      ch, 20h
  4341.         test    dl, 1
  4342.         jnz     @f
  4343.         or      ch, 40h
  4344. @@:
  4345.         call    disasm_readrmop
  4346.         and     byte [edi], 0
  4347.         ret
  4348. .1:
  4349.         cmp     al, 0xE0
  4350.         jnz     cunk
  4351.         mov     eax, 'fnst'
  4352.         stosd
  4353.         mov     eax, 'sw  '
  4354.         stosd
  4355.         mov     ax, 'ax'
  4356.         stosw
  4357.         and     byte [edi], 0
  4358.         ret
  4359.  
  4360. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4361. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4362. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4363.  
  4364. caption_str db 'Kolibri Debugger',0
  4365. caption_len = $ - caption_str
  4366. begin_str db    'Kolibri Debugger, version 0.2',10
  4367.         db      'Hint: type "help" for help, "quit" for quit'
  4368. newline db      10,0
  4369. prompt  db      '> ',0
  4370.  
  4371. help_groups:
  4372.         dd      aControl, 0, 0, help_control_msg
  4373.         db      0
  4374.         dd      aData, 0, 0, help_data_msg
  4375.         db      0
  4376.         dd      aBreakpoints, 0, 0, help_breaks_msg
  4377.         db      0
  4378. ; flags field:
  4379. ; &1: command may be called without parameters
  4380. ; &2: command may be called with parameters
  4381. ; &4: command may be called without loaded program
  4382. ; &8: command may be called with loaded program
  4383. commands:
  4384.         dd      _aH, OnHelp, HelpSyntax, HelpHelp
  4385.         db      0Fh
  4386.         dd      aHelp, OnHelp, HelpSyntax, HelpHelp
  4387.         db      0Fh
  4388.         dd      aQuit, OnQuit, QuitSyntax, QuitHelp
  4389.         db      0Dh
  4390.         dd      aLoad, OnLoad, LoadSyntax, LoadHelp
  4391.         db      6
  4392.         dd      aReload, OnReload, ReloadSyntax, ReloadHelp
  4393.         db      0Dh
  4394.         dd      aTerminate, OnTerminate, TerminateSyntax, TerminateHelp
  4395.         db      9
  4396.         dd      aDetach, OnDetach, DetachSyntax, DetachHelp
  4397.         db      9
  4398.         dd      aSuspend, OnSuspend, SuspendSyntax, SuspendHelp
  4399.         db      9
  4400.         dd      aResume, OnResume, ResumeSyntax, ResumeHelp
  4401.         db      0Bh
  4402.         dd      aStep, OnStep, StepSyntax, StepHelp
  4403.         db      9
  4404.         dd      aProceed, OnProceed, ProceedSyntax, ProceedHelp
  4405.         db      9
  4406.         dd      aCalc, OnCalc, CalcSyntax, CalcHelp
  4407.         db      0Eh
  4408.         dd      aDump, OnDump, DumpSyntax, DumpHelp
  4409.         db      0Bh
  4410.         dd      aUnassemble, OnUnassemble, UnassembleSyntax, UnassembleHelp
  4411.         db      0Bh
  4412.         dd      aBp, OnBp, BpSyntax, BpHelp
  4413.         db      0Ah
  4414.         dd      aBpm, OnBpmb, BpmSyntax, BpmHelp
  4415.         db      0Ah
  4416.         dd      aBpmb, OnBpmb, BpmSyntax, BpmHelp
  4417.         db      0Ah
  4418.         dd      aBpmw, OnBpmw, BpmSyntax, BpmHelp
  4419.         db      0Ah
  4420.         dd      aBpmd, OnBpmd, BpmSyntax, BpmHelp
  4421.         db      0Ah
  4422.         dd      aBl, OnBl, BlSyntax, BlHelp
  4423.         db      0Bh
  4424.         dd      aBc, OnBc, BcSyntax, BcHelp
  4425.         db      0Ah
  4426.         dd      aBd, OnBd, BdSyntax, BdHelp
  4427.         db      0Ah
  4428.         dd      aBe, OnBe, BeSyntax, BeHelp
  4429.         db      0Ah
  4430.         dd      aReg, OnReg, RSyntax, RHelp
  4431.         db      0Ah
  4432.         dd      aUnpack, OnUnpack, UnpackSyntax, UnpackHelp
  4433.         db      9
  4434.         dd      0
  4435. aHelp   db      5,'help',0
  4436. _aH     db      2,'h',0
  4437. HelpHelp db     'Help on specified function',10
  4438. HelpSyntax db   'Usage: h or help [group | command]',10,0
  4439.  
  4440. help_msg db     'List of known command groups:',10
  4441.         db      '"help control"     - display list of control commands',10
  4442.         db      '"help data"        - display list of commands concerning data',10
  4443.         db      '"help breakpoints" - display list of commands concerning breakpoints',10,0
  4444. aControl db     8,'control',0
  4445. help_control_msg db     'List of control commands:',10
  4446.         db      'h = help             - help',10
  4447.         db      'quit                 - exit from debugger',10
  4448.         db      'load <name> [params] - load program for debugging',10
  4449.         db      'reload               - reload debugging program',10
  4450.         db      'terminate            - terminate loaded program',10
  4451.         db      'detach               - detach from debugging program',10
  4452.         db      'stop                 - suspend execution of debugging program',10
  4453.         db      'g [<expression>]     - go on (resume execution of debugging program)',10
  4454.         db      's = <Ctrl+F7>        - program step',10
  4455.         db      'p = <Ctrl+F8>        - program wide step',10
  4456.         db      'unpack               - try to bypass unpacker code (heuristic)',10,0
  4457. aData   db      5,'data',0
  4458. help_data_msg db        'List of data commands:',10
  4459.         db      '? <expression>       - calculate value of expression',10
  4460.         db      'd [<expression>]     - dump data at given address',10
  4461.         db      'u [<expression>]     - unassemble instructions at given address',10
  4462.         db      'r <register> <expression> or',10
  4463.         db      'r <register>=<expression> - set register value',10,0
  4464. aBreakpoints db 12,'breakpoints',0
  4465. help_breaks_msg db      'List of breakpoints commands:',10
  4466.         db      'bp <expression>      - set breakpoint on execution',10
  4467.         db      'bpm[b|w|d] <type> <expression> - set breakpoint on memory access',10
  4468.         db      'bl [<number>]        - breakpoint(s) info',10
  4469.         db      'bc <number>...       - clear breakpoint',10
  4470.         db      'bd <number>...       - disable breakpoint',10
  4471.         db      'be <number>...       - enable breakpoint',10,0
  4472.  
  4473. aQuit   db      5,'quit',0
  4474. QuitHelp db     'Quit from debugger',10
  4475. QuitSyntax db   'Usage: quit',10,0
  4476.  
  4477. aLoad   db      5,'load',0
  4478. LoadHelp db     'Load program for debugging',10
  4479. LoadSyntax db   'Usage: load <program-name> [parameters]',10,0
  4480.  
  4481. aReload db      7,'reload',0
  4482. ReloadHelp db   'Reload debugging program (restart debug session)',10
  4483. ReloadSyntax db 'Usage: reload',10,0
  4484.  
  4485. aTerminate db   10,'terminate',0
  4486. TerminateHelp db 'Terminate debugged program',10
  4487. TerminateSyntax db 'Usage: terminate',10,0
  4488.  
  4489. aDetach db      7,'detach',0
  4490. DetachHelp db   'Detach from debugged program',10
  4491. DetachSyntax db 'Usage: detach',10,0
  4492.  
  4493. aSuspend db     5,'stop',0
  4494. SuspendHelp db  'Suspend execution of debugged program',10
  4495. SuspendSyntax db 'Usage: stop',10,0
  4496.  
  4497. aResume db      2,'g',0
  4498. ResumeHelp db   'Go (resume execution of debugged program)',10
  4499. ResumeSyntax db 'Usage: g',10
  4500.         db      '   or: g <expression> - wait until specified address is reached',10,0
  4501.  
  4502. aStep   db      2,'s',0
  4503. StepHelp db     'Make step in debugged program',10
  4504. StepSyntax db   'Usage: s',10,0
  4505.  
  4506. aProceed db     2,'p',0
  4507. ProceedHelp db  'Make wide step in debugged program (step over CALL, REPxx, LOOP)',10
  4508. ProceedSyntax db 'Usage: p',10,0
  4509.  
  4510. aDump   db      2,'d',0
  4511. DumpHelp db     'Dump data of debugged program',10
  4512. DumpSyntax db   'Usage: d <expression> - dump data at specified address',10
  4513.         db      '   or: d              - continue current dump',10,0
  4514.  
  4515. aCalc   db      2,'?',0
  4516. CalcHelp db     'Calculate value of expression',10
  4517. CalcSyntax db   'Usage: ? <expression>',10,0
  4518.  
  4519. aUnassemble db  2,'u',0
  4520. UnassembleHelp db 'Unassemble',10
  4521. UnassembleSyntax:
  4522.         db      'Usage: u <expression> - unassemble instructions at specified address',10
  4523.         db      '   or: u              - continue current unassemble screen',10,0
  4524.  
  4525. aReg    db      2,'r',0
  4526. RHelp   db      'Set register value',10
  4527. RSyntax:
  4528.         db      'Usage: r <register> <expression>',10
  4529.         db      '   or: r <register>=<expression> - set value of <register> to <expression>',10,0
  4530.  
  4531. aBp     db      3,'bp',0
  4532. BpHelp  db      'set BreakPoint on execution',10
  4533. BpSyntax db     'Usage: bp <expression>',10,0
  4534.  
  4535. aBpm    db      4,'bpm',0
  4536. aBpmb   db      5,'bpmb',0
  4537. aBpmw   db      5,'bpmw',0
  4538. aBpmd   db      5,'bpmd',0
  4539. BpmHelp db      'set BreakPoint on Memory access',10
  4540.         db      'Maximum 4 breakpoints of this type are allowed',10
  4541.         db      'Note that for this breaks debugger is activated after access',10
  4542. BpmSyntax db    'Usage: bpmb [w] <expression>',10
  4543.         db      '       bpmw [w] <expression>',10
  4544.         db      '       bpmd [w] <expression>',10
  4545.         db      '       bpm is synonym for bpmd',10
  4546.         db      '"w" means break only on writes (default is on read/write)',10,0
  4547.  
  4548. aBl     db      3,'bl',0
  4549. BlHelp  db      'Breakpoint List',10
  4550. BlSyntax db     'Usage: bl          - list all breakpoints',10
  4551.         db      '       bl <number> - display info on particular breakpoint',10,0
  4552.  
  4553. aBc     db      3,'bc',0
  4554. BcHelp  db      'Breakpoint Clear',10
  4555. BcSyntax db     'Usage: bc <number-list>',10
  4556.         db      'Examples: bc 2',10
  4557.         db      '          bc 1 3 4 A',10,0
  4558.  
  4559. aBd     db      3,'bd',0
  4560. BdHelp  db      'Breakpoint Disable',10
  4561. BdSyntax db     'Usage: bd <number-list>',10
  4562.         db      'Examples: bd 2',10
  4563.         db      '          bd 1 3 4 A',10,0
  4564.  
  4565. aBe     db      3,'be',0
  4566. BeHelp  db      'Breakpoint Enable',10
  4567. BeSyntax db     'Usage: be <number-list>',10
  4568.         db      'Examples: be 2',10
  4569.         db      '          be 1 3 4 A',10,0
  4570.  
  4571. aUnpack db      7,'unpack',0
  4572. UnpackHelp db   'Try to bypass unpacker code',10
  4573. UnpackSyntax db 'Usage: unpack',10,0
  4574.  
  4575. aUnknownCommand db 'Unknown command',10,0
  4576.  
  4577. load_err_msg    db      'Cannot load program. ',0
  4578. unk_err_msg     db      'Unknown error code -%4X',10,0
  4579. load_err_msgs:
  4580.         dd      .1, 0, .3, 0, .5, .6, 0, 0, .9, .A, 0, 0, 0, 0, 0, 0
  4581.         dd      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, .1E, .1F, .20
  4582. .1              db      'HD undefined.',10,0
  4583. .3              db      'Unknown FS.',10,0
  4584. .5              db      'File not found.',10,0
  4585. .6              db      'Unexpected EOF.',10,0
  4586. .9              db      'FAT table corrupted.',10,0
  4587. .A              db      'Access denied.',10,0
  4588. .1E             db      'No memory.',10,0
  4589. .1F             db      'Not Menuet/Kolibri executable.',10,0
  4590. .20             db      'Too many processes.',10,0
  4591. load_succ_msg   db      'Program loaded successfully! PID=%4X. Use "g" to run.',10,0
  4592. need_debuggee   db      'No program loaded. Use "load" command.',10,0
  4593. aAlreadyLoaded  db      'Program is already loaded. Use "terminate" or "detach" commands',10,0
  4594. terminated_msg  db      'Program terminated.',10,0
  4595. aException      db      'Debugged program caused an exception %2X. '
  4596. aSuspended      db      'Suspended',10,0
  4597. aContinued      db      'Continuing',10,0
  4598. aRunningErr     db      'Program is running',10,0
  4599. read_mem_err    db      'ERROR: cannot read process memory!!!',10,0
  4600. aBreakpointLimitExceeded db 'Breakpoint limit exceeded',10,0
  4601. aBreakErr       db      'Cannot activate breakpoint, it will be disabled',10,0
  4602. aDuplicateBreakpoint db 'Duplicate breakpoint',10,0
  4603. aInvalidBreak   db      'Invalid breakpoint number',10,0
  4604. OnBeErrMsg      db      'There is already enabled breakpoint on this address',10,0
  4605. aBreakNum       db      '%2X: at %8X',0
  4606. aMemBreak1      db      '%2X: on ',0
  4607. aMemBreak2      db      'read from ',0
  4608. aMemBreak3      db      'access of ',0
  4609. aMemBreak4      db      'byte',0
  4610. aMemBreak5      db      'word',0
  4611. aMemBreak6      db      'dword',0
  4612. aMemBreak7      db      ' at %8X',0
  4613. aOneShot        db      ', one-shot',0
  4614. aDisabled       db      ', disabled',0
  4615. aBreakStop      db      'Breakpoint #%2X',10,0
  4616. aUserBreak      db      'int3 command at %8X',10,0
  4617. ;dbgmsg_str     db      'Debug message for process %4X.',10,0
  4618. aInvAddr        db      'Invalid address',10,0
  4619. NoPrgLoaded_str db      'No program loaded'
  4620. NoPrgLoaded_len = $ - NoPrgLoaded_str
  4621. aRunning        db      'Running'
  4622. aPaused         db      'Paused'
  4623. aPoint          db      0x1C
  4624. aMinus          db      '-'
  4625. aColon          db      ':'
  4626. aQuests         db      '??'
  4627. aDots           db      '...'
  4628. aParseError     db      'Parse error',10,0
  4629. aDivByZero      db      'Division by 0',10,0
  4630. calc_string     db      '%8X',10,0
  4631. aUnaligned      db      'Unaligned address',10,0
  4632. aEnabledBreakErr db     'Enabled breakpoints are not allowed',10,0
  4633. aInterrupted    db      'Interrupted',10,0
  4634. aUnpacked       db      'Unpacked successful!',10,0
  4635. aPacked1        db      'Program is probably packed with ',0
  4636. aPacked2        db      '.',10,'Try to unpack automatically? [y/n]: ',0
  4637. aY_str          db      'y',10,0
  4638. aN_str          db      'n',10,0
  4639. mxp_nrv_name    db      'mxp_nrv',0
  4640. mxp_name        db      'mxp',0
  4641. mxp_lzo_name    db      'mxp_lzo',0
  4642. mtappack_name   db      'mtappack',0
  4643. flags           db      'CPAZSDO'
  4644. flags_bits      db      0,2,4,6,7,10,11
  4645. regs_strs:
  4646.         db      'EAX='
  4647.         db      'EBX='
  4648.         db      'ECX='
  4649.         db      'EDX='
  4650.         db      'ESI='
  4651.         db      'EDI='
  4652.         db      'EBP='
  4653.         db      'ESP='
  4654.         db      'EIP='
  4655.         db      'EFLAGS='
  4656.  
  4657. debuggee_pid    dd      0
  4658. bSuspended      db      0
  4659. bAfterGo        db      0
  4660. temp_break      dd      0
  4661.  
  4662. disasm_table_1:
  4663.         dd      cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cop0           ; 0x
  4664.         dd      cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cF
  4665.         dd      cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cop0           ; 1x
  4666.         dd      cop22, cop22, cop22, cop22, cop21, cop21, cop0,  cop0
  4667.         dd      cop22, cop22, cop22, cop22, cop21, cop21, cseges,cop0           ; 2x
  4668.         dd      cop22, cop22, cop22, cop22, cop21, cop21, csegcs,cop0
  4669.         dd      cop22, cop22, cop22, cop22, cop21, cop21, csegss,cop0           ; 3x
  4670.         dd      cop22, cop22, cop22, cop22, cop21, cop21, csegds,cop0
  4671.         dd      cinc1, cinc1, cinc1, cinc1, cinc1, cinc1, cinc1, cinc1          ; 4x
  4672.         dd      cdec1, cdec1, cdec1, cdec1, cdec1, cdec1, cdec1, cdec1
  4673.         dd      cpush1,cpush1,cpush1,cpush1,cpush1,cpush1,cpush1,cpush1         ; 5x
  4674.         dd      cpop1, cpop1, cpop1, cpop1, cpop1, cpop1, cpop1, cpop1
  4675.         dd      cop0,  cop0,  cunk,  cunk,  csegfs,cseggs,c66,   c67            ; 6x
  4676.         dd      cpush21,cimul1,cpush22,cimul1,cunk,cunk,  cunk,  cunk
  4677.         dd      cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1          ; 7x
  4678.         dd      cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1
  4679.         dd      cop23, cop23, cop23, cop23, cop22, cop22, cop22, cop22          ; 8x
  4680.         dd      cop22, cop22, cop22, cop22, cunk,  cop22, cunk,  cpop2
  4681.         dd      cop0,  cxchg1,cxchg1,cxchg1,cxchg1,cxchg1,cxchg1,cxchg1         ; 9x
  4682.         dd      ccbw,  ccwd,  cunk,  cop0,  cop0,  cop0,  cop0,  cop0
  4683.         dd      cmov3, cmov3, cmov3, cmov3, cop0,  cop0,  cop0,  cop0           ; Ax
  4684.         dd      cop21, cop21, cop0,  cop0,  cop0,  cop0,  cop0,  cop0
  4685.         dd      cmov11,cmov11,cmov11,cmov11,cmov11,cmov11,cmov11,cmov11         ; Bx
  4686.         dd      cmov12,cmov12,cmov12,cmov12,cmov12,cmov12,cmov12,cmov12
  4687.         dd      cshift1,cshift1,cret2,cop0, cunk,  cunk,  cmov2, cmov2          ; Cx
  4688.         dd      center,cop0,  cunk,  cunk,  cop0,  cint,  cunk,  cunk
  4689.         dd      cshift2,cshift2,cshift3,cshift3,caam,cunk,cunk,  cxlat          ; Dx
  4690.         dd      cD8,   cD9,   cDA,   cDB,   cDC,   cDD,   cDE,   cDF
  4691.         dd      cloopnz,cloopz,cloop,cjcxz, cunk,  cunk,  cunk,  cunk           ; Ex
  4692.         dd      ccall1,cjmp1, cunk,  cjmp2, cunk,  cunk,  cunk,  cunk
  4693.         dd      clock, cunk,  crepnz,crep,  cunk,  cop0,  cop1,  cop1           ; Fx
  4694.         dd      cop0,  cop0,  cop0,  cop0,  cop0,  cop0,  cop1,  cop1
  4695.  
  4696. disasm_table_2:
  4697.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  csyscall,cunk,cunk           ; 0x
  4698.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  4699.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk           ; 1x
  4700.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  4701.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk           ; 2x
  4702.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  4703.         dd      cunk,  crdtsc,cunk,  cunk,  csysenter,cunk,cunk, cunk           ; 3x
  4704.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  4705.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk           ; 4x
  4706.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  4707.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk           ; 5x
  4708.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  4709.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk           ; 6x
  4710.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  4711.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk           ; 7x
  4712.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  4713.         dd      cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2          ; 8x
  4714.         dd      cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2
  4715.         dd      csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc         ; 9x
  4716.         dd      csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc
  4717.         dd      cunk,  cunk,  ccpuid,cbtx2, cshld, cshld, cunk,  cunk           ; Ax
  4718.         dd      cunk,  cunk,  cunk,  cbtx2, cshrd, cshrd, cunk,  cop22
  4719.         dd      ccmpxchg,ccmpxchg,cunk,cbtx2,cunk, cunk,  cmovzx,cmovzx         ; Bx
  4720.         dd      cunk,  cunk,  cbtx1, cbtx2, cbsf,  cbsr,  cmovsx,cmovsx
  4721.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  ccmpxchg8b     ; Cx
  4722.         dd      cbswap,cbswap,cbswap,cbswap,cbswap,cbswap,cbswap,cbswap
  4723.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk           ; Dx
  4724.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  4725.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk           ; Ex
  4726.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  4727.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk           ; Fx
  4728.         dd      cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk,  cunk
  4729.  
  4730. reg_table:
  4731.         db      2,'al',0
  4732.         db      2,'cl',1
  4733.         db      2,'dl',2
  4734.         db      2,'bl',3
  4735.         db      2,'ah',4
  4736.         db      2,'ch',5
  4737.         db      2,'dh',6
  4738.         db      2,'bh',7
  4739.         db      2,'ax',8
  4740.         db      2,'cx',9
  4741.         db      2,'dx',10
  4742.         db      2,'bx',11
  4743.         db      2,'sp',12
  4744.         db      2,'bp',13
  4745.         db      2,'si',14
  4746.         db      2,'di',15
  4747.         db      3,'eax',16
  4748.         db      3,'ecx',17
  4749.         db      3,'edx',18
  4750.         db      3,'ebx',19
  4751.         db      3,'esp',20
  4752.         db      3,'ebp',21
  4753.         db      3,'esi',22
  4754.         db      3,'edi',23
  4755.         db      3,'eip',24
  4756.         db      0
  4757.  
  4758. fn70_load_block:
  4759.         dd      7
  4760.         dd      1
  4761. load_params dd  0
  4762.         dd      0
  4763.         dd      0
  4764. i_end:
  4765. loadname:
  4766.         db      0
  4767.         rb      255
  4768.  
  4769. prgname_ptr dd ?
  4770. prgname_len dd ?
  4771.  
  4772. dbgwnd          dd      ?
  4773.  
  4774. messages        rb      messages_height*messages_width
  4775. messages_pos    dd      ?
  4776.  
  4777. cmdline         rb      cmdline_width+1
  4778. cmdline_len     dd      ?
  4779. cmdline_pos     dd      ?
  4780. curarg          dd      ?
  4781.  
  4782. was_temp_break  db      ?
  4783.  
  4784. dbgbufsize      dd      ?
  4785. dbgbuflen       dd      ?
  4786. dbgbuf          rb      256
  4787.  
  4788. needzerostart:
  4789.  
  4790. context:
  4791. _eip    dd      ?
  4792. _eflags dd      ?
  4793. _eax    dd      ?
  4794. _ecx    dd      ?
  4795. _edx    dd      ?
  4796. _ebx    dd      ?
  4797. _esp    dd      ?
  4798. _ebp    dd      ?
  4799. _esi    dd      ?
  4800. _edi    dd      ?
  4801.  
  4802. oldcontext rb $-context
  4803.  
  4804. dumpread dd     ?
  4805. dumppos dd      ?
  4806. dumpdata rb     dump_height*10h
  4807.  
  4808. ; breakpoint structure:
  4809. ; dword +0: address
  4810. ; byte +4: flags
  4811. ; bit 0: 1 <=> breakpoint valid
  4812. ; bit 1: 1 <=> breakpoint disabled
  4813. ; bit 2: 1 <=> one-shot breakpoint
  4814. ; bit 3: 1 <=> DRx breakpoint
  4815. ; byte +5: overwritten byte
  4816. ;          for DRx breaks: flags + (index shl 6)
  4817. breakpoints_n = 256
  4818. breakpoints     rb      breakpoints_n*6
  4819. drx_break       rd      4
  4820.  
  4821. disasm_buf_size         dd      ?
  4822.  
  4823. bReload                 db      ?
  4824.  
  4825. needzeroend:
  4826.  
  4827. disasm_buffer           rb      256
  4828. disasm_start_pos        dd      ?
  4829. disasm_cur_pos          dd      ?
  4830. disasm_cur_str          dd      ?
  4831. disasm_string           rb      256
  4832.  
  4833. i_param         rb      256
  4834.  
  4835. ; stack
  4836.         align   400h
  4837.         rb      400h
  4838. used_mem:
  4839.