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

478 lines
8.4 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-06 14:57:34 +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-06 14:57:34 +02:00
!or 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-06 22:07:34 +02:00
!and 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-06 14:57:34 +02:00
!xor rm rim
2019-06-07 13:38:34 +02:00
2019-06-07 13:43:03 +02:00
# To document
2019-06-06 14:57:34 +02:00
!shl rm rim
!shr 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
#
!sgn 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-06 22:07:34 +02:00
!neg 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-06 14:57:34 +02:00
!inc 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-06 14:57:34 +02:00
!dec 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-06 14:57:34 +02:00
!add 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-06 14:57:34 +02:00
!sub 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-06 14:57:34 +02:00
!mul rm rim
2019-06-07 13:38:34 +02:00
#
# Arithmetical unsigned DIV operation
#
# $1 = $1 DIV $2
#
# Preserves all flags
#
2019-06-06 14:57:34 +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-06 14:57:34 +02:00
!mod rm rim
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-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-07 13:38:34 +02:00
# TEST Comparaison 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
#
# CMP Comparaison instruction
#
# $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-06 22:07:34 +02:00
!j ri
2019-06-06 14:57:34 +02:00
!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-07 13:38:34 +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-06 14:57:34 +02:00
!lea rm m
2019-06-07 13:38:34 +02:00
#
# Movement (MOV) instruction
#
# $1 = $2
#
2019-06-06 14:57:34 +02:00
!mov rm rim
2019-06-07 13:38:34 +02:00
#
# Exchange (XCHG) instruction
#
# $_ = $1
# $1 = $2
# $2 = $_
#
2019-06-06 14:57:34 +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
# Undocumented
# movb rm rim
# movw rm rim
# movl rm rim
# movt rm rim
#---------------------------------------------------------------------------#
# 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-06 14:57:34 +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-06 14:57:34 +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
#
!call rim
#
# Return to caller (RET)
#
# POP(RIP)
#
# Throws:
# See POP
#
2019-06-06 14:57:34 +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
#
# Throws:
# See PUSH
#
2019-05-29 16:57:22 +02:00
enter
2019-05-29 22:27:49 +02:00
2019-06-07 13:38:34 +02:00
#
# Leave stack frame (LEAVE)
#
# RBP = *RSP
# RSP = RSP + 8
#
2019-06-06 14:57:34 +02:00
!leave
2019-05-29 16:57:22 +02:00
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-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
#
# Call an architecture-reserved function slot of device (DEVCTL)
#
# See dv/DEVAPI
#
2019-06-05 19:31:48 +02:00
devctl rim rim
2019-06-07 13:38:34 +02:00
#
# Call a device-defined function slot of device (IOCALL)
#
# See dv/DEVAPI
#
2019-06-05 19:31:48 +02:00
iocall rim rim
2019-06-07 13:38:34 +02:00
#---------------------------------------------------------------------------#
# Misc. instructions #
#---------------------------------------------------------------------------#
2019-06-07 13:43:03 +02:00
#
# Do nothing (NOOP)
#
# (nothing)
#
# Preserves all flags
#
# Throws:
# (nothing)
#
nop
2019-05-30 13:25:30 +02:00
#
2019-06-07 13:38:34 +02:00
# Get code/date 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
#
# Clear base volatile registers (CLR)
#
# RAX = RBX = RCX = RDX = 0
# RSX = RBI = RDI = RSI = 0
#
2019-06-05 22:11:45 +02:00
clr
2019-06-07 13:38:34 +02:00
#
# Clear argument registers (CLA)
#
# AX0 = AX1 = AX2 = AX3 = 0
# AX4 = AX5 = AX6 = AX7 = 0
#
2019-06-05 22:11:45 +02:00
cla
2019-06-07 13:38:34 +02:00
#
# Clear base non-volatile registers (CLN)
#
# NX0 = NX1 = NX2 = NX3 = 0
# NX4 = NX5 = NX6 = NX7 = 0
#
2019-06-05 22:11:45 +02:00
cln
2019-06-07 13:38:34 +02:00
#
# Send a character to standard output
#
# 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-06 14:57:34 +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
#---------------------------------------------------------------------------#