EM06 header type: all is stored as text

This commit is contained in:
Laurent Vivier 2005-11-27 22:31:07 +00:00
parent b08a5c17e6
commit 9589271a29
6 changed files with 200 additions and 113 deletions

View File

@ -3,49 +3,171 @@
#include <sys/types.h>
#include <stdio.h>
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#if defined(USE_CLI) && defined(__LINUX__)
#include "console.h"
#include "cli.h"
#endif
#include "arch.h"
static char kernel[256];
static char ramdisk[256];
#define COMMAND_LINE_LENGTH 256
char parameters[COMMAND_LINE_LENGTH];
static char *read_line(char *s)
{
int read = 0;
while (*s && (*s != '\n'))
{
read++;
s++;
}
return s + 1;
}
static char *read_word(char *line, char **next)
{
char *word;
while ( (*line == ' ') || (*line == '\t') || (*line == '\n') )
line++;
word = line;
while ( *line && (*line != ' ') && (*line != '\t') && (*line != '\n') )
line++;
*next = line;
return word;
}
static char *decode_serial(char* s, int *baudrate, int *parity, int *datasize)
{
*baudrate = strtol(s, &s, 0);
switch(*s)
{
case 'n':
case 'N':
*parity = 0;
break;
case 'o':
case 'O':
*parity = 1;
break;
case 'e':
case 'E':
*parity = 2;
break;
default:
*parity = -1;
break;
}
s++;
*datasize = strtol(s, &s, 0);
return s;
}
int read_config_modem(char *conf, int *bitrate, int *parity, int *datasize)
{
char *next_word, *next_line, *name, *property;
int name_len;
next_line = conf;
while (*next_line)
{
next_word = next_line;
next_line = read_line(next_line);
name = read_word(next_word, &next_word);
name_len = next_word - name;
property = read_word(next_word, &next_word);
if (strncmp(name, "modem", name_len) == 0)
{
decode_serial(property, bitrate, parity, datasize);
return 0;
}
}
return -1;
}
int read_config_printer(char *conf, int *bitrate, int *parity, int *datasize)
{
char *next_word, *next_line, *name, *property;
int name_len;
next_line = conf;
while (*next_line)
{
next_word = next_line;
next_line = read_line(next_line);
name = read_word(next_word, &next_word);
name_len = next_word - name;
property = read_word(next_word, &next_word);
if (strncmp(name, "printer", name_len) == 0)
{
decode_serial(property, bitrate, parity, datasize);
return 0;
}
}
return -1;
}
int read_config(emile_l2_header_t* info,
char **kernel_path, char **command_line, char **ramdisk_path)
{
char *next_word, *next_line, *name, *property;
if (!EMILE_COMPAT(EMILE_05_SIGNATURE, info->signature))
{
printf("Bad header signature !\n");
return -1;
}
if (info->gestaltID != 0)
{
machine_id = info->gestaltID;
printf("User forces gestalt ID to %ld\n", machine_id);
}
next_line = info->configuration;
sprintf(kernel, "block:(fd0)0x%x", info->kernel_image_offset);
*kernel_path = kernel;
if (info->ramdisk_size == 0)
*ramdisk_path = NULL;
else
*ramdisk_path = NULL;
*kernel_path = NULL;
*command_line = NULL;
while (*next_line)
{
sprintf(ramdisk, "block:(fd0)0x%x,0x%x",
info->ramdisk_offset,
info->ramdisk_size);
*ramdisk_path = ramdisk;
next_word = next_line;
next_line = read_line(next_line);
*(next_line - 1) = 0;
name = read_word(next_word, &next_word);
*next_word++ = 0;
property = read_word(next_word, &next_word);
*next_word++ = 0;
if (strcmp(name, "kernel") == 0)
{
*kernel_path = property;
#if defined(USE_CLI) && defined(__LINUX__)
strncpy(parameters, next_word, COMMAND_LINE_LENGTH);
*command_line = parameters;
#else
command_line = next_word;
#endif
}
else if (strcmp(name, "initrd") == 0)
{
*ramdisk_path = property;
}
else if (strcmp(name, "gestaltID") == 0)
{
machine_id = strtol(property, NULL, 0);
printf("User forces gestalt ID to %ld\n", machine_id);
}
}
printf("kernel %s\n", *kernel_path);
if (*ramdisk)
printf("ramdisk %s\n", *ramdisk_path);
*command_line = info->command_line;
printf("initrd %s\n", *ramdisk_path);
#if defined(USE_CLI) && defined(__LINUX__)
printf("command ");
console_cursor_save();

View File

@ -1,4 +1,5 @@
#include "head.h"
extern int read_config(emile_l2_header_t* info, char **kernel_path, char **command_line, char **ramdisk_path);
extern int read_config_modem(char *conf, int *bitrate, int *parity, int *datasize);
extern int read_config_printer(char *conf, int *bitrate, int *parity, int *datasize);

View File

@ -18,13 +18,9 @@ static int vga_enabled = 0;
void
console_init(emile_l2_header_t* info)
{
if (info->console_mask & STDOUT_VGA)
{
vga_init();
vga_enabled = 1;
}
if ( info->console_mask & (STDOUT_SERIAL0 | STDOUT_SERIAL1) )
serial_init(info);
vga_init();
vga_enabled = 1;
serial_init(info);
}
int console_putchar(int c)

View File

@ -1,6 +1,6 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
* (c) 2004, 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
@ -14,7 +14,7 @@
.short 0xA31E
.endm
.equ cmdline_length, 256 /* see CL_SIZE in bootinfo.c */
.equ paramstring_length, 1024
/***************************************************************************
*
@ -23,41 +23,12 @@
***************************************************************************/
_start: bra setup
_signature: .dc.b 'E','M','0','5'
_signature: .dc.b 'E','M','0','6'
/* kernel image information */
/* EM06 */
#ifdef SCSI_SUPPORT
_kernel_image_offset: .long scsi_container - _start
#else
_kernel_image_offset: .long 0
#endif
_kernel_image_size: .long 0
_kernel_size: .long 0
/* ramdisk image information */
_ramdisk_offset: .long 0
_ramdisk_size: .long 0
_command_line: .skip cmdline_length, 0
/* console management: display, serial modem or printer */
_console_mask: .long 1
_serial0_bitrate: .long 9600
_serial0_datasize: .byte 8
_serial0_parity: .byte 0
_serial0_stopbits: .byte 1
_pad0: .byte 0
_serial1_bitrate: .long 9600
_serial1_datasize: .byte 8
_serial1_parity: .byte 0
_serial1_stopbits: .byte 1
_pad1: .byte 0
/* Force gestalt for Mystic macintosh */
_gestaltID: .long 0
_conf_size: .dc.w paramstring_length
_configuration: .skip paramstring_length, 0
.align 4
setup:

View File

@ -1,14 +1,12 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
* (c) 2004, 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#ifndef __HEAD_H__
#define __HEAD_H__
#define COMMAND_LINE_LENGTH 256
/*
* WARNING: remember that m68k is big endian, like powerPC.
* i386 is little-endian
@ -21,35 +19,30 @@ struct emile_l2_header {
u_int32_t entry;
u_int32_t signature;
/* EMO4 addendum: if kernel_image_size == 0,
* kernel_image_offset is a pointer to a container
* EM05 addendum: if kernel_image_size == kernel_size
* kernel is not compressed
* EM06 addendum: configuration is now in string configuration
*/
u_int32_t kernel_image_offset;
u_int32_t kernel_image_size;
u_int32_t kernel_size;
u_int32_t ramdisk_offset;
u_int32_t ramdisk_size;
int8_t command_line[COMMAND_LINE_LENGTH];
/* EM02 */
/* EM06 */
u_int32_t console_mask;
u_int32_t serial0_bitrate;
int8_t serial0_datasize;
int8_t serial0_parity;
int8_t serial0_stopbits;
int8_t pad0;
u_int32_t serial1_bitrate;
int8_t serial1_datasize;
int8_t serial1_parity;
int8_t serial1_stopbits;
int8_t pad1;
u_int16_t conf_size;
int8_t configuration[0];
/* EM03 */
u_int32_t gestaltID;
/*
* gestaltID <digit>
* modem <bitrate><parity><bits> parity is n/o/e
* printer <bitrate><parity><bits>
* kernel <protocol>:<unit>/<path> <parameters>
* <protocol> is "iso9660", "container", "block" ...
* <unit> is "(fd0)", "(sd3)", "(sd0,4)",...
* <path> is "boot/vmlinuz-2.2.25", "install/mac/vmlinuz-2.2.25", "59904", "673280,654848",...
* initrd <protocol>:<unit>/<path>
* configuration <protocol>:<unit>/<path>
*/
} __attribute__((packed));
#define EMILE_ID_MASK 0xFFF0
@ -63,13 +56,8 @@ struct emile_l2_header {
#define EMILE_03_SIGNATURE (('E'<<24)|('M'<<16)|('0'<<8)|'3')
#define EMILE_04_SIGNATURE (('E'<<24)|('M'<<16)|('0'<<8)|'4')
#define EMILE_05_SIGNATURE (('E'<<24)|('M'<<16)|('0'<<8)|'5')
#define EMILE_06_SIGNATURE (('E'<<24)|('M'<<16)|('0'<<8)|'6')
#define EMILE_COMPAT(a,b) ( ( EMILE_ID(a) == EMILE_ID(b) ) && \
( EMILE_VERSION(a) <= EMILE_VERSION(b) ) )
enum {
STDOUT_VGA = 0x00000001,
STDOUT_SERIAL0 = 0x00000002,
STDOUT_SERIAL1 = 0x00000004,
ENABLE_DEBUG = 0x80000000,
};
#endif /* __HEAD_H__ */

