diff options
| author | Eugen Wissner <belka@caraus.de> | 2025-05-09 18:42:46 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2025-05-09 18:42:46 +0200 |
| commit | 890486532c0715fcd0a0c64100d8b8167239d55a (patch) | |
| tree | eafa619486d8babe81ed72f3c65737c2253cc297 /boot/common-boot.s | |
| parent | 92f50fff5f8a9ec2db03cc57dbf00a43e64943bf (diff) | |
| download | elna-890486532c0715fcd0a0c64100d8b8167239d55a.tar.gz | |
Wrap the mmap2 syscall
Diffstat (limited to 'boot/common-boot.s')
| -rw-r--r-- | boot/common-boot.s | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/boot/common-boot.s b/boot/common-boot.s index 2a192d3..ad57b41 100644 --- a/boot/common-boot.s +++ b/boot/common-boot.s @@ -5,17 +5,22 @@ .global _is_alpha, _is_digit, _is_alnum, _is_upper, _is_lower .global _write_out, _read_file, _write_error, _put_char, _printi .global _get, _memcmp, _memchr, _memmem, _memcpy -.global _divide_by_zero_error, _exit -.global _strings_index +.global _divide_by_zero_error, _exit, _mmap +.global _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 .equ STDERR, 2 +.equ PROT_READ, 0x1 +.equ PROT_WRITE, 0x2 +.equ MAP_PRIVATE, 0x02 +.equ MAP_ANONYMOUS, 0x20 new_line: .ascii "\n" @@ -500,3 +505,58 @@ _strings_index: lw s0, 24(sp) add sp, sp, 32 ret + +# Compares two strings for equality. +# +# Parameters: +# a0 - Length of the first string. +# a1 - Pointer to the first string. +# a2 - Length of the second string. +# a3 - Pointer to the second string. +# +# Sets a0 to 1 if the string are equal, to 0 if not. +.type _string_equal, @function +_string_equal: + # Prologue. + addi sp, sp, -32 + sw ra, 28(sp) + sw s0, 24(sp) + addi s0, sp, 32 + + # Compare string lengths. + bne a0, a2, .Lstring_equal_not_found + + # If lengths match, compare the content. + mv a0, a1 + mv a1, a3 + # a2 is already set to the length. + call _memcmp + + bnez a0, .Lstring_equal_not_found + + li a0, 1 + j .Lstring_equal_end + +.Lstring_equal_not_found: + mv a0, zero + +.Lstring_equal_end: + # Epilogue. + lw ra, 28(sp) + lw s0, 24(sp) + addi sp, sp, 32 + ret + +# Sets a0 to the mapping address. +.type _mmap, @function +_mmap: + li a0, 0 # Address at which to create the mapping. + li a1, 4096 # The length of the mapping. + li a2, PROT_READ | PROT_WRITE # Protection flags. + li a3, MAP_ANONYMOUS | MAP_PRIVATE # The mapping is not backed by a file. + li a4, -1 # File descriptor. + li a5, 0 # Page offset. + li a7, SYS_MMAP2 + ecall + + ret |
