# Initial process that invokes SYS_exec to execute the program named "/init".
#
# This code runs in user space as the very first user mode instructions. It does this:
#    _entry:
#      i = sys_exec ("/init.exe", argv)
#    exit:
#      sys_exit (i)
#      goto exit
#
# where "argv" is an array of 1 element. The (first) element is a pointer to the command
# name string. The array is a Blitz array so it has the usual Blitz array header word.
#   

SYS_exit:	.equ	2
SYS_exec:	.equ	7

	.sourcefile	"initcode.s", "Harry Porter - 11 Octgober 2023"
	.begin		startaddr=0x8_0000_0000,gp=undefined
_entry:
	.export		_entry

        movi		r1, init	# Argument 1 is address of string
        movi		r2, argv	# Argument 2 is address of argv array
        syscall		SYS_exec	# Any error code would be returned in r1
exit:
        syscall		SYS_exit
        jump exit

	.align		8


#
# argv: array [1] of ptr = {&init}
#
argv:	.word		1		# Array header
	.word		1
	.doubleword	init


#
# init: array of byte = "/init"
#
init:	.word		strBeyond-str	# Array header
	.word		strBeyond-str
str:	.string		"/init.exe"
strBeyond:
	.align		8

