[Error] : Invalid Assembly instructions (push)




[Error] : Invalid Assembly instructions (push)

Postby MasterCna » 8. Mar 2017, 03:01

Hello, i was tried to write interrupt handle and stubs in assembly (5-Interrupts Video Tutorial), But i have these following errors (Compiling with NASM):
Code: Select all
interruptstubs.s:35: Error: `pusha' is not supported in 64-bit mode
interruptstubs.s:36: Error: invalid instruction suffix for `push'
interruptstubs.s:37: Error: invalid instruction suffix for `push'
interruptstubs.s:38: Error: invalid instruction suffix for `push'
interruptstubs.s:39: Error: invalid instruction suffix for `push'
interruptstubs.s:41: Error: invalid instruction suffix for `push'
interruptstubs.s:47: Error: invalid instruction suffix for `pop'
interruptstubs.s:48: Error: invalid instruction suffix for `pop'
interruptstubs.s:49: Error: invalid instruction suffix for `pop'
interruptstubs.s:50: Error: invalid instruction suffix for `pop'
interruptstubs.s:51: Error: `popa' is not supported in 64-bit mode

And its my code:
Code: Select all
pusha
    pushl %ds
    pushl %es
    pushl %fs
    pushl %gs
   
    pushl %esp
    push (interruptnumber)
    call _ZL15handleInterrupthj
    # addl $5, %esp
    movl %eax, %esp
   
    popl %gs
    popl %fs
    popl %es
    popl %ds
    popa

Any x64 instruction format for alternative with "pushl"? Also i used pushq for x64 bit instruction but that was not match with %gs or %ds.
User avatar
MasterCna
 
Posts: 11
Joined: 7. Mar 2017, 00:17

by Advertising » 8. Mar 2017, 03:01

Advertising
 

Re: [Error] : Invalid Assembly instructions (push)

Postby algorithman » 8. Mar 2017, 10:29

In part 15 (Multitasking), that code is replaced by something that manually copies the registers into a "CPUState" object and later loads the registers from a CPUState again.

For 64 bit, you'd have to pushq and popq instead of pushl and popl.
And the 64 bit registers start with an additional r, so it's rax, rbx, etc.

I would not recommend compiling for 64 bit though, as it is quite hard to make the CPU switch to 64 bit mode.
http://wiki.osdev.org/Creating_a_64-bit_kernel
User avatar
algorithman
Administrator
 
Posts: 49
Joined: 2. Mar 2017, 11:40

Re: [Error] : Invalid Assembly instructions (push)

Postby MasterCna » 12. Mar 2017, 14:43

Thank you algorithman but,
After days and days researching about problem and solutions (And Part 15 Tutorial), finally i write this code:
Code: Select all
    pusha
    pushl %ds
    pushl %es
    pushl %fs
    pushl %gs



    pushl %esp
    push (interruptnumber)
    call _ZN16InterruptManager15handleInterruptEhj
    #add %esp, 6
    movl %eax, %esp


    popl %gs
    popl %fs
    popl %es
    popl %ds
    popa


For solving 32bit compiling i used .code32 in the first line. Then i tried to link and compile mykernel.bin
i saw this error:
ld: i386:x86-64 architecture of input file `interruptstubs.o' is incompatible with i386 output
.
Many search and read handbooks doesn't help me ! Where is my mistake? in the code or link and compile ? Any solution ?!
:| :|
User avatar
MasterCna
 
Posts: 11
Joined: 7. Mar 2017, 00:17

Re: [Error] : Invalid Assembly instructions (push)

Postby algorithman » 13. Mar 2017, 12:18

That looks like you are linking 32 bit object files with 64 bit object files.
Probably some of your .o files haven't been rebuilt after the switch (since the makefile doesn't say that they depend on the linkerscript and others).
A little
Code: Select all
make clean

should fix that.
User avatar
algorithman
Administrator
 
Posts: 49
Joined: 2. Mar 2017, 11:40

Re: [Error] : Invalid Assembly instructions (push)

Postby MasterCna » 13. Mar 2017, 15:44

I used it too before and didn't fix problem. Also use Shift + delete to remove permanently .o files still didn't fix. Maybe problem is come from my Makefile with compiling parameters. it's my make file:
Code: Select all
GCCPARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore
ASPARAMS = --32
LDPARAMS = -melf_i386


or My nasm assembler ? (I use 64-bit mint OS).
User avatar
MasterCna
 
Posts: 11
Joined: 7. Mar 2017, 00:17

Re: [Error] : Invalid Assembly instructions (push)

Postby algorithman » 13. Mar 2017, 19:41

hmmm I don't know the parameters for nasm - the ones I used in the makefile are for the GNU Assembler...
So I'd say then you should look up how to make nasm compile to 32 bit...
also nasm has a different syntax from gnu assembler - in nasm you have
operator target source
so for example mov x y overwrites x with the content of y
whereas in gnu you have
operator source target
so there mov x y overwrites y with the content of x.
so you'll have to be careful with that.
User avatar
algorithman
Administrator
 
Posts: 49
Joined: 2. Mar 2017, 11:40

Re: [Error] : Invalid Assembly instructions (push)

Postby MasterCna » 13. Mar 2017, 23:08

NASM have a same parameters with GNU Assembler. Anyway i fixed this problem :) :)
Solved by just change
Code: Select all
 loader.o: loader.s

To:
Code: Select all
%.o: %.s

stupid syntax bug !
Thank you for your help and your tutorials. ;)
User avatar
MasterCna
 
Posts: 11
Joined: 7. Mar 2017, 00:17

Re: [Error] : Invalid Assembly instructions (push)

Postby algorithman » 14. Mar 2017, 11:45

huh, really? that should not have made a difference... anyways - happy you got it running 8-)

do you delete loader.o in the make clean command? maybe it was an older, 64 bit loader.o after all and a minor change in loader.s caused make to finally recompile it? :?
User avatar
algorithman
Administrator
 
Posts: 49
Joined: 2. Mar 2017, 11:40

Re: [Error] : Invalid Assembly instructions (push)

Postby MasterCna » 14. Mar 2017, 16:32

I delete .o files over and over with clean command and manually (that was not solution).

Not in loader.s, the error occurred in Makefile.
My fault:
Code: Select all
%loader.o: %loader.s
   as $(ASPARAMS) -o $@ $<


Changed with:
Code: Select all
%.o: %.s
   as $(ASPARAMS) -o $@ $<

Simple but tedious bug!
User avatar
MasterCna
 
Posts: 11
Joined: 7. Mar 2017, 00:17


Return to Compiling & Linking

Who is online

No registered users

cron