All of lore.kernel.org
 help / color / mirror / Atom feed
* int 16 ?
@ 2003-02-14  5:23 dAvId KeDrOsKy
  2003-02-14  8:07 ` Rudolf Marek
  2003-02-14 20:10 ` Jack Dennon
  0 siblings, 2 replies; 6+ messages in thread
From: dAvId KeDrOsKy @ 2003-02-14  5:23 UTC (permalink / raw)
  To: linux-assembly

I was told there exists int 0x16, which can be used to read a single character 
at a time.  Does this interrupt exist in Linux and if so, where can I find 
some documentation on it?

Thanks, 

Dave

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: int 16 ?
  2003-02-14  5:23 int 16 ? dAvId KeDrOsKy
@ 2003-02-14  8:07 ` Rudolf Marek
  2003-02-14 20:10 ` Jack Dennon
  1 sibling, 0 replies; 6+ messages in thread
From: Rudolf Marek @ 2003-02-14  8:07 UTC (permalink / raw)
  To: dAvId KeDrOsKy; +Cc: linux-assembly




> 
> I was told there exists int 0x16, which can be used to read a single character 
> at a time.  Does this interrupt exist in Linux 

no, just use stdin for reading the keyboard, see examples at asmutils 
(linuxassembly.org/asmutils.html) for example in sh.asm or snake.asm

simply: man 2 read
        man 2 open (stdin is already open in your process by default and 
has file desc. number 0)

and mabe man stdin

sys_read STDIN, buff,buff_len 	;<= this is asmutils macro, wich reads 
				;from stdin 

which on linux works this way:

mov eax,   ; service number, dont remember look at 
           ; /usr/src/linux/include/unistd.h
mov ebx,0 ; stdin file descriptor 
mov ecx,buff
mov edx,buff_len
int 0x80


Regards
	Rudolf


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: int 16 ?
  2003-02-14  5:23 int 16 ? dAvId KeDrOsKy
  2003-02-14  8:07 ` Rudolf Marek
@ 2003-02-14 20:10 ` Jack Dennon
  2003-02-15 18:17   ` Rodrigo F. Baroni
  1 sibling, 1 reply; 6+ messages in thread
From: Jack Dennon @ 2003-02-14 20:10 UTC (permalink / raw)
  To: dAvId KeDrOsKy; +Cc: linux-assembly

When the PC boots up, the BIOS sets up an interrupt vector
table at 0000:0000 with int 0x16 pointing into the BIOS keyboard
driver. Linux uses this same vector table to access BIOS disk
routines that are used for booting the system. Linux then sets up
its own interrupt vector table and switches into protected mode.
None of the original BIOS interrupts are then available, nor
are they needed. There are several ways to read a single character
at a time. One of the easier ways is provided by the curses
library. Get on Amazon and look at the programming books
by Matthew & Stones, and maybe even by J. Dennon.


dAvId KeDrOsKy wrote:

> I was told there exists int 0x16, which can be used to read a single character
> at a time.  Does this interrupt exist in Linux and if so, where can I find
> some documentation on it?
>
> Thanks,
>
> Dave
> -
> To unsubscribe from this list: send the line "unsubscribe linux-assembly" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: int 16 ?
  2003-02-14 20:10 ` Jack Dennon
@ 2003-02-15 18:17   ` Rodrigo F. Baroni
  2003-02-15 21:36     ` Jack Dennon
  0 siblings, 1 reply; 6+ messages in thread
From: Rodrigo F. Baroni @ 2003-02-15 18:17 UTC (permalink / raw)
  To: jdennon; +Cc: linux-assembly

 --- Jack Dennon <jdennon@seasurf.net> escreveu: >
When the PC boots up, the BIOS sets up an interrupt
> vector
> table at 0000:0000 with int 0x16 pointing into the
> BIOS keyboard
> driver. Linux uses this same vector table to access
> BIOS disk
> routines that are used for booting the system. Linux
> then sets up
> its own interrupt vector table and switches into
> protected mode.
> None of the original BIOS interrupts are then
> available, nor
> are they needed. There are several ways to read a
> single character
> at a time. One of the easier ways is provided by the
> curses
> library. Get on Amazon and look at the programming
> books
> by Matthew & Stones, and maybe even by J. Dennon.

    So the interrupt vector table created by linux is
other, that access the hardware of the another way so
(using for this others functions/drivers) ?

    I'm a student that loves architeture of computer,
assembly... , and I'm studing this topics at my
univesity now - I would like to do a lot of programs
to test and 'feel' the hardware and the intel
processor (I did this some time ago, but in DOS), but
using linux ...  There is some way to do this ? Like
manipulate control registers, bios interrupts, and so
on ? I had read "Linux Device Drivers", and some
another stuff, but I would like to know more about,
but in the raw mode - assembly, and if possible, in
"binary" mode (100101) or using hexa characteres - I
got this in DOS sometime ago (okay, I'm not crazy,
just wanting feel what is really going happen).

   Any knowlegde, docs, references about would be very
