Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Programming and Minix

24 views
Skip to first unread message

Teemu Savolainen

unread,
May 27, 1998, 3:00:00 AM5/27/98
to

Is it possible to write program with CC that directly writes/reads memory
under Minix 2.0.0? I tried to find information about it on the web but I
didn't succeed.

I got old half-working 8086 for free and it had Minix installed in it. I'd
use dos/tasm for doing such programming but the floppy drive is broken and I
can't put dos to the hard disk without buying/finding working 5,25" floppy
drive. I will use that computer for experimenting - adding my home made
cards to ISA bus and so on.

Thank you for any help

Shawn Ramsey

unread,
May 27, 1998, 3:00:00 AM5/27/98
to

Teemu Savolainen (ts...@cc.tut.nospam.fi) wrote:
: Is it possible to write program with CC that directly writes/reads memory

You can do it like this:

#include <sys/types.h>
#include <fcntl.h>
main()
{
int f;
if((f=open("/dev/mem",O_RDWR))<0){
perror("/dev/mem");
return 1;
}
/* Insert your code here. */
return 0;
}

After opening /dev/mem you can write it like any normal file (via read(2) and
write(2)), my only question is, why? Unix-like OS's have kernels to prevent
user-space processses from doing things like this, and indeed a user process
that writes directly into system memory bypasses one of the kernel's most
important features (IMHO), separation of users from hardware. I would suggest
that if you need/want to write low-level code, you modify the kernel instead
of doing it from user-space. Although, you may want to start out with a user
process just to test your code and then hack the kernel source (that's what I
generally do if possible), this will save time, especially if you are
modifying large sections of the kernel code, since compilations are a tad on
the slow side when using the traditional processors (8086/88) thus you want to
make the large variety as infrequent as possible.

Just a thought,
Dave

Will Rose

unread,
May 28, 1998, 3:00:00 AM5/28/98
to

Teemu Savolainen (ts...@cc.tut.nospam.fi) wrote:
: Is it possible to write program with CC that directly writes/reads memory
: under Minix 2.0.0? I tried to find information about it on the web but I
: didn't succeed.

: I got old half-working 8086 for free and it had Minix installed in it. I'd
: use dos/tasm for doing such programming but the floppy drive is broken and I
: can't put dos to the hard disk without buying/finding working 5,25" floppy
: drive. I will use that computer for experimenting - adding my home made
: cards to ISA bus and so on.

On an 8086 it shouldn't be too difficult, since those CPUs had no
memory management functions. A 386 would be trickier; it would
probably be simplest to write a device driver to handle the i/o.


Will
c...@crash.cts.com


Al Woodhull

unread,
May 28, 1998, 3:00:00 AM5/28/98
to

On Wed, 27 May 1998 23:42:03 +0300 Teemu Savolainen
(ts...@cc.tut.nospam.fi) wrote in comp.os.minix:

: Is it possible to write program with CC that directly writes/reads memory
: under Minix 2.0.0? I tried to find information about it on the web but I
: didn't succeed.

The Minix memory device driver, the first device driver described in
the OSDI text, provides support for this. It is described as the RAM
disk driver, but in fact in addition to /dev/ram it supports /dev/mem
and /dev/kmem.

The genius of the Unix device driver concept is that the driver makes
any device accessible as a file. So you can use standard tools that
examine files, like the Unix command od, to look at memory:
od -hx <dev/mem | more
will dump memory in hex starting from location zero. You can also
specify an offset.

You could use the standard Unix dd command to write to memory, too. Be
careful with this! The /dev/mem and /dev/kmem devices by default are
given restricted privileges, you really don't want ordinary users
getting access. And you want to be very cautious about writing to
memory.

I have had a lot of use for tools to display contents of files and
memory in my teaching, and I never liked the formats available with
the od command, so long ago I wrote a similar program which I called
xd, which provides a hexadecimal+ascii dump by default, in a format
similar to that used by the MS-DOS debug utility. An old version of
this is available at ftp://minix1.hampshire.edu/pub/minix.1.5/misc/xd1.shar.

I have a newer version written for Minix 2.0 that I have never posted
publically, partly because I never decided what to call it. I
developed the original xd before I began to use the X-Window System,
before I realized that any command name that begins with 'x' will
immediately be assumed to be an X utility by those in the know. I
suppose I should just call it hexd and make it publically available.
I can mail the source to anyone interested.

The Minix memory drivers make all of memory (or at least up to 16M)
available in a linear address space, but the integer variables used in
od and dd probably don't support such big numbers.

Al
+----------------------------------+
| Albert S. Woodhull |
| Hampshire College, Amherst, MA |
| awoo...@hampshire.edu |
| http://minix1.hampshire.edu/asw/ |
+----------------------------------

Drayth

unread,
Jun 2, 1998, 3:00:00 AM6/2/98
to


Teemu Savolainen wrote:

> Is it possible to write program with CC that directly writes/reads memory
> under Minix 2.0.0? I tried to find information about it on the web but I
> didn't succeed.
>

> I got old half-working 8086 for free and it had Minix installed in it. I'd
> use dos/tasm for doing such programming but the floppy drive is broken and I
> can't put dos to the hard disk without buying/finding working 5,25" floppy
> drive. I will use that computer for experimenting - adding my home made
> cards to ISA bus and so on.
>

> Thank you for any help

if you're actually looking for some old 5 1/4 disk drives I have a couple
lieing around and I could send them to you for a couple of bucks, I dunno
shipping costs + a bit I suppose. However I was under the impression that they
were dirt-common.
Drayth


0 new messages