GAS : Assembler Code for writing to memory :Segfault
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.