summaryrefslogtreecommitdiffstats
path: root/open.asm
blob: b14add7c2007628f911af62040aa809e3047c525 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* -----------------------------------------------------------------------
 *   
 *   Copyright 2013 H. Peter Anvin - All Rights Reserved
 *
 *   Permission is hereby granted, free of charge, to any person
 *   obtaining a copy of this software and associated documentation
 *   files (the "Software"), to deal in the Software without
 *   restriction, including without limitation the rights to use,
 *   copy, modify, merge, publish, distribute, sublicense, and/or
 *   sell copies of the Software, and to permit persons to whom
 *   the Software is furnished to do so, subject to the following
 *   conditions:
 *   
 *   The above copyright notice and this permission notice shall
 *   be included in all copies or substantial portions of the Software.
 *   
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *   OTHER DEALINGS IN THE SOFTWARE.
 *
 * ----------------------------------------------------------------------- */

#include "v9fs.h"
	.code16
	.section ".rtext","ax"
	
/* ------------------------------------------------------------------------- *
 *  fxn_create
 * ------------------------------------------------------------------------- */

GPROC(fxn_create)
	lfsw dos_sdafn,%si
	movb $0x21,%al		/* Action: create or truncate */
	testb $1,F_TOSH
	jz 1f
	movb $0x01,%al		/* Action: create only (= O_EXCL) */
	movw $0x0002,%dx	/* Open mode: compatibility + read/write */
	call do_open
	retw
END(fxn_create)

/* ------------------------------------------------------------------------- *
 *  fxn_open
 * ------------------------------------------------------------------------- */

GPROC(fxn_open)
	lfsw dos_sdafcb,%bx
	movb $0x10,%al			/* Action: open */
	movw %fs:SDF_OPENMODE(%bx),%dx	/* Open mode */
	call do_open
	retw
END(fxn_open)

/* ------------------------------------------------------------------------- *
 *  fxn_spopenfile
 * ------------------------------------------------------------------------- */

GPROC(fxn_spopenfile)
	lfsw dos_sdafcb,%bx
	movw %fs:SDF_SPCACTION(%bx),%ax	/* Open action */
	movw %fs:SDF_SPCMODE(%bx),%dx	/* Open mode */
	call do_open
	andw %ax,%ax
	jnz 1f
	movw %cx,F_CX			/* Status return */
1:
	retw
END(fxn_spopenfile)

/* ------------------------------------------------------------------------- *
 *  do_open
 *
 *  Common interface to all the open variants.  Take the extended open
 *  action code in %al and the open mode in %dx.  SDN_FN1 contains the
 *  fully qualified filename.
 *
 *  On return, the status code is in %(e)ax and on success an extended
 *  open result code is in %cx.
 * ------------------------------------------------------------------------- */

LPROC(do_open)
	lfsw dos_sdafn,%si

	pushw %ax		/*  8(%bp) Action code */
	pushw %dx		/*  6(%bp) Open mode */
	pushw F_ES		/*  2(%bp) SFT pointer - also used as FID */
	pushw F_DI
	pushw %bp		/*  (%bp) */
	movw %sp,%bp

	addw $2,%si		/* Skip leading drive : */

	testb $0x03,%al
	jz 101f

	/* Open or "replace" */
	movl 2(%bp),%eax
	call path_walk_asciiz
	jc 101f			/* Not found */
	andb %al,%al		/* P9_QTFILE = 0x00 */
	jne 102f		/* Not a file */

	movw msgbuf7,%si
	movl 2(%bp),%eax
	stosl
	movzwl 6(%bp),%eax
	andb $3,%al		/* O_RDONLY, O_WRONLY, O_RDWR */
	movb 8(%bp),%cl
	andb $0x2,%cl
	orb %cl,%ah		/* 0x200 = O_TRUNC */
	stosl
	movb $P9_TLOPEN,%al
	call simple_message
	jc 102f

	/* XXX: Set %cx return status */
	
	xorw %ax,%ax		/* Success! */
	jmp 100f

103:
	/* Error, but need to clunk */
	movl 2(%bp),%eax
	call clunk
101:	/* XXX: should handle create!!! */
102:
	/* Error: XXX: handle error code */
	movl $0x08030002,%eax
100:
	popw %bp
	addw $8,%sp
	retw
END(do_open)