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

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
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

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

Post 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 :)
Regards, Bonfra.
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

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

Post 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?
Regards, Bonfra.
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

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

Post 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.
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

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

Post 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!
Regards, Bonfra.
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

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

Post 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...
Regards, Bonfra.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post by iansjack »

A really simple solution would be to use an existing bootloader - e.g. GRUB.
sj95126
Member
Member
Posts: 151
Joined: Tue Aug 11, 2020 12:14 pm

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

Post 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.
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

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

Post 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! :)
Regards, Bonfra.
Post Reply