1
\ *****************************************************************************
2
\ * Copyright (c) 2004, 2011 IBM Corporation
3
\ * All rights reserved.
4
\ * This program and the accompanying materials
5
\ * are made available under the terms of the BSD License
6
\ * which accompanies this distribution, and is available at
7
\ * http://www.opensource.org/licenses/bsd-license.php
10
\ * IBM Corporation - initial implementation
11
\ ****************************************************************************/
13
\ Claim memory for segment
14
\ Abort, if no memory available
16
false value elf-claim?
19
\ cur-brk is set by elf loader to end of data segment
23
: elf-claim-segment ( addr size -- errorcode )
27
here last-claim , to last-claim \ Setup ptr to last claim
28
\ Put addr and size in the data space
29
dup , r> dup , ( addr size )
31
." Memory for ELF file is already in use!" cr
32
true ABORT" Memory for ELF file already in use "
43
\ Load ELF file and claim the corresponding memory regions.
44
\ A destination address can be specified. If the parameter is -1 then
45
\ the file is loaded to the ddress that is specified in its header.
46
: elf-load-claim ( file-addr destaddr -- claim-list entry imagetype )
49
dup -1 = IF \ If destaddr == -1 then load to addr from ELF header
50
drop ['] elf-load-file CATCH IF false to elf-claim? ABORT THEN
52
['] elf-load-file-to-addr CATCH IF false to elf-claim? ABORT THEN
61
\ Release memory claimed before
63
: elf-release ( claim-list -- )
65
dup cell+ ( claim-list claim-list-addr )
66
dup @ swap cell+ @ ( claim-list claim-list-addr claim-list-sz )
67
release ( claim-list )
68
@ dup 0= ( Next-element )