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.
: Thank you for any help
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