Re: Linking error - undefined references
Posted: Thu Sep 24, 2015 1:58 am
Did you mean me?
The Place to Start for Operating System Developers
https://f.osdev.org/
And that's where the problem is.catnikita255 wrote:If Combuster meaned me, i'm using the cross-compiler.
Code: Select all
; This will set up our new segment registers. We need to do
; something special in order to set CS. We do what is called a
; far jump. A jump that includes a segment as well as an offset.
; This is declared in C as 'extern void gdt_flush();'
global _gdt_flush ; Allows the C code to link to this
extern _gp ; Says that '_gp' is in another file
_gdt_flush:
lgdt [_gp] ; Load the GDT with our '_gp' which is a special pointer
mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump!
flush2:
ret ; Returns back to the C code!
...---...
/* This will be a function in start.asm. We use this to properly
* reload the new segment registers */
extern void gdt_flush();Code: Select all
; This will set up our new segment registers. We need to do
; something special in order to set CS. We do what is called a
; far jump. A jump that includes a segment as well as an offset.
; This is declared in C as 'extern void gdt_flush();'
global gdt_flush ; Allows the C code to link to this
extern gp ; Says that '_gp' is in another file
gdt_flush:
lgdt [gp] ; Load the GDT with our '_gp' which is a special pointer
mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump!
flush2:
ret ; Returns back to the C code!
...---...
/* This will be a function in start.asm. We use this to properly
* reload the new segment registers */
extern void gdt_flush();Thanks, now code is linking fine. *goed creating vm86*BASICFreak wrote:And that's where the problem is.catnikita255 wrote:If Combuster meaned me, i'm using the cross-compiler.
Bran's Tutorial is written for DJGPP and NASM on windows.
DJGPP adds a leading underscore to all external ASM names.
GCC (or a cross compiler) does not.
EXAMPLE (Directly from Bran's Kernel)
under the original is:and with a cross compiler it should be:Code: Select all
; This will set up our new segment registers. We need to do ; something special in order to set CS. We do what is called a ; far jump. A jump that includes a segment as well as an offset. ; This is declared in C as 'extern void gdt_flush();' global _gdt_flush ; Allows the C code to link to this extern _gp ; Says that '_gp' is in another file _gdt_flush: lgdt [_gp] ; Load the GDT with our '_gp' which is a special pointer mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump! flush2: ret ; Returns back to the C code! ...---... /* This will be a function in start.asm. We use this to properly * reload the new segment registers */ extern void gdt_flush();Notice the lack of the leading underscore in the ASM (this does not affect the C code)Code: Select all
; This will set up our new segment registers. We need to do ; something special in order to set CS. We do what is called a ; far jump. A jump that includes a segment as well as an offset. ; This is declared in C as 'extern void gdt_flush();' global gdt_flush ; Allows the C code to link to this extern gp ; Says that '_gp' is in another file gdt_flush: lgdt [gp] ; Load the GDT with our '_gp' which is a special pointer mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump! flush2: ret ; Returns back to the C code! ...---... /* This will be a function in start.asm. We use this to properly * reload the new segment registers */ extern void gdt_flush();
So effectively ALL the ASM in Bran's Tutorial is DEAD - unless you really want DJGPP, which is not worth it I have tried.
I am curious why this is not mentioned under Bran's Known Bugs... http://wiki.osdev.org/Bran's_Known_Bugs
EDIT: No longer curious as I have added the section "Does not use Cross-Compiler".
Woot, first WiKi Edit