Page 1 of 2
Problem loading kernel
Posted: Sun Jan 06, 2013 4:18 am
by BMW
I am trying to load my kernel from my bootloader, however the int 0x13 refuses to load more than 2 sectors.
Can it only load 2 sectors at a time or something?
Re: Loading sectors from disk only loading 2 sectors
Posted: Sun Jan 06, 2013 5:09 am
by Combuster
Int 0x13 can read many sectors depending on a whole range of other conditions.
Learn to check error codes.
Re: Loading sectors from disk only loading 2 sectors
Posted: Sun Jan 06, 2013 5:14 am
by iansjack
The INT 13 functions can read more than two sectors at a time, although - obviously - it is limited by the number of sectors on the track, so clearly you are doing something wrong.
Without code it is less clear what that is.
Re: Loading sectors from disk only loading 2 sectors
Posted: Sun Jan 06, 2013 2:26 pm
by BMW
I am reading 5 sectors from a hard drive (sectors 4-8).
Re: Loading sectors from disk only loading 2 sectors
Posted: Sun Jan 06, 2013 3:08 pm
by Griwes
iansjack wrote:Without code it is less clear what that is.
Also, which functions of int 0x13...? What device...?
We know almost exactly nothing from your description of problem; how are we supposed to be able to help?
Re: Loading sectors from disk only loading 2 sectors
Posted: Sun Jan 06, 2013 3:28 pm
by BMW
Griwes wrote:iansjack wrote:Without code it is less clear what that is.
Also, which functions of int 0x13...? What device...?
We know almost exactly nothing from your description of problem; how are we supposed to be able to help?
Sorry.
Function 0x02.
The device is a hard drive.
Re: Loading sectors from disk only loading 2 sectors
Posted: Sun Jan 06, 2013 3:33 pm
by BMW
Combuster wrote:Int 0x13 can read many sectors depending on a whole range of other conditions.
Learn to check error codes.
Hmmm... there is no error.
Re: Loading sectors from disk only loading 2 sectors
Posted: Sun Jan 06, 2013 3:40 pm
by Combuster
How many more questions do we need to ask you before we are able to reproduce your problem?
Re: Loading sectors from disk only loading 2 sectors
Posted: Sun Jan 06, 2013 3:54 pm
by BMW
Combuster wrote:How many more questions do we need to ask you before we are able to reproduce your problem?
Ok, the problem is not with the loading of the kernel, but with the executing of it.
When you load a PE file, do you just load the whole thing then jump to the entry point? Or do you have to load different parts of it to different places?
Re: Problem loading kernel
Posted: Sun Jan 06, 2013 4:03 pm
by sortie
Do you know what the file format of a PE file is? If you did, then you'd know the answer to your question.
Re: Problem loading kernel
Posted: Sun Jan 06, 2013 4:42 pm
by BMW
sortie wrote:Do you know what the file format of a PE file is? If you did, then you'd know the answer to your question.
Ok sorry I see now. I have to use the relocation tables and move the sections to appropriate places.
Re: Problem loading kernel
Posted: Sun Jan 06, 2013 6:49 pm
by BMW
If I set the base address in visual studio to where I load the PE file, will this eliminate the need to change the offsets in the relocation table?
Re: Problem loading kernel
Posted: Sun Jan 06, 2013 7:23 pm
by Brendan
Hi,
BMW wrote:If I set the base address in visual studio to where I load the PE file, will this eliminate the need to change the offsets in the relocation table?
A quick questionnaire:
- Do you need relocatable code (e.g. will the kernel be loaded at "random" virtual addresses)?
- Do you need dynamic linking (e.g. will unresolved references in the kernel be linked to something else when it's loaded)?
- Do you need a real mode stub that displays "This program requires Windows" in case someone tries to execute your kernel on MS-DOS?
If the answer to these questions are all "no", then why do you want to use PE in the first place? Just use something (e.g. objcopy) to convert the PE into a flat binary and load the flat binary into memory "as is" (without any of the PE loader hassles or file format bloat).
Cheers,
Brendan
Re: Problem loading kernel
Posted: Sun Jan 06, 2013 8:43 pm
by BMW
No. No. No.
What a good idea. Thanks.
Re: Problem loading kernel
Posted: Sun Jan 06, 2013 9:35 pm
by BMW
Brendan wrote:Hi,
BMW wrote:If I set the base address in visual studio to where I load the PE file, will this eliminate the need to change the offsets in the relocation table?
A quick questionnaire:
- Do you need relocatable code (e.g. will the kernel be loaded at "random" virtual addresses)?
- Do you need dynamic linking (e.g. will unresolved references in the kernel be linked to something else when it's loaded)?
- Do you need a real mode stub that displays "This program requires Windows" in case someone tries to execute your kernel on MS-DOS?
If the answer to these questions are all "no", then why do you want to use PE in the first place? Just use something (e.g. objcopy) to convert the PE into a flat binary and load the flat binary into memory "as is" (without any of the PE loader hassles or file format bloat).
Cheers,
Brendan
Lol, chucked a 2.5KB PE file into objcopy, spat out a 9KB binary file 99% full of 0x00... im not putting up with that.
How can I fix this?