Subversion Repositories Kolibri OS

Rev

Rev 1926 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ; TinyPy module
  2. ; Name: kolibri_dbg
  3. ;
  4. ; Exports:
  5. ;           debug_print(msg) - prints a message to debug board.
  6.  
  7. format ELF
  8. use32
  9. include 'proc32.inc'
  10. include 'struct.inc'
  11. include 'tinypy.inc'
  12.  
  13. extrn tp_dict
  14. extrn tp_set
  15. extrn tp_get
  16. extrn tp_None
  17. extrn tp_fnc
  18.  
  19. public kolibri_dbg_init
  20.  
  21. ; Module name
  22. modname        db "kolibri_dbg"
  23. modnamelen = $-modname
  24.  
  25. ; Exported function name
  26. debug_print_name db "debug_print"
  27. debug_print_namelen = $-debug_print_name
  28. ; Export dictionary for module
  29. kolibri_dbg_dict    rb sizeof.tp_obj
  30. ; tp_obj of exported function
  31. debug_print_obj rb sizeof.tp_obj
  32.  
  33. ; Function debug_print(tp_vm *tp)
  34. ; return nothing
  35. debug_print:
  36.      push ebp
  37.      mov  ebp, esp
  38.      ; Store registers
  39.      push eax
  40.      push ebx
  41.      push ecx
  42.      push edx
  43.      sub  esp, sizeof.tp_obj; Reserve tp_obj tmp
  44.      mov  edx, esp
  45.      push edx           ;Store &tmp
  46.      ; Obtain tp_string parameter
  47.      ; tp_get(&tmp, tp, *(tp_obj *)(tp_vm->params), tp_None)
  48.      push_tp_none
  49.      mov  eax, dword[ebp+12] ;4 for return address, 4 for result pointer; 4 for tp_vm
  50.      add  eax, tp_vm.params
  51.      push_tp_obj_at_reg eax
  52.      push dword[ebp+12]
  53.      push edx   ;ebx contains address of reserved tp_obj variable
  54.      call tp_get
  55.  
  56.      ;Restore stack
  57.      add  esp, sizeof.tp_obj*2+4;2 tp_obj's and 2 pointers in parameters minus 1 pointer to result (cleared inside tp_get)
  58.  
  59.      ;Leave if parameter is not a string. tp_raise() should be called here.
  60.      pop  edx; edx = &tmp
  61.      cmp  dword[edx], TP_STRING ; Check that function returned a TP_STRING
  62.      jne  .exit
  63.      mov  ecx, dword[edx+tp_string_.len]    ; String length
  64.      mov  edx, dword[edx+tp_string_.val]     ;
  65.      mov  eax, 63
  66.      mov  ebx, 1
  67. .cont:
  68.       ; Print message.
  69.      push ecx   ; Store ecx to use it in inner loop
  70.      mov  cl, byte[edx]
  71.      inc  edx
  72.      int  40h
  73.      pop  ecx   ; Get ecx back
  74.      loop .cont
  75. .exit:
  76.      add  esp, sizeof.tp_obj ; Release tp_obj reserved in stack.
  77.      ; Returning tp_None
  78.      mov  eax, dword[ebp+8]
  79.      mov  dword[eax], 0
  80.      ; Restore registers
  81.      pop  edx
  82.      pop  ecx
  83.      pop  ebx
  84.      pop  eax
  85.      mov  esp, ebp
  86.      pop  ebp
  87.      ret
  88.  
  89. ;void kolibri_dbg_init(tp_vm *tp);
  90. kolibri_dbg_init:
  91.      push ebp
  92.      mov ebp, esp
  93.      ;Save registers
  94.      push eax
  95.      push ebx
  96.      push ecx
  97.      ; Create module dictionary and store its address in kolibri_dbg_str
  98.      mov eax, dword [ebp + 8]
  99.      push eax
  100.      push kolibri_dbg_dict
  101.      call tp_dict
  102.      add  esp, 4        ;Clear stack
  103.      ; Push tp_obj structure pointed by kolibri_dbg_dict
  104.      push_tp_obj kolibri_dbg_dict
  105.      ; Push modname as a tp_obj object
  106.      push modnamelen; len
  107.      push modname   ; val
  108.      push 0         ;_tp_string info
  109.      push TP_STRING ; type
  110.      ; Push tp_obj structure pointed by tp->modules
  111.      mov eax, dword [ebp + 8]
  112.      add eax, tp_vm.modules + 16
  113.      mov ecx, 4
  114. .push_tpobj1:
  115.      sub  eax, 4
  116.      push dword[eax]
  117. loop .push_tpobj1
  118.      push eax
  119.      call tp_set
  120.      add  esp, sizeof.tp_obj*3+4
  121.      ; Register "debug_print" function
  122.      ;Reserve memory for function tp_obj object
  123.      sub  esp, sizeof.tp_obj
  124.      mov  eax, esp
  125.      push debug_print
  126.      push dword[ebp+8]
  127.      push eax
  128.      call tp_fnc
  129.      add  esp, 8; tp_obj is already in stack, adding other arguments
  130.      ;Pushing function name tp_obj
  131.      ;mov eax, esp
  132.      ;push_tp_obj_at_reg eax
  133.      push debug_print_namelen
  134.      push debug_print_name
  135.      push 0
  136.      push TP_STRING
  137.      ;Pushing module dictionary tp_obj
  138.      push_tp_obj kolibri_dbg_dict
  139.      ;Pushing tp_vm
  140.      push dword[ebp+8]
  141.      call tp_set
  142.      add  esp, sizeof.tp_obj*3+4
  143.      ; Leaving function
  144.      pop ecx
  145.      pop ebx
  146.      pop eax
  147.      mov esp, ebp
  148.      pop ebp
  149.      ret
  150.