[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 6502 Multitasking OS announce
After a rethink ( and a quick brushup on 6502 asm :) )......
I think you can implement critical sections using the set & test that
the 6502 provides. I think sal ( or sar ) are the best for this
purpose because no matter how many threads try concurrently to get the
cs only one will succeed.
The Idea is that in the non-entered state the cs memory contains the
lsb set. One ( and only one ) process can then roll the bit off to
the carry flag.
to release it all you need to do is set that bit again. I written a
couple of routines that do just that. They also allow the same
process to get the same cs again ( otherwise you can deadlock ).
get_cs:
jsr get_current_process ;make sure it's the righe process
cmp cs_page+2,x
beq inc_exit
sal cs_page,x ; try to get it
bcc loop:
inc_exit:
inc cs_page+1,x ; keep a count
jsr get_current_process ; asumes that process is returned in A
sta cs_page+2,x
ret
release_cs:
jsr get_current_process ;make sure it's the righe process
cmp cs_page+2,x
bnz exit
dec cs_page+1,x ; dec the count of who is using it
bnz exit
lda #0
sta cs_page+2,x ; cleanup owner
inc cs_page,x; ; clear cs
exit:
ret
To use these functions you set X with the cs number you want and call
the function.
Of course you'll need some setup code to set all the sections to 1,
and process Id's & counts to zero during the OS startup.
setup_cs
lda #1
ldx #0
loop:
sta cs_page,x
inx
bnz loop:
loop_2:
lda #0
sta cs_page+1,x
sta cs_page+2,x
inx
bnz loop_2:
If you find any instructions that are not exactly the right 6502
please excuse me.. it's been a while.
have fun
Ralph Mason