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

617 lines
12 KiB
Plaintext
Raw Normal View History

2019-05-30 12:44:56 +02:00
# The OS/K Team licenses this file to you under the MIT license.
2019-05-15 21:56:42 +02:00
# See the LICENSE file in the project root for more information.
2019-05-15 21:47:08 +02:00
2019-06-07 13:43:03 +02:00
#---------------------------------------------------------------------------#
# Special instructions #
#---------------------------------------------------------------------------#
#
# Initiate machine shutdown (STOP)
#
# THROW #SHT
#
# Throws:
# #SYS if not in supervisor mode
# #ILL if disabled through DV
# #SHT otherwise
#
2019-05-22 18:39:46 +02:00
stop
2019-05-16 10:03:01 +02:00
2019-06-07 13:38:34 +02:00
#---------------------------------------------------------------------------#
# Logical instructions #
#---------------------------------------------------------------------------#
2019-05-16 18:45:00 +02:00
#
2019-06-07 13:38:34 +02:00
# Bitwise NOT operation
#
# $1 = NOT($1)
#
# Preserves all flags
2019-05-16 18:45:00 +02:00
#
2019-06-12 15:30:35 +02:00
not rm
2019-06-07 13:38:34 +02:00
#
# Bitwise OR operation
#
# $1 = $1 OR $2
#
# Clears OF and CF
# Sets ZF and SF according to the result
#
2019-06-12 15:30:35 +02:00
or rm rim
orf rm rim
2019-06-07 13:38:34 +02:00
#
# Bitwise AND operation
#
# $1 = $1 AND $2
#
# Clears OF and CF
# Sets ZF and SF according to the result
#
2019-06-12 15:30:35 +02:00
and rm rim
andf rm rim
2019-06-07 13:38:34 +02:00
#
# Bitwise XOR operation
#
# $1 = $1 XOR $2
#
# Clears OF and CF
# Sets ZF and SF according to the result
#
2019-06-12 15:30:35 +02:00
xor rm rim
xorf rm rim
2019-06-07 13:38:34 +02:00
2019-06-07 13:43:03 +02:00
# To document
2019-06-12 15:30:35 +02:00
shl rm rim
shr rm rim
shlf rm rim
shrf rm rim
2019-05-30 20:27:11 +02:00
2019-06-07 13:38:34 +02:00
#---------------------------------------------------------------------------#
# Arithmetic instructions #
#---------------------------------------------------------------------------#
2019-05-16 18:45:00 +02:00
#
2019-06-07 13:38:34 +02:00
# Arithmetical SGN operation
2019-05-16 18:45:00 +02:00
#
2019-06-07 13:38:34 +02:00
# IF ($1 == 0) THEN
# $2 = 0
# ELIF ($1 GT 0) THEN
# $2 = 1
# ELSE
# $2 = LONG_MIN
# FI
#
# Treats $1 and $2 as signed values
# Sets ZF and SF according to the result
#
2019-06-12 15:30:35 +02:00
sgn rm rim
sgnf rm rim
2019-05-16 18:45:00 +02:00
2019-06-07 13:38:34 +02:00
#
# Arithmetical NEG operation
#
# $1 = NOT($1) + 1
#
# Sets CF if $1 == 0; clears it otherwise
# Sets OF if $1 == $LONG_MIN; clears it otherwise
# Sets ZF and SF according to the result
#
2019-06-12 15:30:35 +02:00
neg rm
negf rm
2019-06-07 13:38:34 +02:00
#
# Arithmetical INC operation
#
# $1 = $1 + 1
#
# Preserves CF
# Sets OF if $1 == $LONG_MAX, clears it otherwise
# Sets ZF and SF according to the result
#
2019-06-12 15:30:35 +02:00
inc rm
incf rm
2019-06-07 13:38:34 +02:00
#
# Arithmetical DEC operation
#
# $1 = $1 - 1
#
# Preserves CF
# Sets OF if $1 == $LONG_MIN, clears it otherwise
# Sets ZF and SF according to the result
#
2019-06-12 15:30:35 +02:00
dec rm
decf rm
2019-06-07 13:38:34 +02:00
#
# Arithmetical ADD operation
#
# $1 = $1 + $2
#
# Sets CF if unsigned integer overflow occur, clears it otherwise
# Sets OF is signed integer overflow occur, clears it otherwise
# Sets ZF and SF according to the result
#
2019-06-12 15:30:35 +02:00
add rm rim
addf rm rim
2019-06-07 13:38:34 +02:00
#
# Arithmetical SUB operation
#
# $1 = $1 - $2
#
# Sets CF if unsigned integer overflow occur, clears it otherwise
# Sets OF is signed integer overflow occur, clears it otherwise
# Sets ZF and SF according to the result
#
2019-06-12 15:30:35 +02:00
sub rm rim
subf rm rim
2019-06-07 13:38:34 +02:00
#
# Arithmetical unsigned MUL operation
#
# $1 = LO($1 * $2)
#
# Sets CF and OF if HI($1 * $2) > 0, clears them otherwise
# Preserves ZF and SF
#
2019-06-12 15:30:35 +02:00
mul rm rim
mulf rm rim
2019-06-07 13:38:34 +02:00
#
# Arithmetical unsigned DIV operation
#
# $1 = $1 DIV $2
#
# Preserves all flags
#
2019-06-12 15:30:35 +02:00
div rm rim
2019-06-07 13:38:34 +02:00
#
# Arithmetical unsigned MOD operation
#
# $1 = $1 MOD $2
#
# Preserves all flags
#
2019-06-12 15:30:35 +02:00
mod rm rim
2019-06-06 14:57:34 +02:00
2019-06-07 13:38:34 +02:00
#
# Arithmetical unsigned 128-bit MUL operation
#
# RDX = HI(RAX * $1)
# RAX = LO(RAX * $1)
#
# Sets CF and OF if HI($1 * $2) > 0, clears them otherwise
# Preserves ZF and SF
#
2019-06-06 22:07:34 +02:00
mul2 rim
2019-06-12 15:30:35 +02:00
mul2f rim
2019-05-30 20:23:27 +02:00
2019-06-07 13:38:34 +02:00
#
# Arithmetical unsigned combined DIV and MOD operations
#
# RDX = (RAX MOD $1)
# RAX = (RAX DIV $1)
#
# Preserves all flags
#
2019-06-06 22:07:34 +02:00
div2 rim
2019-05-31 21:25:56 +02:00
2019-06-07 13:38:34 +02:00
#---------------------------------------------------------------------------#
# Comparison instructions #
#---------------------------------------------------------------------------#
2019-05-16 19:49:51 +02:00
#
2019-06-13 15:47:20 +02:00
# TEST Comparison instruction
2019-05-16 19:49:51 +02:00
#
2019-06-07 13:38:34 +02:00
# $1 AND $2
#
# Clears OF and CF
# Sets ZF and SF according to the result
#
test rim rim
2019-05-16 19:49:51 +02:00
2019-06-07 13:38:34 +02:00
#
2019-06-13 15:47:20 +02:00
# CMP Comparison instruction
2019-06-07 13:38:34 +02:00
#
# $1 - $2
#
# Sets CF if unsigned integer overflow occur, clears it otherwise
# Sets OF is signed integer overflow occur, clears it otherwise
# Sets ZF and SF according to the result
#
2019-06-02 16:33:28 +02:00
cmp rim rim
2019-06-07 13:38:34 +02:00
#---------------------------------------------------------------------------#
# Jump instructions #
#---------------------------------------------------------------------------#
2019-05-16 19:49:51 +02:00
#
2019-06-07 13:38:34 +02:00
# Unconditional jump (JMP) instruction
#
# RIP = CR1 + $1
2019-05-16 19:49:51 +02:00
#
2019-06-12 15:30:35 +02:00
j ri
jmp ri
2019-05-16 19:49:51 +02:00
2019-05-16 18:45:00 +02:00
#
2019-06-07 13:38:34 +02:00
# RCX-dependent jump (LOOP) instruction
#
# IF (RCX > 0) THEN
# RCX = RCX - 1
# RIP = CR1 + $1
# FI
2019-05-16 18:45:00 +02:00
#
2019-06-12 15:30:35 +02:00
loop ri
2019-05-16 18:45:00 +02:00
2019-06-07 13:38:34 +02:00
#---------------------------------------------------------------------------#
# Movement instructions #
#---------------------------------------------------------------------------#
#
# Load Effective Address (LEA) instruction
#
# $1 = ADDR($2)
#
# For instance:
# LEA RAX, [RBX + RCX + 4]
# will result in:
# RAX = RBX + RCX + 4
#
# Preserves all flags
#
2019-06-12 15:30:35 +02:00
lea rm m
2019-06-07 13:38:34 +02:00
#
# Movement (MOV) instruction
#
# $1 = $2
#
2019-06-12 15:30:35 +02:00
mov rm rim
2019-06-07 13:38:34 +02:00
2019-06-13 15:00:48 +02:00
#
# Movement with zero-extension (MOVZX) instruction
#
# $1 = ZeroExtend($2)
#
movzx rm m
2019-06-07 13:38:34 +02:00
#
# Exchange (XCHG) instruction
#
# $_ = $1
# $1 = $2
# $2 = $_
#
2019-06-12 15:30:35 +02:00
xchg rm rim
2019-06-07 13:38:34 +02:00
#
# Compare-and-exchange (CMPXCHG) instruction
#
# IF ($1 == RAX) THEN
# $1 = $2
# ZF = 1
# ELSE
# RAX = $1
# ZF = 0
# FI
#
# Preserves CF, OF and SF
#
2019-06-06 22:07:34 +02:00
cmpxchg rm rim
2019-06-04 19:28:34 +02:00
2019-06-07 13:38:34 +02:00
#---------------------------------------------------------------------------#
# Stack manipulation instructions #
#---------------------------------------------------------------------------#
2019-05-30 20:23:27 +02:00
2019-05-16 18:45:00 +02:00
#
2019-06-07 13:38:34 +02:00
# PUSH value onto stack
#
# RSP = RSP - 8
# *RSP = $1
#
# Throws:
# #STA if RBP MOD 8 > 0
# #STA if RSP MOD 8 > 0
# #STU if RSP > RBP
2019-05-16 18:45:00 +02:00
#
2019-06-12 15:30:35 +02:00
push rim
2019-06-07 13:38:34 +02:00
#
# POP value from stack
#
# $1 = *RSP
# RSP = RSP + 8
#
# Throws:
# #STA if RBP MOD 8 > 0
# #STA if RSP MOD 8 > 0
# #STU if RSP >= RBP
#
2019-06-12 15:30:35 +02:00
pop rm
2019-06-07 13:38:34 +02:00
#
# Unconditional jump with possible return (CALL)
#
# PUSH(RIP)
# JMP(RIP)
#
# Throws:
# See PUSH and JMP
#
2019-06-12 15:30:35 +02:00
call rim
2019-06-07 13:38:34 +02:00
#
# Return to caller (RET)
#
# POP(RIP)
#
# Throws:
# See POP
#
2019-06-12 15:30:35 +02:00
ret
2019-05-16 17:11:22 +02:00
2019-06-07 13:38:34 +02:00
#
# Make new stack frame (ENTER)
#
# PUSH(RBP)
# RBP = RSP
2019-06-12 18:43:24 +02:00
# RSP = RSP - $1
2019-06-07 13:38:34 +02:00
#
# Throws:
# See PUSH
#
2019-05-29 16:57:22 +02:00
enter
2019-06-12 18:43:24 +02:00
enter i
2019-05-29 22:27:49 +02:00
2019-06-07 13:38:34 +02:00
#
# Leave stack frame (LEAVE)
#
2019-06-12 18:43:24 +02:00
# RSP = RBP
# POP(RBP)
2019-06-07 13:38:34 +02:00
#
2019-06-12 15:30:35 +02:00
leave
2019-05-29 16:57:22 +02:00
2019-06-13 15:00:48 +02:00
#---------------------------------------------------------------------------#
# String manipulation instructions #
#---------------------------------------------------------------------------#
2019-06-13 15:32:24 +02:00
#
# 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
#
2019-06-13 16:27:33 +02:00
# When no parameters are given, %dest = RAX and %str = RSI
# When one parameter is given, %dest = $1 and %str = RSI
# When two parameters are given, %dest = $1 and %str = $2
2019-06-13 15:32:24 +02:00
#
lodsb
lodsb r
2019-06-13 16:27:33 +02:00
lodsb r r
2019-06-13 15:32:24 +02:00
2019-06-13 15:47:20 +02:00
#
# Scan string for a particular value (SCASx)
#
# CMP([%str], $val)
#
# IF (DF == 0) THEN
# %str = %str + sizeof(x)
# ELSE
# %str = %str - sizeof(x)
# FI
#
# Sets CF, OF, ZF and SF according to the result of the comparison
#
# 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
#
scasb
scasb rim
scasb r rim
#
# Compare bytes in strings (CMPSx)
#
# CMP([%str1], [%str2])
#
# IF (DF == 0) THEN
# %str1 = %str1 + sizeof(x)
# %str2 = %str2 + sizeof(x)
# ELSE
# %str1 = %str1 - sizeof(x)
# %str2 = %str2 - sizeof(x)
# FI
#
# Sets CF, OF, ZF and SF according to the result of the comparison
#
# 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
#
cmpsb
cmpsb r
cmpsb r r
2019-06-13 15:32:24 +02:00
#
# 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
2019-06-07 13:38:34 +02:00
#---------------------------------------------------------------------------#
# Supervisor only instructions #
#---------------------------------------------------------------------------#
2019-05-16 19:49:51 +02:00
pushf
2019-06-06 14:57:34 +02:00
popf
2019-05-16 19:49:51 +02:00
2019-06-13 15:00:48 +02:00
#
# Call an architecture-reserved function slot of device (DEVCTL)
#
# See dv/DEVAPI
#
devctl rim rim
#
# Call a device-defined function slot of device (IOCALL)
#
# See dv/DEVAPI
#
iocall rim rim
#---------------------------------------------------------------------------#
# Flag manipulation instructions #
#---------------------------------------------------------------------------#
2019-05-16 18:45:00 +02:00
#
2019-06-07 13:38:34 +02:00
# Clear or set interrupt flag (CLI/STI)
#
# Throws:
# #SYS if not in supervisor mode
2019-05-16 18:45:00 +02:00
#
2019-05-16 16:48:45 +02:00
cli
sti
2019-05-15 21:47:08 +02:00
2019-06-07 13:38:34 +02:00
#
2019-06-13 15:00:48 +02:00
# Clear or set direction flag (CLD/STD)
2019-06-07 13:38:34 +02:00
#
2019-06-13 15:00:48 +02:00
cld
std
2019-06-07 13:38:34 +02:00
#
2019-06-13 15:00:48 +02:00
# Complement, clear or set carry flag (CMC/CLC/STC)
2019-06-07 13:38:34 +02:00
#
2019-06-13 15:00:48 +02:00
cmc
clc
stc
2019-06-05 19:31:48 +02:00
2019-06-07 13:38:34 +02:00
#---------------------------------------------------------------------------#
# Misc. instructions #
#---------------------------------------------------------------------------#
2019-06-07 13:43:03 +02:00
#
# Do nothing (NOOP)
#
# (nothing)
#
# Throws:
# (nothing)
#
2019-06-07 13:45:20 +02:00
# Preserves all flags
#
2019-06-07 13:43:03 +02:00
nop
2019-05-30 13:25:30 +02:00
#
2019-06-13 15:00:48 +02:00
# Get code/data offset (GCO/GCD)
2019-05-30 13:25:30 +02:00
#
2019-06-07 13:38:34 +02:00
# $1 = CR1 (GCO)
# $1 = CR2 (GCD)
#
gco rm
gcd rm
2019-05-30 13:25:30 +02:00
2019-06-07 13:38:34 +02:00
#
2019-06-12 18:43:24 +02:00
# Send a character to standard output (PRN)
2019-06-07 13:38:34 +02:00
#
# Throws:
# #PRN if DV text mode enabled
# #PRN if graphic mode enabled
#
2019-06-02 16:33:28 +02:00
prn rim
2019-05-29 16:57:22 +02:00
2019-06-07 13:38:34 +02:00
#---------------------------------------------------------------------------#
# Debugging instructions #
#---------------------------------------------------------------------------#
2019-05-30 13:25:30 +02:00
#
2019-06-07 13:38:34 +02:00
# Breakpoint instruction (BREAK)
#
# (cause register dump on standard error)
# (wait for user input before proceeeding)
2019-05-30 13:25:30 +02:00
#
2019-06-12 15:30:35 +02:00
break
2019-05-30 13:25:30 +02:00
2019-06-07 13:38:34 +02:00
#
# Step-by-step execution (STEP)
#
# IF $1 == 0 THEN
# (disable step-by-step execution)
# ELSE
# (enable step-by-step execution)
# FI
#
2019-06-05 22:59:32 +02:00
step rim
2019-06-07 13:38:34 +02:00
#---------------------------------------------------------------------------#
2019-06-13 15:00:48 +02:00
# Clean-up misc. instructions #
#---------------------------------------------------------------------------#
#
# Clear base volatile registers (CLR)
#
# RAX = RBX = RCX = RDX = 0
# RSX = RBI = RDI = RSI = 0
#
clr
#
# Clear argument registers (CLA)
#
# AX0 = AX1 = AX2 = AX3 = 0
# AX4 = AX5 = AX6 = AX7 = 0
#
cla
#
# Clear base non-volatile registers (CLN)
#
# NX0 = NX1 = NX2 = NX3 = 0
# NX4 = NX5 = NX6 = NX7 = 0
#
cln
#---------------------------------------------------------------------------#
2019-06-07 13:38:34 +02:00