; ****************************************************************************
; inittest.s (init386.s)
; ----------------------------------------------------------------------------
;
; Retro UNIX 386 v1.2 Kernel - /etc/init file executing test (30/11/2021)
;
; [ Last Modification: 12/12/2021 ]
;
; ****************************************************************************
; (modified from 'init0.s', 24/10/2015, Retro UNIX 386 v1 /etc/init test file)
; ----------------------------------------------------------------------------
; nasm inittest.s -l inittest.txt -o init386 -Z error.txt

; 04/12/2021
; 30/11/2021
; 21/09/2015
; 07/08/2015
; 30/06/2015
; 14/07/2013
; UNIX v1 system calls
_rele 	equ 0
_exit 	equ 1
_fork 	equ 2
_read 	equ 3
_write	equ 4
_open	equ 5
_close 	equ 6
_wait 	equ 7
_creat 	equ 8
_link 	equ 9
_unlink	equ 10
_exec	equ 11
_chdir	equ 12
_time 	equ 13
_mkdir 	equ 14
_chmod	equ 15
_chown	equ 16
_break	equ 17
_stat	equ 18
_seek	equ 19
_tell 	equ 20
_mount	equ 21
_umount	equ 22
_setuid	equ 23
_getuid	equ 24
_stime	equ 25
_quit	equ 26	
_intr	equ 27
_fstat	equ 28
_emt 	equ 29
_mdate 	equ 30
_stty 	equ 31
_gtty	equ 32
_ilgins	equ 33
_sleep	equ 34 ; Retro UNIX 8086 v1 feature only !
_msg    equ 35 ; Retro UNIX 386 v1 feature only !
_getrr	equ 36 ; Retro UNIX 386 v1 feature only !
_test	equ 37 ; Retro UNIX 386 v1.2 test !!!		

%macro sys 1-4
    ; 13/04/2015
    ; Retro UNIX 386 v1 system call.		
    mov eax, %1
    %if %0 >= 2   
        mov ebx, %2
        %if %0 >= 3    
            mov ecx, %3
            %if %0 = 4
               mov edx, %4   
            %endif
        %endif
    %endif
    int 30h	   
%endmacro

[BITS 32] ; We need 32-bit intructions for protected mode

[ORG 0] 

START_CODE:
	; 12/12/2021
	;sys _test ; 04/12/2021
	;;sys _msg, copy_right_msg, 255, 0Fh ; copy right message with white color
	sys _msg, running_msg, sizeof_msg, 0Fh

	sys _exit

haltsys:
	hlt
	jmp short haltsys

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  messages
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

running_msg:
	;db 0Dh, 0Ah, 07h
	db 0Dh, 0Ah ; 04/12/2021
	db 'Retro UNIX 386 v1.2 Kernel Function Test : <sysexec> Function is OK!'
	db 0Dh, 0Ah
	db 0Dh, 0Ah
	db 'Retro UNIX 386 v1.2 </etc/init> loading and running test is OK!'
	db 0Dh, 0Ah
	db 0Dh, 0Ah	
sizeof_msg equ $ - running_msg 
	db 0

copy_right_msg:
	db '(c) Erdogan TAN - 12/12/2021'
	db 0Dh, 0Ah, 0