Help with tutorial? [Paging]
- GeniusCobyWalker
- Member
- Posts: 65
- Joined: Mon Jan 12, 2009 4:17 pm
Help with tutorial? [Paging]
I have followed this tutorial: http://www.jamesmolloy.co.uk/tutorial_h ... aging.html
Step-by-step.
I wrote code to fit my OS.
But, I just don't get it. I would google it, but I don't know what to google.
Can someone help?
Here is the problem:
All the commands work it's just...
How do I save data to memory?
Malloc allocates a page, how do I read and write to a frame?
I have been working on this about a week. Any help would be appreciated.
(I don't get why I can't understand this)
Step-by-step.
I wrote code to fit my OS.
But, I just don't get it. I would google it, but I don't know what to google.
Can someone help?
Here is the problem:
All the commands work it's just...
How do I save data to memory?
Malloc allocates a page, how do I read and write to a frame?
I have been working on this about a week. Any help would be appreciated.
(I don't get why I can't understand this)
Full Knowledge in:
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
Re: Help with tutorial?
"Save" into RAM? Better "save" to a permanent data storage system.How do I save data to memory?
Perhaps this chart helps you a little bit with understanding paging on a whole:
http://www.henkessoft.de/OS_Dev/Bilder/ ... Bitset.PNG
(k)malloc should be reserved for the heap.
http://www.henkessoft.de/OS_Dev/OS_Dev3.htm (OSDEV)
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
http://www.c-plusplus.de/forum/viewforu ... is-62.html
irc.euirc.net #PrettyOS
Re: Help with tutorial?
Paging is completely transparent for application programs. You access memory as ordinary (via mov instruction) and paging mechanism will translate address for you.
Read Intel/AMD manuals.
Read Intel/AMD manuals.
Keep the world with all its sin
It's not fit for livin' in
It's not fit for livin' in
- GeniusCobyWalker
- Member
- Posts: 65
- Joined: Mon Jan 12, 2009 4:17 pm
Re: Help with tutorial?
So can I save variables to frames? or what are they for?
Full Knowledge in:
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
Re: Help with tutorial?
A frame is just a block of physical memory, nothing special to it. It can be used to store anything that can be in physical memory: a loaded file or part of one, data areas, dynamic memory allocations, et al.GeniusCobyWalker wrote:So can I save variables to frames? or what are they for?
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
- GeniusCobyWalker
- Member
- Posts: 65
- Joined: Mon Jan 12, 2009 4:17 pm
Re: Help with tutorial?
OK, by looking at that tutorial,
how would I:
save int A to MEM
and load int B from that spot in MEM
any ideas?
I have no Idea why i'm not getting this
how would I:
save int A to MEM
and load int B from that spot in MEM
any ideas?
I have no Idea why i'm not getting this
Full Knowledge in:
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: Help with tutorial?
Paging splits the address space into blocks of pages (which are normally 4096 bytes on x86). These blocks are used by different parts of your OS.
So you have your physical memory manager, which allocates physical pages from real RAM. Then your virtual memory manager, which maps virtual addresses to these pages.
On top of that, you build things like your heap (malloc/free), which splits pages into small allocation units. You would also build things like executable loaders on top of this - mapping loaded pages to the addresses in the program headers of an ELF, for instance.
EDIT: Once you have your heap built upon a VMM (which is built upon your PMM)...
So you have your physical memory manager, which allocates physical pages from real RAM. Then your virtual memory manager, which maps virtual addresses to these pages.
On top of that, you build things like your heap (malloc/free), which splits pages into small allocation units. You would also build things like executable loaders on top of this - mapping loaded pages to the addresses in the program headers of an ELF, for instance.
EDIT: Once you have your heap built upon a VMM (which is built upon your PMM)...
Is just...save int A to MEM
and load int B from that spot in MEM
Code: Select all
int a = 1234;
......
int *p = (int*) malloc(sizeof(int));
*p = a;
int b = *p;
Re: Help with tutorial?
...Its just basic dynamic memory allocation...GeniusCobyWalker wrote:I have no Idea why i'm not getting this
To save int A to memory:
Code: Select all
int A;
char* p = malloc (sizeof int);
*p = A;
Code: Select all
int B = *p;
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: Help with tutorial?
Maybe Memory management from the Wiki can help?
Every good solution is obvious once you've found it.
- GeniusCobyWalker
- Member
- Posts: 65
- Joined: Mon Jan 12, 2009 4:17 pm
Re: Help with tutorial?
I hate to bring up old threads but,
The ban was horrible.
Anyway,
You all have made me realize my skills so I am now taking a C Programming class at College.
Luna's progress will continue as soon as pointers are covered in class.
Thanks
The ban was horrible.
Anyway,
You all have made me realize my skills so I am now taking a C Programming class at College.
Luna's progress will continue as soon as pointers are covered in class.
Thanks
Full Knowledge in:
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
Re: Help with tutorial?
Linux's memory management is so good.
You can understand and reference it. It's good experience.
You can understand and reference it. It's good experience.
Re: Help with tutorial?
What do you mean? Is there some book called "Linux's memory management", or are you trying to say that the memory management from Linux sources is readily comprehensible for anyone who knows a bit of C alone?kop99 wrote:Linux's memory management is so good.
You can understand and reference it. It's good experience.
=============================
There are several intricacies about pointers, but if you already know basic C maybe you could study again the different parts of the language, as there are little things that one could not know yet.GeniusCobyWalker wrote:Luna's progress will continue as soon as pointers are covered in class.
I had to study a copy of "C by Discovery" by L. S. Foster, and studied like 75% of if from the first chapter and up (the whole chapters). It took me like one month and 1 week, but I greatly improved my understanding of C. I mostly was also in need to understand the pointer usage and syntax. These are the chapters it contains:
Chapter 1: Getting Started
Chapter 2: Gaining Control
Regular things like if, for, etc.
Chapter 3: Basic data Types
Chapter 4: Pointers and Arrays
Here is the main theory about pointers. This is what an assembly programmer would like to study more from this book carefuly to convert something like mov byte[var],1 to var=1, and *pointer=1 I think that should be the same as mov edi,[pointer] ;;; mov byte[edi],1.
Chapter 5: Strings
Chapter 6: Keeping Control
More things like do-while, switch, goto, etc.
Chapter 7: Structuring the Data
Structures, arrays, pointers, bit fields, enum, unions, etc.
Chapter 8: Intraprogram Communication
Didn't study it very much.
Chapter 9: Multidimensional Arrays and Double Indirection
This talks about arrays and compares them with pointers, and also talks about double indirection and arrays of pointers
Chapter 10: Input and Output
I almost didn't study it but the name says it.
Chapter 11: C Library and Preprocessor Facilities
Explains some standard functions from the standard C library as well as how to use the preprocessor.
PART II: The Programmer's Handbook
This is a reference of things like identifiers, operator precedence, etc.
======================================================
If I remember correctly, one of the curious things that was explained is that, if a normal variable like an integer "i" is referenced with "&i" it will be referencing its address, NOT its value, and then if it's referenced as "*&i" would be accessing the value of the variable as if it had plainly been using "i", because the "&i" part would return the address of the variable and the * part would point to whatever is at that memory address,
It also talks about pointer arithmetic and the implications of the different combinations of operators in the syntax precedence.
Things like the differences of:
*pointer
*(pointer+5)
*pointer+5
Other things are the fact that doing something like int *intarray is better than int intarray[100] because *intarray only is a pointer (maybe 32 bits) but intarray[100] has to allocate 100 integer elements from the beginning.
The fact that pointing with a pointer of some type to an arbitrary memory location causes that location to be interpreted as a data of that type.
The fact that the "strings" in printf are like put apart like in assembler and then referenced with a pointer to an array of null-terminated chars, or something like that. That whenever something is put as in 'A' that character is considered a character in C, and if it is "A" it is considered a null-terminated string in C.
The fact that myvar[51] could be accessed as *(myvar+51).
One of the good things of C pointers, contrary to assembly "pointers" is that C pointers do the math. For example, if an integer is 4 bytes and we access *(myint+5) in assembly we won't be accessing [myint+5] but [myint+(5*4)], where 4 is the size of the data type that is referenced by the pointer of that type.
I think that other strange think is the difference between something like *a+=1 and (*a)+=1.
And a lot of other small details.
Some sample source code can be found here:
http://web.archive.org/web/200107110343 ... Discovery/
YouTube:
http://youtube.com/@AltComp126
My x86 OS/software:
https://sourceforge.net/projects/api-simple-completa/
Donate to get more food/programming resources/computers:
https://www.paypal.com/donate/?hosted_b ... QS2YTW3V64
http://youtube.com/@AltComp126
My x86 OS/software:
https://sourceforge.net/projects/api-simple-completa/
Donate to get more food/programming resources/computers:
https://www.paypal.com/donate/?hosted_b ... QS2YTW3V64
Re: Help with tutorial?
There are many book for LMM...What do you mean? Is there some book called "Linux's memory management", or are you trying to say that the memory management from Linux sources is readily comprehensible for anyone who knows a bit of C alone?
"Understanding the Linux Virtual Memory Manager" and "Understanding the Linux Kernel 3rd Edition"...
- GeniusCobyWalker
- Member
- Posts: 65
- Joined: Mon Jan 12, 2009 4:17 pm
:shock: Help with tutorial?
Once again, I hate bringing up old threads.
I did the MM by that Tutorial Line-by-line and it's still not working
It says "Page Fault" right after being Initialized. I can't even print "Welcome to Luna"
Has anyone else used that Tutorial and had success?
I did the MM by that Tutorial Line-by-line and it's still not working
It says "Page Fault" right after being Initialized. I can't even print "Welcome to Luna"
Has anyone else used that Tutorial and had success?
Full Knowledge in:
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
GML, Ti-Basic, Zilog Z80 Assembly, SX28 Assembly and Blender
Experience in:
C++,OpenGl,NDS C++,Dark Basic,Dark Basic Pro,Dark Gdk and PSP Coding
Using:
Ubuntu ,GEdit ,NASM ,GCC ,LD ,Bochs
Re: Help with tutorial?
I have not used his tutorial but I do know it works. Understanding paging is easy, getting it working effectively is hard - I hope you mastered pointers before attempting it.
If it page faults as soon as enabling paging, it means that your running code is not identity mapped before enabling paging. I cant help much after without looking at code. (I assume and hope its not copied+pasted.)
If it page faults as soon as enabling paging, it means that your running code is not identity mapped before enabling paging. I cant help much after without looking at code. (I assume and hope its not copied+pasted.)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}