summaryrefslogtreecommitdiff
path: root/boot/common-boot.s
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2025-08-28 22:45:42 +0200
committerEugen Wissner <belka@caraus.de>2025-08-30 01:29:00 +0200
commit627975775c941130975ce0f9dbef08c723e69794 (patch)
tree0f7f4c2c6d83420262d89ff720e6435a67410c9a /boot/common-boot.s
parente614d43ea9af078301d538fcddb19e83eed7e879 (diff)
downloadelna-627975775c941130975ce0f9dbef08c723e69794.tar.gz
Start over
Diffstat (limited to 'boot/common-boot.s')
-rw-r--r--boot/common-boot.s268
1 files changed, 3 insertions, 265 deletions
diff --git a/boot/common-boot.s b/boot/common-boot.s
index f61321e..9305d40 100644
--- a/boot/common-boot.s
+++ b/boot/common-boot.s
@@ -2,17 +2,15 @@
# 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 _is_alpha, _is_digit, _is_alnum, _is_upper, _is_lower
-.global _write_s, _read_file, _write_error, _write_c, _write_i, _print_i
-.global _memcmp, _memchr, _memmem, _memcpy, _mmap
+.global _read_file, _write_error
+.global _memcmp, _memchr, _memmem, _mmap
.global _current, _get, _advance, _label_counter
-.global _divide_by_zero_error, _exit, _strings_index, _string_equal
+.global _divide_by_zero_error, _strings_index, _string_equal
.section .rodata
.equ SYS_READ, 63
.equ SYS_WRITE, 64
-.equ SYS_EXIT, 93
.equ SYS_MMAP2, 222
.equ STDIN, 0
.equ STDOUT, 1
@@ -77,128 +75,6 @@ _memcmp:
.Lmemcmp_end:
ret
-# Detects if a0 is an uppercase character. Sets a0 to 1 if so, otherwise to 0.
-.type _is_upper, @function
-_is_upper:
- li t0, 'A' - 1
- sltu t1, t0, a0 # t1 = a0 >= 'A'
-
- sltiu t2, a0, 'Z' + 1 # t2 = a0 <= 'Z'
- and a0, t1, t2 # t1 = a0 >= 'A' & a0 <= 'Z'
-
- ret
-
-# Detects if a0 is an lowercase character. Sets a0 to 1 if so, otherwise to 0.
-.type _is_lower, @function
-_is_lower:
- li t0, 'a' - 1
- sltu t2, t0, a0 # t2 = a0 >= 'a'
-
- sltiu t3, a0, 'z' + 1 # t3 = a0 <= 'z'
- and a0, t2, t3 # t2 = a0 >= 'a' & a0 <= 'z'
-
- ret
-
-# Detects if the passed character is a 7-bit alpha character or an underscore.
-# The character is passed in a0.
-# Sets a0 to 1 if the character is an alpha character or underscore, sets it to 0 otherwise.
-.type _is_alpha, @function
-_is_alpha:
- # Prologue.
- addi sp, sp, -16
- sw ra, 12(sp)
- sw s0, 8(sp)
- addi s0, sp, 16
-
- sw a0, 4(sp)
-
- call _is_upper
- sw a0, 0(sp)
-
- lw a0, 4(sp)
- call _is_lower
-
- lw t0, 4(sp)
- xori t1, t0, '_'
- seqz t1, t1
-
- lw t0, 0(sp)
- or a0, a0, t0
- or a0, a0, t1
-
- # Epilogue.
- lw ra, 12(sp)
- lw s0, 8(sp)
- addi sp, sp, 16
- ret
-
-# Detects whether the passed character is a digit
-# (a value between 0 and 9).
-#
-# Parameters:
-# a0 - Exemined value.
-#
-# Sets a0 to 1 if it is a digit, to 0 otherwise.
-.type _is_digit, @function
-_is_digit:
- li t0, '0' - 1
- sltu t1, t0, a0 # t1 = a0 >= '0'
-
- sltiu t2, a0, '9' + 1 # t2 = a0 <= '9'
-
- and a0, t1, t2
-
- ret
-
-.type _is_alnum, @function
-_is_alnum:
- # Prologue.
- addi sp, sp, -16
- sw ra, 12(sp)
- sw s0, 8(sp)
- addi s0, sp, 16
-
- sw a0, 4(sp)
-
- call _is_alpha
- sw a0, 0(sp)
-
- lw a0, 4(sp)
- call _is_digit
-
- lw a1, 0(sp)
- or a0, a0, a1
-
- # Epilogue.
- lw ra, 12(sp)
- lw s0, 8(sp)
- addi sp, sp, 16
- ret
-
-# Writes a string to the standard output.
-#
-# Parameters:
-# a0 - Length of the string.
-# a1 - String pointer.
-.type _write_s, @function
-_write_s:
- # Prologue.
- addi sp, sp, -8
- sw ra, 4(sp)
- sw s0, 0(sp)
- addi s0, sp, 8
-
- mv a2, a0
- li a0, STDOUT
- li a7, SYS_WRITE
- ecall
-
- # Epilogue.
- lw ra, 4(sp)
- lw s0, 0(sp)
- addi sp, sp, 8
- ret
-
# Reads standard input into a buffer.
# a0 - Buffer pointer.
# a1 - Buffer size.
@@ -228,16 +104,6 @@ _read_file:
addi sp, sp, 8
ret
-# Terminates the program. a0 contains the return code.
-#
-# Parameters:
-# a0 - Status code.
-.type _exit, @function
-_exit:
- li a7, SYS_EXIT
- ecall
- # ret
-
.type _divide_by_zero_error, @function
_divide_by_zero_error:
addi a7, zero, 172 # getpid
@@ -248,106 +114,6 @@ _divide_by_zero_error:
ecall
ret
-# Writes a number to a string buffer.
-#
-# t0 - Local buffer.
-# t1 - Constant 10.
-# t2 - Current character.
-# t3 - Whether the number is negative.
-#
-# Parameters:
-# a0 - Whole number.
-# a1 - Buffer pointer.
-#
-# Sets a0 to the length of the written number.
-.type _print_i, @function
-_print_i:
- addi sp, sp, -32
- sw ra, 28(sp)
- sw s0, 24(sp)
- addi s0, sp, 32
-
- li t1, 10
- addi t0, s0, -9
-
- li t3, 0
- bgez a0, .Lprint_i_digit10
- li t3, 1
- neg a0, a0
-
-.Lprint_i_digit10:
- rem t2, a0, t1
- addi t2, t2, '0'
- sb t2, 0(t0)
- div a0, a0, t1
- addi t0, t0, -1
- bne zero, a0, .Lprint_i_digit10
-
- beq zero, t3, .Lprint_i_write_call
- addi t2, zero, '-'
- sb t2, 0(t0)
- addi t0, t0, -1
-
-.Lprint_i_write_call:
- mv a0, a1
- addi a1, t0, 1
- sub a2, s0, t0
- addi a2, a2, -9
- sw a2, 0(sp)
-
- call _memcpy
-
- lw a0, 0(sp)
-
- lw ra, 28(sp)
- lw s0, 24(sp)
- addi sp, sp, 32
- ret
-
-# Writes a number to the standard output.
-#
-# Parameters:
-# a0 - Whole number.
-.type _write_i, @function
-_write_i:
- addi sp, sp, -32
- sw ra, 28(sp)
- sw s0, 24(sp)
- addi s0, sp, 32
-
- addi a1, sp, 0
- call _print_i
-
- addi a1, sp, 0
- call _write_s
-
- lw ra, 28(sp)
- lw s0, 24(sp)
- addi sp, sp, 32
- ret
-
-# Writes a character from a0 into the standard output.
-.type _write_c, @function
-_write_c:
- # Prologue
- addi sp, sp, -16
- sw ra, 12(sp)
- sw s0, 8(sp)
- addi s0, sp, 16
-
- sb a0, 4(sp)
- li a0, STDOUT
- addi a1, sp, 4
- li a2, 1
- li a7, SYS_WRITE
- ecall
-
- # Epilogue.
- lw ra, 12(sp)
- lw s0, 8(sp)
- add sp, sp, 16
- ret
-
# a0 - Pointer to an array to get the first element.
#
# Dereferences a pointer and returns what is on the address in a0.
@@ -448,34 +214,6 @@ _memmem:
add sp, sp, 24
ret
-# Copies memory.
-#
-# Parameters:
-# a0 - Destination.
-# a1 - Source.
-# a2 - Size.
-#
-# Preserves a0.
-.type _memcpy, @function
-_memcpy:
- mv t0, a0
-
-.Lmemcpy_loop:
- beqz a2, .Lmemcpy_end
-
- lbu t1, (a1)
- sb t1, (a0)
-
- addi a0, a0, 1
- addi a1, a1, 1
- addi a2, a2, -1
-
- j .Lmemcpy_loop
-
-.Lmemcpy_end:
- mv a0, t0
- ret
-
# Searches for a string in a string array.
#
# Parameters: