Page 1 of 1

Converting barebones boot.s to intel syntax

Posted: Sun May 29, 2016 11:05 am
by Twicetimes
Hi,

I followed the barebones guide and got the 'hello world' OS up and running.

As an exercise, I tried changing the boot.s file to intel syntax. As far as I can see, this just involved changing

Code: Select all

movl $stack_top, %esp
to

Code: Select all

mov esp, offset dword ptr stack_top
and then recompiling it with

Code: Select all

i686-elf-as -msyntax=intel
This all went fine. However, when it came to linking time, I received the following error:

Code: Select all

(.text+0x2): undefined reference to 'esp'
which instantly made me think it was still looking for ATT-syntax mnemonics like '%esp' instead of 'esp'. I tried combinations of adding '-masm=intel' to the i686-elf-gcc call, and '-mmnemonic=intel' to the i686-elf-as call, but these made no difference.

What finally did work was adding '.intel_syntax noprefix' to the top of the boot.s file. However, I'm assuming that the command line options are meant to make it so you don't have to specify this in each .s file. The flags seem to affect the general syntax, but not the register names somehow.

Any guidance on this would be much appreciated.

Re: Converting barebones boot.s to intel syntax

Posted: Sun May 29, 2016 4:20 pm
by mikegonta
Twicetimes wrote:What finally did work was adding '.intel_syntax noprefix' to the top of the boot.s file. However, I'm assuming that the command line
options are meant to make it so you don't have to specify this in each .s file. The flags seem to affect the general syntax, but not the
register names somehow. Any guidance on this would be much appreciated.
Silly, but that's the way it is.
By the way, this is all you need to specify an offset.

Code: Select all

  mov esp, OFFSET stack_top

Re: Converting barebones boot.s to intel syntax

Posted: Sun May 29, 2016 5:16 pm
by Twicetimes
Fair enough. Thanks for the tip about 'offset'.