Add emile-first-info to see content of boot block

This commit is contained in:
Laurent Vivier 2004-05-21 10:23:12 +00:00
parent 2bb05adaad
commit 26fac279a5
4 changed files with 215 additions and 2 deletions

View File

@ -77,7 +77,8 @@ DISTFILES = second/head.S second/MMU030.c second/MMU040.c second/main.c \
second/enter_kernel040.S first/first.S \
first/Makefile second/bank.c second/bank.h second/arch.h \
second/arch.c Makefile COPYING README AUTHORS ChangeLog \
tools/Makefile tools/emile-set-cmdline.c
tools/Makefile tools/emile-first.h tools/emile-set-cmdline.c \
tools/emile-first-info.c
dist:
rm -fr $(PACKAGE)-$(VERSION)

View File

@ -6,7 +6,11 @@
CFLAGS = -Wall
all: emile-set-cmdline
all: emile-set-cmdline emile-first-info
emile-set-cmdline.o: emile-set-cmdline.c emile-first.h
emile-first-info.o: emile-first-info.c emile-first.h
clean:
rm -f *.o emile-set-cmdline

129
tools/emile-first-info.c Normal file
View File

@ -0,0 +1,129 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include "emile-first.h"
static void usage(int argc, char** argv)
{
fprintf(stderr, "Usage: %s <image>\n", argv[0]);
fprintf(stderr, "\n display first level boot block info\n");
}
static void pprint(char *string)
{
int l = *string++;
while (l-- != 0)
putchar(*string++);
}
int first_info(char* image)
{
int fd;
eBootBlock_t firstBlock;
int ret;
fd = open(image, O_RDONLY);
if (fd == -1)
{
perror("Cannot open image file");
return 2;
}
ret = read(fd, &firstBlock, sizeof(firstBlock));
if (ret != sizeof(firstBlock))
{
perror("Cannot read first level boot block");
close(fd);
return 3;
}
printf("Boot Block Header:\n\n");
printf("Boot blocks signature: 0x%x\n",
firstBlock.boot_block_header.ID);
printf("Entry point to bootcode: 0x%lX\n",
firstBlock.boot_block_header.Entry);
printf("Boot blocks version number: %x\n",
firstBlock.boot_block_header.Version);
printf("System filename: ");
pprint(firstBlock.boot_block_header.SysName);
putchar('\n');
printf("Finder filename: ");
pprint(firstBlock.boot_block_header.ShellName);
putchar('\n');
printf("Debugger1 filename: ");
pprint(firstBlock.boot_block_header.Dbg1Name);
putchar('\n');
printf("Debugger2 filename: ");
pprint(firstBlock.boot_block_header.Dbg2Name);
putchar('\n');
printf("Name of startup screen: ");
pprint(firstBlock.boot_block_header.ScreenName);
putchar('\n');
printf("Name of startup program: ");
pprint(firstBlock.boot_block_header.HelloName);
putchar('\n');
printf("Name of system scrap file: ");
pprint(firstBlock.boot_block_header.ScrapName);
putchar('\n');
printf("Number of FCBs to allocate: %d\n",
firstBlock.boot_block_header.CntFCBs);
printf("Number of event queue elements: %d\n",
firstBlock.boot_block_header.CntEvts);
printf("System heap size on 128K Mac: 0x%lx\n",
firstBlock.boot_block_header.Heap128K);
printf("System heap size on 256K Mac: 0x%lx\n",
firstBlock.boot_block_header.Heap256K);
printf("System heap size on all machines: 0x%lx\n",
firstBlock.boot_block_header.SysHeapSize);
if ( strncmp( firstBlock.boot_block_header.SysName+1,
"Mac Bootloader", 14) == 0 )
{
printf("\nEMILE boot block identified\n\n");
printf("Drive number: %d\n",
firstBlock.second_param_block.ioVRefNum);
printf("File reference number: %d\n",
firstBlock.second_param_block.ioRefNum);
printf("Second level size: %ld\n",
firstBlock.second_param_block.ioReqCount);
printf("Second level offset: %ld\n",
firstBlock.second_param_block.ioPosOffset);
}
close(fd);
return 0;
}
int main(int argc, char** argv)
{
int ret;
ASSERT_BBH(
{fprintf(stderr,"Internal Error: Bad BootBlkHdr size\n"); exit(1);});
ASSERT_PBR(
{fprintf(stderr,"Internal Error: Bad ParamBlockRec size\n"); exit(1);});
ASSERT_BB(
{fprintf(stderr,"Internal Error: Bad boot block size\n"); exit(1);});
if (argc != 2)
{
usage(argc, argv);
return 1;
}
ret = first_info(argv[1]);
return ret;
}

