Page 1 of 1

LD Problems

Posted: Wed Apr 11, 2007 12:22 pm
by jzgriffin
Okay...so I'm doing a complete rewrite of my OS, based somewhat on OpenBSD, but boot.asm and start.asm are original. When I try to link the kernel, I get these errors:

Code: Select all

start.o:start.o:(.text+0x14): relocation truncated to fit: 16 against `.text'
start.o:start.o:(.text+0x17): relocation truncated to fit: 16 against `.text'
start.o:start.o:(.text+0x1e): relocation truncated to fit: 16 against `.text'
start.o:start.o:(.text+0x21): relocation truncated to fit: 16 against `.text'
start.o:start.o:(.text+0x25): relocation truncated to fit: 16 against `.text'
start.o:start.o:(.text+0x29): relocation truncated to fit: 16 against `.text'
start.o:start.o:(.text+0x35): relocation truncated to fit: 16 against `.text'
start.o:start.o:(.text+0x43): relocation truncated to fit: 16 against `.text'
start.o:start.o:(.text+0x4e): relocation truncated to fit: 16 against `.text'
start.asm:

Code: Select all

;;;
;; <header id="source/system/start.asm">
;;   <description>Enters 32-bit protected mode, then the C
;;                kernel.</description>
;;   <copyright>Copyright (C) 2007, Griffinsoft Corporation</copyright>
;;   <website>http://www.griffinsoft.net/</website>
;;   <notes>
;;     <!--None-->
;;   </notes>
;; </header>
;;;

[BITS 16]
[GLOBAL start]

;; Jump directly to Start
jmp Start

;;;
;; <function id="Start">
;;   <description>Enters protected mode and sets up the GDT.</description>
;;   <parameters>
;;     <!--None-->
;;   </parameters>
;; </function>
;;;
Start:
    xor ebx, ebx
    mov bx, cs
    shl ebx, 4
    mov eax, ebx
    lea eax, [ebx]
    mov [GDT2 + 2], ax
    mov [GDT3 + 2], ax
    shr eax, 16
    mov [GDT2 + 4], al
    mov [GDT3 + 4], al
    mov [GDT2 + 7], ah
    mov [GDT3 + 7], ah
    lea eax, [ebx + GDT]
    mov [GDTPointer + 2], eax
    push dword 0
    popfd
    o32 lgdt [GDTPointer]
    mov eax, cr0
    or al, 1
    mov cr0, eax
    jmp codeSelector:ProtectedMode

[BITS 32]

;;;
;; <function id="ProtectedMode">
;;   <description>Goes to the C kernel.</description>
;;   <parameters>
;;     <!--None-->
;;   </parameters>
;; </function>
;;;
ProtectedMode:
    mov ax, dataSelector
    mov ds, eax
    mov ss, eax
    nop
    mov es, eax
    mov fs, eax
    mov gs, eax
    xor eax, eax
    mov ax, sp
    mov esp, eax
[EXTERN _Kernel]
    call _Kernel
    jmp $

;;;
;; <function id="GDT">
;;   <description>Part of the GDT.</description>
;;   <parameters>
;;     <!--None-->
;;   </parameters>
;; </function>
;;;
GDT:
    dw 0
    dw 0
    db 0
    db 0
    db 0
    db 0

;;;
;; <function id="linearSelector">
;;   <description>Linear segment selector.</description>
;;   <parameters>
;;     <!--None-->
;;   </parameters>
;; </function>
;;;
linearSelector equ $-GDT
    dw 0xFFFF
    dw 0
    db 0
    db 0x92
    db 0xCF
    db 0

;;;
;; <function id="codeSelector">
;;   <description>Code segment selector.</description>
;;   <parameters>
;;     <!--None-->
;;   </parameters>
;; </function>
;;;
codeSelector equ $-GDT

;;;
;; <function id="GDT2">
;;   <description>Part of the GDT.</description>
;;   <parameters>
;;     <!--None-->
;;   </parameters>
;; </function>
;;;
GDT2:
    dw 0xFFFF
    dw 0
    db 0
    db 0x9A
    db 0xCF
    db 0

;;;
;; <function id="dataSelector">
;;   <description>Data segment selector.</description>
;;   <parameters>
;;     <!--None-->
;;   </parameters>
;; </function>
;;;
dataSelector equ $-GDT

;;;
;; <function id="GDT3">
;;   <description>Part of the GDT.</description>
;;   <parameters>
;;     <!--None-->
;;   </parameters>
;; </function>
;;;
GDT3:
    dw 0xFFFF
    dw 0
    db 0
    db 0x92
    db 0xCF
    db 0

;;;
;; <function id="GDTEnd">
;;   <description>Part of the GDT.</description>
;;   <parameters>
;;     <!--None-->
;;   </parameters>
;; </function>
;;;
GDTEnd:

;;;
;; <function id="GDTPointer">
;;   <description>Part of the GDT.</description>
;;   <parameters>
;;     <!--None-->
;;   </parameters>
;; </function>
;;;
GDTPointer:
    dw GDTEnd - GDT - 1
    dd GDT
Any ideas as to why this is happening, and/or how to fix it?

Posted: Wed Apr 11, 2007 1:01 pm
by Brynet-Inc
Can you post your linker script? I think it might have something to do with the .text section..

Maybe something to do with 16bit vs 32bit values.. :?

Posted: Wed Apr 11, 2007 6:08 pm
by bubach