View File

@ -14,6 +14,7 @@
#include "misc.h"
#include "head.h"
#include "driver.h"
#include "config.h"
static short out_refnum0 = -1;
static short out_refnum1 = -1;
@ -234,18 +235,24 @@ flush:
void serial_init(emile_l2_header_t* info)
{
int res;
int bitrate, parity, datasize, stopbits;
if (info->console_mask & STDOUT_SERIAL0) {
stopbits = 1;
res = read_config_modem(info->configuration,
&bitrate, &parity, &datasize);
if (res != -1)
{
res = OpenDriver(c2pstring(".AOut"), &out_refnum0);
if (res != noErr) {
printf("Cannot open modem output port (%d)\n", res);
}
else
{
res = setserial(out_refnum0, info->serial0_bitrate,
info->serial0_datasize,
info->serial0_parity,
info->serial0_stopbits);
res = setserial(out_refnum0, bitrate,
datasize,
parity,
stopbits);
if (res != noErr) {
printf("Cannot setup modem output port (%d)\n",
res);
@ -258,10 +265,10 @@ void serial_init(emile_l2_header_t* info)
}
else
{
res = setserial(in_refnum0, info->serial0_bitrate,
info->serial0_datasize,
info->serial0_parity,
info->serial0_stopbits);
res = setserial(in_refnum0, bitrate,
datasize,
parity,
stopbits);
if (res != noErr) {
printf("Cannot setup modem input port (%d)\n",
res);
@ -270,17 +277,19 @@ void serial_init(emile_l2_header_t* info)
#endif /* USE_CLI */
}
if (info->console_mask & STDOUT_SERIAL1) {
res = read_config_printer(info->configuration,
&bitrate, &parity, &datasize);
if (res != -1) {
res = OpenDriver(c2pstring(".BOut"), &out_refnum1);
if (res != noErr) {
printf("Cannot open printer output port (%d)\n", res);
}
else
{
res = setserial(out_refnum1, info->serial1_bitrate,
info->serial1_datasize,
info->serial1_parity,
info->serial1_stopbits);
res = setserial(out_refnum1, bitrate,
datasize,
parity,
stopbits);
if (res != noErr) {
printf("Cannot setup printer output port (%d)\n"
, res);
@ -293,10 +302,10 @@ void serial_init(emile_l2_header_t* info)
}
else
{
res = setserial(in_refnum1, info->serial1_bitrate,
info->serial1_datasize,
info->serial1_parity,
info->serial1_stopbits);
res = setserial(in_refnum1, bitrate,
datasize,
parity,
stopbits);
if (res != noErr) {
printf("Cannot setup printer input port (%d)\n"
, res);