File:  [Isaki's NoNo m68k/m88k emulator] / nono / exp / dosff58.has
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed Apr 29 17:04:57 2026 UTC (2 months, 3 weeks ago) by root
Branches: MAIN, Isaki
CVS tags: v027, v026, v025, v024, v023, v022, v021, v020, v019, v018, v017, v016, v015, v014, v013, v012, HEAD
nono 0.2.1

;
; nono
; Copyright (C) 2020 nono project
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions
; are met:
; 1. Redistributions of source code must retain the above copyright
;    notice, this list of conditions and the following disclaimer.
; 2. Redistributions in binary form must reproduce the above copyright
;    notice, this list of conditions and the following disclaimer in the
;    documentation and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
; IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
; AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
; SUCH DAMAGE.

		.include doscall.mac
		.list
		.cpu	68030

PRINT		.macro	msg
		pea.l	msg(pc)
		DOS	_PRINT
		addq.l	#4,sp
		.endm

		.text
		.even
start:
		bsr	test_user
		bsr	test_super
		DOS	_EXIT

; ユーザモードで $ff58 を実行すると先に特権違反例外が起きる。
; Human68k はこれをトラップして DOS コールに回している(?)。
test_user:
		PRINT	msg_user

		; 特権違反ベクタを差し替える
		pea.l	(priv_handler)
		move.w	#$0008,-(sp)
		DOS	_INTVCS
		addq.l	#6,sp
		movea.l	d0,a2			; 元ベクタを a2 に保存

		; a1 にハンドラからの戻りアドレスを入れておく
		lea.l	user_ret,a1

		; d0 を初期化。_MALLOC2 が失敗すると $8xxxxxxx が返る
		clr.l	d0

		move.l	#$01000000,-(sp)	; 16MB(必ず失敗させる)
		clr.w	-(sp)			; MD=0
		; $ff58 = Human68k ver2 の DOS _MALLOC2
		; $ff58 = CPID=7 の FRESTORE (A0)+
		.dc.w	$ff58
user_ret:
		addq.l	#6,sp
		move.l	d0,-(sp)

		; ベクタを戻す
		move.l	a2,-(sp)
		move.w	#$0008,-(sp)
		DOS	_INTVCS
		addq.l	#6,sp

		; 結果確認
		move.l	(sp)+,d0
		tst.l	d0
		bpl	@f
		PRINT	msg_umalloc
		bra	user_done
@@:
		cmpi.l	#1,d0
		bne	@f
		PRINT	msg_priv
		bra	user_done
@@:
		PRINT	msg_unknown
user_done:
		rts

		; 特権違反ハンドラ
priv_handler:
		moveq.l	#1,d0
		move.l	a1,2(sp)
		rte


; スーパーバイザーモードで $ff58 を実行するとこれは
; CPID=7 の frestore (a0)+ なので、(a0)+ が実行された後
; CPID=7 をチェックする。いないので F ライン例外を出す。
; これで DOS コールが呼ばれる(?)。
test_super:
		PRINT	msg_super

		move.l	d0,-(sp)
		DOS	_SUPER
		move.l	d0,(sp)			; スタック戻さず push

		; (a0)+ された時のために、読み込み可能なところをさしておく
		lea.l	test_super,a0

		; $ff58 を実行
		clr.l	d0
		move.l	#$01000000,-(sp)	; 16MB(必ず失敗させる)
		clr.w	-(sp)			; MD=0
		.dc.w	$ff58
		addq.l	#6,sp

		; 結果確認
		tst.l	d0
		bmi	@f
		PRINT	msg_unknown
		bra	super_done
@@:
		; d0 が負なら正しいので次に a0 をチェック
		cmpa.l	(test_super+4),a0
		beq	@f
		PRINT	msg_a0
		bra	super_done
@@:
		PRINT	msg_smalloc
super_done:
		move.l	(sp)+,d0
		DOS	_SUPER
		addq.l	#4,sp
		rts


msg_user:	.dc.b	"Testing in user mode...",$d,$a,0
msg_super:	.dc.b	"Testing in supervisor mode...",$d,$a,0
msg_umalloc:	.dc.b	"_MALLOC2 called (incorrect!)",$d,$a,0
msg_priv:	.dc.b	"Privilege violation exception called (expected)"
		.dc.b	$d,$a,0
msg_a0:		.dc.b	"(a0)+ not processed (incorrect!)",$d,$a,0
msg_smalloc:	.dc.b	"_MALLCO2 called (expected)",$d,$a,0
msg_unknown:	.dc.b	"Unknown result",$d,$a,0

		.end	start

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.