envydis: Merge ctxdis.

This commit is contained in:
Marcin Kościelnicki
2010-10-19 19:44:34 +00:00
parent 5f1809ca43
commit fb22dce462
13 changed files with 45 additions and 185 deletions

1
.gitignore vendored
View File

@ -6,6 +6,5 @@ lookup
expand
demmio
nvbios
ctxdis
envydis
*.xml.h

View File

@ -1,4 +1,4 @@
all: headergen expand lookup demmio nvbios ctxdis envydis
all: headergen expand lookup demmio nvbios envydis
headergen: headergen.c rnn.c rnn.h
gcc -o headergen headergen.c rnn.c -lxml2 -I/usr/include/libxml2 -g -Wall -Wno-pointer-sign
@ -17,10 +17,7 @@ nvbios: nvbios.c
clean:
rm -f headergen nv50_texture.h
rm -f ctxdis envydis
rm -f envydis
ctxdis: ctxdis.c ctxd-back.c dis.h coredis.c
cc -o ctxdis ctxdis.c ctxd-back.c coredis.c
envydis: envydis.c nv50d-back.c nvc0d-back.c vp2d-back.c fucd-back.c pmd-back.c dis.h coredis.c
cc -o envydis envydis.c nv50d-back.c nvc0d-back.c vp2d-back.c fucd-back.c pmd-back.c coredis.c
envydis: envydis.c nv50d-back.c nvc0d-back.c ctxd-back.c vp2d-back.c fucd-back.c pmd-back.c dis.h coredis.c
cc -o envydis envydis.c nv50d-back.c nvc0d-back.c ctxd-back.c vp2d-back.c fucd-back.c pmd-back.c coredis.c

View File

