Page 1 of 3

Emulador

Posted: Sun May 26, 2013 8:13 pm
by angel
Hola!

Llevo tiempo con la idea de hacer un emular de kolibrios :D , ¿hay algún lugar donde explique que es cada byte code? :evil:

Un saludo y muchas gracias :wink:

Ángel

Re: Emulador

Posted: Sun May 26, 2013 8:16 pm
by SoUrcerer
Sorry, what bytecode?

Re: Emulador

Posted: Sun May 26, 2013 8:31 pm
by angel
SoUrcerer wrote:Sorry, what bytecode?
Son los bytes que componen el programa ejecutable :wink:

Que representa cada uno de estos bytecodes es indispensable para poder hacer un emulador :twisted:

Re: Emulador

Posted: Sun May 26, 2013 10:06 pm
by Kopa
Sorry from russian to spanish translation (from translate.google.com) :roll:

Байт код не используется в колибри
Código de byte no se utiliza en colibrí Byte Code

QEMU?

P.S.
Cсылка, которую можно использовать, чтобы войти на форум. Используем Google Translate, чтобы иметь возможность видеть все разделы и темы (русский и английский), переведенные на испанский язык.
les dejo un enlace que pueden utilizar para entrar al foro mediante Google Translate, de esa forma van a poder ver todas las secciones y temas (en ruso y en inglés) traducidos al español.

Re: Emulador

Posted: Sun May 26, 2013 10:25 pm
by stefano
Hol Ángel,
no entiendo bien qué es lo que quieres hacer.
Si tienes tiempo, explica más desarrollado qué es lo que quieres hacer.

Gracias.
Saludos desde Uruguay.

Re: Emulador

Posted: Sun May 26, 2013 11:00 pm
by angel
esevece wrote:Hol Ángel,
no entiendo bien qué es lo que quieres hacer.
Si tienes tiempo, explica más desarrollado qué es lo que quieres hacer.

Gracias.
Saludos desde Uruguay.
Quiero hacer algo parecido a KlbrInWin o al MeOSEmul

Algunos de los byteCodes son estos
El DWORD después da 'MENUET01' es el número de versión de cabecera, debería ser 1.
El DWORD después de que es el puntero para iniciar de código, como se ha explicado antes.
El siguiente DWORD es el tamaño de todo el archivo, en bytes.
El DWORD después de que el tamaño es el programa tomará en la memoria (esto debería ser al menos tan grande como el DWORD anterior, si no más grande)
Esta información la he sacado de otro hilo, concretamene de aquí viewtopic.php?f=23&t=1362

Pero me gustaría saber el resto :roll:

Re: Emulador

Posted: Sun May 26, 2013 11:38 pm
by stefano
Sigo sin entender qué es lo que querés hacer. ¿Querés hacer un KlbrInWin?

Con respecto a lo segundo que mencionaste, aquí se explica qué es cada parte del código de un programa en Kolibri http://wiki.kolibrios.org/wiki/Development (tenés para elegir el lenguaje).
Lamentablemente está sólo en inglés.

Re: Emulador

Posted: Sun May 26, 2013 11:45 pm
by angel
esevece wrote:Sigo sin entender qué es lo que querés hacer. ¿Querés hacer un KlbrInWin?
Exactamente... Pero en un lenguaje de alto nivel, C, Pascal :twisted: pero necesito saber con exactitud que hace cada byteCode...

Re: Emulador

Posted: Mon May 27, 2013 12:26 am
by stefano
Bien. Desconozco a qué te refieres con Bytecode. Pero en el enlace que te pasé se explica que hace cada parte de un programa para Kolibri. Hay ejemplos en C también (creo que no tan explicados como ensamblador).

Ahora estuve leyendo sobre Bytecode... por lo que entendí, lo utilizan los lenguajes tipo Python o Java que son lenguajes interpretados que no corren nativamente. Así que con los programas de Kolibri vas muerto :)

Re: Emulador

Posted: Mon May 27, 2013 2:36 pm
by angel
esevece wrote:Bien. Desconozco a qué te refieres con Bytecode. Pero en el enlace que te pasé se explica que hace cada parte de un programa para Kolibri. Hay ejemplos en C también (creo que no tan explicados como ensamblador).

Ahora estuve leyendo sobre Bytecode... por lo que entendí, lo utilizan los lenguajes tipo Python o Java que son lenguajes interpretados que no corren nativamente. Así que con los programas de Kolibri vas muerto :)
He copiado el siguiente ejemplo:

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                  ;
;      EXAMPLE APPLICATION                         ;
;                                                  ;
;      Compile with FASM                           ;
;                                                  ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
; The header
 
use32                                   ; Tell compiler to use 32 bit instructions
 
org 0x0                                 ; the base address of code, always 0x0
 
db 'MENUET01'
dd 0x01
dd START
dd I_END
dd 0x100000
dd 0x7fff0
dd 0, 0
 
; The code area
 
include 'macros.inc'
 
START:                                  ; start of execution
        call    draw_window             ; draw the window
 
; After the window is drawn, it's practical to have the main loop.
; Events are distributed from here.
 
