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/>.
20 #include <grub/misc.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
)
41 /* Setup video for xnu. */
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
;
52 modevar
= grub_env_get ("gfxpayload");
53 if (! modevar
|| *modevar
== 0)
54 err
= grub_video_set_mode (DEFAULT_VIDEO_MODE
, video_hook
);
57 tmp
= grub_malloc (grub_strlen (modevar
)
58 + sizeof (DEFAULT_VIDEO_MODE
) + 1);
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
);
70 ret
= grub_video_get_info (&mode_info
);
72 return grub_error (GRUB_ERR_IO
, "couldn't retrieve video parameters");
74 ret
= grub_video_get_active_render_target (&render_target
);
76 return grub_error (GRUB_ERR_IO
, "couldn't retrieve video parameters");
79 x
= mode_info
.width
- grub_xnu_bitmap
->mode_info
.width
;
81 y
= mode_info
.height
- grub_xnu_bitmap
->mode_info
.height
;
83 err
= grub_video_blit_bitmap (grub_xnu_bitmap
,
84 GRUB_VIDEO_BLIT_REPLACE
,
89 min (grub_xnu_bitmap
->mode_info
.width
,
91 min (grub_xnu_bitmap
->mode_info
.height
,
96 grub_errno
= GRUB_ERR_NONE
;
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
;