Trying to get bootloader to read EXE file compiled in MinGW

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
Thunderbirds747
Member
Member
Posts: 83
Joined: Sat Sep 17, 2016 2:14 am
Location: Moscow, Russia

Trying to get bootloader to read EXE file compiled in MinGW

Post by Thunderbirds747 »

Hello,
I was playing around with BrokenThorn's tutorials in NASM and tried to get the bootloader to read the file.
When I put in the kernel in a virtual floppy drive, it just keeps on looping.
Hope you can help me out,
Timothy Ryazanov.
Attachments
os.zip
OS written in NASM (Mike's tutorial + my code in C)
(50.89 KiB) Downloaded 65 times
Coffee is not airplane fuel.
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

Re: Trying to get bootloader to read EXE file compiled in Mi

Post by PeterX »

It would be useful to know where the loop occurs. In the bootloader? In which part of it? Or in the kernel? And does it reboot or does it print endlessly on the screen or does it showing the same message again after some input from the user?

Maybe this is case for *dramatic music* Captain Debug.
User avatar
Thunderbirds747
Member
Member
Posts: 83
Joined: Sat Sep 17, 2016 2:14 am
Location: Moscow, Russia

Re: Trying to get bootloader to read EXE file compiled in Mi

Post by Thunderbirds747 »

PeterX wrote:It would be useful to know where the loop occurs. In the bootloader? In which part of it? Or in the kernel? And does it reboot or does it print endlessly on the screen or does it showing the same message again after some input from the user?

Maybe this is case for *dramatic music* Captain Debug.
The loop occurs whenever the two stage bootloader tries to read KRNL32.EXE which I wrote.
Technically, I should have used some commands from Bare Bones tutorial (OSDev Wiki)
I suddenly realised that I haven't used the command while I was asleep.
Will try again to get the kernel to load.

Cheers,
Tim
Coffee is not airplane fuel.
User avatar
Thunderbirds747
Member
Member
Posts: 83
Joined: Sat Sep 17, 2016 2:14 am
Location: Moscow, Russia

Re: Trying to get bootloader to read EXE file compiled in Mi

Post by Thunderbirds747 »

It appears to be a triple fault caused by the kernel file that I wrote in MinGW.
Tried out Bochs and VirtualBox, no improvements.
Coffee is not airplane fuel.
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

Re: Trying to get bootloader to read EXE file compiled in Mi

Post by PeterX »

You are referencing an array over a simple char pointer. Seems wrong to me. There is no array, I think.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Trying to get bootloader to read EXE file compiled in Mi

Post by bzt »

PeterX wrote:Maybe this is case for *dramatic music* Captain Debug.
Haha, good one! And you're absolutely correct.

To the OP:
TimothyARyazanov wrote:The loop occurs whenever the two stage bootloader tries to read KRNL32.EXE which I wrote.
This suggests you haven't loaded the file yet.
TimothyARyazanov wrote:It appears to be a triple fault caused by the kernel file that I wrote in MinGW.
This suggests you have loaded the file. Which one is it?

Do debug, and figure out which part is failing.
1. does you bootloader load the file properly? (has nothing to do with MinGW)
2. if the file is loaded, do you parse the PE header correctly? (has nothing to do with MinGW)
3. do you copy the code segment and data segments at the positions they should be? (not MinGW related either)
4. do you identify the entry point correctly? Is it in the code segment, and does it point the instruction as it should? (not MinGW related)
5. do you transfer the control correctly? Are the registers containing the correct arguments? Does your jmp really jump where it supposed to? (not MinGW related)
6. if you put nothing more than an infinite loop in your kernel file, do simulation stop there? (not MinGW related)
7. if you replace that infinite loop with something else, does it work? (Probably linker script or could be MinGW related, as it should compile for freestanding, no libraries and no functions like printf)

Please check this list one-by-one. Don't go to the next step unless you're certain (==you debugged it successfully).
A few notes: for 1., run debugger and dump memory at load address. Do you see the MZ header there? For 4., check with objdump what instructions are in the file at _start label, and with a debugger dump the memory to see if the instructions in memory at the entry point are the same. For 7., it could be that it's not working because your load address and linking address are not the same.

One more hint: if you're using long mode, then you'll have to sign extend the entry point address, because the memory address is 64 bit, but the entry point in the file is just 32 bit. This is very important if you're using upper-half.

Cheers,
bzt
FusT
Member
Member
Posts: 91
Joined: Wed Sep 19, 2012 3:43 am
Location: The Netherlands

Re: Trying to get bootloader to read EXE file compiled in Mi

Post by FusT »

I would start by using Bochs with reboot on triple fault disabled.
That way you can inspect the register and memory contents and actually see what's going on instead of guessing
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

Re: Trying to get bootloader to read EXE file compiled in Mi

Post by PeterX »

in core/main.c:

Code: Select all

vidptr[j] = ' ';
That is wrong, I think.
Use something like:

Code: Select all

vidptr++;
*vidptr = ' ';
Post Reply