ReactOS  0.4.14-dev-554-g2f8d847
mboot.c File Reference
#include <freeldr.h>
#include <elf/elf.h>
#include <elf/reactos.h>
#include <of.h>
#include "ppcmmu/mmu.h"
#include "compat.h"
#include <debug.h>
Include dependency graph for mboot.c:

Go to the source code of this file.

Classes

struct  _ppc_map_set_t
 

Macros

#define PFN_SHIFT   12
 
#define PDE_SHIFT   22
 
#define PDE_SHIFT_PAE   18
 
#define STARTUP_BASE   0xC0000000
 
#define HYPERSPACE_BASE   0xC0400000
 
#define HYPERSPACE_PAE_BASE   0xC0800000
 
#define APIC_BASE   0xFEC00000
 
#define KPCR_BASE   0xFF000000
 
#define LowMemPageTableIndex   0
 
#define StartupPageTableIndex   (STARTUP_BASE >> 22)
 
#define HyperspacePageTableIndex   (HYPERSPACE_BASE >> 22)
 
#define KpcrPageTableIndex   (KPCR_BASE >> 22)
 
#define ApicPageTableIndex   (APIC_BASE >> 22)
 
#define BAT_GRANULARITY   (64 * 1024)
 
#define KernelMemorySize   (8 * 1024 * 1024)
 
#define XROUNDUP(x, n)   ((((ULONG)x) + ((n) - 1)) & (~((n) - 1)))
 
#define TAG_MBOOT   'oobM'
 
#define ELF_SECTION(n)   ((Elf32_Shdr*)(sptr + (n * shsize)))
 
#define COFF_FIRST_SECTION(h)   ((PIMAGE_SECTION_HEADER) ((DWORD)h+FIELD_OFFSET(IMAGE_NT_HEADERS,OptionalHeader)+(SWAPW(((PIMAGE_NT_HEADERS)(h))->FileHeader.SizeOfOptionalHeader))))
 

Typedefs

typedef void(* KernelEntryFn) (void *)
 
typedef struct _ppc_map_set_t ppc_map_set_t
 

Functions

PLOADER_MODULE NTAPI LdrGetModuleObject (PCHAR ModuleName)
 
NTSTATUS NTAPI LdrPEFixupImports (IN PVOID DllBase, IN PCHAR DllName)
 
VOID PpcInitializeMmu (int max)
 
int MmuPageMiss (int trapCode, ppc_trap_frame_t *trap)
 
paddr_t MmuTranslate (paddr_t possibly_virtual)
 
VOID NTAPI FrLdrAddPageMapping (ppc_map_set_t *set, int proc, paddr_t phys, vaddr_t virt)
 
VOID NTAPI FrLdrStartup (ULONG Magic)
 
VOID FASTCALL FrLdrSetupPae (ULONG Magic)
 
VOID FASTCALL FrLdrGetKernelBase (VOID)
 
VOID FASTCALL FrLdrGetPaeMode (VOID)
 
VOID FASTCALL FrLdrSetupPageDirectory (VOID)
 
BOOLEAN NTAPI FrLdrMapModule (FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG KernelAddr)
 
BOOLEAN NTAPI FrLdrMapKernel (FILE *KernelImage)
 
ULONG_PTR NTAPI FrLdrLoadModule (FILE *ModuleImage, PCSTR ModuleName, PULONG ModuleSize)
 
PVOID NTAPI FrLdrMapImage (IN FILE *Image, IN PCHAR ShortName, IN ULONG ImageType)
 
ULONG_PTR NTAPI FrLdrCreateModule (PCSTR ModuleName)
 
BOOLEAN NTAPI FrLdrCloseModule (ULONG_PTR ModuleBase, ULONG ModuleSize)
 

Variables

of_proxy ofproxy
 
PVOID KernelMemory = NULL
 
char reactos_module_strings [64][256]
 
ULONG_PTR NextModuleBase = 0
 
PLOADER_MODULE CurrentModule = NULL
 
ULONG_PTR KernelBase
 
BOOLEAN PaeModeEnabled
 
ULONG_PTR KernelEntryPoint
 
PVOID memmove_dummy = memmove
 
int mmu_handle
 
int _start []
 
int _end []
 

Macro Definition Documentation

◆ APIC_BASE

#define APIC_BASE   0xFEC00000

Definition at line 45 of file mboot.c.

◆ ApicPageTableIndex

#define ApicPageTableIndex   (APIC_BASE >> 22)

Definition at line 52 of file mboot.c.

◆ BAT_GRANULARITY

#define BAT_GRANULARITY   (64 * 1024)

Definition at line 54 of file mboot.c.

◆ COFF_FIRST_SECTION

#define COFF_FIRST_SECTION (   h)    ((PIMAGE_SECTION_HEADER) ((DWORD)h+FIELD_OFFSET(IMAGE_NT_HEADERS,OptionalHeader)+(SWAPW(((PIMAGE_NT_HEADERS)(h))->FileHeader.SizeOfOptionalHeader))))

Definition at line 416 of file mboot.c.

◆ ELF_SECTION

#define ELF_SECTION (   n)    ((Elf32_Shdr*)(sptr + (n * shsize)))

Definition at line 415 of file mboot.c.

◆ HYPERSPACE_BASE

#define HYPERSPACE_BASE   0xC0400000

Definition at line 43 of file mboot.c.

◆ HYPERSPACE_PAE_BASE

#define HYPERSPACE_PAE_BASE   0xC0800000

Definition at line 44 of file mboot.c.

◆ HyperspacePageTableIndex

#define HyperspacePageTableIndex   (HYPERSPACE_BASE >> 22)

Definition at line 50 of file mboot.c.

◆ KernelMemorySize

