#############################################################
#
# Basic Boot Program
#
# 13 December 2023 -- Harry Porter III
#
# This program is loaded into the BootROM and is the first thing executed
# (simultaneously) by every core at start-up.
#
# It is designed to function with the emulator. It assumes the emulator has preloaded
#  an executable file. Thhis code will branch to the program's "_entry" point.
#
#############################################################
#
# This program can be assembled as a NORMAL EXECUTABLE file, with:
#     asm boot0.s -o boot0.o
#     link boot0.o -o boot0.exe -k
#
# It can written to the file "emulationROM" with:
#     blitz boot0.exe
#     E> rom
# which will ask whether the user wishes to write out to the file "emulationROM".
# Saying "yes" will effectively store these bytes into the ROM. 
#
# This program will be loaded into the BootROM area (0x4_0000_0000). It makes no
# assumptions about main memory.
#
#############################################################
#
# Upon entry, the "blitz" emulator will preload the registers as follows.
# This is unrealistic for actual hardware, but will suffice to communicate
# the memory size and entry-point of the executable file.
#
#    r1 = Boot_Code                e.g., "coldboot" = 0x636F6C64626F6F74
#    r2 = Private_Memory_Size      in bytes
#    r3 = Shared_Memory_Start
#    r4 = Shared_Memory_Size       in bytes, possibly 0
#    r5 = First_Unused_Addr        (Beyond what was loaded with the .exe file)
#    r6 = Address of _entry
#
#############################################################

# Place this program in the Bootstrap ROM area

	.begin	kernel,startaddr=0x400000000,gp=undefined

####################  MAIN ENTRY POINT  ####################
_entry:
	.export	_entry

	mov	sp,r2		# Initialize stack
	movi	gp,0x0000010000	# Initialize gp
	jr	r6		# Jump to address in r6 (i.e., to "_entry")


