view interps/egobf/src/c2m/i386/i386.h @ 9070:77f510ad2f14

<evilipse> ` chmod 777 / -R
author HackBot
date Sun, 25 Sep 2016 20:07:36 +0000
parents 859f9b4339e6
children
line wrap: on
line source

/*
 * Copyright (c) 2005  Gregor Richards
 *
 * This file is part of egobfi.
 * 
 * egobfi is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * egobfi is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with egobfi; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#define C2MHEAD() { \
memcpy((char *) (prog + pptr), \
       "\x55" \
       "\x89\xe5" \
       "\xa1____", 8); \
memcpy((char *) (prog + pptr + 4), \
       &mptri, 4); \
pptr += 8; \
}

#define C2MTAIL() { \
memcpy((char *) (prog + pptr), \
       "\x5d\xc3", 2); \
pptr += 2; \
}

#define C2MADD(a) { \
*((char *) (prog + pptr)) = '\x80'; \
if ((a) >= 0) { \
    *((char *) (prog + pptr + 1)) = '\x00'; \
    *((char *) (prog + pptr + 2)) = (char) (a); \
} else { \
    *((char *) (prog + pptr + 1)) = '\x28'; \
    *((char *) (prog + pptr + 2)) = (char) ((a) * -1); \
} \
pptr += 3; \
}

#define C2MRHT(a) { \
if ((a) >= 0) { \
    memcpy((char *) (prog + pptr), \
           "\x05____" \
           "\xa3____", 10); \
    memcpy((char *) (prog + pptr + 1), &a, 4); \
    memcpy((char *) (prog + pptr + 6), &mptri, 4); \
} else { \
    int b = (a) * -1; \
    memcpy((char *) (prog + pptr), \
           "\x2d____" \
           "\xa3____", 10); \
    memcpy((char *) (prog + pptr + 1), &b, 4); \
    memcpy((char *) (prog + pptr + 6), &mptri, 4); \
} \
pptr += 10; \
}

#define C2MLOS 9

#define C2MLO(rpptr) { \
int jlen; \
jlen = (int) (prog + pptr) - (int) (rpptr) - 4; \
memcpy((char *) (rpptr), \
       "\x80\x38\x00" \
       "\x0f\x84____", 9); \
memcpy((char *) ((rpptr) + 5), &jlen, 4); \
}

#define C2MLC(sp) { \
int jlen; \
jlen = (int) (sp) - (int) (prog + pptr) - 5; \
memcpy((char *) (prog + pptr), \
       "\xe9____", 5); \
memcpy((char *) (prog + pptr + 1), &jlen, 4); \
pptr += 5; \
}

#define C2MJUMP(a) { \
int cptr; \
cptr = (int) (a) - (int) (prog + pptr) - 5; \
memcpy((char *) (prog + pptr), \
       "\xe9____", 5); \
memcpy((char *) (prog + pptr + 1), &cptr, 4); \
pptr += 5; \
}

#define C2MCALL(a) { \
int cptr; \
cptr = (int) (a) - (int) (prog + pptr) - 5; \
memcpy((char *) (prog + pptr), \
       "\xe8____" \
       "\xa1____", 10); \
memcpy((char *) (prog + pptr + 1), &cptr, 4); \
memcpy((char *) (prog + pptr + 6), &mptri, 4); \
pptr += 10; \
}

#define C2MZERO() { \
memcpy((char *) (prog + pptr), \
       "\xc6\x00\x00", 3); \
pptr += 3; \
}