OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 5:27 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: received signal SIGQUIT, Quit. When kernel file is too large
PostPosted: Mon Oct 19, 2020 4:32 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 270
Location: Italy
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 :)

_________________
Regards, Bonfra.


Top
 Profile  
 
 Post subject: Re: received signal SIGQUIT, Quit. When kernel file is too l
PostPosted: Mon Oct 19, 2020 6:27 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5103
Your buffer offset wraps around at 64kiB.


Top
 Profile  
 
 Post subject: Re: received signal SIGQUIT, Quit. When kernel file is too l
PostPosted: Mon Oct 19, 2020 11:58 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 270
Location: Italy
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?

_________________
Regards, Bonfra.


Top
 Profile  
 
 Post subject: Re: received signal SIGQUIT, Quit. When kernel file is too l
PostPosted: Tue Oct 20, 2020 12:30 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5103
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.


Top
 Profile  
 
 Post subject: Re: received signal SIGQUIT, Quit. When kernel file is too l
PostPosted: Tue Oct 20, 2020 4:15 am 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 270
Location: Italy
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.


Top
 Profile  
 
 Post subject: Re: received signal SIGQUIT, Quit. When kernel file is too l
PostPosted: Tue Oct 20, 2020 6:22 am 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 270
Location: Italy
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.


Top
 Profile  
 
 Post subject: Re: received signal SIGQUIT, Quit. When kernel file is too l
PostPosted: Tue Oct 20, 2020 8:23 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
A really simple solution would be to use an existing bootloader - e.g. GRUB.


Top
 Profile  
 
 Post subject: Re: received signal SIGQUIT, Quit. When kernel file is too l
PostPosted: Tue Oct 20, 2020 9:17 am 
Offline
Member
Member

Joined: Tue Aug 11, 2020 12:14 pm
Posts: 151
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.


Top
 Profile  
 
 Post subject: Re: received signal SIGQUIT, Quit. When kernel file is too l
PostPosted: Tue Oct 20, 2020 9:44 am 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 270
Location: Italy
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! :)

_________________
Regards, Bonfra.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot] and 114 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group