paging error

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
RW2003
Posts: 3
Joined: Fri Mar 29, 2019 4:31 am

paging error

Post by RW2003 »

Hello there!
I´m trying to implement paging on x86.
I test my code with qemu. It gives me following error:
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: Select all

int $number
the misaligned address is 26.
Without paging the interrupts and multitasking works fine.

Can someone tell me what happens?
MichaelPetch
Member
Member
Posts: 798
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: paging error

Post by MichaelPetch »

Do you have your project online anywhere (like github/gitlab) etc? Might be easier to pinpoint a problem if we saw your code.
RW2003
Posts: 3
Joined: Fri Mar 29, 2019 4:31 am

Re: paging error

Post by RW2003 »

Yes, you can find the project on
bitbucket.org /RW2003 / os.git
MichaelPetch
Member
Member
Posts: 798
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: paging error

Post by MichaelPetch »

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.
RW2003
Posts: 3
Joined: Fri Mar 29, 2019 4:31 am

Re: paging error

Post by RW2003 »

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.
Post Reply