From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FsL2N-00029r-Nt for qemu-devel@nongnu.org; Mon, 19 Jun 2006 10:47:35 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FsL2M-00026H-0z for qemu-devel@nongnu.org; Mon, 19 Jun 2006 10:47:35 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FsL2L-000267-Tb for qemu-devel@nongnu.org; Mon, 19 Jun 2006 10:47:33 -0400 Received: from [62.128.13.235] (helo=smtp.codingtechnologies.de) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FsLCf-0006rs-9t for qemu-devel@nongnu.org; Mon, 19 Jun 2006 10:58:13 -0400 Received: from mailhub.nbg.ct.dom (unknown [10.10.1.6]) by smtp.codingtechnologies.de (Postfix) with ESMTP id 3764FE400D for ; Mon, 19 Jun 2006 16:47:26 +0200 (CEST) Received: from notesserv.nbg.ct.dom (notesserv.nbg.ct.dom [10.10.1.6]) by mailhub.nbg.ct.dom (Postfix) with ESMTP id D23611A46 for ; Mon, 19 Jun 2006 16:47:25 +0200 (CEST) In-Reply-To: <200606121747.13346.paul@codesourcery.com> Subject: Re: [Qemu-devel] qemu qemu-doc.texi MIME-Version: 1.0 Message-ID: From: Wolfgang Schildbach Date: Mon, 19 Jun 2006 16:47:24 +0200 Content-Type: multipart/mixed; boundary="=_mixed 00513EDAC1257192_=" Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --=_mixed 00513EDAC1257192_= Content-Type: text/plain; charset="US-ASCII" Hi Paul, Thanks for the explanation. I feel like fixing the alignment issue in the qemu code is a little above my head right now. However, it turns out that the alignment issue can be solved on the arm compiler/linker side, by giving appropriate arguments to the linker (--ro-base 0x8034). The "missing command line issue" can be attributed to the fact that the corresponding ARM semihosting function was not implemented. The patch below implements the SYS_GET_CMDLINE semihosting call, by keeping a global pointer to the user space commandline arguments, and by re-building a space-separated command line in the guest side supplied buffer. This patch has two shortcomings: - I am keeping a global pointer in order to have a handle on the command line arguments inside do_arm_semihosting. Is there a better place to keep this? - The ARM (guest) side supplied buffer is only 256 bytes long; if the user supplied command line is larger, the semihosting call will fail (gracefully). A better strategy may be to build the string on the initial guest stack (similar to loader_build_argptgr()) and then hand that pointer to the guest. I am not quite sure whether the ARGS[] array should be locked before access (then again, none of the functions in do_arm_semihosting() do this). Anyhow, with the patch below (and the linker flags above), I can successfully execute ADS/RVCT compiled binaries, together with command line arguments, both little- and bigendian. All comments welcome. - Wolfgang Paul Brook wrote on 12.06.2006 18:47:12: > > Where would I (start to) look for the reasons behind this? Is this > > something that needs to be "fixed" on the ARM side (i.e. fix the location > > where the ARM code looks for the environment)? > > Look at the code in load_elf_binary that uses target_mmap to map theloadable > segments into memory. The page size I'm referring to below is the target page > size (4k for qemu-arm). target_mmap is more-or-less a wrapper around normal > mmap that deals with the corner cases and differences in page size when > host != target. > > There are two issues: > - mmap requires the file offset be a multiple of the page size. This is > relatively easy to fix. If the file data is misaligned create an anonymous > mapping and pread the data. > > - The code assumes the VMA of the segments after roundind to a page boundary > do not overlap. ie. a single memory page will contain data from no more than > one segment. Fixing this is more complicated and probably involves merging > the regions used by sections with "overlapping" pages. > > Paul -- Wolfgang Schildbach, Senior Research Engineer Coding Technologies GmbH --=_mixed 00513EDAC1257192_= Content-Type: application/octet-stream; name="arm_semihosting_commandline.diff" Content-Disposition: attachment; filename="arm_semihosting_commandline.diff" Content-Transfer-Encoding: base64 SW5kZXg6IGxpbnV4LXVzZXIvYXJtLXNlbWkuYwo9PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09ClJDUyBmaWxlOiAvc291cmNl cy9xZW11L3FlbXUvbGludXgtdXNlci9hcm0tc2VtaS5jLHYKcmV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AgIGV4dGVybiBjaGFyICoqZ2xvYmFsX3VzZXJzcGFjZV9hcmd2IDsgLyogaW5pdGlh bGl6ZWQgaW4gbWFpbigpICovCj4gICAgICAgICAgICAgY2hhciAqKmF2ID0gZ2xvYmFsX3VzZXJz cGFjZV9hcmd2IDsgICAvKiB3b3JrIHB0ciAqLwo+ICAgICAgICAgICAgIGludCBsZW4gPSBBUkco MSk7IC8qIGFtb3VudCBvZiBSQU0gdGhhdCB0aGUgQVJNIGJpbmFyeSBoYXMgc2V0Cj4gICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgYXNpZGUgZm9yIHRoZSBjb21tYW5kIGxpbmUgKi8K PiAgICAgICAgICAgICAvKiBsb2NrIHRoZSBidWZmZXIgb24gdGhlIEFSTSBzaWRlICovCj4gICAg ICAgICAgICAgY2hhciAqY21kbGluZV9idWZmZXIgPSAoY2hhciopbG9ja191c2VyKEFSRygwKSxs ZW4sMCk7Cj4gICAgICAgICAgICAgcyA9IGNtZGxpbmVfYnVmZmVyIDsKPiAgICAgICAgICAgICBk byB7Cj4gICAgICAgICAgICAgICAgIGludCBuID0gc3RybGVuKCphdikgOwo+IAo+ICAgICAgICAg ICAgICAgICAvKiBpcyB0aGVyZSBzdGlsbCBzcGFjZSBpbiB0aGUgc3VwcGxpZWQgYnVmZmVyLCBp bmNsdWRpbmcKPiAgICAgICAgICAgICAgICAgICAgdGhlIHRlcm1pbmF0aW5nIHplcm8/ICovCj4g ICAgICAgICAgICAgICAgIGlmIChzIC0gY21kbGluZV9idWZmZXIgKyBuKzEgPiBsZW4pCj4gICAg ICAgICAgICAgICAgICAgICBicmVhayA7IC8qIG5vICovCj4gCj4gICAgICAgICAgICAgICAgIG1l bWNweShzLCphdixuKTsKPiAgICAgICAgICAgICAgICAgcyArPSBuIDsKPiAgICAgICAgICAgICAg ICAgKnMrKyA9ICcgJzsKPiAgICAgICAgICAgICAgICAgbGVuIC09IG4rMSA7Cj4gICAgICAgICAg ICAgICAgIGF2Kys7Cj4gICAgICAgICAgICAgfSB3aGlsZSAoKmF2KTsKPiAgICAgICAgICAgICAq cysrID0gMDsgLyogdGVybWluYXRlIGNtZGxpbmUgc3RyaW5nICovCj4gCj4gICAgICAgICAgICAg LyogdW5sb2NrIHRoZSBidWZmZXIgb24gdGhlIEFSTSBzaWRlICovCj4gICAgICAgICAgICAgdW5s b2NrX3VzZXIoY21kbGluZV9idWZmZXIsIEFSRygwKSwgQVJHKDEpKTsKPiAKPiAgICAgICAgICAg ICAvKiBhZGp1c3QgdGhlIGNvbW1hbmRsaW5lIGxlbmd0aCBhcmd1bWVudCAqLwo+ICAgICAgICAg ICAgIFNFVF9BUkcoMSwgKHVpbnQzMl90KShzIC0gY21kbGluZV9idWZmZXIpKTsKPiAKPiAgICAg ICAgICAgICAvKiBzdWNjZXNzZnVsbCByZXR1cm4gaWYgY29tbWFuZGxpbmUgZml0IGludG8gYnVm ZmVyICovCj4gICAgICAgICAgICAgcmV0dXJuICphdiA9PSAwID8gMCA6IC0xIDsKPiAgICAgICAg IH0KSW5kZXg6IGxpbnV4LXVzZXIvbWFpbi5jCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KUkNTIGZpbGU6IC9zb3VyY2Vz L3FlbXUvcWVtdS9saW51eC11c2VyL21haW4uYyx2CnJldHJpZXZpbmcgcmV2aXNpb24gMS44OApk aWZmIC1yMS44OCBtYWluLmMKMzEyYTMxMywzMTUKPiAvKiBYWFg6IHRoaXMgaXMgYW4gdWdseSBo YWNrLCB0byBtYWtlIGFyZ2MvYXJndiBhdmFpbGFibGUgdG8gQVJNIHNlbWlob3N0aW5nICovCj4g Y2hhciAqKmdsb2JhbF91c2Vyc3BhY2VfYXJndiA7Cj4gCjE1MzEsMTUzMmMxNTM0LDE1MzYKPCAg ICAgCjwgICAgIGlmIChsb2FkZXJfZXhlYyhmaWxlbmFtZSwgYXJnditvcHRpbmQsIGVudmlyb24s IHJlZ3MsIGluZm8pICE9IDApIHsKLS0tCj4gICAgIGdsb2JhbF91c2Vyc3BhY2VfYXJndiA9IGFy Z3YgKyBvcHRpbmQ7Cj4gCj4gICAgIGlmICgobG9hZGVyX2V4ZWMoZmlsZW5hbWUsIGdsb2JhbF91 c2Vyc3BhY2VfYXJndiwgZW52aXJvbiwgcmVncywgaW5mbykpICE9IDApIHsK --=_mixed 00513EDAC1257192_=--