fn rsEnterSSection(sStoragePaddr: u64, sp1: u64 /*, uuid: u64*/) -> u64{
	// let id = getID();
	let id1: u64;
	let id2: u64;
	GET_PROCID!(id1);
	// GET_THREADID!(id2, sp1);
	GET_THREADID!(id2);

	// ymh_log_str("ENTER:\0");
	// ymh_log_hex(id1);
	// ymh_log_hex(id2);
	// ymh_log_nl();
	// PRINT_SLIB_REAL!("ENTER-S:\0", id1, id2);

	/*ymh_log_str("ID2:\0");
	ymh_log_hex(id2);
	ymh_log_nl();	*/
	let uuid_top: u64 = getX(sp1, 13);
	let uuid_bottom: u64 = getX(sp1, 14);
	// let lr: u64 = getX(sp1, 15);
	let bExitEval = uuid_top == EVAL_ENTRY_EXIT_UUID_TOP && uuid_bottom == EVAL_ENTRY_EXIT_UUID_BOTTOM;
	/*let bSetExeceptionTrap = uuid_top == EVAL_EXECTRAP_UUID_TOP && uuid_bottom == EVAL_EXECTRAP_UUID_BOTTOM;
	let bOTP = B_EVAL_OTP && (
				(uuid_top == EVAL_OTP_UUID1_TOP && uuid_bottom == EVAL_OTP_UUID1_BOTTOM) ||
				(uuid_top == EVAL_OTP_UUID2_TOP && uuid_bottom == EVAL_OTP_UUID2_BOTTOM) ||
				(uuid_top == EVAL_OTP_UUID3_TOP && uuid_bottom == EVAL_OTP_UUID3_BOTTOM) ||
				(uuid_top == EVAL_OTP_UUID4_TOP && uuid_bottom == EVAL_OTP_UUID4_BOTTOM)
				);*/
	let bDebugExcep = 	(uuid_top == EVAL_EXCEPTRAP_ML_UUID_TOP && uuid_bottom == EVAL_EXCEPTRAP_ML_UUID_BOTTOM) ||
						(uuid_top == EVAL_EXECTRAP_UUID_TOP 		&& uuid_bottom == EVAL_EXECTRAP_UUID_BOTTOM) ||
						(uuid_top == EVAL_OTP_FIRST_FUNC_UUID_TOP 	&& uuid_bottom == EVAL_OTP_FIRST_FUNC_UUID_BOTTOM);
	//bSetExeceptionTrap || bOTP;

	if bDebugExcep {
		// initHCR();
		*G_EXCEPTION_INITED.lock() = true;

		// ymh_log_str("EXCEPTION\n\0");
		/*ymh_log_str("SS_ENTRY for EXCEPTION\nuuid_top:\0");
		ymh_log_hex(uuid_top);
		ymh_log_nl();

		ymh_log_str("uuid_bottom:\0");
		ymh_log_hex(uuid_bottom);
		ymh_log_nl();*/
		/*ymh_log_str("\nSS_ENTRY for EXCEPTION\nprocID:\0");
		ymh_log_hex(id);
		ymh_log_nl();*/
	}

	/*{
		if *G_EXCEPTION_INITED.lock() {
			ymh_log_str("G_EXECPTION inited:\n\0");
		}
	}*/


	/*ymh_log_str("SS_ENTRY\0");
	// ymh_log_dec(getMonotonic());
	ymh_log_str("\nuuid_top:\0");
	ymh_log_hex(uuid_top);
	ymh_log_nl();

	ymh_log_str("uuid_bottom:\0");
	ymh_log_hex(uuid_bottom);
	ymh_log_nl();*/

	/*ymh_log_str("lr:\0");
	ymh_log_hex(lr);
	ymh_log_nl();*/

	// check if we already have a corresponding SCB instance.
	// If so, set the instance bInUse and return.
	// LR should be updated because a ssection can be called in different places
	// if checkID_setUseOrNotuse(id, uuid_top, uuid_bottom, true,/* lr,*/ bExitEval) /*!= None*/ { return 0; }
	if checkID_setUseOrNotuse(id1, id2, uuid_top, uuid_bottom, true,/* lr, bExitEval*/) {
		// if bSetExeceptionTrap {ymh_log_str("SCB found - return\n\0");}
		if !bExitEval {
			// ymh_log_str("SCB found - return\n\0");
			return 0; 
		}
	}

	// debugpoint
	// return 0;

	/*ymh_log_str("SS_ENTRY-newSCB\0");
	ymh_log_str("\nuuid_top:\0");
	ymh_log_hex(uuid_top);
	ymh_log_nl();

	ymh_log_str("uuid_bottom:\0");
	ymh_log_hex(uuid_bottom);
	ymh_log_nl();*/

	/*let mut t_start: u64;
	let mut t_end: u64;
	pmEnableReset();

	ymh_log_str("Kernel PT walk latency...\n\0");
	unsafe { asm! ("mrs $0, pmccntr_el0" : "=r" (t_start) :: "memory"); }

	for i in 0..1000 {
		memutil::checkKernelPT();
	}
	unsafe { asm! ("mrs $0, pmccntr_el0" : "=r" (t_end) :: "memory"); }
	ymh_log_str("PT walk latency avg:\0");
	ymh_log_dec( (t_end-t_start)/1000 );
	ymh_log_nl();*/

	// if bSetExeceptionTrap {ymh_log_str("EXCEP-CHECK-1\n\0");}
	// ymh_log_str("checkKernelPT\n\0");
	memutil::checkKernelPT(); // ################### TODO: RESTORE AFTER DEBUGGING!!
	// if bSetExeceptionTrap {ymh_log_str("EXCEP-CHECK-2\n\0");}

	// TEST AES
	/*if bExitEval {
		let plaintext = [0, lr];
		let mut ciphertext = [0 as u64; 2];
		let user_key = [0x0001020304050607, 0x08090a0b0c0d0e0f];
		AES_ENC(&plaintext, &mut ciphertext, &user_key);

		ymh_log_str("lr:\0");
		ymh_log_hex(lr);
		ymh_log_nl();

		ymh_log_str("ciphertext[0]:\0");
		ymh_log_hex(ciphertext[0]);
		ymh_log_nl();
		ymh_log_str("ciphertext[1]:\0");
		ymh_log_hex(ciphertext[1]);
		ymh_log_nl();

		let mut decrypted = [0 as u64; 2];
		AES_DEC(&ciphertext, &mut decrypted, &user_key);

		ymh_log_str("decrypted[0]:\0");
		ymh_log_hex(decrypted[0]);
		ymh_log_nl();
		ymh_log_str("decrypted[1]:\0");
		ymh_log_hex(decrypted[1]);
		ymh_log_nl();
	}*/

	// For QEMU and debugging purpose
	// For release, don't use the if-statement but the commented line
	// let elr = if sStoragePaddr == smc::GINSENG_UUID_QEMU_TEST {getElrEl1()} else {getElr3()};

	let elr: u64;
	GET_ELR_EL3!(elr);
	// let elr = ||->u64 {if uuid == smc::GINSENG_UUID_QEMU_TEST {getElrEl1()} else {getElr3()}}();

	// TODO: 	check code measurement.
	// 			For now, we assume we have the measurement passed by the vendor.
	// 			So, we just calculate the measurement and save it.
	// ymh_log_str("rsEnterSSection() is called\n\0");
	// ymh_log(&format!("sStoragePaddr(0x{:X})\n\0", sStoragePaddr));
	// ymh_log_str("sStoragePaddr:\0");
	// ymh_log_hex(sStoragePaddr);
	// ymh_log_nl();


	/*ymh_log(&format!("S-Section StartPAddr(0x{:X}) elr(0x{:X})\n\0", userVaddr2Paddr(elr), elr) );
	ymh_log(&format!("S-Section StartPAddr(0x{:X}) StartPAddr_page(0x{:X}) elr(0x{:X})\n\0", memutil::userVaddr2PaddrEx(elr, false /*not a page addr*/), memutil::userVaddr2PaddrEx(elr, true /*page addr*/), elr) );*/

	// TODO: Currently, I assume there exists a single SS_node for each SSection.
	let mut scb = SCB::new();
	scb.m_scbPKey = getSCBPKey();
	scb.m_processId = id1;
	scb.m_threadId = id2;
	scb.m_uuidTop = uuid_top;
	scb.m_uuidBottom = uuid_bottom;
	// scb.m_lr = lr;
	scb.m_bInUse = true;

	// I originally wanted to use the format!() macro, but I cannot use it due to a bug in that macro.
	// Instead, I resort to an unsafe function.
	// But, this can be reverted to using the format!() macro when its bug is fixed.
	// scb.m_name = Box::new(format!("HAHAHOHO\0"));
	// scb.m_name = Box::new(format!("{:08}\0", getASID()));
	// setAsidAsName(scb.m_name.as_ptr() as *mut _, scb.m_name.len() - 1);
	

	// let mut ss_node = SS_node::new();
	// scb.m_slist.push(ss_node);
	// scb.m_slist.push(SS_node::new());
	// if bDebugExcep {ymh_log_str("EXCEP-CHECK-3\n\0");}
	// checkTtbr();
	//read20test_whenUserAddr(getElr3());


	// assume that we already know S-Section info (Assumption_0)
	// TODO: Currently, we assume S-Setion belongs to a single page
	//		 But, we HAVE the facility to map multiple physical pages to a contiguous virtual address region!!

	// CHECK EVAL!
	if elr < 0xFFFF_FFFF_FFFFu64 { 
		// ymh_log_str("messure coode\n\0"); 
		// loop{}
		measureSSection(elr, sStoragePaddr, &mut scb);	
	}
	/*if uuid_top == EVAL_ENTRY_EXIT_UUID_TOP_NOSHA 
		&& uuid_bottom == EVAL_ENTRY_EXIT_UUID_BOTTOM_NOSHA {
		ymh_log_str("NO CHECK FOR EVAL\n\0");
			
	} else*/ /*if elr < 0xFFFFFFFFFFFFu64 { 
			// ymh_log_str("CODE CHECK FOR EVAL\n\0");
			// if bDebugExcep {ymh_log_str("EXCEP-CHECK-4\n\0");}
			measureSSection_forEval(elr, sStoragePaddr, &mut scb);	
			// if bDebugExcep {ymh_log_str("EXCEP-CHECK-5\n\0");}
	}*/
	
	{ // lock scope
		let mut gScbList_lock = G_SCB_LIST.lock();
		if let Some(ref mut v) = *gScbList_lock {
			/*ymh_log_str("New SCB PKey \0");
			ymh_log_dec(scb.m_scbPKey);
			ymh_log_str(" procID\0");
			ymh_log_hex(scb.m_processId);
			ymh_log_nl();*/
			v.push(scb)
		} else {
			ymh_log_str("ERROR MUST NOT HAPPEN - G_SCB_LIST is NONE\n\0");
			loop{}
		}
	}
	/*let mut gl = &*gScbList_lock;
	*gl.unwrap().push(scb);*/

	/*let dog = "The quick brown fox jumps over the lazy dog";
	let cog = "The quick brown fox jumps over the lazy cog";
	let mut out: [u8; 20] = [0; 20];
	SHA1("".as_ptr() as *const u8, 0, &mut out);
	rsHexdump(out.as_ptr(), 20);

	SHA1(dog.as_ptr() as *const u8, dog.len() as u32, &mut out);
	rsHexdump(out.as_ptr(), 20);

	SHA1(cog.as_ptr() as *const u8, cog.len() as u32, &mut out);
	rsHexdump(out.as_ptr(), 20);*/

	// printSCBList();
	// ymh_log_str("rsEnterSSection() returning\n\0");
	PRINT_SLIB!("ENTER-E:\0", id1, id2);
	0
}
/*
 * @sStoragePaddr: 	physical address of sStorage in NW.
 *					This points to a starting address of a page, 
 *					and Rust is free to choose an arbitrary portion of a page to save private (encrypted) data.
 *					Mostly, Ginseng uses sStorage to store encrypted regs
 *					sStorage is per SSection, thus it has to be passed at every S-Section entery point
 * => Rtn:	0: Ok; 99: Error
 */
@sStoragePaddr:      physical address of sStorage in NW.
This points to a starting address of a page,
and Rust is free to choose an arbitrary portion of a page to save private (encrypted) data.
Mostly, Ginseng uses sStorage to store encrypted regs
sStorage is per SSection, thus it has to be passed at every S-Section entery point
=> Rtn:      0: Ok; 99: Error
@sStoragePaddr : physical address of sStorage in NW . This points to a starting address of a page and Rust is free to choose an arbitrary portion of a page to save private ( encrypted ) data . Mostly Ginseng uses sStorage to store encrypted regs sStorage is per SSection thus it has to be passed at every S - Section entery point = > Rtn : 0 : Ok ; 99 : Error
fn rsEnterSSection(sStoragePaddr: u64, sp1: u64 /*, uuid: u64*/) -> u64{
	// let id = getID();
	let id1: u64;
	let id2: u64;
	GET_PROCID!(id1);
	// GET_THREADID!(id2, sp1);
	GET_THREADID!(id2);
	// ymh_log_str("ENTER:\0");
	// ymh_log_hex(id1);
	// ymh_log_hex(id2);
	// ymh_log_nl();
	// PRINT_SLIB_REAL!("ENTER-S:\0", id1, id2);
	/*ymh_log_str("ID2:\0");
	ymh_log_hex(id2);
	ymh_log_nl();	*/
	let uuid_top: u64 = getX(sp1, 13);
	let uuid_bottom: u64 = getX(sp1, 14);
	// let lr: u64 = getX(sp1, 15);
	let bExitEval = uuid_top == EVAL_ENTRY_EXIT_UUID_TOP && uuid_bottom == EVAL_ENTRY_EXIT_UUID_BOTTOM;
	/*let bSetExeceptionTrap = uuid_top == EVAL_EXECTRAP_UUID_TOP && uuid_bottom == EVAL_EXECTRAP_UUID_BOTTOM;
	let bOTP = B_EVAL_OTP && (
				(uuid_top == EVAL_OTP_UUID1_TOP && uuid_bottom == EVAL_OTP_UUID1_BOTTOM) ||
				(uuid_top == EVAL_OTP_UUID2_TOP && uuid_bottom == EVAL_OTP_UUID2_BOTTOM) ||
				(uuid_top == EVAL_OTP_UUID3_TOP && uuid_bottom == EVAL_OTP_UUID3_BOTTOM) ||
				(uuid_top == EVAL_OTP_UUID4_TOP && uuid_bottom == EVAL_OTP_UUID4_BOTTOM)
				);*/
	let bDebugExcep = 	(uuid_top == EVAL_EXCEPTRAP_ML_UUID_TOP && uuid_bottom == EVAL_EXCEPTRAP_ML_UUID_BOTTOM) ||
						(uuid_top == EVAL_EXECTRAP_UUID_TOP 		&& uuid_bottom == EVAL_EXECTRAP_UUID_BOTTOM) ||
						(uuid_top == EVAL_OTP_FIRST_FUNC_UUID_TOP 	&& uuid_bottom == EVAL_OTP_FIRST_FUNC_UUID_BOTTOM);
	//bSetExeceptionTrap || bOTP;
	if bDebugExcep {
		// initHCR();
		*G_EXCEPTION_INITED.lock() = true;
		// ymh_log_str("EXCEPTION\n\0");
		/*ymh_log_str("SS_ENTRY for EXCEPTION\nuuid_top:\0");
		ymh_log_hex(uuid_top);
		ymh_log_nl();
		ymh_log_str("uuid_bottom:\0");
		ymh_log_hex(uuid_bottom);
		ymh_log_nl();*/
		/*ymh_log_str("\nSS_ENTRY for EXCEPTION\nprocID:\0");
		ymh_log_hex(id);
		ymh_log_nl();*/
	}
	/*{
		if *G_EXCEPTION_INITED.lock() {
			ymh_log_str("G_EXECPTION inited:\n\0");
		}
	}*/
	/*ymh_log_str("SS_ENTRY\0");
	// ymh_log_dec(getMonotonic());
	ymh_log_str("\nuuid_top:\0");
	ymh_log_hex(uuid_top);
	ymh_log_nl();
	ymh_log_str("uuid_bottom:\0");
	ymh_log_hex(uuid_bottom);
	ymh_log_nl();*/
	/*ymh_log_str("lr:\0");
	ymh_log_hex(lr);
	ymh_log_nl();*/
	// check if we already have a corresponding SCB instance.
	// If so, set the instance bInUse and return.
	// LR should be updated because a ssection can be called in different places
	// if checkID_setUseOrNotuse(id, uuid_top, uuid_bottom, true,/* lr,*/ bExitEval) /*!= None*/ { return 0; }
	if checkID_setUseOrNotuse(id1, id2, uuid_top, uuid_bottom, true,/* lr, bExitEval*/) {
		// if bSetExeceptionTrap {ymh_log_str("SCB found - return\n\0");}
		if !bExitEval {
			// ymh_log_str("SCB found - return\n\0");
			return 0; 
		}
	}
	// debugpoint
	// return 0;
	/*ymh_log_str("SS_ENTRY-newSCB\0");
	ymh_log_str("\nuuid_top:\0");
	ymh_log_hex(uuid_top);
	ymh_log_nl();
	ymh_log_str("uuid_bottom:\0");
	ymh_log_hex(uuid_bottom);
	ymh_log_nl();*/
	/*let mut t_start: u64;
	let mut t_end: u64;
	pmEnableReset();
	ymh_log_str("Kernel PT walk latency...\n\0");
	unsafe { asm! ("mrs $0, pmccntr_el0" : "=r" (t_start) :: "memory"); }
	for i in 0..1000 {
		memutil::checkKernelPT();
	}
	unsafe { asm! ("mrs $0, pmccntr_el0" : "=r" (t_end) :: "memory"); }
	ymh_log_str("PT walk latency avg:\0");
	ymh_log_dec( (t_end-t_start)/1000 );
	ymh_log_nl();*/
	// if bSetExeceptionTrap {ymh_log_str("EXCEP-CHECK-1\n\0");}
	// ymh_log_str("checkKernelPT\n\0");
	memutil::checkKernelPT(); // ################### TODO: RESTORE AFTER DEBUGGING!!
	// if bSetExeceptionTrap {ymh_log_str("EXCEP-CHECK-2\n\0");}
	// TEST AES
	/*if bExitEval {
		let plaintext = [0, lr];
		let mut ciphertext = [0 as u64; 2];
		let user_key = [0x0001020304050607, 0x08090a0b0c0d0e0f];
		AES_ENC(&plaintext, &mut ciphertext, &user_key);
		ymh_log_str("lr:\0");
		ymh_log_hex(lr);
		ymh_log_nl();
		ymh_log_str("ciphertext[0]:\0");
		ymh_log_hex(ciphertext[0]);
		ymh_log_nl();
		ymh_log_str("ciphertext[1]:\0");
		ymh_log_hex(ciphertext[1]);
		ymh_log_nl();
		let mut decrypted = [0 as u64; 2];
		AES_DEC(&ciphertext, &mut decrypted, &user_key);
		ymh_log_str("decrypted[0]:\0");
		ymh_log_hex(decrypted[0]);
		ymh_log_nl();
		ymh_log_str("decrypted[1]:\0");
		ymh_log_hex(decrypted[1]);
		ymh_log_nl();
	}*/
	// For QEMU and debugging purpose
	// For release, don't use the if-statement but the commented line
	// let elr = if sStoragePaddr == smc::GINSENG_UUID_QEMU_TEST {getElrEl1()} else {getElr3()};
	let elr: u64;
	GET_ELR_EL3!(elr);
	// let elr = ||->u64 {if uuid == smc::GINSENG_UUID_QEMU_TEST {getElrEl1()} else {getElr3()}}();
	// TODO: 	check code measurement.
	// 			For now, we assume we have the measurement passed by the vendor.
	// 			So, we just calculate the measurement and save it.
	// ymh_log_str("rsEnterSSection() is called\n\0");
	// ymh_log(&format!("sStoragePaddr(0x{:X})\n\0", sStoragePaddr));
	// ymh_log_str("sStoragePaddr:\0");
	// ymh_log_hex(sStoragePaddr);
	// ymh_log_nl();
	/*ymh_log(&format!("S-Section StartPAddr(0x{:X}) elr(0x{:X})\n\0", userVaddr2Paddr(elr), elr) );
	ymh_log(&format!("S-Section StartPAddr(0x{:X}) StartPAddr_page(0x{:X}) elr(0x{:X})\n\0", memutil::userVaddr2PaddrEx(elr, false /*not a page addr*/), memutil::userVaddr2PaddrEx(elr, true /*page addr*/), elr) );*/
	// TODO: Currently, I assume there exists a single SS_node for each SSection.
	let mut scb = SCB::new();
	scb.m_scbPKey = getSCBPKey();
	scb.m_processId = id1;
	scb.m_threadId = id2;
	scb.m_uuidTop = uuid_top;
	scb.m_uuidBottom = uuid_bottom;
	// scb.m_lr = lr;
	scb.m_bInUse = true;
	// I originally wanted to use the format!() macro, but I cannot use it due to a bug in that macro.
	// Instead, I resort to an unsafe function.
	// But, this can be reverted to using the format!() macro when its bug is fixed.
	// scb.m_name = Box::new(format!("HAHAHOHO\0"));
	// scb.m_name = Box::new(format!("{:08}\0", getASID()));
	// setAsidAsName(scb.m_name.as_ptr() as *mut _, scb.m_name.len() - 1);
	// let mut ss_node = SS_node::new();
	// scb.m_slist.push(ss_node);
	// scb.m_slist.push(SS_node::new());
	// if bDebugExcep {ymh_log_str("EXCEP-CHECK-3\n\0");}
	// checkTtbr();
	//read20test_whenUserAddr(getElr3());
	// assume that we already know S-Section info (Assumption_0)
	// TODO: Currently, we assume S-Setion belongs to a single page
	//		 But, we HAVE the facility to map multiple physical pages to a contiguous virtual address region!!
	// CHECK EVAL!
	if elr < 0xFFFF_FFFF_FFFFu64 { 
		// ymh_log_str("messure coode\n\0"); 
		// loop{}
		measureSSection(elr, sStoragePaddr, &mut scb);	
	}
	/*if uuid_top == EVAL_ENTRY_EXIT_UUID_TOP_NOSHA 
		&& uuid_bottom == EVAL_ENTRY_EXIT_UUID_BOTTOM_NOSHA {
		ymh_log_str("NO CHECK FOR EVAL\n\0");
	} else*/ /*if elr < 0xFFFFFFFFFFFFu64 { 
			// ymh_log_str("CODE CHECK FOR EVAL\n\0");
			// if bDebugExcep {ymh_log_str("EXCEP-CHECK-4\n\0");}
			measureSSection_forEval(elr, sStoragePaddr, &mut scb);	
			// if bDebugExcep {ymh_log_str("EXCEP-CHECK-5\n\0");}
	}*/
	{ // lock scope
		let mut gScbList_lock = G_SCB_LIST.lock();
		if let Some(ref mut v) = *gScbList_lock {
			/*ymh_log_str("New SCB PKey \0");
			ymh_log_dec(scb.m_scbPKey);
			ymh_log_str(" procID\0");
			ymh_log_hex(scb.m_processId);
			ymh_log_nl();*/
			v.push(scb)
		} else {
			ymh_log_str("ERROR MUST NOT HAPPEN - G_SCB_LIST is NONE\n\0");
			loop{}
		}
	}
	/*let mut gl = &*gScbList_lock;
	*gl.unwrap().push(scb);*/
	/*let dog = "The quick brown fox jumps over the lazy dog";
	let cog = "The quick brown fox jumps over the lazy cog";
	let mut out: [u8; 20] = [0; 20];
	SHA1("".as_ptr() as *const u8, 0, &mut out);
	rsHexdump(out.as_ptr(), 20);
	SHA1(dog.as_ptr() as *const u8, dog.len() as u32, &mut out);
	rsHexdump(out.as_ptr(), 20);
	SHA1(cog.as_ptr() as *const u8, cog.len() as u32, &mut out);
	rsHexdump(out.as_ptr(), 20);*/
	// printSCBList();
	// ymh_log_str("rsEnterSSection() returning\n\0");
	PRINT_SLIB!("ENTER-E:\0", id1, id2);
	0
}
fn rsEnterSSection ( sStoragePaddr : u64 , sp1 : u64 /*, uuid: u64*/ ) -> u64 { // let id = getID(); let id1 : u64 ; let id2 : u64 ; GET_PROCID ! ( id1 ) ; // GET_THREADID!(id2, sp1); GET_THREADID ! ( id2 ) ; // ymh_log_str("ENTER:\0"); // ymh_log_hex(id1); // ymh_log_hex(id2); // ymh_log_nl(); // PRINT_SLIB_REAL!("ENTER-S:\0", id1, id2); /*ymh_log_str("ID2:\0");
	ymh_log_hex(id2);
	ymh_log_nl();	*/ let uuid_top : u64 = getX ( sp1 , 13 ) ; let uuid_bottom : u64 = getX ( sp1 , 14 ) ; // let lr: u64 = getX(sp1, 15); let bExitEval = uuid_top == EVAL_ENTRY_EXIT_UUID_TOP && uuid_bottom == EVAL_ENTRY_EXIT_UUID_BOTTOM ; /*let bSetExeceptionTrap = uuid_top == EVAL_EXECTRAP_UUID_TOP && uuid_bottom == EVAL_EXECTRAP_UUID_BOTTOM;
	let bOTP = B_EVAL_OTP && (
				(uuid_top == EVAL_OTP_UUID1_TOP && uuid_bottom == EVAL_OTP_UUID1_BOTTOM) ||
				(uuid_top == EVAL_OTP_UUID2_TOP && uuid_bottom == EVAL_OTP_UUID2_BOTTOM) ||
				(uuid_top == EVAL_OTP_UUID3_TOP && uuid_bottom == EVAL_OTP_UUID3_BOTTOM) ||
				(uuid_top == EVAL_OTP_UUID4_TOP && uuid_bottom == EVAL_OTP_UUID4_BOTTOM)
				);*/ let bDebugExcep = ( uuid_top == EVAL_EXCEPTRAP_ML_UUID_TOP && uuid_bottom == EVAL_EXCEPTRAP_ML_UUID_BOTTOM ) || ( uuid_top == EVAL_EXECTRAP_UUID_TOP && uuid_bottom == EVAL_EXECTRAP_UUID_BOTTOM ) || ( uuid_top == EVAL_OTP_FIRST_FUNC_UUID_TOP && uuid_bottom == EVAL_OTP_FIRST_FUNC_UUID_BOTTOM ) ; //bSetExeceptionTrap || bOTP; if bDebugExcep { // initHCR(); * G_EXCEPTION_INITED . lock ( ) = true ; // ymh_log_str("EXCEPTION\n\0"); /*ymh_log_str("SS_ENTRY for EXCEPTION\nuuid_top:\0");
		ymh_log_hex(uuid_top);
		ymh_log_nl();

		ymh_log_str("uuid_bottom:\0");
		ymh_log_hex(uuid_bottom);
		ymh_log_nl();*/ /*ymh_log_str("\nSS_ENTRY for EXCEPTION\nprocID:\0");
		ymh_log_hex(id);
		ymh_log_nl();*/ } /*{
		if *G_EXCEPTION_INITED.lock() {
			ymh_log_str("G_EXECPTION inited:\n\0");
		}
	}*/ /*ymh_log_str("SS_ENTRY\0");
	// ymh_log_dec(getMonotonic());
	ymh_log_str("\nuuid_top:\0");
	ymh_log_hex(uuid_top);
	ymh_log_nl();

	ymh_log_str("uuid_bottom:\0");
	ymh_log_hex(uuid_bottom);
	ymh_log_nl();*/ /*ymh_log_str("lr:\0");
	ymh_log_hex(lr);
	ymh_log_nl();*/ // check if we already have a corresponding SCB instance. // If so, set the instance bInUse and return. // LR should be updated because a ssection can be called in different places // if checkID_setUseOrNotuse(id, uuid_top, uuid_bottom, true,/* lr,*/ bExitEval) /*!= None*/ { return 0; } if checkID_setUseOrNotuse ( id1 , id2 , uuid_top , uuid_bottom , true , /* lr, bExitEval*/ ) { // if bSetExeceptionTrap {ymh_log_str("SCB found - return\n\0");} if ! bExitEval { // ymh_log_str("SCB found - return\n\0"); return 0 ; } } // debugpoint // return 0; /*ymh_log_str("SS_ENTRY-newSCB\0");
	ymh_log_str("\nuuid_top:\0");
	ymh_log_hex(uuid_top);
	ymh_log_nl();

	ymh_log_str("uuid_bottom:\0");
	ymh_log_hex(uuid_bottom);
	ymh_log_nl();*/ /*let mut t_start: u64;
	let mut t_end: u64;
	pmEnableReset();

	ymh_log_str("Kernel PT walk latency...\n\0");
	unsafe { asm! ("mrs $0, pmccntr_el0" : "=r" (t_start) :: "memory"); }

	for i in 0..1000 {
		memutil::checkKernelPT();
	}
	unsafe { asm! ("mrs $0, pmccntr_el0" : "=r" (t_end) :: "memory"); }
	ymh_log_str("PT walk latency avg:\0");
	ymh_log_dec( (t_end-t_start)/1000 );
	ymh_log_nl();*/ // if bSetExeceptionTrap {ymh_log_str("EXCEP-CHECK-1\n\0");} // ymh_log_str("checkKernelPT\n\0"); memutil :: checkKernelPT ( ) ; // ################### TODO: RESTORE AFTER DEBUGGING!! // if bSetExeceptionTrap {ymh_log_str("EXCEP-CHECK-2\n\0");} // TEST AES /*if bExitEval {
		let plaintext = [0, lr];
		let mut ciphertext = [0 as u64; 2];
		let user_key = [0x0001020304050607, 0x08090a0b0c0d0e0f];
		AES_ENC(&plaintext, &mut ciphertext, &user_key);

		ymh_log_str("lr:\0");
		ymh_log_hex(lr);
		ymh_log_nl();

		ymh_log_str("ciphertext[0]:\0");
		ymh_log_hex(ciphertext[0]);
		ymh_log_nl();
		ymh_log_str("ciphertext[1]:\0");
		ymh_log_hex(ciphertext[1]);
		ymh_log_nl();

		let mut decrypted = [0 as u64; 2];
		AES_DEC(&ciphertext, &mut decrypted, &user_key);

		ymh_log_str("decrypted[0]:\0");
		ymh_log_hex(decrypted[0]);
		ymh_log_nl();
		ymh_log_str("decrypted[1]:\0");
		ymh_log_hex(decrypted[1]);
		ymh_log_nl();
	}*/ // For QEMU and debugging purpose // For release, don't use the if-statement but the commented line // let elr = if sStoragePaddr == smc::GINSENG_UUID_QEMU_TEST {getElrEl1()} else {getElr3()}; let elr : u64 ; GET_ELR_EL3 ! ( elr ) ; // let elr = ||->u64 {if uuid == smc::GINSENG_UUID_QEMU_TEST {getElrEl1()} else {getElr3()}}(); // TODO: 	check code measurement. // 			For now, we assume we have the measurement passed by the vendor. // 			So, we just calculate the measurement and save it. // ymh_log_str("rsEnterSSection() is called\n\0"); // ymh_log(&format!("sStoragePaddr(0x{:X})\n\0", sStoragePaddr)); // ymh_log_str("sStoragePaddr:\0"); // ymh_log_hex(sStoragePaddr); // ymh_log_nl(); /*ymh_log(&format!("S-Section StartPAddr(0x{:X}) elr(0x{:X})\n\0", userVaddr2Paddr(elr), elr) );
	ymh_log(&format!("S-Section StartPAddr(0x{:X}) StartPAddr_page(0x{:X}) elr(0x{:X})\n\0", memutil::userVaddr2PaddrEx(elr, false /*not a page addr*/), memutil::userVaddr2PaddrEx(elr, true /*page addr*/), elr) );*/ // TODO: Currently, I assume there exists a single SS_node for each SSection. let mut scb = SCB :: new ( ) ; scb . m_scbPKey = getSCBPKey ( ) ; scb . m_processId = id1 ; scb . m_threadId = id2 ; scb . m_uuidTop = uuid_top ; scb . m_uuidBottom = uuid_bottom ; // scb.m_lr = lr; scb . m_bInUse = true ; // I originally wanted to use the format!() macro, but I cannot use it due to a bug in that macro. // Instead, I resort to an unsafe function. // But, this can be reverted to using the format!() macro when its bug is fixed. // scb.m_name = Box::new(format!("HAHAHOHO\0")); // scb.m_name = Box::new(format!("{:08}\0", getASID())); // setAsidAsName(scb.m_name.as_ptr() as *mut _, scb.m_name.len() - 1); // let mut ss_node = SS_node::new(); // scb.m_slist.push(ss_node); // scb.m_slist.push(SS_node::new()); // if bDebugExcep {ymh_log_str("EXCEP-CHECK-3\n\0");} // checkTtbr(); //read20test_whenUserAddr(getElr3()); // assume that we already know S-Section info (Assumption_0) // TODO: Currently, we assume S-Setion belongs to a single page //		 But, we HAVE the facility to map multiple physical pages to a contiguous virtual address region!! // CHECK EVAL! if elr < 0xFFFF_FFFF_FFFFu64 { // ymh_log_str("messure coode\n\0");  // loop{} measureSSection ( elr , sStoragePaddr , & mut scb ) ; } /*if uuid_top == EVAL_ENTRY_EXIT_UUID_TOP_NOSHA 
		&& uuid_bottom == EVAL_ENTRY_EXIT_UUID_BOTTOM_NOSHA {
		ymh_log_str("NO CHECK FOR EVAL\n\0");
			
	} else*/ /*if elr < 0xFFFFFFFFFFFFu64 { 
			// ymh_log_str("CODE CHECK FOR EVAL\n\0");
			// if bDebugExcep {ymh_log_str("EXCEP-CHECK-4\n\0");}
			measureSSection_forEval(elr, sStoragePaddr, &mut scb);	
			// if bDebugExcep {ymh_log_str("EXCEP-CHECK-5\n\0");}
	}*/ { // lock scope let mut gScbList_lock = G_SCB_LIST . lock ( ) ; if let Some ( ref mut v ) = * gScbList_lock { /*ymh_log_str("New SCB PKey \0");
			ymh_log_dec(scb.m_scbPKey);
			ymh_log_str(" procID\0");
			ymh_log_hex(scb.m_processId);
			ymh_log_nl();*/ v . push ( scb ) } else { ymh_log_str ( " \n \0 " ) ; loop { } } } /*let mut gl = &*gScbList_lock;
	*gl.unwrap().push(scb);*/ /*let dog = "The quick brown fox jumps over the lazy dog";
	let cog = "The quick brown fox jumps over the lazy cog";
	let mut out: [u8; 20] = [0; 20];
	SHA1("".as_ptr() as *const u8, 0, &mut out);
	rsHexdump(out.as_ptr(), 20);

	SHA1(dog.as_ptr() as *const u8, dog.len() as u32, &mut out);
	rsHexdump(out.as_ptr(), 20);

	SHA1(cog.as_ptr() as *const u8, cog.len() as u32, &mut out);
	rsHexdump(out.as_ptr(), 20);*/ // printSCBList(); // ymh_log_str("rsEnterSSection() returning\n\0"); PRINT_SLIB ! ( " \0 " id1 id2 ) ; 0 }
@sStoragePaddr:      physical address of sStorage in NW.
@sStoragePaddr : physical address of sStorage in NW .
sStoragePaddr
u64
sp1
u64
sStoragePaddr
u64
sp1
u64