#define KernelMemorySize   (8 * 1024 * 1024)

Definition at line 55 of file mboot.c.

◆ KPCR_BASE

#define KPCR_BASE   0xFF000000

Definition at line 46 of file mboot.c.

◆ KpcrPageTableIndex

#define KpcrPageTableIndex   (KPCR_BASE >> 22)

Definition at line 51 of file mboot.c.

◆ LowMemPageTableIndex

#define LowMemPageTableIndex   0

Definition at line 48 of file mboot.c.

◆ PDE_SHIFT

#define PDE_SHIFT   22

Definition at line 39 of file mboot.c.

◆ PDE_SHIFT_PAE

#define PDE_SHIFT_PAE   18

Definition at line 40 of file mboot.c.

◆ PFN_SHIFT

#define PFN_SHIFT   12

Definition at line 36 of file mboot.c.

◆ STARTUP_BASE

#define STARTUP_BASE   0xC0000000

Definition at line 42 of file mboot.c.

◆ StartupPageTableIndex

#define StartupPageTableIndex   (STARTUP_BASE >> 22)

Definition at line 49 of file mboot.c.

◆ TAG_MBOOT

#define TAG_MBOOT   'oobM'

Definition at line 58 of file mboot.c.

◆ XROUNDUP

#define XROUNDUP (   x,
  n 
)    ((((ULONG)x) + ((n) - 1)) & (~((n) - 1)))

Definition at line 56 of file mboot.c.

Typedef Documentation

◆ KernelEntryFn

typedef void(* KernelEntryFn) (void *)

Definition at line 110 of file mboot.c.

◆ ppc_map_set_t

Function Documentation

◆ FrLdrAddPageMapping()

VOID NTAPI FrLdrAddPageMapping ( ppc_map_set_t set,
int  proc,
paddr_t  phys,
vaddr_t  virt 
)

Definition at line 152 of file mboot.c.

153 {
154  int j;
155  paddr_t page = ROUND_DOWN(phys, (1<<PFN_SHIFT));
156 
157  if (virt == 0)
158  virt = ROUND_DOWN(page, (1<<PFN_SHIFT));
159  else
160  virt = ROUND_DOWN(virt, (1<<PFN_SHIFT));
161 
163 
164  //printf("Mapping virt [%x] to phys [%x (from) %x]\n", virt, page, phys);
165 
166  for( j = 0; j < set->usecount; j++ )
167  {
168  if(set->info[j].addr == page) return;
169  }
170 
171  if (!set->mapsize)
172  {
173  set->mapsize = 0x80;
174  set->info = MmAllocateMemory(0x80 * sizeof(*set->info));
175  }
176  else if (set->mapsize <= set->usecount)
177  {
178  ppc_map_info_t *newinfo = MmAllocateMemory(set->mapsize * 2 * sizeof(*set->info));
179  memcpy(newinfo, set->info, set->mapsize * sizeof(*set->info));
180  MmFreeMemory(set->info);
181  set->info = newinfo;
182  set->mapsize *= 2;
183  }
184 
185  set->info[set->usecount].flags = MMU_ALL_RW;
186  set->info[set->usecount].proc = proc;
187  set->info[set->usecount].addr = virt;
188  set->info[set->usecount].phys = page;
189  set->usecount++;
190 }
static HANDLE proc()
Definition: pdb.c:32
unsigned long paddr_t
Definition: mmu.h:89
paddr_t MmuTranslate(paddr_t possibly_virtual)
Definition: mboot.c:129
Definition: module.h:566
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
PVOID MmAllocateMemory(SIZE_T MemorySize)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
VOID MmFreeMemory(PVOID MemoryPointer)
Definition: mm.c:215
#define PFN_SHIFT
Definition: mboot.c:36
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
#define MMU_ALL_RW
Definition: mmu.h:78
Definition: _set.h:46

Referenced by FrLdrStartup().

◆ FrLdrCloseModule()

BOOLEAN NTAPI FrLdrCloseModule ( ULONG_PTR  ModuleBase,
ULONG  ModuleSize 
)

Definition at line 824 of file mboot.c.

826 {
827  PLOADER_MODULE ModuleData = CurrentModule;
828 
829  /* Make sure a module is opened */
830  if (ModuleData) {
831 
832  /* Make sure this is the right module and that it hasn't been closed */
833  if ((ModuleBase == ModuleData->ModStart) && (ModuleData->ModEnd == MAXULONG_PTR)) {
834 
835  /* Close the Module */
836  ModuleData->ModEnd = ModuleData->ModStart + ModuleSize;
837 
838  /* Set the next Module Base and increase the number of modules */
840  LoaderBlock.ModsCount++;
841 
842  /* Close the currently opened module */
844 
845  /* Success */
846  return(TRUE);
847  }
848  }
849 
850  /* Failure path */
851  return(FALSE);
852 }
#define TRUE
Definition: types.h:120
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
#define MAXULONG_PTR
Definition: basetsd.h:103
smooth NULL
Definition: ftsmooth.c:416
PLOADER_MODULE CurrentModule
Definition: mboot.c:66
ULONG_PTR NextModuleBase
Definition: mboot.c:63
#define PAGE_SIZE
Definition: env_spec_w32.h:49

◆ FrLdrCreateModule()

ULONG_PTR NTAPI FrLdrCreateModule ( PCSTR  ModuleName)

Definition at line 798 of file mboot.c.

