LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-12-2010, 05:47 AM   #1
Saptarshi4031
LQ Newbie
 
Registered: May 2010
Posts: 8

Rep: Reputation: 0
GAS : Assembler Code for writing to memory :Segfault


.globl _start
_start:
movl $0xb800,%eax
movl $0x411f,(%eax)
loop: jmp loop

The above is my code for writng into Video Memory for displaying a character A. However The second line of the code where I am trying to
write 0x411f to the memory 0xb800 pointed by eax causes sigfault.

This is how i have created the hex code
as -o video.o video.s
ld video.o -o video
./video

help appreciated.
 
Old 05-12-2010, 11:36 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Writing directly to video RAM

Hi -

There's this little thing called "protected mode"

If you want to write to video memory, a preferred approach is to use a higher-level library like OpenGL or SDL (on Linux), or DirectX (on Windows):

http://www.libsdl.org/

If you want to simply "talk to the metal", communicating directly with physical hardware addresses and hardware interrupts, then you need an OS that works in "real mode" ... like DOS.

Last edited by paulsm4; 05-13-2010 at 12:03 AM.
 
1 members found this post helpful.
Old 07-20-2010, 01:15 AM   #3
joshebosh
LQ Newbie
 
Registered: Jan 2010
Posts: 1

Rep: Reputation: 0
Assembly Graphics?

i'm stuck the same as Saptarshi4031...

i discovered the real/protected mode thing this past weekend concerning linux, and so far it still does not really satisfy as an answer that we should use higher level language to code graphics...

i mean, why cant i just get simple graphics using assembly?
Sure protected mode locks me out of the video memory/buffer area, but how can programs like dosbox or dosemu simulate real mode environments and run other programs like ketman which codes assembly on the spot to access the video buffer 0xB800 and it works just fine? but i myself cant seem to turn on that little real mode switch and have fun?

And still what would be involved in these two thing? 1.) assembly graphics 2.) in protected mode?

Last edited by joshebosh; 07-20-2010 at 01:17 AM.
 
Old 07-20-2010, 02:00 AM   #4
Elv13
Member
 
Registered: Apr 2006
Location: Montreal,Quebec
Distribution: Gentoo
Posts: 825

Rep: Reputation: 129Reputation: 129
DosBox is an emulator, it does not run on the real hardware, but interface an emulated one of something else (SDL?). And nothing prevent you from doing graphics in assembly, you just need to link it to a library able to interface with the real hardware or see how DirectFB does it. My guess is that it will require you to write in the /dev/fb0 file for the frame buffer or link (and use) XLib or XCB for X11 (graphical server).

Accessing the hardware directly is a major security flaw, it is what drivers are all about, not userland applications. You know, it is why doing void main() { unsigned short i=1; while (i) *i = 0; } does not crash Linux.
 
Old 07-20-2010, 03:33 AM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Assembly is as nice as you want to make it, but as others already pointed out, if every program could do whatever it wishes with the hardware then linux wouldn't differ from any other OS in which regards security and stability. That's why we use OSes nowadays: they are supposed to talk to the hardware for you (or your program). If you want to get direct access to *real* hardware, then you are looking at the wrong direction. You should rather be programming a kernel module and make your program interface with that, just like graphic drivers do in X, vhba, fuse, virtualbox, qemu, etc.

You can use assembly there if that's your call, good luck making it portable then.

Dosbox and dosemu are (or use) a VM. So, when you use assembly inside that jail you are not assembling instructions to real hardware, but instead to emulated hardware.

You can't just "change to real mode" and then continue working as usual in protected mode on the same hardware.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
NASM assembler code, why is it outputting a letter? Omelas0469 Programming 2 03-15-2007 11:37 PM
gas - GNU Assembler - Source Platform yitzle Linux - Software 2 02-24-2007 08:32 PM
Optimizing assembler code dogpatch Programming 6 02-06-2007 08:33 PM
unhandled page fault from assembler code lordofring Programming 2 09-14-2005 02:29 PM
Writing an assembler Yoko Programming 4 10-18-2004 05:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration