Merge branch 'master' of https://github.com/DoctorWkt/pdp7-unix
This commit is contained in:
+117
-103
@@ -1,33 +1,38 @@
|
|||||||
"** 01-s1.pdf page 7
|
"** 01-s1.pdf page 7
|
||||||
" s2
|
" s2
|
||||||
|
|
||||||
|
" file status (stat) system call
|
||||||
|
" AC/ pointer to status (inode) buffer (12 words)
|
||||||
|
" sys status; dir_name_ptr; file_name_ptr
|
||||||
.status:
|
.status:
|
||||||
jms arg
|
jms arg " fetch directory name pointer
|
||||||
dac .+5
|
dac .+5
|
||||||
jms arg
|
jms arg " fetch file name pointer
|
||||||
dac .+6
|
dac .+6
|
||||||
lac u.cdir
|
lac u.cdir " get current working directory
|
||||||
jms namei; ..
|
jms namei; .. " look up source directory
|
||||||
jms error
|
jms error " not found: return error to user
|
||||||
jms namei; ..
|
jms namei; .. " look up file
|
||||||
jms error
|
jms error " not found: return error
|
||||||
jms iget
|
jms iget " read file inode
|
||||||
lac u.ac
|
lac u.ac " get user buffer pointer
|
||||||
and o17777
|
and o17777 " truncate to 13 bits
|
||||||
jms betwen; o10000; o17762
|
jms betwen; o10000; o17762 " is user memory (but not last 14 wds)?
|
||||||
jms error
|
jms error " no: error
|
||||||
dac .+3
|
dac .+3 " save as copy destination
|
||||||
jms copy; inode; ..; 12
|
jms copy; inode; ..; 12 " copy inode to user buffer
|
||||||
lac d.i
|
lac d.i " copy i-num from last dnode read ??
|
||||||
dac 9 i
|
dac 9 i " save thru index 9 (pre-increment) ??
|
||||||
jmp okexit
|
jmp okexit
|
||||||
|
|
||||||
|
" capture display?
|
||||||
.capt:
|
.capt:
|
||||||
lac u.ac
|
lac u.ac
|
||||||
dac u.dspbuf
|
dac u.dspbuf
|
||||||
jms movdsp
|
jms movdsp
|
||||||
jmp sysexit
|
jmp sysexit
|
||||||
|
|
||||||
|
" release display?
|
||||||
.rele:
|
.rele:
|
||||||
dzm u.dspbuf
|
dzm u.dspbuf
|
||||||
law dspbuf
|
law dspbuf
|
||||||
@@ -35,22 +40,22 @@
|
|||||||
jmp sysexit
|
jmp sysexit
|
||||||
|
|
||||||
.chmod:
|
.chmod:
|
||||||
jms isown
|
jms isown " check if user owns file arg
|
||||||
lac u.ac
|
lac u.ac " get new permissions
|
||||||
and o17
|
and o17 " mask to read/write bits
|
||||||
lmq
|
lmq " save in MQ
|
||||||
lac i.flags
|
lac i.flags " get file flags
|
||||||
and o777760
|
and o777760 " clear permissions
|
||||||
omq
|
omq " or in new permissions from MQ
|
||||||
dac i.flags
|
dac i.flags " save in inode
|
||||||
jms iput
|
jms iput " write inode back
|
||||||
jmp okexit
|
jmp okexit
|
||||||
|
|
||||||
.chown:
|
.chown:
|
||||||
jms isown
|
jms isown " check if user owns file arg
|
||||||
lac u.ac
|
lac u.ac " get new owner
|
||||||
dac i.uid
|
dac i.uid " save in inode
|
||||||
jms iput
|
jms iput " write inode back
|
||||||
jmp okexit
|
jmp okexit
|
||||||
|
|
||||||
.getuid: " getuid system call
|
.getuid: " getuid system call
|
||||||
@@ -103,7 +108,7 @@
|
|||||||
jms error " Didn't find it
|
jms error " Didn't find it
|
||||||
jms namei; 1:0 " In the i-num found by 1st namei,
|
jms namei; 1:0 " In the i-num found by 1st namei,
|
||||||
jms error " search for 2nd argument, err not found
|
jms error " search for 2nd argument, err not found
|
||||||
dac u.base
|
dac u.base " save in user data
|
||||||
jms copy; 2:0; name; 4
|
jms copy; 2:0; name; 4
|
||||||
lac u.cdir " Search the process' current directory
|
lac u.cdir " Search the process' current directory
|
||||||
jms namei; name " for the third argument
|
jms namei; name " for the third argument
|
||||||
@@ -111,11 +116,11 @@
|
|||||||
jms error " Error if it already exists
|
jms error " Error if it already exists
|
||||||
lac d1
|
lac d1
|
||||||
dac mode " Save mode bits for access
|
dac mode " Save mode bits for access
|
||||||
jms access
|
jms access " check access (or return error to user)
|
||||||
jms dslot " ???
|
jms dslot " allocate directory slot
|
||||||
lac u.base " ???
|
lac u.base " get source file i-number
|
||||||
jms iget " ???
|
jms iget " read inode in
|
||||||
lac ii " ???
|
lac ii " get the i-num
|
||||||
dac d.i " Save the i-num in the directory entry
|
dac d.i " Save the i-num in the directory entry
|
||||||
jms copy; name; d.name; 4 " Copy the new link name into the directory entry
|
jms copy; name; d.name; 4 " Copy the new link name into the directory entry
|
||||||
lac i.uniq " Copy the i-node unique number into
|
lac i.uniq " Copy the i-node unique number into
|
||||||
@@ -129,47 +134,56 @@
|
|||||||
jmp okexit " and return OK
|
jmp okexit " and return OK
|
||||||
|
|
||||||
.unlink:
|
.unlink:
|
||||||
jms argname
|
jms argname " fetch filename, inode
|
||||||
dac u.base
|
dac u.base " save i-number
|
||||||
lac d1 " mode bit 1 (write?)
|
lac d1 " write mode bit
|
||||||
dac mode " save for access call
|
dac mode " save for access call
|
||||||
jms access
|
jms access " check access or return error (reads inode)
|
||||||
dac d.i
|
dzm d.i " clear directory i-num
|
||||||
jms dput
|
jms dput " write directory entry back
|
||||||
lac u.base
|
lac u.base " get i-number back
|
||||||
jms iget
|
jms iget " read inode back
|
||||||
isz i.nlks " increment link count
|
isz i.nlks " increment link count (kept as negative count)
|
||||||
jmp 1f " not zero
|
jmp 1f " not zero
|
||||||
jms itrunc " zero links: free blocks
|
jms itrunc " zero links: free blocks
|
||||||
dzm i.flags " clear status (free inode)
|
dzm i.flags " clear status (free inode)
|
||||||
1:
|
1:
|
||||||
jms iput
|
jms iput " write inode back to disk
|
||||||
jmp sysexit
|
jmp sysexit
|
||||||
|
|
||||||
.setuid: " setuid system call
|
.setuid: " setuid system call
|
||||||
lac u.uid " load current user id
|
lac u.uid " load current user id
|
||||||
sma " negative?
|
sma " negative (super user)
|
||||||
jms error " no: error!!
|
jms error " no: error!!
|
||||||
lac u.ac " load user AC
|
lac u.ac " load user AC
|
||||||
dac u.uid " save as new uid
|
dac u.uid " save as new uid
|
||||||
jmp sysexit
|
jmp sysexit
|
||||||
|
|
||||||
|
" rename system call:
|
||||||
|
" sys rename; old_name_ptr; new_name_ptr
|
||||||
|
" Questions:
|
||||||
|
" when is directory entry read??
|
||||||
|
" is access check on directory or src file??
|
||||||
|
" check for existing file with new name??
|
||||||
|
" when is directory entry written back??
|
||||||
.rename:
|
.rename:
|
||||||
jms arg
|
jms arg " fetch first arg (old name pointer)
|
||||||
dac 0f
|
dac 0f " save for namei
|
||||||
jms arg
|
jms arg " fetch second arg (new name pointer)
|
||||||
dac 1f
|
dac 1f " save for copy
|
||||||
lac u.cdir
|
lac u.cdir " get CWD
|
||||||
jms namei; 0:0
|
jms namei; 0:0 " search for (old) name
|
||||||
jms error
|
jms error " not found: return error
|
||||||
lac d1 " mode bit 1 (write?)
|
lac d1 " get write mode bit
|
||||||
dac mode " save for access call
|
dac mode " save for access call
|
||||||
jms access
|
jms access " access OK? (or return error to user)
|
||||||
jms copy; 1:0; d.name; 4
|
jms copy; 1:0; d.name; 4 " copy new name into directory entry
|
||||||
jmp okexit
|
jmp okexit
|
||||||
|
|
||||||
" time system call returns line (mains) frequency ticks since boot?
|
" time system call returns line (mains) frequency ticks
|
||||||
" note: returns uptime!?
|
" high order bits returned in AC, low order in MQ
|
||||||
|
" s.tim is located in "system" block (written to disk)
|
||||||
|
" so this is a running count of uptime since first boot!
|
||||||
" at 60Hz, 36 bits would last 36+ years!
|
" at 60Hz, 36 bits would last 36+ years!
|
||||||
.time:
|
.time:
|
||||||
lac s.tim " load high order bits
|
lac s.tim " load high order bits
|
||||||
@@ -179,14 +193,14 @@
|
|||||||
jmp sysexit
|
jmp sysexit
|
||||||
|
|
||||||
.chdir:
|
.chdir:
|
||||||
jms argname
|
jms argname " fetch argument as filename
|
||||||
jms iget
|
jms iget " (re)read inode(???)
|
||||||
lac i.flags
|
lac i.flags " get flags
|
||||||
and o20
|
and o20 " get directory bit
|
||||||
sna
|
sna " is a directory?
|
||||||
jms error
|
jms error " no: return error to user
|
||||||
lac ii
|
lac ii " yes: get i-number
|
||||||
dac u.cdir
|
dac u.cdir " save as current working directory
|
||||||
"** 01-s1.pdf page 10
|
"** 01-s1.pdf page 10
|
||||||
jmp okexit
|
jmp okexit
|
||||||
|
|
||||||
@@ -223,27 +237,27 @@
|
|||||||
.creat:
|
.creat:
|
||||||
lac d1 " mode bit 1 (write)
|
lac d1 " mode bit 1 (write)
|
||||||
dac mode " save for access call
|
dac mode " save for access call
|
||||||
jms arg
|
jms arg " get name pointer
|
||||||
dac .+2
|
dac .+2 " save for copy
|
||||||
jms copy; ..; name; 4
|
jms copy; ..; name; 4 " copy filename to "name"
|
||||||
lac u.cdir
|
lac u.cdir
|
||||||
jms namei; name
|
jms namei; name " look up in current working directory
|
||||||
jmp 1f
|
jmp 1f " not found
|
||||||
jms iget
|
jms iget " file exists: read inode
|
||||||
jms access
|
jms access " check access (or return error to user)
|
||||||
lac i.flags
|
lac i.flags " get flags
|
||||||
and o20
|
and o20 " get directory bit
|
||||||
sna
|
sna " is a directory?
|
||||||
jmp .+4
|
jmp .+4 " no: skip to truncate
|
||||||
lac u.uid
|
lac u.uid " get user
|
||||||
sma
|
sma " is super user?
|
||||||
jms error
|
jms error " no: error
|
||||||
jms itrunc
|
jms itrunc " yes: truncate
|
||||||
cla
|
cla
|
||||||
jms dacisize
|
jms dacisize " clear i.size
|
||||||
jmp open1
|
jmp open1
|
||||||
1:
|
1:
|
||||||
jms access
|
jms access " here if not found
|
||||||
lac u.ac " get access bits from user AC (zero for lock!)
|
lac u.ac " get access bits from user AC (zero for lock!)
|
||||||
and o17 " mask to permissions
|
and o17 " mask to permissions
|
||||||
jms icreat
|
jms icreat
|
||||||
@@ -254,30 +268,30 @@ open1: " common exit for open/creat
|
|||||||
|
|
||||||
"** 01-s1.pdf page 11
|
"** 01-s1.pdf page 11
|
||||||
.close:
|
.close:
|
||||||
jms finac
|
jms finac " get fnode (open file)
|
||||||
dzm f.flags
|
dzm f.flags " clear flags
|
||||||
jms fput
|
jms fput " write fnode back to u.ofiles
|
||||||
jmp sysexit
|
jmp sysexit
|
||||||
|
|
||||||
.read:
|
.read:
|
||||||
jms arg
|
jms arg " get argument
|
||||||
and o17777
|
and o17777 " mask to address
|
||||||
dac u.base
|
dac u.base " save as I/O base
|
||||||
jms arg
|
jms arg " get second argument
|
||||||
dac u.count
|
dac u.count " save as count
|
||||||
lac u.base
|
lac u.base " get base
|
||||||
jms betwen; o10000; o17777
|
jms betwen; o10000; o17777 " end inside user memory?
|
||||||
jms error
|
jms error " no: error
|
||||||
tad u.count
|
tad u.count " get end of buffer
|
||||||
jms betwen; u.base; o17777
|
jms betwen; u.base; o17777 " inside buffer/user memory?
|
||||||
jms error
|
jms error " no: error
|
||||||
dac u.limit
|
dac u.limit " yes: save as I/O limit
|
||||||
1:
|
1:
|
||||||
jms finac
|
jms finac " get fnode for fd in user AC
|
||||||
lac f.flags
|
lac f.flags " get open file flags
|
||||||
and d1
|
and d1 " get write bit
|
||||||
sza
|
sza " open for write?
|
||||||
jms error
|
jms error " yes: error
|
||||||
lac i.flags " get inode flags
|
lac i.flags " get inode flags
|
||||||
and o40 " get special file bit
|
and o40 " get special file bit
|
||||||
sna " special?
|
sna " special?
|
||||||
|
|||||||
+25
-16
@@ -17,15 +17,15 @@ dskswap: 0
|
|||||||
t = t+1
|
t = t+1
|
||||||
|
|
||||||
access: 0
|
access: 0
|
||||||
lac i.flags
|
lac i.flags " get inode flags
|
||||||
lmq " save in MQ
|
lmq " save in MQ
|
||||||
lac u.uid " get user id
|
lac u.uid " get user id
|
||||||
spa " negative?
|
spa " negative?
|
||||||
jmp access i " yes: super user, return
|
jmp access i " yes: super user, return
|
||||||
sad i.uid " compare to file owner
|
sad i.uid " compare to file owner
|
||||||
lrs 2 " same: shift flags down two
|
lrs 2 " same: shift flags down two
|
||||||
lacq " get flags back
|
lacq " get inode flags back
|
||||||
and mode " mode from system call
|
and mode " AND with mode from system call
|
||||||
sza " access allowed?
|
sza " access allowed?
|
||||||
jmp access i " yes: return
|
jmp access i " yes: return
|
||||||
jms error " no: return error from system call
|
jms error " no: return error from system call
|
||||||
@@ -256,18 +256,24 @@ movdsp: 0
|
|||||||
ion
|
ion
|
||||||
jmp movdsp i
|
jmp movdsp i
|
||||||
|
|
||||||
|
" fetch user argument from word after "sys" call, return in AC
|
||||||
arg: 0
|
arg: 0
|
||||||
lac u.rq+8 i
|
lac u.rq+8 i " fetch word after return PC
|
||||||
isz u.rq+8
|
isz u.rq+8 " bump PC
|
||||||
jmp arg i
|
jmp arg i
|
||||||
|
|
||||||
|
" fetch user pathname argument from pointer word after "sys" call
|
||||||
|
" into "name" and look it up (in current working directory)
|
||||||
|
" if lookup fails: returns error to user (not caller)
|
||||||
|
" if lookup OK: returns with file i-inode read (into "inode")
|
||||||
|
" and i-number in AC
|
||||||
argname: 0
|
argname: 0
|
||||||
jms arg
|
jms arg " fetch name pointer
|
||||||
dac .+2
|
dac .+2 " save as copy source
|
||||||
jms copy; ..; name; 4
|
jms copy; ..; name; 4 " copy to "name"
|
||||||
lac u.cdir
|
lac u.cdir " get CWD
|
||||||
jms namei; name
|
jms namei; name " look up file
|
||||||
jms error
|
jms error " failed: return error directly to user
|
||||||
jmp argname i
|
jmp argname i
|
||||||
|
|
||||||
seektell: 0
|
seektell: 0
|
||||||
@@ -288,13 +294,16 @@ seektell: 0
|
|||||||
lac f.badd
|
lac f.badd
|
||||||
jmp seektell i
|
jmp seektell i
|
||||||
|
|
||||||
|
" system call helper
|
||||||
|
" fetch system call argument name pointer from after "sys" call
|
||||||
|
" read inode; if current user is not owner, return error to user
|
||||||
isown: 0
|
isown: 0
|
||||||
jms argname
|
jms argname
|
||||||
jms iget
|
jms iget
|
||||||
lac u.uid
|
lac u.uid " get user id
|
||||||
sma
|
sma " super user?
|
||||||
sad i.uid
|
sad i.uid " no: does user own file?
|
||||||
skp
|
skp " yes, or super user
|
||||||
jms error
|
jms error " not super user, not owner: return error
|
||||||
jmp isown i
|
jmp isown i
|
||||||
|
|
||||||
|
|||||||
+19
-18
@@ -43,24 +43,25 @@ t = t+4
|
|||||||
" Given a pointer to a 4-word filename after
|
" Given a pointer to a 4-word filename after
|
||||||
" the jms to namei, and with AC holding the
|
" the jms to namei, and with AC holding the
|
||||||
" i-num of the directory it is in, return the
|
" i-num of the directory it is in, return the
|
||||||
" i-number of the filename, or 0 if not found
|
" i-number of the filename (and skip)
|
||||||
|
" return zero in AC if not found (no skip)
|
||||||
namei: 0
|
namei: 0
|
||||||
jms iget " Get the inode from the i-num in the AC
|
jms iget " Get the inode from the i-num in the AC
|
||||||
-1
|
-1
|
||||||
tad namei i
|
tad namei i " get argptr-1
|
||||||
dac 9f+t+1
|
dac 9f+t+1 " save in t1
|
||||||
isz namei
|
isz namei " skip over argument
|
||||||
lac i.flags
|
lac i.flags
|
||||||
and o20 " Is this a directory?
|
and o20 " get directory bit
|
||||||
sna
|
sna " Is this a directory?
|
||||||
jmp namei i " No, loop back
|
jmp namei i " no: return without skip
|
||||||
-8
|
-8
|
||||||
tad i.size " Subtract 8 from the file's size
|
tad i.size " Subtract 8 from the file's size
|
||||||
cma
|
cma
|
||||||
lrss 3
|
lrss 3
|
||||||
dac 9f+t
|
dac 9f+t " negative count of directory entries in t0
|
||||||
sna
|
sna " any?
|
||||||
jmp namei i
|
jmp namei i " no: return without skip
|
||||||
dzm di " Store zero in di
|
dzm di " Store zero in di
|
||||||
1:
|
1:
|
||||||
lac di
|
lac di
|
||||||
@@ -68,10 +69,10 @@ namei: 0
|
|||||||
"** 01-s1.pdf page 35
|
"** 01-s1.pdf page 35
|
||||||
|
|
||||||
jms dget " Get a directory entry from the dirblock
|
jms dget " Get a directory entry from the dirblock
|
||||||
lac d.i
|
lac d.i " get i-num
|
||||||
sna
|
sna " in use?
|
||||||
jmp 2f
|
jmp 2f " no
|
||||||
lac 9f+t+1
|
lac 9f+t+1 " get argptr-1
|
||||||
dac 8
|
dac 8
|
||||||
lac d.name " Compare the four words of the filename in the
|
lac d.name " Compare the four words of the filename in the
|
||||||
sad 8 i " directory entry with the argument to namei
|
sad 8 i " directory entry with the argument to namei
|
||||||
@@ -90,13 +91,13 @@ namei: 0
|
|||||||
skp
|
skp
|
||||||
jmp 2f " No match
|
jmp 2f " No match
|
||||||
lac d.i " A match. Get the i-number into AC
|
lac d.i " A match. Get the i-number into AC
|
||||||
isz namei " Skip over the argument and return
|
isz namei " give skip return
|
||||||
jmp namei i
|
jmp namei i
|
||||||
2:
|
2:
|
||||||
isz di " No match, move up to the next direntry
|
isz di " No match, move up to the next direntry
|
||||||
isz 9f+t
|
isz 9f+t " any left?
|
||||||
jmp 1b
|
jmp 1b " yes: keep going
|
||||||
jmp namei i " Didn't find it, return zero in AC
|
jmp namei i " Didn't find it, return zero in AC (without skip)
|
||||||
t = t+2
|
t = t+2
|
||||||
" Given an i-number in AC, fetch that i-node
|
" Given an i-number in AC, fetch that i-node
|
||||||
" from disk and store it in the inode buffer
|
" from disk and store it in the inode buffer
|
||||||
|
|||||||
+1
-1
@@ -77,7 +77,7 @@ rrb = 0700112 " PTR: clear flag, or read buffer
|
|||||||
psf = 0700201 " PTP: skip if flag set
|
psf = 0700201 " PTP: skip if flag set
|
||||||
pcf = 0700202 " PTP: clear flag
|
pcf = 0700202 " PTP: clear flag
|
||||||
psa = 0700204 " PTP: alphanumeric mode
|
psa = 0700204 " PTP: alphanumeric mode
|
||||||
cdf = 0700501 " ???
|
cdf = 0700501 " G-2: clear display flags
|
||||||
lds = 0701052 " G-2: load display status
|
lds = 0701052 " G-2: load display status
|
||||||
lda = 0701012 " G-2: load display address
|
lda = 0701012 " G-2: load display address
|
||||||
wcga = 0704206 " G-2: ???
|
wcga = 0704206 " G-2: ???
|
||||||
|
|||||||
Reference in New Issue
Block a user