OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:25 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Loading kernel made in GCC from bootloader.
PostPosted: Sun May 07, 2017 12:37 pm 
Offline
Member
Member
User avatar

Joined: Sat Sep 17, 2016 2:14 am
Posts: 83
Location: Moscow, Russia
Hi,
I can't get the kernel written in GCC to work with my bootloader. The file is krnl32.sys. Instead of booting directly, it just gets stuck in an infinite loop.
Any suggestions?
Sincerely,
Timo.

_________________
Coffee is not airplane fuel.


Top
 Profile  
 
 Post subject: Re: Loading kernel made in GCC from bootloader.
PostPosted: Sun May 07, 2017 2:12 pm 
Offline
Member
Member
User avatar

Joined: Tue Aug 02, 2016 1:52 pm
Posts: 286
Location: East Riding of Yorkshire, UK
L̶e̶t̶ ̶m̶e̶ ̶j̶u̶s̶t̶ ̶l̶o̶o̶k̶ ̶i̶n̶t̶o̶ ̶m̶y̶ ̶c̶r̶y̶s̶t̶a̶l̶ ̶b̶a̶l̶l̶ ̶t̶o̶ ̶l̶o̶o̶k̶ ̶a̶t̶ ̶y̶o̶u̶r̶ ̶c̶o̶d̶e̶.̶.̶.̶

Can you post some relevant code?

_________________
com.sun.java.swing.plaf.nimbus.InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState
Compiler Development Forum


Top
 Profile  
 
 Post subject: Re: Loading kernel made in GCC from bootloader.
PostPosted: Sun May 07, 2017 2:15 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
TimothyWilliams wrote:
Any suggestions?

Well, to answer in the style of the question, you've done something wrong.


Top
 Profile  
 
 Post subject: Re: Loading kernel made in GCC from bootloader.
PostPosted: Sun May 07, 2017 2:59 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 21, 2011 9:47 pm
Posts: 286
Location: Tustin, CA USA
iansjack wrote:
Well, to answer in the style of the question, you've done something wrong.

I'm having a god laugh at this... My first reaction would have been: "fix the problem."

_________________
Adam

The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal

"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber


Top
 Profile  
 
 Post subject: Re: Loading kernel made in GCC from bootloader.
PostPosted: Wed May 10, 2017 10:48 am 
Offline
Member
Member
User avatar

Joined: Sat Sep 17, 2016 2:14 am
Posts: 83
Location: Moscow, Russia
matt11235 wrote:
L̶e̶t̶ ̶m̶e̶ ̶j̶u̶s̶t̶ ̶l̶o̶o̶k̶ ̶i̶n̶t̶o̶ ̶m̶y̶ ̶c̶r̶y̶s̶t̶a̶l̶ ̶b̶a̶l̶l̶ ̶t̶o̶ ̶l̶o̶o̶k̶ ̶a̶t̶ ̶y̶o̶u̶r̶ ̶c̶o̶d̶e̶.̶.̶.̶

Can you post some relevant code?


Here.


Attachments:
File comment: Thunder v0.1 Code
thundercode.zip [17.58 KiB]
Downloaded 41 times

_________________
Coffee is not airplane fuel.
Top
 Profile  
 
 Post subject: Re: Loading kernel made in GCC from bootloader.
PostPosted: Wed May 10, 2017 11:50 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
As an aside here, are you using a VCS such as git, Subversion, mercurial, or bazaar, and do you have an offisite repo for the code (o, say, CloudForge or Github)? I would strongly recommend both, for a number of reasons. If nothing else, it would mean that you could give us a link to the repo rather than an archive file, and we'd be able to see the latest updates as the project progresses.

EDIT: OK, I have taken a look at the files kernel.asm and krnl.c, and will look at some of the others later, but I can tell you right now that either I'm confused about what you are doing, or you are.

The main thing that strikes me here is that the boot loader has a) a multiboot header, and b) no boot signature byte, meaning that it should be used as an entry point for a multiboot loader such as GRUB. However, in other respects, it looks like a typical hand-rolled boot loader - the code is 16-bit, and sets up the A20 line and a GDT, which wouldn't be necessary if it were meant to boot from GRUB (the Multiboot spec is such that the loader should always put the system into protected or long mode before the hand-off to the OS).

I think we need to hear what you think is going on, and how you expect it to work. Some details on your development methods (especially your linker script) would be useful here as well. I know that you have had problems trying to get the boot block loaded into an image and/or a live disk (your posts about dd and other tools), but it looks like there are other problems here as well.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: Loading kernel made in GCC from bootloader.
PostPosted: Thu May 11, 2017 1:19 pm 
Offline
Member
Member
User avatar

