Discussion:
Loading into Physical Memory
(too old to reply)
Sam
2011-07-22 06:22:49 UTC
Permalink
Hi,
We are having a bit of trouble loading pages into memory.
We know that our implementation should be based on the load_segment code
provided, but we would like the following to be clarified a bit:

1. We know that we could refer to a physical address by a virtual address.
We noticed that there is a macro called "PADDR_TO_KVADDR(paddr)" which
returns a kernel virtual address of paddr. What we are not sure is that,
is this returned vaddr a "reference" to the passed in paddr? Could we make
use of this if we are trying to load something into the paddr?

2. If possible, we would like to know what kind of values should be stored
into the fields of a uio structure.

3. We made use of VOP_READ for loading values onto memory (please hint us
if our approach is incorrect). As mentioned in previous posts, load_elf
should call a function (say save_info) that saves vnodes, offsets, and
sizes for future use. However, when we tried to run palin, the load_elf
function never called save_info on stack segment. Since VOP_READ requires
a vnode, how could a stack segment be loaded in this case?


Thanks in advance!
cs350
2011-07-22 07:17:45 UTC
Permalink
1. It's not a reference to an address, it's the same address, only
translated. You can use this kernel virtual address with uio in
load_segment, as long as you change the uio settings to use kernelspace
(kbase instead of ubase, SYSSPACE instead of USERSPACE).

2. The one usage example you need is in load_segment. Apart from changing
the destination to be a kernel virtual address (which is not absolutely
necessary), you can call the same code with different parameters (for
example memory size is just PAGE_SIZE to load a page at a time).

3. The stack segment does not involve the ELF file at all. When you load
stack pages, you just allocate and zero them. The size of the stack
segment is also defined globally for all processes; look at the top of
dumbvm.c

-Alex
Post by Sam
Hi,
We are having a bit of trouble loading pages into memory.
We know that our implementation should be based on the load_segment code
1. We know that we could refer to a physical address by a virtual address. We
noticed that there is a macro called "PADDR_TO_KVADDR(paddr)" which returns a
kernel virtual address of paddr. What we are not sure is that, is this
returned vaddr a "reference" to the passed in paddr? Could we make use of
this if we are trying to load something into the paddr?
2. If possible, we would like to know what kind of values should be stored
into the fields of a uio structure.
3. We made use of VOP_READ for loading values onto memory (please hint us if
our approach is incorrect). As mentioned in previous posts, load_elf should
call a function (say save_info) that saves vnodes, offsets, and sizes for
future use. However, when we tried to run palin, the load_elf function never
called save_info on stack segment. Since VOP_READ requires a vnode, how could
a stack segment be loaded in this case?
Thanks in advance!
Sam
2011-07-22 16:05:39 UTC
Permalink
Hi,
Thank you very much for the response, it was really helpful.
Could you please also give us some hint on how resid and offset work in
this case?

Thanks in advance!
Post by cs350
1. It's not a reference to an address, it's the same address, only
translated. You can use this kernel virtual address with uio in
load_segment, as long as you change the uio settings to use kernelspace
(kbase instead of ubase, SYSSPACE instead of USERSPACE).
2. The one usage example you need is in load_segment. Apart from changing
the destination to be a kernel virtual address (which is not absolutely
necessary), you can call the same code with different parameters (for
example memory size is just PAGE_SIZE to load a page at a time).
3. The stack segment does not involve the ELF file at all. When you load
stack pages, you just allocate and zero them. The size of the stack
segment is also defined globally for all processes; look at the top of
dumbvm.c
-Alex
Post by Sam
Hi,
We are having a bit of trouble loading pages into memory.
We know that our implementation should be based on the load_segment code
1. We know that we could refer to a physical address by a virtual address. We
noticed that there is a macro called "PADDR_TO_KVADDR(paddr)" which returns a
kernel virtual address of paddr. What we are not sure is that, is this
returned vaddr a "reference" to the passed in paddr? Could we make use of
this if we are trying to load something into the paddr?
2. If possible, we would like to know what kind of values should be stored
into the fields of a uio structure.
3. We made use of VOP_READ for loading values onto memory (please hint us if
our approach is incorrect). As mentioned in previous posts, load_elf should
call a function (say save_info) that saves vnodes, offsets, and sizes for
future use. However, when we tried to run palin, the load_elf function never
called save_info on stack segment. Since VOP_READ requires a vnode, how could
a stack segment be loaded in this case?
Thanks in advance!
cs350
2011-07-22 18:07:35 UTC
Permalink
iov_len is the length of the memory space (memsize), resid is the amount
to actually read (filesize), offset is the offset into the file.

-Alex
Post by Sam
Hi,
Thank you very much for the response, it was really helpful.
Could you please also give us some hint on how resid and offset work in this
case?
Thanks in advance!
Post by cs350
1. It's not a reference to an address, it's the same address, only
translated. You can use this kernel virtual address with uio in
load_segment, as long as you change the uio settings to use kernelspace
(kbase instead of ubase, SYSSPACE instead of USERSPACE).
2. The one usage example you need is in load_segment. Apart from changing
the destination to be a kernel virtual address (which is not absolutely
necessary), you can call the same code with different parameters (for
example memory size is just PAGE_SIZE to load a page at a time).
3. The stack segment does not involve the ELF file at all. When you load
stack pages, you just allocate and zero them. The size of the stack segment
is also defined globally for all processes; look at the top of dumbvm.c
-Alex
Post by Sam
Hi,
We are having a bit of trouble loading pages into memory.
We know that our implementation should be based on the load_segment code
1. We know that we could refer to a physical address by a virtual address.
We
Post by cs350
Post by Sam
noticed that there is a macro called "PADDR_TO_KVADDR(paddr)" which
returns
a
Post by cs350
Post by Sam
kernel virtual address of paddr. What we are not sure is that, is this
returned vaddr a "reference" to the passed in paddr? Could we make use of
this if we are trying to load something into the paddr?
2. If possible, we would like to know what kind of values should be stored
into the fields of a uio structure.
3. We made use of VOP_READ for loading values onto memory (please hint us
if
Post by cs350
Post by Sam
our approach is incorrect). As mentioned in previous posts, load_elf
should call a function (say save_info) that saves vnodes, offsets, and
sizes for future use. However, when we tried to run palin, the load_elf
function
never
Post by cs350
Post by Sam
called save_info on stack segment. Since VOP_READ requires a vnode, how
could
Post by cs350
Post by Sam
a stack segment be loaded in this case?
Thanks in advance!
Continue reading on narkive:
Loading...