How to tell GCC to generate 16-bit code for real mode

后端 未结 4 724
悲哀的现实
悲哀的现实 2020-12-15 23:53

I am writing real mode function, which should be normal function with stackframes and so, but it should use %sp instead of %esp. Is there some way to do it?

4条回答
  •  自闭症患者
    2020-12-16 00:15

    Firstly, gcc could build 16bit code, because the linux kernel is go through realmode to protectmode, so it could even build 16bit c code.

    Then, -m16 option is supported by GCC >= 4.9 and clang >= 3.5

    gcc will ignore asm(".code16"),you can see it by -S output the assembly code surround by #APP #NO_APP

    the linux kernel do the trick to compile 16bit c with a code16gcc.h(only have .code16gcc) pass to gcc compile params directly. see Build 16-bit code with -m16 where possible, also see the linux kernel build Makefile

    if you direct put the asm(".code16gcc"), see Writing 16-bit Code, it's not real 16bit code, call, ret, enter, leave, push, pop, pusha, popa, pushf, and popf instructions default to 32-bit size

提交回复
热议问题