ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
First of all i have to say that I am very new to the Assembler programming language.
I tried the following on a linux ix86 box without success.
msg db "Druckertest ...",0x0A ;0x0A->zeilenumbruch
msg2 db "Drucker bereit",0x0A
len equ $-msg
len2 equ $-msg2
mov eax,4 ; Ausgabe von msg
mov eax, 4
mov ebx, 1
mov ecx, msg2
mov edx, len2
mov eax,1 ;syscall 1 = exit
int 0x80 ;exit
My goal is to fetch the printers Statusbyte to analyze how the printer works, but when the program reaches "int 17h" it runs into a segmentation fault.
Does anyone has any idea how to solve this problem?
I have never programmed in assembly on Linux and
it has been a while since I've touched assembly at all
but off the top of my head I see:
1) This might be it, I think you might not be able
to access the hardware directly like that from
user space. Try running the program as root.
I doubt that will work. You will probably have
to use system calls to get the information
2) This just kind of jumped out at me but won't solve
your problem you jump unecessarily.
could just be
And the same for the other times you do it.
and when you
There is no point, you will always fall through
you are right, the jumps are unecessary. I thought I can prevent some problems if the program becomes more complex. :-) But that shouldnt be the reason for the segmentation fault when calling int 17h.
You said accessing the hardware directly from user space might not work. Do I have the opportunity to implement these lines into a LKM? Or which syscall do I need to access the hardware to get the printers status byte?
You could do that from kernel module but I don't know if you'd
have a conflict form the normal parallel port driver. But as we've
just left user space and entered the kernel I am way out of my
league. It would be a terrible security risk to be able to have
direct hardware access from userspace. If you can find out what
int 0x17 does exactly you might be able to stay in nice friendly
userspace by manipulating the i/o lines. See the i/o port programming
I should be more clear.
int 0x80 is allowed and you are correct that is how you
interact with the kernel for system calls. Other interrupts
aren't allowed. int is a privileged instruction. Using int in
usermode generates an exception which is why his program
segfaults. The kernel masks int 0x80 and catches the exception
it when a process uses it. The kernel does this sort of thing for
other stuff too. For example when you want to use floating
point instructions on an i386 w/ no fpu. The kernel will catch
the "illegal" instruction exception and instead of giving your
program a SIGILL it will emulate the instruction and hand it
back to the program transparently.
Ok, thank you all. I think, now I understand why it doesnt work to call the interrupt, but another question regarding that topic ... What is the way a driver (module in the linux world) initialize the printer to communicate with the system. Interrupt 17h, function 1 (ah =1) specifies a printer initialization. What does that mean in clear text? Does that has anything to do with driver wrtiting or is it just another method to confuse me. :-)