Skip to content

Commit

Permalink
Merge pull request #11 from robalb/develop
Browse files Browse the repository at this point in the history
Intel syntax
  • Loading branch information
robalb authored Nov 17, 2024
2 parents f5106e9 + 39cc56c commit 74f8d43
Show file tree
Hide file tree
Showing 9 changed files with 448 additions and 73 deletions.
3 changes: 3 additions & 0 deletions emscripten_blink/blink/blink/dis.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

#define DIS_MAX_SYMBOL_LENGTH 128


#ifdef HTML
#define INTEL_SYNTAX true
#define DisHTML(p, str) (stpcpy((p), (str)))
#else
#define INTEL_SYNTAX false
#define DisHTML(p, str) (p)
#endif

Expand Down
102 changes: 78 additions & 24 deletions emscripten_blink/blink/blink/disarg.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ static const char *GetAddrReg(struct Dis *d, u64 rde, u8 x, u8 r) {

static char *DisRegister(char *p, const char *s) {
p = HighStart(p, g_high.reg);
*p++ = '%';
if(!INTEL_SYNTAX)
*p++ = '$';
p = stpcpy(p, s);
p = HighEnd(p);
return p;
Expand Down Expand Up @@ -139,7 +140,8 @@ static char *DisSym(struct Dis *d, char *p, i64 value, i64 addr) {
}

static char *DisSymLiteral(struct Dis *d, u64 rde, char *p, u64 addr, u64 ip) {
*p++ = '$';
if(!INTEL_SYNTAX)
*p++ = '$';
p = HighStart(p, g_high.literal);
p = DisSym(d, p, addr, addr);
p = HighEnd(p);
Expand Down Expand Up @@ -190,7 +192,16 @@ static char *DisDisp(struct Dis *d, u64 rde, char *p) {
} else if (IsRealModrmAbsolute(rde)) {
disp = Unrelative(rde, disp);
}
p = DisSym(d, p, disp, disp);
if(INTEL_SYNTAX){
char* beforeDisSym = p;
*p++ = ' ';
p = DisSym(d, p, disp, disp);
if(beforeDisSym[1] == '0'){
*beforeDisSym = '+';
}
}else{
p = DisSym(d, p, disp, disp);
}
}
return p;
}
Expand Down Expand Up @@ -253,26 +264,49 @@ static char *DisBis(struct Dis *d, u64 rde, char *p) {
}
}
if (base || index) {
*p++ = '(';
if (base) {
p = DisRegister(p, base);
if(INTEL_SYNTAX){
*p++ = '[';
if (base) {
p = DisRegister(p, base);
}
if (index) {
*p++ = '+';
p = DisRegister(p, index);
if (scale) {
p = stpcpy(p, scale);
if(scale[0]){
*(p-2) = '*';
}
}
}
p = DisDisp(d, rde, p);
*p++ = ']';
}
if (index) {
*p++ = ',';
p = DisRegister(p, index);
if (scale) {
p = stpcpy(p, scale);
else{
*p++ = '(';
if (base) {
p = DisRegister(p, base);
}
if (index) {
*p++ = ',';
p = DisRegister(p, index);
if (scale) {
p = stpcpy(p, scale);
}
}
*p++ = ')';
}
*p++ = ')';
}
*p = '\0';
return p;
}


static char *DisM(struct Dis *d, u64 rde, char *p) {
p = DisSego(d, rde, p);
p = DisDisp(d, rde, p);
if(!INTEL_SYNTAX){
p = DisDisp(d, rde, p);
}
p = DisBis(d, rde, p);
return p;
}
Expand Down Expand Up @@ -393,9 +427,15 @@ static char *DisRdx(struct Dis *d, u64 rde, char *p) {
}

static char *DisPort(struct Dis *d, u64 rde, char *p) {
*p++ = '(';
p = DisRegister(p, kGreg[1][0][0][2]);
*p++ = ')';
if(INTEL_SYNTAX){
*p++ = '[';
p = DisRegister(p, kGreg[1][0][0][2]);
*p++ = ']';
}else{
*p++ = '(';
p = DisRegister(p, kGreg[1][0][0][2]);
*p++ = ')';
}
*p = '\0';
return p;
}
Expand Down Expand Up @@ -428,7 +468,8 @@ static char *DisRvds(struct Dis *d, u64 rde, char *p) {
}

static char *DisKpvds(struct Dis *d, u64 rde, char *p, u64 x) {
*p++ = '$';
if(!INTEL_SYNTAX)
*p++ = '$';
p = HighStart(p, g_high.literal);
p = DisInt(p, x);
p = HighEnd(p);
Expand All @@ -445,7 +486,8 @@ static char *DisPvds(struct Dis *d, u64 rde, char *p) {
}

static char *DisOne(struct Dis *d, u64 rde, char *p) {
*p++ = '$';
if(!INTEL_SYNTAX)
*p++ = '$';
p = HighStart(p, g_high.literal);
p = stpcpy(p, "1");
p = HighEnd(p);
Expand Down Expand Up @@ -479,9 +521,15 @@ static char *DisSw(struct Dis *d, u64 rde, char *p) {
}

static char *DisSpecialAddr(struct Dis *d, u64 rde, char *p, int r) {
*p++ = '(';
p = DisRegister(p, GetAddrReg(d, rde, 0, r));
*p++ = ')';
if(INTEL_SYNTAX){
*p++ = '[';
p = DisRegister(p, GetAddrReg(d, rde, 0, r));
*p++ = ']';
}else{
*p++ = '(';
p = DisRegister(p, GetAddrReg(d, rde, 0, r));
*p++ = ')';
}
*p = '\0';
return p;
}
Expand Down Expand Up @@ -536,9 +584,15 @@ static char *DisQq(struct Dis *d, u64 rde, char *p) {
static char *DisEst(struct Dis *d, u64 rde, char *p) {
p = DisRegister(p, "st");
if (ModrmRm(rde) != 0) {
*p++ = '(';
*p++ = '0' + ModrmRm(rde);
*p++ = ')';
if(INTEL_SYNTAX){
*p++ = '[';
*p++ = '0' + ModrmRm(rde);
*p++ = ']';
}else{
*p++ = '(';
*p++ = '0' + ModrmRm(rde);
*p++ = ')';
}
*p = '\0';
}
return p;
Expand Down
45 changes: 37 additions & 8 deletions emscripten_blink/blink/blink/disinst.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,30 @@ static char *DisName(struct Dis *d, char *bp, const char *name,
!StartsWith(name, "set"))) {
if (Osz(rde)) {
if (ambiguous || Mode(rde) != XED_MODE_REAL) {
*p++ = 'w';
if(INTEL_SYNTAX){
p = stpcpy(p, " word");
}else{
*p++ = 'w';
}
}
} else if (Rexw(rde)) {
*p++ = 'q';
if(INTEL_SYNTAX){
p = stpcpy(p, " qword");
}else{
*p++ = 'q';
}
} else if (ambiguous && !notbyte && IsProbablyByteOp(d->xedd)) {
*p++ = 'b';
if(INTEL_SYNTAX){
p = stpcpy(p, " byte");
}else{
*p++ = 'b';
}
} else if (!notlong) {
*p++ = 'l';
if(INTEL_SYNTAX){
p = stpcpy(p, " dword");
}else{
*p++ = 'l';
}
}
}
}
Expand All @@ -174,6 +190,7 @@ static char *DisName(struct Dis *d, char *bp, const char *name,
return p;
}


/**
* Disassembles instruction based on string spec.
* @see DisSpec()
Expand Down Expand Up @@ -201,11 +218,23 @@ char *DisInst(struct Dis *d, char *p, const char *spec) {
p = HighStart(p, g_high.keyword);
p = DisName(d, p, name, hasarg && !hasregister && hasmemory);
p = HighEnd(p);
for (i = 0; i < n; ++i) {
if (i && args[n - i][0]) {
*p++ = ',';
if(INTEL_SYNTAX){
for (i = 0; i < n; ++i) {
if (i && args[i][0]) {
*p++ = ',';
*p++ = ' ';
}
p = stpcpy(p, args[i]);
}
p = stpcpy(p, args[n - i - 1]);
}
else{
for (i = 0; i < n; ++i) {
if (i && args[n - i][0]) {
*p++ = ',';
}
p = stpcpy(p, args[n - i - 1]);
}
}

return p;
}
Loading

0 comments on commit 74f8d43

Please sign in to comment.