- Add stubs for video mach functions and update minor to 1.3.
[reactos.git] / reactos / boot / armllb / os / loader.c
1 /*
2 * PROJECT: ReactOS Boot Loader
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: boot/armllb/os/loader.c
5 * PURPOSE: OS Loader Code for LLB
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 #include "precomp.h"
10
11 BIOS_MEMORY_MAP MemoryMap[32];
12 ARM_BOARD_CONFIGURATION_BLOCK ArmBlock;
13 POSLOADER_INIT LoaderInit;
14
15 VOID
16 NTAPI
17 LlbAllocateMemoryEntry(IN BIOS_MEMORY_TYPE Type,
18 IN ULONG BaseAddress,
19 IN ULONG Length)
20 {
21 PBIOS_MEMORY_MAP Entry;
22
23 /* Get the next memory entry */
24 Entry = MemoryMap;
25 while (Entry->Length) Entry++;
26
27 /* Fill it out */
28 Entry->Length = Length;
29 Entry->BaseAddress = BaseAddress;
30 Entry->Type = Type;
31
32 /* Block count */
33 ArmBlock.MemoryMapEntryCount++;
34 }
35
36 VOID
37 NTAPI
38 LlbSetCommandLine(IN PCHAR CommandLine)
39 {
40 /* Copy the command line in the ARM block */
41 strcpy(ArmBlock.CommandLine, CommandLine);
42 }
43
44 VOID
45 NTAPI
46 LlbBuildArmBlock(VOID)
47 {
48 /* Write version number */
49 ArmBlock.MajorVersion = ARM_BOARD_CONFIGURATION_MAJOR_VERSION;
50 ArmBlock.MinorVersion = ARM_BOARD_CONFIGURATION_MINOR_VERSION;
51
52 /* Get arch type */
53 ArmBlock.BoardType = LlbHwGetBoardType();
54
55 /* Get peripheral clock rate */
56 ArmBlock.ClockRate = LlbHwGetPClk();
57
58 /* Get timer and serial port base addresses */
59 ArmBlock.TimerRegisterBase = LlbHwGetTmr0Base();
60 ArmBlock.UartRegisterBase = LlbHwGetUartBase(LlbHwGetSerialUart());
61
62 /* Debug */
63 DbgPrint("Machine Identifier: %lx\nPCLK: %d\nTIMER 0: %p\nSERIAL UART: %p\n",
64 ArmBlock.BoardType,
65 ArmBlock.ClockRate,
66 ArmBlock.TimerRegisterBase,
67 ArmBlock.UartRegisterBase);
68
69 /* Now load the memory map */
70 ArmBlock.MemoryMap = MemoryMap;
71
72 /* Write firmware callbacks */
73 ArmBlock.ConsPutChar = LlbFwPutChar;
74 ArmBlock.ConsKbHit = LlbFwKbHit;
75 ArmBlock.ConsGetCh = LlbFwGetCh;
76 ArmBlock.VideoClearScreen = LlbFwVideoClearScreen;
77 ArmBlock.VideoSetDisplayMode = LlbFwVideoSetDisplayMode;
78 ArmBlock.VideoGetDisplaySize = LlbFwVideoGetDisplaySize;
79 ArmBlock.VideoGetBufferSize = LlbFwVideoGetBufferSize;
80 ArmBlock.VideoSetTextCursorPosition = LlbFwVideoSetTextCursorPosition;
81 ArmBlock.VideoSetTextCursorPosition = LlbFwVideoSetTextCursorPosition;
82 ArmBlock.VideoHideShowTextCursor = LlbFwVideoHideShowTextCursor;
83 ArmBlock.VideoPutChar = LlbFwVideoPutChar;
84 ArmBlock.VideoCopyOffScreenBufferToVRAM = LlbFwVideoCopyOffScreenBufferToVRAM;
85 ArmBlock.VideoIsPaletteFixed = LlbFwVideoIsPaletteFixed;
86 ArmBlock.VideoSetPaletteColor = LlbFwVideoSetPaletteColor;
87 ArmBlock.VideoGetPaletteColor = LlbFwVideoGetPaletteColor;
88 ArmBlock.VideoSync = LlbFwVideoSync;
89 }
90
91 VOID
92 NTAPI
93 LlbBuildMemoryMap(VOID)
94 {
95 ULONG Base, Size;
96
97 /* Zero out the memory map */
98 memset(MemoryMap, 0, sizeof(MemoryMap));
99
100 /* Query memory information */
101 LlbEnvGetMemoryInformation(&Base, &Size);
102 LlbAllocateMemoryEntry(BiosMemoryUsable, Base, Size);
103
104 /* Call the hardware-specific function for hardware-defined regions */
105 LlbHwBuildMemoryMap(MemoryMap);
106 }
107
108 VOID
109 NTAPI
110 LlbLoadOsLoader(VOID)
111 {
112 PCHAR BootDevice;
113
114 /* Read the current boot device */
115 BootDevice = LlbEnvRead("boot-device");
116 printf("Loading OS Loader from: %s...\n", BootDevice);
117 if (!strcmp(BootDevice, "NAND"))
118 {
119 // todo
120 }
121 else if (!strcmp(BootDevice, "RAMDISK"))
122 {
123 /* Call the hardware-specific function */
124 LoaderInit = LlbHwLoadOsLoaderFromRam();
125 }
126 else if (!strcmp(BootDevice, "MMC") ||
127 !strcmp(BootDevice, "SD"))
128 {
129 //todo
130 }
131 else if (!strcmp(BootDevice, "HDD"))
132 {
133 //todo
134 }
135 printf("OS Loader loaded at 0x%p...JUMP!\n\n\n\n\n", LoaderInit);
136 }
137
138 VOID
139 NTAPI
140 LlbBoot(VOID)
141 {
142 /* Setup the ARM block */
143 LlbBuildArmBlock();
144
145 /* Build the memory map */
146 LlbBuildMemoryMap();
147
148 /* Load the OS loader */
149 LlbLoadOsLoader();
150
151 /* Jump to the OS Loader (FreeLDR in this case) */
152 LoaderInit(&ArmBlock);
153 }
154
155 /* EOF */