I have a small OS supporting no user mode. very code is run in kernel space.
I have 3 GDT entries as NullSegmentSelector, CodeSegmentSelector, and DataSegmentSelector. Code and data segments are overlapped with base = 0, and limit = 0xFFFFFFFF.
In my loader, I have already reserved 100 MB for stack. Not until recently that I started ti implement a custom JPEG decoder for my OS, everything was fine. By everything I mean, US3.0 support, SVGA support, AHCI, FAT32 filesystem support, etc.
This JPEG decoder uses a huge amount of stack (based on SSE and SIMD operations) to be able to work optimized.
I already tested it on my Windows visual studio and all bugs and errors have been addressed. Now that I want to translate it for my OS, I figured out that the size of this JPEG decoder binary is somehow big. From where I know that? In visual studio C++, I had to manually increase the size of stack for my decoder to something like 10 MB. There I had no problem. But now, as soon as my OS reaches to the first function in JPEG decoder, it restarts itself.
I tried to test it on QEMU. Also on qemu, I cannot get it worked and I always get "executing code outside RAM or ROM" fatal error.
What I have done so far:
- try to increase or decrease the stack size in my loader.asm file, but did not help.
- try to use "align 16" for stack bytes in loader.asm, but no way.
- specifically calling -Wl,--stack,10485760 in my gcc command in order to assign a larger stack to the binary file, but again it failed (I thought this might help like what I had done in visual studio to manually increase the stack size).
- using --nmagic flag in my linker.ld file, but it still fails.
The last option, i am not sure about and I found it somewhere saying that perhaps the linker using 4096 aligned files and it might be the source of issue, but I do not know about it. This is my linker:
Code: Select all
ENTRY(LOADER)
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386:i386)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys)
{
code = .;
*(.text)
*(.rodata)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}
Best regards.
Iman.