summaryrefslogtreecommitdiffstats
path: root/qemu/roms/SLOF/slof/fs/elf.fs
diff options
context:
space:
mode:
authorYang Zhang <yang.z.zhang@intel.com>2015-08-28 09:58:54 +0800
committerYang Zhang <yang.z.zhang@intel.com>2015-09-01 12:44:00 +0800
commite44e3482bdb4d0ebde2d8b41830ac2cdb07948fb (patch)
tree66b09f592c55df2878107a468a91d21506104d3f /qemu/roms/SLOF/slof/fs/elf.fs
parent9ca8dbcc65cfc63d6f5ef3312a33184e1d726e00 (diff)
Add qemu 2.4.0
Change-Id: Ic99cbad4b61f8b127b7dc74d04576c0bcbaaf4f5 Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
Diffstat (limited to 'qemu/roms/SLOF/slof/fs/elf.fs')
-rw-r--r--qemu/roms/SLOF/slof/fs/elf.fs71
1 files changed, 71 insertions, 0 deletions
diff --git a/qemu/roms/SLOF/slof/fs/elf.fs b/qemu/roms/SLOF/slof/fs/elf.fs
new file mode 100644
index 000000000..5a80c78d5
--- /dev/null
+++ b/qemu/roms/SLOF/slof/fs/elf.fs
@@ -0,0 +1,71 @@
+\ *****************************************************************************
+\ * Copyright (c) 2004, 2011 IBM Corporation
+\ * All rights reserved.
+\ * This program and the accompanying materials
+\ * are made available under the terms of the BSD License
+\ * which accompanies this distribution, and is available at
+\ * http://www.opensource.org/licenses/bsd-license.php
+\ *
+\ * Contributors:
+\ * IBM Corporation - initial implementation
+\ ****************************************************************************/
+
+\ Claim memory for segment
+\ Abort, if no memory available
+
+false value elf-claim?
+0 value last-claim
+
+\ cur-brk is set by elf loader to end of data segment
+0 VALUE cur-brk
+
+
+: elf-claim-segment ( addr size -- errorcode )
+ 2dup
+ elf-claim? IF
+ >r
+ here last-claim , to last-claim \ Setup ptr to last claim
+ \ Put addr and size in the data space
+ dup , r> dup , ( addr size )
+ 0 ['] claim CATCH IF
+ ." Memory for ELF file is already in use!" cr
+ true ABORT" Memory for ELF file already in use "
+ THEN
+ drop
+ ELSE
+ 2drop
+ THEN
+ + to cur-brk
+ 0
+;
+
+
+\ Load ELF file and claim the corresponding memory regions.
+\ A destination address can be specified. If the parameter is -1 then
+\ the file is loaded to the ddress that is specified in its header.
+: elf-load-claim ( file-addr destaddr -- claim-list entry imagetype )
+ true to elf-claim?
+ 0 to last-claim
+ dup -1 = IF \ If destaddr == -1 then load to addr from ELF header
+ drop ['] elf-load-file CATCH IF false to elf-claim? ABORT THEN
+ ELSE
+ ['] elf-load-file-to-addr CATCH IF false to elf-claim? ABORT THEN
+ THEN
+ >r
+ last-claim swap
+ false to elf-claim?
+ r>
+;
+
+
+\ Release memory claimed before
+
+: elf-release ( claim-list -- )
+ BEGIN
+ dup cell+ ( claim-list claim-list-addr )
+ dup @ swap cell+ @ ( claim-list claim-list-addr claim-list-sz )
+ release ( claim-list )
+ @ dup 0= ( Next-element )
+ UNTIL
+ drop
+;