flat assembler
Message board for the users of flat assembler.

Index > Linux > Bios interrupts not allowed?

Author
Thread Post new topic Reply to topic
andyz74



Joined: 26 Nov 2007
Posts: 36
Location: Germany
andyz74 31 Mar 2009, 19:25
Hello there!

I tried the following code...
Code:
xor  eax, eax                ;eax = 0 weil ah als 0 gebraucht wird.
int   1ah
mov      [para_w],dx
call     print_dez
mov        [para_w],cx
call     print_dez
    


...to get the time through the system-ticks and print out the two used registers cx and dx (Just for the fun of it)
But the only thing I see is a segmentation fault.
Am I not allowed to run the interrupt 1ah under Linux?

Many thanks for your answers, Andy
Post 31 Mar 2009, 19:25
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 31 Mar 2009, 20:12
Quote:

Am I not allowed to run the interrupt 1ah under Linux?

I think you cannot.

From lscr help ( http://lscr.sourceforge.net/ ) I have extracted this:
Code:
sys_time  [kernel/time.c]


Returns the time since the Epoch (00:00:00 UTC, January 1, 1970), measured in seconds.

Arguments
eax      13
ebx       Pointer to an integer which will receive the return value. If ebx is 0, then time is returned only in eax.

Return values

If the system call succeeds the return value is the time in seconds since the Epoch.
If the system call fails the return value is one of the following errno values:
-EFAULT   ebx points outside your accessible address space.

Remarks

n/a

Compatibility

n/a    


So I suppose that in this way you can get the number of seconds since Epoch:
Code:
mov eax, 13
xor ebx, ebx
int 80h    
Post 31 Mar 2009, 20:12
View user's profile Send private message Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
buzzkill 31 Mar 2009, 20:59
Andy,

Since Linux (like all modern OSes) runs in protected mode, you can't use any BIOS/real mode interrupts natively. There are some libraries that let you emulate a real mode interface, like eg these two:
- lrmi : "library for calling real mode BIOS routines under Linux", http://www.sourceforge.net/projects/lrmi/
- libx86 : "A hardware-independent library for executing real-mode x86 code", http://www.codon.org.uk/~mjg59/libx86
but I've never used these myself, so I can't tell you how well these work.

If you just want the time from the linux kernel, use a syscall like LocoDelAssembly said.
If you want to learn assembly by starting with real mode programming, I think you'd be better of emulating a complete real-mode environment and work in that. Eg dosbox and dosemu can provide you with a DOS environment (DOS is a real-mode OS), and you can run your code in there. There's also bochs, which emulates a complete PC (with integrated debugger), so you can even develop your own real mode OS in it if you like. I have used these three solutions for various things and they all work great.
Post 31 Mar 2009, 20:59
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 31 Mar 2009, 21:16
Quote:

- lrmi : "library for calling real mode BIOS routines under Linux", http://www.sourceforge.net/projects/lrmi/

This one can't run under AMD64 kernels, right? Also root user is required?

Great lib anyway, it is also small enough to port it to Assembly or just grab the essential parts.
Post 31 Mar 2009, 21:16
View user's profile Send private message Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 215
Location: Budapest, Hungary
Endre 01 Apr 2009, 09:30
I think you should use syscall 78 and then libc's localtime function (this latter is not necessary of course, you can implement it by yourself Smile).
Post 01 Apr 2009, 09:30
View user's profile Send private message Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
buzzkill 01 Apr 2009, 14:57
Quote:
This one can't run under AMD64 kernels, right? Also root user is required?

If you're asking me, I don't know. Like I said, I've never used this library myself

Quote:
I think you should use syscall 78 and then libc's localtime function

Normally, you would choose one of the two: either syscall when you want to do the work yourself, or the libc wrapper if you want to make it easier for yourself (and don't mind linking to libc).
Post 01 Apr 2009, 14:57
View user's profile Send private message Reply with quote
andyz74



Joined: 26 Nov 2007
Posts: 36
Location: Germany
andyz74 01 Apr 2009, 16:11
Thank U all for your help!
LocoDelAssembly, I think I'll try the "eax=13 / int 80h" solution, this seems to be the easiest.
Due to lack of intelligence, I'm always forced to take easy solutions. Smile
Again thank U all! Smile
Post 01 Apr 2009, 16:11
View user's profile Send private message Visit poster's website Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 215
Location: Budapest, Hungary
Endre 02 Apr 2009, 13:48
Quote:
Normally, you would choose one of the two: either syscall when you want to do the work yourself, or the libc wrapper if you want to make it easier for yourself (and don't mind linking to libc).
You might not know but int 78 and localtime don't substitute but complement each other. Colossal difference. And in what book did you read that mixing syscalls and libc-calls is to be avoided? Throw it away, it misleads you.
Post 02 Apr 2009, 13:48
View user's profile Send private message Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
buzzkill 02 Apr 2009, 15:23
Quote:
You might not know but int 78 and localtime don't substitute but complement each other. Colossal difference. And in what book did you read that mixing syscalls and libc-calls is to be avoided? Throw it away, it misleads you.


What's wrong with using gettimeofday() ? What would be the advantage of using one syscall and one libc-call over either two syscalls or two libc calls? I never said that mixing the two should be avoided, I'm saying there's usually no point in mixing them: if you're already linked to libc to call localtime(), then why not call libc's gettimeofday() as well?
Post 02 Apr 2009, 15:23
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.