Thank you for an early response. It's really helpful. Harsh
On Tue, May 4, 2021 at 6:31 AM Gabe Black <gabe.bl...@gmail.com> wrote: > Hi. VPtr<> is supposed to be equivalent to void *. Even with a c void * > though, you can't (in standard c) use it as an array of bytes. If you need > it to be an array of bytes, you need to use VPtr<uint8_t>. There are some > facilities to cast VPtrs of different types, but I don't remember how > extensive that support is, or if VPtr<> is part of it. Also VPtrs in > general can't be used as arrays, just as pointers. You can approximate > using them as arrays by using pointer (like) arithmetic on them and > increment them with ++, or I think add an integer offset to them, etc. I > intend to give them that capability eventually, and then replace BufferArg > with VPtr so there's only one system. In the mean time, if you really need > array like behavior, you might want to use BufferArg, and manage its > contents manually with copyIn and copyOut. I would suggest using a > VPtr<uint8_t> though, if what you're manipulating is an array of bytes and > you're accessing those bytes individually. > > In the arguments for a system call, you should still use VPtr<> for a bare > pointer/address even if you access the data with BufferArg, since then the > system call mechanism will know that those arguments should be pointer > sized for whatever the simulated system is. VPtr<> can be cast to Addr > which will turn it into the underlying address which was passed in as an > argument. Something like this (not tested): > > void > sayHello(SyscallDesc *desc, ThreadContext *tc, VPtr<> hello_ptr, size_t > size) > { > BufferArg hello_buf(hello_ptr, size); > hello_buf.copyIn(tc->getVirtProxy()); > const char *hello_str = (const char *)hello_buf.bufferPtr(); > std::cout << "Hello " << hello_str << "!\n"; > hello_str[0] = '\0'; > hello_buf.copyOut(tc->getVirtProxy()); > } > > Alternatively you could do mostly the same thing with VPtr<char> (also > untested): > > void > sayHello(SyscallDesc *desc, ThreadContext *tc, VPtr<char> hello_ptr, > size_t size) > { > std::cout << "Hello "; > while (size--) > std::cout << *hello_ptr++; > std::cout << "!\n"; > } > > Gabe > > On Mon, May 3, 2021 at 2:24 PM Harsh via gem5-users <gem5-users@gem5.org> > wrote: > >> I'm trying to implement a few of the system calls. The system call 318 >> includes copying random bytes to a void* few. However, in the >> src/sim/syscall_emul.cc file, I could not find any use of void* there are >> uses of VPtr<>. I'm not sure whether they are the same thing. >> >> Also, I looked into the implementation of VPtr<> >> http://pages.cs.wisc.edu/~swilson/gem5-docs/vptr_8hh_source.html#l00083 >> and there is no functionality of inserting elements into the underlying >> buffer attribute. I tried creating the BufferArg object and then calling >> its bufferPtr() method, however, I'm not sure if this is the best method. >> Some of the examples make use of std::memcpy on the bufferPtr, but I do not >> have any other buffer object to copy from. >> >> Can someone please confirm whether VPtr<> is the alternative of void* and >> whether there is any other way to implement >> for (int i = 0; i < size ; i++) {buf[i] = some random byte;} using VPtr<> >> _______________________________________________ >> gem5-users mailing list -- gem5-users@gem5.org >> To unsubscribe send an email to gem5-users-le...@gem5.org >> %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s >> >
_______________________________________________ gem5-users mailing list -- gem5-users@gem5.org To unsubscribe send an email to gem5-users-le...@gem5.org %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s