2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
8 #include <aros/kernel.h>
9 #include <hardware/vbe.h>
11 #include <bootconsole.h>
15 #include "bootstrap.h"
19 void setupVESA(char *vesa
)
22 unsigned char palwidth
= 6;
23 BOOL prioritise_depth
= FALSE
, set_refresh
= FALSE
;
24 long x
= 0, y
= 0, d
= 0, vfreq
= 0;
26 unsigned long vesa_size
= (unsigned long)&_binary_vesa_size
;
27 void *vesa_start
= &_binary_vesa_start
;
28 void *tmp
= __bs_malloc(vesa_size
);
32 kprintf("[VESA] Setup failed, not enough working memory\n");
36 x
= strtoul(vesa
, &vesa
, 10);
40 y
= strtoul(vesa
, &vesa
, 10);
45 d
= strtoul(vesa
, &vesa
, 10);
51 d
= x
, x
= 10000, y
= 10000, prioritise_depth
= TRUE
;
53 /* Check for user-set refresh rate */
57 vfreq
= strtoul(vesa
, &vesa
, 10);
64 * 16-bit VBE trampoline is needed only once only here, so
65 * we can simply copy it to some address, do what we need, and
67 * However we must keep in mind that low memory can be occupied by
68 * something useful, like kickstart modules or boot information.
69 * So we preserve our region and put it back when we are done.
71 D(kprintf("[VESA] Backing up low memory, buffer at 0x%p\n", tmp
));
72 memcpy(tmp
, VESA_START
, vesa_size
);
74 D(kprintf("[VESA] vesa.bin @ %p [size=%d]\n", &_binary_vesa_start
, &_binary_vesa_size
));
75 memcpy(VESA_START
, vesa_start
, vesa_size
);
77 kprintf("[VESA] BestModeMatch for %ldx%ldx%ld = ", x
, y
, d
);
78 mode
= findMode(x
, y
, d
, vfreq
, prioritise_depth
);
80 /* Get information and copy it from 16-bit memory space to our 32-bit memory */
82 memcpy(&VBEModeInfo
, modeinfo
, sizeof(struct vbe_mode
));
84 memcpy(&VBEControllerInfo
, controllerinfo
, sizeof(struct vbe_controller
));
86 /* Activate linear framebuffer is supported by the mode */
87 if (VBEModeInfo
.mode_attributes
& VM_LINEAR_FB
)
88 mode
|= VBE_MODE_LINEAR_FB
;
92 r
= setVbeMode(mode
, set_refresh
);
93 if (r
== VBE_RC_SUPPORTED
)
95 /* Try to switch palette width to 8 bits if possible */
96 if (VBEControllerInfo
.capabilities
& VC_PALETTE_WIDTH
)
97 paletteWidth(0x0800, &palwidth
);
100 /* Put memory back and reset memory allocator */
101 memcpy(VESA_START
, tmp
, vesa_size
);
104 if (r
== VBE_RC_SUPPORTED
)
106 /* Reinitialize our console */
107 fb_Mirror
= __bs_malloc(0);
108 con_InitVESA(VBEControllerInfo
.version
, &VBEModeInfo
);
111 D(kprintf("[VESA] VBE version 0x%04X\n", VBEControllerInfo
.version
));
112 D(kprintf("[VESA] Resolution %d x %d\n", VBEModeInfo
.x_resolution
, VBEModeInfo
.y_resolution
));
113 D(kprintf("[VESA] %d bits per pixel, %d/%d bytes per line\n", VBEModeInfo
.bits_per_pixel
, VBEModeInfo
.bytes_per_scanline
, VBEModeInfo
.linear_bytes_per_scanline
));
114 D(kprintf("[VESA] Mode flags 0x%04X, framebuffer 0x%p\n", VBEModeInfo
.mode_attributes
, VBEModeInfo
.phys_base
));
115 D(kprintf("[VESA] Windows A 0x%04X B 0x%04X\n", VBEModeInfo
.win_a_segment
, VBEModeInfo
.win_b_segment
));
117 tag
->ti_Tag
= KRN_VBEModeInfo
;
118 tag
->ti_Data
= KERNEL_OFFSET
| (unsigned long)&VBEModeInfo
;
121 tag
->ti_Tag
= KRN_VBEControllerInfo
;
122 tag
->ti_Data
= KERNEL_OFFSET
| (unsigned long)&VBEControllerInfo
;
125 tag
->ti_Tag
= KRN_VBEMode
;
129 tag
->ti_Tag
= KRN_VBEPaletteWidth
;
130 tag
->ti_Data
= palwidth
;
134 kprintf("[VESA] Setup complete\n");