revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-pc / bootstrap / vesa_setup.c
blob2a7c9ec5cd4e5baf4469c3893b64fb5c3aa60dd8
1 /*
2 Copyright © 1995-2018, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
8 #include <aros/kernel.h>
9 #include <hardware/vbe.h>
11 #include <bootconsole.h>
12 #include <stdlib.h>
13 #include <string.h>
15 #include "bootstrap.h"
16 #include "support.h"
17 #include "vesa.h"
19 void setupVESA(char *vesa)
21 short r;
22 unsigned char palwidth = 6;
23 BOOL prioritise_depth = FALSE, set_refresh = FALSE;
24 long x = 0, y = 0, d = 0, vfreq = 0;
25 long mode;
26 unsigned long vesa_size = (unsigned long)&_binary_vesa_size;
27 void *vesa_start = &_binary_vesa_start;
28 void *tmp = __bs_malloc(vesa_size);
30 if (!tmp)
32 kprintf("[VESA] Setup failed, not enough working memory\n");
33 return;
36 x = strtoul(vesa, &vesa, 10);
37 if (*vesa == 'x')
39 vesa++;
40 y = strtoul(vesa, &vesa, 10);
42 if (*vesa == 'x')
44 vesa++;
45 d = strtoul(vesa, &vesa, 10);
47 else
48 d = 32;
50 else
51 d = x, x = 10000, y = 10000, prioritise_depth = TRUE;
53 /* Check for user-set refresh rate */
54 if (*vesa == '@')
56 vesa++;
57 vfreq = strtoul(vesa, &vesa, 10);
58 set_refresh = TRUE;
60 else
61 vfreq = 60;
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
66 * then forget.
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 */
81 getModeInfo(mode);
82 memcpy(&VBEModeInfo, modeinfo, sizeof(struct vbe_mode));
83 getControllerInfo();
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;
90 kprintf("%x\n",mode);
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);
102 __bs_free();
104 if (r == VBE_RC_SUPPORTED)
106 /* Reinitialize our console */
107 fb_Mirror = __bs_malloc(0);
108 con_InitVESA(VBEControllerInfo.version, &VBEModeInfo);
109 AllocFB();
111 D(kprintf("[VESA] VBE version 0x%04X\n", VBEControllerInfo.version));
112 D(kprintf("[VESA] Mode 0x%x\n", mode));
113 D(kprintf("[VESA] Resolution %d x %d\n", VBEModeInfo.x_resolution, VBEModeInfo.y_resolution));
114 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));
115 D(kprintf("[VESA] Mode flags 0x%04X, framebuffer 0x%p\n", VBEModeInfo.mode_attributes, VBEModeInfo.phys_base));
116 D(kprintf("[VESA] Windows A 0x%04X B 0x%04X\n", VBEModeInfo.win_a_segment, VBEModeInfo.win_b_segment));
117 D(kprintf("[VESA] Palette width %d\n", palwidth));
119 tag->ti_Tag = KRN_VBEModeInfo;
120 tag->ti_Data = KERNEL_OFFSET | (unsigned long)&VBEModeInfo;
121 tag++;
123 tag->ti_Tag = KRN_VBEControllerInfo;
124 tag->ti_Data = KERNEL_OFFSET | (unsigned long)&VBEControllerInfo;
125 tag++;
127 tag->ti_Tag = KRN_VBEMode;
128 tag->ti_Data = mode;
129 tag++;
131 tag->ti_Tag = KRN_VBEPaletteWidth;
132 tag->ti_Data = palwidth;
133 tag++;
136 kprintf("[VESA] Setup complete\n");