Parse procedure parameters
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
# obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
.global symbol_table_build
|
||||
.global symbol_table_build, symbol_table_find
|
||||
|
||||
.include "boot/definitions.inc"
|
||||
|
||||
@@ -49,6 +49,70 @@ symbol_table: .zero SYMBOL_PRIME
|
||||
|
||||
.section .text
|
||||
|
||||
# Searches for a symbol by name.
|
||||
#
|
||||
# Parameters:
|
||||
# a0 - Local symbol table or 0.
|
||||
# a1 - Length of the symbol to search.
|
||||
# a2 - Pointer to the symbol name.
|
||||
#
|
||||
# Sets a0 to the symbol info.
|
||||
.type symbol_table_find, @function
|
||||
symbol_table_find:
|
||||
# Prologue.
|
||||
addi sp, sp, -32
|
||||
sw ra, 28(sp)
|
||||
sw s0, 24(sp)
|
||||
addi s0, sp, 32
|
||||
|
||||
sw s1, 20(sp) # Current symbol in the table.
|
||||
sw s2, 16(sp) # Symbol table length.
|
||||
sw s3, 12(sp) # Length of the symbol to search.
|
||||
sw s4, 8(sp) # Pointer to the symbol to search.
|
||||
|
||||
mv s3, a1
|
||||
mv s4, a2
|
||||
|
||||
la s1, symbol_table
|
||||
lw s2, 0(s1)
|
||||
addi s1, s1, 4 # Advance to the first symbol in the table.
|
||||
|
||||
.Lsymbol_table_find_loop:
|
||||
beqz s2, .Lsymbol_table_find_not_found
|
||||
|
||||
# Compare string lengths.
|
||||
lw a2, 0(s1)
|
||||
bne s3, a2, .Lsymbol_table_find_continue
|
||||
|
||||
# If lengths match, compare the content.
|
||||
mv a0, s4
|
||||
lw a1, 4(s1)
|
||||
call _memcmp
|
||||
|
||||
bnez a0, .Lsymbol_table_find_continue
|
||||
|
||||
lw a0, 8(s1) # Pointer to the symbol.
|
||||
j .Lsymbol_table_end
|
||||
|
||||
.Lsymbol_table_find_continue:
|
||||
addi s2, s2, -1
|
||||
j .Lsymbol_table_find_loop
|
||||
|
||||
.Lsymbol_table_find_not_found:
|
||||
li a0, 0
|
||||
|
||||
.Lsymbol_table_end:
|
||||
lw s1, 20(sp)
|
||||
lw s2, 16(sp)
|
||||
lw s3, 12(sp)
|
||||
lw s4, 8(sp)
|
||||
|
||||
# Epilogue.
|
||||
lw ra, 28(sp)
|
||||
lw s0, 24(sp)
|
||||
addi sp, sp, 32
|
||||
ret
|
||||
|
||||
# Build the initial symbols.
|
||||
#
|
||||
# Sets a0 to the pointer to the global symbol table.
|
||||
|
Reference in New Issue
Block a user