Howto write on parallel port
Alexios Chouchoulas
alexios at vennea.demon.co.uk
Thu Mar 27 03:43:42 EET 1997
On Wed, 26 Mar 1997, Nikos Vasaitis wrote:
> To na min iparxei i outportb sto linux einai apolyta logico - me ligo
> psaksimo sta ports tha mporousa na sou ftiakso ena programmataki pou na
> kanei to disko sou agnoristo (direct disk writes). Alla den mporoume na
> epitrepsoume se ena programma na kanei oti thelei.
Akribws. Alla, an den yphrxe I/O port access sto user space, pws tha
douleve, px, h SVGAlib;;; Skepsou to! O monos tropos na prospelaseis thn VGA
einai mesw kataxwrhtwn. Yparxoun kai VGA me memory-mapped I/O, alla gia na
to energopoihseis prepei na xrhsimopoihseis port I/O prwta!
Port I/O exeis. Alla yparxoun dyo krithria:
(a) Prepei na zhthseis adeia apo ton kernel PRIN kaneis otidhpote se ena
port, alliws apla DEN SE AFHNEI.
(b) Kai ton Kernighan mparmpa na'xeis, adeia gia na paikseis me ena apo ta
ports (px hard disk, keyboard, DMA, RTC, PIC klp) *DEN* pairneis.
Apax kai o kernel dwsei adeia se kapoion na xeirizetai mia syskevh,
kanenas allos den mporei na thn xeiristei apeftheias. Kai ola ta
pragmatika epikindyna ports exoun drivers pou ta exoun reserved.
Paradeigma, gia tou logou to alithes:
/* Sataniko programma pou katastrefei to MBR tou prwtou sklhrou */
/* 'H ``giati den mporeis na grapseis ious sto Linux [efkola]'' */
static inline void port_out(int value, int port)
{
__asm__ volatile ("outb %0,%1"
::"a" ((unsigned char) value),"d"((unsigned short) port));
}
/* Scary? To phra apo to source ths SVGAlib. Den ftaiw poly! :-) */
/* Mono to parapanw, fysika. H SVGAlib den katastrefei diskous. */
void
main()
{
port_out(0x1f2,0x0); /* Write 256 sectors; bwahahaha */
port_out(0x1f3,0x1); /* Start at sector 1; */
port_out(0x1f4,0x0); /* Cylinder xx00; */
port_out(0x1f5,0x0); /* Cylinder 00xx; */
port_out(0x1f6,0xa0); /* Head 000, drive 0; */
port_out(0x1f7,0x21); /* And write it! */
}
Ok; Klassiko barbaro programma-aytoktonia. A, btw, exei ena lathos stis
IDE/ATA entoles. Einai skopimo gia evnohtous logous mh katastrofhs diskwn.
:-)
Pame na to treksoume twra:
$ gcc file.c -o file
$ ./file
Segmentation fault
$
Aploustata, an den zhthseis adeia apo ton kernel den mporeis na grapseis
s'aftous tous kataxwrhtes. Epeidh, de, o IDE driver exei parei tous
registers gia dikh tou xrhsh:
# grep ide0 /proc/ioports
01f0-01f7 : ide0
03f6-03f6 : ide0
O,ti kai na kanw den tha mou dwsei prosbash.
Alexios Chouchoulas '88 ,88' ,88' alexios at vennea.demon.co.uk
The Unpronouncable One ,o88oooo88ooooo88oo, axc at dcs.ed.ac.uk
==================================================================
For help on using this list (linux-greek-users), send a message to
"majordomo at argeas.argos.hol.gr" with one line of text: "help".
For any problem send e-mail to owner-linux-greek-users
==================================================================
More information about the Linux-greek-users
mailing list