OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Aug 18, 2022 4:18 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: [Solved] realmode asm with C (gcc -m16 used)
PostPosted: Wed May 11, 2022 3:18 pm 
Offline

Joined: Fri Apr 08, 2022 3:12 pm
Posts: 15
I'd like to call a function defined in object compiled by gcc (-m16) from object compiled by gas, all in realmode. I'm using these CFLAGS to compile object for realmode, compiled as
Code:
load.o:   load.c
   $(CC) $(REALMODE_CFLAGS) load.c -c -o $(OBJDIR)/load.o
where contents of load.c is one dummy function:
Code:

void test_load() {
   puts16("hi\r\n");
}
puts16() comes from my libsa16 library.

Problem is that while code generated by gcc is using 0x66 prefix any push/ret/call push 4B instead of 2. Segments are all 0.
Code:
$ objdump -d obj/load.o -mi8086

obj/load.o:     file format elf32-i386

00000000 <test_load>:
   0:   66 68 00 00 00 00       pushd  0x0
   6:   66 e8 fc ff ff ff       calld  8 <test_load+0x8>
   c:   66 58                   pop    eax
   e:   66 c3                   retd


I don't necessarily need to use C but I'm curious to see what am I missing.

Edit: thanks.


Last edited by mtbro on Wed May 11, 2022 3:45 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: realmode asm with C (gcc -m16 used)
PostPosted: Wed May 11, 2022 3:37 pm 
Online
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 4037
Your assembly code is written according to a 16-bit ABI. GCC does not support any 16-bit ABIs.

If you want to call an assembly function, it needs to use a 32-bit ABI, even if it's 16-bit code. GCC allows you to specify the ABI on a per-function basis.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group