event_wait:
        mov     eax, 10                 ; function 10 : wait until event
        mcall                           ; event type is returned in eax
 
        cmp     eax, 1                  ; Event redraw request ?
        je      red                     ; Expl.: there has been activity on screen and
                                        ; parts of the applications has to be redrawn.
 
        cmp     eax, 2                  ; Event key in buffer ?
        je      key                     ; Expl.: User has pressed a key while the
                                        ; app is at the top of the window stack.
 
        cmp     eax, 3                  ; Event button in buffer ?
        je      button                  ; Expl.: User has pressed one of the
                                        ; applications buttons.
 
        jmp     event_wait
 
;  The next section reads the event and processes data.
 
red:                                    ; Redraw event handler
        call    draw_window             ; We call the window_draw function and
        jmp     event_wait              ; jump back to event_wait
 
key:                                    ; Keypress event handler
        mov     eax, 2                  ; The key is returned in ah. The key must be
        mcall                           ; read and cleared from the system queue.
        jmp     event_wait              ; Just read the key, ignore it and jump to event_wait.
 
button:                                 ; Buttonpress event handler
        mov     eax,17                  ; The button number defined in window_draw
        mcall                           ; is returned to ah.
 
        cmp     ah,1                    ; button id=1 ?
        jne     noclose
        mov     eax,-1                  ; Function -1 : close this program
        mcall
 
noclose:
        jmp     event_wait              ; This is for ignored events, useful at development
 
;  *********************************************
;  ******  WINDOW DEFINITIONS AND DRAW  ********
;  *********************************************
;
;  The static window parts are drawn in this function. The window canvas can
;  be accessed later from any parts of this code (thread) for displaying
;  processes or recorded data, for example.
;
;  The static parts *must* be placed within the fn 12 , ebx = 1 and ebx = 2.
 
draw_window:
        mov     eax, 12                 ; function 12: tell os about windowdraw
        mov     ebx, 1                  ; 1, start of draw
        mcall
 
        mov     eax, 0                  ; function 0 : define and draw window
        mov     ebx, 100 * 65536 + 300  ; [x start] *65536 + [x size]
        mov     ecx, 100 * 65536 + 120  ; [y start] *65536 + [y size]
        mov     edx, 0x14ffffff         ; color of work area RRGGBB
                                        ; 0x02000000 = window type 4 (fixed size, skinned window)
        mov     esi, 0x808899ff         ; color of grab bar  RRGGBB
                                        ; 0x80000000 = color glide
        mov     edi, title
        mcall
 
        mov     ebx, 25 * 65536 + 35    ; draw info text with function 4
        mov     ecx, 0x224466
        mov     edx, text
        mov     esi, 40
        mov     eax, 4
 
  .newline:                             ; text from the DATA AREA
        mcall
        add     ebx, 10
        add     edx, 40
        cmp     byte[edx], 0
        jne     .newline
 
        mov     eax, 12                 ; function 12:tell os about windowdraw
        mov     ebx, 2                  ; 2, end of draw
        mcall
 
        ret
 
;  *********************************************
;  *************   DATA AREA   *****************
;  *********************************************
;
; Data can be freely mixed with code to any parts of the image.
; Only the header information is required at the beginning of the image.
 
text    db  "It look's like you have just compiled   "
        db  "your first program for KolibriOS.       "
        db  "                                        "
        db  "Congratulations!                        ", 0
 
title   db  "Example application", 0
 
I_END:
 
; The area after I_END is free for use as the application memory, 
; just avoid the stack.
;
; Application memory structure, according to the used header, 1 Mb.
;
; 0x00000   - Start of compiled image
; I_END     - End of compiled image           
;
;           + Free for use in the application
;
; 0x7ff00   - Start of stack area
; 0x7fff0   - End of stack area                 - defined in the header
;
;           + Free for use in the application
;
; 0xFFFFF   - End of freely useable memory      - defined in the header
;
; All of the the areas can be modified within the application with a
; direct reference.
; For example, mov [0x80000],byte 1 moves a byte above the stack area.
de aquí http://wiki.kolibrios.org/wiki/Writing_ ... le_example

Que da como resultado esto, es decir un archivo tipo BIN que al ejecutarlo dentro de Kolibrios crea la siguiente ventana

Image

Si coges un editor hexadecimal y abres el BIN veras esto:
4D454E554554303101000000240000006301000000001000F0FF07000000000000000000E8350000006A0A58CD4083F801740C83F802740E83F8037410EBEAE81A000000
EBE36A0258CD40EBDC6A1158CD4080FC01750583C8FFCD40EBCB6A0C5831DB43CD4031C0BB2C016400B978006400BAFFFFFF14BEFF998880BF4F010000CD40BB
23001900B966442200BAAE0000006A285E6A0458CD4083C30A83C228803A0075F36A0C586A025BCD40C34974206C6F6F6B2773206C696B6520796F752068617665206A
75737420636F6D70696C6564202020796F75722066697273742070726F6772616D20666F72204B6F6C696272694F532E202020202020202020202020202020202020202020
2020202020202020202020202020202020202020202020202020436F6E67726174756C6174696F6E73212020202020202020202020202020202020202020202020200045786
16D706C65206170706C69636174696F6E00
Los primeros byteCodes son:

