Page 2 of 2

Posted: Wed Mar 21, 2007 12:26 am
by pcmattman
LD still can't find the symbol.

In your linker script, set the entry point to _Stage2...

KEEP the underscore on everything in the linker because it's not going to work if you use C-names with it.

Try "_Stage2" and see what happens.

Posted: Wed Mar 21, 2007 5:49 pm
by neon
Same problem...

Code: Select all

c:/djgpp/bin/ld.exe: warning: cannot find entry symbol _Stage2; defaulting to 000018f8

Posted: Wed Mar 21, 2007 5:54 pm
by neon
Heres the symbol table for KERNEL.o:

Code: Select all

C:\djgpp\MicroOS_Main\Kernel\KERNEL.o:     file format coff-go32-exe

SYMBOL TABLE:
[  0](sec -2)(fl 0x00)(ty   0)(scl 103) (nx 1) 0x00000016 Main.c
File
[  2](sec  2)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00002000 __xPos
[  3](sec  2)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00002004 __yPos
[  4](sec  2)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00002008 LC0
[  5](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x0000193c __clrscr
[  6](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00001a3c __printf
[  7](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00001936 __Die
[  8](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00001956 L5
[  9](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00001961 L8
[ 10](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00001980 L6
[ 11](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00001996 __putch
[ 12](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x000019b7 L11
[ 13](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x000019dc L10
[ 14](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00001a3a L9
[ 15](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00001a70 __gotoxy
[ 16](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00001a80 L16
[ 17](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00001a8d L17
[ 18](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00001a9a L18
[ 19](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00001aa7 L19
[ 20](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00001900 .text
[ 21](sec  2)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00002000 .data
[ 22](sec -2)(fl 0x00)(ty   0)(scl 103) (nx 1) 0x0000001b ..\MicroOS_Mai
File
[ 24](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00001ac0 .text
AUX scnlen 0x7 nreloc 1 nlnno 0
[ 26](sec -1)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .absolut
[ 27](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00002000 djgpp_first_dtor
[ 28](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00002000 djgpp_last_ctor
[ 29](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00002000 djgpp_last_dtor
[ 30](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00002010 edata
[ 31](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00002000 djgpp_first_ctor
[ 32](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 _Stage2
[ 33](sec  4)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00003000 _rodata
[ 34](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00001930 _foo
[ 35](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00003000 end
[ 36](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00001ac7 etext
[ 37](sec  3)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00003000 _bss
[ 38](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00003000 __end
[ 39](sec  3)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00003000 bss
[ 40](sec  4)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00003000 __rodata
[ 41](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00002200 data
[ 42](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x0000200c ___EH_FRAME_BEGIN__
[ 43](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00002200 __data
[ 44](sec  3)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00003000 __bss
[ 45](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00002200 _data
[ 46](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00003000 _end
[ 47](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00001c00 code
[ 48](sec  4)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00003000 rodata
[ 49](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00001c00 __code
[ 50](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00001c00 _code
[ 51](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x0000200c ___EH_FRAME_END__
[ 52](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00001900 _main
As you can see, _Stage2 is there. ...Why cant LD see it?

Posted: Wed Mar 21, 2007 7:37 pm
by Brynet-Inc
Man those underscores are annoying ;)..

Why don't you just setup a cross-compiler already? I'm starting to think you might need it.. :wink:

Posted: Wed Mar 21, 2007 7:59 pm
by neon
I tried numerous times, but same problems...

I know others were able to build a kernel using DJGPP on these
forums, hence I decided to give DJGPP a try :)

And, yes I know about the underscores :)

Posted: Wed Mar 21, 2007 8:16 pm
by pcmattman
I use DJGPP, and I have no problems whatsoever.

I think that if you change the entry point from _Stage2 to 0x00000000 it might just work.

Otherwise, I'm stumped. Unless of course the output format from GCC is not supported?

Posted: Wed Mar 21, 2007 8:30 pm
by neon
I think that if you change the entry point from _Stage2 to 0x00000000 it might just work.
After setting it, I dont get the warning anymore :D

_Stage2 doesnt get executed though...

The basic problem here I am trying to solve is defining routines
before main. I could define it after just fine, before main, it triple faults.

I learned through these forums a common solution is creating an assembly
stub (In my case its _Stage2). This is what I am trying to accomplish.

I suspect that _main is being loaded at 0x1000 (Not _Stage2), as the
kernel does execute.

Heres _Stage2 as of now:

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
	hlt
	call	_main
	cli									; Should never get here
	hlt
If _Stage2 was loaded at 0x1000 (This is all I want!) the first hlt
instruction should have been executed (It wasnt though)

My kernel runs fine, which tells me _main() is being executed just fine...

What versions of GCC and LD do you have?
Do you have a download link?

I have gcc v. 3.1, and LD v. 2.11.2. After noticing my LD doesnt
support the -i option, I am suspecting its my version of DJGPP..

Posted: Wed Mar 21, 2007 8:36 pm
by pcmattman
Ok... first you will need to setup a stack. That's pretty simple (just look at the BareBones loader).

And have you checked that you are actually linking in the object file that comes from assembling your loader, AND that it's in the same format as all the other objects?

Posted: Wed Mar 21, 2007 8:49 pm
by neon
I set the stack in my bootloader:

Code: Select all

;------------------------------------------ Enter: Protected Mode ---------

[BITS 32]

EnterStage2:

; setup 32bit registers

	mov		ax, 10h
	mov		ds, ax
	mov		ss, ax
	mov		esp, 90000h			; stack begins from 90000h

; stop floppy drive controller

	xor		al, al
	mov		dx, 03f2h			; port number
	out		dx, al

; jump to second stage bootloader (0:01000h)

	jmp		08h:1000h
I am currently assembling my bootloader with binary output:

Code: Select all

nasm -f bin BOOT.asm -o BOOT.bin
Then I assembled my Stage2 (Asm stub) with COFF format:
(I should note I have also tried ELF format, but same problems..)

Code: Select all

nasm -f coff Stage2.asm -o Stage2.o
Next I compilie my C kernel:

Code: Select all

gcc -ffreestanding -nostdlib -nostartfiles -fwritable-strings -c -o Main.o Main.c
Then link the kernel with Stage2 to produce KERNEL:

Code: Select all

ld Link.ld -o KERNEL.o Main.o Stage2.o
Then objcopy:

Code: Select all

objcopy -R .note -R .comment -S -O binary KERNEL.o KERNEL.bin
Then I combine my BOOT.bin with KERNEL.bin to produce an image:

Code: Select all

makeboot Floppy.img BOOT.bin KERNEL.bin
I am posting this so you know what I was doing (and thinking).
And to see if there could be problems with my setup.

(I am going to look through that tutorial, and see if I can find anything)

Posted: Wed Mar 21, 2007 8:53 pm
by pcmattman
Stage2.o should be linked first because it's the one containing the entry point.

Posted: Wed Mar 21, 2007 8:59 pm
by neon
Stage2.o should be linked first because it's the one containing the entry point.
lol!

I have just thought that when I was looking at my post, tried it,
and it works! _Stage2 is being executed, and I can now define
routines before main!!

(It litterally took about 2months, and all I had to do was a simple
swap! Sheesh!)--Makes me look bad :D

Thanks to everyone SO much!! :D

I am going to see if my pointers/strings are still missed up now...

Posted: Wed Mar 21, 2007 9:01 pm
by pcmattman
Good to hear, now I really hope your pointers and strings work now! I remember taking a month to figure out something as simple as that.

Posted: Wed Mar 21, 2007 9:02 pm
by neon
...Nope, not yet :(

Oh well, Im just happy my routines are good now! :D