Skip to content

Instantly share code, notes, and snippets.

@allaryin
Last active August 24, 2018 21:57
Show Gist options
  • Save allaryin/1dc317f0027388fb2ec82466e4329343 to your computer and use it in GitHub Desktop.
Save allaryin/1dc317f0027388fb2ec82466e4329343 to your computer and use it in GitHub Desktop.
exapunks bus controller
...
... grab list of block pairs to read/write then return and repl the kids
...
mark chunk_copier
make
note X = read, T = write
copy x f
copy t f
seek -9999
link 800
note get permission for our room
divi f 100 x
mark get_read_room
copy x m
mode
copy m t
note ## NB: true = retry, false = go ahead
fjmp read_room
note ## room locked, must retry
copy 10 t
mark wait_retry_read
subi t 1 t
tjmp wait_retry_read
mode
jump get_read_room
mark read_room
addi 800 x x
link x
seek -9999
copy f x
modi x 10 t
swiz x 2 x
addi 200 x
muli t 10 t
repl reader
copy 10 t
seek 9999
mark buf_read
copy m f
subi t 1 t
tjmp buf_read
note ## return the lock
mode
seek -9999
link -1
divi f -100 m
note ## and get write room
seek 1
divi f 100 x
mark get_write_room
copy x m
mode
copy m t
fjmp write_room
copy 10 t
mark wait_retry_write
subi t 1 t
tjmp wait_retry_write
mode
jump get_write_room
mark write_room
addi 800 x x
link x
seek -1
copy f x
modi x 10 t
swiz x 2 x
addi 200 x
muli t 10 t
repl writer
mark buf_write
copy f m
test eof
fjmp buf_write
note ## return mutex again
mode
seek -9999
link -1
divi f -100 m
wipe
halt
note ##########
mark reader
grab x
seek t
note ## we are in local mode
mark read
copy f m
jump read
note ##########
mark writer
grab x
seek t
note ## we are in local mode
mark write
copy m f
jump write
make
note first block is return count
copy 20 f
@rep 5
copy 0 f
@end
note listening global
mark loop
seek -9999
copy m x
test x > 0
fjmp return
note request
seek x
mode
copy f m
mode
seek -1
copy 1 f
jump loop
mark return
subi f 1 t
fjmp done
muli x -1 x
seek -1
seek x
copy 0 f
jump loop
mark done
wipe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment