| 27 |
|
|
| 28 |
#elif defined(__GNUC__) |
#elif defined(__GNUC__) |
| 29 |
|
|
|
#include <sys/mman.h> |
|
| 30 |
#include <sys/time.h> |
#include <sys/time.h> |
| 31 |
|
|
| 32 |
#endif |
#endif |
| 35 |
#include "cp932.h" |
#include "cp932.h" |
| 36 |
#include "crypt64.h" |
#include "crypt64.h" |
| 37 |
#include "desconst.h" |
#include "desconst.h" |
| 38 |
#include "expr.h" |
#include "expr_parse.h" |
| 39 |
|
#include "scoreboard.h" |
| 40 |
|
#include "synth.h" |
| 41 |
#include "translate.h" |
#include "translate.h" |
| 42 |
|
|
| 43 |
#if USE_DT |
#if USE_DT |
| 761 |
int mincnt; |
int mincnt; |
| 762 |
signed char *code = NULL; |
signed char *code = NULL; |
| 763 |
FILE *ofp; |
FILE *ofp; |
| 764 |
|
FILE *sfp; /* scoreboard */ |
| 765 |
|
struct ITREE *root_expr; |
| 766 |
int n_iter; |
int n_iter; |
| 767 |
int cr; |
int cr; |
| 768 |
|
|
| 773 |
int c; |
int c; |
| 774 |
} ts[N_TS]; |
} ts[N_TS]; |
| 775 |
|
|
|
#ifdef WIN32 |
|
|
HANDLE h; |
|
|
#endif |
|
|
|
|
| 776 |
#if 0 |
#if 0 |
| 777 |
if (argc < 2) |
if (argc < 2) |
| 778 |
{ |
{ |
| 807 |
for (i = 0; i < 28; i++) |
for (i = 0; i < 28; i++) |
| 808 |
key64.ks[i].a[0] = sizeof(WS_T) * ks_ls[i]; |
key64.ks[i].a[0] = sizeof(WS_T) * ks_ls[i]; |
| 809 |
|
|
| 810 |
/* Saltを加味しない場合は、コード領域を |
/* タゲ読み込み */ |
| 811 |
writable 領域に展開しなくてもよい。 |
root_expr = expr_parse("target.txt"); |
| 812 |
[XXX] OSによっては、書込&実行可能領域を専用のサーヴィスで |
|
| 813 |
取得しなければならないものもあるかもしれないので、注意 */ |
/* コードを生成・展開 */ |
| 814 |
#ifdef WIN32 |
sfp = scoreboard_open(); |
| 815 |
h = CreateFileMapping(INVALID_HANDLE_VALUE, |
fwrite(crypt64_sta, 1, crypt64_end - crypt64_sta, sfp); /* prologue */ |
| 816 |
NULL, |
synth_synthesize(sfp, root_expr); |
| 817 |
PAGE_EXECUTE_READWRITE, |
fwrite(crypt64_ep, 1, crypt64_ep_end - crypt64_ep, sfp); /* epilogue */ |
| 818 |
0, 0x20000000, |
|
| 819 |
NULL); |
/* コードをメモリに貼り付ける */ |
| 820 |
#ifndef FILE_MAP_EXECUTE |
code = scoreboard_map(sfp); |
|
#define FILE_MAP_EXECUTE SECTION_MAP_EXECUTE /* XXX cygwin */ |
|
|
#endif |
|
|
if (SUCCEEDED(h)) |
|
|
code = (signed char *)MapViewOfFile(h, |
|
|
FILE_MAP_EXECUTE | FILE_MAP_WRITE, |
|
|
0, 0x10000000, |
|
|
0); |
|
|
#else |
|
|
code = (signed char *)mmap(NULL, |
|
|
0x10000000, |
|
|
PROT_EXEC | PROT_READ | PROT_WRITE, |
|
|
MAP_PRIVATE | MAP_ANON, |
|
|
1, /* fd */ |
|
|
0); |
|
|
if ((void *)code == MAP_FAILED) |
|
|
code =NULL; |
|
|
#endif |
|
|
|
|
|
/* メモリが確保できていない場合のいんちき対策 */ |
|
|
if (code == NULL) |
|
|
code = (signed char *)malloc(crypt64_end - crypt64_sta + 1024 * 1024); |
|
|
assert(code != NULL); |
|
|
|
|
|
/* Prologue を展開 */ |
|
|
memcpy(code, crypt64_sta, crypt64_end - crypt64_sta); |
|
|
memcpy(expr_parse(code + (crypt64_end - crypt64_sta), |
|
|
1024 * 1024 - (crypt64_ep_end - crypt64_ep), |
|
|
argv[1]), |
|
|
crypt64_ep, |
|
|
crypt64_ep_end - crypt64_ep); |
|
| 821 |
|
|
| 822 |
/* キーの初期化 */ |
/* キーの初期化 */ |
| 823 |
srand(time(NULL)); |
srand(time(NULL)); |
| 865 |
ホントはいろいろレジスタが破壊されるハズ…なんだが。 */ |
ホントはいろいろレジスタが破壊されるハズ…なんだが。 */ |
| 866 |
cnt = CALL_CRYPT64(code, key64.k, param64.lr); |
cnt = CALL_CRYPT64(code, key64.k, param64.lr); |
| 867 |
|
|
| 868 |
|
#if DEBUG>=1 |
| 869 |
if (mincnt > cnt && cnt > 0) |
if (mincnt > cnt && cnt > 0) |
| 870 |
{ |
{ |
| 871 |
mincnt = cnt; |
mincnt = cnt; |
| 874 |
cr = 0; |
cr = 0; |
| 875 |
fprintf(stderr, "cycle=%d\n", (int)cnt); |
fprintf(stderr, "cycle=%d\n", (int)cnt); |
| 876 |
} |
} |
| 877 |
|
#endif |
| 878 |
|
|
| 879 |
/* ヒットしたときの処理 */ |
/* ヒットしたときの処理 */ |
| 880 |
for (kk = 0; kk < N_ALU; kk++) |
for (kk = 0; kk < N_ALU; kk++) |