Mapping Memory

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
whiteOS
Member
Member
Posts: 29
Joined: Mon Oct 06, 2008 12:38 am

Mapping Memory

Post by whiteOS »

not sure if anyone can help me this. i want map memory space of device in kernel space. how I do?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Mapping Memory

Post by Combuster »

Er, with paging?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
whiteOS
Member
Member
Posts: 29
Joined: Mon Oct 06, 2008 12:38 am

Re: Mapping Memory

Post by whiteOS »

Er, that is what I was doing before when you said I was wrong! In fact in another thread I spoke:

Code: Select all

#define GET_PAGE_NUMBER( address ) ( address >> 12 )
void map_mem(unsigned int base, unsigned int length)
{
   page_t *pg;
   
   //create pd
   kernel_directory = (page_directory_t*)kmalloc_a(sizeof(page_directory_t));
    memset(kernel_directory, 0, sizeof(page_directory_t));
   
    int i = 0;
   //create pages
    for (i = base; i < base+length; i += 0x1000)
        get_page(i, 1, kernel_directory);

   //identity map
    i = 0;
    while (i < base+0x1000)
    {
        // Kernel code is readable but not writeable from userspace.
        alloc_frame( get_page(i, 1, kernel_directory), 0, 0);
        i += 0x1000;
    }

    // Now allocate those pages we mapped earlier.
    for (i = base; i < base+length; i += 0x1000)
        alloc_frame( get_page(i, 1, kernel_directory), 0, 0);

   //set frame to base addr
   pg->frame=GET_PAGE_NUMBER(base);
}
I told you that it crash my OS and I say what is wrong with it. And you say, looks like you are attempting map of MMIO and you made confused me and said I yes, that is what I am trying to do, but what I was trying to do was map a memory space as the threads title suggested, but you confused and mislead me so I agreed foolishly and wasted time.

the point is that this code does not work without crashing me which means it never mapped the address, so what is wrong with my code that would cause it to crash. Are my questions beyond the scope of this forum as I not get much help here?
User avatar
kmtdk
Member
Member
Posts: 263
Joined: Sat May 17, 2008 4:05 am
Location: Cyperspace, Denmark
Contact:

Re: Mapping Memory

Post by kmtdk »

In oder to help, we will need the full code ( kmalloc_a, and sutch things ).
The point with this foum is not to do your code, but to help eithor, and "out of the scope" , well that depense on how you set up the question, because you can ask foolish, and then noby understand what you mean.


KMT dk
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Mapping Memory

Post by Combuster »

The point is, you are using some code you don't seem to understand what it does, and then you try to use it for something else which is not what the code was meant to do.

And it seems to have happened the same with the used terminology: I said something, and you didn't understand but instead pretended to do so anyway. Of course subsequent attempts to help won't work at that point. And to be honest, I'm rather appalled by the fact that you claim that I gave the wrong info when you say that you never understood it.

Since you finally told us it is the basics you do not understand, we can give more useful responses. Start by reading up on Paging Setting_Up_Paging and rereading the tutorial where you grabbed that code from (and please do tell us in detail what you think it is meant to do so we can fix that too if necessary)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Mapping Memory

Post by egos »

:twisted:

[-o<

It's easy to do if you know the physical address of hardware buffer and have the sequential reserved area with suitable size in kernel space. For example:

Code: Select all

  cld
  mov eax,0A0000h or PF_GLOBAL or PF_PCD or PF_WRITABLE or PF_PRESENT
  mov ecx,128/4
  mov edi,PTable+GET_PAGE_NUMBER(VFB)*4
@@:
  stosd
  add eax,1000h
  loop @b
If you have seen bad English in my words, tell me what's wrong, please.
whiteOS
Member
Member
Posts: 29
Joined: Mon Oct 06, 2008 12:38 am

Re: Mapping Memory

Post by whiteOS »

how far off am I from being correct? i present a prototype for you to examine. may you examine it? i hope I provide you the right pieces if even in excess. my effort is purely educational now as my computer has died and I am not able to test my driver now. i got six years out of it and i happy it dead now. now i get laptop. :)
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Mapping Memory

Post by egos »

My congratulations to you. No driver, no problems :roll: Or the driver is still living :shock:
If you have seen bad English in my words, tell me what's wrong, please.
whiteOS
Member
Member
Posts: 29
Joined: Mon Oct 06, 2008 12:38 am

Re: Mapping Memory

Post by whiteOS »

currently alive in the paradigm of my mind. physically offline for now.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Mapping Memory

Post by egos »

You are just philosophist :)

P.S. I'm sorry for offtop.
If you have seen bad English in my words, tell me what's wrong, please.
Post Reply