Commit 85f92e4f authored by Jeffrey Lee's avatar Jeffrey Lee Committed by ROOL
Browse files

Improve LibKern

Add kalloc (malloc with an error pointer), free, _kernel_irqs_disabled,
_kernel_irqs_off, _kernel_irqs_on, and a simple memcpy implementation.

Export the symbols so they're actually usable from other object files.
parent bc963b02
......@@ -16,6 +16,7 @@
; void *memset(void *s, int c, size_t n) -------------------------------------------------
EXPORT memset
ROUT
memset
TEQ a3, #0 ; return immediately if zero bytes
......@@ -75,6 +76,7 @@ memset
B %BT05
; unsigned __rt_udiv(unsigned divisor, unsigned dividend) --------------------------------
EXPORT |__rt_udiv|
ROUT
|__rt_udiv|
; Unsigned divide of a2 by a1: returns quotient in a1, remainder in a2
......@@ -132,4 +134,55 @@ u_sh0 RSBS ip, a1, a2
dividebyzero
B dividebyzero
; void *kalloc (size_t size, _kernel_oserror **e)
; It's malloc, but it stores any received error in 'e'.
; 'e' is only written to if there's an error, so you can make several calls
; using just one _kernel_oserror *.
EXPORT kalloc
kalloc ROUT
Entry "r4"
MOV r4, r1
; System heap should be sufficient
MOV r3, r0
BL ClaimSysHeapNode
STRVS r0, [r4]
MOVVS r0, #0
MOVVC r0, r2
EXIT
EXPORT free
free ROUT
MOVS r2, r0
BNE FreeSysHeapNode
MOV pc, lr
; void *memcpy(void *dest,void *src,size_t len)
EXPORT memcpy
memcpy ROUT
10
SUBS a3, a3, #1
LDRGEB ip, [a2, a3]
STRGEB ip, [a1, a3]
BGT %BT10
MOV pc, lr
; int _kernel_irqs_disabled(void)
EXPORT |_kernel_irqs_disabled|
|_kernel_irqs_disabled|
MRS a1, CPSR
AND a1, a1, #I32_bit
MOV pc,lr
; void _kernel_irqs_off(void)
EXPORT |_kernel_irqs_off|
|_kernel_irqs_off|
SEI ,a1
MOV pc,lr
; void _kernel_irqs_on(void)
EXPORT |_kernel_irqs_on|
|_kernel_irqs_on|
CLI ,a1
MOV pc,lr
END
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment