LD problem

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
User avatar
matthias
Member
Member
Posts: 158
Joined: Fri Oct 22, 2004 11:00 pm
Location: Vlaardingen, Holland
Contact:

LD problem

Post by matthias »

Hi,

I have the following problem, when I try to link my kernel with LD it gives the following error:

stub.o(.text+0x60):stub.o: relocation truncated to fit: 16 .text

Here is my code:

Code: Select all


;-----------------------------------------------------------------------------
; File: stub.asm
;
; Desc: This is the 16-bit entrypoint of the kernel

;-----------------------------------------------------------------------------
; Globals
;-----------------------------------------------------------------------------

[global load]
[global _header]
[global _export_header]
[global _gdt32]
[global _idt32]
[global _idt16]

;-----------------------------------------------------------------------------
; imports
;-----------------------------------------------------------------------------

[extern _main32]
[extern __main]
[extern __atexit]
[extern code]
[extern data]
[extern bss]
[extern end]

[section .text]
[BITS 16]

;-----------------------------------------------------------------------------
; Name: load
; Desc: 16-bit entrypoint, jumps over the kernel header and exports
;-----------------------------------------------------------------------------

load:

	jmp main16 ; jump over header
	
;-----------------------------------------------------------------------------
; Name: _header
; Desc: header of the kernel
;-----------------------------------------------------------------------------

_header:

	dd 0x3233534f ; magic (OS32)
	dd 0x00000000 ; flags (has to be filled in by OSLOADER so zero them for now)
	dd 0x61313030 ; version (0.0.1.a)
	dd _header
	dd code
	dd data
	dd bss
	dd end
	dd load
	dd 0x28; sizeof this structure (40 bytes)

;-------------------------------------------------------------------------------
; Name: _export_header
; Desc: Defines all the functions that are exported by the kernel.
;		Kernel exports can only be used by system applications!
;		For user programs there is a separate libary to do system calls.
;-------------------------------------------------------------------------------

_export_header:

	dd 0x42545845	; magic (EXTB - EXportTaBle)
	dd 0x3			; number of exports
	dd _main32		; first export
	db "_main32"	; name of export
	db 0x8			; length of name
	dd __main		;
	db "__main"		; name of export
	db 0x7			; length of name
	dd __atexit		;
	db "__atexit"	; name of export
	db 0x9			; length of name
	dd 0xfefefefe	; end of header
	
;-----------------------------------------------------------------------------
; Name: main16
; Desc: Sets up Protected Mode and jumps to the 32-bits entrypoint
;-----------------------------------------------------------------------------
	
main16:

	cli	
	lgdt [cs:gdt]	; load GDT
	mov	ecx, cr0
	inc	cx
	mov	cr0, ecx	; switch to protected mode
	
	; now enable the A20 address line
.1:	
	in	al, 0x64
	test al, 2
	jnz	.1
	mov	al, 0xD1
	out	0x64, al
.2:	
	in	al, 0x64
	and	ax, byte 2
	jnz	.2
	mov	al, 0xDF
	out	0x60, al

	; set segment registers to right values and go 32-bits :)
	
	mov	al, kernel_data		
	mov	ds, ax			
	mov	es, ax
	mov fs, ax
	mov gs, ax
	mov ss, ax	
			
	cli ; disable all interrupts
			
	jmp dword 0x8:main32 ; jump, jump, jump :p
	
;-------------------------------------------------------------------------------
; Name: _gdt16 (16-bit)
; Desc: This is the actual Global Descriptor Table.
;-------------------------------------------------------------------------------
	 
_gdt16:
         dd  0               ; NULL descriptor
         dd  0

kernel_code equ $-_gdt16		; 0x08 kernel 4GB code at 0x00000000 
     
    dd 0xffff0000
	dd 0x009acf00

kernel_data equ $-_gdt16		; 0x10 kernel 4GB data at 0x00000000

    dd 0xffff0000
	dd 0x0092cf00

gdtend:

; 16-bit GDTR
gdt: 
	dw 0x7fff ; limit
	dd _gdt16 ; pointer to the table

[BITS 32]

;-------------------------------------------------------------------------------
; Name: main32
; Desc: Calls the (de)constructor handlers and calls the main kernel routine
;-------------------------------------------------------------------------------

main32:
	hlt
	
	cli ; just to make sure
	
	mov esp, 0x200000 ; set the stack pointer
	call __main   ; call constructors of all global objects
	call _main32  ; load main routine
	call __atexit ; call deconstructors of all global objects 

[section .data]

;-------------------------------------------------------------------------------
; Name: _gdt32 (32-bit)
; Desc: Global Descriptor Table, this is used by the GDTManager
;-------------------------------------------------------------------------------

_gdt32:
	 dw 0x0
	 dd 0x0

;-------------------------------------------------------------------------------
; Name: _idt32 (32-bit)
; Desc: Interrupt Descriptor Table, this is used by the IDTManager
;------------------------------------------------------------------------------- 
	
_idt32: 
	 dw 0
	 dd 0
	 
The source of my problems is in the source.
blackcatcoder
Member
Member
Posts: 132
Joined: Wed Nov 03, 2004 12:00 am
Location: Austria
Contact:

Re: LD problem

Post by blackcatcoder »

hmm....

i know this. you can't link 32-bit C/C++ code in a mixed asm file ! you have to split the stub.asm into two files. One with the pm init and one with the kernel load stuff!

i hope this would help!
User avatar
matthias
Member
Member
Posts: 158
Joined: Fri Oct 22, 2004 11:00 pm
Location: Vlaardingen, Holland
Contact:

Re: LD problem

Post by matthias »

Already tried that :( But thanks anyways.
The source of my problems is in the source.
blackcatcoder
Member
Member
Posts: 132
Joined: Wed Nov 03, 2004 12:00 am
Location: Austria
Contact:

Re: LD problem

Post by blackcatcoder »

if you want I could send you my os loader?
Post Reply