Page 1 of 1

received signal SIGQUIT, Quit. When kernel file is too large

Posted: Mon Oct 19, 2020 4:32 pm
by Bonfra
So I've been developing this kernel for a bit and focussed on the standard C library. Now I started adding functionalities to the kernel, starting with a generic idt support handling just the keyboard interrupt. It seemmed to work just fine but when the file exceed 67KB, when is loaded by the bootloader instantly crush with "received signal SIGQUIT, Quit." on what seems to be a random address in code (depending on how much exceeds). The codebase is too large to copy all here so I'll link the github repository at the end of the post.
Anyway I'll post what i think are the most important stuffs:

linker script:

Code: Select all

OUTPUT_FORMAT(elf64-x86-64)
ENTRY(_start)

SECTIONS
{
    KERNEL_VMA = 0x00301000;

    . = KERNEL_VMA;

    .text : ALIGN(0x1000)
    {
        *(.start)
        *(.text)
    }

    .data : ALIGN(0x1000)
    {
        *(.data)
    }

    .rodata : ALIGN(0x1000)
    {
        *(.rodata)
    }

    .idt BLOCK(0x1000) : ALIGN(0x1000)
    {
        _idt = .;
        . = . + 0x1000;
    }

    .bss : ALIGN(0x1000)
    {
        _BSS_START = ABSOLUTE(.);
        *(COMMON)
        *(.bss)
    }

    _BSS_SIZE = ABSOLUTE(.) - _BSS_START;
}

And the kernel and bootloader are used within a floppy img file created as so:
(with BonsOS.img being the output img, loader.bin the second stage bootloader, kernel.sys the kernel file generated wit the linker script above, boot.bin the first stage bootloader)

Code: Select all

dd if=/dev/zero of=BonsOS.img bs=1024 count=1440
/sbin/mkfs.msdos BonsOS.img
mcopy -i BonsOS.img ./bin/boot/loader.bin ::/
mcopy -i BonsOS.img ./bin/kernel/kernel.sys ::/
dd if=./bin/boot/boot.bin of=BonsOS.img seek=0 count=1 conv=notrunc
Github repo: https://github.com/DefEnge/test-kernel/tree/testing
PS: If you need help navigating the repository to find a file feel free to ask :)

Re: received signal SIGQUIT, Quit. When kernel file is too l

Posted: Mon Oct 19, 2020 6:27 pm
by Octocontrabass

Re: received signal SIGQUIT, Quit. When kernel file is too l

Posted: Mon Oct 19, 2020 11:58 pm
by Bonfra
I kinda suspected it was the bootloader since is the only pice of code that I've mostly copied from various sources...
I understand the problem but I'm not really sure on how to fix it. do you have any resource to suggest on how to implement a correct version?

Re: received signal SIGQUIT, Quit. When kernel file is too l

Posted: Tue Oct 20, 2020 12:30 am
by Octocontrabass
I think correcting it would be pretty easy. One possible solution is to detect wraparound (using CF) and handle it as a special case.

Another option is to do something like what I did here or here. My code is heavily optimized for size, so it can be hard to follow, but I'm pretty confident in it.

Re: received signal SIGQUIT, Quit. When kernel file is too l

Posted: Tue Oct 20, 2020 4:15 am
by Bonfra
I must admit that I'm not really good in assembly and just the fact that the function that I'm using is ReadSectors (plural) and the one you provided is ReadSector(singular) prevents me to understand what is going on with the code... I've tried to adapt it but obviously also the parameters are different and I don't even know how all of this works. Maybe i should just rewrite all the loadFile function.
I'll just keep trying, thaks a lot for your code!

Re: received signal SIGQUIT, Quit. When kernel file is too l

Posted: Tue Oct 20, 2020 6:22 am
by Bonfra
Octocontrabass wrote:One possible solution is to detect wraparound (using CF) and handle it as a special case..
Can you post some code about it? I have no clue on how to do it...

Re: received signal SIGQUIT, Quit. When kernel file is too l

Posted: Tue Oct 20, 2020 8:23 am
by iansjack
A really simple solution would be to use an existing bootloader - e.g. GRUB.

Re: received signal SIGQUIT, Quit. When kernel file is too l

Posted: Tue Oct 20, 2020 9:17 am
by sj95126
One solution is updating your target buffer after each read by increasing the segment, not the offset.

Instead of adding "# of bytes read" to bx, add ("# of bytes read" >> 4) to es. That allows you to keep reading in chunks up to 64k (if your BIOS allows it) and not worry about crossing a segment boundary.

Re: received signal SIGQUIT, Quit. When kernel file is too l

Posted: Tue Oct 20, 2020 9:44 am
by Bonfra
sj95126 wrote:One solution is updating your target buffer after each read by increasing the segment, not the offset.

Instead of adding "# of bytes read" to bx, add ("# of bytes read" >> 4) to es. That allows you to keep reading in chunks up to 64k (if your BIOS allows it) and not worry about crossing a segment boundary.
I've repleaced

Code: Select all

add bx, WORD [bpbBytesPerSector]
with

Code: Select all

mov dx, es
add dx, 32   ; Just for testing since (bpbBytesPerSector >> 4 == 32)
mov es, dx
and it loads correctly all the kernel file! Awesome! Thanks a lot! :)