Framebuffer ieee1275 support & test commands
PATCH 1/1 Framebuffer ieee1275 support & test commands
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Here is my patch to add support for framebuffer on IEEE1275 machines, a fractal drawing test program, and a mouse test program.
Framebuffer support includes :
-setting the palette colours
-drawing a rectangle filled with a colour
-drawing a rectangular image (may have some width & height limitations,
I had some glitches when I used a non-power-of-2 width)
-grabbing a rectangular image from screen (not tested) -getting the framebuffer address (the function I provide doesn't work
for some strange reason... Should be a cast problem somewhere. Mandelbrot command uses a workaround until I find the problem).
Mandelbrot draws directly in the framebuffer memory. It returns, but doesn't restore the colours. It calculates the fractal, so it uses fixed point operations (double).
As I said in a previous mail, mouse support is very limited - but it just works :). Mouse support is actualy 100% handled by mousetest.c. It understands Microsoft 2 buttons mouse protocol. Once started, the mousetest command doesn't exits (except if there is an init error). The rectangle on the top left corner of the screen shows the data received (3 bytes, first top, msb on the left). The format is described in mouse(4), coloured for better readability :
red : left mouse button
green : right moue button
yellow : y axis
blue : x axis
That command uses the (draw,fill)-rectangle functions, so the framebuffer must have them (my Creator3D doesn't).
Usage :
mousetest [screen_device mouse_device]
default : mousetest screen mouse
Please tell me if it doesn't build on PPC as modules (Marco : It's not the patch I sent you, I improved it a bit.) and if it doesn't work. Marco told me he was only getting a grey image with Mandelbrot.
2005-08-25 Vincent Pelletier <[email protected]>
* commands/ieee1275/mandelbrot.c: New file.
* commands/ieee1275/mousetest.c: Likewise.
* include/grub/ieee1275/fb.h: Likewise.
* include/grub/ieee1275/fbprops.h: Likewise.
* video/ieee1275/fb.c: Likewise.
* video/ieee1275/fbprops.c: Likewise.
* conf/powerpc-ieee1275.rmk (pkgdata_MODULES): Add mandelbrot.mod, mousetest.mod and fb.mod. (mandelbrot.mod): New module.
(mousetest.mod): Likewise.
(fb.mod): Likewise.
* conf/sparc64-ieee1275.rmk: Likewise. (grubof_HEADERS, grubof_SOURCES): Add needed files to statically link the commands.
(grubof_CFLAGS): Add -DGRUB_EMBED to make commands build as embedded and rescue commands.
* kern/sparc64/ieee1275/init.c: Handle the commands initialisation and finish when embedded.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFDDZsxFEQoKRQyjtURAgtTAJ9qclafmsNNvgVkC1r8jvhP7kDZYQCffffX koq32EYbF4X0teVkqhCQmg0=
=TF0X
-----END PGP SIGNATURE-----
Index: commands/ieee1275/mandelbrot.c
===================================================================
RCS file: commands/ieee1275/mandelbrot.c
ieee1275/mandelbrot.c new file +145 -0
@@ -0,0 +1,145 @@ +/* mandelbrot.c - Draws a nice Manldebrot fractal. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2005 Free Software Foundation, Inc. +* +* GRUB is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include <grub/rescue.h> +#include <grub/dl.h> +#include <grub/misc.h> +#include <grub/machine/kernel.h> +#include <grub/ieee1275/ieee1275.h> +#include <grub/ieee1275/fb.h> +#include <grub/ieee1275/fbprops.h> + +#ifndef GRUB_EMBED +static grub_err_t +grub_cmd_mandelbrot (struct grub_arg_list *state __attribute__ ((unused)), + int argc, char **argv) +#else /* GRUB_EMBED */ +static void +grub_cmd_mandelbrot (int argc,char *argv[]) +#endif /* ! GRUB_EMBED */ +{ +grub_ieee1275_ihandle_t screen; +grub_ieee1275_phandle_t pscreen; +const unsigned int nmax =25 ; +unsigned int n, x, y, w, h, a; +const double xmin =-2.5 , xmax =2.5 , ymin =-2 , ymax =2 ; +double dx, dy, rz, iz, tz, rc, ic; +unsigned char *fb, tmp[4 ]; +char *device; +grub_ssize_t actual; + +if (argc ==1 ) + device = argv[0 ]; +else + device ="screen" ; +grub_printf ("Using device %s...\n" ,device); +if (!grub_ieee1275_open (device, &screen)) + { +grub_ieee1275_finddevice (device, &pscreen); + h =grub_ieee1275_fb_height (pscreen); + w =grub_ieee1275_fb_width (pscreen); +grub_printf ("w=%d h=%d\n" ,w,h); +grub_ieee1275_get_property (pscreen,"address" ,tmp,sizeof (tmp),&actual); + fb = (unsigned char *)grub_ieee1275_decode_int_4 (tmp); +// fb = (unsigned char *) grub_ieee1275_fb_addr (pscreen); +grub_printf ("Framebuffer is at %p.\nClearing screen...\n" , fb); +for (a =0 ; a < w * h; a++) + fb[a] =0 ; +for (a =0 ; a <256 ; a++)/* Fill palette with shades of gray. */ +grub_ieee1275_setcolor (screen, a, a, a, a); + dx = (xmax - xmin) / w; + dy = (ymax - ymin) / h; +for (x =0 ; x < w; x++) + { + rc = xmin + x * dx; +for (y =0 ; y < h; y++) + { + ic = ymin + y * dy; + rz =0 ; + iz =0 ; +for (n =1 ; n < nmax; n++) + { + tz = rz * rz - iz * iz + rc; + iz =2 * rz * iz + ic; + rz = tz; +if (rz * rz + iz * iz >=4 ) + { + fb[x+w*y] = (n*255 /nmax) %256 ; + n = nmax; + } + } +if (rz * rz + iz * iz <4 ) + fb[x+w*y]=255 ; + } + } +#if 0 +grub_ieee1275_close (screen);/* If screen is closed, it goes black. */ +#endif + } +grub_printf ("Finished !\n" ); +#ifndef GRUB_EMBED +return 0 ; +#endif /* ! GRUB_EMBED */ +} + + +#ifdef GRUB_EMBED +void +grub_mandelbrot_init (void ) +{ +grub_rescue_register_command ("mandelbrot" , grub_cmd_mandelbrot, +"Draws a fractal." ); +} + +void +grub_mandelbrot_fini (void ) +{ +grub_rescue_unregister_command ("mandelbrot" ); +} +#else /* ! GRUB_EMBED */ +#ifdef GRUB_UTIL +void +grub_mandelbrot_init (void ) +{ +grub_register_command ("mandelbrot" , grub_cmd_mandelbrot, +GRUB_COMMAND_FLAG_BOTH ,"mandelbrot" , +"Draws a fractal." ,0 ); +} + +void +grub_mandelbrot_fini (void ) +{ +grub_unregister_command ("mandelbrot" ); +} +#else /* ! GRUB_UTIL */ +GRUB_MOD_INIT +{ + (void )mod;/* To stop warning. */ +grub_register_command ("mandelbrot" , grub_cmd_mandelbrot, +GRUB_COMMAND_FLAG_BOTH ,"mandelbrot" , +"Draws a fractal." ,0 ); +} + +GRUB_MOD_FINI +{ +grub_unregister_command ("mandelbrot" ); +} +#endif /* GRUB_UTIL */ +#endif /* GRUB_EMBED */
Index: commands/ieee1275/mousetest.c
===================================================================
RCS file: commands/ieee1275/mousetest.c
ieee1275/mousetest.c new file +240 -0
240 lines not on this page · raw message
Index: conf/powerpc-ieee1275.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/powerpc-ieee1275.rmk,v retrieving revision 1.37
powerpc-ieee1275.rmk +15 -1
@@ -75,7 +75,8 @@ pkgdata_MODULES = _linux.mod linux.mod f hfs.mod jfs.mod normal.mod hello.mod font.mod ls.mod \ boot.mod cmp.mod cat.mod terminal.mod fshelp.mod amiga.mod apple.mod \ pc.mod suspend.mod loopback.mod help.mod reboot.mod halt.mod sun.mod \ - default.mod timeout.mod configfile.mod search.mod + default.mod timeout.mod configfile.mod search.mod mandelbrot.mod \ + mousetest.mod fb.mod # For fshelp.mod. fshelp_mod_SOURCES = fs/fshelp.c
@@ -204,3 +205,16 @@ configfile_mod_CFLAGS = $(COMMON_CFLAGS) # For search.mod. search_mod_SOURCES = commands/search.c search_mod_CFLAGS = $(COMMON_CFLAGS) + +# For mandelbrot.mod +mandelbrot_mod_SOURCES = commands/ieee1275/mandelbrot.c +mandelbrot_mod_CFLAGS = $(COMMON_CFLAGS) + +# For mousetest.mod +mousetest_mod_SOURCES = commands/ieee1275/mousetest.c +mousetest_mod_CFLAGS = $(COMMON_CFLAGS) + +# For fb.mod +fb_mod_SOURCES = video/ieee1275/fb.c video/ieee1275/fbprops.c +fb_mod_CFLAGS = $(COMMON_CFLAGS) +
Index: conf/sparc64-ieee1275.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/sparc64-ieee1275.rmk,v retrieving revision 1.2
sparc64-ieee1275.rmk +21 -4
@@ -12,7 +12,8 @@ DEFSYMFILES += kernel_syms.lst grubof_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \ file.h fs.h kernel.h misc.h mm.h net.h rescue.h symbol.h \ term.h types.h loader.h \ - partition.h pc_partition.h ieee1275/ieee1275.h machine/time.h + partition.h pc_partition.h ieee1275/ieee1275.h machine/time.h \ + ieee1275/fb.h ieee1275/fbprops.h grubof_symlist.c: $(addprefix include/grub/,$(grubof_HEADERS)) gensymlist.sh sh $(srcdir)/gensymlist.sh $(filter %.h,$^) > $@
@@ -59,9 +60,11 @@ grubof_SOURCES = kern/sparc64/ieee1275/i kern/rescue.c kern/term.c term/ieee1275/ofconsole.c \ kern/sparc64/ieee1275/openfw.c disk/ieee1275/ofdisk.c \ kern/partition.c kern/env.c kern/sparc64/dl.c grubof_symlist.c \ - kern/sparc64/cache.c + kern/sparc64/cache.c \ + video/ieee1275/fb.c video/ieee1275/fbprops.c \ + commands/ieee1275/mandelbrot.c commands/ieee1275/mousetest.c grubof_HEADERS = grub/sparc64/ieee1275/ieee1275.h -grubof_CFLAGS = $(COMMON_CFLAGS) +grubof_CFLAGS = $(COMMON_CFLAGS) -DGRUB_EMBED grubof_ASFLAGS = $(COMMON_ASFLAGS) grubof_LDFLAGS = -m64 -nostdlib -Wl,-N,-Ttext,0x200000,-Bstatic -Xlinker --oformat -Xlinker elf64-sparc
@@ -73,7 +76,8 @@ genmoddep_SOURCES = util/genmoddep.c # hfs.mod jfs.mod normal.mod hello.mod font.mod ls.mod \ # boot.mod cmp.mod cat.mod terminal.mod fshelp.mod amiga.mod apple.mod \ # pc.mod suspend.mod loopback.mod help.mod reboot.mod halt.mod sun.mod \ -# default.mod timeout.mod configfile.mod search.mod +# default.mod timeout.mod configfile.mod search.mod mandelbrot.mod \ +# mousetest.mod fb.mod # For fshelp.mod. fshelp_mod_SOURCES = fs/fshelp.c
@@ -202,3 +206,16 @@ configfile_mod_CFLAGS = $(COMMON_CFLAGS) # For search.mod. search_mod_SOURCES = commands/search.c search_mod_CFLAGS = $(COMMON_CFLAGS) + +# For mandelbrot.mod +mandelbrot_mod_SOURCES = commands/ieee1275/mandelbrot.c +mandelbrot_mod_CFLAGS = $(COMMON_CFLAGS) + +# For mousetest.mod +mousetest_mod_SOURCES = commands/ieee1275/mousetest.c +mousetest_mod_CFLAGS = $(COMMON_CFLAGS) + +# For fb.mod +fb_mod_SOURCES = video/ieee1275/fb.c video/ieee1275/fbprops.c +fb_mod_CFLAGS = $(COMMON_CFLAGS) +
Index: include/grub/ieee1275/fb.h
===================================================================
RCS file: include/grub/ieee1275/fb.h
grub/ieee1275/fb.h new file +54 -0
54 lines not on this page · raw message
Index: include/grub/ieee1275/fbprops.h
===================================================================
RCS file: include/grub/ieee1275/fbprops.h
grub/ieee1275/fbprops.h new file +43 -0
43 lines not on this page · raw message
Index: kern/sparc64/ieee1275/init.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/sparc64/ieee1275/init.c,v retrieving revision 1.1
sparc64/ieee1275/init.c +9 -0
@@ -205,11 +205,20 @@ grub_machine_init (void) } } +#ifdef GRUB_EMBED +grub_mandelbrot_init (); +grub_mousetest_init (); +#endif /* GRUB_EMBED */ + }void grub_machine_fini (void ) { +#ifdef GRUB_EMBED +grub_mousetest_fini (); +grub_mandelbrot_fini (); +#endif /* GRUB_EMBED */ grub_ofdisk_fini ();grub_console_fini (); }
Index: video/ieee1275/fb.c
===================================================================
RCS file: video/ieee1275/fb.c
ieee1275/fb.c new file +222 -0
222 lines not on this page · raw message
Index: video/ieee1275/fbprops.c
===================================================================
RCS file: video/ieee1275/fbprops.c
ieee1275/fbprops.c new file +96 -0
96 lines not on this page · raw message
Quoted 3 lines · Vincent Pelletier
Here is my patch to add support for framebuffer on IEEE1275 machines, a fractal drawing test program, and a mouse test program.
No time for real review at the moment, but:
- you spelled "Manldebrot" wrong in the first comment
- you have lots of commented-out code present
- what is this "GRUB_EMBED" stuff?
- mouse support should be a separate patch from framebuffer support
- the "XXX Test me!" code should either be tested or removed
- I'm unclear on your distinction between "fb" and "fbprops" in file names.
In general I'd say this patch is not yet ready for merging.
What is your model for framebuffer drivers in general (including across architectures)? For example, every fb driver will provide what API, and should that be used by common code?
-Hollis
Quoted 1 line · Hollis Blanchard
- you have lots of commented-out code present
Patch lines :
68 : waiting for me to fix the grub_ieee1275_fb_addr stuff. 597..600 & 949..961 : I don't know how widely these functions are implemented in framebuffers, so I disabled them.
921 & 927 : Forgot those.
Quoted 1 line
- what is this "
GRUB_EMBED" stuff?
It's to work around the fact that sparc64 doesn't support modules. So I have to embed them inside grubof, and make them debug commands. I thought it was obvious...
What may not be is that it has only a meaning for sparc64, and won't have any once module support will be added.
Quoted 1 line
- I'm unclear on your distinction between "fb" and "fbprops" in file names.
fb contains needed functions to make framebuffer work. fbprops only contains functions that make it easier (and less verbose) to get properties of the framebuffer devices. May be merged with fb.c, may not exist at all... I'm not sure.
Quoted 1 line
In general I'd say this patch is not yet ready for merging.
It's not ready for merging, as I don't even know if it builds on ppc as I said in the first mail.
Moreover, I'm not sure I'll have much time to work on those next days, so I prefer posting the patch as soon as possible in case someone want to work on it. It could also help finding a common framebuffer API. I should remember to tag such mails as RFC, not as PATCH...
Quoted 3 lines
What is your model for framebuffer drivers in general (including across architectures)? For example, every fb driver will provide what API, and should that be used by common code?
That common API still has to be defined...
I sent some ideas in a mail some days ago.
Vincent Pelletier