799 {
800  PLOADER_MODULE ModuleData;
801  PSTR NameBuffer;
802 
803  /* Get current module data structure and module name string array */
804  ModuleData = &reactos_modules[LoaderBlock.ModsCount];
805  NameBuffer = reactos_module_strings[LoaderBlock.ModsCount];
806 
807  /* Set up the structure */
808  ModuleData->ModStart = NextModuleBase;
809  ModuleData->ModEnd = -1;
810 
811  /* Copy the name */
812  strcpy(NameBuffer, ModuleName);
813  ModuleData->String = (ULONG_PTR)NameBuffer;
814 
815  /* Set the current Module */
817 
818  /* Return Module Base Address */
819  return(ModuleData->ModStart);
820 }
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char * ModuleName
Definition: acpixf.h:1270
char reactos_module_strings[64][256]
Definition: mboot.c:60
PLOADER_MODULE CurrentModule
Definition: mboot.c:66
ULONG_PTR NextModuleBase
Definition: mboot.c:63
signed char * PSTR
Definition: retypes.h:7
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define ULONG_PTR
Definition: config.h:101

◆ FrLdrGetKernelBase()

VOID FASTCALL FrLdrGetKernelBase ( VOID  )

Definition at line 327 of file mboot.c.

328 {
329  PCHAR p;
330 
331  /* Default kernel base at 2GB */
332  KernelBase = 0x80800000;
333 
334  /* Set KernelBase */
335  LoaderBlock.KernelBase = 0x80000000;
336 
337  /* Read Command Line */
338  p = (PCHAR)LoaderBlock.CommandLine;
339  while ((p = strchr(p, '/')) != NULL) {
340 
341  /* Find "/3GB" */
342  if (!_strnicmp(p + 1, "3GB", 3)) {
343 
344  /* Make sure there's nothing following it */
345  if (p[4] == ' ' || p[4] == 0) {
346 
347  /* Use 3GB */
348  KernelBase = 0xE0000000;
349  LoaderBlock.KernelBase = 0xC0000000;
350  }
351  }
352 
353  p++;
354  }
355 }
signed char * PCHAR
Definition: retypes.h:7
while(1)
Definition: macro.lex.yy.c:740
_Check_return_ _CRTIMP int __cdecl _strnicmp(_In_reads_or_z_(_MaxCount) const char *_Str1, _In_reads_or_z_(_MaxCount) const char *_Str2, _In_ size_t _MaxCount)
smooth NULL
Definition: ftsmooth.c:416
#define PCHAR
Definition: match.c:90
ULONG_PTR KernelBase
Definition: mboot.c:69
char * strchr(const char *String, int ch)
Definition: utclib.c:501
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by FrLdrMapKernel().

◆ FrLdrGetPaeMode()

VOID FASTCALL FrLdrGetPaeMode ( VOID  )

Definition at line 375 of file mboot.c.

376 {
377 }

◆ FrLdrLoadModule()

ULONG_PTR NTAPI FrLdrLoadModule ( FILE ModuleImage,
PCSTR  ModuleName,
PULONG  ModuleSize 
)

Definition at line 710 of file mboot.c.

713 {
716  ULONG LocalModuleSize;
717  ULONG_PTR ThisModuleBase = NextModuleBase;
718  PLOADER_MODULE ModuleData;
719  PSTR NameBuffer;
720  PSTR TempName;
721 
722  /* Get current module data structure and module name string array */
723  ModuleData = &reactos_modules[LoaderBlock.ModsCount];
724 
725  /* Get only the Module Name */
726  do {
727 
728  TempName = strchr(ModuleName, '\\');
729 
730  if(TempName) {
731  ModuleName = TempName + 1;
732  }
733 
734  } while(TempName);
735  NameBuffer = reactos_module_strings[LoaderBlock.ModsCount];
736 
737  /* Get Module Size */
738  Status = ArcGetFileInformation(ModuleImage, &FileInfo);
739  if (Status != ESUCCESS || FileInfo.EndingAddress.HighPart != 0)
740  LocalModuleSize = 0;
741  else
742  LocalModuleSize = FileInfo.EndingAddress.LowPart;
743 
744  /* Fill out Module Data Structure */
745  ModuleData->ModStart = NextModuleBase;
746  ModuleData->ModEnd = NextModuleBase + LocalModuleSize;
747 
748  /* Save name */
749  strcpy(NameBuffer, ModuleName);
750  ModuleData->String = (ULONG_PTR)NameBuffer;
751 
752  /* Load the file image */
753  ArcRead(ModuleImage, (PVOID)NextModuleBase, LocalModuleSize, NULL);
754 
755  /* Move to next memory block and increase Module Count */
757  LoaderBlock.ModsCount++;
758 
759  /* Return Module Size if required */
760  if (ModuleSize != NULL) {
761  *ModuleSize = LocalModuleSize;
762  }
763 
764  printf("Module %s (%x-%x) next at %x\n",
765  ModuleData->String,
766  ModuleData->ModStart,
767  ModuleData->ModEnd,
769 
770  return ThisModuleBase;
771 }
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
Definition: arc.h:32
ULONG ARC_STATUS
Definition: arc.h:4
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char * ModuleName
Definition: acpixf.h:1270
char reactos_module_strings[64][256]
Definition: mboot.c:60
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
ULONG_PTR NextModuleBase
Definition: mboot.c:63
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:236
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Status
Definition: gdiplustypes.h:24
signed char * PSTR
Definition: retypes.h:7
char * strchr(const char *String, int ch)
Definition: utclib.c:501
ARC_STATUS ArcGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: fs.c:250
struct FileInfo FileInfo
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define printf
Definition: config.h:203

◆ FrLdrMapImage()

PVOID NTAPI FrLdrMapImage ( IN FILE Image,
IN PCHAR  ShortName,
IN ULONG  ImageType 
)

Definition at line 775 of file mboot.c.

776 {
777  PVOID Result = NULL;
778 
779  printf("Loading image %s (type %d)\n", ShortName, ImageType);
780 
781  if (ImageType == 1)
782  {
783  if(FrLdrMapKernel(Image))
785  }
786  else
787  {
788  PVOID ModuleBase = (PVOID)NextModuleBase;
789 
790  if(FrLdrMapModule(Image, ShortName, 0, 0))
791  Result = ModuleBase;
792  }
793  return Result;
794 }
IN PDCB IN POEM_STRING IN PUNICODE_STRING IN OUT POEM_STRING ShortName
Definition: fatprocs.h:1294
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
void * PVOID
Definition: retypes.h:9
ULONG_PTR NextModuleBase
Definition: mboot.c:63
BOOLEAN NTAPI FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG KernelAddr)
Definition: mboot.c:420
PVOID KernelMemory
Definition: mboot.c:33
ImageType
Definition: gdiplusenums.h:191
BOOLEAN NTAPI FrLdrMapKernel(FILE *KernelImage)
Definition: mboot.c:697
#define printf
Definition: config.h:203

