* Segfault on ioperm
@ 2005-01-20 13:52 joy merwin monteiro
2005-01-20 14:58 ` Richard Cooper
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: joy merwin monteiro @ 2005-01-20 13:52 UTC (permalink / raw)
To: linux-assembly
Hi,
I had been here before, I can't figure out why the code isnt working.
global _start
port equ 378h
stat equ port+1
ctrl equ port+2
section .text
_start:
mov eax,101
mov ebx,port
mov ecx,3
mov edx,port
int 80h
mov dx,port
mov al,0xff
out 378h,al <----- segfault here
mov eax,1
int 0x80
Any help/ pointers?
Thanks,
Joy.M.Monteiro
--
people always turn away,
from the eyes of a stranger...
Afraid to know
what lies behind the stare.......
--QueensRyche
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Segfault on ioperm
2005-01-20 13:52 Segfault on ioperm joy merwin monteiro
@ 2005-01-20 14:58 ` Richard Cooper
2005-01-20 15:26 ` Jan Wagemakers
2005-01-20 18:40 ` Frank Kotler
2 siblings, 0 replies; 10+ messages in thread
From: Richard Cooper @ 2005-01-20 14:58 UTC (permalink / raw)
To: linux-assembly
> Hi,
>
> I had been here before, I can't figure out why the code isnt working.
> mov eax,101
> mov ebx,port
> mov ecx,3
> mov edx,port
> int 80h
You really should check the return value here. I imagine the call is failing. In particular, you need to have root access, and I believe that edx should actually be 1.
If you're just hoping to control a device you've connected to your parallel port, you might try designing it so that it can work just from the output byte bits, on pins 2 through 9, if that's possible with what you are doing. You'll have to connect pin 11 to 23 and 12 to 24 so that the busy and out of paper signals go away, otherwise the lp driver will block your process on writes thinking the printer is busy or out of paper. Then whatever byte you write to the lp driver will stay on those pins until you write another.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Segfault on ioperm
2005-01-20 13:52 Segfault on ioperm joy merwin monteiro
2005-01-20 14:58 ` Richard Cooper
@ 2005-01-20 15:26 ` Jan Wagemakers
2005-01-20 18:15 ` joy merwin monteiro
2005-01-20 18:40 ` Frank Kotler
2 siblings, 1 reply; 10+ messages in thread
From: Jan Wagemakers @ 2005-01-20 15:26 UTC (permalink / raw)
To: linux-assembly
joy merwin monteiro <joy.merwin@gmail.com> schreef:
> mov dx,port
> mov al,0xff
> out 378h,al <----- segfault here
I think that this should be :
out dx, al
> mov eax,1
> int 0x80
> Any help/ pointers?
I hope this helps you. Good luck!
--
Met vriendelijke groetjes - Jan Wagemakers -
... RFS: picprog: Microchip PIC serial programmer software (GPL)
Deb-package is available at <http://www.janw.easynet.be/picprog.html>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Segfault on ioperm
2005-01-20 15:26 ` Jan Wagemakers
@ 2005-01-20 18:15 ` joy merwin monteiro
0 siblings, 0 replies; 10+ messages in thread
From: joy merwin monteiro @ 2005-01-20 18:15 UTC (permalink / raw)
To: linux-assembly
Hi,
I tried the same program on a different distro (SW 10).
possibly ld on woody is broken (being so old and all..)
it works fine on SW .....
Any comments/suggestions?
Thanks for the help,
Joy.M.Monteiro
On Thu, 20 Jan 2005 16:26:00 +0100, Jan Wagemakers <janw@easynet.be> wrote:
> joy merwin monteiro <joy.merwin@gmail.com> schreef:
>
> > mov dx,port
> > mov al,0xff
> > out 378h,al <----- segfault here
>
> I think that this should be :
>
> out dx, al
>
> > mov eax,1
> > int 0x80
> > Any help/ pointers?
>
> I hope this helps you. Good luck!
>
> --
> Met vriendelijke groetjes - Jan Wagemakers -
>
> ... RFS: picprog: Microchip PIC serial programmer software (GPL)
> Deb-package is available at <http://www.janw.easynet.be/picprog.html>
>
> -
> 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
>
--
people always turn away,
from the eyes of a stranger...
Afraid to know
what lies behind the stare.......
--QueensRyche
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Segfault on ioperm
2005-01-20 13:52 Segfault on ioperm joy merwin monteiro
2005-01-20 14:58 ` Richard Cooper
2005-01-20 15:26 ` Jan Wagemakers
@ 2005-01-20 18:40 ` Frank Kotler
2005-01-21 12:43 ` joy merwin monteiro
2 siblings, 1 reply; 10+ messages in thread
From: Frank Kotler @ 2005-01-20 18:40 UTC (permalink / raw)
To: joy_mm; +Cc: linux-assembly
joy merwin monteiro wrote:
>
> Hi,
>
> I had been here before, I can't figure out why the code isnt working.
Seems like everybody's got a different idea what's wrong...
I might as well throw in my wild guess, too :)
> global _start
>
> port equ 378h
> stat equ port+1
> ctrl equ port+2
>
> section .text
> _start:
>
> mov eax,101
> mov ebx,port
> mov ecx,3
This is the number of ports you're enabling, right?
> mov edx,port
And this should be the "turn-on" value... I imagine you want
"3" here, too, for "in" and "out" permissions...
> int 80h
Check the returned value here, as Richard says, if signed,
bail out.
> mov dx,port
> mov al,0xff
> out 378h,al <----- segfault here
"out dx, al", as Jan suggests...
> mov eax,1
> int 0x80
>
> Any help/ pointers?
Odd that it should work on a different distro... If you
suspect ld, grab newer binutils... Different permissions
setup would be more likely, I would think... But check that
return value - it should tell the tale. (assume you know
that -ERRNO is in eax, not -1 and ERRNO in errno, as man 2
says...)
Best,
Frank
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Segfault on ioperm
2005-01-20 18:40 ` Frank Kotler
@ 2005-01-21 12:43 ` joy merwin monteiro
2005-01-21 14:29 ` Frank Kotler
2005-01-23 8:17 ` Jan Wagemakers
0 siblings, 2 replies; 10+ messages in thread
From: joy merwin monteiro @ 2005-01-21 12:43 UTC (permalink / raw)
To: Frank Kotler; +Cc: linux-assembly
On Thu, 20 Jan 2005 13:40:18 -0500, Frank Kotler <fbkotler@comcast.net> wrote:
> joy merwin monteiro wrote:
> >
> > Hi,
> >
> > I had been here before, I can't figure out why the code isnt working.
>
> Seems like everybody's got a different idea what's wrong...
> I might as well throw in my wild guess, too :)
>
> > global _start
> >
> > port equ 378h
> > stat equ port+1
> > ctrl equ port+2
> >
> > section .text
> > _start:
> >
> > mov eax,101
> > mov ebx,port
> > mov ecx,3
>
> This is the number of ports you're enabling, right?
>
> > mov edx,port
>
> And this should be the "turn-on" value... I imagine you want
> "3" here, too, for "in" and "out" permissions...
No idea, Just used the code available on http://www.janw.easynet.be/eng.html
as a reference. it works fine, so......
>
> > int 80h
>
> Check the returned value here, as Richard says, if signed,
> bail out.
>
> > mov dx,port
> > mov al,0xff
> > out 378h,al <----- segfault here
>
> "out dx, al", as Jan suggests...
However, Jan's musice speaker on the site above uses
"out 43h,al"
Corrected that :-(
>
> > mov eax,1
> > int 0x80
> >
> > Any help/ pointers?
>
> Odd that it should work on a different distro... If you
> suspect ld, grab newer binutils... Different permissions
> setup would be more likely, I would think... But check that
> return value - it should tell the tale. (assume you know
> that -ERRNO is in eax, not -1 and ERRNO in errno, as man 2
> says...)
Thanks for the pointers.....
Joy.M.Monteiro
>
> Best,
> Frank
>
--
people always turn away,
from the eyes of a stranger...
Afraid to know
what lies behind the stare.......
--QueensRyche
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Segfault on ioperm
2005-01-21 12:43 ` joy merwin monteiro
@ 2005-01-21 14:29 ` Frank Kotler
2005-01-23 8:35 ` Jan Wagemakers
2005-01-23 8:17 ` Jan Wagemakers
1 sibling, 1 reply; 10+ messages in thread
From: Frank Kotler @ 2005-01-21 14:29 UTC (permalink / raw)
To: joy_mm; +Cc: linux-assembly
joy merwin monteiro wrote:
> > > mov eax,101
> > > mov ebx,port
> > > mov ecx,3
> >
> > This is the number of ports you're enabling, right?
> >
> > > mov edx,port
> >
> > And this should be the "turn-on" value... I imagine you want
> > "3" here, too, for "in" and "out" permissions...
>
> No idea, Just used the code available on http://www.janw.easynet.be/eng.html
> as a reference. it works fine, so......
Yup. I learn a lot from that page, too. Not "obsolete" at
all, IMO, and your English is fine, too! Thanks, Jan!
In this case, "man 2 ioperm" differs - says "turn on value"
in edx (well... it doesn't say edx...)
> > > out 378h,al <----- segfault here
> >
> > "out dx, al", as Jan suggests...
>
> However, Jan's musice speaker on the site above uses
> "out 43h,al"
Unless I'm mistaken, you can use an "immediate" value for
in/out - but only for the first 255 ports. If the value
exceeds a byte (as 378h does), you have to use dx.
In case it would be of interest to you, or anybody, I'll
include my simple "beep the speaker" example. I make no
claim that this is "right" (certainly not "elegant"), but it
"seems to work". The "delay" routine, for example,
special-cases a duration of 1 (since I want 0 for an
end-of-data marker, "no delay" is 1). This "special case"
should be handled in the "main" part of the code, leaving
the "delay" subroutine more "generic" - just haven't gotten
around to changing it. I'm sure there are other things, too
- any feedback welcome. Since the port numbers are small,
this *does* use immediates on in/out...
Good luck,
Frank
; Plays a tune, of sorts - sound, anyway.
; It is said that I'm not artistic.
;
; nasm -f elf [-g] play.asm
; ld [-s] -o play play.o
;
; to be able to run without being root:
; as root, "chown root:root play" "chmod +s play"
section .text
global _start
_start:
nop ; parking place for gdb
mov eax, 101 ; sys_ioperm
mov ebx, 42h ; starting port
mov ecx, 20h ; how many ports
mov edx, 3 ; read/write
int 80h
test eax, eax
jns okay_ioperm
neg eax
call showeax
mov ebx, eax
jmp exit
okay_ioperm:
; set up PIT
mov al, 10111110b
;.......|------ binary 16-bit counter
;....|||------- square wave generator
;..||---------- r/w bits 0-7, then 8-15
;||------------ select counter 2
out 43h, al
mov esi, melody
playit_sam: ; if she can take it, so can I.
in al, 61h ; enable speaker
or al, 00000011b
;.......|------- enable speaker on timer 2 gate
;......|-------- enable speaker data
out 61h, al
lodsd ; get a note
or eax, eax ; check for zero
jz egress ; coda
out 42h, al ; play it
mov al, ah
out 42h ,al
lodsd ; for this long
call delay
in al, 61h ; Turn Speaker OFF
and al, 11111100b
out 61h, al
lodsd ; for this long
call delay
jmp short playit_sam ; play more
egress:
in al, 61h
and al, 0FCh ; Turn Speaker OFF. Please.
out 61h, al
mov eax, 101 ; sys_ioperm
mov ebx, 42h
mov ecx, 20h
mov edx, 0 ; give back ports
int 80h
test eax, eax
jns okay_exit
neg eax
call showeax
mov ebx, eax
jmp exit
okay_exit:
xor ebx, ebx
exit:
mov eax, 1 ; sys_exit
int 80h
;------------------
;------------------
delay:
push ebx
push ecx
cmp eax, byte 1
jz .no_delay
xor ebx, ebx
.check_ns
cmp eax, 1000000000 ; limit for nanosleep 999999999
ns...
jb .okay_ns
sub eax, 1000000000
inc ebx
jmp short .check_ns
.okay_ns
push eax ; set up a time_spec structure on the stack
push ebx
.take_a_nap
mov eax, 162 ; sys_nanosleep
mov ebx, esp ; same structure for "request"
mov ecx, esp ; and "remaining" - does this work?
int 80h
cmp eax, -4 ; -EINTR
jz .take_a_nap
add esp, byte 8 ; remove time_spec "structure"
.no_delay:
pop ecx
pop ebx
ret
;------------------
;-----------------------------------
; showeax - prints a decimal representation of eax to stdout
; expects - number to print in eax
; returns - nothing
;------------------------------------
showeax:
pushad
xor edi, edi ; counter
mov esi, 10 ; divide by ten
push esi ; double as LF :)
inc edi
.top
xor edx, edx ; zero edx for the divide
div esi ; quotient in eax, remainder in edx
add dl, '0' ; convert number to ascii char
push edx ; save it
inc edi ; bump counter
or eax, eax ; is quotient zero?
jnz .top ; if not, do more
.print
mov eax, 4 ; sys_write
mov ebx, 1 ; stdout
mov ecx, esp ; character's on the stack
mov edx, 1 ; just one
int 80h ; do it
pop edx ; get rid of the character we've
printed
dec edi ; decrement counter
jnz .print ; 'til done
popad
ret
;-----------------------
section .data
; Some equates, for your compositional assistance
; It is said that I'm not artistic.
A0 equ 21728
B0 equ 19328
C0 equ 18244
D0 equ 16144
E0 equ 14080
F0 equ 13668
G0 equ 12176
A1 equ 10864
B1 equ 9664
C1 equ 9122
D1 equ 8072
E1 equ 7040
F1 equ 6834
G1 equ 6088
A2 equ 5432
B2 equ 4832
C2 equ 4561
D2 equ 4063
E2 equ 3520
F2 equ 3417
G2 equ 3044
A3 equ 2712
B3 equ 2416
C3 equ 2280
D3 equ 2032
E3 equ 1810
F3 equ 1708
G3 equ 1522
A4 equ 1356
B4 equ 1208
C4 equ 1140
D4 equ 1016
E4 equ 905
F4 equ 854
G4 equ 762
A5 equ 678
B5 equ 604
C5 equ 558
; Some "durations" for sys_nanosleep
Z equ 1
S equ 60000000
Q equ 120000000
P equ 240000000
R equ 480000000
L equ 1920000000
; The opus itself.
;
; It is said that I'm not artistic.
;
; Format is "note", "duration", "pause", "note", ... , 0
; Write your own!
melody:
dd G2, P, Z, E2, Q, Z, G2, Q, Q, G1, Q, Q
dd G1, Q, Q, C2, Q, Q, B2, Q, Z, C2, Q, Z
dd D2, Q, Q, G2, Q, Q, A3, Q, Z, G2, Q, Z
dd A3, Q, Q, A2, Q, Q, A2, Q, Q, G2, Q, Q
dd E2, Q, Z, G2, Q, Z, F2, Q, Z
dd E2, Q, Z, D2, Q, Q, F2, Q, Z, G2, Q, Z
dd A3, Q, Z, G2, Q, Z, F2, Q, Z, E2, Q, Z
dd F2, Q, Z, E2, Q, Z, D2, Q, Z, B2, Q, Z
dd C2, Q, Z, D2, Q, Z, E2, Q, Z, C2, Q, Z
dd D2, Q, Q, G3, Q, Z, F3, Q, Z, E3, Q, Z
dd D3, Q, Z, C3, Q, Z, B3, Q, Z, A3, Q, Z
dd B3, Q, Z, C3, Q, Z, D3, Q, Z, B3, Q, Q
dd G0, Q, Q, G0, R, Z, 0
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Segfault on ioperm
2005-01-21 12:43 ` joy merwin monteiro
2005-01-21 14:29 ` Frank Kotler
@ 2005-01-23 8:17 ` Jan Wagemakers
2005-01-24 3:28 ` joy merwin monteiro
1 sibling, 1 reply; 10+ messages in thread
From: Jan Wagemakers @ 2005-01-23 8:17 UTC (permalink / raw)
To: linux-assembly
joy merwin monteiro <joy.merwin@gmail.com> schreef:
>>> mov dx,port
>>> mov al,0xff
>>> out 378h,al <----- segfault here
>> "out dx, al", as Jan suggests...
> However, Jan's musice speaker on the site above uses
> "out 43h,al"
This is how OUT works :
| OUT - Output Data to Port
|
| Usage: OUT port,accum
| Modifies flags: None
|
| Transfers byte in AL,word in AX or dword in EAX to the specified
| hardware port address. If the port number is in the range of 0-255
| it can be specified as an immediate. If greater than 255 then the
| port number must be specified in DX. Since the PC only decodes 10
| bits of the port address, values over 1023 can only be decoded by
| third party vendor equipment and also map to the port range 0-1023.
So, if port > 255 then use dx ;-)
--
Met vriendelijke groetjes - Jan Wagemakers -
- Debian GNU/Linux 3.1 - Up : 25 days
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Segfault on ioperm
2005-01-21 14:29 ` Frank Kotler
@ 2005-01-23 8:35 ` Jan Wagemakers
0 siblings, 0 replies; 10+ messages in thread
From: Jan Wagemakers @ 2005-01-23 8:35 UTC (permalink / raw)
To: linux-assembly
Frank Kotler <fbkotler@comcast.net> schreef:
> Yup. I learn a lot from that page, too. Not "obsolete" at
> all, IMO, and your English is fine, too! Thanks, Jan!
:-)
> ; Plays a tune, of sorts - sound, anyway.
> ; It is said that I'm not artistic.
Nice example...
--
Met vriendelijke groetjes - Jan Wagemakers -
- Debian GNU/Linux 3.1 - Up : 25 days
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Segfault on ioperm
2005-01-23 8:17 ` Jan Wagemakers
@ 2005-01-24 3:28 ` joy merwin monteiro
0 siblings, 0 replies; 10+ messages in thread
From: joy merwin monteiro @ 2005-01-24 3:28 UTC (permalink / raw)
To: Jan Wagemakers; +Cc: linux-assembly
I got it.....
Thanks a lot for all the help.
regards,
Joy.M.Monteiro
On Sun, 23 Jan 2005 09:17:22 +0100, Jan Wagemakers <janw@easynet.be> wrote:
> joy merwin monteiro <joy.merwin@gmail.com> schreef:
>
> >>> mov dx,port
> >>> mov al,0xff
> >>> out 378h,al <----- segfault here
> >> "out dx, al", as Jan suggests...
> > However, Jan's musice speaker on the site above uses
> > "out 43h,al"
>
> This is how OUT works :
>
> | OUT - Output Data to Port
> |
> | Usage: OUT port,accum
> | Modifies flags: None
> |
> | Transfers byte in AL,word in AX or dword in EAX to the specified
> | hardware port address. If the port number is in the range of 0-255
> | it can be specified as an immediate. If greater than 255 then the
> | port number must be specified in DX. Since the PC only decodes 10
> | bits of the port address, values over 1023 can only be decoded by
> | third party vendor equipment and also map to the port range 0-1023.
>
> So, if port > 255 then use dx ;-)
>
> --
> Met vriendelijke groetjes - Jan Wagemakers -
>
> - Debian GNU/Linux 3.1 - Up : 25 days
> -
> 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
>
--
people always turn away,
from the eyes of a stranger...
Afraid to know
what lies behind the stare.......
--QueensRyche
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2005-01-24 3:28 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-20 13:52 Segfault on ioperm joy merwin monteiro
2005-01-20 14:58 ` Richard Cooper
2005-01-20 15:26 ` Jan Wagemakers
2005-01-20 18:15 ` joy merwin monteiro
2005-01-20 18:40 ` Frank Kotler
2005-01-21 12:43 ` joy merwin monteiro
2005-01-21 14:29 ` Frank Kotler
2005-01-23 8:35 ` Jan Wagemakers
2005-01-23 8:17 ` Jan Wagemakers
2005-01-24 3:28 ` joy merwin monteiro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).