1,9 → 1,29 |
#include <efi.h> |
#include <efilib.h> |
|
#include <../../../../../../kernel/arch/ia64/include/bootinfo.h> |
|
#define KERNEL_LOAD_ADDRESS 0x4400000 |
|
#define MEM_MAP_DESCRIPTOR_OFFSET_TYPE 0 |
#define MEM_MAP_DESCRIPTOR_OFFSET_BASE 8 |
#define MEM_MAP_DESCRIPTOR_OFFSET_PAGES 24 |
|
|
|
//Link image as a data array into hello - usefull with network boot |
//#define IMAGE_LINKED |
|
bootinfo_t *bootinfo=(bootinfo_t *)BOOTINFO_ADDRESS; |
|
|
#ifdef IMAGE_LINKED |
extern char HOSimage[]; |
extern int HOSimagesize; |
#endif |
|
|
|
static CHAR16 * |
a2u (char *str) |
{ |
15,24 → 35,7 |
mem[i] = 0; |
return mem; |
} |
char HEX[256]; |
|
char hexs[]="0123456789ABCDEF"; |
/* |
void to_hex(unsigned long long num) |
{ |
int a; |
for(a=15;a>=0;a--) |
{ |
char c=num - (num & 0xfffffffffffffff0LL); |
num/=16; |
c=hexs[c]; |
HEX[a]=c; |
} |
|
} |
*/ |
|
EFI_STATUS |
efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) |
{ |
72,16 → 75,18 |
EFI_FILE *FileHandle; |
|
BS->HandleProtocol(LoadedImage->DeviceHandle, &FileSystemProtocol, &Vol); |
Vol->OpenVolume (Vol, &CurDir); |
|
char FileName[1024]; |
char *OsKernelBuffer; |
int i; |
int defaultLoad; |
int imageLoad; |
UINTN Size; |
|
StrCpy(FileName,DevicePathToStr(LoadedImage->FilePath)); |
for(i=StrLen(FileName);i>=0 && FileName[i]!='\\';i--); |
FileName[i] = 0; |
FileName[0] = 0; |
|
Print(L"%s\n",LoadedImage->LoadOptions); |
|
97,11 → 102,13 |
} |
while(LoadOptions[i]==L' ') if(LoadOptions[i++]==0) break; |
|
if(LoadOptions[i++]==0) |
if(LoadOptions[i++]==0){ |
StrCat(FileName,L"\\image.bin"); |
else{ |
defaultLoad=1; |
} |
/* else{ |
CHAR16 buf[1024]; |
buf[0]='\\'; |
//buf[0]='\\'; |
i--; |
int j; |
for(j=0;LoadOptions[i+j]!=L' '&&LoadOptions[i+j]!=0;j++) |
108,10 → 115,36 |
buf[j+1]=LoadOptions[i+j]; |
buf[j+1]=0; |
StrCat(FileName,buf); |
defaultLoad=0; |
}*/ |
else{ |
CHAR16 buf[1024]; |
//buf[0]='\\'; |
i--; |
int j; |
for(j=0;LoadOptions[i+j]!=L' '&&LoadOptions[i+j]!=0;j++) |
buf[j]=LoadOptions[i+j]; |
buf[j+1]=0; |
StrCat(FileName,buf); |
defaultLoad=0; |
} |
|
//Print(L"%s\n",FileName); |
imageLoad=1; |
#ifdef IMAGE_LINKED |
if(defaultLoad) { |
Print(L"Using Linked Image\n"); |
imageLoad=0; |
} |
#endif |
|
|
char * HOS; |
if(imageLoad) |
{ |
Size = 0x00400000; |
|
Vol->OpenVolume (Vol, &CurDir); |
|
EFI_STATUS stat; |
stat=CurDir->Open(CurDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0); |
if(EFI_ERROR(stat)){ |
118,28 → 151,65 |
Print(L"Error Opening Image %s\n",FileName); |
return 0; |
} |
Size = 0x00400000; |
BS->AllocatePool(EfiLoaderData, Size, &OsKernelBuffer); |
FileHandle->Read(FileHandle, &Size, OsKernelBuffer); |
FileHandle->Close(FileHandle); |
|
HOS = OsKernelBuffer; |
if(Size<1) return 0; |
|
|
char * HOS = OsKernelBuffer; |
} |
#ifdef IMAGE_LINKED |
else { |
HOS = HOSimage; |
Size = HOSimagesize; |
Print(L"Image start %llX\n",(long long)HOS); |
Print(L"Image size %llX\n",(long long)Size); |
Print(L"Image &size %llX\n",(long long)&Size); |
} |
#endif |
int HOSSize = Size; |
|
|
{ |
rArg rSAL; |
rArg rPAL; |
|
//Setup AP's wake up address |
LibSalProc(0x01000000,2,0x4400200,0,0,0,0,0,&rSAL); |
|
|
//Get System Frequency |
UINT64 sys_freq; |
LibSalProc(0x01000012,0,0,0,0,0,0,0,&rSAL); |
sys_freq=rSAL.p1; |
|
|
UINT64 freq_scale; |
//Get CPU Frequency to System Frequency ratio |
LibPalProc(14,0,0,0,&rPAL); |
freq_scale=rPAL.p1; |
|
|
UINT64 sapic; |
LibGetSalIpiBlock(&sapic); |
Print (L"SAPIC:%X\n", sapic); |
//bootinfo->sapic=sapic; |
|
|
UINT64 wakeup_intno; |
LibGetSalWakeupVector(&wakeup_intno); |
Print (L"WAKEUP INTNO:%X\n", wakeup_intno); |
|
|
|
|
|
UINTN cookie; |
void *p=(void *)KERNEL_LOAD_ADDRESS; |
UINTN mapsize,descsize; |
UINT32 desver; |
EFI_STATUS status; |
EFI_MEMORY_DESCRIPTOR emd[1024]; |
|
|
mapsize=1024*sizeof(emd); |
|
status=BS->AllocatePages(AllocateAnyPages,EfiLoaderData,/*(HOSSize>>12)+1*/ 1,p); |
if(EFI_ERROR(status)){ |
150,10 → 220,18 |
return EFI_SUCCESS; |
} |
|
status=BS->GetMemoryMap(&mapsize,emd,&cookie,&descsize,&desver); |
if(EFI_ERROR(status)){ |
Print(L"Error 1\n"); |
return EFI_SUCCESS; |
UINTN no_entryes; |
void * mds; |
mds=LibMemoryMap(&no_entryes,&cookie,&descsize,&desver); |
|
for(i=0;i<no_entryes;i++) |
{ |
|
unsigned int type=*((unsigned int *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_TYPE)); |
unsigned long long base=*((unsigned long long *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_BASE)); |
unsigned long long pages=*((unsigned long long *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_PAGES)); |
Print(L"T:%02d %016llX %016llX\n",type,base,pages*EFI_PAGE_SIZE); |
|
} |
status=BS->ExitBootServices(image,cookie); |
if(EFI_ERROR(status)){ |
161,13 → 239,63 |
return EFI_SUCCESS; |
} |
|
} |
|
int a; |
|
for(a=0;a<HOSSize;a++){ |
((char *)(0x4400000))[a]=HOS[a]; |
} |
bootinfo->sapic=(unsigned long *)sapic; |
bootinfo->wakeup_intno=wakeup_intno; |
bootinfo->sys_freq=sys_freq; |
bootinfo->freq_scale=freq_scale; |
bootinfo->hello_configured=1; |
|
|
bootinfo->memmap_items=0; |
|
for(i=0;i<no_entryes;i++) |
{ |
|
unsigned int type=*((unsigned int *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_TYPE)); |
unsigned long long base=*((unsigned long long *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_BASE)); |
unsigned long long pages=*((unsigned long long *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_PAGES)); |
|
|
|
switch (type) |
{ |
case EfiConventionalMemory: |
bootinfo->memmap[bootinfo->memmap_items].type=EFI_MEMMAP_FREE_MEM; |
bootinfo->memmap[bootinfo->memmap_items].base=base; |
bootinfo->memmap[bootinfo->memmap_items].size=pages*EFI_PAGE_SIZE; |
bootinfo->memmap_items++; |
break; |
case EfiMemoryMappedIO: |
bootinfo->memmap[bootinfo->memmap_items].type=EFI_MEMMAP_IO; |
bootinfo->memmap[bootinfo->memmap_items].base=base; |
bootinfo->memmap[bootinfo->memmap_items].size=pages*EFI_PAGE_SIZE; |
bootinfo->memmap_items++; |
break; |
case EfiMemoryMappedIOPortSpace: |
bootinfo->memmap[bootinfo->memmap_items].type=EFI_MEMMAP_IO_PORTS; |
bootinfo->memmap[bootinfo->memmap_items].base=base; |
bootinfo->memmap[bootinfo->memmap_items].size=pages*EFI_PAGE_SIZE; |
bootinfo->memmap_items++; |
break; |
|
default : |
break; |
} |
|
|
|
|
|
} |
|
|
|
//Run Kernel |
asm volatile( |
"nop.i 0x00 ;;\n" |
177,8 → 305,6 |
); |
|
|
while(1){ |
((volatile int *)(0x80000000000b8000))[0]++; |
} |
//Not reached |
return EFI_SUCCESS; |
} |