aboutsummaryrefslogtreecommitdiff
path: root/src/mylloc.s
diff options
context:
space:
mode:
Diffstat (limited to 'src/mylloc.s')
-rw-r--r--src/mylloc.s50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/mylloc.s b/src/mylloc.s
new file mode 100644
index 0000000..9657b73
--- /dev/null
+++ b/src/mylloc.s
@@ -0,0 +1,50 @@
+;;# struct block {
+;;# void *addr; // pointer to the start address of the block
+;;# u32 size; // the size of the block
+;;# void *next // pointer to the previous block
+;;# };
+#
+#;; .section .data
+#
+#;; ;;;# Constants
+#;; .equ SYS_BRK, 214
+#;; .equ BLOCK_SZ, 12
+#;; .equ BLOCK_ARR_CAP, 1024
+#
+#;; .section .bss
+#
+#;; system_break_start:
+#;; .space 4
+#;; system_break_cur:
+#;; .space 4
+#
+#;; block_root:
+#;; .space BLOCK_SZ
+#;; block_arr:
+#;; .space BLOCK_SZ * BLOCK_ARR_CAP
+#
+#;; .section .text
+#
+#;; .globl malloc
+#;; .globl free
+#
+#;; malloc:
+#;; mv t6, a0 ;# save the arg
+#
+#;; la t1, system_break_start ;# load the break
+#;; la t2, system_break_cur ;#
+#;; lw a0, 0(t1) ;# has the break been initialized
+#;; bnez a0, block_loop ;#
+#
+#;; li a7, SYS_BRK ;# do brk syscall with an invalid arg
+#;; ecall ;# to get the current break
+#
+#;; sw a0 0(t1) ;# save the break
+#;; sw a0 0(t2) ;#
+#
+#;; block_loop: ;# in this loop find the first free address
+#
+#;; ret
+#;; free:
+#;; ret
+#