ASM and aout

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
Googles

ASM and aout

Post 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
aladdin

Re:ASM and aout

Post 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 ;)
Googles

Re:ASM and aout

Post by Googles »

my ld (version ?) doesnt support elf..
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:ASM and aout

Post 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) ...
Googles

Re:ASM and aout

Post 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").
Googles

Re:ASM and aout

Post 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.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:ASM and aout

Post by Pype.Clicker »

it will accept it as long as it has nothing special to do with it ;)
Post Reply