Problems with krnl.sys

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
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Problems with krnl.sys

Post by Karlosoft »

Hi! I've notice a problem. When my kernel is biggest than 50kb, my second stage (part of it, taken by brokenthorn.com) isn't able to load it. i'm using a FAT12 floppy, and the file is correctly loaded in it.

Does anyone have some ideas?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Problems with krnl.sys

Post by Brendan »

Hi,
Karlosoft wrote:Hi! I've notice a problem. When my kernel is biggest than 50kb, my second stage (part of it, taken by brokenthorn.com) isn't able to load it. i'm using a FAT12 floppy, and the file is correctly loaded in it.

Does anyone have some ideas?
All of the code you posted above is wrong!!!

Does that help?


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Problems with krnl.sys

Post by qw »

Karlosoft wrote:my second stage [...] isn't able to load it.
Karlosoft wrote:and the file is correctly loaded in it.
Is it or isn't it?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Problems with krnl.sys

Post by Brendan »

Hi,
Hobbes wrote:
Karlosoft wrote:my second stage [...] isn't able to load it.
Karlosoft wrote:and the file is correctly loaded in it.
Is it or isn't it?
I assumed Karlosoft meant "the file is correctly copied into the file system".


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Problems with krnl.sys

Post by Karlosoft »

Yes I meant copied :)

Well I can't post all the sources of the kernel. The code of the bootloader-stage2 that load my kernel is the same of this. I've just add some routines to enable vesa and save information from real mode.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Problems with krnl.sys

Post by neon »

Hello,

Are their any errors or warnings displayed in the bochs crash log or on display?
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Problems with krnl.sys

Post by Brendan »

Hi,
Karlosoft wrote:The code of the bootloader-stage2 that load my kernel is the same of this.
That code uses 16-bit registers to keep track of where to load the next sector into RAM. If you call "LoadFile" with BP = 0, then it'll wrap around after 65536 bytes (and if you call "LoadFile" with BP = 0x8000 you'd only be able to load 32 KiB before it fails).

At the end of "ReadSectors" it does this:

Code: Select all

          pop     cx
          pop     bx
          pop     ax
          add     bx, WORD [bpbBytesPerSector]        ; queue next buffer
          inc     ax                                  ; queue next sector
          loop    .MAIN                               ; read next sector
          ret
You might be able to change it to something like:

Code: Select all

          pop     cx
          pop     bx
          mov ax,es
          add ax,512/16
          mov es,ax
          pop     ax
          inc     ax                                  ; queue next sector
          loop    .MAIN                               ; read next sector
          ret
Not sure if that'd cause problems elsewhere, but it'd be a start - if it doesn't cause problems elsewhere you'd be able to load about 512 KiB before it fails.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Problems with krnl.sys

Post by Karlosoft »

I'll try it in the next days... my computer is dead :(. I'm coping my sources on the old.

No error, no warning only a flat black screen :(
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Problems with krnl.sys

Post by Karlosoft »

Wow, I've just tried this code but it doesn't work. I did some test and I've found the limit. It is C000 in hex, so 49152... well strange. The filesystem that I'm using is FAT12, I don't remember any restriction on the size of a file. This is my link.ld file... maybe the mistake is here...

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS{
	.text 0x100000 :
	{
		code = .; _code = .; __code = .;
		*(.text)
		. = ALIGN(4096);
}

.data :
{
__CTOR_LIST__ = .; LONG((__CTOR_END__ -
__CTOR_LIST__) / 4 - 2) *(.ctors) LONG(0) __CTOR_END__
= .;

 __DTOR_LIST__ = .; LONG((__DTOR_END__ -
__DTOR_LIST__) / 4 - 2) *(.dtors) LONG(0) __DTOR_END__ =
.;
	data = .; _data = .; __data = .;
	*(.data)
	. = ALIGN(4096);
}

.bss :
{
	bss = .; _bss = .; __bss = .;
	*(.bss)
	. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Problems with krnl.sys

Post by Karlosoft »

I have never write nothing in assembly except a pair of line in the C++ code, so it's not easy for me to understand what doesn't work. However i think the problem is in one of the point noticed by Brendan.
The strange thing is that the limit of the copy isn't the register bx that I'm using, but the maximal lenght of the offset. I can copy my kernel up to c000 because c000+3000 (the start offset) is less than ffff. If I move this start limit to 4000 in fact it doesn't work. So how to change the value of the segment pointer??? (I'm not very good to write assembly).
Post Reply