Xosdev tutorial mr. xsism - getting it running

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
nairda
Posts: 7
Joined: Wed Jul 08, 2009 2:31 am

Xosdev tutorial mr. xsism - getting it running

Post by nairda »

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!
User avatar
f2
Member
Member
Posts: 311
Joined: Mon Jun 15, 2009 10:01 am
Location: France

Re: Xosdev tutorial mr. xsism - getting it running

Post by f2 »

nairda wrote:Which gives me: "warning cannot find entry symbol, defaulting to 000008048078"
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.
This should work:

Code: Select all

ld -e start -oformat binary -o [b]the filename you wants[/b] kmain.o k_init.o
nairda wrote:What do I do now? How do I combine the bootloader (boot binary) with the C kernel?
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: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
nairda
Posts: 7
Joined: Wed Jul 08, 2009 2:31 am

Re: Xosdev tutorial mr. xsism - getting it running

Post by nairda »

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)
User avatar
f2
Member
Member
Posts: 311
Joined: Mon Jun 15, 2009 10:01 am
Location: France

Re: Xosdev tutorial mr. xsism - getting it running

Post by f2 »

You can generate a floppy image using both cat and dd commands:

Code: Select all

cat os.bin /dev/zero | dd of=floppy.img bs=1k count=1440
And you can boot this floppy image with qemu using this command:

Code: Select all

qemu -fda floppy.img -m 32
"Open source seems to embrace the dark side of human nature." - Ville Turjanmaa
nairda
Posts: 7
Joined: Wed Jul 08, 2009 2:31 am

Re: Xosdev tutorial mr. xsism - getting it running

Post by nairda »

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?
nairda
Posts: 7
Joined: Wed Jul 08, 2009 2:31 am

Re: Xosdev tutorial mr. xsism - getting it running

Post by nairda »

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)
User avatar
f2
Member
Member
Posts: 311
Joined: Mon Jun 15, 2009 10:01 am
Location: France

Re: Xosdev tutorial mr. xsism - getting it running

Post by f2 »

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?
There should probably have an error in your code. If you do not know where it came from, post it here!
I (or someone else) could help you!
"Open source seems to embrace the dark side of human nature." - Ville Turjanmaa
nairda
Posts: 7
Joined: Wed Jul 08, 2009 2:31 am

Re: Xosdev tutorial mr. xsism - getting it running

Post by nairda »

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"
Attachments
xosdev.zip
(4.47 KiB) Downloaded 111 times
User avatar
f2
Member
Member
Posts: 311
Joined: Mon Jun 15, 2009 10:01 am
Location: France

Re: Xosdev tutorial mr. xsism - getting it running

Post by f2 »

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
:shock: You load your kernel at address 0x100000 in real mode! In real mode, you can not access more than 1 MB of memory (0 to 0FFFFFh). If you really want to load your kernel at this address:
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);
and in your "go" script, put this:

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
nairda
Posts: 7
Joined: Wed Jul 08, 2009 2:31 am

Re: Xosdev tutorial mr. xsism - getting it running

Post by nairda »

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..
User avatar
f2
Member
Member
Posts: 311
Joined: Mon Jun 15, 2009 10:01 am
Location: France

Re: Xosdev tutorial mr. xsism - getting it running

Post by f2 »

nairda wrote:I did not change the second set of reads since I have no idea what that is for..
If you do not know what for, remove these lines.
nairda wrote:I added the link.ld from some other googling... but didn't include it, since it made no difference..
In this case, put this in your "go" script:

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
:shock: :shock: I had not seen this one: "mov sp, 0x200". By placing the stack at 0000:0200, you breaks the IVT. Use a different address.
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
nairda
Posts: 7
Joined: Wed Jul 08, 2009 2:31 am

Re: Xosdev tutorial mr. xsism - getting it running

Post by nairda »

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)
User avatar
f2
Member
Member
Posts: 311
Joined: Mon Jun 15, 2009 10:01 am
Location: France

Re: Xosdev tutorial mr. xsism - getting it running

Post by f2 »

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".
Yes! Also try this: http://osdever.net/bkerndev/Docs/title.htm.
"Open source seems to embrace the dark side of human nature." - Ville Turjanmaa
User avatar
gravaera
Member
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

Post by gravaera »

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.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
Brenden
Posts: 2
Joined: Fri May 22, 2009 10:35 pm

Re: Xosdev tutorial mr. xsism - getting it running

Post by Brenden »

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:

Code: Select all

mov ax,0x1D0               ; stack is at 0x1D00
mov ss,ax                  ; align stack also
mov sp,0x200               ; 512 byte stack
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.
Post Reply