The motivation behind the previous context work was to enable access to the saved context in Forth, e.g. some SPARC64 bootloaders will attempt to read the saved register values.
This patch enables read-only access to the CPU registers in Forth for PPC, SPARC32 and SPARC64 whilst also implementing the IEEE-1275 .registers word.
NOTE: the primary reason this is read-only is because currently there exists no Forth CFA that can evaluate an xt and use the result as part of a "<value> to %g1" construction.
Mark Cave-Ayland (6): Make current CPU context available in Forth libopenbios: don't display output on execution of "go" word ppc: fix off-by-one error for register r4 in context switch ppc: add basic read-only Forth register support SPARC32: add basic read-only Forth register support SPARC64: add basic read-only Forth register support
arch/ppc/ppc.fs | 127 +++++++++++++++++++++++------------- arch/ppc/qemu/switch.S | 2 +- arch/sparc32/build.xml | 1 + arch/sparc32/cpu.fs | 100 +++++++++++++++++++++++++++++ arch/sparc64/build.xml | 1 + arch/sparc64/cpu.fs | 156 +++++++++++++++++++++++++++++++++++++++++++++ forth/debugging/client.fs | 6 ++ libopenbios/init.c | 4 ++ libopenbios/initprogram.c | 16 +---- 9 files changed, 354 insertions(+), 59 deletions(-) create mode 100644 arch/sparc32/cpu.fs create mode 100644 arch/sparc64/cpu.fs
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- forth/debugging/client.fs | 6 ++++++ libopenbios/init.c | 4 ++++ 2 files changed, 10 insertions(+)
diff --git a/forth/debugging/client.fs b/forth/debugging/client.fs index 853998c..c8cd5b6 100644 --- a/forth/debugging/client.fs +++ b/forth/debugging/client.fs @@ -1,5 +1,11 @@ \ 7.6 Client Program Debugging command group
+\ Saved program state context +variable __context +0 __context ! + +: saved-context __context @ @ ; +
\ 7.6.1 Registers display
diff --git a/libopenbios/init.c b/libopenbios/init.c index 9b81821..8882bf3 100644 --- a/libopenbios/init.c +++ b/libopenbios/init.c @@ -22,6 +22,10 @@ void openbios_init( void ) { + // Bind the saved program state context into Forth + PUSH(pointer2cell((void *)&__context)); + feval("['] __context cell+ !"); + // Bind the C implementation of (init-program) into Forth bind_func("(init-program)", init_program);
The displayed output is only correct after a valid load, and so with subsequent enter/exits the information is noisy and actually wrong.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- libopenbios/initprogram.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/libopenbios/initprogram.c b/libopenbios/initprogram.c index 49b5dc2..ffd3254 100644 --- a/libopenbios/initprogram.c +++ b/libopenbios/initprogram.c @@ -113,18 +113,6 @@ void init_forth_context(void)
void go(void) { - ucell address, type; - int image_retval = 0; - - /* Get the entry point and the type (see forth/debugging/client.fs) */ - feval("load-state >ls.entry @"); - address = POP(); - feval("load-state >ls.file-type @"); - type = POP(); - - printk("\nJumping to entry point " FMT_ucellx " for type " FMT_ucellx "...\n", address, type); - - image_retval = start_elf(); - - printk("Image returned with return value %#x\n", image_retval); + /* Switch to the current context */ + start_elf(); }
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- arch/ppc/qemu/switch.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/ppc/qemu/switch.S b/arch/ppc/qemu/switch.S index c3d9d70..f1b120d 100644 --- a/arch/ppc/qemu/switch.S +++ b/arch/ppc/qemu/switch.S @@ -193,7 +193,7 @@ __set_context: /* r4, r1 */ PPC_LL r1, STKOFF(r4) - PPC_LL r4, (STKOFF + 8 * ULONG_SIZE)(r4) + PPC_LL r4, (STKOFF + 9 * ULONG_SIZE)(r4) LOAD_REG_IMMEDIATE(r0, MSR_FP | MSR_ME | MSR_DR | MSR_IR) MTMSRD(r0)
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- arch/ppc/ppc.fs | 127 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 83 insertions(+), 44 deletions(-)
diff --git a/arch/ppc/ppc.fs b/arch/ppc/ppc.fs index 0414f22..f3b439d 100644 --- a/arch/ppc/ppc.fs +++ b/arch/ppc/ppc.fs @@ -4,52 +4,91 @@ include config.fs \ registers \ -------------------------------------------------------------------------
-0 value %cr -0 value %ctr -0 value %lr -0 value %msr -0 value %srr0 -0 value %srr1 -0 value %pc \ should be an alias for %srr0 +: %cr saved-context h# 7 cells + @ ; +: %ctr saved-context h# 6 cells + @ ; +: %lr saved-context h# 1 cells + @ ; +\ 0 value %msr +\ 0 value %srr0 +\ 0 value %srr1 +\ 0 value %pc \ should be an alias for %srr0
-0 value %r0 -0 value %r1 -0 value %r2 -0 value %r3 -0 value %r4 -0 value %r5 -0 value %r6 -0 value %r7 -0 value %r8 -0 value %r9 -0 value %r10 -0 value %r11 -0 value %r12 -0 value %r13 -0 value %r14 -0 value %r15 -0 value %r16 -0 value %r17 -0 value %r18 -0 value %r19 -0 value %r20 -0 value %r21 -0 value %r22 -0 value %r23 -0 value %r24 -0 value %r25 -0 value %r26 -0 value %r27 -0 value %r28 -0 value %r29 -0 value %r30 -0 value %r31 +: %r0 saved-context h# 3 cells + @ ; +: %r1 saved-context h# 0 cells + @ ; +: %r2 saved-context h# 4 cells + @ ; +: %r3 saved-context h# 5 cells + @ ; +: %r4 saved-context h# 9 cells + @ ; +: %r5 saved-context h# a cells + @ ; +: %r6 saved-context h# b cells + @ ; +: %r7 saved-context h# c cells + @ ; +: %r8 saved-context h# d cells + @ ; +: %r9 saved-context h# e cells + @ ; +: %r10 saved-context h# f cells + @ ; +: %r11 saved-context h# 10 cells + @ ; +: %r12 saved-context h# 11 cells + @ ; +: %r13 saved-context h# 12 cells + @ ; +: %r14 saved-context h# 13 cells + @ ; +: %r15 saved-context h# 14 cells + @ ; +: %r16 saved-context h# 15 cells + @ ; +: %r17 saved-context h# 16 cells + @ ; +: %r18 saved-context h# 17 cells + @ ; +: %r19 saved-context h# 18 cells + @ ; +: %r20 saved-context h# 19 cells + @ ; +: %r21 saved-context h# 1a cells + @ ; +: %r22 saved-context h# 1b cells + @ ; +: %r23 saved-context h# 1c cells + @ ; +: %r24 saved-context h# 1d cells + @ ; +: %r25 saved-context h# 1e cells + @ ; +: %r26 saved-context h# 1f cells + @ ; +: %r27 saved-context h# 20 cells + @ ; +: %r28 saved-context h# 21 cells + @ ; +: %r29 saved-context h# 22 cells + @ ; +: %r30 saved-context h# 23 cells + @ ; +: %r31 saved-context h# 24 cells + @ ;
-0 value %xer -0 value %sprg0 -0 value %sprg1 -0 value %sprg2 -0 value %sprg3 +: %xer saved-context h# 8 cells + @ ; +\ 0 value %sprg0 +\ 0 value %sprg1 +\ 0 value %sprg2 +\ 0 value %sprg3 + +: .registers + cr + s" %cr: " type %cr u. cr + s" %ctr: " type %ctr u. cr + s" %lr: " type %lr u. cr + s" %r0: " type %r0 u. cr + s" %r1: " type %r1 u. cr + s" %r2: " type %r2 u. cr + s" %r3: " type %r3 u. cr + s" %r4: " type %r4 u. cr + s" %r5: " type %r5 u. cr + s" %r6: " type %r6 u. cr + s" %r7: " type %r7 u. cr + s" %r8: " type %r8 u. cr + s" %r9: " type %r9 u. cr + s" %r10: " type %r10 u. cr + s" %r11: " type %r11 u. cr + s" %r12: " type %r12 u. cr + s" %r13: " type %r13 u. cr + s" %r14: " type %r14 u. cr + s" %r15: " type %r15 u. cr + s" %r16: " type %r16 u. cr + s" %r17: " type %r17 u. cr + s" %r18: " type %r18 u. cr + s" %r19: " type %r19 u. cr + s" %r20: " type %r20 u. cr + s" %r21: " type %r21 u. cr + s" %r22: " type %r22 u. cr + s" %r23: " type %r23 u. cr + s" %r24: " type %r24 u. cr + s" %r25: " type %r25 u. cr + s" %r26: " type %r26 u. cr + s" %r27: " type %r27 u. cr + s" %r28: " type %r28 u. cr + s" %r29: " type %r29 u. cr + s" %r30: " type %r30 u. cr + s" %r31: " type %r31 u. cr +;
\ ------------------------------------------------------------------------- \ Load VGA FCode driver blob
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- arch/sparc32/build.xml | 1 + arch/sparc32/cpu.fs | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 arch/sparc32/cpu.fs
diff --git a/arch/sparc32/build.xml b/arch/sparc32/build.xml index 81c3586..976432c 100644 --- a/arch/sparc32/build.xml +++ b/arch/sparc32/build.xml @@ -1,6 +1,7 @@ <build condition="SPARC32">
<dictionary name="openbios-sparc32" init="openbios"> + <object source="cpu.fs" target="forth"/> <object source="tree.fs" target="forth"/> <object source="init.fs" target="forth"/> <object source="QEMU,tcx.bin" target="fcode" condition="DRIVER_SBUS"/> diff --git a/arch/sparc32/cpu.fs b/arch/sparc32/cpu.fs new file mode 100644 index 0000000..fab685a --- /dev/null +++ b/arch/sparc32/cpu.fs @@ -0,0 +1,100 @@ +include config.fs + +\ SPARC32 cpu registers + +: %g0 0 ; +: %g1 saved-context h# 14 + @ ; +: %g2 saved-context h# 18 + @ ; +: %g3 saved-context h# 1c + @ ; +: %g4 saved-context h# 20 + @ ; +: %g5 saved-context h# 24 + @ ; +: %g6 saved-context h# 28 + @ ; +: %g7 saved-context h# 2c + @ ; + +: %psr saved-context @ ; +: %wim saved-context h# 4 + @ ; +: %pc saved-context h# 250 + @ ; + +: set-pc ( addr ) + saved-context h# 250 + + ! +; + +: .globals + cr + s" %psr: " type %psr u. cr + s" %wim: " type %wim u. cr + s" %pc: " type %pc u. cr + s" %g0: " type %g0 u. cr + s" %g1: " type %g1 u. cr + s" %g2: " type %g2 u. cr + s" %g3: " type %g3 u. cr + s" %g4: " type %g4 u. cr + s" %g5: " type %g5 u. cr + s" %g6: " type %g6 u. cr + s" %g7: " type %g7 u. cr +; + +\ Local registers +\ WARNING: currently only window 0 (current window) supported + +: %o0 saved-context h# 30 + @ ; +: %o1 saved-context h# 34 + @ ; +: %o2 saved-context h# 38 + @ ; +: %o3 saved-context h# 3c + @ ; +: %o4 saved-context h# 40 + @ ; +: %o5 saved-context h# 44 + @ ; +: %o6 saved-context h# 48 + @ ; +: %o7 saved-context h# 4c + @ ; + +: %l0 saved-context h# 50 + @ ; +: %l1 saved-context h# 54 + @ ; +: %l2 saved-context h# 58 + @ ; +: %l3 saved-context h# 5c + @ ; +: %l4 saved-context h# 60 + @ ; +: %l5 saved-context h# 64 + @ ; +: %l6 saved-context h# 68 + @ ; +: %l7 saved-context h# 6c + @ ; + +: %i0 saved-context h# 70 + @ ; +: %i1 saved-context h# 74 + @ ; +: %i2 saved-context h# 78 + @ ; +: %i3 saved-context h# 7c + @ ; +: %i4 saved-context h# 80 + @ ; +: %i5 saved-context h# 84 + @ ; +: %i6 saved-context h# 88 + @ ; +: %i7 saved-context h# 8c + @ ; + +: .locals + cr + s" %o0: " type %o0 u. cr + s" %o1: " type %o1 u. cr + s" %o2: " type %o2 u. cr + s" %o3: " type %o3 u. cr + s" %o4: " type %o4 u. cr + s" %o5: " type %o5 u. cr + s" %o6: " type %o6 u. cr + s" %o7: " type %o7 u. cr + cr + s" %l0: " type %l0 u. cr + s" %l1: " type %l1 u. cr + s" %l2: " type %l2 u. cr + s" %l3: " type %l3 u. cr + s" %l4: " type %l4 u. cr + s" %l5: " type %l5 u. cr + s" %l6: " type %l6 u. cr + s" %l7: " type %l7 u. cr + cr + s" %i0: " type %i0 u. cr + s" %i1: " type %i1 u. cr + s" %i2: " type %i2 u. cr + s" %i3: " type %i3 u. cr + s" %i4: " type %i4 u. cr + s" %i5: " type %i5 u. cr + s" %i6: " type %i6 u. cr + s" %i7: " type %i7 u. cr +; + +: .registers + .globals .locals +;
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- arch/sparc64/build.xml | 1 + arch/sparc64/cpu.fs | 156 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 arch/sparc64/cpu.fs
diff --git a/arch/sparc64/build.xml b/arch/sparc64/build.xml index 3a1cd34..c5afb82 100644 --- a/arch/sparc64/build.xml +++ b/arch/sparc64/build.xml @@ -1,6 +1,7 @@ <build condition="SPARC64">
<dictionary name="openbios-sparc64" init="openbios"> + <object source="cpu.fs" target="forth"/> <object source="tree.fs" target="forth"/> <object source="init.fs" target="forth"/> <object source="QEMU,VGA.bin" target="fcode" condition="DRIVER_VGA"/> diff --git a/arch/sparc64/cpu.fs b/arch/sparc64/cpu.fs new file mode 100644 index 0000000..b0aa611 --- /dev/null +++ b/arch/sparc64/cpu.fs @@ -0,0 +1,156 @@ +include config.fs + +\ SPARC64 trap registers + +: %tl-c saved-context h# c8 + @ ; + +: tl-offset ( level -- offset ) + h# 20 * h# 4e0 h# 60 + swap - ; +; + +: %tpc ( level -- n ) tl-offset saved-context + @ ; +: %tnpc ( level -- n ) tl-offset saved-context + h# 8 + @ ; +: %tstate ( level -- n ) tl-offset saved-context + h# 10 + @ ; +: %tt ( level -- n ) tl-offset saved-context + h# 18 + @ ; + +: .trap-registers + cr + s" %tl-c: " type %tl-c u. cr + s" %tpc: " type %tl-c %tpc u. cr + s" %tnpc: " type %tl-c %tnpc u. cr + s" %tstate: " type %tl-c %tstate u. cr + s" %tt: " type %tl-c %tt u. cr +; + +: trap? %tl-c 0 > if true else false then ; + +\ SPARC64 cpu registers + +: %g0 0 ; +: %g1 saved-context h# 30 + @ ; +: %g2 saved-context h# 38 + @ ; +: %g3 saved-context h# 40 + @ ; +: %g4 saved-context h# 48 + @ ; +: %g5 saved-context h# 50 + @ ; +: %g6 saved-context h# 58 + @ ; +: %g7 saved-context h# 60 + @ ; + +: %pc + trap? if + %tl-c %tpc + else + saved-context h# 4d0 + @ + then +; + +: %npc + trap? if + %tl-c %tnpc + else + saved-context h# 4d8 + @ + then +; + +: set-pc ( addr ) + saved-context h# 4d0 + + ! +; + +: %pstate saved-context h# b0 + @ ; +: %y saved-context h# b8 + @ ; + +: %cwp saved-context @ ; +: %cansave saved-context h# 8 + @ ; +: %canrestore saved-context h# 10 + @ ; +: %otherwin saved-context h# 18 + @ ; +: %wstate saved-context h# 20 + @ ; +: %cleanwin saved-context h# 28 + @ ; + +: .globals + cr + s" %pstate: " type %pstate u. cr + s" %y: " type %y u. cr + s" %pc: " type %pc u. cr + s" %npc: " type %npc u. cr + s" %cwp: " type %cwp u. cr + s" %cansave: " type %cansave u. cr + s" %canrestore: " type %canrestore u. cr + s" %otherwin: " type %otherwin u. cr + s" %wstate: " type %wstate u. cr + s" %cleanwin: " type %cleanwin u. cr + s" %g0: " type %g0 u. cr + s" %g1: " type %g1 u. cr + s" %g2: " type %g2 u. cr + s" %g3: " type %g3 u. cr + s" %g4: " type %g4 u. cr + s" %g5: " type %g5 u. cr + s" %g6: " type %g6 u. cr + s" %g7: " type %g7 u. cr +; + +\ Local registers +\ WARNING: currently only window 0 (current window) supported + +: %o0 saved-context h# 70 + @ ; +: %o1 saved-context h# 78 + @ ; +: %o2 saved-context h# 80 + @ ; +: %o3 saved-context h# 88 + @ ; +: %o4 saved-context h# 90 + @ ; +: %o5 saved-context h# 98 + @ ; +: %o6 saved-context h# a0 + @ ; +: %o7 saved-context h# a8 + @ ; + +: %l0 saved-context h# d0 + @ ; +: %l1 saved-context h# d8 + @ ; +: %l2 saved-context h# e0 + @ ; +: %l3 saved-context h# e8 + @ ; +: %l4 saved-context h# f0 + @ ; +: %l5 saved-context h# f8 + @ ; +: %l6 saved-context h# 100 + @ ; +: %l7 saved-context h# 108 + @ ; + +: %i0 saved-context h# 110 + @ ; +: %i1 saved-context h# 118 + @ ; +: %i2 saved-context h# 120 + @ ; +: %i3 saved-context h# 128 + @ ; +: %i4 saved-context h# 130 + @ ; +: %i5 saved-context h# 138 + @ ; +: %i6 saved-context h# 140 + @ ; +: %i7 saved-context h# 148 + @ ; + +: .locals + cr + s" %o0: " type %o0 u. cr + s" %o1: " type %o1 u. cr + s" %o2: " type %o2 u. cr + s" %o3: " type %o3 u. cr + s" %o4: " type %o4 u. cr + s" %o5: " type %o5 u. cr + s" %o6: " type %o6 u. cr + s" %o7: " type %o7 u. cr + cr + s" %l0: " type %l0 u. cr + s" %l1: " type %l1 u. cr + s" %l2: " type %l2 u. cr + s" %l3: " type %l3 u. cr + s" %l4: " type %l4 u. cr + s" %l5: " type %l5 u. cr + s" %l6: " type %l6 u. cr + s" %l7: " type %l7 u. cr + cr + s" %i0: " type %i0 u. cr + s" %i1: " type %i1 u. cr + s" %i2: " type %i2 u. cr + s" %i3: " type %i3 u. cr + s" %i4: " type %i4 u. cr + s" %i5: " type %i5 u. cr + s" %i6: " type %i6 u. cr + s" %i7: " type %i7 u. cr +; + +: .registers + .globals .locals +; + +\ Used by Milax +variable warning
On 08/10/16 11:56, Mark Cave-Ayland wrote:
The motivation behind the previous context work was to enable access to the saved context in Forth, e.g. some SPARC64 bootloaders will attempt to read the saved register values.
This patch enables read-only access to the CPU registers in Forth for PPC, SPARC32 and SPARC64 whilst also implementing the IEEE-1275 .registers word.
NOTE: the primary reason this is read-only is because currently there exists no Forth CFA that can evaluate an xt and use the result as part of a "<value> to %g1" construction.
Mark Cave-Ayland (6): Make current CPU context available in Forth libopenbios: don't display output on execution of "go" word ppc: fix off-by-one error for register r4 in context switch ppc: add basic read-only Forth register support SPARC32: add basic read-only Forth register support SPARC64: add basic read-only Forth register support
arch/ppc/ppc.fs | 127 +++++++++++++++++++++++------------- arch/ppc/qemu/switch.S | 2 +- arch/sparc32/build.xml | 1 + arch/sparc32/cpu.fs | 100 +++++++++++++++++++++++++++++ arch/sparc64/build.xml | 1 + arch/sparc64/cpu.fs | 156 +++++++++++++++++++++++++++++++++++++++++++++ forth/debugging/client.fs | 6 ++ libopenbios/init.c | 4 ++ libopenbios/initprogram.c | 16 +---- 9 files changed, 354 insertions(+), 59 deletions(-) create mode 100644 arch/sparc32/cpu.fs create mode 100644 arch/sparc64/cpu.fs
No comments received on this, so I've pushed it to git master since I have another couple of outstanding patchsets that build upon the work done here.
ATB,
Mark.