OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 25, 2024 9:08 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: inline assembly in c for VGA Video mode
PostPosted: Sun Apr 26, 2015 12:42 pm 
Offline

Joined: Fri Apr 24, 2015 1:25 pm
Posts: 14
Hi,
I wrote a program for enabling VGA video mode by

Code:
void enable_vgaVideo()
{
   __asm__("mov %ah,0x0;");
   __asm__("mov %al, 0x13;");
   __asm__("int 0x10;");
   __asm__("ret;");
}


Problem is that , it is throwing error for
Code:
__asm__("int 0x10;");


Code:
/tmp/cczSu1bD.s: Assembler messages:
/tmp/cczSu1bD.s:49: Error: operand size mismatch for `int'
/tmp/cczSu1bD.s:86: Error: operand size mismatch for `int'



The command I used:
Code:
i686-elf-gcc -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra

Why is this happening? My PC is 64 bit i5-3G.


Top
 Profile  
 
 Post subject: Re: inline assembly in c for VGA Video mode
PostPosted: Sun Apr 26, 2015 12:54 pm 
Offline
Member
Member

Joined: Tue Jan 20, 2015 8:33 pm
Posts: 29
If you're using GCC/GAS as your assembler, you have to prefix constants with a $ (I'm pretty sure! I switched to NASM a long time ago... :P)

Code:
__asm__("mov %ah,$0x0;");
__asm__("mov %al, $0x13;");
__asm__("int $0x10;");


When you leave it off I believe it's trying to 'read memory address 0x10' instead of 'use constant 0x10'.


Top
 Profile  
 
 Post subject: Re: inline assembly in c for VGA Video mode
PostPosted: Sun Apr 26, 2015 1:16 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5145
I can see at least three things wrong with your code.

  1. You're using multiple __asm__ statements, giving the compiler freedom to rearrange (and break) them as it sees fit.
  2. You're lying to the compiler about the side effects. The compiler will make false assumptions that will break your code.
  3. You're attempting to call the BIOS from within your kernel, which is most likely already in protected mode and therefore can no longer access the BIOS.

Which of these would you like to fix first?


Top
 Profile  
 
 Post subject: Re: inline assembly in c for VGA Video mode
PostPosted: Sun Apr 26, 2015 1:26 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4597
Location: Chichester, UK
I'd fix the order of the operands first.
Then put in the "$"s.
Then ....

Actually, i'd learn how to program assembler using AT&T syntax. Guess what - Google will help here.

A second word of advice to the OP (even though my first has been ignored). People are soon going to get very tired of these questions that demonstrate a lack of required knowledge. These forums are not programming tutorials for beginners.


Top
 Profile  
 
 Post subject: Re: inline assembly in c for VGA Video mode
PostPosted: Sun Apr 26, 2015 2:14 pm 
Offline

Joined: Fri Apr 24, 2015 1:25 pm
Posts: 14
Thank You guys.

I decided to go through http://wiki.osdev.org/Required_Knowledge and all other relevant links. :)


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot], Majestic-12 [Bot] and 254 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