summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Moody <moody@posixcafe.org>2024-01-07 03:04:35 +0000
committerJacob Moody <moody@posixcafe.org>2024-01-07 03:04:35 +0000
commit74c1f4730b548c3499e59ac0c2f2aadfcd7727c5 (patch)
treedadc025c73eb96de96819645da13f80a51c3c641
parent7a503757b1251c2746df7bdcd891814c1518cc28 (diff)
6?, 8?, libc: add JMPF instruction
In 6? and 8? JMP works a bit uniquely, when passed a function name it always encodes as a JMP* instead of a JMP. This means JMP myfunc(SB) always assume that myfunc is a function pointer, not a function itself. The new JMPF instead has the same semantics as CALL and matches B and JMP in other assemblers. This allows for a small optimization in our 386 and amd64 entrypoint by avoiding a jump between _main and _callmain.
-rw-r--r--sys/src/cmd/6a/lex.c1
-rw-r--r--sys/src/cmd/6c/6.out.h2
-rw-r--r--sys/src/cmd/6l/l.h1
-rw-r--r--sys/src/cmd/6l/optab.c6
-rw-r--r--sys/src/cmd/6l/pass.c4
-rw-r--r--sys/src/cmd/6l/span.c1
-rw-r--r--sys/src/cmd/8a/lex.c1
-rw-r--r--sys/src/cmd/8c/8.out.h2
-rw-r--r--sys/src/cmd/8l/l.h1
-rw-r--r--sys/src/cmd/8l/optab.c6
-rw-r--r--sys/src/cmd/8l/pass.c4
-rw-r--r--sys/src/cmd/8l/span.c1
-rw-r--r--sys/src/libc/386/main9.s3
-rw-r--r--sys/src/libc/386/main9p.s3
-rw-r--r--sys/src/libc/amd64/main9.s3
-rw-r--r--sys/src/libc/amd64/main9p.s3
16 files changed, 30 insertions, 12 deletions
diff --git a/sys/src/cmd/6a/lex.c b/sys/src/cmd/6a/lex.c
index c124161ff..247321525 100644
--- a/sys/src/cmd/6a/lex.c
+++ b/sys/src/cmd/6a/lex.c
@@ -433,6 +433,7 @@ struct
"JCXZ", LTYPER, AJCXZ,
"JMP", LTYPEC, AJMP,
+ "JMPF", LTYPEC, AJMPF,
"LAHF", LTYPE0, ALAHF,
"LARL", LTYPE3, ALARL,
"LARW", LTYPE3, ALARW,
diff --git a/sys/src/cmd/6c/6.out.h b/sys/src/cmd/6c/6.out.h
index 91849172f..8cbed2255 100644
--- a/sys/src/cmd/6c/6.out.h
+++ b/sys/src/cmd/6c/6.out.h
@@ -713,6 +713,8 @@ enum as
ADPPD,
ADPPS,
+ AJMPF,
+
ALAST
};
diff --git a/sys/src/cmd/6l/l.h b/sys/src/cmd/6l/l.h
index 2a2ec08c0..51fc86ed1 100644
--- a/sys/src/cmd/6l/l.h
+++ b/sys/src/cmd/6l/l.h
@@ -170,6 +170,7 @@ enum
Zilo_m,
Ziqo_m,
Zjmp,
+ Zjmpf,
Zloop,
Zo_iw,
Zm_o,
diff --git a/sys/src/cmd/6l/optab.c b/sys/src/cmd/6l/optab.c
index 0d1c8a490..5896fb90c 100644
--- a/sys/src/cmd/6l/optab.c
+++ b/sys/src/cmd/6l/optab.c
@@ -295,6 +295,11 @@ uchar yjmp[] =
Ynone, Ybr, Zjmp, 1,
0
};
+uchar yjmpf[] =
+{
+ Ynone, Ybr, Zjmpf, 1,
+ 0
+};
uchar yfmvd[] =
{
@@ -717,6 +722,7 @@ Optab optab[] =
{ AJLT, yjcond, Px, 0x7c,0x8c },
{ AJMI, yjcond, Px, 0x78,0x88 },
{ AJMP, yjmp, Px, 0xff,(04),0xeb,0xe9 },
+ { AJMPF, yjmpf, Px, 0xe9 },
{ AJNE, yjcond, Px, 0x75,0x85 },
{ AJOC, yjcond, Px, 0x71,0x81,(00) },
{ AJOS, yjcond, Px, 0x70,0x80,(00) },
diff --git a/sys/src/cmd/6l/pass.c b/sys/src/cmd/6l/pass.c
index a00c52d89..50456b189 100644
--- a/sys/src/cmd/6l/pass.c
+++ b/sys/src/cmd/6l/pass.c
@@ -142,7 +142,7 @@ loop:
return;
if(p->as == ATEXT)
curtext = p;
- if(p->as == AJMP)
+ if(p->as == AJMP || p->as == AJMPF)
if((q = p->pcond) != P) {
p->mark = 1;
p = q;
@@ -319,7 +319,7 @@ patch(void)
for(p = firstp; p != P; p = p->link) {
if(p->as == ATEXT)
curtext = p;
- if(p->as == ACALL || p->as == ARET) {
+ if(p->as == ACALL || p->as == ARET || p->as == AJMPF) {
s = p->to.sym;
if(s) {
if(debug['c'])
diff --git a/sys/src/cmd/6l/span.c b/sys/src/cmd/6l/span.c
index ea3e01eb8..d2795ed65 100644
--- a/sys/src/cmd/6l/span.c
+++ b/sys/src/cmd/6l/span.c
@@ -1360,6 +1360,7 @@ found:
}
break;
+ case Zjmpf:
case Zcall:
q = p->pcond;
if(q) {
diff --git a/sys/src/cmd/8a/lex.c b/sys/src/cmd/8a/lex.c
index df76e47d6..8f1dbb549 100644
--- a/sys/src/cmd/8a/lex.c
+++ b/sys/src/cmd/8a/lex.c
@@ -372,6 +372,7 @@ struct
"JCXZ", LTYPER, AJCXZ,
"JMP", LTYPEC, AJMP,
+ "JMPF", LTYPEC, AJMPF,
"LAHF", LTYPE0, ALAHF,
"LARL", LTYPE3, ALARL,
"LARW", LTYPE3, ALARW,
diff --git a/sys/src/cmd/8c/8.out.h b/sys/src/cmd/8c/8.out.h
index 76274d187..6287f3fad 100644
--- a/sys/src/cmd/8c/8.out.h
+++ b/sys/src/cmd/8c/8.out.h
@@ -585,6 +585,8 @@ enum as
API2FW,
API2FL,
+ AJMPF,
+
/* add new operations here. nowhere else. here. */
ALAST
};
diff --git a/sys/src/cmd/8l/l.h b/sys/src/cmd/8l/l.h
index a9d07fb63..647613bc9 100644
--- a/sys/src/cmd/8l/l.h
+++ b/sys/src/cmd/8l/l.h
@@ -158,6 +158,7 @@ enum
Zil_rp,
Zilo_m,
Zjmp,
+ Zjmpf,
Zloop,
Zm_o,
Zm_r,
diff --git a/sys/src/cmd/8l/optab.c b/sys/src/cmd/8l/optab.c
index bde09048b..84f2edefa 100644
--- a/sys/src/cmd/8l/optab.c
+++ b/sys/src/cmd/8l/optab.c
@@ -240,6 +240,11 @@ uchar yjmp[] =
Ynone, Ybr, Zjmp, 1,
0
};
+uchar yjmpf[] =
+{
+ Ynone, Ybr, Zjmp, 1,
+ 0
+};
uchar yfmvd[] =
{
@@ -563,6 +568,7 @@ Optab optab[] =
{ AJLT, yjcond, Px, 0x7c,0x8c },
{ AJMI, yjcond, Px, 0x78,0x88 },
{ AJMP, yjmp, Px, 0xff,(04),0xeb,0xe9 },
+ { AJMPF, yjmpf, Px, 0xe9 },
{ AJNE, yjcond, Px, 0x75,0x85 },
{ AJOC, yjcond, Px, 0x71,0x81,(00) },
{ AJOS, yjcond, Px, 0x70,0x80,(00) },
diff --git a/sys/src/cmd/8l/pass.c b/sys/src/cmd/8l/pass.c
index 297ccdfc4..72abfb29c 100644
--- a/sys/src/cmd/8l/pass.c
+++ b/sys/src/cmd/8l/pass.c
@@ -136,7 +136,7 @@ loop:
return;
if(p->as == ATEXT)
curtext = p;
- if(p->as == AJMP)
+ if(p->as == AJMP || p->as == AJMPF)
if((q = p->pcond) != P) {
p->mark = 1;
p = q;
@@ -303,7 +303,7 @@ patch(void)
for(p = firstp; p != P; p = p->link) {
if(p->as == ATEXT)
curtext = p;
- if(p->as == ACALL || p->as == ARET) {
+ if(p->as == ACALL || p->as == ARET || p->as == AJMPF) {
s = p->to.sym;
if(s) {
if(debug['c'])
diff --git a/sys/src/cmd/8l/span.c b/sys/src/cmd/8l/span.c
index 8f2ece15e..32e231770 100644
--- a/sys/src/cmd/8l/span.c
+++ b/sys/src/cmd/8l/span.c
@@ -1151,6 +1151,7 @@ found:
}
break;
+ case Zjmpf:
case Zcall:
q = p->pcond;
if(q) {
diff --git a/sys/src/libc/386/main9.s b/sys/src/libc/386/main9.s
index eb2f2b812..8a683e054 100644
--- a/sys/src/libc/386/main9.s
+++ b/sys/src/libc/386/main9.s
@@ -3,5 +3,4 @@ TEXT _main(SB), 1, $0
MOVL $main(SB), AX
PUSHL AX
PUSHL $0
- MOVL $_callmain(SB), AX
- JMP* AX
+ JMPF _callmain(SB)
diff --git a/sys/src/libc/386/main9p.s b/sys/src/libc/386/main9p.s
index d24c74311..4268b0584 100644
--- a/sys/src/libc/386/main9p.s
+++ b/sys/src/libc/386/main9p.s
@@ -3,8 +3,7 @@ TEXT _mainp(SB), 1, $0
MOVL $_profmain(SB), AX
PUSHL AX
PUSHL $0
- MOVL $_callmain(SB), AX
- JMP* AX
+ JMPF _callmain(SB)
MOVL $_profin(SB), AX /* force loading of profile */
TEXT _saveret(SB), 1, $0
diff --git a/sys/src/libc/amd64/main9.s b/sys/src/libc/amd64/main9.s
index 0f59991c3..d7dce5e6d 100644
--- a/sys/src/libc/amd64/main9.s
+++ b/sys/src/libc/amd64/main9.s
@@ -3,5 +3,4 @@ TEXT _main(SB), 1, $0
MOVQ $main(SB), RARG
PUSHQ RARG
PUSHQ $0
- MOVQ $_callmain(SB), AX
- JMP* AX
+ JMPF _callmain(SB)
diff --git a/sys/src/libc/amd64/main9p.s b/sys/src/libc/amd64/main9p.s
index 57bda4682..af747e7cc 100644
--- a/sys/src/libc/amd64/main9p.s
+++ b/sys/src/libc/amd64/main9p.s
@@ -3,8 +3,7 @@ TEXT _mainp(SB), 1, $0
MOVQ $_profmain(SB), RARG
PUSHQ RARG
PUSHQ $0
- MOVQ $_callmain(SB), AX
- JMP* AX
+ JMPF _callmain(SB)
MOVQ $_profin(SB), AX /* force loading of profile */