Minal OS -- An operating system written with Joy.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

279 lines
6.1 KiB

;============================================================================
; :file: declarations.asm
;============================================================================
; :section: constants
ws = 8
KiB = 1024
true = -1
false = 0
WALL = 10240000004201 ; wall: internal checks --> sww
COUNTCALLS = 1 ; count calls of atoms, conses, etc
;;;COUNTCALLS = 0
;============================================================================
; :section: registers
; aregs
a equ eax ; first function parameter | return value
b equ ebx ; second function parameter | return value
c equ ecx ; third function parameter | counter
d equ edx ; fourth function parameter | data
si equ esi ; source index
di equ edi ; destination index
k equ r9 ; key
v equ r8 ; value
;esp equ esp ; return-stack pointer, pointing full, grow down
dsp equ ebp ; data-stack pointer, pointing full
ssp equ r10d ; upstack pointer, pointing full
tos equ r12 ; top of data-stack
sos equ r13 ; second of data-stack
sstos equ r11 ; top of software-stack
prog equ r14d ; currently executing quotation
listff equ r15d ; first free list element
;--------------------------------
tosd equ r12d ; tos, 32-bit
sosd equ r13d ; sos, 32-bit
sstosd equ r11d ; top of software-stack
kd equ r9d ; key
vd equ r8d ; value
progq equ r14 ; currently executing quotation
dspq equ rbp
sspq equ r10
;============================================================================
; :section: macros
macro countcall counter {
if COUNTCALLS = 1
inc qword [counter]
end if
}
macro app [ cmd ] { cmd }
macro clr [ reg ] { xor reg,reg }
macro push_sd { push rsi rdi }
macro pop_ds { pop rdi rsi }
macro rpush r {
if r eq d
push rdx
else if r eq c
push rcx
else if r eq di
push rdi
else if r eq r12d
push r12
else if r eq r13d
push r13
else if r eq r9d
push r9
else if r eq r8d
push r8
else if r eq r11d
push r11
else if r eq r14d
push r14
else
push r
end if
}
macro rpop r {
if r eq d
pop rdx
else if r eq c
pop rcx
else if r eq di
pop rdi
else if r eq r12d
pop r12
else if r eq r13d
pop r13
else if r eq r9d
pop r9
else if r eq r8d
pop r8
else if r eq r11d
pop r11
else if r eq r14d
pop r14
else
pop r
end if
}
macro 1drop [r] { mov r, dword [r + ws] } ; drop one list element
macro uncons v,l {
mov v, qword [l]
1drop l
}
macro caa mess,name,reg {
push reg name mess
jmp caaF
}
macro zero? reg,dest {
test reg,reg
jz dest
}
macro equal? reg1,reg2, dest {
cmp reg1,reg2
je dest
}
macro notzero? reg,dest {
test reg,reg
jnz dest
}
macro notequal? reg1,reg2, dest {
cmp reg1,reg2
jne dest
}
macro doloop {
jmp .while
align 16
.loop:
}
macro until_zero reg {
.while:
notzero? reg, .loop
}
macro until_notzero reg {
.while:
zero? reg, .loop
}
macro until_equal r1, r2 {
.while:
notequal? r1,r2, .loop
}
;;;macro func_1 fun {
;;; macro fun p=a, q=b, r=c, s=d \{
;;; if ~(p eq a)
;;; mov a, p
;;; end if
;;; if ~(q eq b)
;;; mov b, q
;;; end if
;;; if ~(r eq c)
;;; mov c, r
;;; end if
;;; if ~(s eq d)
;;; mov d, s
;;; end if
;;; call fun#F
;;; \}
;;; fun#F:
;;;}
macro calls fun, p,q,r,s {
if ~(p eq)
if ~(p eq a)
mov a, p
end if
end if
if ~(q eq)
if ~(q eq b)
mov b, q
end if
end if
if ~(r eq)
if ~(r eq c)
mov c, r
end if
end if
if ~(s eq)
if ~(s eq d)
mov d, s
end if
end if
call fun
}
macro inbyte reg,port {
in al,port
mov reg,al
}
macro outbyte port,val {
mov al,val
out port,al
}
macro error errmess {
mov [status_line_error], dword errmess
jmp restart
}
macro sww messww {
local .mess
jmp @f
.mess: db messww, 0
@@: mov [status_line_error], dword .mess
jmp exit_fail
}
macro ROADWORK roadmess {
local .mess
jmp @f
.mess: db roadmess, 0
@@: print_at 2,31
ink_error
mprint mess_roadwork
mov [status_line_error], dword .mess
jmp exit
}
macro info string {
local .mess
jmp @f
.mess: db string, 0
@@: mprint .mess
spc
}
macro infoln string {
local .mess
jmp @f
.mess: db string, 0
@@: lf
mprint .mess
lf
}
macro EXITXX { jmp exit_fail }
;============================================================================
; end 2021-04-05