From 1796933c0743cd3c332e01c162bd3ddf5f004b19 Mon Sep 17 00:00:00 2001 From: Steffen Winterfeldt Date: Mon, 27 Jan 2020 18:20:16 +0100 Subject: [PATCH] add (i)mul tests --- test/0021_imul_b.done | 2 +- test/0022_imul_w.done | 4 +- test/0037_imul.done | 66 ++++++++++++++++++++++ test/0037_imul.tst | 127 ++++++++++++++++++++++++++++++++++++++++++ test/0038_mul.done | 66 ++++++++++++++++++++++ test/0038_mul.tst | 127 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 389 insertions(+), 3 deletions(-) create mode 100644 test/0037_imul.done create mode 100644 test/0037_imul.tst create mode 100644 test/0038_mul.done create mode 100644 test/0038_mul.tst diff --git a/test/0021_imul_b.done b/test/0021_imul_b.done index 4d044cd..f0ee265 100644 --- a/test/0021_imul_b.done +++ b/test/0021_imul_b.done @@ -3,7 +3,7 @@ 00001000: 6b d9 07 9c 6b d6 cb 9c 6b 05 66 9c 66 6b ee 26 00001010: 9c 66 6b f3 cf 9c 66 6b 4d 02 b9 9c f4 00020100: ef 7f e7 26 c7 0d -0003fff0: 03 08 03 08 03 08 03 08 03 08 03 08 +0003fff0: 03 08 83 08 03 08 87 08 87 08 87 08 ; - - registers msr[0010] 000000000000000d ; tsc diff --git a/test/0022_imul_w.done b/test/0022_imul_w.done index 666c753..c53f8ec 100644 --- a/test/0022_imul_w.done +++ b/test/0022_imul_w.done @@ -4,7 +4,7 @@ 00001010: 69 ee 61 0a b2 79 9c 66 69 f3 1c 2d fa d6 9c 66 00001020: 69 4d 02 a6 cf af 94 9c f4 00020100: f0 fc 99 1d d4 7d -0003fff0: 03 08 03 08 03 08 03 08 03 08 03 08 +0003fff0: 87 08 87 08 83 08 03 08 83 08 07 08 ; - - registers msr[0010] 000000000000000d ; tsc @@ -26,5 +26,5 @@ gs=0000 gs.base=00000000 gs.limit=0000ffff gs.acc=0093 eax=555766d0 ebx=f82012b2 ecx=cb10e836 edx=71a3da1f esi=d49f5578 edi=00000100 ebp=e37c6cf7 esp=0000fff4 -eip=00000029 eflags=00000803 ; of cf +eip=00000029 eflags=00000887 ; of sf pf cf diff --git a/test/0037_imul.done b/test/0037_imul.done new file mode 100644 index 0000000..bef0e64 --- /dev/null +++ b/test/0037_imul.done @@ -0,0 +1,66 @@ +; - - memory +; 0 1 2 3 4 5 6 7 8 9 a b c d e f +00002000: 66 31 ff be 90 20 66 31 c0 66 8b 04 66 8b 4c 04 +00002010: 66 f7 e9 66 3b 44 08 75 6b 66 3b 54 0c 75 65 66 +00002020: 9c 66 8f 44 10 66 47 83 c6 14 81 fe 30 21 72 d6 +00002030: be 30 21 66 31 c0 66 8b 04 66 8b 4c 04 f7 e9 3b +00002040: 44 08 75 40 3b 54 0a 75 3b 66 9c 66 8f 44 10 66 +00002050: 47 83 c6 14 81 fe d0 21 72 d9 be d0 21 66 31 c0 +00002060: 66 8b 04 66 8b 4c 04 f6 e9 3a 44 08 75 16 3a 64 +00002070: 09 75 11 66 9c 66 8f 44 10 66 47 83 c6 14 81 fe +00002080: 70 22 72 d9 66 57 f4 00 00 00 00 00 00 00 00 00 +00002090: 00 00 00 00 0b 00 00 00 00 00 00 00 00 00 00 00 +000020a0: 46 00 00 00 39 00 00 00 f5 ff ff ff 8d fd ff ff +000020b0: ff ff ff ff 46 00 00 00 46 32 00 00 49 00 00 00 +000020c0: f6 55 0e 00 00 00 00 00 46 00 00 00 73 23 a1 00 +000020d0: 0f 00 00 00 bd 13 71 09 00 00 00 00 46 00 00 00 +000020e0: 00 00 00 80 e3 00 00 00 00 00 00 80 8e ff ff ff +000020f0: 46 00 00 00 00 00 00 80 1d ff ff ff 00 00 00 80 +00002100: 71 00 00 00 46 00 00 00 82 ae 9d 24 bc 1d 43 07 +00002110: 78 e1 96 fa 4a e9 09 01 46 00 00 00 0f d0 40 a1 +00002120: ac 76 df d2 14 b4 83 c2 26 a6 b3 10 46 00 00 00 +00002130: 00 00 00 00 0c 00 00 00 00 00 00 00 00 00 00 00 +00002140: 46 00 00 00 4f 00 00 00 0c 00 00 00 b4 03 00 00 +00002150: 00 00 00 00 46 00 00 00 a9 22 00 00 eb ff ff ff +00002160: 23 28 fd ff ff ff ff ff 46 00 00 00 e3 7a 00 00 +00002170: 11 25 00 00 13 f8 ca 11 00 00 00 00 46 00 00 00 +00002180: 00 80 ff ff 6c 03 00 00 00 00 4a fe ff ff ff ff +00002190: 46 00 00 00 00 80 ff ff 01 f3 ff ff 00 80 7f 06 +000021a0: 00 00 00 00 46 00 00 00 93 31 00 00 da 49 00 00 +000021b0: 2e 22 4d 0e 00 00 00 00 46 00 00 00 f9 b1 ff ff +000021c0: 03 8e ff ff eb 33 be 22 00 00 00 00 46 00 00 00 +000021d0: 00 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 +000021e0: 46 00 00 00 39 00 00 00 03 00 00 00 ab 00 00 00 +000021f0: 00 00 00 00 46 00 00 00 40 00 00 00 02 00 00 00 +00002200: 80 00 00 00 00 00 00 00 46 00 00 00 c0 ff ff ff +00002210: 02 00 00 00 80 ff ff ff ff ff ff ff 46 00 00 00 +00002220: 80 ff ff ff 4c 00 00 00 00 da ff ff ff ff ff ff +00002230: 46 00 00 00 80 ff ff ff db ff ff ff 80 12 00 00 +00002240: 00 00 00 00 46 00 00 00 33 00 00 00 4a 00 00 00 +00002250: be 0e 00 00 00 00 00 00 46 00 00 00 b9 ff ff ff +00002260: 8f ff ff ff 57 1f 00 00 00 00 00 00 46 00 00 00 +00002270: f4 +0000fff0: 18 00 00 00 + +; - - registers +msr[0010] 0000000000000156 ; tsc + +cr0=00000000 cr1=00000000 cr2=00000000 cr3=00000000 cr4=00000000 +dr0=00000000 dr1=00000000 dr2=00000000 dr3=00000000 dr6=00000000 dr7=00000000 + +gdt.base=00000000 gdt.limit=ffff +idt.base=00001000 idt.limit=ffff +tr=0000 tr.base=00000000 tr.limit=00000000 tr.acc=0000 +ldt=0000 ldt.base=00000000 ldt.limit=00000000 ldt.acc=0000 + +cs=0000 cs.base=00000000 cs.limit=0000ffff cs.acc=009b +ss=0000 ss.base=00000000 ss.limit=0000ffff ss.acc=0093 +ds=0000 ds.base=00000000 ds.limit=0000ffff ds.acc=0093 +es=0000 es.base=00000000 es.limit=0000ffff es.acc=0093 +fs=0000 fs.base=00000000 fs.limit=0000ffff fs.acc=0093 +gs=0000 gs.base=00000000 gs.limit=0000ffff gs.acc=0093 + +eax=ffff1f57 ebx=00000000 ecx=ffffff8f edx=10b322be +esi=00002270 edi=00000018 ebp=00000000 esp=0000fffc +eip=00002087 eflags=00000046 ; zf pf + diff --git a/test/0037_imul.tst b/test/0037_imul.tst new file mode 100644 index 0000000..7dafa3c --- /dev/null +++ b/test/0037_imul.tst @@ -0,0 +1,127 @@ +; test 8, 16, 32 bit (signed) imul +; +; note: the number of successful tests is returned on the stack +; + +[init mode=real] + +idt.base=0x1000 + +[code start=0x0:0x2000] + +%macro imul_32 2 + dd %1 + dd %2 + dq (%1) * (%2) + dd 0 +%endmacro + +%macro imul_16 2 + dd %1 + dd %2 + dq ((%1) %% 0x10000) * ((%2) %% 0x10000) + dd 0 +%endmacro + +%macro imul_8 2 + dd %1 + dd %2 + dq ((%1) %% 0x100) * ((%2) %% 0x100) + dd 0 +%endmacro + + xor edi,edi + + ; 32 bit + mov si,table_start_32 +mul_10: + xor eax,eax + mov eax,[si] + mov ecx,[si+4] + imul ecx + cmp eax,[si+8] + jnz stop + cmp edx,[si+12] + jnz stop + pushfd + pop dword [si+16] + inc edi + add si,20 + cmp si,table_end_32 + jb mul_10 + + ; 16 bit + mov si,table_start_16 +mul_20: + xor eax,eax + mov eax,[si] + mov ecx,[si+4] + imul cx + cmp ax,[si+8] + jnz stop + cmp dx,[si+10] + jnz stop + pushfd + pop dword [si+16] + inc edi + add si,20 + cmp si,table_end_16 + jb mul_20 + + ; 8 bit + mov si,table_start_8 +mul_30: + xor eax,eax + mov eax,[si] + mov ecx,[si+4] + imul cl + cmp al,[si+8] + jnz stop + cmp ah,[si+9] + jnz stop + pushfd + pop dword [si+16] + inc edi + add si,20 + cmp si,table_end_8 + jb mul_30 + + +stop: + push edi + hlt + + align 0x10, db 0 + +table_start_32: + imul_32 0, 11 + imul_32 57, -11 + imul_32 0x3246, 73 + imul_32 0xa12373, 15 + imul_32 -0x80000000, 227 + imul_32 -0x80000000, -227 + imul_32 0x249dae82, 0x07431dbc + imul_32 -0x5ebf2ff1, -0x2d208954 +table_end_32: + +table_start_16: + imul_16 0, 12 + imul_16 79, 12 + imul_16 0x22a9, -21 + imul_16 0x7ae3, 0x2511 + imul_16 -0x8000, 876 + imul_16 -0x8000, -3327 + imul_16 0x3193, 0x49da + imul_16 -0x4e07,-0x71fd +table_end_16: + +table_start_8: + imul_8 0, 17 + imul_8 57, 3 + imul_8 0x40, 2 + imul_8 -0x40, 2 + imul_8 -0x80, 76 + imul_8 -0x80, -37 + imul_16 0x33, 0x4a + imul_16 -0x47,-0x71 +table_end_8: diff --git a/test/0038_mul.done b/test/0038_mul.done new file mode 100644 index 0000000..f5bd49d --- /dev/null +++ b/test/0038_mul.done @@ -0,0 +1,66 @@ +; - - memory +; 0 1 2 3 4 5 6 7 8 9 a b c d e f +00002000: 66 31 ff be 90 20 66 31 c0 66 8b 04 66 8b 4c 04 +00002010: 66 f7 e1 66 3b 44 08 75 6b 66 3b 54 0c 75 65 66 +00002020: 9c 66 8f 44 10 66 47 83 c6 14 81 fe 30 21 72 d6 +00002030: be 30 21 66 31 c0 66 8b 04 66 8b 4c 04 f7 e1 3b +00002040: 44 08 75 40 3b 54 0a 75 3b 66 9c 66 8f 44 10 66 +00002050: 47 83 c6 14 81 fe d0 21 72 d9 be d0 21 66 31 c0 +00002060: 66 8b 04 66 8b 4c 04 f6 e1 3a 44 08 75 16 3a 64 +00002070: 09 75 11 66 9c 66 8f 44 10 66 47 83 c6 14 81 fe +00002080: 70 22 72 d9 66 57 f4 00 00 00 00 00 00 00 00 00 +00002090: 00 00 00 00 0b 00 00 00 00 00 00 00 00 00 00 00 +000020a0: 46 00 00 00 39 00 00 00 0b 00 00 00 73 02 00 00 +000020b0: 00 00 00 00 46 00 00 00 46 92 00 00 49 00 00 00 +000020c0: f6 b5 29 00 00 00 00 00 46 00 00 00 73 23 a1 00 +000020d0: 0f 00 00 00 bd 13 71 09 00 00 00 00 46 00 00 00 +000020e0: 00 00 00 80 e3 00 00 00 00 00 00 80 71 00 00 00 +000020f0: 46 00 00 00 ff ff ff ff e3 00 00 00 1d ff ff ff +00002100: e2 00 00 00 46 00 00 00 82 ae 9d e4 bc 1d 43 f7 +00002110: 78 e1 96 da 31 13 d0 dc 46 00 00 00 f1 2f bf 2e +00002120: 54 89 20 ed 14 b4 83 c2 5b f0 4c 2b 46 00 00 00 +00002130: 00 00 00 00 0c 00 00 00 00 00 00 00 00 00 00 00 +00002140: 46 00 00 00 4f 00 00 00 0c 00 00 00 b4 03 00 00 +00002150: 00 00 00 00 46 00 00 00 a9 22 00 00 15 00 00 00 +00002160: dd d7 02 00 00 00 00 00 46 00 00 00 e3 ba 00 00 +00002170: 11 25 00 00 13 38 0f 1b 00 00 00 00 46 00 00 00 +00002180: 00 80 00 00 6c 03 00 00 00 00 b6 01 00 00 00 00 +00002190: 46 00 00 00 ff ff 00 00 ff 0c 00 00 01 f3 fe 0c +000021a0: 00 00 00 00 46 00 00 00 93 f1 00 00 da a9 00 00 +000021b0: 2e c2 47 a0 00 00 00 00 46 00 00 00 07 9e 00 00 +000021c0: fd 71 00 00 eb 43 5d 46 00 00 00 00 46 00 00 00 +000021d0: 00 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 +000021e0: 46 00 00 00 39 00 00 00 03 00 00 00 ab 00 00 00 +000021f0: 00 00 00 00 46 00 00 00 40 00 00 00 02 00 00 00 +00002200: 80 00 00 00 00 00 00 00 46 00 00 00 80 00 00 00 +00002210: 80 00 00 00 00 40 00 00 00 00 00 00 46 00 00 00 +00002220: 80 00 00 00 4c 00 00 00 00 26 00 00 00 00 00 00 +00002230: 46 00 00 00 ff 00 00 00 25 00 00 00 db 24 00 00 +00002240: 00 00 00 00 46 00 00 00 93 00 00 00 4a 00 00 00 +00002250: 7e 2a 00 00 00 00 00 00 46 00 00 00 f7 00 00 00 +00002260: e1 00 00 00 17 d9 00 00 00 00 00 00 46 00 00 00 +00002270: f4 +0000fff0: 18 00 00 00 + +; - - registers +msr[0010] 0000000000000156 ; tsc + +cr0=00000000 cr1=00000000 cr2=00000000 cr3=00000000 cr4=00000000 +dr0=00000000 dr1=00000000 dr2=00000000 dr3=00000000 dr6=00000000 dr7=00000000 + +gdt.base=00000000 gdt.limit=ffff +idt.base=00001000 idt.limit=ffff +tr=0000 tr.base=00000000 tr.limit=00000000 tr.acc=0000 +ldt=0000 ldt.base=00000000 ldt.limit=00000000 ldt.acc=0000 + +cs=0000 cs.base=00000000 cs.limit=0000ffff cs.acc=009b +ss=0000 ss.base=00000000 ss.limit=0000ffff ss.acc=0093 +ds=0000 ds.base=00000000 ds.limit=0000ffff ds.acc=0093 +es=0000 es.base=00000000 es.limit=0000ffff es.acc=0093 +fs=0000 fs.base=00000000 fs.limit=0000ffff fs.acc=0093 +gs=0000 gs.base=00000000 gs.limit=0000ffff gs.acc=0093 + +eax=0000d917 ebx=00000000 ecx=000000e1 edx=2b4c465d +esi=00002270 edi=00000018 ebp=00000000 esp=0000fffc +eip=00002087 eflags=00000046 ; zf pf + diff --git a/test/0038_mul.tst b/test/0038_mul.tst new file mode 100644 index 0000000..fd469c7 --- /dev/null +++ b/test/0038_mul.tst @@ -0,0 +1,127 @@ +; test 8, 16, 32 bit (unsigned) mul +; +; note: the number of successful tests is returned on the stack +; + +[init mode=real] + +idt.base=0x1000 + +[code start=0x0:0x2000] + +%macro mul_32 2 + dd %1 + dd %2 + dq (%1) * (%2) + dd 0 +%endmacro + +%macro mul_16 2 + dd %1 + dd %2 + dq ((%1) % 0x10000) * ((%2) % 0x10000) + dd 0 +%endmacro + +%macro mul_8 2 + dd %1 + dd %2 + dq ((%1) % 0x100) * ((%2) % 0x100) + dd 0 +%endmacro + + xor edi,edi + + ; 32 bit + mov si,table_start_32 +mul_10: + xor eax,eax + mov eax,[si] + mov ecx,[si+4] + mul ecx + cmp eax,[si+8] + jnz stop + cmp edx,[si+12] + jnz stop + pushfd + pop dword [si+16] + inc edi + add si,20 + cmp si,table_end_32 + jb mul_10 + + ; 16 bit + mov si,table_start_16 +mul_20: + xor eax,eax + mov eax,[si] + mov ecx,[si+4] + mul cx + cmp ax,[si+8] + jnz stop + cmp dx,[si+10] + jnz stop + pushfd + pop dword [si+16] + inc edi + add si,20 + cmp si,table_end_16 + jb mul_20 + + ; 8 bit + mov si,table_start_8 +mul_30: + xor eax,eax + mov eax,[si] + mov ecx,[si+4] + mul cl + cmp al,[si+8] + jnz stop + cmp ah,[si+9] + jnz stop + pushfd + pop dword [si+16] + inc edi + add si,20 + cmp si,table_end_8 + jb mul_30 + + +stop: + push edi + hlt + + align 0x10, db 0 + +table_start_32: + mul_32 0, 11 + mul_32 57, 11 + mul_32 0x9246, 73 + mul_32 0xa12373, 15 + mul_32 0x80000000, 227 + mul_32 0xffffffff, 227 + mul_32 0xe49dae82, 0xf7431dbc + mul_32 0x2ebf2ff1, 0xed208954 +table_end_32: + +table_start_16: + mul_16 0, 12 + mul_16 79, 12 + mul_16 0x22a9, 21 + mul_16 0xbae3, 0x2511 + mul_16 0x8000, 876 + mul_16 0xffff, 3327 + mul_16 0xf193, 0xa9da + mul_16 0x9e07, 0x71fd +table_end_16: + +table_start_8: + mul_8 0, 17 + mul_8 57, 3 + mul_8 0x40, 2 + mul_8 0x80, 0x80 + mul_8 0x80, 76 + mul_8 0xff, 37 + mul_16 0x93, 0x4a + mul_16 0xf7, 0xe1 +table_end_8: