Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / os / bootprom / dlbin.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: dlbin.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)dlbin.fth 2.14 97/08/11
43purpose:
44copyright: Copyright 1990-1995 Sun Microsystems, Inc. All Rights Reserved
45
46\ Download a.out files over a serial line to a stand-alone Forth system.
47
48decimal
49
50headerless
51headers
52
53\ Move all these out of the way.
54vocabulary dloader also dloader definitions
55
56variable charbuf
57variable dl.break
58variable dl.read
59variable dl.handle
60
61: dl-call ( xxx -- xxx ) dl.handle @ call-package ;
62
63: getbyte ( -- char )
64 begin dl.break @ dl-call charbuf 1 dl.read @ dl-call 0> until
65 charbuf c@
66;
67: getbytes ( adr len -- adr+len )
68 over + tuck swap ?do getbyte i c! loop
69;
70
71: .cantfind ( adr,len -- true )
72 ." Unable find " type ." method" cr true
73;
74
75: setup-dload ( -- )
76 0 0 ttya expand-alias drop ( 0 0 str,len )
77 $open-package ?dup 0= if ( ihandle )
78 ." ttya didn't open" cr ( -- )
79 true exit ( -- )
80 then dl.handle ! ( ihandle )
81 " read" 2dup ( str,len str,len )
82 dl.handle @ ihandle>phandle ( str,len str,len phandle )
83 find-method if ( str,len acf )
84 dl.read ! ( str,len )
85 2drop " poll-tty" 2dup ( str,len str,len )
86 dl.handle @ ihandle>phandle ( str,len str,len phandle )
87 find-method if ( str,len acf )
88 dl.break ! ( str,len )
89 2drop false exit ( false )
90 then ( adr,len )
91 then ( str,len )
92 .cantfind ( -- true )
93;
94
95\ Throw out junk until we see the start of the header
96: consume ( -- ) begin getbyte 1 = until ;
97
98: gettext ( adr len -- adr actual )
99 bounds 2dup ?do ( end start )
100 getbyte dup control D = if ( end start char )
101 drop nip i swap leave ( end' start )
102 then ( end start char )
103 i c!
104 loop ( end' start )
105 tuck - ( adr actual )
106;
107
108previous definitions
109also dloader
110headers
111
112: dlbin ( -- )
113 cleanup setup-dload if exit then
114 ." Ready for download. Send binary file." cr
115 consume
116 1 a.out-header c! \ consume ate the first header byte
117 a.out-header 1+ /a.out-header 1- getbytes drop \ Read the header
118
119 \ Verify the magic number; if it's wrong, then you have to abort with
120 \ a break character.
121 a.out-header a_magic w@ h# 107 <> if begin getbyte drop again then
122
123 entry-adr ( tadr ) \ Read the file segments
124 /text getbytes ( dadr )
125 /data getbytes ( radr )
126 /reloc l->n -1 <> if /reloc getbytes then ( sadr )
127 /syms getbytes ( stradr )
128
129 /syms if ( string-table-adr )
130 4 getbytes ( rest-of-string-table-adr )
131 dup 4 - @ 4 - getbytes ( string-table-end-adr )
132 then ( end-adr )
133 (init-program) ( end-adr )
134 entry-adr set-pc ( end-adr )
135 entry-adr /a.out-header - tuck - initsyms ( )
136 entry-adr /text + /data + /bss erase ( )
137;
138
139: sload ( -- )
140 cleanup setup-dload if exit then
141 ." Ready for download. Send file then type ^D" cr
142 load-base h# 20000
143 \ Turn off interrupts for now because the interrupt handler takes too long
144 \ and we lose characters.
145 lock[ ['] gettext catch ]unlock ?dup if throw then ( adr len )
146 file-size ! drop
147;
148: dl ( -- ) sload load-base file-size @ interpret-string ;
149
150previous
151