4D - M
45 - E
4E - N
55 - U
45 - E
54 - T
30 - 0
31 - 1

Es decir MENUET01, indicando al sistema que es un archivo ejecutable... ¿Lo entiendes ahora? Lo que quiero saber es que son el resto de byteCodes... ¿Hay alguna guía que lo explique?

Re: Emulador

Posted: Mon May 27, 2013 3:26 pm
by SoUrcerer
db 'MENUET01' ; "magic word"
dd 0x01 ; header version
dd START ; address of START of code
dd I_END ; addres of END of code
dd 0x100000 ; memory reserved, wait, 1MEGABYTE for this example? WUT?!
dd 0x7fff0 ; pointer to stack. Wait, why it's center of memory? o_O
dd 0, 0 ; pointers to argv[0] and argv[1]

Other code is 32bit machine code for x86. You can read it with Intel Reference Manual, or using disassemblers. Or in MTDBG in Kolibri.

Re: Emulador

Posted: Mon May 27, 2013 3:28 pm
by SoUrcerer

Re: Emulador

Posted: Tue May 28, 2013 10:18 am
by angel
SoUrcerer wrote:http://wiki.kolibrios.org/wiki/Writing_ ... The_header
I hope you already read this. :)
Esto es muy interesante, aunque lo que hace es abrirme mas dudas :oops: :oops: :roll:

Revisemos el análisis del ejemplo

4D - M - 8bits (1 byte) \
45 - E - 8bits (1 byte) |
4E - N - 8bits (1 byte) |
55 - U - 8bits (1 byte) |
45 - E - 8bits (1 byte) > Magic Word
54 - T - 8bits (1 byte) |
30 - 0 - 8bits (1 byte) |
31 - 1 - 8bits (1 byte) /


01 - 8bits (1 byte) \
00 - 8bits (1 byte) |
00 - 8bits (1 byte) > header version - observo que esta almacenada al reves, no debo leer 01000000, debo leer 00000001
00 - 8bits (1 byte) /

24 - 8bits (1 byte) \
00 - 8bits (1 byte) \
00 - 8bits (1 byte) > address of START of code
00 - 8bits (1 byte) /

63 - 8bits (1 byte) \
01 - 8bits (1 byte) |
00 - 8bits (1 byte) > addres of END of code
00 - 8bits (1 byte) /

00 - 8bits (1 byte) \
00 - 8bits (1 byte) |
10 - 8bits (1 byte) > memory reserved
00 - 8bits (1 byte) /

F0 - 8bits (1 byte) \
FF - 8bits (1 byte) |
07 - 8bits (1 byte) > pointer to stack
00 - 8bits (1 byte) /

00 - 8bits (1 byte) \
00 - 8bits (1 byte) |
00 - 8bits (1 byte) > pointers to argv[0]
00 - 8bits (1 byte) /

00 - 8bits (1 byte) \
00 - 8bits (1 byte) |
00 - 8bits (1 byte) > pointers to argv[1]
00 - 8bits (1 byte) /

¿Hasta aquí es correcto?

¿debo seguir leyendo de 4bytes en 4 bytes? ¿Que es E8350000?

Resto del programa pendiente de analizar.... draw_window... llamadas al sistema...

E8350000006A0A58CD4083F801740C83F802740E83F8037410EBEAE81A000000EBE36A0258CD40EBDC6A1158CD4080FC01750583C8FFCD40EBCB6A0C5831DB43CD4031
C0BB2C016400B978006400BAFFFFFF14BEFF998880BF4F010000CD40BB23001900B966442200BAAE0000006A285E6A0458CD4083C30A83C228803A0075F36A0C586A025B
CD40C34974206C6F6F6B2773206C696B6520796F752068617665206A75737420636F6D70696C6564202020796F75722066697273742070726F6772616D20666F72204B6F6C6962
72694F532E2020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020436F6E67726174756C6174696F6E732120202020
2020202020202020202020202020202020202020004578616D706C65206170706C69636174696F6E00

Re: Emulador

Posted: Tue May 28, 2013 11:05 am
by SoUrcerer
Just use disassembler.

Re: Emulador

Posted: Tue May 28, 2013 12:20 pm
by angel
SoUrcerer wrote:Just use disassembler.
Si!!! el MTDBG :D :twisted:
E8 35 00 00 00 call 5Eh
6A 0A push 0Ah
58 pop eax
CD 40 int 40h
83 F8 01 cmp eax,1
74 0C jz 3Fh
83 F8 02 cmp eax,2
74 0E jz 46h
83 F8 03 cmp eax,3
74 10 jz 4Dh
EB EA jmp 24h
E8 1A 00 00 00 call 5Eh
EB E3 jmp 29h
6A 02 push 2
58 pop eax
CD 40 int 40h
¿Que tecla uso para bajar y ver el resto del programa? ¿Como ejecuto el programa paso a paso? ¿Existe algún manual?

Muchas gracias :D