added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / x86_64-pc / bootloader / bootloader_init.c
blob08fcc632bb6c28511322f3063b7b3c7e23e0a719
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id: bootloader_init.c 25411 2007-03-12 06:54:19Z sonic $
5 Bootloader information initialisation.
6 */
8 #define DEBUG 1
9 #include <aros/debug.h>
11 #include <exec/types.h>
12 #include <exec/memory.h>
13 #include <exec/resident.h>
14 #include <utility/utility.h>
15 #include <utility/tagitem.h>
16 #include <proto/exec.h>
17 #include <proto/bootloader.h>
18 #include <proto/utility.h>
19 #include <proto/kernel.h>
21 #include <aros/symbolsets.h>
22 #include <aros/bootloader.h>
23 #include <aros/kernel.h>
24 #include "../bootstrap/multiboot.h"
25 #include "bootloader_intern.h"
26 #include LC_LIBDEFS_FILE
28 #include <string.h>
30 static int GM_UNIQUENAME(Init)(LIBBASETYPEPTR BootLoaderBase)
32 void *KernelBase = TLS_GET(KernelBase);
33 struct TagItem *msg = KrnGetBootInfo();
34 IPTR tmp;
35 struct vbe_mode *vmi;
36 struct vbe_controller *vci;
38 BootLoaderBase->Flags = 0;
40 NEWLIST(&(BootLoaderBase->Args));
41 NEWLIST(&(BootLoaderBase->DriveInfo));
43 D(bug("[BootLdr] Init. msg=%p\n", msg));
45 /* Right. Now we extract the data currently placed in 0x1000 by exec */
46 if (msg)
48 /* Yay. There is data here */
49 #if 0
50 if (mb->flags & MB_FLAGS_LDRNAME)
52 STRPTR temp;
54 temp = AllocMem(200,MEMF_ANY);
55 if (temp)
57 strcpy(temp,mb->ldrname);
58 BootLoaderBase->LdrName = temp;
59 BootLoaderBase->Flags |= MB_FLAGS_LDRNAME;
60 D(bug("[BootLdr] Init: Loadername = %s\n",BootLoaderBase->LdrName));
62 else
63 bug("[BootLdr] Init: Failed to alloc memory for string\n");
65 #endif
66 tmp = GetTagData(KRN_CmdLine, 0, msg);
67 D(bug("[BootLdr] KRN_CmdLine=%p\n", tmp));
68 if (tmp)
70 STRPTR cmd,buff;
71 ULONG temp;
72 struct Node *node;
74 D(bug("[BootLdr] CmdLine=\"%s\"\n", (STRPTR)tmp));
76 /* First make a working copy of the command line */
77 if ((buff = AllocMem(200,MEMF_ANY|MEMF_CLEAR)))
79 strncpy(buff, (STRPTR)tmp, 200);
80 /* remove any leading spaces */
81 cmd = stpblk(buff);
82 while(cmd[0])
84 /* Split the command line */
85 temp = strcspn(cmd," ");
86 cmd[temp++] = 0x00;
87 D(bug("[BootLdr] Init: Argument %s\n",cmd));
88 /* Allocate node and insert into list */
89 node = AllocMem(sizeof(struct Node),MEMF_ANY|MEMF_CLEAR);
90 node->ln_Name = cmd;
91 AddTail(&(BootLoaderBase->Args),node);
92 /* Skip to next part */
93 cmd = stpblk(cmd+temp);
96 BootLoaderBase->Flags |= MB_FLAGS_CMDLINE;
99 vmi = (struct vbe_mode *)GetTagData(KRN_VBEModeInfo, 0, msg);
100 vci = (struct vbe_controller *)GetTagData(KRN_VBEControllerInfo, 0, msg);
102 if (vmi && vci)
104 ULONG masks [] = { 0x01, 0x03, 0x07, 0x0f ,0x1f, 0x3f, 0x7f, 0xff };
105 UWORD mode = GetTagData(KRN_VBEMode, 0, msg);
106 UBYTE palwidth = GetTagData(KRN_VBEPaletteWidth, 6, msg);
108 BootLoaderBase->Vesa.FrameBuffer = (APTR)vmi->phys_base;
109 BootLoaderBase->Vesa.FrameBufferSize = vci->total_memory * 64; /* FrameBufferSize is in KBytes! */
110 BootLoaderBase->Vesa.XSize = vmi->x_resolution;
111 BootLoaderBase->Vesa.YSize = vmi->y_resolution;
112 BootLoaderBase->Vesa.BytesPerLine = vmi->bytes_per_scanline;
113 BootLoaderBase->Vesa.BitsPerPixel = vmi->bits_per_pixel;
114 BootLoaderBase->Vesa.ModeNumber = mode; /* FIXME! */
115 BootLoaderBase->Vesa.Masks[VI_Red] = masks[vmi->red_mask_size-1]<<vmi->red_field_position;
116 BootLoaderBase->Vesa.Masks[VI_Blue] = masks[vmi->blue_mask_size-1]<<vmi->blue_field_position;
117 BootLoaderBase->Vesa.Masks[VI_Green] = masks[vmi->green_mask_size-1]<<vmi->green_field_position;
118 BootLoaderBase->Vesa.Masks[VI_Alpha] = masks[vmi->reserved_mask_size-1]<<vmi->reserved_field_position;
119 BootLoaderBase->Vesa.Shifts[VI_Red] = 32 - vmi->red_field_position - vmi->red_mask_size;
120 BootLoaderBase->Vesa.Shifts[VI_Blue] = 32 - vmi->blue_field_position - vmi->blue_mask_size;
121 BootLoaderBase->Vesa.Shifts[VI_Green] = 32 - vmi->green_field_position - vmi->green_mask_size;
122 BootLoaderBase->Vesa.Shifts[VI_Alpha] = 32 - vmi->reserved_field_position - vmi->reserved_mask_size;
123 BootLoaderBase->Vesa.PaletteWidth = palwidth;
124 BootLoaderBase->Flags |= MB_FLAGS_GFX;
125 if (BootLoaderBase->Vesa.ModeNumber != 3)
127 D(bug("[BootLdr] Init: Vesa card capability flags: 0x%08lx\n", vci->capabilities));
128 D(bug("[BootLdr] Init: Vesa mode %x type (%dx%dx%d)\n",
129 BootLoaderBase->Vesa.ModeNumber,
130 BootLoaderBase->Vesa.XSize,BootLoaderBase->Vesa.YSize,
131 BootLoaderBase->Vesa.BitsPerPixel));
132 D(bug("[BootLdr] Init: Vesa FB at 0x%08x size %d kB\n",
133 BootLoaderBase->Vesa.FrameBuffer,
134 BootLoaderBase->Vesa.FrameBufferSize));
135 D(bug("[BootLdr] Init: Vesa mode palette width: %d\n", BootLoaderBase->Vesa.PaletteWidth));
136 D(bug("[BootLdr] Init: Vesa mode direct color flags %02x\n", vmi->direct_color_mode_info));
138 else
140 D(bug("[BootLdr] Init: Textmode graphics\n"));
143 #if 0
144 if (mb->flags & MB_FLAGS_DRIVES)
146 struct mb_drive *curr;
147 struct DriveInfoNode *node;
149 for (curr = (struct mb_drive *) mb->drives_addr;
150 (unsigned long) curr < mb->drives_addr + mb->drives_len;
151 curr = (struct mb_drive *) ((unsigned long) curr + curr->size))
153 node = AllocMem(sizeof(struct DriveInfoNode),MEMF_ANY|MEMF_CLEAR);
154 node->Number = curr->number;
155 node->Mode = curr->mode;
156 node->Cylinders = curr->cyls;
157 node->Heads = curr->heads;
158 node->Sectors = curr->secs;
159 ADDTAIL(&(BootLoaderBase->DriveInfo),(struct Node *)node);
161 D(bug("[BootLdr] Init: Drive %02x, CHS (%d/%d/%d) mode %s\n",
162 curr->number,
163 curr->cyls,curr->heads,curr->secs,
164 curr->mode?"CHS":"LBA"));
166 BootLoaderBase->Flags |= MB_FLAGS_DRIVES;
168 #endif
170 return TRUE;
173 ADD2INITLIB(GM_UNIQUENAME(Init), 0)