OSDev.org
https://forum.osdev.org/

received signal SIGQUIT, Quit. When kernel file is too large
https://forum.osdev.org/viewtopic.php?f=1&t=37372
Page 1 of 1

Author:  Bonfra [ Mon Oct 19, 2020 4:32 pm ]
Post subject:  received signal SIGQUIT, Quit. When kernel file is too large

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:
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:
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 :)

Author:  Octocontrabass [ Mon Oct 19, 2020 6:27 pm ]
Post subject:  Re: received signal SIGQUIT, Quit. When kernel file is too l

Your buffer offset wraps around at 64kiB.

Author:  Bonfra [ Mon Oct 19, 2020 11:58 pm ]
Post subject:  Re: received signal SIGQUIT, Quit. When kernel file is too l

Octocontrabass wrote:


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?

Author:  Octocontrabass [ Tue Oct 20, 2020 12:30 am ]
Post subject:  Re: received signal SIGQUIT, Quit. When kernel file is too l

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.

Author:  Bonfra [ Tue Oct 20, 2020 4:15 am ]
Post subject:  Re: received signal SIGQUIT, Quit. When kernel file is too l

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!

Author:  Bonfra [ Tue Oct 20, 2020 6:22 am ]
Post subject:  Re: received signal SIGQUIT, Quit. When kernel file is too l

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

Author:  iansjack [ Tue Oct 20, 2020 8:23 am ]
Post subject:  Re: received signal SIGQUIT, Quit. When kernel file is too l

A really simple solution would be to use an existing bootloader - e.g. GRUB.

Author:  sj95126 [ Tue Oct 20, 2020 9:17 am ]
Post subject:  Re: received signal SIGQUIT, Quit. When kernel file is too l

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.

Author:  Bonfra [ Tue Oct 20, 2020 9:44 am ]
Post subject:  Re: received signal SIGQUIT, Quit. When kernel file is too l

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:
add bx, WORD [bpbBytesPerSector]

with
Code:
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! :)

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/