1
0
mirror of https://gitlab.os-k.eu/os-k-team/kvisc.git synced 2023-08-25 14:05:46 +02:00

Merge branch 'master' of github.com:os-k-team/k-arch

This commit is contained in:
Adrien Bourmault 2019-06-13 17:52:00 +02:00
commit 1dcad85a9c
No known key found for this signature in database
GPG Key ID: A5DDB5F18A6654E6
6 changed files with 83 additions and 20 deletions

View File

@ -323,7 +323,6 @@ pconds = {
}
def get_cond_mask(cond, line):
mask = 0
if cond[0] == 'n':
@ -393,6 +392,13 @@ def parse_instr(line):
# Word 2 (rep|cond|ft1|ft2)
w2 = 0
if '.' in instr:
w2 |= get_cond_mask(instr.split('.', 1)[1], line)
instr = instr.split('.', 1)[0]
else:
instr = instr
if instr == "rep":
if params == None:
print("Missing instruction after rep prefix: {}".format(line))
@ -400,15 +406,14 @@ def parse_instr(line):
sys.exit(1)
w2 |= 0x8000 # 16th bit
instr, params = params.split(' ', 1)
if '.' in instr:
w2 |= get_cond_mask(instr.split('.', 1)[1], line)
instr_name = instr.split('.', 1)[0]
else:
instr_name = instr
if len(params.split(' ', 1)) == 2:
instr, params = params.split(' ', 1)
else:
instr = params.split(' ', 1)[0]
params = None
instr_name = instr
instr_args = ''
if params == None or len(params) == 0:

View File

@ -15,6 +15,12 @@ _start:
stop
jmp .1
;
; Essential definitions
;
CHAR_MAX := 0x7F
INT_MAX := 0x7FFF
;
; Include librairies
;

View File

@ -5,6 +5,26 @@
; Main function
;
main:
cld
mov rcx, 11
mov rax, 33
mov rdi, .buf
mov rsi, .buf
rep stosb
mov rbx, rdi
sub rbx, rsi
mov ax0, .buf
mov ax1, 12
call print_n
ret
.str1 = "Hello World!\n"
.buf = [32]
movzx_test:
enter 1
mov q[rsp], 0xFABC1234CCCCDDDD

View File

@ -1,9 +0,0 @@
TODO
sal, sar
imul, idiv
Flags for shl, shr, mul, div
Useful: https://www.felixcloutier.com/x86

View File

@ -31,7 +31,7 @@ void stos_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
else {
reg = RDI;
val = R(rax);
val = rax;
}
writemem(ctx, val, R(reg), len);
@ -45,6 +45,24 @@ IMPL_START_0(stosb)
}
IMPL_END;
IMPL_START_0(stosw)
{
stos_impl(ctx, p1, p2, 2);
}
IMPL_END;
IMPL_START_0(stosl)
{
stos_impl(ctx, p1, p2, 4);
}
IMPL_END;
IMPL_START_0(stosq)
{
stos_impl(ctx, p1, p2, 8);
}
IMPL_END;
//----------------------------------------------------------------------------//
void lods_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
@ -75,6 +93,24 @@ IMPL_START_0(lodsb)
}
IMPL_END;
IMPL_START_0(lodsw)
{
lods_impl(ctx, p1, p2, 2);
}
IMPL_END;
IMPL_START_0(lodsl)
{
lods_impl(ctx, p1, p2, 4);
}
IMPL_END;
IMPL_START_0(lodsq)
{
lods_impl(ctx, p1, p2, 8);
}
IMPL_END;
//----------------------------------------------------------------------------//
IMPL_START_0(scasb)

View File

@ -345,16 +345,21 @@ do_rep:
}
}
if (rep && rcx > 0)
if (rep)
{
// RCX remains untouched when condition fails
if (!eval_cond(ctx, cond))
return;
if (rcx > 0)
rcx--;
if (rcx == 0)
return;
// Show that we're REP'ing
dump_instr(ctx, in, p1, p2, lock, rep, cond, pc);
rcx--;
goto do_rep;
}
}