Port-sparc64 archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Set PSTATE.PRIV for user process
On Thu, 22 Oct 2026, Sad Clouds wrote:
I need to look at the privileged window state registers from a user
process. Does anyone know a trick to make user process run in
privileged mode? I tried adding this to setregs() but the kernel panics
on boot.
Recently I committed some debug code, the SAVE_WINREGS macro in locore.s
The macro snapshots the complete register window and other relevant window
register control registers to a per-cpu (cpuinfo) structure.
This is from privileged mode.
I have used the macro to snapshot the register windows trying to trackdown
issues with garbage in registers after a process context is restored.
This way I have traced registers at different places in the code path from
the rft_user label in locore.s
The macro is called with two scratch registers.
Example from the last lines of rft_user:
...
#ifdef NOTDEF_DEBUG
ldx [%g6 + CC64FSZ + STKB + TF_L + (0*8)], %g5! DEBUG -- get
proper value for %l0
@@ -5547,6 +5630,10 @@
tst %g5
tnz %icc, 1; nop ! Debugger if we still
have saved windows!
#endif
SAVE_WINREGS %g1, %g2
wrpr %g0, 0, %pil ! Enable all interrupts
retry
Then I have a couple of functions that work on the snapshots. These are
called from relevant places in trap.c.
(please ignore the '+' in the first column of each line...
...
+void clear_winregs(void)
+{
+ curcpu()->ci_winregs = 0;
+ memset(&(curcpu()->ci_rw0_local[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw0_in[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw1_local[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw1_in[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw2_local[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw2_in[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw3_local[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw3_in[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw4_local[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw4_in[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw5_local[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw5_in[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw6_local[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw6_in[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw7_local[0]), 0, 8*sizeof(int64_t));
+ memset(&(curcpu()->ci_rw7_in[0]), 0, 8*sizeof(int64_t));
+}
+
+void print_winregs(void)
+{
+#if 1
+ printf("Register window registers (WINREGS
cansave/canrestore/otherwin/cleanwin/cwp/wstate): %016lx\n",
curcpu()->ci_winregs);
+#endif
+
+#if 1
+ /* COMPRESSED */
+ /* RW 0 */
+ printf("RW 0 %%i0-%%i7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw0_in[i]);
+ }
+ printf("\n");
+ printf("RW 0 %%l0-%%l7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw0_local[i]);
+ }
+ printf("\n");
+ /* RW 1 */
+ printf("RW 1 %%i0-%%i7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw1_in[i]);
+ }
+ printf("\n");
+ printf("RW 1 %%l0-%%l7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw1_local[i]);
+ }
+ printf("\n");
+ /* RW 2 */
+ printf("RW 2 %%i0-%%i7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw2_in[i]);
+ }
+ printf("\n");
+ printf("RW 2 %%l0-%%l7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw2_local[i]);
+ }
+ printf("\n");
+ /* RW 3 */
+ printf("RW 3 %%i0-%%i7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw3_in[i]);
+ }
+ printf("\n");
+ printf("RW 3 %%l0-%%l7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw3_local[i]);
+ }
+ printf("\n");
+ /* RW 4 */
+ printf("RW 4 %%i0-%%i7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw4_in[i]);
+ }
+ printf("\n");
+ printf("RW 4 %%l0-%%l7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw4_local[i]);
+ }
+ printf("\n");
+ /* RW 5 */
+ printf("RW 5 %%i0-%%i7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw5_in[i]);
+ }
+ printf("\n");
+ printf("RW 5 %%l0-%%l7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw5_local[i]);
+ }
+ printf("\n");
+ /* RW 6 */
+ printf("RW 6 %%i0-%%i7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw6_in[i]);
+ }
+ printf("\n");
+ printf("RW 6 %%l0-%%l7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw6_local[i]);
+ }
+ printf("\n");
+ /* RW 7 */
+ printf("RW 7 %%i0-%%i7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw7_in[i]);
+ }
+ printf("\n");
+ printf("RW 7 %%l0-%%l7 ");
+ for (int i = 0; i < 8; i++) {
+ printf("%016lx ", curcpu()->ci_rw7_local[i]);
+ }
+ printf("\n");
+
+#endif
+}
+
I hope that this can be on any use to you - please feel free to use it or
adapt it to your needs.
Home |
Main Index |
Thread Index |
Old Index