OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Jul 21, 2018 7:10 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: Kernel loading problem
PostPosted: Tue Jul 03, 2018 10:13 am 
Offline

Joined: Tue Jul 03, 2018 9:48 am
Posts: 8
Hello, I am on LINUX and I trying to make an little operating system using NASM and QEMU with a FAT12 filesystem but it doesn't work.
I have take the source code from a tutorial that you can download here : http://www.brokenthorn.com/Resources/Demos/Demo1.zip.

I make this :
Code:
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)$ cd Stage1
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)/Stage1$ nasm -f bin Boot1.asm -o Boot1.bin
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)/Stage1$ cd ../Stage2
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)/Stage2$ nasm -f bin Stage2.asm -o KRNLDR.SYS
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)/Stage2$ cd ..
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)$ cat Stage1/Boot1.bin Stage2/KRNLDR.SYS /dev/zero | dd of=floppyA bs=512 count=2880
2880+0 enregistrements lus
2880+0 enregistrements écrits
1474560 bytes (1,5 MB, 1,4 MiB) copied, 0,00695998 s, 212 MB/s
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)$ qemu-system-i386 -boot a -fda floppyA
WARNING: Image format was not specified for 'floppyA' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
sipige@Sipige-GE62VR-6RF:~/Téléchargements/Demo1 (1)$


And I have :
Code:
ERROR : Press Any Key to Reboot


I do not know what to do.
Thanks

_________________
Sorry for my english, I am french.


Top
 Profile  
 
 Post subject: Re: Kernel loading problem
PostPosted: Tue Jul 03, 2018 11:47 am 
Offline
Member
Member
User avatar

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

You shouldn't be concatenating those two files. Reformat the disk, then install stage 1, then mount the disk and copy stage2.bin to the root directory. Please reference the OSDev wiki here for creating and mounting disk images with Linux.

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


Top
 Profile  
 
 Post subject: Re: Kernel loading problem
PostPosted: Tue Jul 03, 2018 11:55 am 
Offline

Joined: Tue Jul 03, 2018 9:48 am
Posts: 8
Thank you. I will test this tomorrow.

_________________
Sorry for my english, I am french.


Top
 Profile  
 
 Post subject: Re: Kernel loading problem
PostPosted: Wed Jul 04, 2018 2:35 am 
Offline

Joined: Tue Jul 03, 2018 9:48 am
Posts: 8
Ok but I have a problem with losetup :
Code:
root@Sipige-GE62VR-6RF:/home/sipige/Téléchargements/Demo1 (1)# dd if=/dev/zero of=floppy.img bs=512 count=2880
2880+0 enregistrements lus
2880+0 enregistrements écrits
1474560 bytes (1,5 MB, 1,4 MiB) copied, 0,0247006 s, 59,7 MB/s
root@Sipige-GE62VR-6RF:/home/sipige/Téléchargements/Demo1 (1)# losetup /dev/loop0 floppy.img
losetup: floppy.img : échec de configuration du périphérique boucle: Périphérique ou ressource occupé
root@Sipige-GE62VR-6RF:/home/sipige/Téléchargements/Demo1 (1)#

_________________
Sorry for my english, I am french.


Top
 Profile  
 
 Post subject: Re: Kernel loading problem
PostPosted: Wed Jul 04, 2018 4:57 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 03, 2008 4:13 am
Posts: 126
Location: Ogre, Latvia, EU
Quote:
échec de configuration du périphérique boucle: Périphérique ou ressource occupé

It complains that /dev/loop0 is already in use.

To see the details, run
Code:
losetup -l


If you know what that loopback device is used for (you did set it up earlier), can detach it by running
Code:
losetup -d /dev/loop0


You can use another loopback device as well. My Linux distro has /dev/loop0, /dev/loop1, ..., /dev/loop7 and there's probably a way to add more.

_________________
If something looks overcomplicated, most likely it is.


Top
 Profile  
 
 Post subject: Re: Kernel loading problem
PostPosted: Wed Jul 04, 2018 7:02 am 
Offline

Joined: Tue Jul 03, 2018 9:48 am
Posts: 8
Ok thanks.

I have this :
Code:
root@Sipige-GE62VR-6RF:/home/sipige/Téléchargements/Demo1 (1)# dd if=/dev/zero of=floppy.img bs=512 count=2880
2880+0 enregistrements lus
2880+0 enregistrements écrits
1474560 bytes (1,5 MB, 1,4 MiB) copied, 0,0243512 s, 60,6 MB/s
root@Sipige-GE62VR-6RF:/home/sipige/Téléchargements/Demo1 (1)# losetup /dev/loop16 floppy.img
root@Sipige-GE62VR-6RF:/home/sipige/Téléchargements/Demo1 (1)# mkdosfs -F 12 /dev/loop16
mkfs.fat 4.1 (2017-01-24)
root@Sipige-GE62VR-6RF:/home/sipige/Téléchargements/Demo1 (1)#


But now I don't know to install stage1 and how to copy stage2.

_________________
Sorry for my english, I am french.


Top
 Profile  
 
 Post subject: Re: Kernel loading problem
PostPosted: Wed Jul 04, 2018 11:42 am 
Offline
Member
Member
User avatar

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

For installing the boot record (stage1) -- This can be done using third party software (i.e. PartCopy or a hex editor like Cygnus or HxD) or writing your own program to do it. We recommend just writing a utility since it can be extended in the future -- for now though all it needs to do is a simple fread/fwrite to read stage1.bin and overwrite the first 512 bytes of the disk image with it.

