|
|
1.1 root 1: ;
2: ; nono
3: ; Copyright (C) 2020 nono project
4: ;
5: ; Redistribution and use in source and binary forms, with or without
6: ; modification, are permitted provided that the following conditions
7: ; are met:
8: ; 1. Redistributions of source code must retain the above copyright
9: ; notice, this list of conditions and the following disclaimer.
10: ; 2. Redistributions in binary form must reproduce the above copyright
11: ; notice, this list of conditions and the following disclaimer in the
12: ; documentation and/or other materials provided with the distribution.
13: ;
14: ; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15: ; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16: ; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17: ; IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18: ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19: ; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20: ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
21: ; AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22: ; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23: ; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24: ; SUCH DAMAGE.
25:
26: .include doscall.mac
27: .list
28: .cpu 68030
29:
30: PRINT .macro msg
31: pea.l msg(pc)
32: DOS _PRINT
33: addq.l #4,sp
34: .endm
35:
36: .text
37: .even
38: start:
39: bsr test_user
40: bsr test_super
41: DOS _EXIT
42:
43: ; ユーザモードで $ff58 を実行すると先に特権違反例外が起きる。
44: ; Human68k はこれをトラップして DOS コールに回している(?)。
45: test_user:
46: PRINT msg_user
47:
48: ; 特権違反ベクタを差し替える
49: pea.l (priv_handler)
50: move.w #$0008,-(sp)
51: DOS _INTVCS
52: addq.l #6,sp
53: movea.l d0,a2 ; 元ベクタを a2 に保存
54:
55: ; a1 にハンドラからの戻りアドレスを入れておく
56: lea.l user_ret,a1
57:
58: ; d0 を初期化。_MALLOC2 が失敗すると $8xxxxxxx が返る
59: clr.l d0
60:
61: move.l #$01000000,-(sp) ; 16MB(必ず失敗させる)
62: clr.w -(sp) ; MD=0
63: ; $ff58 = Human68k ver2 の DOS _MALLOC2
64: ; $ff58 = CPID=7 の FRESTORE (A0)+
65: .dc.w $ff58
66: user_ret:
67: addq.l #6,sp
68: move.l d0,-(sp)
69:
70: ; ベクタを戻す
71: move.l a2,-(sp)
72: move.w #$0008,-(sp)
73: DOS _INTVCS
74: addq.l #6,sp
75:
76: ; 結果確認
77: move.l (sp)+,d0
78: tst.l d0
79: bpl @f
80: PRINT msg_umalloc
81: bra user_done
82: @@:
83: cmpi.l #1,d0
84: bne @f
85: PRINT msg_priv
86: bra user_done
87: @@:
88: PRINT msg_unknown
89: user_done:
90: rts
91:
92: ; 特権違反ハンドラ
93: priv_handler:
94: moveq.l #1,d0
95: move.l a1,2(sp)
96: rte
97:
98:
99: ; スーパーバイザーモードで $ff58 を実行するとこれは
100: ; CPID=7 の frestore (a0)+ なので、(a0)+ が実行された後
101: ; CPID=7 をチェックする。いないので F ライン例外を出す。
102: ; これで DOS コールが呼ばれる(?)。
103: test_super:
104: PRINT msg_super
105:
106: move.l d0,-(sp)
107: DOS _SUPER
108: move.l d0,(sp) ; スタック戻さず push
109:
110: ; (a0)+ された時のために、読み込み可能なところをさしておく
111: lea.l test_super,a0
112:
113: ; $ff58 を実行
114: clr.l d0
115: move.l #$01000000,-(sp) ; 16MB(必ず失敗させる)
116: clr.w -(sp) ; MD=0
117: .dc.w $ff58
118: addq.l #6,sp
119:
120: ; 結果確認
121: tst.l d0
122: bmi @f
123: PRINT msg_unknown
124: bra super_done
125: @@:
126: ; d0 が負なら正しいので次に a0 をチェック
127: cmpa.l (test_super+4),a0
128: beq @f
129: PRINT msg_a0
130: bra super_done
131: @@:
132: PRINT msg_smalloc
133: super_done:
134: move.l (sp)+,d0
135: DOS _SUPER
136: addq.l #4,sp
137: rts
138:
139:
140: msg_user: .dc.b "Testing in user mode...",$d,$a,0
141: msg_super: .dc.b "Testing in supervisor mode...",$d,$a,0
142: msg_umalloc: .dc.b "_MALLOC2 called (incorrect!)",$d,$a,0
143: msg_priv: .dc.b "Privilege violation exception called (expected)"
144: .dc.b $d,$a,0
145: msg_a0: .dc.b "(a0)+ not processed (incorrect!)",$d,$a,0
146: msg_smalloc: .dc.b "_MALLCO2 called (expected)",$d,$a,0
147: msg_unknown: .dc.b "Unknown result",$d,$a,0
148:
149: .end start
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.