@ -136,12 +136,14 @@ uint16_t readle16 (uint8_t *p) {
}
void markct8(struct disctx *ctx, uint32_t ptr) {
ptr *= ctx->isa->posunit;
if (ptr < ctx->codebase || ptr > ctx->codebase + ctx->codesz)
return;
ctx->labels[ptr - ctx->codebase] |= 2;
}
void markbt8(struct disctx *ctx, uint32_t ptr) {
ptr *= ctx->isa->posunit;
if (ptr < ctx->codebase || ptr > ctx->codebase + ctx->codesz)
return;
ctx->labels[ptr - ctx->codebase] |= 1;
@ -164,6 +166,7 @@ void envydis (struct disisa *isa, FILE *out, uint8_t *code, uint32_t start, int
ctx->codebase = start;
ctx->codesz = num;
ctx->ptype = ptype;
ctx->isa = isa;
while (cur < num) {
ull a = 0, m = 0;
for (i = 0; i < 8 && cur + i < num; i++) {
@ -190,16 +193,16 @@ void envydis (struct disisa *isa, FILE *out, uint8_t *code, uint32_t start, int
fprintf (ctx->out, "\n");
switch (ctx->labels[cur] & 3) {
case 0:
fprintf (ctx->out, "%s%08x:%s", cgray, cur + start, cnorm);
fprintf (ctx->out, "%s%08x:%s", cgray, (cur + start) / isa->posunit, cnorm);
break;
case 1:
fprintf (ctx->out, "%s%08x:%s", cmag, cur + start, cnorm);
fprintf (ctx->out, "%s%08x:%s", cmag, (cur + start) / isa->posunit, cnorm);
break;
case 2:
fprintf (ctx->out, "%s%08x:%s", cbr, cur + start, cnorm);
fprintf (ctx->out, "%s%08x:%s", cbr, (cur + start) / isa->posunit, cnorm);
break;
case 3:
fprintf (ctx->out, "%s%08x:%s", cbrmag, cur + start, cnorm);
fprintf (ctx->out, "%s%08x:%s", cbrmag, (cur + start) / isa->posunit, cnorm);
break;
}

View File

@ -275,64 +275,15 @@ static struct insn tabm[] = {
{ NVxx, 0, 0, OOPS },
};
/*
* Disassembler driver
*
* You pass a block of memory to this function, disassembly goes out to given
* FILE*.
*/
static struct insn tabroot[] = {
{ NVxx, 0, 0, OP32, T(m) },
};
void ctxdis (FILE *out, uint32_t *code, uint32_t start, int num, int ptype) {
struct disctx c = { 0 };
struct disctx *ctx = &c;
int cur = 0, i;
ctx->code32 = code;
ctx->labels = calloc(num, sizeof *ctx->labels);
ctx->codebase = start;
ctx->codesz = num;
ctx->ptype = ptype;
while (cur < num) {
ull a = code[cur], m = 0;
atomtab (ctx, &a, &m, tabm, cur + start);
cur++;
}
cur = 0;
ctx->out = out;
while (cur < num) {
ull a = code[cur], m = 0;
if (ctx->labels[cur] & 2)
fprintf (ctx->out, "\n");
switch (ctx->labels[cur] & 3) {
case 0:
fprintf (ctx->out, "%s%08x:%s ", cgray, cur + start, cnorm);
break;
case 1:
fprintf (ctx->out, "%s%08x:%s ", cmag, cur + start, cnorm);
break;
case 2:
fprintf (ctx->out, "%s%08x:%s ", cbr, cur + start, cnorm);
break;
case 3:
fprintf (ctx->out, "%s%08x:%s ", cbrmag, cur + start, cnorm);
break;
}
fprintf (ctx->out, "%08llx", a);
fprintf (ctx->out, " ");
if (ctx->labels[cur] & 2)
fprintf (ctx->out, "%sC", cbr);
else
fprintf (ctx->out, " ");
if (ctx->labels[cur] & 1)
fprintf (ctx->out, "%sB", cmag);
else
fprintf (ctx->out, " ");
atomtab (ctx, &a, &m, tabm, cur + start);
a &= ~m;
if (a) {
fprintf (ctx->out, " %s[unknown: %08llx]%s", cred, a, cnorm);
}
fprintf (ctx->out, "%s\n", cnorm);
cur++;
}
free(ctx->labels);
}
static struct disisa ctx_isa_s = {
tabroot,
4,
4,
4,
};
struct disisa *ctx_isa = &ctx_isa_s;

106
ctxdis.c
View File

@ -1,106 +0,0 @@
/*
*
* Copyright (C) 2009 Marcin Kościelnicki <koriakin@0x04.net>
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "dis.h"
/*
* Options:
*
* -b Read input as binary ctxprog
* -4 Disassembles NV40 ctxprogs
* -5 Disassembles NV50 ctxprogs
* -n Disable color escape sequences in output
*/
int main(int argc, char **argv) {
int ptype = NV5x;
int binary = 0;
char c;
while ((c = getopt (argc, argv, "b45n")) != -1)
switch (c) {
case 'b':
binary = 1;
break;
case '4':
ptype = NV4x;
break;
case '5':
ptype = NV5x;
break;
case 'n':
cnorm = "";
cgray = "";
cgr = "";
cbl= "";
ccy = "";
cyel = "";
cred = "";
cbr = "";
cmag = "";
cbrmag = "";
break;
}
int num = 0;
int maxnum = 16;
uint32_t *code = malloc (maxnum * 4);
uint32_t t;
if(binary) {
uint8_t hdr[7];
uint32_t signature;
uint8_t version;
uint16_t length;
uint8_t b[4];
if(fread(&hdr, 7, 1, stdin) != 1) {
fprintf(stderr, "unable to read the ctxprog header\n");
return 1;
}
signature = readle32(hdr);
version = hdr[4];
length = readle16(hdr+5);
if(signature != 0x5043564e || version != 0) {
fprintf(stderr, "invalid ctxprog header\n");
return 1;
}
while (num < length && !feof(stdin) && fread(&b, 4, 1, stdin) == 1) {
if (num == maxnum) maxnum *= 2, code = realloc (code, maxnum*4);
code[num++] = readle32(b);
}
if(num < length)
fprintf(stderr, "input ctxprog was truncated\n");
} else
while (!feof(stdin) && scanf ("%x", &t) == 1) {
if (num == maxnum) maxnum *= 2, code = realloc (code, maxnum*4);
code[num++] = t;
scanf (" ,");
}
ctxdis (stdout, code, 0, num, ptype);
return 0;
}

View File

@ -309,7 +309,7 @@ int main(int argc, char **argv) {
uint32_t param = value;
struct rnndecaddrinfo *ai = rnndec_decodeaddr(cc->ctx, mmiodom, addr, line[0] == 'W');
printf ("[%d] MMIO%d %c 0x%06"PRIx64" 0x%08"PRIx64" %s %s ", cci, width, line[0], addr, value, ai->name, line[0]=='W'?"<=":"=>");
ctxdis(stdout, &param, cc->ctxpos * 4, 1, cc->arch == 5 ? NV5x : NV4x);
envydis(ctx_isa, stdout, &param, cc->ctxpos, 4, cc->arch == 5 ? NV5x : NV4x);
cc->ctxpos++;
free(ai->name);
free(ai);

9
dis.h
View File

@ -99,6 +99,7 @@ typedef unsigned long long ull;
#define BF(s, l) (*m |= (((1ull<<l)-1)<<s), *a>>s&((1ull<<l)-1))
struct disctx;
struct disisa;
#define APROTO (struct disctx *ctx, ull *a, ull *m, const void *v, uint32_t pos)
@ -117,6 +118,7 @@ struct insn {
};
struct disctx {
struct disisa *isa;
FILE *out;
uint8_t *code8;
uint32_t *code32;
@ -132,6 +134,7 @@ struct disisa {
struct insn *troot;
int maxoplen;
int opunit;
int posunit;
};
/*
@ -200,17 +203,13 @@ void markbt8(struct disctx *ctx, uint32_t ptr);
#define CP 8
#define AP (VP|GP|FP|CP)
void nv50dis (FILE *out, uint32_t *code, uint32_t start, int num, int ptype);
void nvc0dis (FILE *out, uint32_t *code, uint32_t start, int num, int ptype);
#define NV4x 1
#define NV5x 2 /* and 8x and 9x and Ax */
#define NVxx 3
void ctxdis (FILE *out, uint32_t *code, uint32_t start, int num, int ptype);
extern struct disisa *nv50_isa;
extern struct disisa *nvc0_isa;
extern struct disisa *ctx_isa;
extern struct disisa *fuc_isa;
extern struct disisa *pms_isa;
extern struct disisa *vp2_isa;

View File

@ -46,6 +46,10 @@ int main(int argc, char **argv) {
isa = nvc0_isa;
w = 1;
}
if (!strcmp(argv[0], "ctxdis")) {
isa = ctx_isa;
w = 1;
}
if (!strcmp(argv[0], "fucdis"))
isa = fuc_isa;
if (!strcmp(argv[0], "pmsdis"))
@ -55,8 +59,14 @@ int main(int argc, char **argv) {
int ptype = -1;
int c;
unsigned base = 0, skip = 0, limit = 0;
while ((c = getopt (argc, argv, "vgfpcsb:d:l:m:wn")) != -1)
while ((c = getopt (argc, argv, "45vgfpcsb:d:l:m:wn")) != -1)
switch (c) {
case '4':
ptype = NV4x;
break;
case '5':
ptype = NV5x;
break;
case 'v':
ptype = VP;
break;
@ -102,6 +112,8 @@ int main(int argc, char **argv) {
isa = nv50_isa;
else if (!strcmp(optarg, "nvc0"))
isa = nvc0_isa;
else if (!strcmp(optarg, "ctx"))
isa = ctx_isa;
else if (!strcmp(optarg, "fuc"))
isa = fuc_isa;
else if (!strcmp(optarg, "pms"))

View File

@ -682,6 +682,7 @@ static struct disisa fuc_isa_s = {
tabm,
4,
1,
1,
};
struct disisa *fuc_isa = &fuc_isa_s;

View File

@ -1557,6 +1557,7 @@ static struct disisa nv50_isa_s = {
tabroot,
8,
4,
1,
};
struct disisa *nv50_isa = &nv50_isa_s;

View File

@ -994,6 +994,7 @@ static struct disisa nvc0_isa_s = {
tabroot,
8,
8,
1,
};
struct disisa *nvc0_isa = &nvc0_isa_s;

View File

@ -67,6 +67,7 @@ static struct disisa pms_isa_s = {
tabm,
5,
1,
1,
};
struct disisa *pms_isa = &pms_isa_s;

View File

@ -486,6 +486,7 @@ static struct disisa vp2_isa_s = {
tabroot,
3,
1,
1,
};
struct disisa *vp2_isa = &vp2_isa_s;