Skip to content

Commit

Permalink
Memory-backed blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
davazp committed Apr 15, 2012
1 parent 7882152 commit b9ecbdb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
37 changes: 35 additions & 2 deletions blocks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require @structures.fs

defer read-block-from-backend
defer write-block-to-backend
defer block-buffer

:noname -100 throw ; is read-block-from-backend
:noname -100 throw ; is write-block-to-backend
Expand All @@ -33,7 +34,6 @@ variable current-block
-1 current-block !

variable block-updated?
' floppy-buffer alias block-buffer

: update block-updated? on ;
: updated? block-updated? @ ;
Expand Down Expand Up @@ -83,7 +83,40 @@ variable scr
flush
detect-drive not if -100 throw then
['] read-block-from-floppy is read-block-from-backend
['] write-block-to-floppy is write-block-to-backend ;
['] write-block-to-floppy is write-block-to-backend
['] floppy-buffer is block-buffer ;

\ Memory backend

create memblock-buffer 1024 cells allot
variable memblock-index
variable #memblocks

: &memblock ( u -- addr )
cells memblock-index @ + ;

: allocate-memblock ( u -- addr )
1024 allocate throw tuck swap &memblock ! ;

: check-valid-memblock
0 over #memblocks @ between not if -101 throw then ;

: read-block-from-memory ( u -- )
check-valid-memblock
dup &memblock @ ?dup if nip else allocate-memblock then
memblock-buffer 1024 move ;

: write-block-to-memory ( u -- )
check-valid-memblock
memblock-buffer swap &memblock @ 1024 move ;


: use-memory flush
heap-size 1024 u/ #memblocks !
#memblocks @ cells allocate throw memblock-index !
memblock-index @ #memblocks @ cells 0 fill
['] read-block-from-memory is read-block-from-backend
['] write-block-to-memory is write-block-to-backend
['] memblock-buffer is block-buffer ;

\ blocks.fs ends here
2 changes: 1 addition & 1 deletion corestage2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ LIGHT GRAY UPON BLACK
require @tools.fs
require @kernel/interrupts.fs
require @kernel/exceptions.fs
require @debugger.fs
require @kernel/irq.fs
require @kernel/timer.fs
require @kernel/floppy.fs
Expand All @@ -38,7 +39,6 @@ require @kernel/cpuid.fs
require @blocks.fs
require @input.fs
require @editor.fs
require @debugger.fs

\ Rebooting the machine

Expand Down

0 comments on commit b9ecbdb

Please sign in to comment.