-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from fourstix/b_name_update
Change name of MemoryHog to malloc, add mfree and xtrim utilities
- Loading branch information
Showing
11 changed files
with
481 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
; ******************************************************************************************* | ||
; malloc - Allocate a block of memory on the heap for testing low memory conditions. | ||
; Copyright (c) 2021 by Gaston Williams | ||
; ******************************************************************************************* | ||
|
||
include bios.inc | ||
include kernel.inc | ||
; ************************************************************ | ||
; This block generates the Execution header | ||
; It occurs 6 bytes before the program start. | ||
; ************************************************************ | ||
ORG 02000h-6 ; Header starts at 01ffah | ||
dw 02000h ; Program load address | ||
dw endrom-2000h ; Program size | ||
dw 02000h ; Program execution address | ||
|
||
ORG 02000h ; code starts here | ||
br start ; Jump past build info to code | ||
|
||
; Build information | ||
binfo: db 80H+8 ; Month, 80H offset means extended info | ||
db 21 ; Day | ||
dw 2021 ; Year | ||
|
||
; Current build number | ||
build: dw 4 | ||
|
||
; Must end with 0 (null) | ||
db 'Copyright 2021 Gaston Williams',0 | ||
|
||
; ========================================================================================= | ||
; Main | ||
; ========================================================================================= | ||
|
||
start: lda ra ; move past any spaces | ||
smi ' ' | ||
lbz start | ||
dec ra ; move back to non-space character | ||
ldn ra ; check for nonzero byte | ||
lbnz good ; jump if non-zero | ||
lbr usage ; no size or opt, show usage message | ||
good: smi '-' ; was it a dash to indicate option? | ||
lbnz getsize ; if not a dash, get size | ||
|
||
inc ra ; move to next character | ||
lda ra ; check for fill option | ||
smi 'f' | ||
lbnz usage ; bad option, show usage message | ||
sp_1: lda ra ; move past any spaces | ||
smi ' ' | ||
lbz sp_1 | ||
dec ra ; back up to non-space character | ||
ldn ra ; check for nonzero byte | ||
lbz usage ; show message if end of string | ||
mov rf, fill ; set flag to fill memory block | ||
ldi 0FFh | ||
str rf | ||
|
||
ghi ra ; point rf to hex value in argument string | ||
phi rf | ||
glo ra | ||
plo rf | ||
sep scall ; convert input to hex value | ||
dw f_hexin | ||
ghi rf ; point ra to end of hex value in argument string | ||
phi ra | ||
glo rf | ||
plo ra | ||
|
||
mov rf, padding ; point rf to the padding value | ||
glo rd ; get the hexadecimal byte value | ||
str rf ; put in the padding value | ||
sp_2: lda ra ; move past any spaces | ||
smi ' ' | ||
lbz sp_2 | ||
dec ra ; back up to non-space character | ||
ldn ra ; check for zero | ||
lbz usage ; missing size, show usage message | ||
|
||
getsize: ghi ra ; copy argument address to rf | ||
phi rf | ||
glo ra | ||
plo rf | ||
sep scall ; convert input to integer value | ||
dw f_atoi | ||
|
||
ghi rd ; RD contains the block size in bytes | ||
phi rc ; Move size into RC for allocate | ||
glo rd | ||
plo rc ; load block size | ||
ldi 00H ; no alignment | ||
|
||
phi r7 | ||
ldi 04H ; permanent allocation | ||
plo r7 | ||
|
||
sep scall ; allocate a block of memory | ||
dw o_alloc | ||
lbdf bad_blk ; DF = 1 means allocation failed | ||
|
||
ghi rf ; point rd to block, rc contains size | ||
phi rd | ||
glo rf | ||
plo rd | ||
mov rf, fill ; check fill byte | ||
lda rf ; get fill flag, advance pointer to padding byte | ||
lbz goodbye ; if no fill, then we are done | ||
fillmem: ldn rf ; get the padding byte | ||
str rd ; put into memory block | ||
inc rd ; advance to next byte | ||
dec rc ; bump counter | ||
ghi rc ; check high byte of counter | ||
lbnz fillmem ; repeat if not zero | ||
glo rc ; check low byte | ||
lbnz fillmem ; repeat until count is zero | ||
lbr goodbye ; Once block is filled, we are done | ||
bad_blk: sep scall ; display test message | ||
dw o_inmsg | ||
db 'Allocation failed.',13,10,0 | ||
lbr goodbye | ||
|
||
usage: sep scall ; display usage information | ||
dw o_inmsg | ||
db 'Usage: malloc [-f hh] <size>, allocate a memory block of <size> oon the heap.',13,10,0 | ||
sep scall | ||
dw o_inmsg | ||
db 'Option: -f hh, fill memory block with byte hh',13,10,0 | ||
; falls through to exit | ||
goodbye: lbr o_wrmboot ; return to Elf/OS | ||
;---------------------------------------------------------------------------------------- | ||
fill: db 0 | ||
padding: db 0 | ||
|
||
; define end of execution block | ||
endrom: EQU $ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.