[arch] factor out the debug_cycle_count to arch specific code

Conflicts:

	arch/arm/ops.S

Change-Id: Id0d9baa3e669cc59822819c797ce913dba1606d6
diff --git a/app/tests/tests.c b/app/tests/tests.c
index 1a8130b..1a41f6f 100644
--- a/app/tests/tests.c
+++ b/app/tests/tests.c
@@ -29,8 +29,8 @@
 #include <lib/console.h>
 
 STATIC_COMMAND_START
-		{ "printf_tests", NULL, (console_cmd)&printf_tests },
-		{ "thread_tests", NULL, (console_cmd)&thread_tests },
+STATIC_COMMAND("printf_tests", NULL, (console_cmd)&printf_tests)
+STATIC_COMMAND("thread_tests", NULL, (console_cmd)&thread_tests)
 STATIC_COMMAND_END(tests);
 
 #endif
diff --git a/app/tests/thread_tests.c b/app/tests/thread_tests.c
index acbdfbd..908abc7 100644
--- a/app/tests/thread_tests.c
+++ b/app/tests/thread_tests.c
@@ -221,11 +221,11 @@
 
 	event_wait(&context_switch_event);
 
-	uint count = debug_cycle_count();
+	uint count = arch_cycle_count();
 	for (i = 0; i < iter; i++) {
 		thread_yield();
 	}
-	total_count += debug_cycle_count() - count;
+	total_count += arch_cycle_count() - count;
 	thread_sleep(1000);
 	printf("took %u cycles to yield %d times, %u per yield, %u per yield per thread\n", 
 		total_count, iter, total_count / iter, total_count / iter / thread_count);
diff --git a/arch/arm/arch.c b/arch/arm/arch.c
index 37b557c..7a5f85b 100644
--- a/arch/arm/arch.c
+++ b/arch/arm/arch.c
@@ -64,6 +64,19 @@
 	val = (1<<30);
 	__asm__ volatile("mcr  p10, 7, %0, c8, c0, 0" :: "r" (val));
 #endif
+
+#if ARM_CPU_CORTEX_A8
+	/* enable the cycle count register */
+	uint32_t en;
+	__asm__ volatile("mrc	p15, 0, %0, c9, c12, 0" : "=r" (en));
+	en &= ~(1<<3); /* cycle count every cycle */
+	en |= 1; /* enable all performance counters */
+	__asm__ volatile("mcr	p15, 0, %0, c9, c12, 0" :: "r" (en));
+
+	/* enable cycle counter */
+	en = (1<<31);
+	__asm__ volatile("mcr	p15, 0, %0, c9, c12, 1" :: "r" (en));
+#endif
 }
 
 void arch_init(void)
diff --git a/arch/arm/ops.S b/arch/arm/ops.S
index 96b7445..c9660e7 100644
--- a/arch/arm/ops.S
+++ b/arch/arm/ops.S
@@ -221,3 +221,15 @@
 	mcr		p15, 0, r0, c7, c10, 4
 #endif
 	bx		lr
+
+/* uint32_t arm_read_cycle_count(void); */
+FUNCTION(arm_read_cycle_count)
+
+/* uint32_t arch_cycle_count(void); */
+FUNCTION(arch_cycle_count)
+#if ARM_CPU_CORTEX_A8
+	mrc		p15, 0, r0, c9, c13, 0
+#else
+	mov		r0, #0
+#endif
+	bx		lr
diff --git a/arch/x86/arch.c b/arch/x86/arch.c
index 99ca572..bb6a17b 100644
--- a/arch/x86/arch.c
+++ b/arch/x86/arch.c
@@ -60,3 +60,11 @@
 {
 }
 
+uint32_t arch_cycle_count(void)
+{
+	uint32_t timestamp;
+	rdtscl(timestamp);
+	
+	return timestamp;
+}
+
diff --git a/include/arch/ops.h b/include/arch/ops.h
index d5bafd0..5854b8c 100644
--- a/include/arch/ops.h
+++ b/include/arch/ops.h
@@ -58,6 +58,8 @@
 
 void arch_switch_stacks_and_call(addr_t call, addr_t stack) __NO_RETURN;
 
+uint32_t arch_cycle_count(void);
+
 #if defined(__cplusplus)
 }
 #endif
diff --git a/include/platform/debug.h b/include/platform/debug.h
index 4ab460a..785cd42 100644
--- a/include/platform/debug.h
+++ b/include/platform/debug.h
@@ -32,7 +32,6 @@
 #endif
 
 void debug_dump_regs(void);
-uint32_t debug_cycle_count(void);
 
 void debug_dump_memory_bytes(void *mem, int len);
 void debug_dump_memory_halfwords(void *mem, int len);
diff --git a/platform/at91sam7/debug.c b/platform/at91sam7/debug.c
index ad8f262..24a0d85 100644
--- a/platform/at91sam7/debug.c
+++ b/platform/at91sam7/debug.c
@@ -75,7 +75,3 @@
     for(;;);
 }
 
-uint32_t debug_cycle_count()
-{
-	PANIC_UNIMPLEMENTED;
-}
diff --git a/platform/integrator/debug.c b/platform/integrator/debug.c
index 1aedf8b..f8f456c 100644
--- a/platform/integrator/debug.c
+++ b/platform/integrator/debug.c
@@ -140,7 +140,3 @@
 	PANIC_UNIMPLEMENTED;
 }
 
-uint32_t debug_cycle_count()
-{
-	PANIC_UNIMPLEMENTED;
-}
diff --git a/platform/omap3/debug.c b/platform/omap3/debug.c
index 8ddf3b2..87aac8d 100644
--- a/platform/omap3/debug.c
+++ b/platform/omap3/debug.c
@@ -79,8 +79,3 @@
 	PANIC_UNIMPLEMENTED;
 }
 
-uint32_t debug_cycle_count(void)
-{
-//	PANIC_UNIMPLEMENTED;
-	return 0;
-}
diff --git a/platform/omap5912/debug.c b/platform/omap5912/debug.c
index 5b8bcd8..3afb39c 100644
--- a/platform/omap5912/debug.c
+++ b/platform/omap5912/debug.c
@@ -150,12 +150,6 @@
 	PANIC_UNIMPLEMENTED;
 }
 
-uint32_t debug_cycle_count(void)
-{
-//	PANIC_UNIMPLEMENTED;
-	return 0;
-}
-
 void platform_init_debug(void)
 {
 	cbuf_initialize(&debug_buf, 512);
diff --git a/platform/pc/debug.c b/platform/pc/debug.c
index 06ac263..63652d8 100644
--- a/platform/pc/debug.c
+++ b/platform/pc/debug.c
@@ -35,7 +35,7 @@
 	cputc(c);
 }
 
-int dgetc(char *c)
+int dgetc(char *c, bool wait)
 {
 	int ret =  platform_read_key(c);
 	if (ret < 0)
@@ -72,10 +72,3 @@
 {
 }
 
-uint32_t debug_cycle_count()
-{
-	uint32_t timestamp;
-	rdtscl(timestamp);
-	
-	return timestamp;
-}