Author: wmb
Date: 2009-10-02 23:59:51 +0200 (Fri, 02 Oct 2009)
New Revision: 1386
Added:
cpu/x86/pc/mmxdot.fth
cpu/x86/pc/mmxdotcode.fth
Modified:
cpu/x86/pc/ramtest.fth
Log:
X86 - Added early startup diagnostic routines that use MMX registers
to avoid the need for memory, while preserving the general register state.
Added: cpu/x86/pc/mmxdot.fth
===================================================================
--- cpu/x86/pc/mmxdot.fth (rev 0)
+++ cpu/x86/pc/mmxdot.fth 2009-10-02 21:59:51 UTC (rev 1386)
@@ -0,0 +1,75 @@
+\ See license at end of file
+purpose: Assemble a call to the mm0dot routine, preserving general registers
+
+: mmxsave ( -- ) " ax mm7 movd" eval ;
+: mmxrestore ( -- ) " mm7 ax movd" eval ;
+: mmxarg ( ea -- ) " mm0 movd" eval ; \ Put numeric argument in mm0
+: mmx#arg ( immed -- ) " # ax mov ax mm0 movd" eval ;
+: mmx#arg1 ( immed -- ) " # ax mov ax mm1 movd" eval ;
+: mmxcall ( name$ -- )
+ here asm-base - asm-origin + d# 10 + " # ax mov" eval \ 5 bytes - return address in ax
+ eval " #) jmp" eval \ 5 bytes
+;
+: mmxdot ( ea -- )
+ mmxsave
+ mmxarg
+ " mm0dot" mmxcall
+ mmxrestore
+;
+: #mmxdot ( immed -- )
+ mmxsave
+ mmx#arg " mm0dot" mmxcall
+ mmxrestore
+;
+: mmxemit ( char-ea -- )
+ mmxsave
+ mmxarg " mm0emit" mmxcall
+ mmxrestore
+;
+: #mmxemit ( immed-char -- )
+ mmxsave
+ mmx#arg " mm0emit" mmxcall
+ mmxrestore
+;
+: #mmxdump ( adr-immed len-immed -- )
+ mmxsave
+ mmx#arg1 mmx#arg " mm0dump" mmxcall
+ mmxrestore
+;
+: mmxdump ( adr-ea len-immed -- )
+ mmxsave ( adr-ea len-immed )
+ \ Do ea arg first in case it refers to ax; otherwise mmx#arg1 would clobber ax
+ >r mmx#arg r> ( len-immed )
+ mmx#arg1 " mm0dump" mmxcall
+ mmxrestore
+;
+: #mmxcfg-dump ( adr-immed len-immed -- )
+ mmxsave
+ mmx#arg1 mmx#arg " mm0cfg-dump" mmxcall
+ mmxrestore
+;
+: mmxcr ( -- ) carret #mmxemit linefeed #mmxemit ;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2009 FirmWorks
+\
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END
Added: cpu/x86/pc/mmxdotcode.fth
===================================================================
--- cpu/x86/pc/mmxdotcode.fth (rev 0)
+++ cpu/x86/pc/mmxdotcode.fth 2009-10-02 21:59:51 UTC (rev 1386)
@@ -0,0 +1,226 @@
+\ See license at end of file
+purpose: Low-level numeric output for tracing startup code
+
+\ Requires MMX registers
+
+protected-mode
+
+label mm0emit ( mm0: char ax: retadr -- )
+ ax mm1 movd
+ dx mm4 movd
+
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+ h# 3f8 # dx mov mm0 ax movd al dx out
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+
+ mm4 dx movd
+ mm1 ax movd
+
+ ax jmp
+end-code
+
+label mm0dot ( mm0: n ax: retadr -- )
+ ax mm1 movd
+ bx mm2 movd
+ cx mm3 movd
+ dx mm4 movd
+
+ mm0 bx movd
+ 8 # cx mov
+
+ begin
+ bx 4 # rol
+ bl al mov
+
+ h# f # al and
+ d# 10 # al cmp
+ >= if
+ ascii a d# 10 - # al add
+ else
+ ascii 0 # al add
+ then
+
+ al ah mov
+
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+ 3f8 # dx mov ah al mov al dx out
+ loopa
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+ h# 3f8 # dx mov h# 20 # al mov al dx out
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+
+ mm4 dx movd
+ mm3 cx movd
+ mm2 bx movd
+ mm1 ax movd
+
+ ax jmp
+end-code
+
+label mm0dump ( mm0: adr mm1: len ax: retadr -- )
+ ax mm6 movd
+ bx mm5 movd
+ cx mm4 movd
+ dx mm3 movd
+ si mm2 movd
+
+ mm0 si movd
+ mm1 cx movd
+
+ begin
+ al lods
+ al bl mov
+
+ bl al mov
+
+ 4 # al shr
+ h# f # al and
+ d# 10 # al cmp
+ >= if
+ ascii a d# 10 - # al add
+ else
+ ascii 0 # al add
+ then
+
+ al ah mov
+
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+ 3f8 # dx mov ah al mov al dx out
+
+ bl al mov
+
+ h# f # al and
+ d# 10 # al cmp
+ >= if
+ ascii a d# 10 - # al add
+ else
+ ascii 0 # al add
+ then
+
+ al ah mov
+
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+ 3f8 # dx mov ah al mov al dx out
+
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+
+ si ax mov h# f # al and 0= if
+ h# 0d # al mov h# 3f8 # dx mov al dx out
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+ h# 0a # al mov h# 3f8 # dx mov al dx out
+ else
+ h# 20 # al mov h# 3f8 # dx mov al dx out
+ then
+
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+ cx dec 0= until
+
+ mm2 si movd
+ mm3 dx movd
+ mm4 cx movd
+ mm5 bx movd
+ mm6 ax movd
+
+ ax jmp
+end-code
+
+label mm0cfg-dump ( mm0: adr mm1: len ax: retadr -- )
+ ax mm6 movd
+ bx mm5 movd
+ cx mm4 movd
+ dx mm3 movd
+ si mm2 movd
+
+ mm0 si movd
+ mm1 cx movd
+
+ begin
+ si ax mov
+ h# 7fff.fffc # ax and
+ h# 8000.0000 # ax or
+ h# cf8 # dx mov
+ ax dx out
+ si dx mov
+ 3 # dx and
+ h# cfc # dx add
+ dx al in
+ si inc
+
+ al bl mov
+
+ bl al mov
+
+ 4 # al shr
+ h# f # al and
+ d# 10 # al cmp
+ >= if
+ ascii a d# 10 - # al add
+ else
+ ascii 0 # al add
+ then
+
+ al ah mov
+
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+ 3f8 # dx mov ah al mov al dx out
+
+ bl al mov
+
+ h# f # al and
+ d# 10 # al cmp
+ >= if
+ ascii a d# 10 - # al add
+ else
+ ascii 0 # al add
+ then
+
+ al ah mov
+
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+ 3f8 # dx mov ah al mov al dx out
+
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+
+ si ax mov h# f # al and 0= if
+ h# 0d # al mov h# 3f8 # dx mov al dx out
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+ h# 0a # al mov h# 3f8 # dx mov al dx out
+ else
+ h# 20 # al mov h# 3f8 # dx mov al dx out
+ then
+
+ h# 3fd # dx mov begin dx al in h# 40 # al and 0<> until
+ cx dec 0= until
+
+ mm2 si movd
+ mm3 dx movd
+ mm4 cx movd
+ mm5 bx movd
+ mm6 ax movd
+
+ ax jmp
+end-code
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2009 FirmWorks
+\
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END
Modified: cpu/x86/pc/ramtest.fth
===================================================================
--- cpu/x86/pc/ramtest.fth 2009-10-02 21:58:33 UTC (rev 1385)
+++ cpu/x86/pc/ramtest.fth 2009-10-02 21:59:51 UTC (rev 1386)
@@ -1,9 +1,9 @@
\ This can be included in-line in the early startup code, just
\ after memory controller turn-on, to verify basic RAM sanity.
+ramtest-start #mmxdot mmxcr
+
ascii I report ascii n report ascii c report
-carret report linefeed report
-\ here asm-base - ResetBase + .x cr
ramtest-start # ax mov
begin
ax 0 [ax] mov
@@ -11,15 +11,18 @@
ramtest-end # ax cmp
0= until
+ascii . report
+
ramtest-start # ax mov
begin
0 [ax] bx mov
- ax bx cmp <> if
- ax di mov
+ \ ax bx cmp <> if
+ax bx cmp <> if
+ ax mmxdot
+ bx mmxdot
+ 0 [ax] mmxdot
ascii B report ascii A report ascii D report
- di ax mov dot #) call
- 0 [di] ax mov dot #) call
-1 [if] \ Fire up C Forth
+0 [if] \ Fire up C Forth
dcached-base 6 + 0 206 set-msr \ Dcache base address, write back
/dcached negate h# 800 + f 207 set-msr \ Dcache size
\ This region is for CForth
@@ -42,9 +45,7 @@
h# ffff.0000 # ax mov ax jmp
[then]
-
-
- begin again
+ begin hlt again
then
4 # ax add
ramtest-end # ax cmp
@@ -53,7 +54,6 @@
carret report linefeed report
ascii P report ascii a report ascii t report ascii 5 report
-carret report linefeed report
ramtest-start # ax mov
begin
h# 55555555 # 0 [ax] mov
@@ -61,14 +61,16 @@
ramtest-end # ax cmp
0= until
+ascii . report
+
ramtest-start # ax mov
begin
0 [ax] bx mov
h# 55555555 # bx cmp <> if
- ( bx ax mov ) dot #) call
+ ax mmxdot
+ bx mmxdot
ascii B report ascii A report ascii D report
- h# ffff.0000 # ax mov ax jmp \ CForth
- begin again
+ begin hlt again
then
4 # ax add
ramtest-end # ax cmp
@@ -77,7 +79,6 @@
carret report linefeed report
ascii P report ascii a report ascii t report ascii A report
-carret report linefeed report
ramtest-start # ax mov
begin
h# aaaaaaaa # 0 [ax] mov
@@ -85,12 +86,16 @@
ramtest-end # ax cmp
0= until
+ascii . report
+
ramtest-start # ax mov
begin
0 [ax] bx mov
h# aaaaaaaa # bx cmp <> if
+ ax mmxdot
+ bx mmxdot
ascii B report ascii A report ascii D report
- begin again
+ begin hlt again
then
4 # ax add
ramtest-end # ax cmp