OSDev.org
https://forum.osdev.org/

[Solved] realmode asm with C (gcc -m16 used)
https://forum.osdev.org/viewtopic.php?f=13&t=56276
Page 1 of 1

Author:  mtbro [ Wed May 11, 2022 3:18 pm ]
Post subject:  [Solved] realmode asm with C (gcc -m16 used)

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.

Author:  Octocontrabass [ Wed May 11, 2022 3:37 pm ]
Post subject:  Re: realmode asm with C (gcc -m16 used)

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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/