For copying the boot loader (stage2) -- You need to mount the disk image to some device so you can open it and access its contents. Copy stage2.bin to the root directory of the disk image.

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


Top
 Profile  
 
 Post subject: Re: Kernel loading problem
PostPosted: Thu Jul 05, 2018 4:20 am 
Offline
Member
Member

Joined: Wed Sep 19, 2012 3:43 am
Posts: 71
Location: The Netherlands
Did you actually try to search the wiki?
Just about everything you're asking is outlined in the Bare Bones article.
If you're not using Grub to boot the OS, there are resources for that too.

This might come across as hostile, but please search the wiki before posting a question.


Top
 Profile  
 
 Post subject: Re: Kernel loading problem
PostPosted: Thu Jul 05, 2018 4:48 am 
Offline

Joined: Tue Jul 03, 2018 9:48 am
Posts: 8
Fust I have search but I don't want to use grub and all is in english.

Code:
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1/Stage1# nasm -f bin Boot1.asm -o bootloader.bin
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1/Stage1# cd ../Stage2
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1/Stage2# nasm -f bin Stage2.asm -o KRNLDR.SYS
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1/Stage2# cd ..
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1# dd if=/dev/zero of=floppy.img bs=512 count=2880
2880+0 enregistrements lus
2880+0 enregistrements écrits
1474560 bytes (1,5 MB, 1,4 MiB) copied, 0,00841148 s, 175 MB/s
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1# losetup /dev/loop15 floppy.img
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1# mkdosfs -F 12 /dev/loop15
mkfs.fat 4.1 (2017-01-24)
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1# chmod a+w floppy.img


Then I use wxHexEditor for replace the beginning of floppy.img by bootloader.bin.
Now I must copy KRNLDR.SYS to /dev/loop15 but I am new on Linux and I don't know ho to do.
Thank you

EDIT : Ah ok. Just had to do cd / mnt!
So I make this :
Code:
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1# mount /dev/loop15 /mnt -t msdos -o "fat=12"
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1# mv Stage2/KRNLDR.SYS /mnt
root@Sipige-GE62VR-6RF:/home/sipige/Documents/os/BrokenThorn/Demo1# qemu-system-i386 floppy.img

But the boot failed.
I don't know why but it is not in capital letters.
Code:
root@Sipige-GE62VR-6RF:/mnt# dir
krnldr.sys

_________________
Sorry for my english, I am french.


Top
 Profile  
 
 Post subject: Re: Kernel loading problem
PostPosted: Thu Jul 05, 2018 10:04 am 
Offline
Member
Member
User avatar

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

You should be unmounting it before using floppy.img (or just boot directly from /mnt.) Also, case sensitivity (upper/lower case) doesn't matter since we are using the 8.3 short file name to find it. i.e. "krnldr" and "KRNLDR" are two names for the same file.

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


Top
 Profile  
 
 Post subject: Re: Kernel loading problem
PostPosted: Thu Jul 05, 2018 10:16 am 
Offline

Joined: Tue Jul 03, 2018 9:48 am
Posts: 8
THANK YOU !!!
Thank you very much !
Since the time I was stuck on it I began to believe that it would never work!

_________________
Sorry for my english, I am french.


Top
 Profile  
 
 Post subject: Re: Kernel loading problem
PostPosted: Fri Jul 06, 2018 1:03 am 
Offline
Member
Member

Joined: Wed Sep 19, 2012 3:43 am
Posts: 71
Location: The Netherlands
Sipige wrote:
and all is in english.

You'll find that the vast majority of OSdev resources are in English, which can make it a bit difficult if your English isn't very good.
This forum, wiki and most of the hardware manuals are in English. I'd argue that, besides knowing ASM/C/C++/whatever you write your OS in, English is a required skill to start OSdeving (though I have come across some French OSdev-related websites and forums too).

Again, this might come across a bit harsh but a lot of the things you're asking can be found through the wiki, forums or Google search with little to no effort and most of it isn't very OSdev-related, it's basic Linux usage.

Also, starting something as hard as OSdev on a platform that is completely new to you is probably not the best choice.
Stick with what you know (Windows I suppose, lots of great tools and resources out there for OSdev), take your first steps in the world of OSdev and become familiar with it.
It's good to want to learn how to use a new system (or programming language, for that matter), but don't combine it with trying to learn how to develop an OS, it'll be too much.

Of course, this is just my take on things, others might disagree.


Top
 Profile  
 
 Post subject: Re: Kernel loading problem
PostPosted: Fri Jul 06, 2018 2:15 am 
Offline

Joined: Tue Jul 03, 2018 9:48 am
Posts: 8
Yes but reading a language is the best way to learn it.
I can read english well but I need time so I prefer french.

_________________
Sorry for my english, I am french.


Top
 Profile  
 
 Post subject: Re: Kernel loading problem
PostPosted: Fri Jul 06, 2018 9:24 am 
Offline
Member
Member

Joined: Thu Jul 03, 2014 5:18 am
Posts: 54
Location: The Netherlands
I also suppose that if qemu could not open the image, it would have said something along the lines of "Could not open file" in its log file/output window.

If you got stuck on this part, it might be best to take a step back and get used to Linux first.

_________________
My blog: http://www.rivencove.com/


Top
 Profile  
 
 Post subject: Re: Kernel loading problem
PostPosted: Fri Jul 06, 2018 9:25 am 
Offline

Joined: Tue Jul 03, 2018 9:48 am
Posts: 8
No it is solved.

_________________
Sorry for my english, I am french.


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: Google [Bot] and 8 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