Cross-compiler issue (possibly)

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
bean601
Posts: 5
Joined: Tue Oct 14, 2008 12:31 pm
Location: Ohio, USA

Cross-compiler issue (possibly)

Post by bean601 »

Hello everyone, first post on this site :)

I've been programming for a decade now, but never did anything low level and thought it would be a good learning experience.

I'm using Cygwin and just made my cross-compiler with gcc-4.2.4 and binutils-2.18. That worked fine, but I'm still having the grub error 18. Which is the reason I created the cross compiler. Having searched for help on the boards I figured it was time to make a post.

I am using the bare bones tutorial files and code, everything works with no problem (with the i586-elf-gcc and i586-elf-ld of course)


Here is my grub output-

grub> kernel 200+18

Error 13: Invalid or unsupported executable format

Here is the bochs output-

00008023335i[BIOS ] Booting from 0000:7c00
00012720441i[BIOS ] int13_harddisk: function 41, unmapped device for ELDL=80
00012725222i[BIOS ] int13_harddisk: function 08, unmapped device for ELDL=80
00012729879i[BIOS ] *** int 15h function AX=00c0, BX=0000 not yet supported!
00102728573i[FDD ] partial read() on floppy image returns 236/512
00102751306i[FDD ] read() on floppy image returns 0
00102774039i[FDD ] read() on floppy image returns 0
00102796772i[FDD ] read() on floppy image returns 0
00102819505i[FDD ] read() on floppy image returns 0
00102842238i[FDD ] read() on floppy image returns 0
00102864971i[FDD ] read() on floppy image returns 0

Did I mess up somewhere? Need more information?

Thanks in advance! :D
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Cross-compiler issue (possibly)

Post by Combuster »

You seem to have a broken floppy image. Check that it is indeed 1.4M in size like it should

Not quite a cross-compiler thing :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
bean601
Posts: 5
Joined: Tue Oct 14, 2008 12:31 pm
Location: Ohio, USA

Re: Cross-compiler issue (possibly)

Post by bean601 »

Ah, its only 103k. Is there a good way to append to the end of an image?
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: Cross-compiler issue (possibly)

Post by ~ »

Would be better to find a functional floppy disk and read it using sometining like RawWrite to create an 1.44M image of it.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Cross-compiler issue (possibly)

Post by Combuster »

You can, but you'd only be making a broken image look correct. GRUB is still reading where it can't find data, and if you append zeroes, GRUB will still not find the data because there is none.

Its probably better that you download a precompiled FAT+GRUB image, then use an image tool (like mtools) to copy your kernel over
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
bean601
Posts: 5
Joined: Tue Oct 14, 2008 12:31 pm
Location: Ohio, USA

Re: Cross-compiler issue (possibly)

Post by bean601 »

Excellent, thank you. I'm not sure I understand entirely if I get an image an copy my kernel over, will I be able to specify the sector (with mtools for example), or how does that work? I'm thinking what to do as the kernel size gets larger, do I just keep overwriting that?

Thanks
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Cross-compiler issue (possibly)

Post by Combuster »

The whole point of having a filesystem is that you never need to tell anything about sector numbers - just the filename
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
bean601
Posts: 5
Joined: Tue Oct 14, 2008 12:31 pm
Location: Ohio, USA

Re: Cross-compiler issue (possibly)

Post by bean601 »

So once I get the image, I can just dd the files over?

Thanks again for your help, sorry if it was n00bish stuff.
User avatar
Velko
Member
Member
Posts: 153
Joined: Fri Oct 03, 2008 4:13 am
Location: Ogre, Latvia, EU

Re: Cross-compiler issue (possibly)

Post by Velko »

bean601 wrote:So once I get the image, I can just dd the files over?
No. You mount the image (make it to look as a virtual disk for your host OS), then copy files into it.
If something looks overcomplicated, most likely it is.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Cross-compiler issue (possibly)

Post by egos »

I propose to do the reverse actions:

1) get the files which will placed on the floppy:
kernel.bin
menu.lst
stage1
stage2
2) take my fasm sources for making floppy image:
floppy.asc
mkfloppy.inc
3) compile this sources to get the floppy image and write it on the floppy if necessary.

Source file of kernel.bin:

Code: Select all

MBH_MAGIC equ 0x1BADB002
MBH_FLAGS equ 0x10000

  use32

  org 0x100000
load_addr:
header_addr:
  dd MBH_MAGIC
  dd MBH_FLAGS
  dd -MBH_MAGIC-MBH_FLAGS
  dd header_addr
  dd load_addr
  dd load_end_addr
  dd bss_end_addr
  dd entry_addr

entry_addr:
  jmp $

load_end_addr:

bss_end_addr:
menu.lst

Code: Select all

color light-gray/blue black/light-gray

default 0
timeout 10

title Load kernel from floppy (variant 1)
root (fd0)
kernel /kernel.bin

title Load kernel from floppy (variant 2)
kernel (fd0)/kernel.bin
floppy.asc

Code: Select all

include "mkfloppy.inc"

file "stage1", 3
db "MKFLOPPY"
dw 512
db 1
dw 1
db 2
dw 14*512/32
dw 2*80*18
db 0F0h
dw 9
dw 18
dw 2
dd 0
dd 0
db 0
db 0
db 29h
dd 55555555h
db "BOOTABLEDEV"
db "FAT12", 32, 32, 32
file "stage1": $, 512-$

; store byte 0 at 40h ; boot_drive cell for GRUB 1.90
store word 8000h at 42h ; kernel_address cell for GRUB 1.90
store dword stage2_base/512 at 44h ; kernel_sector cell for GRUB 1.90
store word 800h at 48h ; kernel_segment cell for GRUB 1.90

; fat1
db 0F0h, 0FFh, 0FFh, 9*512-3 dup 0

; fat2
db 0F0h, 0FFh, 0FFh, 9*512-3 dup 0

; root
dent kernel, "KERNEL  BIN", FA_ARC
dent boot, "BOOT", FA_DIR
; ...
rb 33*512-$

defdir boot
{
dent grub, "GRUB", FA_DIR
}

defdir grub
{
dent menu, "MENU    LST", FA_ARC
dent stage2, "STAGE2", FA_ARC
}

; data
stof kernel, "kernel.bin"
stod boot, root
stod grub, boot
stof menu, "menu.lst"
stof stage2, "stage2"
store dword stage2_base/512+1 at stage2_base+1F8h
store word (stage2_size+511)/512-1 at stage2_base+1FCh
store word 820h at stage2_base+1FEh
; ...
rb 2*80*18*512-$
mkfloppy.inc - use search on the forum.
If you have seen bad English in my words, tell me what's wrong, please.
bean601
Posts: 5
Joined: Tue Oct 14, 2008 12:31 pm
Location: Ohio, USA

Re: Cross-compiler issue (possibly)

Post by bean601 »

Thank you both for your help. I was having trouble making a loopback device (cygwin) so I did go the route with the physical disk.

A simple example of this process is in John Mcdougall's tutorial http://membres.lycos.fr/preludesoftware/osdev.doc (OS Development on Windows) and I would recommend it to those having trouble setting up an environment on Windows.

Thanks again, look forward to talking to you all more as I get deeper into this!
Post Reply