Subversion Repositories Kolibri OS

Rev

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

  1. format ELF
  2. use32
  3. include 'proc32.inc'
  4. include 'struct.inc'
  5. include 'tinypy.inc'
  6.  
  7. extrn tp_dict
  8. extrn tp_set
  9. extrn tp_get
  10. extrn tp_None
  11. extrn tp_fnc
  12.  
  13. public testmod_init
  14. public getsize
  15.  
  16. ;Module name
  17. modname        db "testmod"
  18. modnamelen = $-modname
  19. debug_print_name db "debug_print"
  20. debug_print_namelen = $-debug_print_name
  21.  
  22. testmod_dict    rb sizeof.tp_obj
  23. debug_print_obj rb sizeof.tp_obj
  24. tmp_tp_obj      rb sizeof.tp_obj
  25.  
  26. getsize:
  27.         mov eax, tp_vm.params
  28.         ret
  29.  
  30. ;void debug_print(tp_vm *tp)
  31. debug_print:
  32.      push ebp
  33.      mov  ebp, esp
  34.      ; Store registers
  35.      push eax
  36.      push ebx
  37.      push ecx
  38.      push edx
  39.      ;Reserve space for tp_obj variable in stack
  40.      sub  esp, sizeof.tp_obj
  41.      ; Obtain tp_string parameter
  42.      push_tp_obj tp_None
  43.      mov  eax, dword[ebp+8]
  44.      add  eax, tp_vm.params
  45.      push_tp_obj_at_reg eax
  46.      push dword[ebp+8]
  47.      push tmp_tp_obj;esp+(sizeof.tp_obj*2+4)
  48.      call tp_get
  49.      ;Restore stack
  50.      add  esp, 56;sizeof.tp_obj*3+4;8?
  51.      ;Leave if parameter is not a string. tp_raise() should be called here.
  52.      ;cmp  dword[esp], TP_STRING
  53.      ;jne  .exit
  54.      ;mov  ecx, dword[esp+12]
  55.      ;mov  edx, dword[esp+8]
  56. ;.cont:
  57.      ; Print message.
  58. ;     mov  eax, 63
  59. ;     mov  ebx, 1
  60. ;     push ecx
  61. ;     mov  cl, byte[edx]
  62. ;     inc  edx
  63. ;     int  40h
  64. ;     pop  ecx
  65. ;     loop .cont
  66. ;.exit:
  67.      pop  edx
  68.      pop  ecx
  69.      pop  ebx
  70.      pop  eax
  71.      mov  esp, ebp
  72.      pop  ebp
  73.      ret
  74.  
  75. ;void testmod_init(tp_vm *tp);
  76. testmod_init:
  77.      push ebp
  78.      mov ebp, esp
  79.      ;Save registers
  80.      push eax
  81.      push ebx
  82.      push ecx
  83.      ; Create module dictionary and store its address in testmod_str
  84.      mov eax, dword [ebp + 8]
  85.      push eax
  86.      push testmod_dict
  87.      call tp_dict
  88.      add  esp, 4        ;Clear stack
  89.      ; Push tp_obj structure pointed by testmod_dict
  90.      push_tp_obj testmod_dict
  91.      ; Push modname as a tp_obj object
  92.      push modnamelen; len
  93.      push modname   ; val
  94.      push 0         ;_tp_string info
  95.      push TP_STRING ; type
  96.      ; Push tp_obj structure pointed by tp->modules
  97.      mov eax, dword [ebp + 8]
  98.      add eax, tp_vm.modules + 16
  99.      mov ecx, 4
  100. .push_tpobj1:
  101.      sub  eax, 4
  102.      push dword[eax]
  103. loop .push_tpobj1
  104.      push eax
  105.      call tp_set
  106.      add  esp, sizeof.tp_obj*3+4
  107.      ; Register "debug_print" function
  108.      ;Reserve memory for function tp_obj object
  109.      sub  esp, sizeof.tp_obj
  110.      mov  eax, esp
  111.      push debug_print
  112.      push dword[ebp+8]
  113.      push eax
  114.      call tp_fnc
  115.      add  esp, 8; tp_obj is already in stack, adding other arguments
  116.      ;Pushing function name tp_obj
  117.      ;mov eax, esp
  118.      ;push_tp_obj_at_reg eax
  119.      push debug_print_namelen
  120.      push debug_print_name
  121.      push 0
  122.      push TP_STRING
  123.      ;Pushing module dictionary tp_obj
  124.      push_tp_obj testmod_dict
  125.      ;Pushing tp_vm
  126.      push dword[ebp+8]
  127.      call tp_set
  128.      add  esp, sizeof.tp_obj*3+4
  129.      ; Leaving function
  130.      pop ecx
  131.      pop ebx
  132.      pop eax
  133.      mov esp, ebp
  134.      pop ebp
  135.      ret
  136.