Page 1 of 1
Segmentation fault problem with C & Inline Assembly code
Posted: Wed Aug 16, 2006 7:57 pm
by SmartBoy
Hi ...
i have this code :
void print()
{
char massege = 'H';
char t;
asm("movb $0x0E,%ah");
asm("movb %0,%%al"
: // No
: "r"(massege)
);
asm("int $0x10");
}
int main()
{
print();
}
it's compiled without any problem , but when i want to run the programme it's show for me segmentation fault problem , so what is the error in this code?
GCC -> Linux
sorry for my bad English .
Re:Segmentation fault problem with C & Inline Assembly c
Posted: Thu Aug 17, 2006 12:21 am
by distantvoices
You are by any chance trying to put a character to screen with bios-interrupt 0x10?
This doesn't work in a protected mode environment as you can see: you get a seg-fault.
what you need to do is (if you want to do it this way under all circumstances) check how to issue vm86 calls with Linux. It isn't trivial but neither it is hard to achieve as far as I recall.
Stay safe & remember: google is your best friend.
Try these lemmata: vm86 linux
Re:Segmentation fault problem with C & Inline Assembly c
Posted: Thu Aug 17, 2006 2:30 am
by Pype.Clicker
i suppose you don't ignore the presence of the standard library function "printf" and have a very good reason to attempt using BIOS calls to print on a text screen from an operating environment that has probably set up a graphic video mode and uses hardware acceleration to blit fonts on screen through the framebuffer, right ?
Re:Segmentation fault problem with C & Inline Assembly c
Posted: Thu Aug 17, 2006 3:06 am
by Solar
@ SmartBoy:
Your print() function is written in a way you would do things if you were writing your own operating system kernel.
If you do, you need more to get it running - a bootloader, Assembler startup code, your binaries written to some boot media, and the computer booted off that media.
If that is what you want to do, visit the Quick Linkz thread (found in my signature) and the FAQ (found by clicking the banner on top of this page).
Taking kernel-space code constructs and trying to execute them as any other application (in user space) will fail.
Re:Segmentation fault problem with C & Inline Assembly c
Posted: Thu Aug 17, 2006 4:48 am
by distantvoices
I'd avoid using int 0x10 out of speed reasons even inside a bootloader:
just put the characters directly to the memory area responsible for screen output: 0xb8000 (is that one correct? dunno exactly such a shame)
Re:Segmentation fault problem with C & Inline Assembly c
Posted: Thu Aug 17, 2006 5:20 am
by bluecode
beyond infinity wrote:0xb8000 (is that one correct? dunno exactly such a shame)
That's correct.