Calculate kernel size in pages dinamically

This commit is contained in:
2025-07-31 23:37:31 +02:00
parent d12bfbcd43
commit 3e50e74526
3 changed files with 136 additions and 34 deletions

View File

@@ -2,9 +2,6 @@
# 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 write_s, write_c
.global memcmp, memchr, memmem, memcpy, bzero
.section .text
# a0 - First pointer.
@@ -13,6 +10,7 @@
#
# Returns 0 in a0 if memory regions are equal.
.type memcmp, @function
.globl memcmp
memcmp:
mv t0, a0
li a0, 0
@@ -41,6 +39,7 @@ memcmp:
# a0 - String pointer.
# a1 - Length of the string.
.type write_s, @function
.globl write_s
write_s:
# Prologue.
addi sp, sp, -32
@@ -80,6 +79,7 @@ write_s:
# Arguments:
# a0 - Character.
.type write_c, @function
.globl write_c
write_c:
li a1, 0
li a2, 0
@@ -102,6 +102,7 @@ write_c:
# Sets a0 to the pointer to the found character or to null if the character
# doesn't occur in the memory block.
.type memchr, @function
.globl memchr
memchr:
.Lmemchr_loop:
beqz a2, .Lmemchr_nil # Exit if the length is 0.
@@ -132,6 +133,7 @@ memchr:
# Sets a0 to the pointer to the beginning of the substring in memory or to 0
# if the substring doesn't occur in the block.
.type memmem, @function
.globl memmem
memmem:
# Prologue.
addi sp, sp, -24
@@ -193,6 +195,7 @@ memmem:
#
# Preserves a0.
.type memcpy, @function
.globl memcpy
memcpy:
mv t0, a0
@@ -200,30 +203,37 @@ memcpy:
beqz a2, .Lmemcpy_end
lbu t1, (a1)
sb t1, (a0)
sb t1, (t0)
addi a0, a0, 1
addi t0, t0, 1
addi a1, a1, 1
addi a2, a2, -1
j .Lmemcpy_loop
.Lmemcpy_end:
mv a0, t0
ret
# Zeroes a chank of memory.
# Sets a memory region to the given byte value.
#
# Parameters:
# a0 - Memory pointer.
# a1 - Memory size.
bzero:
# a0 - Memory chunk to fill.
# a1 - Constant byte.
# a2 - Memory size.
.type memset, @function
.globl memset
memset:
mv t0, a0
.Lbzero_loop:
bgt t0, a1, .Lbzero_end
sb zero, (t0)
.Lmemset_loop:
beqz a2, .Lmemset_end
sb a1, (t0)
addi a2, a2, -1
addi t0, t0, 1
.Lbzero_end:
j .Lmemset_loop
.Lmemset_end:
ret