Joined: Sat Sep 17, 2016 2:14 am
Posts: 83
Location: Moscow, Russia
Schol-R-LEA wrote:
As an aside here, are you using a VCS such as git, Subversion, mercurial, or bazaar, and do you have an offisite repo for the code (o, say, CloudForge or Github)? I would strongly recommend both, for a number of reasons. If nothing else, it would mean that you could give us a link to the repo rather than an archive file, and we'd be able to see the latest updates as the project progresses.

EDIT: OK, I have taken a look at the files kernel.asm and krnl.c, and will look at some of the others later, but I can tell you right now that either I'm confused about what you are doing, or you are.

The main thing that strikes me here is that the boot loader has a) a multiboot header, and b) no boot signature byte, meaning that it should be used as an entry point for a multiboot loader such as GRUB. However, in other respects, it looks like a typical hand-rolled boot loader - the code is 16-bit, and sets up the A20 line and a GDT, which wouldn't be necessary if it were meant to boot from GRUB (the Multiboot spec is such that the loader should always put the system into protected or long mode before the hand-off to the OS).

I think we need to hear what you think is going on, and how you expect it to work. Some details on your development methods (especially your linker script) would be useful here as well. I know that you have had problems trying to get the boot block loaded into an image and/or a live disk (your posts about dd and other tools), but it looks like there are other problems here as well.


OK, Schol-R-LEA, this is what is going on with the system. I copy KRNL32.SYS and KRNLDR.SYS to the virtual drive, then 'mkbt' the bootloader onto a floppy, then I turn on Bochs, set up the virtual floppy, and when I click Start, it shows only the messages from boot and sometimes, the kernel loader.

_________________
Coffee is not airplane fuel.


Top
 Profile  
 
 Post subject: Re: Loading kernel made in GCC from bootloader.
PostPosted: Thu May 11, 2017 2:13 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 21, 2011 9:47 pm
Posts: 286
Location: Tustin, CA USA
Schol-R-LEA wrote:
As an aside here, are you using a VCS such as git, Subversion, mercurial, or bazaar, and do you have an offsite repo for the code (o, say, CloudForge or Github)? I would strongly recommend both, for a number of reasons.


You seem to be stepping over this very important suggestion. One of these days you are going to come across a situation where you are going to want to go back and review old code for some reason or another (or worse, recover it). In my case it was a 2-disk failure (within minutes of each other) of my SAN RAID set. It was a hard lesson and I would hate for you to learn it first hand.

_________________
Adam

The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal

"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber


Top
 Profile  
 
 Post subject: Re: Loading kernel made in GCC from bootloader.
PostPosted: Thu May 11, 2017 6:24 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
TimothyWilliams wrote:
OK, Schol-R-LEA, this is what is going on with the system. I copy KRNL32.SYS and KRNLDR.SYS to the virtual drive, then 'mkbt' the bootloader onto a floppy, then I turn on Bochs, set up the virtual floppy, and when I click Start, it shows only the messages from boot and sometimes, the kernel loader.


Ah, yes, turnabout is fair play. I should be more specific: can you explain some of the different parts of the code, why you wrote them the way they are, and what you expect them to do? The Multiboot header is a good place to start with this. Given that you are describing what seems to be an installation for a one-stage loader you wrote yourself, why did you use a multiboot header here?

(I have a sneaking suspicion this is going to lead to me editing several wiki pages, for clarity if nothing else...)

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: Loading kernel made in GCC from bootloader.
PostPosted: Wed May 17, 2017 4:42 am 
Offline
Member
Member
User avatar

Joined: Sat Sep 17, 2016 2:14 am
Posts: 83
Location: Moscow, Russia
Schol-R-LEA wrote:
TimothyWilliams wrote:
OK, Schol-R-LEA, this is what is going on with the system. I copy KRNL32.SYS and KRNLDR.SYS to the virtual drive, then 'mkbt' the bootloader onto a floppy, then I turn on Bochs, set up the virtual floppy, and when I click Start, it shows only the messages from boot and sometimes, the kernel loader.


Ah, yes, turnabout is fair play. I should be more specific: can you explain some of the different parts of the code, why you wrote them the way they are, and what you expect them to do? The Multiboot header is a good place to start with this. Given that you are describing what seems to be an installation for a one-stage loader you wrote yourself, why did you use a multiboot header here?

(I have a sneaking suspicion this is going to lead to me editing several wiki pages, for clarity if nothing else...)


Ahem, that was from the old bootloader, I use Broken Thorn's bootloader.

_________________
Coffee is not airplane fuel.


Top
 Profile  
 
 Post subject: Re: Loading kernel made in GCC from bootloader.
PostPosted: Wed May 17, 2017 6:44 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
Hello,

It appears to me that other members assumed that you were using GrUB. However, it looks like the original boot loader has been modified. We also noticed the boot loader entry point appears to be missing...double check what files you are using from the original code and how they work together.

