Example #1
0
void
asmb(void)
{
	Prog *p;
	long t, magic;
	Optab *o;
	vlong vl;

	if(debug['v'])
		Bprint(&bso, "%5.2f asm\n", cputime());
	Bflush(&bso);
	seek(cout, HEADR, 0);
	pc = INITTEXT;
	for(p = firstp; p != P; p = p->link) {
		if(p->as == ATEXT) {
			curtext = p;
			autosize = p->to.offset + 8;
			if(p->from3.type == D_CONST) {
				for(; pc < p->pc; pc++)
					CPUT(0);
			}
		}
		if(p->pc != pc) {
			diag("phase error %llux sb %llux",
				p->pc, pc);
			if(!debug['a'])
				prasm(curp);
			pc = p->pc;
		}
		curp = p;
		o = oplook(p);	/* could probably avoid this call */
		if(asmout(p, o, 0)) {
			p = p->link;
			pc += 4;
		}
		pc += o->size;
	}
	if(debug['a'])
		Bprint(&bso, "\n");
	Bflush(&bso);
	cflush();

	curtext = P;
	switch(HEADTYPE) {
	case 0:
	case 1:
	case 2:
	case 5:
	case 9:
	case 10:
		seek(cout, HEADR+textsize, 0);
		break;
	case 3:
		seek(cout, rnd(HEADR+textsize, 4), 0);
		break;
	}

	if(dlm){
		char buf[8];

		write(cout, buf, INITDAT-textsize);
		textsize = INITDAT;
	}

	for(t = 0; t < datsize; t += sizeof(buf)-100) {
		if(datsize-t > sizeof(buf)-100)
			datblk(t, sizeof(buf)-100);
		else
			datblk(t, datsize-t);
	}

	symsize = 0;
	lcsize = 0;
	if(!debug['s']) {
		if(debug['v'])
			Bprint(&bso, "%5.2f sym\n", cputime());
		Bflush(&bso);
		switch(HEADTYPE) {
		case 0:
		case 1:
		case 2:
		case 5:
		case 9:
		case 10:
			seek(cout, HEADR+textsize+datsize, 0);
			break;
		case 3:
			seek(cout, rnd(HEADR+textsize, 4)+datsize, 0);
			break;
		}
		if(!debug['s'])
			asmsym();
		if(debug['v'])
			Bprint(&bso, "%5.2f sp\n", cputime());
		Bflush(&bso);
		if(!debug['s'])
			asmlc();
		if(dlm)
			asmdyn();
		if(HEADTYPE == 0 || HEADTYPE == 1)	/* round up file length for boot image */
			if((symsize+lcsize) & 1)
				CPUT(0);
		cflush();
	}
	else if(dlm){
		asmdyn();
		cflush();
	}

	seek(cout, 0L, 0);
	switch(HEADTYPE) {
	case 0:
		lput(0x1030107);		/* magic and sections */
		lput(textsize);			/* sizes */
		lput(datsize);
		lput(bsssize);
		lput(symsize);			/* nsyms */
		lput(entryvalue());		/* va of entry */
		lput(0L);
		lput(lcsize);
		break;
	case 1:
		if(dlm)
			lput(0x80000000 | (4*21*21+7));		/* q.out magic */
		else
			lput(4*21*21+7);	/* q.out magic */
		lput(textsize);			/* sizes */
		lput(datsize);
		lput(bsssize);
		lput(symsize);			/* nsyms */
		lput(entryvalue());		/* va of entry */
		lput(0L);
		lput(lcsize);
		break;
	case 2:	/* plan9 */
		magic = 4*27*27+7;
		magic |= 0x00008000;		/* fat header */
		if(dlm)
			magic |= 0x80000000;	/* dlm */
		lput(magic);
		lput(textsize);			/* sizes */
		lput(datsize);
		lput(bsssize);
		lput(symsize);			/* nsyms */
		vl = entryvalue();
		lput(PADDR(vl));		/* va of entry (real mode on boot) */
		lput(0L);
		lput(lcsize);
		llput(vl);			/* va of entry */
		break;
	case 3:
		break;
	case 5:
		elf32(POWER, ELFDATA2MSB, 0, nil);
		break;
	case 9:					/* ELF64 Header */
	case 10:				/* A2 weirdness */
		elf64(POWER64, ELFDATA2MSB, 0, nil);
		break;
	}
	cflush();
}
Example #2
0
void readself(){
	printf("\nReading...\n");
	u32 offset=0;
	u32 magic               = be32(self);         /* 53434500 = SCE\0 */
	offset += sizeof(u32);
	u32 version             = le32(self+offset);  /* header version 3*/
	offset += sizeof(u32);
	u16 sdk_type            = le16(self+offset);  /* SDK type */
	offset += sizeof(u16);
	u16 header_type         = le16(self+offset);  /* 1 self, 2 unknown, 3 pkg */
	offset += sizeof(u16);
	u32 metadata_offset     = le32(self+offset);  /* metadata offset */
	offset += sizeof(u32);
	u64 header_len          = le64(self+offset);  /* self header length */
	offset += sizeof(u64);
	u64 elf_filesize        = le64(self+offset);  /* ELF file length */
	offset += sizeof(u64);
	u64 self_filesize       = le64(self+offset);  /* SELF file length */
	offset += sizeof(u64);
	u64 unknown1            = le64(self+offset);  /* UNKNOWN */
	offset += sizeof(u64);
	u64 self_offset         = le64(self+offset);  /* Self Offset */
	offset += sizeof(u64);
	u64 appinfo_offset      = le64(self+offset);  /* app info offset */
	offset += sizeof(u64);
	u64 elf_offset          = le64(self+offset);  /* ELF #1 offset */
	offset += sizeof(u64);
	u64 phdr_offset         = le64(self+offset);  /* program header offset */
	offset += sizeof(u64);
	u64 shdr_offset         = le64(self+offset);  /* section header offset */
	offset += sizeof(u64);
	u64 section_info_offset = le64(self+offset);  /* section info offset */
	offset += sizeof(u64);
	u64 sceversion_offset   = le64(self+offset);  /* version offset */
	offset += sizeof(u64);
	u64 controlinfo_offset  = le64(self+offset);  /* control info offset */
	offset += sizeof(u64);
	u64 controlinfo_size    = le64(self+offset);  /* control info size */
	offset += sizeof(u64);


	if(magic!=HDR)
		fail("\nERROR! Not a PlayStation Vita Self File (Magic: %08x)",magic);

	if(header_type!=1){
		char* HType;
		if(header_type==2)
			HType = "rvk";
		else if(header_type==3)
			HType = "pkg";
		else if(header_type==4)
			HType = "spp";
		else
			HType = "Unknown";

		fail("\nERROR! Not a PlayStation Vita Self File (Type : %08x)\n"
		       "                                               [%s]",header_type,HType);
	}

	printf("Magic                   0x%08x\n",magic);
	printf("Version                 0x%08x\n",version);
	printf("SDK Type                0x%08x\n",sdk_type);
	printf("Header Type             0x%08x\n",header_type);
	printf("Metadata offset         0x%08x\n",metadata_offset);
	printf("Header Length           0x%08x%08x (%u%04u Bytes)\n",(u32)(header_len),(u32)(header_len>>32),(u32)(header_len),(u32)(header_len>>32));
	printf("Elf Size                0x%08x%08x (%u%04u Bytes)\n",(u32)elf_filesize,(u32)(elf_filesize>>32),(u32)elf_filesize,(u32)(elf_filesize>>32));
	printf("Self Size               0x%08x%08x (%u%04u Bytes)\n",(u32)self_filesize,(u32)(self_filesize>>32),(u32)self_filesize,(u32)(self_filesize>>32));
	printf("Unknown_1               0x%08x%08x\n",(u32)unknown1,(u32)(unknown1>>32));
	printf("Self Offset             0x%08x%08x\n",(u32)self_offset,(u32)(self_offset>>32));
	printf("Application Info Offset 0x%08x%08x\n",(u32)appinfo_offset,(u32)(appinfo_offset>>32));
	printf("Elf Offset              0x%08x%08x\n",(u32)elf_offset,(u32)(elf_offset>>32));
	printf("Program hdr  Offset     0x%08x%08x\n",(u32)phdr_offset,(u32)(phdr_offset>>32));
	printf("Section hdr  Offset     0x%08x%08x\n",(u32)shdr_offset,(u32)(shdr_offset>>32));
	printf("Section Info Offset     0x%08x%08x\n",(u32)section_info_offset,(u32)(section_info_offset>>32));
	printf("Version Offset          0x%08x%08x\n",(u32)sceversion_offset,(u32)(sceversion_offset>>32));
	printf("Control Info Offset     0x%08x%08x\n",(u32)controlinfo_offset,(u32)(controlinfo_offset>>32));
	printf("Control Info Size       0x%08x%08x (%u%04u Bytes)\n",(u32)controlinfo_size,(u32)(controlinfo_size>>32)
								    ,(u32)controlinfo_size,(u32)(controlinfo_size>>32));
	
	if(((u32)appinfo_offset)!=0)
		app_info64(appinfo_offset);
	else
		app_info((u32)(appinfo_offset>>32));

	if(((u32)(elf_offset))!=0)
		elf64(elf_offset);
	else
		elf(((u32)(elf_offset>>32)));

	if(((u32)phdr_offset)!=0)
		program_hdr64(phdr_offset);
	else if((phdr_offset>>32)!=0)
		program_hdr((u32)(phdr_offset>>32));

	if(((u32)shdr_offset)!=0)
		section_hdr64(shdr_offset);
	else if((shdr_offset>>32)!=0)
		section_hdr(((u32)(shdr_offset>>32)));

	if(((u32)sceversion_offset)!=0)
		sce_version64(sceversion_offset);
	else
		sce_version(((u32)(sceversion_offset>>32)));

	if(((u32)controlinfo_offset)!=0)
		control_information64(controlinfo_offset);
	else
		control_information(((u32)(controlinfo_offset>>32)));

	printf("\nDone\n");
}
Example #3
0
void
asmb(void)
{
	Prog *p;
	long magic, t, etext;
	vlong vl;
	Optab *o;

	if(debug['v'])
		Bprint(&bso, "%5.2f asm\n", cputime());
	Bflush(&bso);
	OFFSET = HEADR;
	seek(cout, OFFSET, 0);
	pc = INITTEXT;
	for(p = firstp; p != P; p = p->link) {
		if(p->as == ATEXT) {
			curtext = p;
			autosize = p->to.offset + PCSZ;
		}
		if(p->as == ADWORD && (pc & 7) != 0) {
			lputl(0);
			pc += 4;
		}
		if(p->pc != pc) {
			diag("phase error %llux sb %llux",
				p->pc, pc);
			if(!debug['a'])
				prasm(curp);
			pc = p->pc;
		}
		curp = p;
		o = oplook(p);	/* could probably avoid this call */
		asmout(p, o);
		pc += o->size;
	}

	if(debug['a'])
		Bprint(&bso, "\n");
	Bflush(&bso);
	cflush();

	/* output strings in text segment */
	etext = INITTEXT + textsize;
	for(t = pc; t < etext; t += sizeof(buf)-100) {
		if(etext-t > sizeof(buf)-100)
			datblk(t, sizeof(buf)-100, 1);
		else
			datblk(t, etext-t, 1);
	}

	curtext = P;
	switch(HEADTYPE) {
	case 0:
	case 2:
	case 7:
		OFFSET = HEADR+textsize;
		seek(cout, OFFSET, 0);
		break;
	case 6:	/* no header, padded segments */
		OFFSET = rnd(HEADR+textsize, 4096);
		seek(cout, OFFSET, 0);
		break;
	}
	if(dlm){
		char buf[8];

		write(cout, buf, INITDAT-textsize);
		textsize = INITDAT;
	}
	for(t = 0; t < datsize; t += sizeof(buf)-100) {
		if(datsize-t > sizeof(buf)-100)
			datblk(t, sizeof(buf)-100, 0);
		else
			datblk(t, datsize-t, 0);
	}

	symsize = 0;
	lcsize = 0;
	if(!debug['s']) {
		if(debug['v'])
			Bprint(&bso, "%5.2f sym\n", cputime());
		Bflush(&bso);
		switch(HEADTYPE) {
		case 0:
			debug['s'] = 1;
			break;
		case 2:
			OFFSET = HEADR+textsize+datsize;
			seek(cout, OFFSET, 0);
			break;
		case 6:	/* no header, padded segments */
			OFFSET += rnd(datsize, 4096);
			seek(cout, OFFSET, 0);
			break;
		case 7:
			break;
		}
		if(!debug['s'])
			asmsym();
		if(debug['v'])
			Bprint(&bso, "%5.2f pc\n", cputime());
		Bflush(&bso);
		if(!debug['s'])
			asmlc();
		if(dlm)
			asmdyn();
		cflush();
	}
	else if(dlm){
		seek(cout, HEADR+textsize+datsize, 0);
		asmdyn();
		cflush();
	}

	if(debug['v'])
		Bprint(&bso, "%5.2f header\n", cputime());
	Bflush(&bso);
	OFFSET = 0;
	seek(cout, OFFSET, 0);
	switch(HEADTYPE) {
	case 0:	/* no header */
	case 6:	/* no header, padded segments */
		break;
	case 2:	/* plan 9 */
		magic = 4*28*28+7;
		magic |= 0x00008000;		/* fat header */
		if(dlm)
			magic |= 0x80000000;	/* dlm */
		lput(magic);			/* magic */
		lput(textsize);			/* sizes */
		lput(datsize);
		lput(bsssize);
		lput(symsize);			/* nsyms */
		vl = entryvalue();
		lput(PADDR(vl));		/* va of entry */
		lput(0L);
		lput(lcsize);
		llput(vl);			/* va of entry */
		break;
	case 7:	/* elf */
		debug['S'] = 1;			/* symbol table */
		elf64(ARM64, ELFDATA2LSB, 0, nil);
		break;
	}
	cflush();
}