Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / slof / fs / elf.fs
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
8 \ *
9 \ * Contributors:
10 \ *     IBM Corporation - initial implementation
11 \ ****************************************************************************/
12
13 \ Claim memory for segment
14 \ Abort, if no memory available
15
16 false value elf-claim?
17 0     value last-claim
18
19 \ cur-brk is set by elf loader to end of data segment
20 0 VALUE cur-brk
21
22
23 : elf-claim-segment ( addr size -- errorcode )
24    2dup
25    elf-claim? IF
26       >r
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 )
30       0 ['] claim CATCH IF
31          ." Memory for ELF file is already in use!" cr
32          true ABORT" Memory for ELF file already in use "
33       THEN
34       drop
35    ELSE
36       2drop
37    THEN
38    + to cur-brk
39    0 
40 ;
41
42
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 )
47    true to elf-claim?
48    0 to last-claim
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
51    ELSE
52       ['] elf-load-file-to-addr CATCH IF false to elf-claim? ABORT THEN
53    THEN
54    >r
55    last-claim swap
56    false to elf-claim?
57    r>
58 ;
59
60
61 \ Release memory claimed before
62
63 : elf-release ( claim-list -- )
64    BEGIN
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 )
69    UNTIL
70    drop
71 ;