~ubuntu-branches/ubuntu/hardy/silo/hardy-updates

« back to all changes in this revision

Viewing changes to first/ieee32.S

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2007-10-25 09:28:08 UTC
  • mfrom: (15.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071025092808-1yhj12t7s4zqsfu5
Tags: 1.4.13a+git20070930-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Build with -fno-stack-protector.
  - Change silo.postinst to automatically update the boot block without
    invoking siloconfig and keep asking questions on upgrades.
  - Convert silo.conf to use /dev/disk/by-uuid.
  - Ubuntu maintainer foobar.
  - Fix debian/rules call to dh_installdocs.
  - Drop the requirement of gcc-4.1 and start using default gcc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* First stage loader bootstrap for flash of a JavaStation.
 
2
 
 
3
   Copyright (C) 1996,1997,2000 Jakub Jelinek
 
4
   Copyright (C) 1999,2000 Pete Zaitcev
 
5
 
 
6
   This program is free software; you can redistribute it and/or modify
 
7
   it under the terms of the GNU General Public License as published by
 
8
   the Free Software Foundation; either version 2 of the License, or
 
9
   (at your option) any later version.
 
10
   
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program; if not, write to the Free Software
 
18
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
19
   USA.  */
 
20
 
 
21
#define BLOCK_START     0x300   /* We are not a.out, so can use anything */
 
22
#include "ieee32.h"             /* IEEE32_OFFSET */
 
23
#define LOAD_OFF        1024    /* Skip PROM interface buffer */
 
24
 
 
25
#define buffer          %l3
 
26
#define dest            %l4
 
27
#define promvec         %l5
 
28
#define fd              %l6
 
29
#define stdouth         %l7
 
30
 
 
31
        .text
 
32
        .align 4
 
33
        .global _start
 
34
 
 
35
_start:
 
36
        ba      1f
 
37
         sethi  %hi(0x4000), buffer
 
38
        .ascii  IMGVERSION
 
39
1:      sethi   %hi(0x10000), dest
 
40
        mov     %o3, promvec
 
41
 
 
42
        add     buffer, %lo(chosen), %o1
 
43
        call    prom11
 
44
         add    buffer, %lo(finddevice), %o0
 
45
        ld      [dest + 16], fd
 
46
 
 
47
        call    getprop
 
48
         add    buffer, %lo(stdout), %o0
 
49
        ld      [dest + 256], stdouth
 
50
 
 
51
        call    putchar
 
52
         mov    'S', %o0
 
53
 
 
54
        /*
 
55
         * Get phandle of flash memory.
 
56
         * Unlike other first stage loaders
 
57
         * we do not use "/chosen"."bootpath" value.
 
58
         * It's a feature, not a bug.
 
59
         */
 
60
        add     buffer, %lo(flashs), %o1
 
61
        call    prom11
 
62
         add    buffer, %lo(finddevice), %o0
 
63
        ld      [dest + 16], fd         /* phandle of /flash-memory */
 
64
 
 
65
        /*
 
66
         * Get "reg". We use it to find the base address,
 
67
         * which is different for 4MB, 8MB and 16MB SIMMs.
 
68
         */
 
69
        call    getprop
 
70
         add    buffer, %lo(regs), %o0
 
71
        ld      [dest + 260], %i2       /* 20400000 for 8MB SIMM */
 
72
 
 
73
        /*
 
74
         * Load 4 blocks of second stage loader with the map,
 
75
         * then all other blocks at 0x10000 (dest).
 
76
         * First of them will have an 'L' header embedded.
 
77
         */
 
78
        or      buffer, BLOCK_START, %l1
 
79
        add     %l1, (3 * 512), %i5     /* Will read 4 blocks of block map */
 
80
        mov     %l1, %l2
 
81
        /*
 
82
         * But before we start the loop, get the block 0 number.
 
83
         * In other loaders we get it for free when 16 blocks of
 
84
         * bootstrap are loaded. In flash it is outside of ELF.
 
85
         */
 
86
        add     %i2, IEEE32_OFFSET, %i4
 
87
        lda     [%i4] 0x20, %i3
 
88
        st      %i3, [%l2]
 
89
 
 
90
5:
 
91
        ld      [%l2], %i3
 
92
        subcc   %i3, 0, %g0
 
93
        add     %l2, 4, %l2
 
94
        bz      7f
 
95
         sll    %i3, 9, %o3             /* Convert blocks into bytes */
 
96
        /* srl  %i3, 23, %o2 */         /* %o2 and %o3 make an 41 bits offset */
 
97
 
 
98
        /*
 
99
         * blkblt
 
100
         * We use ASI=20 (BYPASS) to spare remapping work. Lazy, but works.
 
101
         * We do not unroll the loop because flash is slow and RAM is tight.
 
102
         */
 
103
        mov     512, %i0                /* running cnt */
 
104
        mov     %l1, %i1                /* running dest */
 
105
        add     %i2, %o3, %i4           /* running source (physical addr) */
 
106
        /* We conviniently ignore upper bits of offset for flash is small. */
 
107
1:
 
108
        lda     [%i4] 0x20, %i3
 
109
        st      %i3, [%i1]
 
110
        add     %i4, 4, %i4
 
111
        add     %i1, 4, %i1
 
112
        subcc   %i0, 4, %i0
 
113
        bne     1b
 
114
         nop
 
115
 
 
116
        cmp     %l1, %i5
 
117
        bne     5b
 
118
         add    %l1, 512, %l1
 
119
 
 
120
        call    putchar
 
121
         mov    'I', %o0
 
122
        b       5b
 
123
         add    dest, LOAD_OFF, %l1
 
124
 
 
125
7:
 
126
        ldub    [dest + LOAD_OFF + 0x08], %o0
 
127
        cmp     %o0, 'L'
 
128
        bne     exit
 
129
         nop
 
130
        call    putchar
 
131
         nop
 
132
        /* flush dest + LOAD_OFF */  /* XXX Write-through cache on IIep */
 
133
 
 
134
        clr     %o4                     /* Important - not Ultra */
 
135
        or      promvec, 1, %o0         /* XXX Gross... */
 
136
        clr     %o3                     /* Hmm... */
 
137
        jmpl    dest + LOAD_OFF, %g0
 
138
         clr    %l3
 
139
 
 
140
exit:
 
141
        add     buffer, %lo(exits), %o0
 
142
        call    prom11
 
143
         st     %o0, [dest + 16]
 
144
 
 
145
/*
 
146
 * getprop(node:fd, name:%o0) {
 
147
 *   cif_handler:promvec("getprops", node, name, dest+256, 1024);
 
148
 * }
 
149
 */
 
150
getprop:
 
151
        add     buffer, %lo(getprops), %o2
 
152
        st      %o2, [dest]
 
153
        mov     4, %o2
 
154
        st      %o2, [dest + 4]
 
155
        mov     1, %o2
 
156
        st      %o2, [dest + 8]
 
157
        st      fd, [dest + 12]
 
158
        st      %o0, [dest + 16]
 
159
        add     dest, 256, %o0
 
160
        st      %o0, [dest + 20]
 
161
        mov     1024, %o0
 
162
        st      %o0, [dest + 24]
 
163
        jmpl    promvec + %g0, %g0
 
164
         mov    dest, %o0
 
165
 
 
166
/*
 
167
 */
 
168
putchar:
 
169
        stb     %o0, [buffer]
 
170
        mov     stdouth, %o1
 
171
        mov     buffer, %o2
 
172
        mov     1, %o3
 
173
        ba      prom31                  /* one of many tail recustion -O's */
 
174
         add    buffer, %lo(write), %o0
 
175
 
 
176
/*
 
177
 * One in, one out.
 
178
 */
 
179
prom11:
 
180
        st      %o0, [dest]
 
181
        mov     1, %o2
 
182
        st      %o2, [dest + 4]
 
183
        st      %o2, [dest + 8]
 
184
        st      %o1, [dest + 12]
 
185
        jmpl    promvec + %g0, %g0
 
186
         mov    dest, %o0
 
187
 
 
188
/*
 
189
 * Three in, one out.
 
190
 */
 
191
prom31:
 
192
        st      %o0, [dest]
 
193
        mov     3, %o4
 
194
        st      %o4, [dest + 4]
 
195
        mov     1, %o4
 
196
        st      %o4, [dest + 8]
 
197
        st      %o1, [dest + 12]
 
198
        st      %o2, [dest + 16]
 
199
        st      %o3, [dest + 20]
 
200
        jmpl    promvec + %g0, %g0
 
201
         mov    dest, %o0
 
202
 
 
203
finddevice:
 
204
        .asciz  "finddevice"
 
205
getprops:
 
206
        .asciz  "getprop"
 
207
stdout:
 
208
        .asciz  "stdout"
 
209
write:
 
210
        .asciz  "write"
 
211
chosen:
 
212
        .asciz  "/chosen"
 
213
exits:
 
214
        .asciz  "exit"
 
215
flashs:
 
216
        .asciz  "/flash-memory"
 
217
regs:
 
218
        .asciz  "reg"