Cross Compilier problem
Cross Compilier problem
Hey everyone,
After some issues with setting up my OSs kernel, I have decided to give a cross compilier a shot.
I am using GCC, running in Cygwin on a WinXP SP2 machine.
Does the cross compilier run in a script (Like a batch program)? I created a *.sh file for Cygwin, containing a simple "dir" command.
It seems like my Cygwin batch files are not effecting anything within
Cygwin (Current directory never changes), which is making it impossible
for me to develope a cross compilier.
I could execute a "dir" command directly within Cygwin, but not within
the batch file!
I know its probably something simple, but I do not have much exp with
Linux command line.
Does anyone have any suggestions?
Thanks!
After some issues with setting up my OSs kernel, I have decided to give a cross compilier a shot.
I am using GCC, running in Cygwin on a WinXP SP2 machine.
Does the cross compilier run in a script (Like a batch program)? I created a *.sh file for Cygwin, containing a simple "dir" command.
It seems like my Cygwin batch files are not effecting anything within
Cygwin (Current directory never changes), which is making it impossible
for me to develope a cross compilier.
I could execute a "dir" command directly within Cygwin, but not within
the batch file!
I know its probably something simple, but I do not have much exp with
Linux command line.
Does anyone have any suggestions?
Thanks!
I can only suggest, at this stage, that you read the following document:
http://www.osdev.org/wiki/GCC_Cross-Compiler
It is a comprehensive guide to compiling a cross-compiler on cygwin.
http://www.osdev.org/wiki/GCC_Cross-Compiler
It is a comprehensive guide to compiling a cross-compiler on cygwin.
The cake is a lie | rackbits.com
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Im setting up a 2 stage bootloader (to fix a previous issue with C routines)
I seem to be having a small issue with my linker script though. My
bootloader enters pmode fine, then I attempt to jump to my 2nd stage
loader:
Keep in mind, I load my kernel at 0x1000, and Im using NASM with
DJGPP. Also, The bootloader is in pmode.
My 2nd stage is in another source file (Stage2.asm):
How would I insure _Stage2 is loaded at 0x1000? My linker (ld)
is giving me the error "Cannot find entry symbol '_Stage2' "
Here is the linker script Im using:
Im not worried about the .rodata section yet, until Im able to jump to
my C kernel's main() routine.
Here is the command line..
Does anyone know what could cause this? The exact error I get is
(Okay its a warning, not an error--Its still a big problem though)
Thanks alot for any help!
I seem to be having a small issue with my linker script though. My
bootloader enters pmode fine, then I attempt to jump to my 2nd stage
loader:
Code: Select all
jmp 08h:1000h
DJGPP. Also, The bootloader is in pmode.
My 2nd stage is in another source file (Stage2.asm):
Code: Select all
[BITS 32]
extern _main
global _Stage2
_Stage2:
hlt
call _main
is giving me the error "Cannot find entry symbol '_Stage2' "
Here is the linker script Im using:
Code: Select all
ENTRY(_Stage2)
OUTPUT_FORMAT("binary")
SECTIONS
{
.text 0x1000 :
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data :
{
data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
my C kernel's main() routine.
Here is the command line..
Code: Select all
nasm -f bin BOOT.asm -o BOOT.bin
nasm -f elf Stage2.asm -o Stage2.o
// Compile main C kernel
gcc -ffreestanding -nostdlib -nostartfiles -fno-builtin -c -o Main.o Main.c
// Link the C kernel with 2nd stage loader
ld Link.ld -c KERNEL.o Main.o Stage2.o
objcopy -R .note -R .comment -S -O binary KERNEL.o KERNEL.bin
makeboot Floppy.img BOOT.bin KERNEL.o
Code: Select all
c:/djgpp/bin/ld.exe: warning: cannot find entry symbol _Stage2; defaulting to 000018
Thanks alot for any help!
It is calling main() just fine right now, but I am still getting that warning
(Weird)
Unfortanly, Im back with a problem (That I was hoping to solve). I am
unable to define any routine before main.
This works just fine (In my kernel):
As soon as I define a routine before main, my kernel triple faults:
What am I doing wrong?
This is one of the issues that stopped my OS development before..
I want to add on that defining a routine after main works. It only
triple faults when it is before main.
(Weird)
Unfortanly, Im back with a problem (That I was hoping to solve). I am
unable to define any routine before main.
This works just fine (In my kernel):
Code: Select all
void main () {
__asm ("hlt");
}
Code: Select all
void foo () {}
void main () {
__asm ("hlt");
}
This is one of the issues that stopped my OS development before..
I want to add on that defining a routine after main works. It only
triple faults when it is before main.
Last edited by neon on Sun Mar 18, 2007 6:23 pm, edited 1 time in total.
Here is the output from Bosch:
I am suspected why IP would be 3 though..
Code: Select all
00000003740i[BIOS ] $Revision: 1.166 $ $Date: 2006/08/11 17:34:12 $
00000317563i[KBD ] reset-disable command received
00000318691i[PIDE ] new BM-DMA address: 0xc000
00000450000i[WGUI ] dimension update x=720 y=400 fontheight=16 fontwidth=9 bpp=8
00004462070i[CPU0 ] LOCK prefix unallowed (op1=0x53, attr=0x0, mod=0x0, nnn=0)
00004462070e[CPU0 ] interrupt(): gate descriptor is not valid sys seg
00004462070e[CPU0 ] interrupt(): gate descriptor is not valid sys seg
00004462070i[CPU0 ] protected mode
00004462070i[CPU0 ] CS.d_b = 32 bit
00004462070i[CPU0 ] SS.d_b = 32 bit
00004462070i[CPU0 ] | EAX=00000000 EBX=00001000 ECX=00000002 EDX=000003f2
00004462070i[CPU0 ] | ESP=00090000 EBP=00000000 ESI=00007cbc EDI=0000ffde
00004462070i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf SF zf af pf cf
00004462070i[CPU0 ] | SEG selector base limit G D
00004462070i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00004462070i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00004462070i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00004462070i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00004462070i[CPU0 ] | ES:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00004462070i[CPU0 ] | FS:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00004462070i[CPU0 ] | GS:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00004462070i[CPU0 ] | EIP=00000003 (00000003)
00004462070i[CPU0 ] | CR0=0x00000011 CR1=0 CR2=0x00000000
00004462070i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00004462070i[CPU0 ] >> lock push ebx : F053
00004462070e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
I (think) the warning is being caused by the underscore. The GCC cross compiler doesn't prefix underscores to the beginning of function names. That warning is telling you it can't find the function you are calling and is defaulting.
The cake is a lie | rackbits.com
I tried it with and without underscores...
Still get the same warning though...
I wonder, how can my kernel still boot up (and run) successfully if it
is being loaded at the wrong address? o.0
Any ideas?
My second stage loader is loaded at 0x1000..
Of course, I am still unable to define routines before main (Triple fault).
Mabey _main is being loaded at 0x1000? (Dont see how though..)
Code: Select all
stage2
_stage2
__stage2
___stage2
____stage2 -I actually tried this :)
I wonder, how can my kernel still boot up (and run) successfully if it
is being loaded at the wrong address? o.0
Any ideas?
My second stage loader is loaded at 0x1000..
Of course, I am still unable to define routines before main (Triple fault).
Mabey _main is being loaded at 0x1000? (Dont see how though..)
Code: Select all
c:/djgpp/bin/ld.exe: warning: cannot find entry symbol Stage2; defaulting to 000018f8
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Okay, from what I read, your problem isn't what you think it is...
When LD links and can't find the symbol, it sets a default value for the entry point. Usually it's correct, but sometimes it's not (triple fault would happen then).
The warning says that it can't find Stage2, NOT stage2. IIRC, C is case-sensitive, which means that Stage2 is very different from stage2. Try renaming, in your C file, stage2 to Stage2, or in your linker script (or whatever you use) change Stage2 to stage2.
Try my idea, prove me wrong, please
.
When LD links and can't find the symbol, it sets a default value for the entry point. Usually it's correct, but sometimes it's not (triple fault would happen then).
The warning says that it can't find Stage2, NOT stage2. IIRC, C is case-sensitive, which means that Stage2 is very different from stage2. Try renaming, in your C file, stage2 to Stage2, or in your linker script (or whatever you use) change Stage2 to stage2.
Try my idea, prove me wrong, please
![Very Happy :D](./images/smilies/icon_biggrin.gif)
Actually, I written it wrong in my post.. (Sorry)
I did use Stage2 and stage2 varants, and still doesnt work.
I should let you know, _Stage2 is defined in an Assembly file, not
a C source file. Mabey Im linking it wrong?
Here is Stage2.asm:
My bootloader goes into pmode, sets up the stack, and jumps
to 08h:1000h (Where it loads my 2nd stage at)
This is when _Stage2 (Supposed) to take over, and call _main()
Heres my command line:
Do you see any problem in the way I link? (Or something else?)
I tried both COFF and ELF formats when linking, but same problem..
Thanks for the help!
I did use Stage2 and stage2 varants, and still doesnt work.
I should let you know, _Stage2 is defined in an Assembly file, not
a C source file. Mabey Im linking it wrong?
Here is Stage2.asm:
Code: Select all
; We should be in pmode, so insure code is 32bit
[BITS 32]
extern _main
global _Stage2
; --------------------------------- Second stage loader
_Stage2:
; might need to setup stack here
; Give control to kernel
call _main
cli ; Should never get here
hlt
to 08h:1000h (Where it loads my 2nd stage at)
This is when _Stage2 (Supposed) to take over, and call _main()
Heres my command line:
Code: Select all
nasm -f bin BOOT.asm -o BOOT.bin
nasm -f elf Stage2.asm -o Stage2.o <<<< _Stage2 links here
// Compile main C kernel
gcc -ffreestanding -nostdlib -nostartfiles -fno-builtin -c -o Main.o Main.c
// Link the C kernel with 2nd stage loader
ld Link.ld -c KERNEL.o Main.o Stage2.o
objcopy -R .note -R .comment -S -O binary KERNEL.o KERNEL.bin
makeboot Floppy.img BOOT.bin KERNEL.o
I tried both COFF and ELF formats when linking, but same problem..
Thanks for the help!