Is kernel.asm supposed to be the kernel? Why not write it in C? It should not be using any part of the boot loader.

In any case, you should note that the boot loader was designed to load PE images at 1MB (later, mapping them to 2GB virtual) whereas GCC typically targets ELF. We typically recommend using ELF if using GCC or a GCC Cross Compiler. Or just use GrUB for now since it natively supports what you are trying to do.

_________________
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject: Re: Loading kernel made in GCC from bootloader.
PostPosted: Thu May 18, 2017 2:50 am 
Offline
Member
Member
User avatar

Joined: Sat Sep 17, 2016 2:14 am
Posts: 83
Location: Moscow, Russia
neon wrote:
Hello,

It appears to me that other members assumed that you were using GrUB. However, it looks like the original boot loader has been modified. We also noticed the boot loader entry point appears to be missing...double check what files you are using from the original code and how they work together.

Is kernel.asm supposed to be the kernel? Why not write it in C? It should not be using any part of the boot loader.

In any case, you should note that the boot loader was designed to load PE images at 1MB (later, mapping them to 2GB virtual) whereas GCC typically targets ELF. We typically recommend using ELF if using GCC or a GCC Cross Compiler. Or just use GrUB for now since it natively supports what you are trying to do.


FYI, kernel.asm is the Stage 2 bootloader. It compiled properly and without any errors, so was the krnl.c and its dependencies itself.
The last problem that I need to solve is the link problem. I use MinGW GCC to link, but when I try to link all of the objects into one, it gives me this" start.o: File not recognized: File format not recognized. When I checked the file it said that it is i686. Any suggestions?

Sincerely,
Tim :|

_________________
Coffee is not airplane fuel.


Top
 Profile  
 
 Post subject: Re: Loading kernel made in GCC from bootloader.
PostPosted: Thu May 18, 2017 6:47 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
Hello,

I see. kernel.asm declares the multiboot header structure so that it can fill it out for use by the kernel. You are correct, this is boot loader code (although modified.)
Quote:
The last problem that I need to solve is the link problem. I use MinGW GCC to link, but when I try to link all of the objects into one, it gives me this" start.o: File not recognized: File format not recognized. When I checked the file it said that it is i686.
What is the command line that you are using and what version of Mingw are you using? If you used a tutorial to get the command lines (and linker script), what tutorial did you use?

_________________
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject: Re: Loading kernel made in GCC from bootloader.
PostPosted: Thu May 18, 2017 1:01 pm 
Offline
Member
Member
User avatar

Joined: Sat Sep 17, 2016 2:14 am
Posts: 83
Location: Moscow, Russia
neon wrote:
Hello,

I see. kernel.asm declares the multiboot header structure so that it can fill it out for use by the kernel. You are correct, this is boot loader code (although modified.)
Quote:
The last problem that I need to solve is the link problem. I use MinGW GCC to link, but when I try to link all of the objects into one, it gives me this" start.o: File not recognized: File format not recognized. When I checked the file it said that it is i686.
What is the command line that you are using and what version of Mingw are you using? If you used a tutorial to get the command lines (and linker script), what tutorial did you use?

GCC 5.3.0

_________________
Coffee is not airplane fuel.


Top
 Profile  
 
 Post subject: Re: Loading kernel made in GCC from bootloader.
PostPosted: Thu May 18, 2017 3:45 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 21, 2011 9:47 pm
Posts: 286
Location: Tustin, CA USA
TimothyWilliams wrote:
neon wrote:
Hello,

I see. kernel.asm declares the multiboot header structure so that it can fill it out for use by the kernel. You are correct, this is boot loader code (although modified.)
Quote:
The last problem that I need to solve is the link problem. I use MinGW GCC to link, but when I try to link all of the objects into one, it gives me this" start.o: File not recognized: File format not recognized. When I checked the file it said that it is i686.
What is the command line that you are using and what version of Mingw are you using? If you used a tutorial to get the command lines (and linker script), what tutorial did you use?

GCC 5.3.0

You know, you are the one seeking help here.... You might take a moment to help us help you.

TimothyWilliams wrote:
GCC 5.3.0


I seriously doubt typing that sequence of characters on any command line will link anything in the manner you wish.

neon wrote:
We typically recommend using ELF if using GCC or a GCC Cross Compiler.


I also believe there is a Cross-Compiler issue. Can you please confirm that you have followed these instructions: http://wiki.osdev.org/GCC_Cross-Compiler.

Now, to the question of exact commands used to create your binaries.... If you are genuinely interested in solving this problem, the people in the best position to help you are asking for the exact bits of information needed to provide you with the advice you are seeking. Ignoring those requests is not going to get you where you want to be any faster (if at all). By the way, the exact commands will help us determine if you are actually using your cross-compiler.

_________________
Adam

The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal

"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 27 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