Merge branch 'afs' into befs2
[grub2/phcoder.git] / loader / i386 / pc / xnu.c
blob037a7134f04a907029cfb72d73e96a4d04235767
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2009 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #include <grub/env.h>
20 #include <grub/misc.h>
21 #include <grub/xnu.h>
22 #include <grub/mm.h>
23 #include <grub/cpu/xnu.h>
24 #include <grub/machine/vbe.h>
25 #include <grub/machine/vga.h>
27 #define min(a,b) (((a) < (b)) ? (a) : (b))
28 #define max(a,b) (((a) > (b)) ? (a) : (b))
30 #define DEFAULT_VIDEO_MODE "1024x768x32,800x600x32,640x480x32"
32 static int NESTED_FUNC_ATTR video_hook (grub_video_adapter_t p __attribute__ ((unused)),
33 struct grub_video_mode_info *info)
35 if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT)
36 return 0;
38 return 1;
41 /* Setup video for xnu. */
42 grub_err_t
43 grub_xnu_set_video (struct grub_xnu_boot_params *params)
45 struct grub_video_mode_info mode_info;
46 struct grub_video_render_target *render_target;
47 int ret;
48 int x,y;
49 char *tmp, *modevar;
50 grub_err_t err;
52 modevar = grub_env_get ("gfxpayload");
53 if (! modevar || *modevar == 0)
54 err = grub_video_set_mode (DEFAULT_VIDEO_MODE, video_hook);
55 else
57 tmp = grub_malloc (grub_strlen (modevar)
58 + sizeof (DEFAULT_VIDEO_MODE) + 1);
59 if (! tmp)
60 return grub_error (GRUB_ERR_OUT_OF_MEMORY,
61 "couldn't allocate temporary storag");
62 grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar);
63 err = grub_video_set_mode (tmp, video_hook);
64 grub_free (tmp);
67 if (err)
68 return err;
70 ret = grub_video_get_info (&mode_info);
71 if (ret)
72 return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters");
74 ret = grub_video_get_active_render_target (&render_target);
75 if (ret)
76 return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters");
78 err = GRUB_ERR_NONE;
79 x = mode_info.width - grub_xnu_bitmap->mode_info.width;
80 x /= 2;
81 y = mode_info.height - grub_xnu_bitmap->mode_info.height;
82 y /= 2;
83 err = grub_video_blit_bitmap (grub_xnu_bitmap,
84 GRUB_VIDEO_BLIT_REPLACE,
85 x > 0 ? x : 0,
86 y > 0 ? y : 0,
87 x < 0 ? -x : 0,
88 y < 0 ? -y : 0,
89 min (grub_xnu_bitmap->mode_info.width,
90 mode_info.width),
91 min (grub_xnu_bitmap->mode_info.height,
92 mode_info.height));
93 if (err)
95 grub_print_error ();
96 grub_errno = GRUB_ERR_NONE;
97 grub_xnu_bitmap = 0;
100 params->lfb_width = mode_info.width;
101 params->lfb_height = mode_info.height;
102 params->lfb_depth = mode_info.bpp;
103 params->lfb_line_len = mode_info.pitch;
105 params->lfb_base = PTR_TO_UINT32 (render_target->data);
106 params->lfb_mode = grub_xnu_bitmap
107 ? GRUB_XNU_VIDEO_SPLASH : GRUB_XNU_VIDEO_TEXT_IN_VIDEO;
109 return GRUB_ERR_NONE;