Skip to content

Commit

Permalink
thunk_gen: separate ret val and func FARs [fixes #10]
Browse files Browse the repository at this point in the history
Now "void FAR *DetectXMSDriver(VOID);" gets parsed correctly.

Before the patch the thunk was:
_THUNK_P_0_vp(40, DetectXMSDriver, 1)

After the patch:
_THUNK_P_0_vpf(40, DetectXMSDriver, 0)
  • Loading branch information
stsp committed Jul 5, 2018
1 parent 04eb7e5 commit 57e9160
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
2 changes: 1 addition & 1 deletion kernel/thunks.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ void f(void) \
do_asm_call(n, NULL, 0, z); \
}

#define _THUNK_P_0_vp(n, f, z) \
#define _THUNK_P_0_vpf(n, f, z) \
void FAR *f(void) \
{ \
uint32_t __ret; \
Expand Down
2 changes: 1 addition & 1 deletion utils/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exeflat.exe: exeflat.c ../hdr/exe.h
$(CLC) $(CFLAGS) -o $@ exeflat.c

thunk_gen: lex.yy.c thunk_gen.tab.c
$(CLC) -o $@ $^
$(CLC) -g -o $@ $^

thunk_gen.tab.c: thunk_gen.y
bison -d $^
Expand Down
53 changes: 39 additions & 14 deletions utils/thunk_gen.y
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static int is_ptr;
static int is_rptr;
static int is_far;
static int is_rfar;
static int is_ffar;
static int is_void;
static int is_rvoid;
static int is_const;
Expand Down Expand Up @@ -53,6 +54,7 @@ static void init_line(void)
is_rvoid = 0;
is_rptr = 0;
is_rfar = 0;
is_ffar = 0;
is_noret = 0;
beg_arg();
}
Expand Down Expand Up @@ -167,7 +169,7 @@ static int get_flags(void)
int flg = 0;
#define FLG_FAR 1
#define FLG_NORET 2
if (is_rfar)
if (is_ffar)
flg |= FLG_FAR;
if (is_noret)
flg |= FLG_NORET;
Expand Down Expand Up @@ -199,13 +201,17 @@ line: lnum rdecls fname lb args rb SEMIC
break;
case 1:
if (!is_rvoid)
printf("_THUNK%s%i(%i, %s, %s",
printf("_THUNK%s%i%s(%i, %s, %s",
is_pas ? "_P_" : "",
arg_num, $1, rtbuf, $3);
arg_num,
is_rptr ? (is_rfar ? "pf" : "p") : "",
$1, rtbuf, $3);
else
printf("_THUNK%s%i_v%s(%i, %s",
is_pas ? "_P_" : "",
arg_num, is_rptr ? "p" : "", $1, $3);
arg_num,
is_rptr ? (is_rfar ? "pf" : "p") : "",
$1, $3);
if (arg_num)
printf(", %s", abuf);
printf(", %i)\n", get_flags());
Expand All @@ -214,7 +220,7 @@ line: lnum rdecls fname lb args rb SEMIC
}
;

lb: LB { arg_offs = 0; arg_num = 0; is_rptr = is_ptr; is_rfar = is_far, beg_arg(); }
lb: LB { arg_offs = 0; arg_num = 0; beg_arg(); }
;
rb: RB { fin_arg(1); }
;
Expand All @@ -230,12 +236,29 @@ sname: STRING
tname: STRING
;

decls: ASMCFUNC decls
| SEGM LB STRING RB decls
| ASMPASCAL decls { is_pas = 1; }
| FAR decls { is_far = 1; }
| NORETURN decls { is_noret = 1; }
| ASTER decls { is_ptr = 1; }
rquals: FAR ASTER { is_rfar = 1; is_rptr = 1; }
| ASTER { is_rptr = 1; }
;

quals: FAR quals { is_far = 1; }
| ASTER quals { is_ptr = 1; }
|
;

fatr: ASMCFUNC
| ASMPASCAL { is_pas = 1; }
| NORETURN { is_noret = 1; }
| FAR { is_ffar = 1; }
| SEGM LB STRING RB
;

fatrs: fatr fatrs
| fatr
;

rq_fa: rquals fatrs
| rquals
| fatrs
|
;

Expand Down Expand Up @@ -336,11 +359,11 @@ atype: VOID {
}
;

rdecls: rtype decls { abuf[0] = 0; }
rdecls: rtype rq_fa { abuf[0] = 0; }
;

adecls: atype decls
| CONST atype decls { is_const = 1; }
adecls: atype quals
| CONST atype quals { is_const = 1; }
;

argsep: COMMA { fin_arg(0); strcat(abuf, ", "); beg_arg(); }
Expand All @@ -361,6 +384,8 @@ int main(int argc, char *argv[])

if (argc >= 2)
thunk_type = atoi(argv[1]);
if (argc >= 3 && argv[2][0] == 'd')
yydebug = 1;
yyparse();
return 0;
}
Expand Down

0 comments on commit 57e9160

Please sign in to comment.