appreciated.


  Thanks a lot
Rodrigo F. Baroni

Computer Science Bach's Student
Sao Paulo, Brazil
   


_______________________________________________________________________
Busca Yahoo!
O serviço de busca mais completo da Internet. O que você pensar o Yahoo! encontra.
http://br.busca.yahoo.com/
-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: int 16 ?
  2003-02-15 18:17   ` Rodrigo F. Baroni
@ 2003-02-15 21:36     ` Jack Dennon
  2003-02-16  6:29       ` Pea Jay
  0 siblings, 1 reply; 6+ messages in thread
From: Jack Dennon @ 2003-02-15 21:36 UTC (permalink / raw)
  To: rodrigobaroni; +Cc: linux-assembly

[-- Attachment #1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #2: sysread.txt --]
[-- Type: text/plain, Size: 1984 bytes --]


Here is an assembly language routine to call
the system read function via int 0x80:

-------------------------------------------------
#/* void asm_sysread(
#	int filedescriptor,
#	char *buffer,
#	int buffer_length)
#
#	invoke syscall __NR_read = 3
# */
	.file	"asm_sysread.s"
.text
.global	asm_sysread
.align	4
SIZE	= 16
BUFF	= 12
FILE	=  8

asm_sysread:
	pushl	%ebp
	movl	%esp,%ebp
	movl	FILE(%ebp),%ebx	#file descriptor
	movl	BUFF(%ebp),%ecx	#buffer fwa
	movl	SIZE(%ebp),%edx	#buffer size
	movl	$3,%eax		# __NR_read
	int	$0x80
	cmpl	$-126,%eax	#check return code
	jbe	.L1		#if no error
#
	negl	%eax		#complement eax
	movl	%eax,%ecx
	movl	$-1,%eax	#on error, return -1
.L1:		
	movl	%ebp,%esp
	popl	%ebp
	ret
	
	.type asm_sysread,@function
	.size asm_sysread,.-asm_sysread
--------------------------------------------------------

And here is a C program to call the above function:

---------------------------------------------------------
/* sysread.c: test the  read  system call
 */
#include <stdio.h>

#define BUFSIZE 16
extern void asm_sysread(int fd, char *buff, int bufsize);

main()
{
	int i;
	int fd = 0;		/* stdin */
	char buff[BUFSIZE];	/* input buffer */
	
	for (i = 0; i < BUFSIZE; i++)
		buff[i] = '\0';
		
	asm_sysread(fd,buff,1);	/* read one char */
	
	for (i = 0; i < BUFSIZE; i++)
		printf("%02x ",buff[i]);
		
	printf("\n");
}
----------------------------------------------------------

If you put these in separate files named, for example,
asm_sysread.s and sysread.c, then you can compile,
assemble, and link with the command

	gcc -o sysread sysread.c asm_sysread.s
	
When called with the command

	sysread

it somewhat works, but it does not do what we want;
the routine asm_sysread does not return after just
one key has been pressed, it returns only after we
hit [Enter]. So the question is, how do we modify
this code to do exactly what we want: fetch the
next keyboard entry and return immediately with it?

Having stalled out on this, I use curses.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: int 16 ?
  2003-02-15 21:36     ` Jack Dennon
@ 2003-02-16  6:29       ` Pea Jay
  0 siblings, 0 replies; 6+ messages in thread
From: Pea Jay @ 2003-02-16  6:29 UTC (permalink / raw)
  To: jdennon; +Cc: linux-assembly

On Sat, 15 Feb 2003 13:36:34 -0800
Jack Dennon <jdennon@seasurf.net> wrote:

> fetch the next keyboard entry and return immediately with it?
>
> Having stalled out on this, I use curses.

Sadly, the easiest way I've found to do this is to use stty.

First fork and exec 'stty -g' and save it's stdout.  It's a special
string that restores the current mode.

Then fork and exec 'stty raw -echo'.  This will change all sorts of
things, e.g. you now have to output CRLF instead of just LF on stdout,
the characters aren't automatically echoed to the screen, and of course,
you get characters as soon as they're typed, typing enter gives you
character 13 instead of character 10, etc.  Basically, it'll work like
one would expect it to.

Just before your program ends, fork and exec stty with that string you
saved from earlier, and it'll put everything back like it was.

Using stty isn't all bad.  Supposedly the reason the ioctls to do this
are undocumented is because they might change, if they ever do, then
once someone fixes stty, your program will be fixed as well.  

This even works over telnet, for reasons I'm afraid to think about.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-02-16  6:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-14  5:23 int 16 ? dAvId KeDrOsKy
2003-02-14  8:07 ` Rudolf Marek
2003-02-14 20:10 ` Jack Dennon
2003-02-15 18:17   ` Rodrigo F. Baroni
2003-02-15 21:36     ` Jack Dennon
2003-02-16  6:29       ` Pea Jay

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.