2 # $NetBSD: os.s,v 1.1 2000/04/14 20:24:39 is Exp $
5 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 # MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
7 # M68000 Hi-Performance Microprocessor Division
8 # M68060 Software Package Production Release
10 # M68060 Software Package Copyright (C) 1993, 1994, 1995, 1996 Motorola Inc.
11 # All rights reserved.
13 # THE SOFTWARE is provided on an "AS IS" basis and without warranty.
14 # To the maximum extent permitted by applicable law,
15 # MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
16 # INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS
17 # FOR A PARTICULAR PURPOSE and any warranty against infringement with
18 # regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
19 # and any accompanying written materials.
21 # To the maximum extent permitted by applicable law,
22 # IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
23 # (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
24 # BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS)
25 # ARISING OF THE USE OR INABILITY TO USE THE SOFTWARE.
27 # Motorola assumes no responsibility for the maintenance and support
30 # You are hereby granted a copyright license to use, modify, and distribute the
31 # SOFTWARE so long as this entire notice is retained without alteration
32 # in any modified and/or redistributed versions, and that such modified
33 # versions are clearly identified as such.
34 # No licenses are granted by implication, estoppel or otherwise under any
35 # patents or trademarks of Motorola, Inc.
36 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42 # - example "Call-Out"s required by both the ISP and FPSP.
46 #################################
52 # _060_dmem_read_byte() #
53 # _060_dmem_read_word() #
54 # _060_dmem_read_long() #
55 # _060_imem_read_word() #
56 # _060_imem_read_long() #
57 # _060_dmem_write_byte() #
58 # _060_dmem_write_word() #
59 # _060_dmem_write_long() #
62 # _060_real_access() #
63 #################################
66 # Each IO routine checks to see if the memory write/read is to/from user
67 # or supervisor application space. The examples below use simple "move"
68 # instructions for supervisor mode applications and call _copyin()/_copyout()
69 # for user mode applications.
70 # When installing the 060SP, the _copyin()/_copyout() equivalents for a
71 # given operating system should be substituted.
73 # The addresses within the 060SP are guaranteed to be on the stack.
74 # The result is that Unix processes are allowed to sleep as a consequence
75 # of a page fault during a _copyout.
81 # Writes to data memory while in supervisor mode.
84 # a0 - supervisor source address
85 # a1 - user destination address
86 # d0 - number of bytes to write
87 # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
89 # d1 - 0 = success, !0 = failure
91 global _060_dmem_write
93 btst
&0x5,0x4(%a6
) # check for supervisor state
96 mov.
b (%a0
)+,(%a1
)+ # copy 1 byte
97 subq.
l &0x1,%d0
# decr byte counter
98 bne.
b super_write
# quit if ctr = 0
99 clr.
l %d1
# return success
102 mov.
l %d0
,-(%sp
) # pass: counter
103 mov.
l %a1
,-(%sp
) # pass: user dst
104 mov.
l %a0
,-(%sp
) # pass: supervisor src
105 bsr.
l _copyout
# write byte to user mem
106 mov.
l %d0
,%d1
# return success
107 add.l &0xc, %sp
# clear 3 lw params
111 # _060_imem_read(), _060_dmem_read():
113 # Reads from data/instruction memory while in supervisor mode.
116 # a0 - user source address
117 # a1 - supervisor destination address
118 # d0 - number of bytes to read
119 # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
121 # d1 - 0 = success, !0 = failure
123 global _060_imem_read
124 global _060_dmem_read
127 btst
&0x5,0x4(%a6
) # check for supervisor state
130 mov.
b (%a0
)+,(%a1
)+ # copy 1 byte
131 subq.
l &0x1,%d0
# decr byte counter
132 bne.
b super_read
# quit if ctr = 0
133 clr.
l %d1
# return success
136 mov.
l %d0
,-(%sp
) # pass: counter
137 mov.
l %a1
,-(%sp
) # pass: super dst
138 mov.
l %a0
,-(%sp
) # pass: user src
139 bsr.
l _copyin
# read byte from user mem
140 mov.
l %d0
,%d1
# return success
141 add.l &0xc,%sp
# clear 3 lw params
145 # _060_dmem_read_byte():
147 # Read a data byte from user memory.
150 # a0 - user source address
151 # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
153 # d0 - data byte in d0
154 # d1 - 0 = success, !0 = failure
156 global _060_dmem_read_byte
158 btst
&0x5,0x4(%a6
) # check for supervisor state
159 bne.
b dmrbs
# supervisor
160 dmrbu
: clr.
l -(%sp
) # clear space on stack for result
161 mov.
l &0x1,-(%sp
) # pass: # bytes to copy
162 pea
0x7(%sp
) # pass: dst addr (stack)
163 mov.
l %a0
,-(%sp
) # pass: src addr (user mem)
164 bsr.
l _copyin
# "copy in" the data
165 mov.
l %d0
,%d1
# return success
166 add.l &0xc,%sp
# delete params
167 mov.
l (%sp
)+,%d0
# put answer in d0
169 dmrbs
: clr.
l %d0
# clear whole longword
170 mov.
b (%a0
),%d0
# fetch super byte
171 clr.
l %d1
# return success
175 # _060_dmem_read_word():
177 # Read a data word from user memory.
180 # a0 - user source address
181 # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
183 # d0 - data word in d0
184 # d1 - 0 = success, !0 = failure
186 global _060_dmem_read_word
188 btst
&0x5,0x4(%a6
) # check for supervisor state
189 bne.
b dmrws
# supervisor
190 dmrwu
: clr.
l -(%sp
) # clear space on stack for result
191 mov.
l &0x2,-(%sp
) # pass: # bytes to copy
192 pea
0x6(%sp
) # pass: dst addr (stack)
193 mov.
l %a0
,-(%sp
) # pass: src addr (user mem)
194 bsr.
l _copyin
# "copy in" the data
195 mov.
l %d0
,%d1
# return success
196 add.l &0xc,%sp
# delete params
197 mov.
l (%sp
)+,%d0
# put answer in d0
199 dmrws
: clr.
l %d0
# clear whole longword
200 mov.w
(%a0
), %d0
# fetch super word
201 clr.
l %d1
# return success
205 # _060_dmem_read_long():
210 # a0 - user source address
211 # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
213 # d0 - data longword in d0
214 # d1 - 0 = success, !0 = failure
216 global _060_dmem_read_long
218 btst
&0x5,0x4(%a6
) # check for supervisor state
219 bne.
b dmrls
# supervisor
220 dmrlu
: subq.
l &0x4,%sp
# clear space on stack for result
221 mov.
l &0x4,-(%sp
) # pass: # bytes to copy
222 pea
0x4(%sp
) # pass: dst addr (stack)
223 mov.
l %a0
,-(%sp
) # pass: src addr (user mem)
224 bsr.
l _copyin
# "copy in" the data
225 mov.
l %d0
,%d1
# return success
226 add.l &0xc,%sp
# delete params
227 mov.
l (%sp
)+,%d0
# put answer in d0
229 dmrls
: mov.
l (%a0
),%d0
# fetch super longword
230 clr.
l %d1
# return success
234 # _060_dmem_write_byte():
236 # Write a data byte to user memory.
239 # a0 - user destination address
240 # d0 - data byte in d0
241 # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
243 # d1 - 0 = success, !0 = failure
245 global _060_dmem_write_byte
246 _060_dmem_write_byte
:
247 btst
&0x5,0x4(%a6
) # check for supervisor state
248 bne.
b dmwbs
# supervisor
249 dmwbu
: mov.
l %d0
,-(%sp
) # put src on stack
250 mov.
l &0x1,-(%sp
) # pass: # bytes to copy
251 mov.
l %a0
,-(%sp
) # pass: dst addr (user mem)
252 pea
0xb(%sp
) # pass: src addr (stack)
253 bsr.
l _copyout
# "copy out" the data
254 mov.
l %d0
,%d1
# return success
255 add.l &0x10,%sp
# delete params + src
257 dmwbs
: mov.
b %d0
,(%a0
) # store super byte
258 clr.
l %d1
# return success
262 # _060_dmem_write_word():
264 # Write a data word to user memory.
267 # a0 - user destination address
268 # d0 - data word in d0
269 # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
271 # d1 - 0 = success, !0 = failure
273 global _060_dmem_write_word
274 _060_dmem_write_word
:
275 btst
&0x5,0x4(%a6
) # check for supervisor state
276 bne.
b dmwws
# supervisor
277 dmwwu
: mov.
l %d0
,-(%sp
) # put src on stack
278 mov.
l &0x2,-(%sp
) # pass: # bytes to copy
279 mov.
l %a0
,-(%sp
) # pass: dst addr (user mem)
280 pea
0xa(%sp
) # pass: src addr (stack)
281 bsr.
l _copyout
# "copy out" the data
282 mov.
l %d0
,%d1
# return success
283 add.l &0x10,%sp
# delete params + src
285 dmwws
: mov.w
%d0
,(%a0
) # store super word
286 clr.
l %d1
# return success
290 # _060_dmem_write_long():
292 # Write a data longword to user memory.
295 # a0 - user destination address
296 # d0 - data longword in d0
297 # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
299 # d1 - 0 = success, !0 = failure
301 global _060_dmem_write_long
302 _060_dmem_write_long
:
303 btst
&0x5,0x4(%a6
) # check for supervisor state
304 bne.
b dmwls
# supervisor
305 dmwlu
: mov.
l %d0
,-(%sp
) # put src on stack
306 mov.
l &0x4,-(%sp
) # pass: # bytes to copy
307 mov.
l %a0
,-(%sp
) # pass: dst addr (user mem)
308 pea
0x8(%sp
) # pass: src addr (stack)
309 bsr.
l _copyout
# "copy out" the data
310 mov.
l %d0
,%d1
# return success
311 add.l &0x10,%sp
# delete params + src
313 dmwls
: mov.
l %d0
,(%a0
) # store super longword
314 clr.
l %d1
# return success
318 # _060_imem_read_word():
320 # Read an instruction word from user memory.
323 # a0 - user source address
324 # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
326 # d0 - instruction word in d0
327 # d1 - 0 = success, !0 = failure
329 global _060_imem_read_word
331 btst
&0x5,0x4(%a6
) # check for supervisor state
332 bne.
b imrws
# supervisor
333 imrwu
: clr.
l -(%sp
) # clear space on stack for result
334 mov.
l &0x2,-(%sp
) # pass: # bytes to copy
335 pea
0x6(%sp
) # pass: dst addr (stack)
336 mov.
l %a0
,-(%sp
) # pass: src addr (user mem)
337 bsr.
l _copyin
# "copy in" the data
338 mov.
l %d0
,%d1
# return success
339 add.l &0xc,%sp
# delete params
340 mov.
l (%sp
)+,%d0
# put answer in d0
342 imrws
: mov.w
(%a0
),%d0
# fetch super word
343 clr.
l %d1
# return success
347 # _060_imem_read_long():
349 # Read an instruction longword from user memory.
352 # a0 - user source address
353 # 0x4(%a6),bit5 - 1 = supervisor mode, 0 = user mode
355 # d0 - instruction longword in d0
356 # d1 - 0 = success, !0 = failure
358 global _060_imem_read_long
360 btst
&0x5,0x4(%a6
) # check for supervisor state
361 bne.
b imrls
# supervisor
362 imrlu
: subq.
l &0x4,%sp
# clear space on stack for result
363 mov.
l &0x4,-(%sp
) # pass: # bytes to copy
364 pea
0x4(%sp
) # pass: dst addr (stack)
365 mov.
l %a0
,-(%sp
) # pass: src addr (user mem)
366 bsr.
l _copyin
# "copy in" the data
367 mov.
l %d0
,%d1
# return success
368 add.l &0xc,%sp
# delete params
369 mov.
l (%sp
)+,%d0
# put answer in d0
371 imrls
: mov.
l (%a0
),%d0
# fetch super longword
372 clr.
l %d1
# return success
375 ################################################
378 # Use these routines if your kernel doesn't have _copyout/_copyin equivalents.
379 # Assumes that D0/D1/A0/A1 are scratch registers. The _copyin/_copyout
380 # below assume that the SFC/DFC have been set previously.
384 # int _copyout(supervisor_addr, user_addr, nbytes)
388 mov.
l 4(%sp
),%a0
# source
389 mov.
l 8(%sp
),%a1
# destination
390 mov.
l 12(%sp
),%d0
# count
392 mov.
b (%a0
)+,%d1
# fetch supervisor byte
393 movs.
b %d1
,(%a1
)+ # store user byte
394 subq.
l &0x1,%d0
# are we through yet?
395 bne.w moreout
# no; so, continue
399 # int _copyin(user_addr, supervisor_addr, nbytes)
403 mov.
l 4(%sp
),%a0
# source
404 mov.
l 8(%sp
),%a1
# destination
405 mov.
l 12(%sp
),%d0
# count
407 movs.
b (%a0
)+,%d1
# fetch user byte
408 mov.
b %d1
,(%a1
)+ # write supervisor byte
409 subq.
l &0x1,%d0
# are we through yet?
410 bne.w morein
# no; so, continue
413 ############################################################################
418 # This is the exit point for the 060FPSP when an instruction is being traced
419 # and there are no other higher priority exceptions pending for this instruction
420 # or they have already been processed.
422 # The sample code below simply executes an "rte".
424 global _060_real_trace
429 # _060_real_access():
431 # This is the exit point for the 060FPSP when an access error exception
432 # is encountered. The routine below should point to the operating system
433 # handler for access error exceptions. The exception stack frame is an
434 # 8-word access error frame.
436 # The sample routine below simply executes an "rte" instruction which
437 # is most likely the incorrect thing to do and could put the system
438 # into an infinite loop.
440 global _060_real_access