79
tools/emile-first.h Normal file
View File

@ -0,0 +1,79 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
/*
* WARNING: remember that m68k is big endian, like powerPC.
* i386 is little-endian
*/
/* first level structure */
/* BootBlkHdr Structure: "Inside Macintosh: Files", p. 2-57 */
typedef struct BootBlkHdr BootBlkHdr_t;
struct BootBlkHdr {
unsigned short ID; /* boot blocks signature */
unsigned long Entry; /* entry point to bootcode */
unsigned short Version; /* boot blocks version number */
unsigned short PageFlags; /* used internally */
unsigned char SysName[16]; /* System filename */
unsigned char ShellName[16]; /* Finder filename */
unsigned char Dbg1Name[16]; /* debugger filename */
unsigned char Dbg2Name[16]; /* debugger filename */
unsigned char ScreenName[16]; /* name of startup screen */
unsigned char HelloName[16]; /* name of startup program */
unsigned char ScrapName[16]; /* name of system scrap file */
unsigned short CntFCBs; /* number of FCBs to allocate */
unsigned short CntEvts; /* number of event queue elements */
unsigned long Heap128K; /* system heap size on 128K Mac */
unsigned long Heap256K; /* used internally */
unsigned long SysHeapSize; /* system heap size on all machines */
} __attribute__((packed));
#define ASSERT_BBH(a) if ( sizeof(BootBlkHdr_t) != 138 ) { a }
/* ParamBlockRec Structure: "Inside Macintosh: Files", p. 2-87 */
typedef struct ParamBlockRec ParamBlockRec_t;
struct ParamBlockRec {
unsigned long qLink; /* next queue entry */
unsigned short qType; /* queue type */
unsigned short ioTrap; /* routine trap */
unsigned long ioCmdAddr; /* routine address */
unsigned long ioCompletion; /* pointer to completion routine */
unsigned short ioResult; /* result code */
unsigned long ioNamePtr; /* pointer to pathname */
signed short ioVRefNum; /* volume specification */
signed short ioRefNum; /* file reference number */
signed char ioVersNum; /* version number */
signed char ioPermssn; /* read/write permission */
unsigned long ioMisc; /* miscellaneaous */
unsigned long ioBuffer; /* data buffer */
unsigned long ioReqCount; /* requested number of bytes */
unsigned long ioActCount; /* actual number of bytes */
unsigned short ioPosMode; /* positioning mode and newline char */
signed long ioPosOffset; /* positionning offset */
} __attribute__((packed));
#define ASSERT_PBR(a) if ( sizeof(ParamBlockRec_t) != 50 ) { a }
/* EMILE Boot block structure */
typedef struct eBootBlock eBootBlock_t;
struct eBootBlock {
BootBlkHdr_t boot_block_header;
ParamBlockRec_t second_param_block;
unsigned char boot_code[1024 - sizeof(BootBlkHdr_t)
- sizeof(ParamBlockRec_t)];
} __attribute__((packed));
#define ASSERT_BB(a) if ( sizeof(eBootBlock_t) != 1024 ) { a }
#define SECTOR_SIZE 512
#define FIRST_LEVEL_SIZE (SECTOR_SIZE * 2)