os.s revision 1.1 1 1.1 is #
2 1.1 is # $NetBSD: os.s,v 1.1 2000/04/14 20:24:39 is Exp $
3 1.1 is #
4 1.1 is
5 1.1 is #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 1.1 is # MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
7 1.1 is # M68000 Hi-Performance Microprocessor Division
8 1.1 is # M68060 Software Package Production Release
9 1.1 is #
10 1.1 is # M68060 Software Package Copyright (C) 1993, 1994, 1995, 1996 Motorola Inc.
11 1.1 is # All rights reserved.
12 1.1 is #
13 1.1 is # THE SOFTWARE is provided on an "AS IS" basis and without warranty.
14 1.1 is # To the maximum extent permitted by applicable law,
15 1.1 is # MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
16 1.1 is # INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS
17 1.1 is # FOR A PARTICULAR PURPOSE and any warranty against infringement with
18 1.1 is # regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
19 1.1 is # and any accompanying written materials.
20 1.1 is #
21 1.1 is # To the maximum extent permitted by applicable law,
22 1.1 is # IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
23 1.1 is # (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
24 1.1 is # BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS)
25 1.1 is # ARISING OF THE USE OR INABILITY TO USE THE SOFTWARE.
26 1.1 is #
27 1.1 is # Motorola assumes no responsibility for the maintenance and support
28 1.1 is # of the SOFTWARE.
29 1.1 is #
30 1.1 is # You are hereby granted a copyright license to use, modify, and distribute the
31 1.1 is # SOFTWARE so long as this entire notice is retained without alteration
32 1.1 is # in any modified and/or redistributed versions, and that such modified
33 1.1 is # versions are clearly identified as such.
34 1.1 is # No licenses are granted by implication, estoppel or otherwise under any
35 1.1 is # patents or trademarks of Motorola, Inc.
36 1.1 is #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 1.1 is
38 1.1 is #
39 1.1 is # os.s
40 1.1 is #
41 1.1 is # This file contains:
42 1.1 is # - example "Call-Out"s required by both the ISP and FPSP.
43 1.1 is #
44 1.1 is
45 1.1 is
46 1.1 is #################################
47 1.1 is # EXAMPLE CALL-OUTS #
48 1.1 is # #
49 1.1 is # _060_dmem_write() #
50 1.1 is # _060_dmem_read() #
51 1.1 is # _060_imem_read() #
52 1.1 is # _060_dmem_read_byte() #
53 1.1 is # _060_dmem_read_word() #
54 1.1 is # _060_dmem_read_long() #
55 1.1 is # _060_imem_read_word() #
56 1.1 is # _060_imem_read_long() #
57 1.1 is # _060_dmem_write_byte() #
58 1.1 is # _060_dmem_write_word() #
59 1.1 is # _060_dmem_write_long() #
60 1.1 is # #
61 1.1 is # _060_real_trace() #
62 1.1 is # _060_real_access() #
63 1.1 is #################################
64 1.1 is
65 1.1 is #
66 1.1 is # Each IO routine checks to see if the memory write/read is to/from user
67 1.1 is # or supervisor application space. The examples below use simple "move"
68 1.1 is # instructions for supervisor mode applications and call _copyin()/_copyout()
69 1.1 is # for user mode applications.
70 1.1 is # When installing the 060SP, the _copyin()/_copyout() equivalents for a
71 1.1 is # given operating system should be substituted.
72 1.1 is #
73 1.1 is # The addresses within the 060SP are guaranteed to be on the stack.
74 1.1 is # The result is that Unix processes are allowed to sleep as a consequence
75 1.1 is # of a page fault during a _copyout.
76 1.1 is #
77 1.1 is
78 1.1 is #
79 1.1 is # _060_dmem_write():
80 1.1 is #
81 1.1 is # Writes to data memory while in supervisor mode.
82 1.1 is #
83 1.1 is # INPUTS:
84 1.1 is # a0 - supervisor source address
85 1.1 is # a1 - user destination address
86 1.1 is # d0 - number of bytes to write
87 1.1 is # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
88 1.1 is # OUTPUTS:
89 1.1 is # d1 - 0 = success, !0 = failure
90 1.1 is #
91 1.1 is global _060_dmem_write
92 1.1 is _060_dmem_write:
93 1.1 is btst &0x5,0x4(%a6) # check for supervisor state
94 1.1 is beq.b user_write
95 1.1 is super_write:
96 1.1 is mov.b (%a0)+,(%a1)+ # copy 1 byte
97 1.1 is subq.l &0x1,%d0 # decr byte counter
98 1.1 is bne.b super_write # quit if ctr = 0
99 1.1 is clr.l %d1 # return success
100 1.1 is rts
101 1.1 is user_write:
102 1.1 is mov.l %d0,-(%sp) # pass: counter
103 1.1 is mov.l %a1,-(%sp) # pass: user dst
104 1.1 is mov.l %a0,-(%sp) # pass: supervisor src
105 1.1 is bsr.l _copyout # write byte to user mem
106 1.1 is mov.l %d0,%d1 # return success
107 1.1 is add.l &0xc, %sp # clear 3 lw params
108 1.1 is rts
109 1.1 is
110 1.1 is #
111 1.1 is # _060_imem_read(), _060_dmem_read():
112 1.1 is #
113 1.1 is # Reads from data/instruction memory while in supervisor mode.
114 1.1 is #
115 1.1 is # INPUTS:
116 1.1 is # a0 - user source address
117 1.1 is # a1 - supervisor destination address
118 1.1 is # d0 - number of bytes to read
119 1.1 is # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
120 1.1 is # OUTPUTS:
121 1.1 is # d1 - 0 = success, !0 = failure
122 1.1 is #
123 1.1 is global _060_imem_read
124 1.1 is global _060_dmem_read
125 1.1 is _060_imem_read:
126 1.1 is _060_dmem_read:
127 1.1 is btst &0x5,0x4(%a6) # check for supervisor state
128 1.1 is beq.b user_read
129 1.1 is super_read:
130 1.1 is mov.b (%a0)+,(%a1)+ # copy 1 byte
131 1.1 is subq.l &0x1,%d0 # decr byte counter
132 1.1 is bne.b super_read # quit if ctr = 0
133 1.1 is clr.l %d1 # return success
134 1.1 is rts
135 1.1 is user_read:
136 1.1 is mov.l %d0,-(%sp) # pass: counter
137 1.1 is mov.l %a1,-(%sp) # pass: super dst
138 1.1 is mov.l %a0,-(%sp) # pass: user src
139 1.1 is bsr.l _copyin # read byte from user mem
140 1.1 is mov.l %d0,%d1 # return success
141 1.1 is add.l &0xc,%sp # clear 3 lw params
142 1.1 is rts
143 1.1 is
144 1.1 is #
145 1.1 is # _060_dmem_read_byte():
146 1.1 is #
147 1.1 is # Read a data byte from user memory.
148 1.1 is #
149 1.1 is # INPUTS:
150 1.1 is # a0 - user source address
151 1.1 is # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
152 1.1 is # OUTPUTS:
153 1.1 is # d0 - data byte in d0
154 1.1 is # d1 - 0 = success, !0 = failure
155 1.1 is #
156 1.1 is global _060_dmem_read_byte
157 1.1 is _060_dmem_read_byte:
158 1.1 is btst &0x5,0x4(%a6) # check for supervisor state
159 1.1 is bne.b dmrbs # supervisor
160 1.1 is dmrbu: clr.l -(%sp) # clear space on stack for result
161 1.1 is mov.l &0x1,-(%sp) # pass: # bytes to copy
162 1.1 is pea 0x7(%sp) # pass: dst addr (stack)
163 1.1 is mov.l %a0,-(%sp) # pass: src addr (user mem)
164 1.1 is bsr.l _copyin # "copy in" the data
165 1.1 is mov.l %d0,%d1 # return success
166 1.1 is add.l &0xc,%sp # delete params
167 1.1 is mov.l (%sp)+,%d0 # put answer in d0
168 1.1 is rts
169 1.1 is dmrbs: clr.l %d0 # clear whole longword
170 1.1 is mov.b (%a0),%d0 # fetch super byte
171 1.1 is clr.l %d1 # return success
172 1.1 is rts
173 1.1 is
174 1.1 is #
175 1.1 is # _060_dmem_read_word():
176 1.1 is #
177 1.1 is # Read a data word from user memory.
178 1.1 is #
179 1.1 is # INPUTS:
180 1.1 is # a0 - user source address
181 1.1 is # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
182 1.1 is # OUTPUTS:
183 1.1 is # d0 - data word in d0
184 1.1 is # d1 - 0 = success, !0 = failure
185 1.1 is #
186 1.1 is global _060_dmem_read_word
187 1.1 is _060_dmem_read_word:
188 1.1 is btst &0x5,0x4(%a6) # check for supervisor state
189 1.1 is bne.b dmrws # supervisor
190 1.1 is dmrwu: clr.l -(%sp) # clear space on stack for result
191 1.1 is mov.l &0x2,-(%sp) # pass: # bytes to copy
192 1.1 is pea 0x6(%sp) # pass: dst addr (stack)
193 1.1 is mov.l %a0,-(%sp) # pass: src addr (user mem)
194 1.1 is bsr.l _copyin # "copy in" the data
195 1.1 is mov.l %d0,%d1 # return success
196 1.1 is add.l &0xc,%sp # delete params
197 1.1 is mov.l (%sp)+,%d0 # put answer in d0
198 1.1 is rts
199 1.1 is dmrws: clr.l %d0 # clear whole longword
200 1.1 is mov.w (%a0), %d0 # fetch super word
201 1.1 is clr.l %d1 # return success
202 1.1 is rts
203 1.1 is
204 1.1 is #
205 1.1 is # _060_dmem_read_long():
206 1.1 is #
207 1.1 is
208 1.1 is #
209 1.1 is # INPUTS:
210 1.1 is # a0 - user source address
211 1.1 is # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
212 1.1 is # OUTPUTS:
213 1.1 is # d0 - data longword in d0
214 1.1 is # d1 - 0 = success, !0 = failure
215 1.1 is #
216 1.1 is global _060_dmem_read_long
217 1.1 is _060_dmem_read_long:
218 1.1 is btst &0x5,0x4(%a6) # check for supervisor state
219 1.1 is bne.b dmrls # supervisor
220 1.1 is dmrlu: subq.l &0x4,%sp # clear space on stack for result
221 1.1 is mov.l &0x4,-(%sp) # pass: # bytes to copy
222 1.1 is pea 0x4(%sp) # pass: dst addr (stack)
223 1.1 is mov.l %a0,-(%sp) # pass: src addr (user mem)
224 1.1 is bsr.l _copyin # "copy in" the data
225 1.1 is mov.l %d0,%d1 # return success
226 1.1 is add.l &0xc,%sp # delete params
227 1.1 is mov.l (%sp)+,%d0 # put answer in d0
228 1.1 is rts
229 1.1 is dmrls: mov.l (%a0),%d0 # fetch super longword
230 1.1 is clr.l %d1 # return success
231 1.1 is rts
232 1.1 is
233 1.1 is #
234 1.1 is # _060_dmem_write_byte():
235 1.1 is #
236 1.1 is # Write a data byte to user memory.
237 1.1 is #
238 1.1 is # INPUTS:
239 1.1 is # a0 - user destination address
240 1.1 is # d0 - data byte in d0
241 1.1 is # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
242 1.1 is # OUTPUTS:
243 1.1 is # d1 - 0 = success, !0 = failure
244 1.1 is #
245 1.1 is global _060_dmem_write_byte
246 1.1 is _060_dmem_write_byte:
247 1.1 is btst &0x5,0x4(%a6) # check for supervisor state
248 1.1 is bne.b dmwbs # supervisor
249 1.1 is dmwbu: mov.l %d0,-(%sp) # put src on stack
250 1.1 is mov.l &0x1,-(%sp) # pass: # bytes to copy
251 1.1 is mov.l %a0,-(%sp) # pass: dst addr (user mem)
252 1.1 is pea 0xb(%sp) # pass: src addr (stack)
253 1.1 is bsr.l _copyout # "copy out" the data
254 1.1 is mov.l %d0,%d1 # return success
255 1.1 is add.l &0x10,%sp # delete params + src
256 1.1 is rts
257 1.1 is dmwbs: mov.b %d0,(%a0) # store super byte
258 1.1 is clr.l %d1 # return success
259 1.1 is rts
260 1.1 is
261 1.1 is #
262 1.1 is # _060_dmem_write_word():
263 1.1 is #
264 1.1 is # Write a data word to user memory.
265 1.1 is #
266 1.1 is # INPUTS:
267 1.1 is # a0 - user destination address
268 1.1 is # d0 - data word in d0
269 1.1 is # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
270 1.1 is # OUTPUTS:
271 1.1 is # d1 - 0 = success, !0 = failure
272 1.1 is #
273 1.1 is global _060_dmem_write_word
274 1.1 is _060_dmem_write_word:
275 1.1 is btst &0x5,0x4(%a6) # check for supervisor state
276 1.1 is bne.b dmwws # supervisor
277 1.1 is dmwwu: mov.l %d0,-(%sp) # put src on stack
278 1.1 is mov.l &0x2,-(%sp) # pass: # bytes to copy
279 1.1 is mov.l %a0,-(%sp) # pass: dst addr (user mem)
280 1.1 is pea 0xa(%sp) # pass: src addr (stack)
281 1.1 is bsr.l _copyout # "copy out" the data
282 1.1 is mov.l %d0,%d1 # return success
283 1.1 is add.l &0x10,%sp # delete params + src
284 1.1 is rts
285 1.1 is dmwws: mov.w %d0,(%a0) # store super word
286 1.1 is clr.l %d1 # return success
287 1.1 is rts
288 1.1 is
289 1.1 is #
290 1.1 is # _060_dmem_write_long():
291 1.1 is #
292 1.1 is # Write a data longword to user memory.
293 1.1 is #
294 1.1 is # INPUTS:
295 1.1 is # a0 - user destination address
296 1.1 is # d0 - data longword in d0
297 1.1 is # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
298 1.1 is # OUTPUTS:
299 1.1 is # d1 - 0 = success, !0 = failure
300 1.1 is #
301 1.1 is global _060_dmem_write_long
302 1.1 is _060_dmem_write_long:
303 1.1 is btst &0x5,0x4(%a6) # check for supervisor state
304 1.1 is bne.b dmwls # supervisor
305 1.1 is dmwlu: mov.l %d0,-(%sp) # put src on stack
306 1.1 is mov.l &0x4,-(%sp) # pass: # bytes to copy
307 1.1 is mov.l %a0,-(%sp) # pass: dst addr (user mem)
308 1.1 is pea 0x8(%sp) # pass: src addr (stack)
309 1.1 is bsr.l _copyout # "copy out" the data
310 1.1 is mov.l %d0,%d1 # return success
311 1.1 is add.l &0x10,%sp # delete params + src
312 1.1 is rts
313 1.1 is dmwls: mov.l %d0,(%a0) # store super longword
314 1.1 is clr.l %d1 # return success
315 1.1 is rts
316 1.1 is
317 1.1 is #
318 1.1 is # _060_imem_read_word():
319 1.1 is #
320 1.1 is # Read an instruction word from user memory.
321 1.1 is #
322 1.1 is # INPUTS:
323 1.1 is # a0 - user source address
324 1.1 is # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
325 1.1 is # OUTPUTS:
326 1.1 is # d0 - instruction word in d0
327 1.1 is # d1 - 0 = success, !0 = failure
328 1.1 is #
329 1.1 is global _060_imem_read_word
330 1.1 is _060_imem_read_word:
331 1.1 is btst &0x5,0x4(%a6) # check for supervisor state
332 1.1 is bne.b imrws # supervisor
333 1.1 is imrwu: clr.l -(%sp) # clear space on stack for result
334 1.1 is mov.l &0x2,-(%sp) # pass: # bytes to copy
335 1.1 is pea 0x6(%sp) # pass: dst addr (stack)
336 1.1 is mov.l %a0,-(%sp) # pass: src addr (user mem)
337 1.1 is bsr.l _copyin # "copy in" the data
338 1.1 is mov.l %d0,%d1 # return success
339 1.1 is add.l &0xc,%sp # delete params
340 1.1 is mov.l (%sp)+,%d0 # put answer in d0
341 1.1 is rts
342 1.1 is imrws: mov.w (%a0),%d0 # fetch super word
343 1.1 is clr.l %d1 # return success
344 1.1 is rts
345 1.1 is
346 1.1 is #
347 1.1 is # _060_imem_read_long():
348 1.1 is #
349 1.1 is # Read an instruction longword from user memory.
350 1.1 is #
351 1.1 is # INPUTS:
352 1.1 is # a0 - user source address
353 1.1 is # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
354 1.1 is # OUTPUTS:
355 1.1 is # d0 - instruction longword in d0
356 1.1 is # d1 - 0 = success, !0 = failure
357 1.1 is #
358 1.1 is global _060_imem_read_long
359 1.1 is _060_imem_read_long:
360 1.1 is btst &0x5,0x4(%a6) # check for supervisor state
361 1.1 is bne.b imrls # supervisor
362 1.1 is imrlu: subq.l &0x4,%sp # clear space on stack for result
363 1.1 is mov.l &0x4,-(%sp) # pass: # bytes to copy
364 1.1 is pea 0x4(%sp) # pass: dst addr (stack)
365 1.1 is mov.l %a0,-(%sp) # pass: src addr (user mem)
366 1.1 is bsr.l _copyin # "copy in" the data
367 1.1 is mov.l %d0,%d1 # return success
368 1.1 is add.l &0xc,%sp # delete params
369 1.1 is mov.l (%sp)+,%d0 # put answer in d0
370 1.1 is rts
371 1.1 is imrls: mov.l (%a0),%d0 # fetch super longword
372 1.1 is clr.l %d1 # return success
373 1.1 is rts
374 1.1 is
375 1.1 is ################################################
376 1.1 is
377 1.1 is #
378 1.1 is # Use these routines if your kernel doesn't have _copyout/_copyin equivalents.
379 1.1 is # Assumes that D0/D1/A0/A1 are scratch registers. The _copyin/_copyout
380 1.1 is # below assume that the SFC/DFC have been set previously.
381 1.1 is #
382 1.1 is
383 1.1 is #
384 1.1 is # int _copyout(supervisor_addr, user_addr, nbytes)
385 1.1 is #
386 1.1 is global _copyout
387 1.1 is _copyout:
388 1.1 is mov.l 4(%sp),%a0 # source
389 1.1 is mov.l 8(%sp),%a1 # destination
390 1.1 is mov.l 12(%sp),%d0 # count
391 1.1 is moreout:
392 1.1 is mov.b (%a0)+,%d1 # fetch supervisor byte
393 1.1 is movs.b %d1,(%a1)+ # store user byte
394 1.1 is subq.l &0x1,%d0 # are we through yet?
395 1.1 is bne.w moreout # no; so, continue
396 1.1 is rts
397 1.1 is
398 1.1 is #
399 1.1 is # int _copyin(user_addr, supervisor_addr, nbytes)
400 1.1 is #
401 1.1 is global _copyin
402 1.1 is _copyin:
403 1.1 is mov.l 4(%sp),%a0 # source
404 1.1 is mov.l 8(%sp),%a1 # destination
405 1.1 is mov.l 12(%sp),%d0 # count
406 1.1 is morein:
407 1.1 is movs.b (%a0)+,%d1 # fetch user byte
408 1.1 is mov.b %d1,(%a1)+ # write supervisor byte
409 1.1 is subq.l &0x1,%d0 # are we through yet?
410 1.1 is bne.w morein # no; so, continue
411 1.1 is rts
412 1.1 is
413 1.1 is ############################################################################
414 1.1 is
415 1.1 is #
416 1.1 is # _060_real_trace():
417 1.1 is #
418 1.1 is # This is the exit point for the 060FPSP when an instruction is being traced
419 1.1 is # and there are no other higher priority exceptions pending for this instruction
420 1.1 is # or they have already been processed.
421 1.1 is #
422 1.1 is # The sample code below simply executes an "rte".
423 1.1 is #
424 1.1 is global _060_real_trace
425 1.1 is _060_real_trace:
426 1.1 is rte
427 1.1 is
428 1.1 is #
429 1.1 is # _060_real_access():
430 1.1 is #
431 1.1 is # This is the exit point for the 060FPSP when an access error exception
432 1.1 is # is encountered. The routine below should point to the operating system
433 1.1 is # handler for access error exceptions. The exception stack frame is an
434 1.1 is # 8-word access error frame.
435 1.1 is #
436 1.1 is # The sample routine below simply executes an "rte" instruction which
437 1.1 is # is most likely the incorrect thing to do and could put the system
438 1.1 is # into an infinite loop.
439 1.1 is #
440 1.1 is global _060_real_access
441 1.1 is _060_real_access:
442 1.1 is rte
443