\ ========== Copyright Header Begin ==========================================
\ Hypervisor Software File: register.fth
\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
\ - Do no alter or remove copyright notices
\ - Redistribution and use of this software in source and binary forms, with
\ or without modification, are permitted provided that the following
\ - Redistribution of source code must retain the above copyright notice,
\ this list of conditions and the following disclaimer.
\ - Redistribution in binary form must reproduce the above copyright notice,
\ this list of conditions and the following disclaimer in the
\ documentation and/or other materials provided with the distribution.
\ Neither the name of Sun Microsystems, Inc. or the names of contributors
\ may be used to endorse or promote products derived from this software
\ without specific prior written permission.
\ This software is provided "AS IS," without a warranty of any kind.
\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
\ You acknowledge that this software is not designed, licensed or
\ intended for use in the design, construction, operation or maintenance of
\ ========== Copyright Header End ============================================
id: @(#)register.fth 2.16 07/06/05 10:54:45
purpose: Register names for saved program state
copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
copyright: Use is subject to license terms.
\ Copyright 1985-1990 Bradley Forthware
\ This version uses multiple-code-field defining words for the self-fetching
\ Display and modify the saved state of the machine.
\ This code is highly machine-dependent.
\ Version for the SPARC processor
\ >state ( offset -- addr )
\ Returns an address within the processor state array given the
\ The number of implemented register windows
\ window-registers ( -- offset )
\ The offset from CPU-STATE to the start of the area where the
\ window registers are stored
\ %g0 .. %g7 %o0 .. %o7 %l0 .. %l7 %i0 .. %i7
\ V8, Priviliged: %wim %tbr
needs action: objects.fth
only forth hidden also forth also definitions
action: @ >state ! ; ( is )
action: @ >state ; ( addr )
: global-reg \ name ( offset -- offset+/n )
: global-regs \ name name ... ( offset #regs -- offset' )
( offset #regs ) 0 ?do global-reg loop ( offset' )
: offset-of \ name ( -- offset )
parse-word ['] forth $vfind if
." offset-of can't find " type cr
: >outreg ( reg# -- ) previous-outs @ + ;
: >window ( reg# -- ) view-window @ + ;
action: @ >window ! ; ( is )
action: @ >window ; ( addr )
: local-regs \ name name ... ( reg# #regs -- )
bounds ?do create i /n* , use-actions loop
action: @ >outreg ! ; ( is )
action: @ >outreg ; ( addr )
: out-regs \ name name ... ( #regs -- )
( #regs ) 0 do create i /n* , use-actions loop
4 global-regs %pc %npc %y %psr
8 global-regs %g0 %g1 %g2 %g3 %g4 %g5 %g6 %g7
2 global-regs %state-valid %restartable?
\ Following words defined here to satisfy the
\ references to these "variables" anywhere else
: state-valid ( -- addr ) addr %state-valid ;
: restartable? ( -- addr ) addr %restartable? ;
3 global-regs %saved-my-self last-trap# error-reset-trap
\ Following words defined here to satisfy the
\ references to these "variables" anywhere else
: saved-my-self ( -- addr ) addr %saved-my-self ;
\ The set of out registers has to be defined as a single batch.
\ They can't be defined piecemeal like global registers.
\ The set of local registers must be "batched" too.
8 out-regs %o0 %o1 %o2 %o3 %o4 %o5 %o6 %o7
0 8 local-regs %l0 %l1 %l2 %l3 %l4 %l5 %l6 %l7
8 8 local-regs %i0 %i1 %i2 %i3 %i4 %i5 %i6 %i7
false value standalone? \ Can be used to turn off stuff in stand.exe
: aligned? ( adr -- flag ) 3 and 0= ;
defer accessible? ( adr -- flag )
: yes-accessible ( adr -- true ) drop true ;
' yes-accessible is accessible?
\ Invalid, unaligned, or inaccessible call point
: pointer-bad? ( adr -- flag ) \ True if the address is not a good pointer
dup 0<> over aligned? and swap accessible? and 0=
window-registers >state dup previous-outs ! 8 na+ view-window !
\ cached-window? can be used in cases where the hardware register windows
\ are saved in a place other than on the stack.
defer cached-window? ( -- [ last? ] handled? ) ' false is cached-window?
cached-window? if exit then
%i6 pointer-bad? %i6 0= or if
: +w ( -- ) (+w) abort" No more valid windows" ;
: set-window ( n -- ) 0w ( n ) 0 ?do (+w) ?leave loop ;
dup set-window window# <> if
." Window number too large. The maximum number is " window# . cr
defer .other-regs ' noop is .other-regs
." %g0 %g1 %g2 %g3 %g4 %g5 %g6 %g7" cr
." " addr %g0 8 .ndump cr
." " %pc .nx %npc .nx %y .nx cr
." IN: " addr %i0 8 .ndump cr
." LOC:" addr %l0 8 .ndump cr
." OUT:" addr %o0 8 .ndump cr
: init-window ( -- ) 0w ;
: .window ( window# -- ) w .locals ;
only forth also definitions