1 |
|
/* |
2 |
< |
* UAE - The Un*x Amiga Emulator |
2 |
> |
* compiler/gencomp.c - MC680x0 compilation generator |
3 |
|
* |
4 |
< |
* MC68000 compilation generator |
4 |
> |
* Based on work Copyright 1995, 1996 Bernd Schmidt |
5 |
> |
* Changes for UAE-JIT Copyright 2000 Bernd Meyer |
6 |
|
* |
7 |
< |
* Based on work Copyright 1995, 1996 Bernd Schmidt. Changes Copyright 2000 |
8 |
< |
* Bernd Meyer |
7 |
> |
* Adaptation for Basilisk II and improvements, copyright 2000-2005 |
8 |
> |
* Gwenole Beauchesne |
9 |
> |
* |
10 |
> |
* Basilisk II (C) 1997-2005 Christian Bauer |
11 |
> |
* |
12 |
> |
* This program is free software; you can redistribute it and/or modify |
13 |
> |
* it under the terms of the GNU General Public License as published by |
14 |
> |
* the Free Software Foundation; either version 2 of the License, or |
15 |
> |
* (at your option) any later version. |
16 |
> |
* |
17 |
> |
* This program is distributed in the hope that it will be useful, |
18 |
> |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 |
> |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 |
> |
* GNU General Public License for more details. |
21 |
> |
* |
22 |
> |
* You should have received a copy of the GNU General Public License |
23 |
> |
* along with this program; if not, write to the Free Software |
24 |
> |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
25 |
|
*/ |
26 |
|
|
10 |
– |
|
27 |
|
#include <stdio.h> |
28 |
|
#include <stdlib.h> |
29 |
|
#include <stdarg.h> |
1100 |
|
"\tint one=scratchie++;\n" |
1101 |
|
"\tif (needed_flags&FLAG_Z) {\n" |
1102 |
|
"\tmov_l_ri(zero,0);\n" |
1103 |
< |
"\tmov_l_ri(one,1);\n" |
1103 |
> |
"\tmov_l_ri(one,-1);\n" |
1104 |
|
"\tmake_flags_live();\n" |
1105 |
|
"\tcmov_l_rr(zero,one,5);\n" |
1106 |
|
"\t}\n"); |
1120 |
|
"\t%s_l(%s,%s);\n",op,dst,src); |
1121 |
|
break; |
1122 |
|
} |
1123 |
+ |
comprintf("\tlive_flags();\n"); |
1124 |
|
comprintf("\tif (needed_flags&FLAG_Z) {\n" |
1125 |
|
"\tcmov_l_rr(zero,one,5);\n" |
1126 |
< |
"\tbsf_l_rr(zero,zero);\n" |
1126 |
> |
"\tset_zero(zero, one);\n" /* No longer need one */ |
1127 |
> |
"\tlive_flags();\n" |
1128 |
|
"\t}\n"); |
1111 |
– |
comprintf("\tlive_flags();\n"); |
1129 |
|
comprintf("\tend_needflags();\n"); |
1130 |
|
duplicate_carry(); |
1131 |
|
comprintf("if (!(needed_flags & FLAG_CZNV)) dont_care_flags();\n"); |
1365 |
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1366 |
|
start_brace(); |
1367 |
|
comprintf("\tint s=scratchie++;\n" |
1368 |
+ |
"\tint tmp=scratchie++;\n" |
1369 |
|
"\tmov_l_rr(s,src);\n"); |
1370 |
|
if (curi->size == sz_byte) |
1371 |
|
comprintf("\tand_l_ri(s,7);\n"); |
1381 |
|
case i_BCLR: op="btr"; break; |
1382 |
|
case i_BSET: op="bts"; break; |
1383 |
|
case i_BTST: op="bt"; need_write=0; break; |
1384 |
+ |
default: abort(); |
1385 |
|
} |
1386 |
|
comprintf("\t%s_l_rr(dst,s);\n" /* Answer now in C */ |
1387 |
< |
"\tsbb_l(s,s);\n" /* s is 0 if bit was 0, |
1388 |
< |
-1 otherwise */ |
1389 |
< |
"\tmake_flags_live();\n" /* Get the flags back */ |
1390 |
< |
"\tdont_care_flags();\n" |
1391 |
< |
"\tstart_needflags();\n" |
1392 |
< |
"\tbsf_l_rr(s,s);\n" |
1393 |
< |
"\tlive_flags();\n" |
1394 |
< |
"\tend_needflags();\n",op); |
1387 |
> |
"\tsbb_l(s,s);\n" /* s is 0 if bit was 0, -1 otherwise */ |
1388 |
> |
"\tmake_flags_live();\n" /* Get the flags back */ |
1389 |
> |
"\tdont_care_flags();\n",op); |
1390 |
> |
if (!noflags) { |
1391 |
> |
comprintf("\tstart_needflags();\n" |
1392 |
> |
"\tset_zero(s,tmp);\n" |
1393 |
> |
"\tlive_flags();\n" |
1394 |
> |
"\tend_needflags();\n"); |
1395 |
> |
} |
1396 |
|
if (need_write) |
1397 |
|
genastore ("dst", curi->dmode, "dstreg", curi->size, "dst"); |
1398 |
|
} |
1549 |
|
start_brace(); |
1550 |
|
comprintf("\tint newad=scratchie++;\n" |
1551 |
|
"\treadlong(15,newad,scratchie);\n" |
1552 |
< |
"\tmov_l_mr((uae_u32)®s.pc,newad);\n" |
1552 |
> |
"\tmov_l_mr((uintptr)®s.pc,newad);\n" |
1553 |
|
"\tget_n_addr_jmp(newad,PC_P,scratchie);\n" |
1554 |
< |
"\tmov_l_mr((uae_u32)®s.pc_oldp,PC_P);\n" |
1554 |
> |
"\tmov_l_mr((uintptr)®s.pc_oldp,PC_P);\n" |
1555 |
|
"\tm68k_pc_offset=0;\n" |
1556 |
|
"\tadd_l(15,offs);\n"); |
1557 |
|
gen_update_next_handler(); |
1580 |
|
case i_RTS: |
1581 |
|
comprintf("\tint newad=scratchie++;\n" |
1582 |
|
"\treadlong(15,newad,scratchie);\n" |
1583 |
< |
"\tmov_l_mr((uae_u32)®s.pc,newad);\n" |
1583 |
> |
"\tmov_l_mr((uintptr)®s.pc,newad);\n" |
1584 |
|
"\tget_n_addr_jmp(newad,PC_P,scratchie);\n" |
1585 |
< |
"\tmov_l_mr((uae_u32)®s.pc_oldp,PC_P);\n" |
1585 |
> |
"\tmov_l_mr((uintptr)®s.pc_oldp,PC_P);\n" |
1586 |
|
"\tm68k_pc_offset=0;\n" |
1587 |
|
"\tlea_l_brr(15,15,4);\n"); |
1588 |
|
gen_update_next_handler(); |
1605 |
|
"\tmov_l_ri(ret,retadd);\n" |
1606 |
|
"\tsub_l_ri(15,4);\n" |
1607 |
|
"\twritelong_clobber(15,ret,scratchie);\n"); |
1608 |
< |
comprintf("\tmov_l_mr((uae_u32)®s.pc,srca);\n" |
1608 |
> |
comprintf("\tmov_l_mr((uintptr)®s.pc,srca);\n" |
1609 |
|
"\tget_n_addr_jmp(srca,PC_P,scratchie);\n" |
1610 |
< |
"\tmov_l_mr((uae_u32)®s.pc_oldp,PC_P);\n" |
1610 |
> |
"\tmov_l_mr((uintptr)®s.pc_oldp,PC_P);\n" |
1611 |
|
"\tm68k_pc_offset=0;\n"); |
1612 |
|
gen_update_next_handler(); |
1613 |
|
break; |
1614 |
|
case i_JMP: |
1615 |
|
isjump; |
1616 |
|
genamode (curi->smode, "srcreg", curi->size, "src", 0, 0); |
1617 |
< |
comprintf("\tmov_l_mr((uae_u32)®s.pc,srca);\n" |
1617 |
> |
comprintf("\tmov_l_mr((uintptr)®s.pc,srca);\n" |
1618 |
|
"\tget_n_addr_jmp(srca,PC_P,scratchie);\n" |
1619 |
< |
"\tmov_l_mr((uae_u32)®s.pc_oldp,PC_P);\n" |
1619 |
> |
"\tmov_l_mr((uintptr)®s.pc_oldp,PC_P);\n" |
1620 |
|
"\tm68k_pc_offset=0;\n"); |
1621 |
|
gen_update_next_handler(); |
1622 |
|
break; |
1623 |
|
case i_BSR: |
1604 |
– |
if (curi->size==sz_long) |
1605 |
– |
failure; |
1624 |
|
is_const_jump; |
1625 |
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1626 |
|
start_brace(); |
1647 |
|
comprintf("\tsub_l_ri(src,m68k_pc_offset-m68k_pc_offset_thisinst-2);\n"); |
1648 |
|
/* Leave the following as "add" --- it will allow it to be optimized |
1649 |
|
away due to src being a constant ;-) */ |
1650 |
< |
comprintf("\tadd_l_ri(src,(uae_u32)comp_pc_p);\n"); |
1651 |
< |
comprintf("\tmov_l_ri(PC_P,(uae_u32)comp_pc_p);\n"); |
1650 |
> |
comprintf("\tadd_l_ri(src,(uintptr)comp_pc_p);\n"); |
1651 |
> |
comprintf("\tmov_l_ri(PC_P,(uintptr)comp_pc_p);\n"); |
1652 |
|
/* Now they are both constant. Might as well fold in m68k_pc_offset */ |
1653 |
|
comprintf("\tadd_l_ri(src,m68k_pc_offset);\n"); |
1654 |
|
comprintf("\tadd_l_ri(PC_P,m68k_pc_offset);\n"); |
1721 |
|
default: abort(); /* Seems this only comes in word flavour */ |
1722 |
|
} |
1723 |
|
comprintf("\tsub_l_ri(offs,m68k_pc_offset-m68k_pc_offset_thisinst-2);\n"); |
1724 |
< |
comprintf("\tadd_l_ri(offs,(uae_u32)comp_pc_p);\n"); /* New PC, |
1724 |
> |
comprintf("\tadd_l_ri(offs,(uintptr)comp_pc_p);\n"); /* New PC, |
1725 |
|
once the |
1726 |
|
offset_68k is |
1727 |
|
* also added */ |
1896 |
|
comprintf("\tint highmask;\n" |
1897 |
|
"\tint width;\n" |
1898 |
|
"\tint cdata=scratchie++;\n" |
1899 |
< |
"\tint tmpcnt=scratchie++;\n" |
1900 |
< |
"\tint highshift=scratchie++;\n"); |
1901 |
< |
comprintf("\tmov_l_rr(tmpcnt,cnt);\n" |
1902 |
< |
"\tand_l_ri(tmpcnt,63);\n" |
1903 |
< |
"\tmov_l_ri(cdata,0);\n" |
1904 |
< |
"\tcmov_l_rr(cdata,data,5);\n"); |
1905 |
< |
/* cdata is now either data (for shift count!=0) or |
1906 |
< |
0 (for shift count==0) */ |
1907 |
< |
switch(curi->size) { |
1908 |
< |
case sz_byte: comprintf("\tshra_b_rr(data,cnt);\n" |
1909 |
< |
"\thighmask=0x38;\n" |
1910 |
< |
"\twidth=8;\n"); |
1911 |
< |
break; |
1912 |
< |
case sz_word: comprintf("\tshra_w_rr(data,cnt);\n" |
1895 |
< |
"\thighmask=0x30;\n" |
1896 |
< |
"\twidth=16;\n"); |
1897 |
< |
break; |
1898 |
< |
case sz_long: comprintf("\tshra_l_rr(data,cnt);\n" |
1899 |
< |
"\thighmask=0x20;\n" |
1900 |
< |
"\twidth=32;\n"); |
1901 |
< |
break; |
1902 |
< |
default: abort(); |
1903 |
< |
} |
1904 |
< |
comprintf("test_l_ri(cnt,highmask);\n" |
1905 |
< |
"mov_l_ri(highshift,0);\n" |
1906 |
< |
"mov_l_ri(scratchie,width/2);\n" |
1907 |
< |
"cmov_l_rr(highshift,scratchie,5);\n"); |
1908 |
< |
/* The x86 masks out bits, so we now make sure that things |
1909 |
< |
really get shifted as much as planned */ |
1899 |
> |
"\tint sdata=scratchie++;\n" |
1900 |
> |
"\tint tmpcnt=scratchie++;\n"); |
1901 |
> |
comprintf("\tmov_l_rr(sdata,data);\n" |
1902 |
> |
"\tmov_l_rr(cdata,data);\n" |
1903 |
> |
"\tmov_l_rr(tmpcnt,cnt);\n"); |
1904 |
> |
switch (curi->size) { |
1905 |
> |
case sz_byte: comprintf("\tshra_b_ri(sdata,7);\n"); break; |
1906 |
> |
case sz_word: comprintf("\tshra_w_ri(sdata,15);\n"); break; |
1907 |
> |
case sz_long: comprintf("\tshra_l_ri(sdata,31);\n"); break; |
1908 |
> |
default: abort(); |
1909 |
> |
} |
1910 |
> |
/* sdata is now the MSB propagated to all bits for the |
1911 |
> |
register of specified size */ |
1912 |
> |
comprintf("\tand_l_ri(tmpcnt,63);\n"); |
1913 |
|
switch(curi->size) { |
1914 |
< |
case sz_byte: comprintf("\tshra_b_rr(data,highshift);\n");break; |
1915 |
< |
case sz_word: comprintf("\tshra_w_rr(data,highshift);\n");break; |
1916 |
< |
case sz_long: comprintf("\tshra_l_rr(data,highshift);\n");break; |
1917 |
< |
default: abort(); |
1914 |
> |
case sz_byte: comprintf("\tshra_b_rr(data,tmpcnt);\n" |
1915 |
> |
"\thighmask=0x38;\n"); |
1916 |
> |
break; |
1917 |
> |
case sz_word: comprintf("\tshra_w_rr(data,tmpcnt);\n" |
1918 |
> |
"\thighmask=0x30;\n"); |
1919 |
> |
break; |
1920 |
> |
case sz_long: comprintf("\tshra_l_rr(data,tmpcnt);\n" |
1921 |
> |
"\thighmask=0x20;\n"); |
1922 |
> |
break; |
1923 |
|
} |
1924 |
< |
/* And again */ |
1925 |
< |
switch(curi->size) { |
1926 |
< |
case sz_byte: comprintf("\tshra_b_rr(data,highshift);\n");break; |
1927 |
< |
case sz_word: comprintf("\tshra_w_rr(data,highshift);\n");break; |
1928 |
< |
case sz_long: comprintf("\tshra_l_rr(data,highshift);\n");break; |
1921 |
< |
default: abort(); |
1924 |
> |
comprintf("\ttest_l_ri(tmpcnt,highmask);\n"); |
1925 |
> |
switch (curi->size) { |
1926 |
> |
case sz_byte: comprintf("\tcmov_b_rr(data,sdata,NATIVE_CC_NE);\n"); break; |
1927 |
> |
case sz_word: comprintf("\tcmov_w_rr(data,sdata,NATIVE_CC_NE);\n"); break; |
1928 |
> |
case sz_long: comprintf("\tcmov_l_rr(data,sdata,NATIVE_CC_NE);\n"); break; |
1929 |
|
} |
1930 |
|
|
1931 |
|
/* Result of shift is now in data. Now we need to determine |
1932 |
|
the carry by shifting cdata one less */ |
1933 |
+ |
/* NOTE: carry bit is cleared if shift count is zero */ |
1934 |
+ |
comprintf("\tmov_l_ri(scratchie,0);\n" |
1935 |
+ |
"\ttest_l_rr(tmpcnt,tmpcnt);\n" |
1936 |
+ |
"\tcmov_l_rr(sdata,scratchie,NATIVE_CC_EQ);\n" |
1937 |
+ |
"\tforget_about(scratchie);\n"); |
1938 |
|
comprintf("\tsub_l_ri(tmpcnt,1);\n"); |
1939 |
|
switch(curi->size) { |
1940 |
|
case sz_byte: comprintf("\tshra_b_rr(cdata,tmpcnt);\n");break; |
1943 |
|
default: abort(); |
1944 |
|
} |
1945 |
|
/* If the shift count was higher than the width, we need |
1946 |
< |
to pick up the sign from data */ |
1947 |
< |
comprintf("test_l_ri(tmpcnt,highmask);\n" |
1948 |
< |
"cmov_l_rr(cdata,data,5);\n"); |
1949 |
< |
/* And create the flags */ |
1946 |
> |
to pick up the sign from original data (sdata) */ |
1947 |
> |
/* NOTE: for shift count of zero, the following holds |
1948 |
> |
true and cdata contains 0 so that carry bit is cleared */ |
1949 |
> |
comprintf("\ttest_l_ri(tmpcnt,highmask);\n" |
1950 |
> |
"\tforget_about(tmpcnt);\n" |
1951 |
> |
"\tcmov_l_rr(cdata,sdata,NATIVE_CC_NE);\n"); |
1952 |
> |
|
1953 |
> |
/* And create the flags (preserve X flag if shift count is zero) */ |
1954 |
> |
comprintf("\ttest_l_ri(cnt,63);\n" |
1955 |
> |
"\tcmov_l_rr(FLAGX,cdata,NATIVE_CC_NE);\n"); |
1956 |
|
comprintf("\tstart_needflags();\n"); |
1957 |
|
comprintf("\tif (needed_flags & FLAG_ZNV)\n"); |
1958 |
|
switch(curi->size) { |
1963 |
|
comprintf("\t bt_l_ri(cdata,0);\n"); /* Set C */ |
1964 |
|
comprintf("\t live_flags();\n"); |
1965 |
|
comprintf("\t end_needflags();\n"); |
1948 |
– |
comprintf("\t duplicate_carry();\n"); |
1966 |
|
comprintf("if (!(needed_flags & FLAG_CZNV)) dont_care_flags();\n"); |
1967 |
|
genastore ("data", curi->dmode, "dstreg", curi->size, "data"); |
1968 |
|
} |
2213 |
|
comprintf("\tmov_l_rr(tmpcnt,cnt);\n" |
2214 |
|
"\tand_l_ri(tmpcnt,63);\n" |
2215 |
|
"\tmov_l_ri(cdata,0);\n" |
2216 |
< |
"\tcmov_l_rr(cdata,data,5);\n"); |
2216 |
> |
"\tcmov_l_rr(cdata,data,NATIVE_CC_NE);\n"); |
2217 |
|
/* cdata is now either data (for shift count!=0) or |
2218 |
|
0 (for shift count==0) */ |
2219 |
|
switch(curi->size) { |
2220 |
< |
case sz_byte: comprintf("\tshrl_b_rr(data,cnt);\n" |
2220 |
> |
case sz_byte: comprintf("\tshrl_b_rr(data,tmpcnt);\n" |
2221 |
|
"\thighmask=0x38;\n"); |
2222 |
|
break; |
2223 |
< |
case sz_word: comprintf("\tshrl_w_rr(data,cnt);\n" |
2223 |
> |
case sz_word: comprintf("\tshrl_w_rr(data,tmpcnt);\n" |
2224 |
|
"\thighmask=0x30;\n"); |
2225 |
|
break; |
2226 |
< |
case sz_long: comprintf("\tshrl_l_rr(data,cnt);\n" |
2226 |
> |
case sz_long: comprintf("\tshrl_l_rr(data,tmpcnt);\n" |
2227 |
|
"\thighmask=0x20;\n"); |
2228 |
|
break; |
2229 |
|
default: abort(); |
2230 |
|
} |
2231 |
< |
comprintf("test_l_ri(cnt,highmask);\n" |
2232 |
< |
"mov_l_ri(scratchie,0);\n" |
2233 |
< |
"cmov_l_rr(scratchie,data,4);\n"); |
2234 |
< |
switch(curi->size) { |
2235 |
< |
case sz_byte: comprintf("\tmov_b_rr(data,scratchie);\n");break; |
2236 |
< |
case sz_word: comprintf("\tmov_w_rr(data,scratchie);\n");break; |
2237 |
< |
case sz_long: comprintf("\tmov_l_rr(data,scratchie);\n");break; |
2238 |
< |
default: abort(); |
2231 |
> |
comprintf("\ttest_l_ri(tmpcnt,highmask);\n" |
2232 |
> |
"\rmov_l_ri(scratchie,0);\n"); |
2233 |
> |
if (curi->size == sz_long) |
2234 |
> |
comprintf("\tcmov_l_rr(data,scratchie,NATIVE_CC_NE);\n"); |
2235 |
> |
else { |
2236 |
> |
comprintf("\tcmov_l_rr(scratchie,data,NATIVE_CC_EQ);\n"); |
2237 |
> |
switch(curi->size) { |
2238 |
> |
case sz_byte: comprintf("\tmov_b_rr(data,scratchie);\n");break; |
2239 |
> |
case sz_word: comprintf("\tmov_w_rr(data,scratchie);\n");break; |
2240 |
> |
default: abort(); |
2241 |
> |
} |
2242 |
|
} |
2243 |
|
/* Result of shift is now in data. Now we need to determine |
2244 |
|
the carry by shifting cdata one less */ |
2245 |
|
comprintf("\tsub_l_ri(tmpcnt,1);\n"); |
2246 |
< |
switch(curi->size) { |
2247 |
< |
case sz_byte: comprintf("\tshrl_b_rr(cdata,tmpcnt);\n");break; |
2248 |
< |
case sz_word: comprintf("\tshrl_w_rr(cdata,tmpcnt);\n");break; |
2249 |
< |
case sz_long: comprintf("\tshrl_l_rr(cdata,tmpcnt);\n");break; |
2250 |
< |
default: abort(); |
2251 |
< |
} |
2252 |
< |
comprintf("test_l_ri(tmpcnt,highmask);\n" |
2253 |
< |
"mov_l_ri(scratchie,0);\n" |
2254 |
< |
"cmov_l_rr(cdata,scratchie,5);\n"); |
2255 |
< |
/* And create the flags */ |
2246 |
> |
comprintf("\tshrl_l_rr(cdata,tmpcnt);\n"); |
2247 |
> |
comprintf("\ttest_l_ri(tmpcnt,highmask);\n"); |
2248 |
> |
comprintf("\tforget_about(tmpcnt);\n"); |
2249 |
> |
if (curi->size != sz_long) /* scratchie is still live for LSR.L */ |
2250 |
> |
comprintf("\tmov_l_ri(scratchie,0);\n"); |
2251 |
> |
comprintf("\tcmov_l_rr(cdata,scratchie,NATIVE_CC_NE);\n"); |
2252 |
> |
comprintf("\tforget_about(scratchie);\n"); |
2253 |
> |
/* And create the flags (preserve X flag if shift count is zero) */ |
2254 |
> |
comprintf("\ttest_l_ri(cnt,63);\n" |
2255 |
> |
"\tcmov_l_rr(FLAGX,cdata,NATIVE_CC_NE);\n"); |
2256 |
|
comprintf("\tstart_needflags();\n"); |
2257 |
|
comprintf("\tif (needed_flags & FLAG_ZNV)\n"); |
2258 |
|
switch(curi->size) { |
2263 |
|
comprintf("\t bt_l_ri(cdata,0);\n"); /* Set C */ |
2264 |
|
comprintf("\t live_flags();\n"); |
2265 |
|
comprintf("\t end_needflags();\n"); |
2246 |
– |
comprintf("\t duplicate_carry();\n"); |
2266 |
|
comprintf("if (!(needed_flags & FLAG_CZNV)) dont_care_flags();\n"); |
2267 |
|
genastore ("data", curi->dmode, "dstreg", curi->size, "data"); |
2268 |
|
} |
2351 |
|
comprintf("\tmov_l_rr(tmpcnt,cnt);\n" |
2352 |
|
"\tand_l_ri(tmpcnt,63);\n" |
2353 |
|
"\tmov_l_ri(cdata,0);\n" |
2354 |
< |
"\tcmov_l_rr(cdata,data,5);\n"); |
2354 |
> |
"\tcmov_l_rr(cdata,data,NATIVE_CC_NE);\n"); |
2355 |
|
/* cdata is now either data (for shift count!=0) or |
2356 |
|
0 (for shift count==0) */ |
2357 |
|
switch(curi->size) { |
2358 |
< |
case sz_byte: comprintf("\tshll_b_rr(data,cnt);\n" |
2358 |
> |
case sz_byte: comprintf("\tshll_b_rr(data,tmpcnt);\n" |
2359 |
|
"\thighmask=0x38;\n"); |
2360 |
|
break; |
2361 |
< |
case sz_word: comprintf("\tshll_w_rr(data,cnt);\n" |
2361 |
> |
case sz_word: comprintf("\tshll_w_rr(data,tmpcnt);\n" |
2362 |
|
"\thighmask=0x30;\n"); |
2363 |
|
break; |
2364 |
< |
case sz_long: comprintf("\tshll_l_rr(data,cnt);\n" |
2364 |
> |
case sz_long: comprintf("\tshll_l_rr(data,tmpcnt);\n" |
2365 |
|
"\thighmask=0x20;\n"); |
2366 |
|
break; |
2367 |
|
default: abort(); |
2368 |
|
} |
2369 |
< |
comprintf("test_l_ri(cnt,highmask);\n" |
2370 |
< |
"mov_l_ri(scratchie,0);\n" |
2371 |
< |
"cmov_l_rr(scratchie,data,4);\n"); |
2372 |
< |
switch(curi->size) { |
2373 |
< |
case sz_byte: comprintf("\tmov_b_rr(data,scratchie);\n");break; |
2374 |
< |
case sz_word: comprintf("\tmov_w_rr(data,scratchie);\n");break; |
2375 |
< |
case sz_long: comprintf("\tmov_l_rr(data,scratchie);\n");break; |
2376 |
< |
default: abort(); |
2369 |
> |
comprintf("\ttest_l_ri(tmpcnt,highmask);\n" |
2370 |
> |
"\tmov_l_ri(scratchie,0);\n"); |
2371 |
> |
if (curi->size == sz_long) |
2372 |
> |
comprintf("\tcmov_l_rr(data,scratchie,NATIVE_CC_NE);\n"); |
2373 |
> |
else { |
2374 |
> |
comprintf("\tcmov_l_rr(scratchie,data,NATIVE_CC_EQ);\n"); |
2375 |
> |
switch(curi->size) { |
2376 |
> |
case sz_byte: comprintf("\tmov_b_rr(data,scratchie);\n");break; |
2377 |
> |
case sz_word: comprintf("\tmov_w_rr(data,scratchie);\n");break; |
2378 |
> |
default: abort(); |
2379 |
> |
} |
2380 |
|
} |
2381 |
|
/* Result of shift is now in data. Now we need to determine |
2382 |
|
the carry by shifting cdata one less */ |
2383 |
|
comprintf("\tsub_l_ri(tmpcnt,1);\n"); |
2384 |
< |
switch(curi->size) { |
2385 |
< |
case sz_byte: comprintf("\tshll_b_rr(cdata,tmpcnt);\n");break; |
2386 |
< |
case sz_word: comprintf("\tshll_w_rr(cdata,tmpcnt);\n");break; |
2387 |
< |
case sz_long: comprintf("\tshll_l_rr(cdata,tmpcnt);\n");break; |
2388 |
< |
default: abort(); |
2384 |
> |
comprintf("\tshll_l_rr(cdata,tmpcnt);\n"); |
2385 |
> |
comprintf("\ttest_l_ri(tmpcnt,highmask);\n"); |
2386 |
> |
comprintf("\tforget_about(tmpcnt);\n"); |
2387 |
> |
if (curi->size != sz_long) /* scratchie is still live for LSL.L */ |
2388 |
> |
comprintf("\tmov_l_ri(scratchie,0);\n"); |
2389 |
> |
comprintf("\tcmov_l_rr(cdata,scratchie,NATIVE_CC_NE);\n"); |
2390 |
> |
comprintf("\tforget_about(scratchie);\n"); |
2391 |
> |
/* And create the flags (preserve X flag if shift count is zero) */ |
2392 |
> |
switch (curi->size) { |
2393 |
> |
case sz_byte: comprintf("\tshrl_l_ri(cdata,7);\n"); break; |
2394 |
> |
case sz_word: comprintf("\tshrl_l_ri(cdata,15);\n"); break; |
2395 |
> |
case sz_long: comprintf("\tshrl_l_ri(cdata,31);\n"); break; |
2396 |
|
} |
2397 |
< |
comprintf("test_l_ri(tmpcnt,highmask);\n" |
2398 |
< |
"mov_l_ri(scratchie,0);\n" |
2370 |
< |
"cmov_l_rr(cdata,scratchie,5);\n"); |
2371 |
< |
/* And create the flags */ |
2397 |
> |
comprintf("\ttest_l_ri(cnt,63);\n" |
2398 |
> |
"\tcmov_l_rr(FLAGX,cdata,NATIVE_CC_NE);\n"); |
2399 |
|
comprintf("\tstart_needflags();\n"); |
2400 |
|
comprintf("\tif (needed_flags & FLAG_ZNV)\n"); |
2401 |
|
switch(curi->size) { |
2402 |
< |
case sz_byte: comprintf("\t test_b_rr(data,data);\n"); |
2403 |
< |
comprintf("\t bt_l_ri(cdata,7);\n"); break; |
2404 |
< |
case sz_word: comprintf("\t test_w_rr(data,data);\n"); |
2378 |
< |
comprintf("\t bt_l_ri(cdata,15);\n"); break; |
2379 |
< |
case sz_long: comprintf("\t test_l_rr(data,data);\n"); |
2380 |
< |
comprintf("\t bt_l_ri(cdata,31);\n"); break; |
2402 |
> |
case sz_byte: comprintf("\t test_b_rr(data,data);\n"); break; |
2403 |
> |
case sz_word: comprintf("\t test_w_rr(data,data);\n"); break; |
2404 |
> |
case sz_long: comprintf("\t test_l_rr(data,data);\n"); break; |
2405 |
|
} |
2406 |
+ |
comprintf("\t bt_l_ri(cdata,0);\n"); |
2407 |
|
comprintf("\t live_flags();\n"); |
2408 |
|
comprintf("\t end_needflags();\n"); |
2384 |
– |
comprintf("\t duplicate_carry();\n"); |
2409 |
|
comprintf("if (!(needed_flags & FLAG_CZNV)) dont_care_flags();\n"); |
2410 |
|
genastore ("data", curi->dmode, "dstreg", curi->size, "data"); |
2411 |
|
} |
2774 |
|
static void |
2775 |
|
generate_one_opcode (int rp, int noflags) |
2776 |
|
{ |
2753 |
– |
int i; |
2777 |
|
uae_u16 smsk, dmsk; |
2778 |
< |
long int opcode = opcode_map[rp]; |
2778 |
> |
const long int opcode = opcode_map[rp]; |
2779 |
> |
const char *opcode_str; |
2780 |
|
int aborted=0; |
2781 |
|
int have_srcreg=0; |
2782 |
|
int have_dstreg=0; |
2785 |
|
|| table68k[opcode].clev > cpu_level) |
2786 |
|
return; |
2787 |
|
|
2764 |
– |
for (i = 0; lookuptab[i].name[0]; i++) |
2765 |
– |
{ |
2766 |
– |
if (table68k[opcode].mnemo == lookuptab[i].mnemo) |
2767 |
– |
break; |
2768 |
– |
} |
2769 |
– |
|
2788 |
|
if (table68k[opcode].handler != -1) |
2789 |
|
return; |
2790 |
|
|
2936 |
|
comprintf("\tuae_u32 m68k_pc_offset_thisinst=m68k_pc_offset;\n"); |
2937 |
|
comprintf("\tm68k_pc_offset+=2;\n"); |
2938 |
|
|
2939 |
+ |
opcode_str = get_instruction_string (opcode); |
2940 |
+ |
|
2941 |
|
aborted=gen_opcode (opcode); |
2942 |
|
{ |
2943 |
|
int flags=0; |
2951 |
|
comprintf ("}\n"); |
2952 |
|
|
2953 |
|
if (aborted) { |
2954 |
< |
fprintf (stblfile, "{ NULL, 0x%08x, %ld }, /* %s */\n", flags, opcode, lookuptab[i].name); |
2954 |
> |
fprintf (stblfile, "{ NULL, 0x%08x, %ld }, /* %s */\n", flags, opcode, opcode_str); |
2955 |
|
com_discard(); |
2956 |
|
} |
2957 |
|
else { |
2958 |
|
if (noflags) { |
2959 |
< |
fprintf (stblfile, "{ op_%lx_%d_comp_nf, 0x%08x, %ld }, /* %s */\n", opcode, postfix, flags, opcode, lookuptab[i].name); |
2959 |
> |
fprintf (stblfile, "{ op_%lx_%d_comp_nf, 0x%08x, %ld }, /* %s */\n", opcode, postfix, flags, opcode, opcode_str); |
2960 |
|
fprintf (headerfile, "extern compop_func op_%lx_%d_comp_nf;\n", opcode, postfix); |
2961 |
< |
printf ("void REGPARAM2 op_%lx_%d_comp_nf(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name); |
2961 |
> |
printf ("void REGPARAM2 op_%lx_%d_comp_nf(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, opcode_str); |
2962 |
|
} |
2963 |
|
else { |
2964 |
< |
fprintf (stblfile, "{ op_%lx_%d_comp_ff, 0x%08x, %ld }, /* %s */\n", opcode, postfix, flags, opcode, lookuptab[i].name); |
2964 |
> |
fprintf (stblfile, "{ op_%lx_%d_comp_ff, 0x%08x, %ld }, /* %s */\n", opcode, postfix, flags, opcode, opcode_str); |
2965 |
|
fprintf (headerfile, "extern compop_func op_%lx_%d_comp_ff;\n", opcode, postfix); |
2966 |
< |
printf ("void REGPARAM2 op_%lx_%d_comp_ff(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name); |
2966 |
> |
printf ("void REGPARAM2 op_%lx_%d_comp_ff(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, opcode_str); |
2967 |
|
} |
2968 |
|
com_flush(); |
2969 |
|
} |
3071 |
|
free (table68k); |
3072 |
|
fclose (stblfile); |
3073 |
|
fclose (headerfile); |
3074 |
+ |
fflush (stdout); |
3075 |
|
return 0; |
3076 |
|
} |