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.
I wrote simple paging according to this tutorial, and i have some trouble.
When i run my OS , the text on a screen begins to appear and disappear. I don't know what's going on, but if i don't call switch_page_directory() (see - https://github.com/s04v/locOS/blob/mast ... ing.c#L143). All works correctly.
Those are your current mappings. Your code fails when it hits the leave instruction at the end of the function. The reason why? If you look at the register dump when it fails it says this:
What is important is that ESP is 0008ffb4 which is in memory you haven't mapped (the address may be slightly different because of your compiler), thus leave fails trying to access the stack. I highly recommend using BOCHs for debugging this kind of thing.
Those are your current mappings. Your code fails when it hits the leave instruction at the end of the function. The reason why? If you look at the register dump when it fails it says this:
What is important is that ESP is 0008ffb4 which is in memory you haven't mapped (the address may be slightly different because of your compiler), thus leave fails trying to access the stack. I highly recommend using BOCHs for debugging this kind of thing.
I use QEMU too, but I will say this. BOCHs is a better tool IMHO for this kind of issue (paging). It took me a matter of seconds to identify this problem in BOCHs. Whether you run this in QEMU or BOCHs your issue is that the stack isn't in a region of memory you have mapped, thus it fails.
MichaelPetch wrote:I use QEMU too, but I will say this. BOCHs is a better tool IMHO for this kind of issue (paging). It took me a matter of seconds to identify this problem in BOCHs. Whether you run this in QEMU or BOCHs your issue is that the stack isn't in a region of memory you have mapped, thus it fails.
You need to create a mapping that includes the region of memory where you have your stack. I also didn't look at your code to determine what mapping you were expecting.What you have seems a bit unusual. The question is - is the mapping I showed from BOCHs what you were expecting to be mapped? If not then you have an issue with mapping already. If it is as you expect then you have to add additional mapping for the stack area.The other alternative is to place the stack in a region of memory that is already mapped.
Since the value of ESP suggests you probably started having your stack grow down from 0x90000 you could start by mapping the 4KiB page at 0x8f000 (which includes 0x8f000 to 0x8ffff) into virtual memory. Just identity map it as a test (virtual address 0x8f000 mapped to physical address 0x8f000). You could also just identity map all the memory in the first megabyte.
MichaelPetch wrote:You need to create a mapping that includes the region of memory where you have your stack. I also didn't look at your code to determine what mapping you were expecting.What you have seems a bit unusual. The question is - is the mapping I showed from BOCHs what you were expecting to be mapped? If not then you have an issue with mapping already. If it is as you expect then you have to add additional mapping for the stack area.The other alternative is to place the stack in a region of memory that is already mapped.
Since the value of ESP suggests you probably started having your stack grow down from 0x90000 you could start by mapping the 4KiB page at 0x8f000 (which includes 0x8f000 to 0x8ffff) into virtual memory. Just identity map it as a test (virtual address 0x8f000 mapped to physical address 0x8f000). You could also just identity map all the memory in the first megabyte.
I started VM at 0x100000. and it works, but when page fault happens I continuously receive messages about page fault.