3 #include <aros/kernel.h>
4 #include <hardware/vbe.h>
6 #include <bootconsole.h>
10 #include "bootstrap.h"
14 void setupVESA(char *vesa
)
17 unsigned char palwidth
= 6;
18 BOOL prioritise_depth
= FALSE
, set_refresh
= FALSE
;
19 long x
= 0, y
= 0, d
= 0, vfreq
= 0;
21 unsigned long vesa_size
= (unsigned long)&_binary_vesa_size
;
22 void *vesa_start
= &_binary_vesa_start
;
23 void *tmp
= __bs_malloc(vesa_size
);
27 kprintf("[VESA] Setup failed, not enough working memory\n");
31 x
= strtoul(vesa
, &vesa
, 10);
35 y
= strtoul(vesa
, &vesa
, 10);
40 d
= strtoul(vesa
, &vesa
, 10);
46 d
= x
, x
= 10000, y
= 10000, prioritise_depth
= TRUE
;
48 /* Check for user-set refresh rate */
52 vfreq
= strtoul(vesa
, &vesa
, 10);
59 * 16-bit VBE trampoline is needed only once only here, so
60 * we can simply copy it to some address, do what we need, and
62 * However we must keep in mind that low memory can be occupied by
63 * something useful, like kickstart modules or boot information.
64 * So we preserve our region and put it back when we are done.
66 D(kprintf("[VESA] Backing up low memory, buffer at 0x%p\n", tmp
));
67 memcpy(tmp
, VESA_START
, vesa_size
);
69 D(kprintf("[VESA] vesa.bin @ %p [size=%d]\n", &_binary_vesa_start
, &_binary_vesa_size
));
70 memcpy(VESA_START
, vesa_start
, vesa_size
);
72 kprintf("[VESA] BestModeMatch for %ldx%ldx%ld = ", x
, y
, d
);
73 mode
= findMode(x
, y
, d
, vfreq
, prioritise_depth
);
75 /* Get information and copy it from 16-bit memory space to our 32-bit memory */
77 memcpy(&VBEModeInfo
, modeinfo
, sizeof(struct vbe_mode
));
79 memcpy(&VBEControllerInfo
, controllerinfo
, sizeof(struct vbe_controller
));
81 /* Activate linear framebuffer is supported by the mode */
82 if (VBEModeInfo
.mode_attributes
& VM_LINEAR_FB
)
83 mode
|= VBE_MODE_LINEAR_FB
;
87 r
= setVbeMode(mode
, set_refresh
);
88 if (r
== VBE_RC_SUPPORTED
)
90 /* Try to switch palette width to 8 bits if possible */
91 if (VBEControllerInfo
.capabilities
& VC_PALETTE_WIDTH
)
92 paletteWidth(0x0800, &palwidth
);
95 /* Put memory back and reset memory allocator */
96 memcpy(VESA_START
, tmp
, vesa_size
);
99 if (r
== VBE_RC_SUPPORTED
)
101 /* Reinitialize our console */
102 fb_Mirror
= __bs_malloc(0);
103 con_InitVESA(VBEControllerInfo
.version
, &VBEModeInfo
);
106 D(kprintf("[VESA] VBE version 0x%04X\n", VBEControllerInfo
.version
));
107 D(kprintf("[VESA] Resolution %d x %d\n", VBEModeInfo
.x_resolution
, VBEModeInfo
.y_resolution
));
108 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
));
109 D(kprintf("[VESA] Mode flags 0x%04X, framebuffer 0x%p\n", VBEModeInfo
.mode_attributes
, VBEModeInfo
.phys_base
));
110 D(kprintf("[VESA] Windows A 0x%04X B 0x%04X\n", VBEModeInfo
.win_a_segment
, VBEModeInfo
.win_b_segment
));
112 tag
->ti_Tag
= KRN_VBEModeInfo
;
113 tag
->ti_Data
= KERNEL_OFFSET
| (unsigned long)&VBEModeInfo
;
116 tag
->ti_Tag
= KRN_VBEControllerInfo
;
117 tag
->ti_Data
= KERNEL_OFFSET
| (unsigned long)&VBEControllerInfo
;
120 tag
->ti_Tag
= KRN_VBEMode
;
124 tag
->ti_Tag
= KRN_VBEPaletteWidth
;
125 tag
->ti_Data
= palwidth
;
129 kprintf("[VESA] Setup complete\n");