aboutsummaryrefslogtreecommitdiff
path: root/src/mylloc.s
blob: 9657b7362bf0b539602564c8375d1122dab32552 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
#