memfiddle, new kernel

0 views
Skip to first unread message

Mechiel Lukkien

unread,
Apr 13, 2008, 4:36:17 PM4/13/08
to infer...@googlegroups.com
hi all,

i just uploaded a new kernel to

http://code.google.com/p/inferno-ds/downloads/list

named `isds-93-memfiddle0.nds'. it is from revision 93, with memfiddle
in it and the patch i posted almost a week ago that got touch
calibration somewhat going.

memfiddle is a program to read, change and write the memory mapped
registers used to configure the nds (and which can also be used to access
the frame buffer memory).

BEWARE: you can write to any register, so be careful with what you
write, and to which register.

memfiddle has also been committed to svn, in the directory
inferno-ds/root, copy it to the root of your inferno-os directory and
`mk install' in the appl/ dir, and copy the /lib/registers to your
inferno-os.

the following is an excerpt from the commit message:

about memfiddle:

it allows playing with the registers (reading, changing bits, writing)
using the touch screen. four bytes can be shown at a time, each bit is
a button. bits can be flipped by clicking on them. all bits can be
zeroed, `oned', inverted at a time. or a new value can be read, or
written. a listing of registers is kept. new addresses can be added to
the list by increasing the `current address', the byte/short/long-form
can be set for the address, and you can cycle through known addresses
with the `k' button.

a listing of well-known registers is given in the files /lib/registers/.
each `subject' has a file, e.g. `video'. the listings are not complete,
feel free to fill in the blanks. the files are included in the sds
kernel and are loaded by memfiddle. the program has a button `K' to
load the next file in the list.

a short description of the buttons presented by memfiddle are printed as
comment at the top of the memfiddle.b file.

i hope this can help with development, e.g. getting video on the second
screen. this allows me to not do the compile+put kernel on flash
card+boot cycle for each attempt to change a register.

best regards,
mechiel

Salva Peiró

unread,
Apr 15, 2008, 12:58:10 PM4/15/08
to infer...@googlegroups.com
On Sun, Apr 13, 2008 at 10:36 PM, Mechiel Lukkien <mec...@ueber.net> wrote:
>
> i hope this can help with development, e.g. getting video on the second
> screen. this allows me to not do the compile+put kernel on flash
> card+boot cycle for each attempt to change a register.
>

This is another way to use '#R/registers',
which given that allows accesses to all the memory space i'd call '#R/ndsmem',
or something like that. The idea is that one can also use it with mdb(1)
from sh(1) to modify a register (lcd control reg) and swap both screens.

this is not of practical use, just a curious use.

% cat $home/lib/wmsetup
#!/dis/sh script

wmrun bind -a '#R' /dev # nds regs
wmrun bind -b /icons/tinytk /icons/tk

menu '' ''
menu Kbd { wm/keyboard }
menu Pen { wm/pen }
menu Halt { wmrun shutdown -h }

#wmrun auth/factotum
#wmrun wm/date
wmrun wm/keyboard -t
wmrun wm/sh -w 240 -h 130 -ic '
echo welcome `{cat /dev/user}!;
#
# cat /dev/ndsfw

echo /dev/ndsrom works! > /dev/ndsrom
cat /dev/ndsrom | read -o 0 19

echo ''
0x04000208/X
0x04000210/X
0x04000214/X'' | mdb /dev/registers

echo ''
0x04000304/X
0x04000304/w 0x00000580'' | mdb -w /dev/registers
echo lcd swap
echo ''
0x04000304/w 0x00000500
0x04000304/X'' | mdb -w /dev/registers
'

--
salva

Salva Peiró

unread,
Apr 16, 2008, 1:13:40 PM4/16/08
to infer...@googlegroups.com
On Tue, Apr 15, 2008 at 6:58 PM, Salva Peiró <saore...@gmail.com> wrote:
> On Sun, Apr 13, 2008 at 10:36 PM, Mechiel Lukkien <mec...@ueber.net> wrote:
> >
> > i hope this can help with development, e.g. getting video on the second
> > screen. this allows me to not do the compile+put kernel on flash
> > card+boot cycle for each attempt to change a register.
> >
>
> This is another way to use '#R/registers',
> which given that allows accesses to all the memory space i'd call '#R/ndsmem',
> or something like that. The idea is that one can also use it with mdb(1)
> from sh(1) to modify a register (lcd control reg) and swap both screens.
>
> this is not of practical use, just a curious use.
>

