GCC/AS bug when compiling for x86-64?
Posted: Thu Apr 17, 2008 8:29 pm
I'm not sure if OS Development is the right forum to put this in, but it is pretty OSdev related...
I've been porting my kernel to x86-64 from x86 (better earlier than later), and I've run into a strange problem with my scrolling text function. Once scrolling is triggered, in the x86-64 kernel only, an invalid opcode occurs. In x86, it scrolls normally.
Here's the non-working part of the scrolling code, which shifts each line to the previous one:
Remember that this code does work in the x86 kernel, that text_vidmem is an array of uint16_ts which starts at 0xB8000, and that the macros have proper values (TEXT_NUMOFCHARS = TEXT_COLUMNS*TEXT_ROWS, TEXT_COLUMNS = 80, TEXT_ROWS = 25)
Stranger still, when I finally gave up and used inline assembly instead, it actually worked (for both kernels)!
I think the weird part is that the exception caused by the original code is an 'invalid opcode' at somewhere in my kernel's virtual address (0xFFFFFFFFC01*****) and it does occur within this for statement, instead of a more common one such as a GPF or a page fault.
Is it my code, or is something in my GNU toolchain messing up?
I've been porting my kernel to x86-64 from x86 (better earlier than later), and I've run into a strange problem with my scrolling text function. Once scrolling is triggered, in the x86-64 kernel only, an invalid opcode occurs. In x86, it scrolls normally.
Here's the non-working part of the scrolling code, which shifts each line to the previous one:
Code: Select all
if (text_ypos >= TEXT_ROWS)
{
// Non-working code:
for (i = 0; i < TEXT_NUMOFCHARS - TEXT_COLUMNS; i++)
{
text_vidmem[i] = text_vidmem[i + TEXT_COLUMNS];
}
(more working code)
Stranger still, when I finally gave up and used inline assembly instead, it actually worked (for both kernels)!
Code: Select all
if (text_ypos >= TEXT_ROWS)
{
asm (
"mov %0, %%esi;"
"mov %1, %%edi;"
"mov %2, %%ecx;"
"rep movsw;"
:
: "n"(TEXT_MEMADDR + (TEXT_COLUMNS * 2)), "n"(TEXT_MEMADDR), "n"(TEXT_NUMOFCHARS - TEXT_COLUMNS)
: "esi", "edi", "ecx"
);
(working fine with this)
Is it my code, or is something in my GNU toolchain messing up?