Skip to content

Commit

Permalink
change allocate/deallocate to use rewritable code instead of code poi…
Browse files Browse the repository at this point in the history
…nter
  • Loading branch information
devyn committed Aug 9, 2023
1 parent 5e64ba8 commit d6e5312
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
24 changes: 6 additions & 18 deletions stage1/memory.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@

.bss

.align 3
.global ALLOCATE
ALLOCATE: .skip 8 # builtin_allocate

.align 3
.global DEALLOCATE
DEALLOCATE: .skip 8 # builtin_deallocate

.align 3
.global BUILTIN_HEAP_PTR
BUILTIN_HEAP_PTR: .skip 8 # _heap_start
Expand All @@ -41,32 +33,28 @@ _object_region_start: .skip 0xc0000 # 768 KiB

.text

# rewritable with up to 6 instructions
# args: a0 = bytes to allocate, a1 = alignment
# ret: a0 = pointer on success, zero on failure
.global allocate
allocate:
ld t0, (ALLOCATE)
jalr zero, (t0)
jal zero, builtin_allocate
.skip 5 * 4

# rewritable with up to 6 instructions
# args: a0 = pointer, a1 = number of bytes
# ret: a0 = 0
.global deallocate
deallocate:
ld t0, (DEALLOCATE)
jalr zero, (t0)
jal zero, builtin_deallocate
.skip 5 * 4

.global memory_init
memory_init:
addi sp, sp, -0x10
sd ra, 0x00(sp)
sd s1, 0x08(sp)
# initialize globals
la t1, builtin_allocate
la t2, ALLOCATE
sd t1, (t2)
la t1, builtin_deallocate
la t2, DEALLOCATE
sd t1, (t2)
la t1, _heap_start
la t2, BUILTIN_HEAP_PTR
sd t1, (t2)
Expand Down
12 changes: 6 additions & 6 deletions stage1/words.s
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ INITIAL_WORDS:
.ascii "eval"
.balign 8

.quad ALLOCATE
.2byte 10
.quad allocate
.2byte 9
.byte LISP_OBJECT_TYPE_INTEGER
.ascii "allocate$$"
.ascii "allocate$"
.balign 8

.quad DEALLOCATE
.2byte 12
.quad deallocate
.2byte 11
.byte LISP_OBJECT_TYPE_INTEGER
.ascii "deallocate$$"
.ascii "deallocate$"
.balign 8

.quad define
Expand Down
2 changes: 1 addition & 1 deletion stage2.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
; (allocate <size> <align>)
(define allocate (proc args scope
(car
(call-native (peek.d allocate$$)
(call-native allocate$
(eval scope (car args))
(eval scope (cadr args))))))

Expand Down

0 comments on commit d6e5312

Please sign in to comment.