Page 1 of 1

[Solved] realmode asm with C (gcc -m16 used)

Posted: Wed May 11, 2022 3:18 pm
by mtbro
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: Select all

load.o:	load.c
	$(CC) $(REALMODE_CFLAGS) load.c -c -o $(OBJDIR)/load.o
where contents of load.c is one dummy function:

Code: Select all


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: Select all

$ 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.

Re: realmode asm with C (gcc -m16 used)

Posted: Wed May 11, 2022 3:37 pm
by Octocontrabass
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.