◆ FrLdrMapKernel()

BOOLEAN NTAPI FrLdrMapKernel ( FILE KernelImage)

Definition at line 697 of file mboot.c.

698 {
699  /* Get Kernel Base */
701 
702  /* Allocate kernel memory */
704 
705  return FrLdrMapModule(KernelImage, "ntoskrnl.exe", KernelMemory, KernelBase);
706 }
#define KernelMemorySize
Definition: mboot.c:55
PVOID MmAllocateMemory(SIZE_T MemorySize)
BOOLEAN NTAPI FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG KernelAddr)
Definition: mboot.c:420
ULONG_PTR KernelBase
Definition: mboot.c:69
PVOID KernelMemory
Definition: mboot.c:33
VOID FASTCALL FrLdrGetKernelBase(VOID)
Definition: mboot.c:327

Referenced by FrLdrMapImage().

◆ FrLdrMapModule()

BOOLEAN NTAPI FrLdrMapModule ( FILE KernelImage,
PCHAR  ImageName,
PCHAR  MemLoadAddr,
ULONG  KernelAddr 
)

Definition at line 420 of file mboot.c.

421 {
422  PIMAGE_DOS_HEADER ImageHeader = 0;
423  PIMAGE_NT_HEADERS NtHeader = 0;
424  PIMAGE_SECTION_HEADER Section;
425  ULONG SectionCount;
426  ULONG ImageSize;
427  INT i, j;
428  PLOADER_MODULE ModuleData;
429  //int phsize, phnum;
430  int shsize, shnum, relsize, SectionAddr = 0;
431  PCHAR sptr;
432  Elf32_Ehdr ehdr;
433  Elf32_Shdr *shdr;
435  PSTR TempName;
436 
437  TempName = strrchr(ImageName, '\\');
438  if(TempName) TempName++; else TempName = (PSTR)ImageName;
439  ModuleData = LdrGetModuleObject(TempName);
440 
441  if(ModuleData)
442  {
443  return TRUE;
444  }
445 
446  if(!KernelAddr)
447  KernelAddr = (ULONG)NextModuleBase - (ULONG)KernelMemory + KernelBase;
448  if(!MemLoadAddr)
449  MemLoadAddr = (PCHAR)NextModuleBase;
450 
451  ModuleData = &reactos_modules[LoaderBlock.ModsCount];
452  //printf("Loading file (elf at %x)\n", KernelAddr);
453 
454  /* Load the first 1024 bytes of the kernel image so we can read the PE header */
455  if (ArcRead(KernelImage, &ehdr, sizeof(ehdr), NULL) != ESUCCESS) {
456 
457  /* Fail if we couldn't read */
458  printf("Couldn't read the elf header\n");
459  return FALSE;
460  }
461 
462  /* Start by getting elf headers */
463  //phsize = ehdr.e_phentsize;
464  //phnum = ehdr.e_phnum;
465  shsize = ehdr.e_shentsize;
466  shnum = ehdr.e_shnum;
467  sptr = (PCHAR)FrLdrTempAlloc(shnum * shsize, TAG_MBOOT);
468 
469  /* Read section headers */
470  Position.QuadPart = ehdr.e_shoff;
471  ArcSeek(KernelImage, &Position, SeekAbsolute);
472  ArcRead(KernelImage, sptr, shsize * shnum, NULL);
473 
474  /* Now we'll get the PE Header */
475  for( i = 0; i < shnum; i++ )
476  {
477  shdr = ELF_SECTION(i);
478  shdr->sh_addr = 0;
479 
480  /* Find the PE Header */
481  if (shdr->sh_type == TYPE_PEHEADER)
482  {
483  Position.QuadPart = shdr->sh_offset;
484  ArcSeek(KernelImage, &Position, SeekAbsolute);
485  ArcRead(KernelImage, MemLoadAddr, shdr->sh_size, NULL);
486  ImageHeader = (PIMAGE_DOS_HEADER)MemLoadAddr;
487  NtHeader = (PIMAGE_NT_HEADERS)((PCHAR)MemLoadAddr + SWAPD(ImageHeader->e_lfanew));
488 #if 0
489  printf("NtHeader at %x\n", SWAPD(ImageHeader->e_lfanew));
490  printf("SectionAlignment %x\n",
492  SectionAddr = ROUND_UP
493  (shdr->sh_size, SWAPD(NtHeader->OptionalHeader.SectionAlignment));
494  printf("Header ends at %x\n", SectionAddr);
495 #endif
496  break;
497  }
498  }
499 
500  if(i == shnum)
501  {
502  printf("No peheader section encountered :-(\n");
503  return 0;
504  }
505 #if 0
506  else
507  {
508  printf("DOS SIG: %s\n", (PCHAR)MemLoadAddr);
509  }
510 #endif
511 
512  /* Save the Image Base */
513  NtHeader->OptionalHeader.ImageBase = SWAPD(KernelAddr);
514 
515  /* Load the file image */
516  Section = COFF_FIRST_SECTION(NtHeader);
517  SectionCount = SWAPW(NtHeader->FileHeader.NumberOfSections);
518 
519  /* Walk each section */
520  for (i=0; i < SectionCount; i++, Section++)
521  {
522  shdr = ELF_SECTION((SWAPD(Section->PointerToRawData)+1));
523 
524  shdr->sh_addr = SectionAddr = SWAPD(Section->VirtualAddress);
525  shdr->sh_addr += KernelAddr;
526 
527  Section->PointerToRawData = SWAPD((Section->VirtualAddress - KernelAddr));
528 
529  if (shdr->sh_type != SHT_NOBITS)
530  {
531  /* Content area */
532  printf("Loading section %d at %x (real: %x:%d)\n", i, KernelAddr + SectionAddr, MemLoadAddr+SectionAddr, shdr->sh_size);
533  Position.QuadPart = shdr->sh_offset;
534  ArcSeek(KernelImage, &Position, SeekAbsolute);
535  ArcRead(KernelImage, MemLoadAddr + SectionAddr, shdr->sh_size, NULL);
536  }
537  else
538  {
539  /* Zero it out */
540  printf("BSS section %d at %x\n", i, KernelAddr + SectionAddr);
541  memset(MemLoadAddr + SectionAddr, 0,
542  ROUND_UP(shdr->sh_size,
544  }
545  }
546 
547  ImageSize = SWAPD(NtHeader->OptionalHeader.SizeOfImage);
548  printf("Total image size is %x\n", ImageSize);
549 
550  /* Handle relocation sections */
551  for (i = 0; i < shnum; i++) {
552  Elf32_Rela reloc = { };
553  ULONG *Target32;
554  USHORT *Target16;
555  int numreloc, relstart, targetSection;
556  Elf32_Sym symbol;
557  PCHAR RelocSection, SymbolSection;
558 
559  shdr = ELF_SECTION(i);
560  /* Only relocs here */
561  if((shdr->sh_type != SHT_REL) &&
562  (shdr->sh_type != SHT_RELA)) continue;
563 
564  relstart = shdr->sh_offset;
565  relsize = shdr->sh_type == SHT_RELA ? 12 : 8;
566  numreloc = shdr->sh_size / relsize;
567  targetSection = shdr->sh_info;
568 
569  if (!ELF_SECTION(targetSection)->sh_addr) continue;
570 
571  RelocSection = FrLdrTempAlloc(shdr->sh_size, TAG_MBOOT);
572  Position.QuadPart = relstart;
573  ArcSeek(KernelImage, &Position, SeekAbsolute);
574  ArcRead(KernelImage, RelocSection, shdr->sh_size, NULL);
575 
576  /* Get the symbol section */
577  shdr = ELF_SECTION(shdr->sh_link);
578 
579  SymbolSection = FrLdrTempAlloc(shdr->sh_size, TAG_MBOOT);
580  Position.QuadPart = shdr->sh_offset;
581  ArcSeek(KernelImage, &Position, SeekAbsolute);
582  ArcRead(KernelImage, SymbolSection, shdr->sh_size, NULL);
583 
584  for(j = 0; j < numreloc; j++)
585  {
586  ULONG S,A,P;
587 
588  /* Get the reloc */
589  memcpy(&reloc, RelocSection + (j * relsize), sizeof(reloc));
590 
591  /* Get the symbol */
592  memcpy(&symbol, SymbolSection + (ELF32_R_SYM(reloc.r_info) * sizeof(symbol)), sizeof(symbol));
593 
594  /* Compute addends */
595  S = symbol.st_value + ELF_SECTION(symbol.st_shndx)->sh_addr;
596  A = reloc.r_addend;
597  P = reloc.r_offset + ELF_SECTION(targetSection)->sh_addr;
598 
599 #if 0
600  printf("Symbol[%d] %d -> %d(%x:%x) -> %x(+%x)@%x\n",
601  ELF32_R_TYPE(reloc.r_info),
602  ELF32_R_SYM(reloc.r_info),
603  symbol.st_shndx,
604  ELF_SECTION(symbol.st_shndx)->sh_addr,
605  symbol.st_value,
606  S,
607  A,
608  P);
609 #endif
610 
611  Target32 = (ULONG*)(((PCHAR)MemLoadAddr) + (P - KernelAddr));
612  Target16 = (USHORT *)Target32;
613 
614  switch (ELF32_R_TYPE(reloc.r_info))
615  {
616  case R_PPC_NONE:
617  break;
618  case R_PPC_ADDR32:
619  *Target32 = S + A;
620  break;
621  case R_PPC_REL32:
622  *Target32 = S + A - P;
623  break;
624  case R_PPC_UADDR32: /* Special: Treat as RVA */
625  *Target32 = S + A - KernelAddr;
626  break;
627  case R_PPC_ADDR24:
628  *Target32 = (ADDR24_MASK & (S+A)) | (*Target32 & ~ADDR24_MASK);
629  break;
630  case R_PPC_REL24:
631  *Target32 = (ADDR24_MASK & (S+A-P)) | (*Target32 & ~ADDR24_MASK);
632  break;
633  case R_PPC_ADDR16_LO:
634  *Target16 = S + A;
635  break;
636  case R_PPC_ADDR16_HA:
637  *Target16 = (S + A + 0x8000) >> 16;
638  break;
639  default:
640  break;
641  }
642 
643 #if 0
644  printf("reloc[%d:%x]: (type %x sym %d val %d) off %x add %x (old %x new %x)\n",
645  j,
646  ((ULONG)Target32) - ((ULONG)MemLoadAddr),
647  ELF32_R_TYPE(reloc.r_info),
648  ELF32_R_SYM(reloc.r_info),
649  symbol.st_value,
650  reloc.r_offset, reloc.r_addend,
651  x, *Target32);
652 #endif
653  }
654 
655  FrLdrTempFree(SymbolSection, TAG_MBOOT);
656  FrLdrTempFree(RelocSection, TAG_MBOOT);
657  }
658 
659  FrLdrTempFree(sptr, TAG_MBOOT);
660 
661  ModuleData->ModStart = (ULONG)MemLoadAddr;
662  /* Increase the next Load Base */
663  NextModuleBase = ROUND_UP((ULONG)MemLoadAddr + ImageSize, PAGE_SIZE);
664  ModuleData->ModEnd = NextModuleBase;
666  strcpy((PCHAR)ModuleData->String, ImageName);
667  printf("Module %s (%x-%x) next at %x\n",
668  ModuleData->String,
669  ModuleData->ModStart,
670  ModuleData->ModEnd,
672  LoaderBlock.ModsCount++;
673 
674  /* Return Success */
675  return TRUE;
676 }
signed char * PCHAR
Definition: retypes.h:7
Elf32_Size sh_size
Definition: elf32.h:76
#define COFF_FIRST_SECTION(h)
Definition: mboot.c:416
Elf32_Off e_shoff
Definition: elf32.h:55
#define TRUE
Definition: types.h:120
Elf32_Addr st_value
Definition: elf32.h:140
PLOADER_MODULE NTAPI LdrGetModuleObject(PCHAR ModuleName)
Definition: loader.c:40
#define SHT_NOBITS
Definition: common.h:254
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
#define SWAPW(x)
Definition: bytesex.h:8
#define TYPE_PEHEADER
Definition: reactos.h:4
Definition: arc.h:32
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
Elf32_Half e_shnum
Definition: elf32.h:61
static COORD Position
Definition: mouse.c:34
#define R_PPC_ADDR24
Definition: elf-powerpc.h:121
Elf32_Word sh_link
Definition: elf32.h:77
#define SWAPD(x)
Definition: bytesex.h:7
#define S(x)
Definition: test.h:207
Elf32_Sword r_addend
Definition: elf32.h:124
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
Definition: movable.cpp:7
DWORD PointerToRawData
Definition: pedump.c:290
#define R_PPC_NONE
Definition: elf-powerpc.h:119
Elf32_Word sh_info
Definition: elf32.h:78
int32_t INT
Definition: typedefs.h:56
#define SHT_REL
Definition: common.h:255
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
#define A(row, col)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Elf32_Word r_info
Definition: elf32.h:123
Elf32_Addr sh_addr
Definition: elf32.h:74
#define R_PPC_REL32
Definition: elf-powerpc.h:145
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:177
#define ELF_SECTION(n)
Definition: mboot.c:415
smooth NULL
Definition: ftsmooth.c:416
struct _IMAGE_DOS_HEADER * PIMAGE_DOS_HEADER
#define ELF32_R_TYPE(info)
Definition: elf32.h:129
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
Elf32_Addr r_offset
Definition: elf32.h:122
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define PCHAR
Definition: match.c:90
PVOID MmAllocateMemory(SIZE_T MemorySize)
ULONG_PTR NextModuleBase
Definition: mboot.c:63
ULONG_PTR KernelBase
Definition: mboot.c:69
#define SHT_RELA
Definition: common.h:250
Elf32_Half e_shentsize
Definition: elf32.h:60
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:236
#define ADDR24_MASK
Definition: reactos.h:5
static const char * ImageName
Definition: image.c:34
Definition: ttei1.cpp:12
ARC_STATUS ArcSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
Definition: fs.c:243
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define PAGE_SIZE
Definition: env_spec_w32.h:49
PVOID KernelMemory
Definition: mboot.c:33
Elf32_Half st_shndx
Definition: elf32.h:144
#define TAG_MBOOT
Definition: mboot.c:58
#define P(row, col)
Elf32_Word sh_type
Definition: elf32.h:72
unsigned short USHORT
Definition: pedump.c:61
#define R_PPC_ADDR16_LO
Definition: elf-powerpc.h:123
signed char * PSTR
Definition: retypes.h:7
Elf32_Off sh_offset
Definition: elf32.h:75
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define R_PPC_UADDR32
Definition: elf-powerpc.h:143
unsigned int ULONG
Definition: retypes.h:1
#define R_PPC_ADDR16_HA
Definition: elf-powerpc.h:125
#define R_PPC_ADDR32
Definition: elf-powerpc.h:120
#define memset(x, y, z)
Definition: compat.h:39
#define R_PPC_REL24
Definition: elf-powerpc.h:129
#define ELF32_R_SYM(info)
Definition: elf32.h:128
#define printf
Definition: config.h:203
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
Definition: ntddk_ex.h:187
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:186

Referenced by FrLdrMapImage(), and FrLdrMapKernel().

◆ FrLdrSetupPae()

VOID FASTCALL FrLdrSetupPae ( ULONG  Magic)

Definition at line 305 of file mboot.c.

306 {
307 }

◆ FrLdrSetupPageDirectory()

VOID FASTCALL FrLdrSetupPageDirectory ( VOID  )

Definition at line 398 of file mboot.c.

399 {
400 }

◆ FrLdrStartup()

VOID NTAPI FrLdrStartup ( ULONG  Magic)

Definition at line 196 of file mboot.c.

197 {
198  ULONG_PTR i, tmp, OldModCount = 0;
199  PCHAR ModHeader;
200  CHAR ModulesTreated[64] = { 0 };
201  ULONG NumberOfEntries = 0, UsedEntries = 0;
202  PPAGE_LOOKUP_TABLE_ITEM FreeLdrMap = MmGetMemoryMap(&NumberOfEntries);
203  ppc_map_set_t memmap = { };
204 
205  printf("FrLdrStartup\n");
206 
207  /* Disable EE */
208  __asm__("mfmsr %0" : "=r" (tmp));
209  tmp &= 0x7fff;
210  __asm__("mtmsr %0" : : "r" (tmp));
211 
212  while(OldModCount != LoaderBlock.ModsCount)
213  {
214  printf("Added %d modules last pass\n",
215  LoaderBlock.ModsCount - OldModCount);
216 
217  OldModCount = LoaderBlock.ModsCount;
218 
219  for(i = 0; i < LoaderBlock.ModsCount; i++)
220  {
221  if (!ModulesTreated[i])
222  {
223  ModulesTreated[i] = 1;
224  ModHeader = ((PCHAR)reactos_modules[i].ModStart);
225  if(ModHeader[0] == 'M' && ModHeader[1] == 'Z')
227  ((PVOID)reactos_modules[i].ModStart,
228  (PCHAR)reactos_modules[i].String);
229  }
230  }
231  }
232 
233  printf("Starting mmu\n");
234 
235  PpcInitializeMmu(0);
236 
237  printf("Allocating vsid 0 (kernel)\n");
238  MmuAllocVsid(0, 0xff00);
239 
240  /* We'll use vsid 1 for freeldr (expendable) */
241  printf("Allocating vsid 1 (freeldr)\n");
242  MmuAllocVsid(1, 0xff);
243 
244  printf("Mapping Freeldr Code (%x-%x)\n", _start, _end);
245 
246  /* Map memory zones */
247  /* Freeldr itself */
248  for( i = (int)_start;
249  i < (int)_end;
250  i += (1<<PFN_SHIFT) ) {
251  FrLdrAddPageMapping(&memmap, 1, i, 0);
252  }
253 
254  printf("KernelBase %x\n", KernelBase);
255 
256  /* Heap pages -- this gets the entire freeldr heap */
257  for( i = 0; i < NumberOfEntries; i++ ) {
258  tmp = i<<PFN_SHIFT;
259  if (FreeLdrMap[i].PageAllocated == LoaderSystemCode) {
260  UsedEntries++;
261  if (tmp >= (ULONG)KernelMemory &&
263  FrLdrAddPageMapping(&memmap, 0, tmp, KernelBase + tmp - (ULONG)KernelMemory);
264  } else {
265  FrLdrAddPageMapping(&memmap, 1, tmp, 0);
266  }
267  }
268  }
269 
270  MmuMapPage(memmap.info, memmap.usecount);
271 
272  printf("Finished Mapping the Freeldr Heap (used %d pages)\n", UsedEntries);
273 
274  printf("Setting initial segments\n");
275  MmuSetVsid(0, 8, 1);
276  MmuSetVsid(8, 16, 0);
277 
278  printf("Segments set!\n");
279 
280  MmuTurnOn((KernelEntryFn)KernelEntryPoint, &LoaderBlock);
281 
282  /* Nothing more */
283  while(1);
284 }
signed char * PCHAR
Definition: retypes.h:7
int usecount
Definition: mboot.c:124
#define KernelMemorySize
Definition: mboot.c:55
VOID NTAPI FrLdrAddPageMapping(ppc_map_set_t *set, int proc, paddr_t phys, vaddr_t virt)
Definition: mboot.c:152
char CHAR
Definition: xmlstorage.h:175
int _start[]
static WCHAR String[]
Definition: stringtable.c:55
uint32_t ULONG_PTR
Definition: typedefs.h:63
NTSTATUS NTAPI LdrPEFixupImports(IN PVOID DllBase, IN PCHAR DllName)
Definition: loader.c:316
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
#define PCHAR
Definition: match.c:90
int _end[]
PPAGE_LOOKUP_TABLE_ITEM MmGetMemoryMap(PFN_NUMBER *NoEntries)
Definition: mm.c:297
static void * MmuAllocVsid(int vsid, int mask)
Definition: mmu.h:242
ULONG_PTR KernelEntryPoint
Definition: mboot.c:75
ULONG_PTR KernelBase
Definition: mboot.c:69
PVOID KernelMemory
Definition: mboot.c:33
static int MmuMapPage(ppc_map_info_t *info, int count)
Definition: mmu.h:197
#define PFN_SHIFT
Definition: mboot.c:36
void(* KernelEntryFn)(void *)
Definition: mboot.c:110
VOID PpcInitializeMmu(int max)
static int MmuTurnOn(void *fun, void *arg)
Definition: mmu.h:227
static void MmuSetVsid(int start, int end, int vsid)
Definition: mmu.h:207
unsigned int ULONG
Definition: retypes.h:1
ppc_map_info_t * info
Definition: mboot.c:125
#define printf
Definition: config.h:203
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

◆ LdrGetModuleObject()

PLOADER_MODULE NTAPI LdrGetModuleObject ( PCHAR  ModuleName)

Definition at line 40 of file loader.c.

41 {
42  ULONG i;
43 
44  for (i = 0; i < LoaderBlock.ModsCount; i++)
45  {
46  if (strstr(_strupr((PCHAR)reactos_modules[i].String), _strupr(ModuleName)))
47  {
48  return &reactos_modules[i];
49  }
50  }
51 
52  return NULL;
53 }
signed char * PCHAR
Definition: retypes.h:7
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
static WCHAR String[]
Definition: stringtable.c:55
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char * ModuleName
Definition: acpixf.h:1270
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
unsigned int ULONG
Definition: retypes.h:1

Referenced by FrLdrMapModule(), LdrPEFixupForward(), and LdrPEGetOrLoadModule().

◆ LdrPEFixupImports()

NTSTATUS NTAPI LdrPEFixupImports ( IN PVOID  DllBase,
IN PCHAR  DllName 
)

Definition at line 316 of file loader.c.

318 {
319  PIMAGE_IMPORT_DESCRIPTOR ImportModuleDirectory;
320  PCHAR ImportedName;
322  PLOADER_MODULE ImportedModule;
323  ULONG Size;
324 
325  /* Process each import module */
326  ImportModuleDirectory = (PIMAGE_IMPORT_DESCRIPTOR)
328  TRUE,
330  &Size);
331  while (ImportModuleDirectory && ImportModuleDirectory->Name)
332  {
333  /* Check to make sure that import lib is kernel */
334  ImportedName = (PCHAR) DllBase + ImportModuleDirectory->Name;
335  //DbgPrint("Processing imports for file: %s into file: %s\n", DllName, ImportedName);
336 
337  Status = LdrPEGetOrLoadModule(DllName, ImportedName, &ImportedModule);
338  if (!NT_SUCCESS(Status)) return Status;
339 
340  Status = LdrPEProcessImportDirectoryEntry(DllBase, ImportedModule, ImportModuleDirectory);
341  if (!NT_SUCCESS(Status)) return Status;
342 
343  //DbgPrint("Imports for file: %s into file: %s complete\n", DllName, ImportedName);
344  ImportModuleDirectory++;
345  }
346 
347  return STATUS_SUCCESS;
348 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
struct _IMAGE_IMPORT_DESCRIPTOR * PIMAGE_IMPORT_DESCRIPTOR
#define PCHAR
Definition: match.c:90
NTSTATUS NTAPI LdrPEProcessImportDirectoryEntry(PVOID DriverBase, PLOADER_MODULE LoaderModule, PIMAGE_IMPORT_DESCRIPTOR ImportModuleDirectory)
Definition: loader.c:226
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI LdrPEGetOrLoadModule(IN PCHAR ModuleName, IN PCHAR ImportedName, IN PLOADER_MODULE *ImportedModule)
Definition: loader.c:286
#define RtlImageDirectoryEntryToData
Definition: compat.h:468
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
#define IMAGE_DIRECTORY_ENTRY_IMPORT
Definition: pedump.c:260
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by FrLdrStartup().

◆ MmuPageMiss()

int MmuPageMiss ( int  trapCode,
ppc_trap_frame_t trap 
)

Definition at line 112 of file mboot.c.

113 {
114  int i;
115  printf("TRAP %x\n", trapCode);
116  for( i = 0; i < 40; i++ )
117  printf("r[%d] %x\n", i, trap->gpr[i]);
118  printf("HALT!\n");
119  while(1);
120 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned long gpr[32]
Definition: mmu.h:113
#define printf
Definition: config.h:203

◆ MmuTranslate()

paddr_t MmuTranslate ( paddr_t  possibly_virtual)

Definition at line 129 of file mboot.c.

130 {
131  if (ofproxy)
132  {
133  /* Openfirmware takes liberties with boot-time memory.
134  * if you're in a unitary kernel, it's not as difficult, but since
135  * we rely on loading things into virtual space from here, we need
136  * to detect the mappings so far.
137  */
138  int args[2];
139  args[0] = possibly_virtual;
140  args[1] = 1; /* Marker to tell we want a physical addr */
141  return (paddr_t)ofw_callmethod_ret("translate", mmu_handle, 2, args, 3);
142  }
143  else
144  {
145  /* Other booters don't remap ram */
146  return possibly_virtual;
147  }
148 }
of_proxy ofproxy
Definition: mach.c:28
int ofw_callmethod_ret(const char *method, int handle, int nargs, int *args, int ret)
Definition: ofw_method.c:15
int mmu_handle
Definition: mach.c:31
Definition: match.c:390
unsigned long paddr_t
Definition: mmu.h:89

Referenced by FrLdrAddPageMapping().

◆ PpcInitializeMmu()

VOID PpcInitializeMmu ( int  max)

Referenced by FrLdrStartup().

Variable Documentation

◆ _end

int _end[]

Referenced by _MmuInit(), and FrLdrStartup().

◆ _start

int _start[]

Referenced by _MmuInit(), and FrLdrStartup().

◆ CurrentModule

PLOADER_MODULE CurrentModule = NULL

Definition at line 66 of file mboot.c.

Referenced by EnumProcessModules(), FrLdrCloseModule(), FrLdrCreateModule(), and START_TEST().

◆ KernelBase

ULONG_PTR KernelBase

Definition at line 69 of file mboot.c.

Referenced by FrLdrGetKernelBase(), FrLdrMapKernel(), FrLdrMapModule(), and FrLdrStartup().

◆ KernelEntryPoint

ULONG_PTR KernelEntryPoint

Definition at line 75 of file mboot.c.

Referenced by FrLdrStartup().

◆ KernelMemory

◆ memmove_dummy

PVOID memmove_dummy = memmove

Definition at line 78 of file mboot.c.

◆ mmu_handle

int mmu_handle

Definition at line 31 of file mach.c.

Referenced by MmuTranslate(), and PpcOfwInit().

◆ NextModuleBase

ULONG_PTR NextModuleBase = 0

◆ ofproxy

of_proxy ofproxy

Definition at line 28 of file mach.c.

Referenced by MmuTranslate().

◆ PaeModeEnabled

BOOLEAN PaeModeEnabled

Definition at line 72 of file mboot.c.

◆ reactos_module_strings

char reactos_module_strings[64][256]

Definition at line 60 of file mboot.c.

Referenced by FrLdrCreateModule(), and FrLdrLoadModule().