Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

To err is human, to forgive, beyond the scope of the Operating System.


devel / comp.lang.asm.x86 / serial port

SubjectAuthor
* serial portPaul Edwards
`* serial portTerje Mathisen
 +- serial portPaul Edwards
 `* serial portPaul Edwards
  `* serial portPaul Edwards
   +* serial portAndrew Cooper
   |`- serial portPaul Edwards
   +* serial portsean
   |`* serial portPaul Edwards
   | `- serial portsean
   `* serial portPaul Edwards
    `* serial portPaul Edwards
     `* serial portPaul Edwards
      `* serial portPaul Edwards
       +* serial portPaul Edwards
       |+* serial portTerje Mathisen
       ||`- serial portPaul Edwards
       |`* serial portPaul Edwards
       | `- serial portPaul Edwards
       `* serial portsean
        `- serial portPaul Edwards

1
serial port

<65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=410&group=comp.lang.asm.x86#410

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: serial port
Date: Tue, 11 Apr 2023 04:18:14 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 70
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Tue, 11 Apr 2023 11:18:14 +0000
Injection-Info: dont-email.me; posting-host="c9b82046df037cdc4c842b45000ccac7";
logging-data="2744138"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Ka4705rhHJ1899euJZK2Wzy3wEmqHW+c="
User-Agent: G2/1.0
Cancel-Lock: sha1:VpuJ7d37NyS8aZr+agQwozgo52M=
 by: Paul Edwards - Tue, 11 Apr 2023 11:18 UTC

Hi.

As far as I can tell from testing, the BIOS INT 14H doesn't
work on most real hardware I have tried (computers made
maybe 10 years ago that still have a serial port).

So I am gearing up to replace that with 80386 PM32 code.

I have some comms routines for MSDOS (pdcomm) that I
wrote decades ago, but I want to do it a different way this time.

Less sophisticated, but more straightforward.

And designed for a single-tasking system with only one
CPU enabled (PDOS/386).

Most of the code can be done in C, but the last bit I want
to do in assembler.

Prior to hitting the assembler, I will have installed the
new interrupt address (which is assembler code, gotint,
below).

I'm just trying to confirm the sequence in the final assembler.

outb port1, transmit_byte
outb port2, tbemask ; enable transmit buffer empty (only)
xxx:
hlt ; this could get interrupted by timer interrupts and
; then processing continues so we need a jmp
jmp xxx
gotint: ; this is the interrupt address installed by C caller
outb port2, oldmask ; restore previous interrupt mask (everything disabled)
add esp, 12 ; we don't return to the previous instruction, which was hlt
; instead we skip over the return address, segment and flags

ret ; return to C caller which will do the EOI or whatever
; via separate calls to individual simple assembler functions
; like outportb()

Note that this was inspired by something similar I wrote
for S/370.

It's basically quite minimal assembler and straightforward.

There is a loop in the assembler, which I didn't have in my
old routines, but it's not really processing logic.

After transmit is working I'll try a variation of the above for receive.

I especially don't know if these two need to be swapped:

outb port1, transmit_byte
outb port2, tbemask ; enable transmit buffer empty (only)

I don't want to miss an interrupt. I want the order to
guarantee that I will get the interrupt. ie if I have already
attempted to write the transmit byte, will the interrupt
pend until I enable it, or will it be skipped?

Or is the other way around? If I haven't enabled interrupts
will it just transmit the byte and not bother interrupting?

Assume that the transmit is very fast, or the CPU is very
slow, so that there is a gap between the two outb
instructions where a decision is made on whether to
interrupt or not.

Thanks. Paul.

Re: serial port

<u14b9q$2mq6r$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=411&group=comp.lang.asm.x86#411

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: terje.mathisen@nospicedham.tmsw.no (Terje Mathisen)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Tue, 11 Apr 2023 21:09:45 +0200
Organization: A noiseless patient Spider
Lines: 93
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <u14b9q$2mq6r$1@dont-email.me>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="c9b82046df037cdc4c842b45000ccac7";
logging-data="2845230"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+l4XffyIRLTDUJzJua70TCJDS0GxE1Xi8="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.16
Cancel-Lock: sha1:QvRyvcULi7mP4yxlGCWpXsbUC3Y=
 by: Terje Mathisen - Tue, 11 Apr 2023 19:09 UTC

I last looked at my RS232 drivers at least 30+ years ago, but from
memory what I had to do was to get the data from the serial port chip,
at this point I re-enable all other interrupts except the one I am
servicing.

After saving the received byte I optionally loop back until the input
buffer is empty (more modern PCs had a 16-byte buffer you could enable).

Before returning from the interrupt with IRET, I would reenable the
serial port IRQ channel (stil with interrupts disabled), then IRET back
to the interrupted process.

If you are interested I can see if I can locate my source code...

Terje

Paul Edwards wrote:
> Hi.
>
> As far as I can tell from testing, the BIOS INT 14H doesn't
> work on most real hardware I have tried (computers made
> maybe 10 years ago that still have a serial port).
>
> So I am gearing up to replace that with 80386 PM32 code.
>
> I have some comms routines for MSDOS (pdcomm) that I
> wrote decades ago, but I want to do it a different way this time.
>
> Less sophisticated, but more straightforward.
>
> And designed for a single-tasking system with only one
> CPU enabled (PDOS/386).
>
> Most of the code can be done in C, but the last bit I want
> to do in assembler.
>
> Prior to hitting the assembler, I will have installed the
> new interrupt address (which is assembler code, gotint,
> below).
>
> I'm just trying to confirm the sequence in the final assembler.
>
> outb port1, transmit_byte
> outb port2, tbemask ; enable transmit buffer empty (only)
> xxx:
> hlt ; this could get interrupted by timer interrupts and
> ; then processing continues so we need a jmp
> jmp xxx
> gotint: ; this is the interrupt address installed by C caller
> outb port2, oldmask ; restore previous interrupt mask (everything disabled)
> add esp, 12 ; we don't return to the previous instruction, which was hlt
> ; instead we skip over the return address, segment and flags
>
> ret ; return to C caller which will do the EOI or whatever
> ; via separate calls to individual simple assembler functions
> ; like outportb()
>
> Note that this was inspired by something similar I wrote
> for S/370.
>
> It's basically quite minimal assembler and straightforward.
>
> There is a loop in the assembler, which I didn't have in my
> old routines, but it's not really processing logic.
>
> After transmit is working I'll try a variation of the above for receive.
>
> I especially don't know if these two need to be swapped:
>
> outb port1, transmit_byte
> outb port2, tbemask ; enable transmit buffer empty (only)
>
> I don't want to miss an interrupt. I want the order to
> guarantee that I will get the interrupt. ie if I have already
> attempted to write the transmit byte, will the interrupt
> pend until I enable it, or will it be skipped?
>
> Or is the other way around? If I haven't enabled interrupts
> will it just transmit the byte and not bother interrupting?
>
> Assume that the transmit is very fast, or the CPU is very
> slow, so that there is a gap between the two outb
> instructions where a decision is made on whether to
> interrupt or not.
>
> Thanks. Paul.
>

--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Re: serial port

<2c9209ca-7c67-4a21-ad37-63aee5a099abn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=412&group=comp.lang.asm.x86#412

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Tue, 11 Apr 2023 13:57:26 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 27
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <2c9209ca-7c67-4a21-ad37-63aee5a099abn@googlegroups.com>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com> <u14b9q$2mq6r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Tue, 11 Apr 2023 20:57:27 +0000
Injection-Info: dont-email.me; posting-host="c9b82046df037cdc4c842b45000ccac7";
logging-data="2865774"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FuVgACWyhebAqQJew+UQGQ2sV3OmztIU="
User-Agent: G2/1.0
Cancel-Lock: sha1:SKbNynVElAAN620VcSv2V0qpn8s=
 by: Paul Edwards - Tue, 11 Apr 2023 20:57 UTC

On Wednesday, April 12, 2023 at 3:25:01 AM UTC+8, Terje Mathisen wrote:

> After saving the received byte I optionally loop back until the input
> buffer is empty (more modern PCs had a 16-byte buffer you could enable).

This sounds like the normal/proper way to do things.

I did that with a proper buffer too:

https://sourceforge.net/projects/pdos/files/pdcomm/PDCOMM%202.50/

But now I would like to do things differently (simpler).

> If you are interested I can see if I can locate my source code...

Thanks, but I already have source code for a traditional
implementation. Note that I've never used "hlt" ever - I
just heard about it, and the code I wrote above is what
I picked up by osmosis.

So I'm unsure whether the logic is correct or not. Bypassing
the iret too is new. On return to the C caller I might need to
reenable interrupts because I bypassed the iret.

BFN. Paul.

Re: serial port

<e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=413&group=comp.lang.asm.x86#413

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Tue, 11 Apr 2023 18:29:04 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 65
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com> <u14b9q$2mq6r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Wed, 12 Apr 2023 01:29:05 +0000
Injection-Info: dont-email.me; posting-host="2e4ab8a76f89737d8abf6b3f730b088a";
logging-data="2910061"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ibDY0X3OYLjNujl9wfRClSnY4QeiuqoA="
User-Agent: G2/1.0
Cancel-Lock: sha1:HPu7aIBvQB1iMZXeziriU77YJz4=
 by: Paul Edwards - Wed, 12 Apr 2023 01:29 UTC

On Wednesday, April 12, 2023 at 3:25:01 AM UTC+8, Terje Mathisen wrote:

> at this point I re-enable all other interrupts

Actually, that made me rethink - maybe it is more straightforward to:

Do this from C code, to signal that I am interested in TBE:

outb port2, tbemask ; enable transmit buffer empty (only)

Disable all interrupts (cli) from C code as well

Do this from C code:

outb port1, transmit_byte

And at this point, if the byte is transmitted very quickly,
the UART knows that it needs to do an interrupt, but
interrupts are temporarily disabled, so it knows that it
needs to queue the interrupt, not discard it.

And then I call this assembler:

xxx:
hlt ; this could get interrupted by timer interrupts and
; then processing continues so we need a jmp
jmp xxx

And actually, even that can go into a function called halt_loop(),
called by C.

And then I can have this generic assembler routine:

gotint: ; this is the interrupt address installed by C caller
add esp, 12 ; we don't return to the previous instruction, which was hlt
; instead we skip over the return address, segment and flags

Actually, no I can't. They need to be combined.

sti
xxx:
hlt ; this could get interrupted by timer interrupts and
; then processing continues so we need a jmp
jmp xxx

gotint: ; this is the interrupt address installed by C caller
add esp, 12 ; we don't return to the previous instruction, which was hlt
; instead we skip over the return address, segment and flags
sti ; interrupts will have been disabled automatically. need to reenable
ret

Possibly take that sti out and do it from C, as C will have
done a call to disable interrupts, so this would be a good match.

And this is put back into C code:

outb port2, oldmask ; restore previous interrupt mask (everything disabled)

So down to just 5 assembler instructions.

That's probably neat. And yes, I know it is inefficient.

BFN. Paul.

Re: serial port

<2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=414&group=comp.lang.asm.x86#414

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.uzoreto.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Thu, 13 Apr 2023 04:05:42 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 82
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
<u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Thu, 13 Apr 2023 11:05:43 +0000
Injection-Info: dont-email.me; posting-host="ac7cc60de739c79ad638e1c816358a3e";
logging-data="3194545"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+EkJ0JoRk27S1Ni/0V7NW4NSWkaQM6+0M="
User-Agent: G2/1.0
Cancel-Lock: sha1:CVw/EEPN2+2n8ebd/Hwsgmv1BCk=
 by: Paul Edwards - Thu, 13 Apr 2023 11:05 UTC

I committed code that I expected to work:

https://sourceforge.net/p/pdos/gitcode/ci/3260d2aabe9f133f89bae3f9148070c188eb42b1/

But I am only getting the first character transmitted,
and then it never returns, thus never reboots.

So I need to begin debugging.

BFN. Paul.

#ifdef __32BIT__
static void writecomm(int port, int ch)
{ UART uart;
unsigned long old1;
unsigned long old2;
unsigned long intdesc1;
unsigned long intdesc2;
unsigned long intaddr;
int xch;
int intno = 4;
int imr = 0x21;

uartInit(&uart);
uartAddress(&uart, 0x3f8);
uartDisableInts(&uart);
/* IRQs 0-7 are at 0xb0 instead of 8 now */
/* we are using IRQ 4 for COM1 */
old1 = G_intloc[(intno + 0xb0) * 2];
old2 = G_intloc[(intno + 0xb0) * 2 + 1];
intaddr = (unsigned long)hltinthit;

/* we are interested in this interrupt */
xch = PREADB(imr);
xch &= ~(1 << (intno % 8));
PWRITEB(imr, xch);

uartEnableGPO2(&uart);

uartEnableTBE(&uart);
intdesc1 = (0x8 << 16) | (intaddr & 0xffff);
intdesc2 = (intaddr & 0xffff0000)
| (1 << 15)
| (0 << 13)
| (0x0e << 8);
disable();
G_intloc[(intno + 0xb0) * 2] = intdesc1;
G_intloc[(intno + 0xb0) * 2 + 1] = intdesc2;
uartTxCh(&uart, ch);
hltintgo();
G_intloc[(intno + 0xb0) * 2] = old1;
G_intloc[(intno + 0xb0) * 2 + 1] = old2;
enable();
PosReboot();
uartReset(&uart);
} #endif

/ enable interrupts and then halt until interrupt hit
_hltintgo:
sti
hloop:
/ I believe hlt will be interrupted by other interrupts, like
/ the timer interrupt, so we need to do it in a loop
hlt
jmp hloop
_hltinthit:
/ remove return address, segment and flags from the stack as we
/ do not intend to return to the jmp following the hlt instruction
/ that was likely interrupted
add %esp, 12
/ note that interrupts will be disabled again (I think) by virtue
/ of the fact that an interrupt occurred. The caller would have
/ disabled interrupts already, so we are returning to the same
/ disabled state.
ret

Re: serial port

<u18rsu$n4o6$1@flame.srcf.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=415&group=comp.lang.asm.x86#415

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: andrew@nospicedham.cam.ac.uk (Andrew Cooper)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Thu, 13 Apr 2023 13:17:34 +0100
Organization: Student-Run Computing Facility (SRCF)
Lines: 47
Sender: amc96@news.srcf.net
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <u18rsu$n4o6$1@flame.srcf.net>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
<u14b9q$2mq6r$1@dont-email.me>
<e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
<2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="ac7cc60de739c79ad638e1c816358a3e";
logging-data="3198197"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/qDt/z3aYOnmA8XitIxrurU/BMAnJzCC4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.10.0
Cancel-Lock: sha1:jWYRr6IXHDf25hJQDfquDJj2XuY=
 by: Andrew Cooper - Thu, 13 Apr 2023 12:17 UTC

On 13/04/2023 12:05 pm, Paul Edwards wrote:
> / enable interrupts and then halt until interrupt hit
> _hltintgo:
> sti
> hloop:
> / I believe hlt will be interrupted by other interrupts, like
> / the timer interrupt, so we need to do it in a loop
> hlt
> jmp hloop
> _hltinthit:
> / remove return address, segment and flags from the stack as we
> / do not intend to return to the jmp following the hlt instruction
> / that was likely interrupted
> add %esp, 12
> / note that interrupts will be disabled again (I think) by virtue
> / of the fact that an interrupt occurred. The caller would have
> / disabled interrupts already, so we are returning to the same
> / disabled state.
> ret

This is why things get stuck.

The first time through, you hlt with interrupts enabled, so will wake up
on the fist interrupt.

But when you loop, you'll hlt again, this time with interrupts disabled,
and will never ever wake up again (other than for an NMI).

Your loop needs to read:

_hltintgo:
sti
hlt
cli
jmp _hltintgo
_hltinthit:
...

to make things work as you intend.

sti;hlt as a pair is important for getting the blocked-by-STI shadow to
cover you into the hlt state, but it only works on the rising edge of
IF, so you need to explicitly clear interrupts in order to make the
sti;hlt on the second loop iteration work.

~Andrew

Re: serial port

<ad2619bb-555d-4710-9ec5-302739ce356dn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=416&group=comp.lang.asm.x86#416

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Thu, 13 Apr 2023 09:26:54 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 54
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <ad2619bb-555d-4710-9ec5-302739ce356dn@googlegroups.com>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
<u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
<2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com> <u18rsu$n4o6$1@flame.srcf.net>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Thu, 13 Apr 2023 16:26:54 +0000
Injection-Info: dont-email.me; posting-host="ac7cc60de739c79ad638e1c816358a3e";
logging-data="3209424"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FO8DsGz/mNhoev0k5iARGqflffLJ2rik="
User-Agent: G2/1.0
Cancel-Lock: sha1:xnbfTLO8+scbWIjBYs8U/XP52QU=
 by: Paul Edwards - Thu, 13 Apr 2023 16:26 UTC

On Thursday, April 13, 2023 at 8:27:03 PM UTC+8, Andrew Cooper wrote:

Hi Andrew. Thanks for your reply.

> The first time through, you hlt with interrupts enabled, so will wake up
> on the fist interrupt.
>
> But when you loop, you'll hlt again, this time with interrupts disabled,
> and will never ever wake up again (other than for an NMI).

I'm not expecting that behavior. I'm expecting the first
interrupt to move me to the hltinthit location and I never
return to the jmp.

Only a timer interrupt is expected to interfere with that,
and I would have expected that to be unlikely. And also
I expect the timer interrupt to do a rti and restore the
interrupt status to enabled.

I made the change anyway:

https://sourceforge.net/p/pdos/gitcode/ci/cdd5921434e5a827ad29d0024d456b059d9188b4/

But it still hangs.

I assume I haven't set up the interrupt properly.

BFN. Paul.

/ enable interrupts and then halt until interrupt hit
_hltintgo:
hloop:
/ I believe hlt will be interrupted by other interrupts, like
/ the timer interrupt, so we need to do it in a loop
sti
hlt
cli
jmp hloop
_hltinthit:
/ remove return address, segment and flags from the stack as we
/ do not intend to return to the jmp following the hlt instruction
/ that was likely interrupted
add %esp, 12
/ note that interrupts will be disabled again (I think) by virtue
/ of the fact that an interrupt occurred. The caller would have
/ disabled interrupts already, so we are returning to the same
/ disabled state.
ret

Re: serial port

<u1a5og$16ilp$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=417&group=comp.lang.asm.x86#417

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: sean@nospicedham.conman.org
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Fri, 14 Apr 2023 00:12:01 -0000 (UTC)
Organization: Conman Laboratories
Lines: 35
Sender: Sean Conner <spc@lucy.roswell.conman.org>
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <u1a5og$16ilp$1@dont-email.me>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com> <u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com> <2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com>
Reply-To: sean@conman.org
Injection-Info: dont-email.me; posting-host="c249b9a11c7a443d397868aac5af813e";
logging-data="3325370"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ZABFZUuqZ9GuzH2KQvG0JZnlbLiv9/WU="
User-Agent: tin/2.4.0-20160823 ("Octomore") (UNIX) (Linux/2.6.9-100.EL.plus.c4smp (i686))
Cancel-Lock: sha1:mnoxiTl4Nq9rM9zrb1zJG7Saqgg=
 by: sean@nospicedham.conman.org - Fri, 14 Apr 2023 00:12 UTC

It was thus said that the Great Paul Edwards <mutazilah@nospicedham.gmail.com> once stated:
> I committed code that I expected to work:
>
> https://sourceforge.net/p/pdos/gitcode/ci/3260d2aabe9f133f89bae3f9148070c188eb42b1/
>
> But I am only getting the first character transmitted,
> and then it never returns, thus never reboots.
>
> So I need to begin debugging.

So if you are writing code that only runs one program at a time, why do
you even need to mess with interrupts in the first place? Assuming a C
funcion inb() to read a byte from an IO port, and outb() to write a byte to
an IO port, I would think this would work:

/* Assuming UART has been initialized, but its IRQ has been disabled */
static void writecomm(int c)
{
/* read line status register to detect if the xmit buffer */
/* is ready to send. */

while (inb(0x3f8+5) & 0x20 == 0)
{
/* do nothing but wait */
}

/* we can now write the data */
outb(0x3f8,c);
}

It seems simpler to me than trying to muck with interrupts and adjusting
the return stack and all that.

-spc

Re: serial port

<2715a587-a99a-4173-8a96-0656a92e24fbn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=418&group=comp.lang.asm.x86#418

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!news.chmurka.net!nntp.terraraq.uk!nntp-feed.chiark.greenend.org.uk!ewrotcd!maths.tcd.ie!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Thu, 13 Apr 2023 19:59:08 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 46
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <2715a587-a99a-4173-8a96-0656a92e24fbn@googlegroups.com>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
<u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
<2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com> <u1a5og$16ilp$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Fri, 14 Apr 2023 02:59:09 +0000
Injection-Info: dont-email.me; posting-host="c249b9a11c7a443d397868aac5af813e";
logging-data="3329567"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BEKUeFqIUNdrHyFMpY8+W+ZWrl63rHek="
User-Agent: G2/1.0
Cancel-Lock: sha1:Tq0xI84uNNbusyjbWVjOo/y0wAI=
 by: Paul Edwards - Fri, 14 Apr 2023 02:59 UTC

On Friday, April 14, 2023 at 9:33:57 AM UTC+8, se...@nospicedham.conman.org wrote:
> It was thus said that the Great Paul Edwards <muta...@nospicedham.gmail.com> once stated:
> > I committed code that I expected to work:
> >
> > https://sourceforge.net/p/pdos/gitcode/ci/3260d2aabe9f133f89bae3f9148070c188eb42b1/
> >
> > But I am only getting the first character transmitted,
> > and then it never returns, thus never reboots.
> >
> > So I need to begin debugging.
> So if you are writing code that only runs one program at a time, why do
> you even need to mess with interrupts in the first place? Assuming a C
> funcion inb() to read a byte from an IO port, and outb() to write a byte to
> an IO port, I would think this would work:
>
> /* Assuming UART has been initialized, but its IRQ has been disabled */
> static void writecomm(int c)
> {
> /* read line status register to detect if the xmit buffer */
> /* is ready to send. */
>
> while (inb(0x3f8+5) & 0x20 == 0)
> {
> /* do nothing but wait */
> }
>
> /* we can now write the data */
> outb(0x3f8,c);
> }
>
> It seems simpler to me than trying to muck with interrupts and adjusting
> the return stack and all that.
>
> -spc

My solution is in-between those two extremes.

I only support a single task but I don't run hot polling.

Re: serial port

<u1auah$1dm53$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=419&group=comp.lang.asm.x86#419

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: sean@nospicedham.conman.org
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Fri, 14 Apr 2023 07:11:13 -0000 (UTC)
Organization: Conman Laboratories
Lines: 77
Sender: Sean Conner <spc@lucy.roswell.conman.org>
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <u1auah$1dm53$1@dont-email.me>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com> <u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com> <2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com> <u1a5og$16ilp$1@dont-email.me> <2715a587-a99a-4173-8a96-0656a92e24fbn@googlegroups.com>
Reply-To: sean@conman.org
Injection-Info: dont-email.me; posting-host="c249b9a11c7a443d397868aac5af813e";
logging-data="3342077"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/R1cyxr9tlJ8Id1RP05Nq66dbx+HkZt+Y="
User-Agent: tin/2.4.0-20160823 ("Octomore") (UNIX) (Linux/2.6.9-100.EL.plus.c4smp (i686))
Cancel-Lock: sha1:KtxDol1Bc9yiqaRzVK6W5IyPlTY=
 by: sean@nospicedham.conman.org - Fri, 14 Apr 2023 07:11 UTC

It was thus said that the Great Paul Edwards <mutazilah@nospicedham.gmail.com> once stated:
>> So if you are writing code that only runs one program at a time, why do
>> you even need to mess with interrupts in the first place? Assuming a C
>> funcion inb() to read a byte from an IO port, and outb() to write a byte to
>> an IO port, I would think this would work:
>>
>> /* Assuming UART has been initialized, but its IRQ has been disabled */
>> static void writecomm(int c)
>> {
>> /* read line status register to detect if the xmit buffer */
>> /* is ready to send. */
>>
>> while (inb(0x3f8+5) & 0x20 == 0)
>> {
>> /* do nothing but wait */
>> }
>>
>> /* we can now write the data */
>> outb(0x3f8,c);
>> }
>>
>> It seems simpler to me than trying to muck with interrupts and adjusting
>> the return stack and all that.
>
> My solution is in-between those two extremes.
>
> I only support a single task but I don't run hot polling.

Okay. If this is on a x86 system (an assumption on my part), and you
don't want to poll, then this method might work. The interrupt handler does
little more than sending the EOI (end of interrupt) to the 8259 PIC:

uart_irq_handler:
push ax ; eax if 32 bit
mov al,20h
out 020h,al ; signal end of interrupt
pop ax
iret

and then your transmit routine (in assembly):

; assume character to transmit in AL
; also assume that the transmitter
; register is empty

mov dx,[port] ; get port address
out dx,al ; write character
inc dx ; point to interrupt enable reg
in al,dx
or al,2 ; enable transmit
out dx,al
inc dx ; now point to interrupt ID reg

pause:
hlt ; halt CPU

; read interrupt ID reg; this also clears the IRQ on the serial chip
; and checks to see if we're the cause of the IRQ, and not something
; else like the keyboard.

in al,dx
and al,0eh ; isolate interrupt ID bits
cmp al,2 ; transmitter empty bit IRQ?
bne pause ; we're not the cause, keep waiting
dec dx ; point back to interrupt enable reg
in al,dx
and al,0FDh ; disable transmit empty IRQ
out dx,al

; and we're done with transmitting the character

I think you may not have been telling the 8259 that the IRQ has been
handled. But you also need to clear the IRQ from the UART itself as well,
which you might not have been doing.

-spc

Re: serial port

<c22a922c-3149-4b28-959f-3ff5e9438bfdn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=420&group=comp.lang.asm.x86#420

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Fri, 14 Apr 2023 09:55:12 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 120
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <c22a922c-3149-4b28-959f-3ff5e9438bfdn@googlegroups.com>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
<u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
<2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Fri, 14 Apr 2023 16:55:13 +0000
Injection-Info: dont-email.me; posting-host="be257f48dc72a90c7e425e50d583f199";
logging-data="1982369"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Gko35pFAH7itIiEz2FW9oylk7wJUkbeI="
User-Agent: G2/1.0
Cancel-Lock: sha1:h/zxPgzuJ3bPtaYL094OBDUWu6o=
 by: Paul Edwards - Fri, 14 Apr 2023 16:55 UTC

On Thursday, April 13, 2023 at 7:11:58 PM UTC+8, Paul Edwards wrote:
> I committed code that I expected to work:
>
> So I need to begin debugging.

> add %esp, 12

This was the main problem.

Should have been add $12, %esp

Current status is that it is outputting the first character,
then it is printing "id is 2" (TBE) then "id is 0" (no pending),
and then no further screen output, but there is another
character that goes to the com port, but not the expected
character, so I would expect that means it is transmitting
instead of waiting for the interrupt, but I don't see how it
can get ahead of itself.

I've tried lots of things, still don't understand what is happening.

I'll try debugging again when I wake up.

BFN. Paul.

/ enable interrupts and then halt until interrupt hit
_hltintgo:
hloop:
/ I believe hlt will be interrupted by other interrupts, like
/ the timer interrupt, so we need to do it in a loop
sti
hlt
cli
jmp hloop
_hltinthit:
/ remove return address, segment and flags from the stack as we
/ do not intend to return to the jmp following the hlt instruction
/ that was likely interrupted
add $12, %esp
/ note that interrupts will be disabled again (I think) by virtue
/ of the fact that an interrupt occurred. The caller would have
/ disabled interrupts already, so we are returning to the same
/ disabled state.
ret

#ifdef __32BIT__
static void writecomm(int port, int ch)
{ UART uart;
unsigned long old1;
unsigned long old2;
unsigned long intdesc1;
unsigned long intdesc2;
unsigned long intaddr;
int xch;
int intno = 4;
int a8259 = 0x20;
int imr = 0x21;
int id;

uartInit(&uart);
uartAddress(&uart, 0x3f8);
PREADB(a8259); /* we don't use the result of this */
uartDisableInts(&uart);
/* IRQs 0-7 are at 0xb0 instead of 8 now */
/* we are using IRQ 4 for COM1 */
old1 = G_intloc[(intno + 0xb0) * 2];
old2 = G_intloc[(intno + 0xb0) * 2 + 1];
intaddr = (unsigned long)hltinthit;

/* we are interested in this interrupt */
xch = PREADB(imr);
xch &= ~(1 << (intno % 8));
PWRITEB(imr, xch);

uartEnableGPO2(&uart);

uartEnableTBE(&uart);
/* uartEnableModem(&uart); */
/* uartRaiseDTR(&uart); */
/* uartRaiseRTS(&uart); */
/* uartCTS(&uart); */
intdesc1 = (0x8 << 16) | (intaddr & 0xffff);
intdesc2 = (intaddr & 0xffff0000)
| (1 << 15)
| (0 << 13)
| (0x0e << 8);
disable();
G_intloc[(intno + 0xb0) * 2] = intdesc1;
G_intloc[(intno + 0xb0) * 2 + 1] = intdesc2;
uartTxCh(&uart, ch);
hltintgo();
enable();
do
{
id = uartGetIntType(&uart);
printf("id is %d\n", id);
} while (id != UART_NO_PENDING);
PWRITEB(0x20, 0x20);
uartDisableInts(&uart);
uartDisableGPO2(&uart);

xch = PREADB(imr);
xch |= (1 << (intno % 8));
PWRITEB(imr, xch);

uartReset(&uart);
uartTerm(&uart);

disable();
G_intloc[(intno + 0xb0) * 2] = old1;
G_intloc[(intno + 0xb0) * 2 + 1] = old2;
enable();
} #endif

Re: serial port

<1788b1d4-40ea-4a6f-a6ef-5c0bf4b1cd92n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=421&group=comp.lang.asm.x86#421

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Sat, 15 Apr 2023 02:29:14 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 33
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <1788b1d4-40ea-4a6f-a6ef-5c0bf4b1cd92n@googlegroups.com>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
<u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
<2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com> <c22a922c-3149-4b28-959f-3ff5e9438bfdn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Sat, 15 Apr 2023 09:29:15 +0000
Injection-Info: dont-email.me; posting-host="be257f48dc72a90c7e425e50d583f199";
logging-data="2093901"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19MTyEMHkQtta5r1Q+8KYn7p++LHYaEN2c="
User-Agent: G2/1.0
Cancel-Lock: sha1:lumHOSnEywWAblmtAzEGx3XTepI=
 by: Paul Edwards - Sat, 15 Apr 2023 09:29 UTC

On Saturday, April 15, 2023 at 10:20:57 AM UTC+8, Paul Edwards wrote:

> uartEnableTBE(&uart);

I have found that I need this in order to get an
interrupt, as expected.

> uartTxCh(&uart, ch);

But I was surprised to find that I didn't need this.

Basically it appears that TBE wakes up once to let
me know that it is currently empty, but once I start
sending it data, and then halting, it doesn't feel the
need to let me know it is empty again.

But my whole design is centered around being
informed of that.

Maybe what is happening is that interrupts are disabled
so often/sometimes the character is transmitted
immediately and it isn't allowed to interrupt, so it doesn't.

I then enable interrupts and hlt but the show is already over.

So maybe what I need to do instead is send the character
after enabling interrupts.

I'll try that next. Not as neat as the previous generic solution.

BFN. Paul.

Re: serial port

<93062fbe-ad7f-489c-8525-b68922dfaa89n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=422&group=comp.lang.asm.x86#422

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Sat, 15 Apr 2023 05:44:53 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 27
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <93062fbe-ad7f-489c-8525-b68922dfaa89n@googlegroups.com>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
<u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
<2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com> <c22a922c-3149-4b28-959f-3ff5e9438bfdn@googlegroups.com>
<1788b1d4-40ea-4a6f-a6ef-5c0bf4b1cd92n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Sat, 15 Apr 2023 12:44:53 +0000
Injection-Info: dont-email.me; posting-host="be257f48dc72a90c7e425e50d583f199";
logging-data="2158298"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XW9K8qXjQNN5vODymANiut8L3JszBWls="
User-Agent: G2/1.0
Cancel-Lock: sha1:JDsWL0PBQcJNXiS1ecFZzi1k6Lk=
 by: Paul Edwards - Sat, 15 Apr 2023 12:44 UTC

On Saturday, April 15, 2023 at 5:36:19 PM UTC+8, Paul Edwards wrote:

> > uartEnableTBE(&uart);

So far I have confirmed that after I have issued this
(but without installing my own interrupt handler),
I can read the uart to find out what interrupts are
available and I see that TBE is the only one.

I think transmit a byte, and I do get an interrupt,
so I do get an additional interrupt even though
I've read all the previous ones.

Then when I go through for the second time, enabling
TBE does the same thing, and I read the same thing
from the uart.

But this time when I try to transmit a byte I either don't
get an interrupt or I get a hang for some other reason.

So I don't know what is going on.

If I can get consistent behavior I can have a simple design.

BFN. Paul.

Re: serial port

<8d15d0b8-7b81-4695-a396-bceb04266f33n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=423&group=comp.lang.asm.x86#423

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Sat, 15 Apr 2023 07:24:27 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 101
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <8d15d0b8-7b81-4695-a396-bceb04266f33n@googlegroups.com>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
<u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
<2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com> <c22a922c-3149-4b28-959f-3ff5e9438bfdn@googlegroups.com>
<1788b1d4-40ea-4a6f-a6ef-5c0bf4b1cd92n@googlegroups.com> <93062fbe-ad7f-489c-8525-b68922dfaa89n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Sat, 15 Apr 2023 14:24:27 +0000
Injection-Info: dont-email.me; posting-host="be257f48dc72a90c7e425e50d583f199";
logging-data="2187837"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/B0dJjAKY9Ngv57u6epglfgmBJAmnAmKQ="
User-Agent: G2/1.0
Cancel-Lock: sha1:swUwucqxfs4zwDnVcmFfV2u32Bs=
 by: Paul Edwards - Sat, 15 Apr 2023 14:24 UTC

I finally realized that since I'm getting an interrupt from
the TBE enable (for unknown reasons), then if I moved
the disable (cli) before that, then by the time I had
outputted a byte, the interrupt would still be pending
and even if I didn't get one for the outputted byte, it
was enough to get one for the TBE call.

And now it is working, with the simple design.

I will look into refinements now that the basics are working.

static void writecomm(int port, int ch)
{ UART uart;
unsigned long old1;
unsigned long old2;
unsigned long intdesc1;
unsigned long intdesc2;
unsigned long intaddr;
int xch;
int intno = 4;
int a8259 = 0x20;
int imr = 0x21;
int id;

uartInit(&uart);
uartAddress(&uart, 0x3f8);
PREADB(a8259); /* we don't use the result of this */
uartDisableInts(&uart);
/* IRQs 0-7 are at 0xb0 instead of 8 now */
/* we are using IRQ 4 for COM1 */
old1 = G_intloc[(intno + 0xb0) * 2];
old2 = G_intloc[(intno + 0xb0) * 2 + 1];
intaddr = (unsigned long)hltinthit;

/* we are interested in this interrupt */
xch = PREADB(imr);
xch &= ~(1 << (intno % 8));
PWRITEB(imr, xch);

disable();
uartEnableGPO2(&uart);

uartEnableTBE(&uart);
/* uartEnableModem(&uart); */
/* uartRaiseDTR(&uart); */
/* uartRaiseRTS(&uart); */
/* uartCTS(&uart); */
intdesc1 = (0x8 << 16) | (intaddr & 0xffff);
intdesc2 = (intaddr & 0xffff0000)
| (1 << 15)
| (0 << 13)
| (0x0e << 8);
G_intloc[(intno + 0xb0) * 2] = intdesc1;
G_intloc[(intno + 0xb0) * 2 + 1] = intdesc2;
uartTxCh(&uart, ch);
hltintgo();
enable();
do
{
id = uartGetIntType(&uart);
} while (id != UART_NO_PENDING);
PWRITEB(0x20, 0x20);
uartDisableInts(&uart);
uartDisableGPO2(&uart);

xch = PREADB(imr);
xch |= (1 << (intno % 8));
PWRITEB(imr, xch);

uartReset(&uart);
uartTerm(&uart);

disable();
G_intloc[(intno + 0xb0) * 2] = old1;
G_intloc[(intno + 0xb0) * 2 + 1] = old2;
enable();
}

/ enable interrupts and then halt until interrupt hit
_hltintgo:
hloop:
/ I believe hlt will be interrupted by other interrupts, like
/ the timer interrupt, so we need to do it in a loop
sti
hlt
cli
jmp hloop
_hltinthit:
/ remove return address, segment and flags from the stack as we
/ do not intend to return to the jmp following the hlt instruction
/ that was likely interrupted
add $12, %esp
/ note that interrupts will be disabled again (I think) by virtue
/ of the fact that an interrupt occurred. The caller would have
/ disabled interrupts already, so we are returning to the same
/ disabled state.
ret

Re: serial port

<913b01e7-aae1-4673-81d8-a6ee38f79fadn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=424&group=comp.lang.asm.x86#424

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Sat, 15 Apr 2023 14:13:50 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 42
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <913b01e7-aae1-4673-81d8-a6ee38f79fadn@googlegroups.com>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
<u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
<2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com> <c22a922c-3149-4b28-959f-3ff5e9438bfdn@googlegroups.com>
<1788b1d4-40ea-4a6f-a6ef-5c0bf4b1cd92n@googlegroups.com> <93062fbe-ad7f-489c-8525-b68922dfaa89n@googlegroups.com>
<8d15d0b8-7b81-4695-a396-bceb04266f33n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Sat, 15 Apr 2023 21:13:51 +0000
Injection-Info: dont-email.me; posting-host="be257f48dc72a90c7e425e50d583f199";
logging-data="2302954"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+zwmMUm0Bl/VxrlxErNdNALAy8HjUoP8Y="
User-Agent: G2/1.0
Cancel-Lock: sha1:bhKdVYQW/trfrzWzUyvQtyGrybg=
 by: Paul Edwards - Sat, 15 Apr 2023 21:13 UTC

On Saturday, April 15, 2023 at 10:36:37 PM UTC+8, Paul Edwards wrote:

> I finally realized that since I'm getting an interrupt from
> the TBE enable (for unknown reasons), then if I moved
> the disable (cli) before that, then by the time I had
> outputted a byte, the interrupt would still be pending
> and even if I didn't get one for the outputted byte, it
> was enough to get one for the TBE call.
>
> And now it is working, with the simple design.

Note that it is working (and previously failing) under
Bochs. I haven't tried real hardware yet.

And now I realize there may be a problem with the
current code.

Let's say the serial port is slow.

The sequence I am doing is enabling TBE and then outputting
a byte.

Enabling TBE generates an interrupt, but outputting the byte
only randomly does (could also be a Bochs bug).

Because I am now relying on the TBE enable interrupt to get
me out of the HLT loop, I am no longer have the desired
constraint on the OUT instruction completing.

Meaning the second time through the loop, the second OUT
could be executed before the first one has completed.

If the UART discards the TBE interrupt when it realizes that
it is no longer the case that the transmit buffer is empty,
because there has been an OUT instruction issued since
then, then my current design should work.

Does anyone know what is happening?

Thanks. Paul.

Re: serial port

<u1f5no$26e4a$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=425&group=comp.lang.asm.x86#425

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: terje.mathisen@nospicedham.tmsw.no (Terje Mathisen)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Sat, 15 Apr 2023 23:42:17 +0200
Organization: A noiseless patient Spider
Lines: 51
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <u1f5no$26e4a$1@dont-email.me>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
<u14b9q$2mq6r$1@dont-email.me>
<e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
<2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com>
<c22a922c-3149-4b28-959f-3ff5e9438bfdn@googlegroups.com>
<1788b1d4-40ea-4a6f-a6ef-5c0bf4b1cd92n@googlegroups.com>
<93062fbe-ad7f-489c-8525-b68922dfaa89n@googlegroups.com>
<8d15d0b8-7b81-4695-a396-bceb04266f33n@googlegroups.com>
<913b01e7-aae1-4673-81d8-a6ee38f79fadn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="be257f48dc72a90c7e425e50d583f199";
logging-data="2311541"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/l4zfqiRlMottkU5A3gFht7Cls3HjHnTE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.16
Cancel-Lock: sha1:rR4bjqthQ7z7/kd6+qdxoYMJ8Y0=
 by: Terje Mathisen - Sat, 15 Apr 2023 21:42 UTC

Paul Edwards wrote:
> On Saturday, April 15, 2023 at 10:36:37 PM UTC+8, Paul Edwards wrote:
>
>> I finally realized that since I'm getting an interrupt from
>> the TBE enable (for unknown reasons), then if I moved
>> the disable (cli) before that, then by the time I had
>> outputted a byte, the interrupt would still be pending
>> and even if I didn't get one for the outputted byte, it
>> was enough to get one for the TBE call.
>>
>> And now it is working, with the simple design.
>
> Note that it is working (and previously failing) under
> Bochs. I haven't tried real hardware yet.
>
> And now I realize there may be a problem with the
> current code.
>
> Let's say the serial port is slow.
>
> The sequence I am doing is enabling TBE and then outputting
> a byte.
>
> Enabling TBE generates an interrupt, but outputting the byte
> only randomly does (could also be a Bochs bug).
>
> Because I am now relying on the TBE enable interrupt to get
> me out of the HLT loop, I am no longer have the desired
> constraint on the OUT instruction completing.
>
> Meaning the second time through the loop, the second OUT
> could be executed before the first one has completed.
>
> If the UART discards the TBE interrupt when it realizes that
> it is no longer the case that the transmit buffer is empty,
> because there has been an OUT instruction issued since
> then, then my current design should work.
>
> Does anyone know what is happening?
>
> Thanks. Paul.
>
How do you guarantee that the interrupt is directed to your thread
that's sitting in a HLT state?

Terje

--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Re: serial port

<u1fbl9$27akr$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=426&group=comp.lang.asm.x86#426

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: sean@nospicedham.conman.org
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Sat, 15 Apr 2023 23:23:22 -0000 (UTC)
Organization: Conman Laboratories
Lines: 91
Sender: Sean Conner <spc@lucy.roswell.conman.org>
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <u1fbl9$27akr$1@dont-email.me>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com> <u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com> <2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com> <c22a922c-3149-4b28-959f-3ff5e9438bfdn@googlegroups.com> <1788b1d4-40ea-4a6f-a6ef-5c0bf4b1cd92n@googlegroups.com> <93062fbe-ad7f-489c-8525-b68922dfaa89n@googlegroups.com> <8d15d0b8-7b81-4695-a396-bceb04266f33n@googlegroups.com>
Reply-To: sean@conman.org
Injection-Info: dont-email.me; posting-host="4268555b5cfb331527b14cec0a33b8fc";
logging-data="2341673"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+EVXA+P53eVloRn35oSDA0EYXz7y/pnfs="
User-Agent: tin/2.4.0-20160823 ("Octomore") (UNIX) (Linux/2.6.9-100.EL.plus.c4smp (i686))
Cancel-Lock: sha1:r6iGquFoJ5jlItVBhbP8eu0C7K0=
 by: sean@nospicedham.conman.org - Sat, 15 Apr 2023 23:23 UTC

I replied once with some code, but it seems you didn't see it, so I'm
replying again.

It was thus said that the Great Paul Edwards <mutazilah@nospicedham.gmail.com> once stated:
>
> And now it is working, with the simple design.
>
> I will look into refinements now that the basics are working.
>
> static void writecomm(int port, int ch)
> {
...

> old1 = G_intloc[(intno + 0xb0) * 2];
> old2 = G_intloc[(intno + 0xb0) * 2 + 1];
> intaddr = (unsigned long)hltinthit;

...

> intdesc1 = (0x8 << 16) | (intaddr & 0xffff);
> intdesc2 = (intaddr & 0xffff0000)
> | (1 << 15)
> | (0 << 13)
> | (0x0e << 8);
> G_intloc[(intno + 0xb0) * 2] = intdesc1;
> G_intloc[(intno + 0xb0) * 2 + 1] = intdesc2;

...

> G_intloc[(intno + 0xb0) * 2] = old1;
> G_intloc[(intno + 0xb0) * 2 + 1] = old2;

...

> }

Why are you installing, then uninstalling, the interrupt handler for each
character? And I think you are making this out to be more complicated that
it should be. As I wrote before, the interrupt handler for the UART can be
as simple as:

uart_irq_handler:
push ax ; or eax if 32-bit
mov al,20h ; sent end-of-interrupt to 8259 PIC
out 20h,al
pop ax
iret

That's it. No mucking with return addresses, or CLI/STI instructions or
anything like that. Let the interrupt happen, and inform the 8259 it's been
handled. Set the vector once, and be done with it.

And the code to transmit the character, which assumes the UART has been
initialized with the baud rate and bit settings:

; assume character to transmit is in AL
; also assume the transmitter register
; is empty

mov dx,[port] ; get port address
out dx,al ; send the character
inc dx ; point to interrupt enable register
in al,dx ; read current setting
or al,2 ; set transmitter empty IRQ
out dx,al ; tell UART
inc dx ; point to interrupt ID register

pause:

hlt ; halt CPU

; read interrupt ID reg; this also clears the IRQ on the serial chip
; and checks to see if we're the cause of the IRQ, and not something
; else like the keyboard.

in al,dx ; read UART interrupt register
and al,0eh ; isolate source of interrupt bits
cmp al,2 ; is it the transmitter empty IRQ?
bne pause ; if not, keep waiting
dec dx ; point to interrupt enable register
in al,dx ; read current setting
and al,0FDh ; disable transmit empty IRQ
out dx,al

; and we're done with transmitting the character

You need to tell both the 8259 and the UART that the interrupt has been
handled.

-spc

Re: serial port

<b21e7bbc-0f85-497f-891a-ee3d90a558fan@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=428&group=comp.lang.asm.x86#428

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Sat, 15 Apr 2023 18:19:12 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 63
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <b21e7bbc-0f85-497f-891a-ee3d90a558fan@googlegroups.com>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
<u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
<2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com> <c22a922c-3149-4b28-959f-3ff5e9438bfdn@googlegroups.com>
<1788b1d4-40ea-4a6f-a6ef-5c0bf4b1cd92n@googlegroups.com> <93062fbe-ad7f-489c-8525-b68922dfaa89n@googlegroups.com>
<8d15d0b8-7b81-4695-a396-bceb04266f33n@googlegroups.com> <u1fbl9$27akr$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Sun, 16 Apr 2023 01:19:12 +0000
Injection-Info: dont-email.me; posting-host="4268555b5cfb331527b14cec0a33b8fc";
logging-data="2493689"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19WraLMIvKcm/gen64UvH88Od/ZyFDoLms="
User-Agent: G2/1.0
Cancel-Lock: sha1:Dqk7otdHHyXyBOtzuO5Iw2M5gPc=
 by: Paul Edwards - Sun, 16 Apr 2023 01:19 UTC

On Sunday, April 16, 2023 at 7:37:08 AM UTC+8, se...@nospicedham.conman.org wrote:

> I replied once with some code, but it seems you didn't see it, so I'm
> replying again.

Sorry. I wasn't sure what to reply with, and I was still in
the process of debugging. Yours a different design,
and assembler-focused. I know this is an assembler group,
and I am indeed using assembler, but I'm trying to minimize it.
The required minimal assembler has already changed
numerous times to try to get this very basic functionality
working.

I'm not disputing that it wouldn't work or be better.

But I have a different design I am trying to get to work.
(and it should work - and the fact that it only half-works
is exactly what I want to see and understand).

> Why are you installing, then uninstalling, the interrupt handler for each
> character?

So that I can see an understandable sequence until I
am happy that the sequence is right.

I can potentially move that later. But I probably won't,
because the interrupt may be shared. And code
elsewhere would use the same assembler routine,
same interrupt number, same simple logic, and still work.

> And I think you are making this out to be more complicated that
> it should be.

It is more complicated for an assembler programmer, but
not more complicated for a (or at least, this) C programmer,
because almost all the logic is in C.

> As I wrote before, the interrupt handler for the UART can be
> as simple as:
>
> pause:
>
> hlt ; halt CPU
>
....
> bne pause ; if not, keep waiting

And I can't move this code out into C, due to this requiring
the stack pointer isn't changed.

I don't wish to use inline assembler either - I want my
C code to be C90-compliant.

> You need to tell both the 8259 and the UART that the interrupt has been
> handled.

I believe my code does that.

BFN. Paul.

Re: serial port

<40014284-479f-47c6-8561-296ca1d1fa89n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=429&group=comp.lang.asm.x86#429

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Sat, 15 Apr 2023 18:08:23 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 17
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <40014284-479f-47c6-8561-296ca1d1fa89n@googlegroups.com>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
<u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
<2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com> <c22a922c-3149-4b28-959f-3ff5e9438bfdn@googlegroups.com>
<1788b1d4-40ea-4a6f-a6ef-5c0bf4b1cd92n@googlegroups.com> <93062fbe-ad7f-489c-8525-b68922dfaa89n@googlegroups.com>
<8d15d0b8-7b81-4695-a396-bceb04266f33n@googlegroups.com> <913b01e7-aae1-4673-81d8-a6ee38f79fadn@googlegroups.com>
<u1f5no$26e4a$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Sun, 16 Apr 2023 01:08:24 +0000
Injection-Info: dont-email.me; posting-host="4268555b5cfb331527b14cec0a33b8fc";
logging-data="2493674"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/VBHjYCHMBS+c8UB/V+bZkbGYGNjcEDv8="
User-Agent: G2/1.0
Cancel-Lock: sha1:rikFfoC9WEW1zOaOEO2aXlE80ss=
 by: Paul Edwards - Sun, 16 Apr 2023 01:08 UTC

On Sunday, April 16, 2023 at 5:52:00 AM UTC+8, Terje Mathisen wrote:

> How do you guarantee that the interrupt is directed to your thread
> that's sitting in a HLT state?

This is single-threading PDOS/386.

Simple, and understandable.

And once you have this system, you can use it to create
a more complicated system of your own. (And I may
choose to do that myself one day, but I'm getting
pretty old and I'm still on the simple system(s)).

BFN. Paul.

Re: serial port

<f4f4f70e-92be-46dd-8ef9-7458ee3286e8n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=432&group=comp.lang.asm.x86#432

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Sun, 16 Apr 2023 01:37:04 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 130
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <f4f4f70e-92be-46dd-8ef9-7458ee3286e8n@googlegroups.com>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
<u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
<2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com> <c22a922c-3149-4b28-959f-3ff5e9438bfdn@googlegroups.com>
<1788b1d4-40ea-4a6f-a6ef-5c0bf4b1cd92n@googlegroups.com> <93062fbe-ad7f-489c-8525-b68922dfaa89n@googlegroups.com>
<8d15d0b8-7b81-4695-a396-bceb04266f33n@googlegroups.com> <913b01e7-aae1-4673-81d8-a6ee38f79fadn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Sun, 16 Apr 2023 08:37:05 +0000
Injection-Info: dont-email.me; posting-host="4268555b5cfb331527b14cec0a33b8fc";
logging-data="2614686"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zQmxFBat9bp9q+x9BX8bgJWnp4oJ+cwk="
User-Agent: G2/1.0
Cancel-Lock: sha1:kb5f/FHSZAFkpqi25iND7ZhKIM0=
 by: Paul Edwards - Sun, 16 Apr 2023 08:37 UTC

On Sunday, April 16, 2023 at 5:21:57 AM UTC+8, Paul Edwards wrote:

> And now I realize there may be a problem with the
> current code.

I have now managed to test on real hardware.

I was surprised to see that INT 14H to initialize the
port is apparently working, as I was able to transmit
characters.

I was expecting to have to update PDOS to replace
the INT 14H initialization functionality.

However, when I copied a file to com1, most characters
were dropped.

So that bit of the theory was correct.

If I just copied a 1-byte file to com1, then copied another
1-byte file to com1, the characters both went through.

I then tried moving the disable() below the TBE enable in
the hope that the old (default) interrupt handler would
take care of that, and I would get my character. But that
would have created a timing issue even if it had worked.
Instead there was no change in behavior.

And then I figured that what I needed was consistency,
and that there should be two interrupts.

So I did a second call to hltintgo.

And this time it hung.

Fortunately I realized I need to repeat the read of the uart
and do the write to 0x20 and it worked on my real hardware.

And the same code worked on Bochs too.

So working code now below.

Thanks everyone for your thoughts.

BFN. Paul.

static void writecomm(int port, int ch)
{ UART uart;
unsigned long old1;
unsigned long old2;
unsigned long intdesc1;
unsigned long intdesc2;
unsigned long intaddr;
int xch;
int intno = 4;
int a8259 = 0x20;
int imr = 0x21;
int id;

uartInit(&uart);
uartAddress(&uart, 0x3f8);
PREADB(a8259); /* we don't use the result of this */
uartDisableInts(&uart);
/* IRQs 0-7 are at 0xb0 instead of 8 now */
/* we are using IRQ 4 for COM1 */
old1 = G_intloc[(intno + 0xb0) * 2];
old2 = G_intloc[(intno + 0xb0) * 2 + 1];
intaddr = (unsigned long)hltinthit;

/* we are interested in this interrupt */
xch = PREADB(imr);
xch &= ~(1 << (intno % 8));
PWRITEB(imr, xch);

uartEnableGPO2(&uart);

/* uartEnableModem(&uart); */
/* uartRaiseDTR(&uart); */
/* uartRaiseRTS(&uart); */
/* uartCTS(&uart); */
intdesc1 = (0x8 << 16) | (intaddr & 0xffff);
intdesc2 = (intaddr & 0xffff0000)
| (1 << 15)
| (0 << 13)
| (0x0e << 8);
disable();
G_intloc[(intno + 0xb0) * 2] = intdesc1;
G_intloc[(intno + 0xb0) * 2 + 1] = intdesc2;
/* for some reason just enabling the interrupt causes
an interrupt. But transmitting a character doesn't
necessarily generate an interrupt for some reason.
But by disabling the interrupts while both enabling
TBE and sending a character, we 'guarantee' that we
will receive an interrupt from at least one of those
so that the hlt instruction will be interrupted. */
uartEnableTBE(&uart);
hltintgo();
enable();
do
{
id = uartGetIntType(&uart);
} while (id != UART_NO_PENDING);
PWRITEB(0x20, 0x20);
disable();
uartTxCh(&uart, ch);
hltintgo();
enable();
do
{
id = uartGetIntType(&uart);
} while (id != UART_NO_PENDING);
PWRITEB(0x20, 0x20);
uartDisableInts(&uart);
uartDisableGPO2(&uart);

xch = PREADB(imr);
xch |= (1 << (intno % 8));
PWRITEB(imr, xch);

uartReset(&uart);
uartTerm(&uart);

disable();
G_intloc[(intno + 0xb0) * 2] = old1;
G_intloc[(intno + 0xb0) * 2 + 1] = old2;
enable();
}

Re: serial port

<a0385645-17c5-473d-a885-76ceddde2711n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=433&group=comp.lang.asm.x86#433

  copy link   Newsgroups: comp.lang.asm.x86
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mutazilah@nospicedham.gmail.com (Paul Edwards)
Newsgroups: comp.lang.asm.x86
Subject: Re: serial port
Date: Sun, 16 Apr 2023 17:44:53 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 88
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <a0385645-17c5-473d-a885-76ceddde2711n@googlegroups.com>
References: <65eaaa7f-3e19-4f37-833c-0d42cc019b4bn@googlegroups.com>
<u14b9q$2mq6r$1@dont-email.me> <e2274ef7-2035-4cc5-ada2-9dcfb5d09638n@googlegroups.com>
<2950aebb-1fd7-489b-af90-54a3f2d7302an@googlegroups.com> <c22a922c-3149-4b28-959f-3ff5e9438bfdn@googlegroups.com>
<1788b1d4-40ea-4a6f-a6ef-5c0bf4b1cd92n@googlegroups.com> <93062fbe-ad7f-489c-8525-b68922dfaa89n@googlegroups.com>
<8d15d0b8-7b81-4695-a396-bceb04266f33n@googlegroups.com> <913b01e7-aae1-4673-81d8-a6ee38f79fadn@googlegroups.com>
<f4f4f70e-92be-46dd-8ef9-7458ee3286e8n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 17 Apr 2023 00:44:53 +0000
Injection-Info: dont-email.me; posting-host="6da4003753ee92ebe583110a5457cf3e";
logging-data="2892069"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/VKwB4YybG6oAdrvMq94JHG/7mNJt9nBw="
User-Agent: G2/1.0
Cancel-Lock: sha1:P0HLXIjZLcaOdHMdcjItXmF9X4k=
 by: Paul Edwards - Mon, 17 Apr 2023 00:44 UTC

I have now added read functionality.

And I was able to reuse my existing assembler code.

So that's a great result.

But as per comments below, I did get two surprising
results attempting to get it to work, with a working
theory.

BFN. Paul.

static int readcomm(int port)
{ UART uart;
unsigned long old1;
unsigned long old2;
unsigned long intdesc1;
unsigned long intdesc2;
unsigned long intaddr;
int xch;
int intno = 4;
int a8259 = 0x20;
int imr = 0x21;
int id;
int ch;

uartInit(&uart);
uartAddress(&uart, 0x3f8);
PREADB(a8259); /* we don't use the result of this */
uartDisableInts(&uart);
/* IRQs 0-7 are at 0xb0 instead of 8 now */
/* we are using IRQ 4 for COM1 */
old1 = G_intloc[(intno + 0xb0) * 2];
old2 = G_intloc[(intno + 0xb0) * 2 + 1];
intaddr = (unsigned long)hltinthit;

/* we are interested in this interrupt */
xch = PREADB(imr);
xch &= ~(1 << (intno % 8));
PWRITEB(imr, xch);

uartEnableGPO2(&uart);

/* uartEnableModem(&uart); */
/* uartRaiseDTR(&uart); */
/* uartRaiseRTS(&uart); */
/* uartCTS(&uart); */
intdesc1 = (0x8 << 16) | (intaddr & 0xffff);
intdesc2 = (intaddr & 0xffff0000)
| (1 << 15)
| (0 << 13)
| (0x0e << 8);
disable();
G_intloc[(intno + 0xb0) * 2] = intdesc1;
G_intloc[(intno + 0xb0) * 2 + 1] = intdesc2;
uartEnableRxRDY(&uart);
hltintgo();
/* if I immediately disable UART interrupts, I can no
longer read the old pending id of RxRDY.
If I read the pending ids, RxRDY just gets reasserted,
presumably because I haven't actually read the
character yet.
If I try reading the character, a new character may
come in and I'll miss it.
So the safest thing to do is just disable interrupts
and assume that RxRDY was hit, since that was the only
thing actually enabled, and I don't bother reading the
interrupt ids. */
G_intloc[(intno + 0xb0) * 2] = old1;
G_intloc[(intno + 0xb0) * 2 + 1] = old2;
uartDisableInts(&uart);
enable();
ch = uartRecCh(&uart);
PWRITEB(0x20, 0x20);
uartDisableGPO2(&uart);

xch = PREADB(imr);
xch |= (1 << (intno % 8));
PWRITEB(imr, xch);

uartReset(&uart);
uartTerm(&uart);

return (ch);
}

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor