armraspberry-piclockarmv6

How to access user mode in Raspberry pi 1?


What I want to do is trying to run a short code in Raspberry pi 1(ARMv6), and get the number of clock cycles it took. So I have to read the Cycle Counter Register, which is in CP15 c15. In the document(ARM11->ARM1176->ARM1176JZF-S Technical Reference Manual->System Control Coprocessor->System control processor registers->c15, Cycle Counter Register) it says that I need to access the user mode firstly. But I have no idea how to do it.

In Raspberry pi 2(ARMv7) I know this could be done with a kernel module of following code:

/* enable user-mode access */
asm ("MCR p15, 0, %0, C9, C14, 0\n\t" :: "r"(1));

but since the registers of ARMv6 and ARMv7 are different, I don't know how to write the assembler for Raspberry 1. Until now I couldn't find anything about this in the manual. Does anyone know how to do it?

Btw, my purpose is just getting the clock cycles of running a code. If anyone knows other approaches to do it, I'm also glad to see. Thank you!


Solution

  • There is no general ability to modify kernel parameters. To edit /boot/cmdline.txt you must either already have root access, or the ability to physically swap the card. It only takes effect on the next boot too, so you already have the greatest possible denial of service capability.

    Since this thread will not die, may I at least point out that init=shell is not what is properly called single-user mode. Single-user mode is when you add "single" to cmdline, or otherwise boot or transition into runlevel 1 or S. You have almost no background daemons started, and only root may login, on console. If a root password is set, it is normally required to be entered.

    init=/bin/bash might be better called "single-process mode". The init system, and runlevels, and init scripts are skipped completely, and a root shell is launched instead. Even important pseudo-filesystems like /dev and /proc and /sys are not mounted, so many normal commands will fail. Job control is not available.