Xosdev tutorial mr. xsism - getting it running
Xosdev tutorial mr. xsism - getting it running
Hi, OS newbie here.
I am using linux & qemu as a development environment and I am trying to get the kernel from the Xosdev tutorial going.
http://www.osdever.net/tutorials/ch01.php
Can anyone help me with this process? I have written the simple C kernel, and have the asm files. So I have:
boot.asm
k_init.asm
kmain.c
I assume I am meant to:
nasm boot.asm -f bin
Then I do:
nasm k_init.asm -f aout
and:
gcc -c kmain.c
Then:
ld -o kernel.o kmain.o k_init.o
Which gives me: "warning cannot find entry symbol, defaulting to 000008048078"
What do I do now? How do I combine the bootloader (boot binary) with the C kernel? How do I get it to load in qemu?
(Just typing "qemu boot" - does very little, obviously it is not 'loading' the 'kernel')..
Thanks!
I am using linux & qemu as a development environment and I am trying to get the kernel from the Xosdev tutorial going.
http://www.osdever.net/tutorials/ch01.php
Can anyone help me with this process? I have written the simple C kernel, and have the asm files. So I have:
boot.asm
k_init.asm
kmain.c
I assume I am meant to:
nasm boot.asm -f bin
Then I do:
nasm k_init.asm -f aout
and:
gcc -c kmain.c
Then:
ld -o kernel.o kmain.o k_init.o
Which gives me: "warning cannot find entry symbol, defaulting to 000008048078"
What do I do now? How do I combine the bootloader (boot binary) with the C kernel? How do I get it to load in qemu?
(Just typing "qemu boot" - does very little, obviously it is not 'loading' the 'kernel')..
Thanks!
Re: Xosdev tutorial mr. xsism - getting it running
This is normal, you do not specify to LD the entry point. But for your kernel, you must generate a binary file and not an ELF object file.nairda wrote:Which gives me: "warning cannot find entry symbol, defaulting to 000008048078"
This should work:
Code: Select all
ld -e start -oformat binary -o [b]the filename you wants[/b] kmain.o k_init.o
I assume that your boot sector loads contiguous sectors from the disk into memory. In this case, simply concatenate the bootloader "boot.bin" and the kernel, to generate a third binary file. This binary file must then be written in the first sector of a floppy disk.nairda wrote:What do I do now? How do I combine the bootloader (boot binary) with the C kernel?
nairda wrote:How do I get it to load in qemu?
Code: Select all
qemu -fda /dev/fda -m 32
"Open source seems to embrace the dark side of human nature." - Ville Turjanmaa
Re: Xosdev tutorial mr. xsism - getting it running
Thanks for the reply.
Sorry, I should have mentioned I don't actually have a floppy disk drive, so how can I create an image qemu can boot from?
I now have two more steps as you have suggested:
ld -e start --oformat binary -o kernel kmain.o k_init.o
cat boot kernel > os.bin
(loading os.bin in qemu again, does very little)
Sorry, I should have mentioned I don't actually have a floppy disk drive, so how can I create an image qemu can boot from?
I now have two more steps as you have suggested:
ld -e start --oformat binary -o kernel kmain.o k_init.o
cat boot kernel > os.bin
(loading os.bin in qemu again, does very little)
Re: Xosdev tutorial mr. xsism - getting it running
You can generate a floppy image using both cat and dd commands:
And you can boot this floppy image with qemu using this command:
Code: Select all
cat os.bin /dev/zero | dd of=floppy.img bs=1k count=1440
Code: Select all
qemu -fda floppy.img -m 32
"Open source seems to embrace the dark side of human nature." - Ville Turjanmaa
Re: Xosdev tutorial mr. xsism - getting it running
Thanks for all your help Tommy.
qemu trys to load the floppy disk now but says 'not a bootable disk'...
I'm not sure what the problem is. I googled a bit, and tried dd with bs=512 and count=2880, and I modified the GCC command to include '-fnobuiltin -nostdinc -fomit-frame-pointer' , but these have all had no effect...
Does anyone know what else needs to be done? Has anyone else had success in getting the Xosdev tutorial code working?
qemu trys to load the floppy disk now but says 'not a bootable disk'...
I'm not sure what the problem is. I googled a bit, and tried dd with bs=512 and count=2880, and I modified the GCC command to include '-fnobuiltin -nostdinc -fomit-frame-pointer' , but these have all had no effect...
Does anyone know what else needs to be done? Has anyone else had success in getting the Xosdev tutorial code working?
Re: Xosdev tutorial mr. xsism - getting it running
Sorry, I missed a step in my build process. (The cat > osbin) now qemu will infact load and presumably try and boot the image, but qemu just crashes straight away. Does anyone know what might be causing this?
(It says 'fatal, trying to execute code outside RAM or ROM at 0x8ec03100)
(It says 'fatal, trying to execute code outside RAM or ROM at 0x8ec03100)
Re: Xosdev tutorial mr. xsism - getting it running
There should probably have an error in your code. If you do not know where it came from, post it here!nairda wrote:Sorry, I missed a step in my build process. (The cat > osbin) now qemu will infact load and presumably try and boot the image, but qemu just crashes straight away. Does anyone know what might be causing this?
I (or someone else) could help you!
"Open source seems to embrace the dark side of human nature." - Ville Turjanmaa
Re: Xosdev tutorial mr. xsism - getting it running
Ok, here we go, it is the code from the Xosdev tutorial, unmodified, plus a 'go' script.
If anyone can get it going I'd greatly appreciate it!
Attached the file, it is a .tgz, but I had to rename it a couple of times to get the forums to accept it.. whatever format you download in, please rename it back to ".tgz"
If anyone can get it going I'd greatly appreciate it!
Attached the file, it is a .tgz, but I had to rename it a couple of times to get the forums to accept it.. whatever format you download in, please rename it back to ".tgz"
- Attachments
-
- xosdev.zip
- (4.47 KiB) Downloaded 111 times
Re: Xosdev tutorial mr. xsism - getting it running
Code: Select all
mov ax,0xffff
mov es,ax ; Data buffer for file
mov bx,0x10 ; Start of segment
mov ah,2 ; Function to read disk
mov al,17 ; Total sectors to read
mov ch,0 ; Track
mov cl,2 ; Sector
mov dh,0 ; Head | Drive is already loaded
int 0x13 ; Call BIOS read disk function
jc read ; motor error, try again
1) load the kernel first in a lower address (for example 0x10000),
2) switch to 32-bit protected-mode,
3) move the kernel at address 0x100000.
4) jump to this address.
EDIT: I saw that there is a "link.ld" script. In this case, add this to this script:
Code: Select all
OUTPUT_FORMAT(binary);
Code: Select all
ld -T link.ld -o kernel kmain.o k_init.o
"Open source seems to embrace the dark side of human nature." - Ville Turjanmaa
Re: Xosdev tutorial mr. xsism - getting it running
Hi Tommy,
Thanks for pointing that out, I tried making the changes to make it work, but with no luck. (strange that the tutorial has errors in it..) I'm still trying to understand what everything does..
The changes I've made:
added link.ld to the go script
link.ld, added the output binary as you said, set text to 0x1000
changed lines 159+ to:
mov ax, 0x0
mov es,ax
mov bx,0x1000
I did not change the second set of reads since I have no idea what that is for..
then I changed line 227 to:
jmp CODESEL:0x1000
this still results in the same error as before. Is there anything else that needs changing?
PS: I added the link.ld from some other googling... but didn't include it, since it made no difference..
Thanks for pointing that out, I tried making the changes to make it work, but with no luck. (strange that the tutorial has errors in it..) I'm still trying to understand what everything does..
The changes I've made:
added link.ld to the go script
link.ld, added the output binary as you said, set text to 0x1000
changed lines 159+ to:
mov ax, 0x0
mov es,ax
mov bx,0x1000
I did not change the second set of reads since I have no idea what that is for..
then I changed line 227 to:
jmp CODESEL:0x1000
this still results in the same error as before. Is there anything else that needs changing?
PS: I added the link.ld from some other googling... but didn't include it, since it made no difference..
Re: Xosdev tutorial mr. xsism - getting it running
If you do not know what for, remove these lines.nairda wrote:I did not change the second set of reads since I have no idea what that is for..
In this case, put this in your "go" script:nairda wrote:I added the link.ld from some other googling... but didn't include it, since it made no difference..
Code: Select all
ld -Ttext <the address of your kernel>-e start -oformat binary -o <the filename you wants> kmain.o k_init.o
Code: Select all
[bits 16]
[org 0x7c00]
.....
mov ax,cs ; setup ds segment
mov ds,ax
mov es,ax
mov fs,ax
mov ss,ax ; align stack also
mov sp,0x200 ; 512 byte stack
I suggess you this code:
Code: Select all
boot:
jmp 0x0000:init ; Some BIOSes jump to 0x7c0:0x0 rather than 0x0:0x7c0
init:
mov [drive],dl ; save boot drive number(0x00=floppy 0x80=hard drive)
xor ax,ax ; setup ds segment
mov ds,ax
mov es,ax
mov fs,ax
mov ss,ax ; align stack also
mov sp,0x7C00 ; put the stack before the boot sector.
"Open source seems to embrace the dark side of human nature." - Ville Turjanmaa
Re: Xosdev tutorial mr. xsism - getting it running
I made the changes you suggested, using the link.ld script qemu doesn't crash but keeps rebooting. If I don't use the link.ld script, qemu crashes.
Do you have it working on your PC? I'm thinking of trying a different tutorial since this tutorial seems to have a lot of mistakes. (Maybe this one: http://www.osdever.net/tutorials/brunma ... ial_03.php)
Do you have it working on your PC? I'm thinking of trying a different tutorial since this tutorial seems to have a lot of mistakes. (Maybe this one: http://www.osdever.net/tutorials/brunma ... ial_03.php)
Re: Xosdev tutorial mr. xsism - getting it running
I noticed that the file "kernel" that you provided contains no code, just the string "Kernel loaded".
I also noticed that you do not define a .text section in "k_init.asm". Also use "elf32" format instead of the obsolete "aout".
I also noticed that you do not define a .text section in "k_init.asm". Also use "elf32" format instead of the obsolete "aout".
Yes! Also try this: http://osdever.net/bkerndev/Docs/title.htm.nairda wrote:Maybe this one: http://www.osdever.net/tutorials/brunma ... ial_03.php
"Open source seems to embrace the dark side of human nature." - Ville Turjanmaa
- gravaera
- Member
- Posts: 737
- Joined: Tue Jun 02, 2009 4:35 pm
- Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.
Re: Xosdev tutorial mr. xsism - getting it running
To be perfectly honest, I was surprised this thread wasn't closed down.
Hi, there: You can find workable files for reference in the Bare Bones tutorial. Use them for a boost while you go on reading, and reading, and doing yet more reading..
Actually, you'll find that large parts of your initial journey into OSDev are just nothing more than long, interesting periods of reading, and searching for useful information. After you've got the basics down, then you can ask questions.
OSDev isn't going to be an easy, step by step process, and at a certain point, you'll have nothing but various technical documents (specifications, data sheets) that will be your only help. You'll be reading full time then. So you should get used to reading.
Hi, there: You can find workable files for reference in the Bare Bones tutorial. Use them for a boost while you go on reading, and reading, and doing yet more reading..
Actually, you'll find that large parts of your initial journey into OSDev are just nothing more than long, interesting periods of reading, and searching for useful information. After you've got the basics down, then you can ask questions.
OSDev isn't going to be an easy, step by step process, and at a certain point, you'll have nothing but various technical documents (specifications, data sheets) that will be your only help. You'll be reading full time then. So you should get used to reading.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
Re: Xosdev tutorial mr. xsism - getting it running
Hi guys. I'm sure this is a dead topic, but the xosdev tutorial that I wrote was reviewed by other coders and tested to be working. looking over it though, there are some typos, missing content, and other inconsistencies. I had planned to write a complete series on osdev with the xosdev tutorials, but as you see I barely got through the 2nc chapter.
Just a note, the bootloader code in chapter 1 puts the stack at 0x1D00 - 0x1F00. The following code does this:
So anything else that was mentioned in this thread about putting it in the IVT is not my doing.
I've been away from osdev fro at least 3 years now. It's amazing how much you lose when you don't use it. I'd like to revise the xosdev tutorials and make sure they're working properly with current compilers and on a current emulator like bochs.
Sorry for any confusion caused by the tutorial. It'll be addressed soon I hope.
Just a note, the bootloader code in chapter 1 puts the stack at 0x1D00 - 0x1F00. The following code does this:
Code: Select all
mov ax,0x1D0 ; stack is at 0x1D00
mov ss,ax ; align stack also
mov sp,0x200 ; 512 byte stack
I've been away from osdev fro at least 3 years now. It's amazing how much you lose when you don't use it. I'd like to revise the xosdev tutorials and make sure they're working properly with current compilers and on a current emulator like bochs.
Sorry for any confusion caused by the tutorial. It'll be addressed soon I hope.