OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 1:34 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: paging error
PostPosted: Fri Mar 29, 2019 4:38 am 
Offline

Joined: Fri Mar 29, 2019 4:31 am
Posts: 3
Hello there!
I´m trying to implement paging on x86.
I test my code with qemu. It gives me following error:
Quote:
Misaligned i/o to address 00000004 with size 4 for memory region io

It seems like there are problems to call or handle interrupts.
If I try to call an interrupt with
Code:
int $number
the misaligned address is 26.
Without paging the interrupts and multitasking works fine.

Can someone tell me what happens?


Top
 Profile  
 
 Post subject: Re: paging error
PostPosted: Fri Mar 29, 2019 6:34 am 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 692
Do you have your project online anywhere (like github/gitlab) etc? Might be easier to pinpoint a problem if we saw your code.


Top
 Profile  
 
 Post subject: Re: paging error
PostPosted: Fri Mar 29, 2019 9:39 am 
Offline

Joined: Fri Mar 29, 2019 4:31 am
Posts: 3
Yes, you can find the project on
Quote:
bitbucket.org /RW2003 / os.git


Top
 Profile  
 
 Post subject: Re: paging error
PostPosted: Fri Mar 29, 2019 3:49 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 692
In your virtual memory code you use inline assembly and a lot of it is incorrect. There is a OR of 0x80000000 but it doesn't have a $ sign before it so it is a memory operand. I see many of the inline assembly instruction have the source and destination reversed including the loading of CR3. In at&t syntax source is first instruction operand and destination is the second operand (Intel is reverse as it is dest, source).

If inline assembly modifies a register it has to be done with extended inline assembly statement where at a minimum it needs to be listed at a clobber (or better through an output or output/input&output constraint). Beyond that I'm unsure if pym_malloc works right or there is some other bug. I noticed the value of CR3 ended up being 0x100000 which is the memory where the bootloader starts? That ended up being used for the pageDirectoryPointer which seems very wrong.

Regarding using inline assembly, the general advice is if you are new to it - don't use it. Unlike Microsoft whose inline assembly is far more forgiving - GCC is not, but GCC inline assembly is more powerful. GCC's inline assembly has some interesting nuances that can cause code to work in one case and not another if it isn't done correctly. It is often a reason why code that works with optimizations off and fails with them on. There is an article about reasons not to use inline assembly: https://gcc.gnu.org/wiki/DontUseInlineAsm . The alternative to inline assembly is writing small functions in an assembly module (.S files). There you only have to really worry (in most use cases) about saving and restoring the non-volatile registers EBX, EDI, ESI, EBP if you modify them in the function.


Top
 Profile  
 
 Post subject: Re: paging error
PostPosted: Sat Mar 30, 2019 3:27 am 
Offline

Joined: Fri Mar 29, 2019 4:31 am
Posts: 3
thank you.

I changed the operands in the assembly blocks and I think it works.

You´re rigth. May, I should learn more about inline assembly if I´m using it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 95 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group