Page 1 of 1

ASM and aout

Posted: Mon Dec 20, 2004 5:49 pm
by Googles
I'm trying to combine C and asm.
I know that my asm print function works in .bin format (have tried it in bochs), but as soon as I compile it to aout format (so that ld can handle it) it gets weird.

Here is the print function (only used in 80x25 mode that's why it's so simple).

Code: Select all

print_string_real:
             ;ds:esi - String addr
             ;es:edi - Screen offset
             ;ecx - String Length
             ;ah - Color attribute
             load_save_loop:
                            lodsb
                            stosw
             loop load_save_loop
             ret
here is the string declaration:

Code: Select all

cpuid_works db '386+ CPU detected' ;Len: 17
here is when I call print_string_real():

Code: Select all

        mov ax,0000h
        mov ds,ax
        mov esi,cpuid_works
        mov ax,(SCREEN_ADDR/16)
        mov es,ax
        mov edi,0000h+0*160
        mov ecx,17
        mov ah,STANDARD_COLOR
        call near print_string_real
SCREEN_ADDR is set to 0b8000h and STANDARD_COLOR is set to 4.

Let me know if you need more info

Re:ASM and aout

Posted: Mon Dec 20, 2004 7:42 pm
by aladdin
u have to compile ur asm file to an object elf instead of a.out, then link it to ur kernel like what u do with other .o files ;)

Re:ASM and aout

Posted: Tue Dec 21, 2004 6:32 am
by Googles
my ld (version ?) doesnt support elf..

Re:ASM and aout

Posted: Tue Dec 21, 2004 8:22 am
by Pype.Clicker
you may then wish to create a cross compiler that will support ELF ...

Or you may use COFF (which is likely to be the native format of your linker if your linker is not from MinGW)


Can you be more specific than "it get weirds" ? Also can you tell if you're trying to run that in 16 bits (which LD will not like at all) or 32 bits (if such, *why* are you trying to load selectors with the invalid "0" value) ...

Re:ASM and aout

Posted: Tue Dec 21, 2004 10:15 am
by Googles
No, the asm file which I'm trying to link start of in 16-bit but switches to 32-bit.

I tried COFF but nasm tells me that COFF doesn't like 32 relocatable data.

What gets weird... well the file seems corrupt, the 386+ test is the first thing that happens so I haven't seen much. But the very first thing in the 386+ test routine is that it print the result... For some reason there seems to be a space (0x20) char between all other characters (so "'386+ CPU detected" becomes "'3 8 6 + C P U d e t e c t e d").

Re:ASM and aout

Posted: Tue Dec 21, 2004 2:31 pm
by Googles
I found the problem!

Right above the print_string_real() function there is a function called Enter_Pmode (guess what that function does ;) ). At then end of Enter_PMode I was using 32 bits code but I hade forgot to add "bits 16" before print_string_real.

Now everything works great! It seems LD accepts 16-bits code after all.

Re:ASM and aout

Posted: Tue Dec 21, 2004 2:49 pm
by Pype.Clicker
it will accept it as long as it has nothing special to do with it ;)