From 92ad76792ffc919a8b63d7abce55fb3046cf9f4e Mon Sep 17 00:00:00 2001 From: julianb0 Date: Thu, 13 Jun 2019 15:32:24 +0200 Subject: [PATCH] string instrs doc --- vm/in/INSTRS | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ vm/in/string.c | 24 ++++++++++++++++++++++ vm/pc/decd.c | 17 ++++++++++++--- 3 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 vm/in/string.c diff --git a/vm/in/INSTRS b/vm/in/INSTRS index b947993..66d5bea 100644 --- a/vm/in/INSTRS +++ b/vm/in/INSTRS @@ -380,6 +380,62 @@ leave # String manipulation instructions # #---------------------------------------------------------------------------# +# +# Store value into string (STOSx) +# +# [%str] = $val +# IF (DF == 0) THEN +# %str = %str + sizeof(x) +# ELSE +# %str = %str - sizeof(x) +# FI +# +# When no parameters are given, %str = RDI and $val = RAX +# When one parameter is given, %str = RDI and $val = $1 +# When two parameters are given, %str = $1 and $val = $2 +# +stosb +stosb rim +stosb r rim + +# +# Load value from string (LODSx) +# +# %dest = [%str] +# IF (DF == 0) THEN +# %str = %str + sizeof(x) +# ELSE +# %str = %str - sizeof(x) +# FI +# +# When no parameters are given, %str = RDI and %dest = RAX +# When one parameter is given, %str = RDI and %dest = $1 +# When two parameters are given, %str = $2 and %dest = $1 +# +lodsb +lodsb r +lodsb rm r + +# +# Move value from string to string (MOVSx) +# +# [%str1] = [%str2] +# IF (DF == 0) THEN +# %str1 = %str1 + sizeof(x) +# %str2 = %str2 + sizeof(x) +# ELSE +# %str1 = %str1 - sizeof(x) +# %str2 = %str2 - sizeof(x) +# FI +# +# When no parameters are given, %str1 = RDI and %str2 = RSI +# When one parameter is given, %str1 = RDI and %str2 = $1 +# When two parameters are given, %str1 = $1 and %str2 = $2 +# +movsb +movsb r +movsb r r + #---------------------------------------------------------------------------# # Supervisor only instructions # #---------------------------------------------------------------------------# diff --git a/vm/in/string.c b/vm/in/string.c new file mode 100644 index 0000000..f355502 --- /dev/null +++ b/vm/in/string.c @@ -0,0 +1,24 @@ +// The OS/K Team licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include + +//----------------------------------------------------------------------------// + +IMPL_START_0(stosb) +{ +} +IMPL_END; + +IMPL_START_0(lodsb) +{ +} +IMPL_END; + +IMPL_START_0(movsb) +{ +} +IMPL_END; + +//----------------------------------------------------------------------------// + diff --git a/vm/pc/decd.c b/vm/pc/decd.c index c93d024..4bb48cb 100644 --- a/vm/pc/decd.c +++ b/vm/pc/decd.c @@ -304,11 +304,15 @@ void exec_instr(ctx_t *ctx, // Debugging dump_instr(ctx, in, p1, p2, lock, rep, cond, pc); -do_rep: - - if (!eval_cond(ctx, cond)) + // + // For REPs we evaluate the condition AFTER running the instruction, + // in a do ... while(cond) fashion + // + if (!rep && !eval_cond(ctx, cond)) return; +do_rep: + out = in->func(ctx, p1, p2, &r1, &r2); if (out) @@ -343,6 +347,13 @@ do_rep: if (rep && rcx > 0) { + // RCX remains untouched when condition fails + if (!eval_cond(ctx, cond)) + return; + + // Show that we're REP'ing + dump_instr(ctx, in, p1, p2, lock, rep, cond, pc); + rcx--; goto do_rep; }