OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Nov 18, 2017 4:24 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: C inline assembly question
PostPosted: Sun Mar 19, 2017 10:47 am 
Offline

Joined: Sun Mar 19, 2017 10:43 am
Posts: 2
Hi!
I have some trouble with using the inline assembly when writing in c.
I have this code:
Code:
void isr0() {
   __asm__ (
      "pusha\n"
      "push gs\n"
      "push fs\n"
      "push ds\n"
      "push es\n"
      "call interrupt_0\n"
      "pop es\n"
      "pop ds\n"
      "pop fs\n"
      "pop gs\n"
      "popa\n"
      "iret\n"
   );
}

void interrupt_0() {
   print("Divide by 0!\n");
   asm("cli");
     asm("hlt");
}


However, when I try to compile it I get an error:
Code:
kernel.o:kernel.c:(.text+0x2a9): undefined reference to `gs'
kernel.o:kernel.c:(.text+0x2af): undefined reference to `fs'
kernel.o:kernel.c:(.text+0x2b5): undefined reference to `ds'
kernel.o:kernel.c:(.text+0x2bb): undefined reference to `es'
kernel.o:kernel.c:(.text+0x2c0): undefined reference to `interrupt_0'
kernel.o:kernel.c:(.text+0x2c6): undefined reference to `es'
kernel.o:kernel.c:(.text+0x2cc): undefined reference to `ds'
kernel.o:kernel.c:(.text+0x2d2): undefined reference to `fs'
kernel.o:kernel.c:(.text+0x2d8): undefined reference to `gs'


Can someone please help me with that?


Top
 Profile  
 
 Post subject: Re: C inline assembly question
PostPosted: Sun Mar 19, 2017 11:27 am 
Offline
Member
Member

Joined: Thu May 19, 2011 5:13 am
Posts: 204
cyanide wrote:
I have some trouble with using the inline assembly when writing in c.
However, when I try to compile it I get an error:
Can someone please help me with that?
To use intel syntax in GCC inline asm you need to use the -masm=intel option when calling GCC.

_________________
Mike Gonta
look and see - many look but few see

http://mikegonta.com


Top
 Profile  
 
 Post subject: Re: C inline assembly question
PostPosted: Sun Mar 19, 2017 11:50 am 
Offline

Joined: Sun Mar 19, 2017 10:43 am
Posts: 2
Thanks a lot, that helped :D


Top
 Profile  
 
 Post subject: Re: C inline assembly question
PostPosted: Sun Mar 19, 2017 12:02 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1174
You can't do that in inline assembly. You have to put it in a separate assembly file, or try to figure out how __attribute__ ((interrupt)) works.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group