I've continued reading about mdb(1), and reworked my previous example,
in the process i noticed that the byteorder of the values printed/introduced
wasn't the same as the one used when directly accessing the registers
from C code,
so i modified a bit mdb.b to show what i was expecting (maybe i've
introduced bugs).

% svn diff appl/cmd/mdb.b
Index: appl/cmd/mdb.b
===================================================================
--- appl/cmd/mdb.b (revision 278)
+++ appl/cmd/mdb.b (working copy)
@@ -262,8 +262,12 @@
sys->seek(mfd, big dot, Sys->SEEKSTART);
sys->read(mfd, b, len b);
v = 0;
+
for(i := 0; i < n; i++)
- v |= int b[i] << (8*i);
+ if (bigendian)
+ v |= int b[i] << (8*(n-1-i));
+ else
+ v |= int b[i] << (8*i);
}
case fmt {
'c' => print("%c", v);
@@ -296,7 +300,10 @@
return;
b := array[n] of byte;
for(i := 0; i < n; i++)
- b[i] = byte (v >> (8*i));
+ if (bigendian)
+ b[n-1-i] = byte (v >> (8*i));
+ else
+ b[i] = byte (v >> (8*i));
if (sys->write(mfd, b, len b) != len b)
sys->fprint(stderr, "mdb: write error: %r\n");
}
@@ -304,11 +311,12 @@

usage()
{
- sys->fprint(stderr, "usage: mdb [-w] file [command]\n");
+ sys->fprint(stderr, "usage: mdb [-w] [-b] file [command]\n");
raise "fail:usage";
}

writeable := 0;
+bigendian := 0;

init(nil: ref Draw->Context, argv: list of string)
{
@@ -331,10 +339,12 @@
usage();
if (argv != nil)
argv = tl argv;
- if (argv != nil && len hd argv && (hd argv)[0] == '-') {
- if (hd argv != "-w")
- usage();
- writeable = 1;
+ while (argv != nil && len hd argv && (hd argv)[0] == '-') {
+ case (hd argv)[1] {
+ 'w' => writeable = 1;
+ 'b' => bigendian = 1;
+ * => usage();
+ }
argv = tl argv;
}
if (argv == nil)


With the modified mdb.b, i've tried to use sh(1) together with mdb(1),
to write the example in a cleaner/structured way, this in conjunction
with a file of register addresses to snarf, cut, send & plumb from wm/sh
would do a curious mix low and high level programming.

In any case i still feel slow when using wm/keyboard to enter commands,
which is stopping me from using this more often to test/try things.

% cat $home/lib/wmsetup
#!/dis/sh script

wmrun bind -a '#R' /dev # nds regs
wmrun bind -b /icons/tinytk /icons/tk

menu '' ''
menu Kbd { wm/keyboard }
menu Pen { wm/pen }
menu Halt { wmrun shutdown -h }

#wmrun auth/factotum
#wmrun wm/date

wmrun wm/keyboard -t
wmrun wm/sh -w 240 -h 130 -ic '
echo welcome `{cat /dev/user}!;
#
# cat /dev/ndsfw

echo /dev/ndsrom works! > /dev/ndsrom
cat /dev/ndsrom | read -o 0 19

echo /dev/ndssram works! > /dev/ndssram
cat /dev/ndssram | read -o 0 20

echo ints: ime, ier, ipr
echo '' 0x04000208/X
0x04000210/X
0x04000214/X'' | mdb -b /dev/registers

pwrctl=0x04000304
vpwrctl=`{mdb -b /dev/registers $pwrctl/X}

mdb -b -w /dev/registers $pwrctl''/w 0x00008000 | ''$"vpwrctl
echo lcd swap
mdb -b -w /dev/registers $pwrctl''/w ''$"vpwrctl
'

--
salva

Salva Peiró

unread,
Apr 20, 2008, 8:14:29 AM4/20/08
to infer...@googlegroups.com
On Wed, Apr 16, 2008 at 7:13 PM, Salva Peiró <saore...@gmail.com> wrote:
> I've continued reading about mdb(1), and reworked my previous example,
> in the process i noticed that the byteorder of the values printed/introduced
> wasn't the same as the one used when directly accessing the registers
> from C code, so i modified a bit mdb.b to show what i was expecting (maybe i've
> introduced bugs).
>

there was no need for big-endian,
as mdb(1) explains it assumes little-endian,
and the DS port is also little-endian so the problem was
that devregs.c was changing the byte order to big-endian.

This is fixed in the repo.

--
salva

Reply all
Reply to author
Forward
0 new messages