URL
https://opencores.org/ocsvn/or1k_old/or1k_old/trunk
Subversion Repositories or1k_old
Compare Revisions
- This comparison shows the changes necessary to convert path
/or1k_old/trunk/rc203soc/sw/uClinux/arch/m68k/boot
- from Rev 1765 to Rev 1782
- ↔ Reverse comparison
Rev 1765 → Rev 1782
/atari/sysvars.h
0,0 → 1,22
typedef struct _osheader |
{ |
unsigned short os_entry; |
unsigned short os_version; |
void *reseth; |
struct _osheader *os_beg; |
void *os_end; |
long os_rsv1; |
void *os_magic; |
long os_date; |
unsigned short os_conf; |
unsigned short os_dosdate; |
char **p_root; |
unsigned char **pkbshift; |
void **p_run; |
char *p_rsv2; |
} OSHEADER; |
|
#define phystop ((unsigned long *)0x42e) |
#define _sysbase ((OSHEADER **)0x4f2) |
#define _p_cookies ((unsigned long **)0x5a0) |
#define ramtop ((unsigned long *)0x5a4) |
/atari/bootstrap.h
0,0 → 1,147
/* |
** bootstrap.h -- This file is a part of the Atari bootloader. |
** |
** Copyright 1993 by Arjan Knor |
** |
** Modified by Andreas Schwab |
** - clear transparent translation registers |
** |
** This file is subject to the terms and conditions of the GNU General Public |
** License. See the file COPYING in the main directory of this archive |
** for more details. |
** |
*/ |
|
#ifndef BOOTSTRAP_H |
#define BOOTSTRAP_H |
|
/* _MCH cookie values */ |
#define MACH_ST 0 |
#define MACH_STE 1 |
#define MACH_TT 2 |
#define MACH_FALCON 3 |
|
/* some constants for memory handling */ |
#define ST_RAM 0 |
#define TT_RAM 1 |
#define TT_RAM_BASE (u_long)(0x01000000) |
#define MB (1024 * 1024) |
#define START_MEM (bi.memory[0].addr) |
#define MEM_SIZE (bi.memory[0].size) |
|
/* the various CPU- and FPU-types */ |
#define AFF_68000 (1) |
#define AFF_68020 (2) |
#define AFF_68030 (4) |
#define AFF_68040 (8) |
#define AFF_68881 (16) |
#define AFF_68882 (32) |
|
/* the possible OS-languages */ |
#define USA 0 |
#define FRG 1 |
#define FRA 2 |
#define UK 3 |
#define SPA 4 |
#define ITA 5 |
#define SWE 6 |
#define SWF 7 |
#define SWG 8 |
#define TUR 9 |
#define FIN 10 |
#define NOR 11 |
#define DEN 12 |
#define SAU 13 |
#define HOL 14 |
|
/* some inline functions */ |
|
static __inline int fpu_idle_frame_size (void) |
{ |
char fpu_frame[216]; |
__asm__ __volatile__ ("fnop"::); |
__asm__ __volatile__ ("fsave %0@" : : "a" (fpu_frame)); |
return fpu_frame[1]; |
} |
|
static __inline void change_stack (u_long *stackp) |
{ |
__asm__ volatile ("movel %0,sp\n\t" :: "g" (stackp) : "sp"); |
} |
|
static __inline void disable_interrupts (void) |
{ |
__asm__ volatile ("orw #0x700,sr":); |
} |
|
extern struct bootinfo bi; |
static __inline void disable_cache (void) |
{ |
__asm__ volatile ("movec %0,cacr" :: "d" (0)); |
if (bi.cputype & CPU_68060) { |
/* '060: clear branch cache after disabling it; |
* disable superscalar operation (and enable FPU) */ |
__asm__ volatile ("movec %0,cacr" :: "d" (0x00400000)); |
__asm__ volatile ("moveq #0,d0;" |
".long 0x4e7b0808" /* movec d0,pcr */ |
: /* no outputs */ |
: /* no inputs */ |
: "d0"); |
} |
} |
|
static __inline void disable_mmu (void) |
{ |
if (bi.cputype & (CPU_68040|CPU_68060)) { |
__asm__ volatile ("moveq #0,d0;" |
".long 0x4e7b0003;" /* movec d0,tc */ |
".long 0x4e7b0004;" /* movec d0,itt0 */ |
".long 0x4e7b0005;" /* movec d0,itt1 */ |
".long 0x4e7b0006;" /* movec d0,dtt0 */ |
".long 0x4e7b0007" /* movec d0,dtt1 */ |
: /* no outputs */ |
: /* no inputs */ |
: "d0"); |
} |
else { |
__asm__ volatile ("subl #4,sp\n\t" |
"pmove tc,sp@\n\t" |
"bclr #7,sp@\n\t" |
"pmove sp@,tc\n\t" |
"addl #4,sp"); |
if (bi.cputype & CPU_68030) { |
__asm__ volatile ("clrl sp@-\n\t" |
".long 0xf0170800\n\t" /* pmove sp@,tt0 */ |
".long 0xf0170c00\n\t" /* pmove sp@,tt1 */ |
"addl #4,sp\n"); |
} |
} |
} |
|
static __inline void jump_to_mover (void *, void *, void *, void *, int, int, |
void *) __attribute__ ((noreturn)); |
static __inline void jump_to_mover (void *kernel_start, void *mem_start, |
void *ramdisk_end, void *mem_end, |
int kernel_size, int ramdisk_size, |
void *mover_addr) |
{ |
asm volatile ("movel %0,a0\n\t" |
"movel %1,a1\n\t" |
"movel %2,a2\n\t" |
"movel %3,a3\n\t" |
"movel %4,d0\n\t" |
"movel %5,d1\n\t" |
"jmp %6@\n" |
: /* no outputs */ |
: "g" (kernel_start), "g" (mem_start), |
"g" (ramdisk_end), "g" (mem_end), |
"g" (kernel_size), "g" (ramdisk_size), |
"a" (mover_addr) |
: "a0", "a1", "a2", "a3", "d0", "d1"); |
|
/* Avoid warning that function may return */ |
for (;;) ; |
} |
|
#endif /* BOOTSTRAP_H */ |
|
/atari/Makefile
0,0 → 1,12
|
CC := d:/gnu/bin/gcc.ttp |
CFLAGS := -Wall -O2 -fno-defer-pop -mint -s |
LD := d:/gnu/bin/gcc.ttp |
LDFLAGS := -mint -D__GNUC__ |
|
bootstra.ttp: bootstra.o |
$(LD) $(LDFLAGS) -o $@ $^ |
prgflags 7 7 $@ |
cp $@ d:/linux |
|
bootstra.o: bootstra.c bootinfo.h |
/atari/bootstrap.c
0,0 → 1,999
/* |
** bootstrap.c -- Load and launch the Atari Linux kernel |
** |
** Copyright 1993 by Arjan Knor |
** |
** This file is subject to the terms and conditions of the GNU General Public |
** License. See the file COPYING in the main directory of this archive |
** for more details. |
** |
** History: |
** 10 Dec 1995 BOOTP/TFTP support (Roman) |
** 03 Oct 1995 Allow kernel to be loaded to TT ram again (Andreas) |
** 11 Jul 1995 Add support for ELF format kernel (Andreas) |
** 16 Jun 1995 Adapted to Linux 1.2: kernel always loaded into ST ram |
** (Andreas) |
** 14 Nov 1994 YANML (Yet Another New Memory Layout :-) kernel |
** start address is KSTART_ADDR + PAGE_SIZE, this |
** does not need the ugly kludge with |
** -fwritable-strings (++andreas) |
** 09 Sep 1994 Adapted to the new memory layout: All the boot_info entry |
** mentions all ST-Ram and the mover is located somewhere |
** in the middle of memory (roman) |
** Added the default arguments file known from the other |
** bootstrap version |
** 19 Feb 1994 Changed everything so that it works? (rdv) |
** 14 Mar 1994 New mini-copy routine used (rdv) |
*/ |
|
#include <stdio.h> |
#include <stdlib.h> |
#include <unistd.h> |
#include <stddef.h> |
#include <string.h> |
#include <ctype.h> |
#include "sysvars.h" |
#include <osbind.h> |
#include <sys/types.h> |
#include <sys/file.h> |
|
/* linux specific include files */ |
#include <linux/a.out.h> |
#include <linux/elf.h> |
#include <asm/page.h> |
|
#define _LINUX_TYPES_H /* Hack to prevent including <linux/types.h> */ |
#include <asm/bootinfo.h> |
|
/* Atari bootstrap include file */ |
#include "bootstrap.h" |
|
#define MIN_RAMSIZE (3) /* 3 MB */ |
#define TEMP_STACKSIZE 256 |
|
extern char *optarg; |
extern int optind; |
static void get_default_args( int *argc, char ***argv ); |
/* This is missing in <unistd.h> */ |
extern int sync (void); |
|
struct bootinfo bi; |
u_long *cookiejar; |
u_long userstk; |
|
/* getcookie -- function to get the value of the given cookie. */ |
static int getcookie(char *cookie, u_long *value) |
{ |
int i = 0; |
|
while(cookiejar[i] != 0L) { |
if(cookiejar[i] == *(u_long *)cookie) { |
*value = cookiejar[i + 1]; |
return 1; |
} |
i += 2; |
} |
return -1; |
} |
|
static void usage(void) |
{ |
fprintf(stderr, "Usage:\n" |
"\tbootstrap [-dst] [-k kernel_executable] [-r ramdisk_file]" |
" [option...]\n"); |
exit(EXIT_FAILURE); |
} |
|
/* |
* Copy the kernel and the ramdisk to their final resting places. |
* |
* I assume that the kernel data and the ramdisk reside somewhere |
* in the middle of the memory. |
* |
* This program itself should be somewhere in the first 4096 bytes of memory |
* where the kernel never will be. In this way it can never be overwritten |
* by itself. |
* |
* At this point the registers have: |
* a0: the start of the final kernel |
* a1: the start of the current kernel |
* a2: the end of the final ramdisk |
* a3: the end of the current ramdisk |
* d0: the kernel size |
* d1: the ramdisk size |
*/ |
asm (" |
.text |
.globl _copyall, _copyallend |
_copyall: |
|
movel a0,a4 /* save the start of the kernel for booting */ |
|
1: movel a1@+,a0@+ /* copy the kernel starting at the beginning */ |
subql #4,d0 |
jcc 1b |
|
tstl d1 |
beq 3f |
|
2: movel a3@-,a2@- /* copy the ramdisk starting at the end */ |
subql #4,d1 |
jcc 2b |
|
3: jmp a4@ /* jump to the start of the kernel */ |
_copyallend: |
"); |
|
extern char copyall, copyallend; |
|
|
/* Test for a Medusa: This is the only machine on which address 0 is |
* writeable! |
* ...err! On the Afterburner040 (for the Falcon) it's the same... So we do |
* another test with 0x00ff82fe, that gives a bus error on the Falcon, but is |
* in the range where the Medusa always asserts DTACK. |
*/ |
|
int test_medusa( void ) |
|
{ int rv = 0; |
|
__asm__ __volatile__ |
( "movel 0x8,a0\n\t" |
"movel sp,a1\n\t" |
"moveb 0x0,d1\n\t" |
"movel #Lberr,0x8\n\t" |
"moveq #0,%0\n\t" |
"clrb 0x0\n\t" |
"nop \n\t" |
"moveb d1,0x0\n\t" |
"nop \n\t" |
"tstb 0x00ff82fe\n\t" |
"nop \n\t" |
"moveq #1,%0\n" |
"Lberr:\t" |
"movel a1,sp\n\t" |
"movel a0,0x8" |
: "=d" (rv) |
: /* no inputs */ |
: "d1", "a0", "a1", "memory" ); |
|
return( rv ); |
} |
|
|
void get_medusa_bank_sizes( u_long *bank1, u_long *bank2 ) |
|
{ static u_long save_addr; |
u_long test_base, saved_contents[16]; |
#define TESTADDR(i) (*((u_long *)((char *)test_base + i*8*MB))) |
#define TESTPAT 0x12345678 |
unsigned short oldflags; |
int i; |
|
/* This ensures at least that none of the test addresses conflicts |
* with the test code itself */ |
test_base = ((unsigned long)&save_addr & 0x007fffff) | 0x20000000; |
*bank1 = *bank2 = 0; |
|
/* Interrupts must be disabled because arbitrary addresses may be |
* temporarily overwritten, even code of an interrupt handler */ |
__asm__ __volatile__ ( "movew sr,%0; oriw #0x700,sr" : "=g" (oldflags) : ); |
disable_cache(); |
|
/* save contents of the test addresses */ |
for( i = 0; i < 16; ++i ) |
saved_contents[i] = TESTADDR(i); |
|
/* write 0s into all test addresses */ |
for( i = 0; i < 16; ++i ) |
TESTADDR(i) = 0; |
|
/* test for bank 1 */ |
#if 0 |
/* This is Freddi's original test, but it didn't work. */ |
TESTADDR(0) = TESTADDR(1) = TESTPAT; |
if (TESTADDR(1) == TESTPAT) { |
if (TESTADDR(2) == TESTPAT) |
*bank1 = 8*MB; |
else if (TESTADDR(3) == TESTPAT) |
*bank1 = 16*MB; |
else |
*bank1 = 32*MB; |
} |
else { |
if (TESTADDR(2) == TESTPAT) |
*bank1 = 0; |
else |
*bank1 = 16*MB; |
} |
#else |
TESTADDR(0) = TESTPAT; |
if (TESTADDR(1) == TESTPAT) |
*bank1 = 8*MB; |
else if (TESTADDR(2) == TESTPAT) |
*bank1 = 16*MB; |
else if (TESTADDR(4) == TESTPAT) |
*bank1 = 32*MB; |
else |
*bank1 = 64*MB; |
#endif |
|
/* test for bank2 */ |
if (TESTADDR(8) != 0) |
*bank2 = 0; |
else { |
TESTADDR(8) = TESTPAT; |
if (TESTADDR(9) != 0) { |
if (TESTADDR(10) == TESTPAT) |
*bank2 = 8*MB; |
else |
*bank2 = 32*MB; |
} |
else { |
TESTADDR(9) = TESTPAT; |
if (TESTADDR(10) == TESTPAT) |
*bank2 = 16*MB; |
else |
*bank2 = 64*MB; |
} |
} |
|
/* restore contents of the test addresses and restore interrupt mask */ |
for( i = 0; i < 16; ++i ) |
TESTADDR(i) = saved_contents[i]; |
__asm__ __volatile__ ( "movew %0,sr" : : "g" (oldflags) ); |
} |
|
#undef TESTADDR |
#undef TESTPAT |
|
#ifdef USE_BOOTP |
# include "bootp.h" |
#else |
# define kread read |
# define klseek lseek |
# define kclose close |
#endif |
|
|
/* ++andreas: this must be inline due to Super */ |
static inline void boot_exit (int) __attribute__ ((noreturn)); |
static inline void boot_exit(int status) |
{ |
/* first go back to user mode */ |
(void)Super(userstk); |
getchar(); |
exit(status); |
} |
|
int main(int argc, char *argv[]) |
{ |
int debugflag = 0, ch, kfd, rfd = -1, i, ignore_ttram = 0; |
int load_to_stram = 0; |
char *ramdisk_name, *kernel_name, *memptr; |
u_long ST_ramsize, TT_ramsize, memreq; |
u_long cpu_type, fpu_type, mch_type, mint; |
struct exec kexec; |
int elf_kernel = 0; |
Elf32_Ehdr kexec_elf; |
Elf32_Phdr *kernel_phdrs = NULL; |
u_long start_mem, mem_size, rd_size, text_offset = 0, kernel_size; |
#ifdef USE_BOOTP |
int prefer_bootp = 1, kname_set = 0; |
#endif |
|
ramdisk_name = NULL; |
kernel_name = "vmlinux"; |
|
/* print the startup message */ |
puts("\fLinux/68k Atari Bootstrap version 1.6" |
#ifdef USE_BOOTP |
" (with BOOTP)" |
#endif |
); |
puts("Copyright 1993,1994 by Arjan Knor, Robert de Vries, Roman Hodek, Andreas Schwab\n"); |
|
/* ++roman: If no arguments on the command line, read them from |
* file */ |
if (argc == 1) |
get_default_args( &argc, &argv ); |
|
/* machine is Atari */ |
bi.machtype = MACH_ATARI; |
|
/* check arguments */ |
#ifdef USE_BOOTP |
while ((ch = getopt(argc, argv, "bdtsk:r:")) != EOF) |
#else |
while ((ch = getopt(argc, argv, "dtsk:r:")) != EOF) |
#endif |
switch (ch) { |
case 'd': |
debugflag = 1; |
break; |
case 't': |
ignore_ttram = 1; |
break; |
case 's': |
load_to_stram = 1; |
break; |
case 'k': |
kernel_name = optarg; |
#ifdef USE_BOOTP |
kname_set = 1; |
#endif |
break; |
case 'r': |
ramdisk_name = optarg; |
break; |
#ifdef USE_BOOTP |
case 'b': |
prefer_bootp = 1; |
break; |
#endif |
case '?': |
default: |
usage(); |
} |
|
argc -= optind; |
argv += optind; |
|
/* We have to access some system variables to get |
* the information we need, so we must switch to |
* supervisor mode first. |
*/ |
userstk = Super(0L); |
|
/* get the info we need from the cookie-jar */ |
cookiejar = *_p_cookies; |
if(cookiejar == 0L) { |
/* if we find no cookies, it's probably an ST */ |
fprintf(stderr, "Error: No cookiejar found. Is this an ST?\n"); |
boot_exit(EXIT_FAILURE); |
} |
|
/* Exit if MiNT/MultiTOS is running. */ |
if(getcookie("MiNT", &mint) != -1) |
{ |
puts("Warning: MiNT is running\n"); |
#if 0 |
puts("Linux cannot be started when MiNT is running. Aborting...\n"); |
boot_exit(EXIT_FAILURE); |
#endif |
} |
|
/* get _CPU, _FPU and _MCH */ |
getcookie("_CPU", &cpu_type); |
getcookie("_FPU", &fpu_type); |
getcookie("_MCH", &mch_type); |
|
/* check if we are on a 68030/40 with FPU */ |
if ((cpu_type != 30 && cpu_type != 40 && cpu_type != 60) || |
(fpu_type >> 16) < 2) |
{ |
puts("Machine type currently not supported. Aborting..."); |
boot_exit(EXIT_FAILURE); |
} |
|
switch(cpu_type) { |
case 0: |
case 10: break; |
case 20: bi.cputype = CPU_68020; break; |
case 30: bi.cputype = CPU_68030; break; |
case 40: bi.cputype = CPU_68040; break; |
case 60: bi.cputype = CPU_68060; break; |
default: |
fprintf(stderr, "Error: Unknown CPU type. Aborting...\n"); |
boot_exit(EXIT_FAILURE); |
break; |
} |
|
printf("CPU: %ld; ", cpu_type + 68000); |
printf("FPU: "); |
|
/* check for FPU; in case of a '040 or '060, don't look at _FPU itself, |
* some software may set it to wrong values (68882 or the like) */ |
if (cpu_type == 40) { |
bi.cputype |= FPU_68040; |
puts( "68040\n" ); |
} |
else if (cpu_type == 60) { |
bi.cputype |= FPU_68060; |
puts( "68060\n" ); |
} |
else { |
switch ((fpu_type >> 16) & 6) { |
case 0: |
puts("not present\n"); |
break; |
case 2: |
/* try to determine real type */ |
if (fpu_idle_frame_size () != 0x18) |
goto m68882; |
/* fall through */ |
case 4: |
bi.cputype |= FPU_68881; |
puts("68881\n"); |
break; |
case 6: |
m68882: |
bi.cputype |= FPU_68882; |
puts("68882\n"); |
break; |
default: |
puts("Unknown FPU type. Assuming no FPU."); |
break; |
} |
} |
|
memset(&bi.bi_atari.hw_present, 0, sizeof(bi.bi_atari.hw_present)); |
|
/* Get the amounts of ST- and TT-RAM. */ |
/* The size must be a multiple of 1MB. */ |
i = 0; |
|
if (!test_medusa()) { |
struct { |
unsigned short version; /* version - currently 1 */ |
unsigned long fr_start; /* start addr FastRAM */ |
unsigned long fr_len; /* length FastRAM */ |
} *magn_cookie; |
struct { |
unsigned long version; |
unsigned long fr_start; /* start addr */ |
unsigned long fr_len; /* length */ |
} *fx_cookie; |
|
TT_ramsize = 0; |
if (!ignore_ttram) { |
/* "Original" or properly emulated TT-Ram */ |
if (*ramtop) { |
/* the 'ramtop' variable at 0x05a4 is not |
* officially documented. We use it anyway |
* because it is the only way to get the TTram size. |
* (It is zero if there is no TTram.) |
*/ |
bi.memory[i].addr = TT_RAM_BASE; |
bi.memory[i].size = (*ramtop - TT_RAM_BASE) & ~(MB - 1); |
TT_ramsize = bi.memory[i].size / MB; |
i++; |
printf("TT-RAM: %ld Mb; ", TT_ramsize); |
} |
|
/* test for MAGNUM alternate RAM |
* added 26.9.1995 M. Schwingen, rincewind@discworld.oche.de |
*/ |
if (getcookie("MAGN", (u_long *)&magn_cookie) != -1) { |
bi.memory[i].addr = magn_cookie->fr_start; |
bi.memory[i].size = magn_cookie->fr_len & ~(MB - 1); |
TT_ramsize += bi.memory[i].size / MB; |
printf("MAGNUM alternate RAM: %ld Mb; ", bi.memory[i].size/MB); |
i++; |
} |
|
/* BlowUps FX */ |
if (getcookie("BPFX", (u_long *)&fx_cookie) != -1 && fx_cookie) { |
/* if fx is set (cookie call above), |
* we assume that BlowUps FX-card |
* is installed. (Nat!) |
*/ |
bi.memory[i].addr = fx_cookie->fr_start; |
bi.memory[i].size = fx_cookie->fr_len & ~(MB - 1); |
printf("FX alternate RAM: %ld Mb; ", bi.memory[i].size/MB); |
i++; |
} |
} |
|
bi.memory[i].addr = 0; |
bi.memory[i].size = *phystop & ~(MB - 1); |
ST_ramsize = bi.memory[i].size / MB; |
i++; |
printf("ST-RAM: %ld Mb\n", ST_ramsize ); |
|
bi.num_memory = i; |
|
if (load_to_stram && i > 1) { |
/* Put ST-RAM first in the list of mem blocks */ |
struct mem_info temp = bi.memory[i - 1]; |
bi.memory[i - 1] = bi.memory[0]; |
bi.memory[0] = temp; |
} |
} |
else { |
u_long bank1, bank2, medusa_st_ram; |
|
get_medusa_bank_sizes( &bank1, &bank2 ); |
medusa_st_ram = *phystop & ~(MB - 1); |
bank1 -= medusa_st_ram; |
TT_ramsize = 0; |
|
bi.memory[i].addr = 0; |
bi.memory[i].size = medusa_st_ram; |
ST_ramsize = bi.memory[i].size / MB; |
i++; |
printf("Medusa pseudo ST-RAM from bank 1: %ld Mb; ", ST_ramsize ); |
|
if (!ignore_ttram && bank1 > 0) { |
bi.memory[i].addr = 0x20000000 + medusa_st_ram; |
bi.memory[i].size = bank1; |
TT_ramsize += bank1; |
i++; |
printf("TT-RAM bank 1: %ld Mb; ", bank1/MB ); |
} |
|
if (!ignore_ttram && bank2 > 0) { |
bi.memory[i].addr = 0x24000000; |
bi.memory[i].size = bank2; |
TT_ramsize += bank2; |
i++; |
printf("TT-RAM bank 2: %ld Mb; ", bank2/MB ); |
} |
|
bi.num_memory = i; |
printf("\n"); |
} |
|
/* verify that there is enough RAM; ST- and TT-RAM combined */ |
if (ST_ramsize + TT_ramsize < MIN_RAMSIZE) { |
puts("Not enough RAM. Aborting..."); |
boot_exit(10); |
} |
|
#if 0 |
/* Get language/keyboard info */ |
/* TODO: do we need this ? */ |
/* Could be used to auto-select keyboard map later on. (rdv) */ |
if (getcookie("_AKP",&language) == -1) |
{ |
/* Get the language info from the OS-header */ |
os_header = *_sysbase; |
os_header = os_header->os_beg; |
lang = (os_header->os_conf) >> 1; |
printf("Language: "); |
switch(lang) { |
case HOL: puts("Dutch"); break; /* Own country first :-) */ |
case USA: puts("American"); break; |
case SWG: puts("Switzerland (German)"); break; |
case FRG: puts("German"); break; |
case FRA: puts("French"); break; |
case SWF: puts("Switzerland (French)"); break; |
case UK: puts("English"); break; |
case SPA: puts("Spanish"); break; |
case ITA: puts("Italian"); break; |
case SWE: puts("Swedish"); break; |
case TUR: puts("Turkey"); break; |
case FIN: puts("Finnish"); break; |
case NOR: puts("Norwegian"); break; |
case DEN: puts("Danish"); break; |
case SAU: puts("Saudi-Arabian"); break; |
default: puts("Unknown"); break; |
} |
} |
else |
{ |
printf("Language: "); |
switch(language & 0x0F) |
{ |
case 1: printf("German "); break; |
case 2: printf("French "); break; |
case 4: printf("Spanish "); break; |
case 5: printf("Italian "); break; |
case 7: printf("Swiss French "); break; |
case 8: printf("Swiss German "); break; |
default: printf("English "); |
} |
printf("Keyboard type :"); |
switch(language >> 8) |
{ |
case 1: printf("German "); break; |
case 2: printf("French "); break; |
case 4: printf("Spanish "); break; |
case 5: printf("Italian "); break; |
case 7: printf("Swiss French "); break; |
case 8: printf("Swiss German "); break; |
default: printf("English "); |
} |
printf("\n"); |
} |
#endif |
|
/* Pass contents of the _MCH cookie to the kernel */ |
bi.bi_atari.mch_cookie = mch_type; |
|
/* |
* Copy command line options into the kernel command line. |
*/ |
i = 0; |
while (argc--) { |
if ((i+strlen(*argv)+1) < CL_SIZE) { |
i += strlen(*argv) + 1; |
if (bi.command_line[0]) |
strcat (bi.command_line, " "); |
strcat (bi.command_line, *argv++); |
} |
} |
printf ("Command line is '%s'\n", bi.command_line); |
|
start_mem = bi.memory[0].addr; |
mem_size = bi.memory[0].size; |
|
/* tell us where the kernel will go */ |
printf("\nThe kernel will be located at 0x%08lx\n", start_mem); |
|
#ifdef TEST |
/* |
** Temporary exit point for testing |
*/ |
boot_exit(-1); |
#endif /* TEST */ |
|
#ifdef USE_BOOTP |
kfd = -1; |
if (prefer_bootp) { |
/* First try to get a remote kernel, then use a local kernel (if |
* present) */ |
if (get_remote_kernel( kname_set ? kernel_name : NULL ) < 0) { |
printf( "\nremote boot failed; trying local kernel\n" ); |
if ((kfd = open (kernel_name, O_RDONLY)) == -1) { |
fprintf (stderr, "Unable to open kernel file %s\n", |
kernel_name); |
boot_exit (EXIT_FAILURE); |
} |
} |
} |
else { |
/* Try BOOTP if local kernel cannot be opened */ |
if ((kfd = open (kernel_name, O_RDONLY)) == -1) { |
printf( "\nlocal kernel failed; trying remote boot\n" ); |
if (get_remote_kernel( kname_set ? kernel_name : NULL ) < 0) { |
fprintf (stderr, "Unable to remote boot and " |
"to open kernel file %s\n", kernel_name); |
boot_exit (EXIT_FAILURE); |
} |
} |
} |
#else |
/* open kernel executable and read exec header */ |
if ((kfd = open (kernel_name, O_RDONLY)) == -1) { |
fprintf (stderr, "Unable to open kernel file %s\n", kernel_name); |
boot_exit (EXIT_FAILURE); |
} |
#endif |
|
if (kread (kfd, (void *)&kexec, sizeof(kexec)) != sizeof(kexec)) |
{ |
fprintf (stderr, "Unable to read exec header from %s\n", kernel_name); |
boot_exit (EXIT_FAILURE); |
} |
|
switch (N_MAGIC(kexec)) { |
case ZMAGIC: |
text_offset = N_TXTOFF(kexec); |
break; |
case QMAGIC: |
text_offset = sizeof(kexec); |
/* the text size includes the exec header; remove this */ |
kexec.a_text -= sizeof(kexec); |
break; |
default: |
/* Try to parse it as an ELF header */ |
klseek (kfd, 0, SEEK_SET); |
if (kread (kfd, (void *)&kexec_elf, sizeof (kexec_elf)) == sizeof (kexec_elf) |
&& memcmp (&kexec_elf.e_ident[EI_MAG0], ELFMAG, SELFMAG) == 0) |
{ |
elf_kernel = 1; |
/* A few plausibility checks */ |
if (kexec_elf.e_type != ET_EXEC || kexec_elf.e_machine != EM_68K |
|| kexec_elf.e_version != EV_CURRENT) |
{ |
fprintf (stderr, "Invalid ELF header contents in kernel\n"); |
boot_exit (EXIT_FAILURE); |
} |
/* Load the program headers */ |
kernel_phdrs = (Elf32_Phdr *) Malloc (kexec_elf.e_phnum * sizeof (Elf32_Phdr)); |
if (kernel_phdrs == NULL) |
{ |
fprintf (stderr, "Unable to allocate memory for program headers\n"); |
boot_exit (EXIT_FAILURE); |
} |
klseek (kfd, kexec_elf.e_phoff, SEEK_SET); |
if (kread (kfd, (void *) kernel_phdrs, |
kexec_elf.e_phnum * sizeof (*kernel_phdrs)) |
!= kexec_elf.e_phnum * sizeof (*kernel_phdrs)) |
{ |
fprintf (stderr, "Unable to read program headers from %s\n", |
kernel_name); |
boot_exit (EXIT_FAILURE); |
} |
break; |
} |
fprintf (stderr, "Wrong magic number %lo in kernel header\n", |
N_MAGIC(kexec)); |
boot_exit (EXIT_FAILURE); |
} |
|
/* Load the kernel one page after start of mem */ |
start_mem += PAGE_SIZE; |
mem_size -= PAGE_SIZE; |
/* Align bss size to multiple of four */ |
if (!elf_kernel) |
kexec.a_bss = (kexec.a_bss + 3) & ~3; |
|
/* init ramdisk */ |
if(ramdisk_name) { |
if((rfd = open(ramdisk_name, O_RDONLY)) == -1) { |
fprintf(stderr, "Unable to open ramdisk file %s\n", |
ramdisk_name); |
boot_exit(EXIT_FAILURE); |
} |
bi.ramdisk_size = (lseek(rfd, 0, SEEK_END) + 1023) / 1024; |
} |
else |
bi.ramdisk_size = 0; |
|
rd_size = bi.ramdisk_size << 10; |
if (mem_size - rd_size < MB && bi.num_memory > 1) |
/* If running low on ST ram load ramdisk into alternate ram. */ |
bi.ramdisk_addr = (u_long) bi.memory[1].addr + bi.memory[1].size - rd_size; |
else |
/* Else hopefully there is enough ST ram. */ |
bi.ramdisk_addr = (u_long)start_mem + mem_size - rd_size; |
|
/* calculate the total required amount of memory */ |
if (elf_kernel) |
{ |
u_long min_addr = 0xffffffff, max_addr = 0; |
for (i = 0; i < kexec_elf.e_phnum; i++) |
{ |
if (min_addr > kernel_phdrs[i].p_vaddr) |
min_addr = kernel_phdrs[i].p_vaddr; |
if (max_addr < kernel_phdrs[i].p_vaddr + kernel_phdrs[i].p_memsz) |
max_addr = kernel_phdrs[i].p_vaddr + kernel_phdrs[i].p_memsz; |
} |
/* This is needed for newer linkers that include the header in |
the first segment. */ |
if (min_addr == 0) |
{ |
min_addr = PAGE_SIZE; |
kernel_phdrs[0].p_vaddr += PAGE_SIZE; |
kernel_phdrs[0].p_offset += PAGE_SIZE; |
kernel_phdrs[0].p_filesz -= PAGE_SIZE; |
kernel_phdrs[0].p_memsz -= PAGE_SIZE; |
} |
kernel_size = max_addr - min_addr; |
} |
else |
kernel_size = kexec.a_text + kexec.a_data + kexec.a_bss; |
memreq = kernel_size + sizeof (bi) + rd_size; |
|
/* allocate RAM for the kernel */ |
if (!(memptr = (char *)Malloc (memreq))) |
{ |
fprintf (stderr, "Unable to allocate memory for kernel and ramdisk\n"); |
boot_exit (EXIT_FAILURE); |
} |
else |
fprintf(stderr, "kernel at address %lx\n", (u_long) memptr); |
|
(void)memset(memptr, 0, memreq); |
|
/* read the text and data segments from the kernel image */ |
if (elf_kernel) |
{ |
for (i = 0; i < kexec_elf.e_phnum; i++) |
{ |
if (klseek (kfd, kernel_phdrs[i].p_offset, SEEK_SET) == -1) |
{ |
fprintf (stderr, "Failed to seek to segment %d\n", i); |
boot_exit (EXIT_FAILURE); |
} |
if (kread (kfd, memptr + kernel_phdrs[i].p_vaddr - PAGE_SIZE, |
kernel_phdrs[i].p_filesz) |
!= kernel_phdrs[i].p_filesz) |
{ |
fprintf (stderr, "Failed to read segment %d\n", i); |
boot_exit (EXIT_FAILURE); |
} |
} |
} |
else |
{ |
if (klseek (kfd, text_offset, SEEK_SET) == -1) |
{ |
fprintf (stderr, "Failed to seek to text\n"); |
Mfree ((void *)memptr); |
boot_exit (EXIT_FAILURE); |
} |
|
if (kread (kfd, memptr, kexec.a_text) != kexec.a_text) |
{ |
fprintf (stderr, "Failed to read text\n"); |
Mfree ((void *)memptr); |
boot_exit (EXIT_FAILURE); |
} |
|
/* data follows immediately after text */ |
if (kread (kfd, memptr + kexec.a_text, kexec.a_data) != kexec.a_data) |
{ |
fprintf (stderr, "Failed to read data\n"); |
Mfree ((void *)memptr); |
boot_exit (EXIT_FAILURE); |
} |
} |
kclose (kfd); |
|
/* copy the boot_info struct to the end of the kernel image */ |
memcpy ((void *)(memptr + kernel_size), |
&bi, sizeof(bi)); |
|
/* read the ramdisk image */ |
if (rfd != -1) |
{ |
if (lseek (rfd, 0, SEEK_SET) == -1) |
{ |
fprintf (stderr, "Failed to seek to beginning of ramdisk file\n"); |
Mfree ((void *)memptr); |
boot_exit (EXIT_FAILURE); |
} |
if (read (rfd, memptr + kernel_size + sizeof (bi), |
rd_size) != rd_size) |
{ |
fprintf (stderr, "Failed to read ramdisk file\n"); |
Mfree ((void *)memptr); |
boot_exit (EXIT_FAILURE); |
} |
close (rfd); |
} |
|
/* for those who want to debug */ |
if (debugflag) |
{ |
if (bi.ramdisk_size) |
printf ("RAM disk at %#lx, size is %ldK\n", |
(u_long)memptr + kernel_size, |
bi.ramdisk_size); |
|
if (elf_kernel) |
{ |
for (i = 0; i < kexec_elf.e_phnum; i++) |
{ |
printf ("Kernel segment %d at %#lx, size %ld\n", i, |
start_mem + kernel_phdrs[i].p_vaddr - PAGE_SIZE, |
kernel_phdrs[i].p_memsz); |
} |
} |
else |
{ |
printf ("\nKernel text at %#lx, code size %d\n", |
start_mem, kexec.a_text); |
printf ("Kernel data at %#lx, data size %d\n", |
start_mem + kexec.a_text, kexec.a_data ); |
printf ("Kernel bss at %#lx, bss size %d\n", |
start_mem + kexec.a_text + kexec.a_data, kexec.a_bss ); |
} |
printf ("\nboot_info is at %#lx\n", |
start_mem + kernel_size); |
printf ("\nKernel entry is %#lx\n", |
elf_kernel ? kexec_elf.e_entry : kexec.a_entry); |
printf ("ramdisk dest top is %#lx\n", bi.ramdisk_addr + rd_size); |
printf ("ramdisk lower limit is %#lx\n", |
(u_long)(memptr + kernel_size)); |
printf ("ramdisk src top is %#lx\n", |
(u_long)(memptr + kernel_size) + |
rd_size); |
|
printf ("Type a key to continue the Linux boot..."); |
fflush (stdout); |
getchar(); |
} |
|
printf("Booting Linux...\n"); |
|
sync (); |
|
/* turn off interrupts... */ |
disable_interrupts(); |
|
/* turn off caches... */ |
disable_cache(); |
|
/* ..and any MMU translation */ |
disable_mmu(); |
|
/* ++guenther: allow reset if launched with MiNT */ |
*(long*)0x426 = 0; |
|
/* copy mover code to a safe place if needed */ |
memcpy ((void *) 0x400, ©all, ©allend - ©all); |
|
/* setup stack */ |
change_stack ((void *) PAGE_SIZE); |
|
/* |
* On the Atari you can have two situations: |
* 1. One piece of contiguous RAM (Falcon) |
* 2. Two pieces of contiguous RAM (TT) |
* In case 2 you can load your program into ST-ram and load your data in |
* any old RAM you have left. |
* In case 1 you could overwrite your own program when copying the |
* kernel and ramdisk to their final positions. |
* To solve this the mover code is copied to a safe place first. |
* Then this program jumps to the mover code. After the mover code |
* has finished it jumps to the start of the kernel in its new position. |
* I thought the memory just after the interrupt vector table was a safe |
* place because it is used by TOS to store some system variables. |
* This range goes from 0x400 to approx. 0x5B0. |
* This is more than enough for the miniscule mover routine (16 bytes). |
*/ |
|
jump_to_mover((char *) start_mem, memptr, |
(char *) bi.ramdisk_addr + rd_size, memptr + memreq, |
kernel_size + sizeof (bi), |
rd_size, |
(void *) 0x400); |
|
for (;;); |
/* NOTREACHED */ |
} |
|
|
|
#define MAXARGS 30 |
|
static void get_default_args( int *argc, char ***argv ) |
|
{ FILE *f; |
static char *nargv[MAXARGS]; |
char arg[256], *p; |
int c, quote, state; |
|
if (!(f = fopen( "bootargs", "r" ))) |
return; |
|
*argc = 1; |
if (***argv) |
nargv[0] = **argv; |
else |
nargv[0] = "bootstrap"; |
*argv = nargv; |
|
quote = state = 0; |
p = arg; |
while( (c = fgetc(f)) != EOF ) { |
|
if (state == 0) { |
/* outside args, skip whitespace */ |
if (!isspace(c)) { |
state = 1; |
p = arg; |
} |
} |
|
if (state) { |
/* inside an arg: copy it into 'arg', obeying quoting */ |
if (!quote && (c == '\'' || c == '"')) |
quote = c; |
else if (quote && c == quote) |
quote = 0; |
else if (!quote && isspace(c)) { |
/* end of this arg */ |
*p = 0; |
nargv[(*argc)++] = strdup(arg); |
state = 0; |
} |
else |
*p++ = c; |
} |
} |
if (state) { |
/* last arg finished by EOF! */ |
*p = 0; |
nargv[(*argc)++] = strdup(arg); |
} |
fclose( f ); |
|
nargv[*argc] = 0; |
} |
|
/Makefile
0,0 → 1,37
# |
# linux/arch/m68k/boot/Makefile |
# |
# This file is subject to the terms and conditions of the GNU General Public |
# License. See the file "COPYING" in the main directory of this archive |
# for more details. |
|
ifdef CONFIG_AMIGA |
AMIGA_BOOTOBJS := amiga/bootstrap.o |
endif |
|
ifdef CONFIG_ATARI |
ATARI_BOOTOBJS := atari/bootstrap.o |
HOSTCC += -b m68k-mint |
endif |
|
ifdef CONFIG_ATARI |
atari_bootstrap: $(ATARI_BOOTOBJS) |
$(HOSTCC) $(HOSTFLAGS) -o $@ $(ATARI_BOOTOBJS) |
rm -f ../../../bootstrap |
ln $@ ../../../bootstrap |
endif |
|
ifdef CONFIG_AMIGA |
amiga_bootstrap: $(AMIGA_BOOTOBJS) |
$(HOSTCC) $(HOSTFLAGS) -o $@ $(AMIGA_BOOTOBJS) |
rm -f ../../../bootstrap |
ln $@ ../../../bootstrap |
endif |
|
$(AMIGA_BOOTOBJS) $(ATARI_BOOTOBJS): %.o: %.c |
$(HOSTCC) $(HOSTFLAGS) -c $< -o $@ |
|
clean: |
rm -f *.o |
|
dep: |
/amiga/bootstrap.h
0,0 → 1,329
/* |
** bootstrap.h -- This file is a part of the Amiga bootloader. |
** |
** Copyright 1993, 1994 by Hamish Macdonald |
** |
** Some minor additions by Michael Rausch 1-11-94 |
** Modified 11-May-94 by Geert Uytterhoeven |
** (Geert.Uytterhoeven@cs.kuleuven.ac.be) |
** - inline Supervisor() call |
** |
** This file is subject to the terms and conditions of the GNU General Public |
** License. See the file COPYING in the main directory of this archive |
** for more details. |
** |
*/ |
|
#ifndef BOOTSTRAP_H |
#define BOOTSTRAP_H |
|
#include <asm/amigatypes.h> |
#include <asm/amigahw.h> |
|
struct List { |
struct Node *l_head; |
struct Node *l_tail; |
struct Node *l_tailpred; |
u_char l_type; |
u_char l_pad; |
}; |
|
struct MemChunk { |
struct MemChunk *mc_Next; /* pointer to next chunk */ |
u_long mc_Bytes; /* chunk byte size */ |
}; |
|
#define MEMF_CHIP (1<<1) |
#define MEMF_FAST (1<<2) |
#define MEMF_LOCAL (1<<8) |
#define MEMF_CLEAR (1<<16) |
|
struct MemHeader { |
struct Node mh_Node; |
u_short mh_Attributes; /* characteristics of this region */ |
struct MemChunk *mh_First; /* first free region */ |
void *mh_Lower; /* lower memory bound */ |
void *mh_Upper; /* upper memory bound+1 */ |
u_long mh_Free; /* total number of free bytes */ |
}; |
|
struct ExecBase { |
u_char fill1[296]; |
u_short AttnFlags; |
u_char fill2[24]; |
struct List MemList; |
u_char fill3[194]; |
u_char VBlankFrequency; |
u_char PowerSupplyFrequency; |
u_char fill4[36]; |
u_long EClockFrequency; |
}; |
|
#ifndef AFF_68020 |
#define AFB_68020 1 |
#define AFF_68020 (1<<AFB_68020) |
#endif |
|
#ifndef AFF_68030 |
#define AFB_68030 2 |
#define AFF_68030 (1<<AFB_68030) |
#endif |
|
#ifndef AFF_68040 |
#define AFB_68040 3 |
#define AFF_68040 (1<<AFB_68040) |
#endif |
|
#ifndef AFF_68881 |
#define AFB_68881 4 |
#define AFF_68881 (1<<AFB_68881) |
#endif |
|
#ifndef AFF_68882 |
#define AFB_68882 5 |
#define AFF_68882 (1<<AFB_68882) |
#endif |
|
#ifndef AFF_FPU40 |
#define AFB_FPU40 6 |
#define AFF_FPU40 (1<<AFB_FPU40) |
#endif |
|
/* |
* GfxBase is now used to determine if AGA or ECS is present |
*/ |
|
struct GfxBase { |
u_char unused1[0xec]; |
u_char ChipRevBits0; |
u_char unused2[5]; |
u_short monitor_id; |
}; |
|
#ifndef GFXB_HR_AGNUS |
#define GFXB_HR_AGNUS 0 |
#define GFXF_HR_AGNUS (1<<GFXB_HR_AGNUS) |
#endif |
|
#ifndef GFXB_HR_DENISE |
#define GFXB_HR_DENISE 1 |
#define GFXF_HR_DENISE (1<<GFXB_HR_DENISE) |
#endif |
|
#ifndef GFXB_AA_ALICE |
#define GFXB_AA_ALICE 2 |
#define GFXF_AA_ALICE (1<<GFXB_AA_ALICE) |
#endif |
|
#ifndef GFXB_AA_LISA |
#define GFXB_AA_LISA 3 |
#define GFXF_AA_LISA (1<<GFXB_AA_LISA) |
#endif |
|
/* |
* HiRes(=Big) Agnus present; i.e. |
* 1MB chipmem, big blits (none of interest so far) and programmable sync |
*/ |
#define GFXG_OCS (GFXF_HR_AGNUS) |
/* |
* HiRes Agnus/Denise present; we are running on ECS |
*/ |
#define GFXG_ECS (GFXF_HR_AGNUS|GFXF_HR_DENISE) |
/* |
* Alice and Lisa present; we are running on AGA |
*/ |
#define GFXG_AGA (GFXF_AA_ALICE|GFXF_AA_LISA) |
|
struct Library; |
|
extern struct ExecBase *SysBase; |
|
static __inline void * |
AllocMem (unsigned long byteSize,unsigned long requirements) |
{ |
register void *_res __asm("d0"); |
register struct ExecBase *a6 __asm("a6") = SysBase; |
register unsigned long d0 __asm("d0") = byteSize; |
register unsigned long d1 __asm("d1") = requirements; |
__asm __volatile ("jsr a6@(-0xc6)" |
: "=r" (_res) |
: "r" (a6), "r" (d0), "r" (d1) |
: "a0","a1","d0","d1", "memory"); |
return _res; |
} |
static __inline void |
CloseLibrary (struct Library *library) |
{ |
register struct ExecBase *a6 __asm("a6") = SysBase; |
register struct Library *a1 __asm("a1") = library; |
__asm __volatile ("jsr a6@(-0x19e)" |
: /* no output */ |
: "r" (a6), "r" (a1) |
: "a0","a1","d0","d1", "memory"); |
} |
static __inline void |
Disable (void) |
{ |
extern struct ExecBase *SysBase; |
register struct ExecBase *a6 __asm("a6") = SysBase; |
__asm __volatile ("jsr a6@(-0x78)" |
: /* no output */ |
: "r" (a6) |
: "a0","a1","d0","d1", "memory"); |
} |
static __inline void |
Enable (void) |
{ |
register struct ExecBase *a6 __asm("a6") = SysBase; |
__asm __volatile ("jsr a6@(-0x7e)" |
: /* no output */ |
: "r" (a6) |
: "a0","a1","d0","d1", "memory"); |
} |
static __inline void |
FreeMem (void * memoryBlock,unsigned long byteSize) |
{ |
register struct ExecBase *a6 __asm("a6") = SysBase; |
register void *a1 __asm("a1") = memoryBlock; |
register unsigned long d0 __asm("d0") = byteSize; |
__asm __volatile ("jsr a6@(-0xd2)" |
: /* no output */ |
: "r" (a6), "r" (a1), "r" (d0) |
: "a0","a1","d0","d1", "memory"); |
} |
static __inline struct Library * |
OpenLibrary (char *libName,unsigned long version) |
{ |
register struct Library * _res __asm("d0"); |
register struct ExecBase *a6 __asm("a6") = SysBase; |
register u_char *a1 __asm("a1") = libName; |
register unsigned long d0 __asm("d0") = version; |
__asm __volatile ("jsr a6@(-0x228)" |
: "=r" (_res) |
: "r" (a6), "r" (a1), "r" (d0) |
: "a0","a1","d0","d1", "memory"); |
return _res; |
} |
static __inline void * |
SuperState (void) |
{ |
register void *_res __asm("d0"); |
register struct ExecBase *a6 __asm("a6") = SysBase; |
__asm __volatile ("jsr a6@(-0x96)" |
: "=r" (_res) |
: "r" (a6) |
: "a0","a1","d0","d1", "memory"); |
return _res; |
} |
static __inline void |
CacheClearU (void) |
{ |
register struct ExecBase *a6 __asm("a6") = SysBase; |
__asm __volatile ("jsr a6@(-0x27c)" |
: /* no output */ |
: "r" (a6) |
: "a0","a1","d0","d1", "memory"); |
} |
static __inline unsigned long |
CacheControl (unsigned long cacheBits,unsigned long cacheMask) |
{ |
register unsigned long _res __asm("d0"); |
register struct ExecBase *a6 __asm("a6") = SysBase; |
register unsigned long d0 __asm("d0") = cacheBits; |
register unsigned long d1 __asm("d1") = cacheMask; |
__asm __volatile ("jsr a6@(-0x288)" |
: "=r" (_res) |
: "r" (a6), "r" (d0), "r" (d1) |
: "a0","a1","d0","d1", "memory"); |
return _res; |
} |
static __inline unsigned long |
Supervisor (unsigned long (*userfunc)()) |
{ |
register unsigned long _res __asm("d0"); |
register struct ExecBase *a6 __asm("a6") = SysBase; |
register unsigned long (*a0)() __asm("a0") = userfunc; |
/* gcc doesn't seem to like asm parameters in a5 */ |
__asm __volatile ("movel a5,sp@-;movel a0,a5;jsr a6@(-0x1e);movel sp@+,a5" |
: "=r" (_res) |
: "r" (a6), "r" (a0) |
: "a0","a1","d0","d1","memory"); |
return _res; |
} |
|
|
struct ExpansionBase; |
extern struct ExpansionBase *ExpansionBase; |
|
static __inline struct ConfigDev * |
FindConfigDev (struct ConfigDev *oldConfigDev,long manufacturer,long product) |
{ |
register struct ConfigDev * _res __asm("d0"); |
register struct ExpansionBase* a6 __asm("a6") = ExpansionBase; |
register struct ConfigDev *a0 __asm("a0") = oldConfigDev; |
register long d0 __asm("d0") = manufacturer; |
register long d1 __asm("d1") = product; |
__asm __volatile ("jsr a6@(-0x48)" |
: "=r" (_res) |
: "r" (a6), "r" (a0), "r" (d0), "r" (d1) |
: "a0","a1","d0","d1", "memory"); |
return _res; |
} |
|
struct GfxBase; |
extern struct GfxBase *GfxBase; |
struct View; |
static __inline void |
LoadView (struct View *view) |
{ |
register struct GfxBase* a6 __asm("a6") = GfxBase; |
register struct View *a1 __asm("a1") = view; |
__asm __volatile ("jsr a6@(-0xde)" |
: /* no output */ |
: "r" (a6), "r" (a1) |
: "a0","a1","d0","d1", "memory"); |
} |
|
static __inline void change_stack (char *stackp) |
{ |
__asm__ volatile ("movel %0,sp\n\t" :: "g" (stackp) : "sp"); |
} |
|
static __inline void disable_cache (void) |
{ |
__asm__ volatile ("movec %0,cacr" :: "d" (0)); |
} |
|
static __inline void disable_mmu (void) |
{ |
if (SysBase->AttnFlags & AFF_68040) |
__asm__ volatile ("moveq #0,d0;" |
".long 0x4e7b0003;" /* movec d0,tc */ |
".long 0x4e7b0004;" /* movec d0,itt0 */ |
".long 0x4e7b0005;" /* movec d0,itt1 */ |
".long 0x4e7b0006;" /* movec d0,dtt0 */ |
".long 0x4e7b0007" /* movec d0,dtt1 */ |
: /* no outputs */ |
: /* no inputs */ |
: "d0"); |
else { |
__asm__ volatile ("subl #4,sp;" |
"pmove tc,sp@;" |
"bclr #7,sp@;" |
"pmove sp@,tc;" |
"addl #4,sp"); |
if (SysBase->AttnFlags & AFF_68030) |
__asm__ volatile ("clrl sp@-;" |
".long 0xf0170800;" /* pmove sp@,tt0 */ |
".long 0xf0170c00;" /* pmove sp@,tt1 */ |
"addql #4,sp"); |
} |
} |
|
static __inline void jump_to (unsigned long addr) |
{ |
__asm__ volatile ("jmp %0@" :: "a" (addr)); |
/* NOTREACHED */ |
} |
|
#endif /* BOOTSTRAP_H */ |
/amiga/bootstrap.c
0,0 → 1,782
/* |
** bootstrap.c -- This program loads the Linux/68k kernel into an Amiga |
** and launches it. |
** |
** Copyright 1993,1994 by Hamish Macdonald, Greg Harp |
** |
** Modified 11-May-94 by Geert Uytterhoeven |
** (Geert.Uytterhoeven@cs.kuleuven.ac.be) |
** - A3640 MapROM check |
** Modified 31-May-94 by Geert Uytterhoeven |
** - Memory thrash problem solved |
** Modified 07-March-95 by Geert Uytterhoeven |
** - Memory block sizes are rounded to a multiple of 256K instead of 1M |
** This _requires_ >0.9pl5 to work! |
** (unless all block sizes are multiples of 1M :-) |
** |
** This file is subject to the terms and conditions of the GNU General Public |
** License. See the file COPYING in the main directory of this archive |
** for more details. |
** |
*/ |
|
#include <stddef.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <string.h> |
#include <sys/file.h> |
#include <sys/types.h> |
#include <unistd.h> |
|
/* Amiga bootstrap include file */ |
#include "bootstrap.h" |
|
/* required Linux/68k include files */ |
#include <linux/a.out.h> |
#include <asm/bootinfo.h> |
|
/* temporary stack size */ |
#define TEMP_STACKSIZE 256 |
|
/* Exec Base */ |
extern struct ExecBase *SysBase; |
|
extern char *optarg; |
|
struct exec kexec; |
char *memptr; |
u_long start_mem; |
u_long mem_size; |
u_long rd_size; |
|
struct ExpansionBase *ExpansionBase; |
struct GfxBase *GfxBase; |
|
struct bootinfo bi; |
u_long bi_size = sizeof bi; |
|
caddr_t CustomBase = (caddr_t)CUSTOM_PHYSADDR; |
|
void usage(void) |
{ |
fprintf (stderr, "Usage:\n" |
"\tbootstrap [-d] [-k kernel_executable] [-r ramdisk_file]" |
" [option...]\n"); |
exit (EXIT_FAILURE); |
} |
|
/* |
* This assembler code is copied to chip ram, and |
* then executed. |
* It copies the kernel (and ramdisk) to their |
* final resting place. |
*/ |
#ifndef __GNUC__ |
#error GNU CC is required to compile the bootstrap program |
#endif |
asm(" |
.text |
.globl _copyall, _copyallend |
_copyall: |
| /* put variables in registers because they may */ |
lea _kexec,a3 | /* be overwritten by kernel/ramdisk copy!! - G.U. */ |
movel _memptr,a4 |
movel _start_mem,a5 |
movel _mem_size,d0 |
movel _rd_size,d1 |
movel _bi_size,d5 |
movel a3@(4),d2 | kexec.a_text |
movel a3@(8),d3 | kexec.a_data |
movel a3@(12),d4 | kexec.a_bss |
|
| /* copy kernel text and data */ |
movel a4,a0 | src = (u_long *)memptr; |
movel a0,a2 | limit = (u_long *)(memptr + kexec.a_text + kexec.a_data); |
addl d2,a2 |
addl d3,a2 |
movel a5,a1 | dest = (u_long *)start_mem; |
1: cmpl a0,a2 |
beqs 2f | while (src < limit) |
moveb a0@+,a1@+ | *dest++ = *src++; |
bras 1b |
2: |
|
| /* clear kernel bss */ |
movel a1,a0 | dest = (u_long *)(start_mem + kexec.a_text + kexec.a_data); |
movel a1,a2 | limit = dest + kexec.a_bss / sizeof(u_long); |
addl d4,a2 |
1: cmpl a0,a2 |
beqs 2f | while (dest < limit) |
clrb a0@+ | *dest++ = 0; |
bras 1b |
2: |
|
| /* copy bootinfo to end of bss */ |
movel a4,a1 | src = (u long *)memptr + kexec.a_text + kexec.a_data); |
addl d2,a1 |
addl d3,a1 | dest = end of bss (already in a0) |
movel d5,d7 | count = sizeof bi |
subql #1,d7 |
1: moveb a1@+,a0@+ | while (--count > -1) |
dbra d7,1b | *dest++ = *src++ |
|
|
| /* copy the ramdisk to the top of memory (from back to front) */ |
movel a5,a1 | dest = (u_long *)(start_mem + mem_size); |
addl d0,a1 |
movel a4,a2 | limit = (u_long *)(memptr + kexec.a_text + kexec.a_data + sizeof bi); |
addl d2,a2 |
addl d3,a2 |
addl d5,a2 |
movel a2,a0 | src = (u_long *)((u_long)limit + rd_size); |
addl d1,a0 |
1: cmpl a0,a2 |
beqs 2f | while (src > limit) |
moveb a0@-,a1@- | *--dest = *--src; |
bras 1b |
2: |
| /* jump to start of kernel */ |
movel a5,a0 | jump_to (START_MEM); |
jsr a0@ |
_copyallend: |
"); |
|
asm(" |
.text |
.globl _maprommed |
_maprommed: |
oriw #0x0700,sr |
moveml #0x3f20,sp@- |
/* Save cache settings */ |
.long 0x4e7a1002 /* movec cacr,d1 */ |
/* Save MMU settings */ |
.long 0x4e7a2003 /* movec tc,d2 */ |
.long 0x4e7a3004 /* movec itt0,d3 */ |
.long 0x4e7a4005 /* movec itt1,d4 */ |
.long 0x4e7a5006 /* movec dtt0,d5 */ |
.long 0x4e7a6007 /* movec dtt1,d6 */ |
moveq #0,d0 |
movel d0,a2 |
/* Disable caches */ |
.long 0x4e7b0002 /* movec d0,cacr */ |
/* Disable MMU */ |
.long 0x4e7b0003 /* movec d0,tc */ |
.long 0x4e7b0004 /* movec d0,itt0 */ |
.long 0x4e7b0005 /* movec d0,itt1 */ |
.long 0x4e7b0006 /* movec d0,dtt0 */ |
.long 0x4e7b0007 /* movec d0,dtt1 */ |
lea 0x07f80000,a0 |
lea 0x00f80000,a1 |
movel a0@,d7 |
cmpl a1@,d7 |
jnes 1f |
movel d7,d0 |
notl d0 |
movel d0,a0@ |
nop |
cmpl a1@,d0 |
jnes 1f |
/* MapROMmed A3640 present */ |
moveq #-1,d0 |
movel d0,a2 |
1: movel d7,a0@ |
/* Restore MMU settings */ |
.long 0x4e7b2003 /* movec d2,tc */ |
.long 0x4e7b3004 /* movec d3,itt0 */ |
.long 0x4e7b4005 /* movec d4,itt1 */ |
.long 0x4e7b5006 /* movec d5,dtt0 */ |
.long 0x4e7b6007 /* movec d6,dtt1 */ |
/* Restore cache settings */ |
.long 0x4e7b1002 /* movec d1,cacr */ |
movel a2,d0 |
moveml sp@+,#0x04fc |
rte |
"); |
|
extern unsigned long maprommed(); |
|
|
extern char copyall, copyallend; |
|
int main(int argc, char *argv[]) |
{ |
int ch, debugflag = 0, kfd, rfd = -1, i; |
long fast_total = 0; /* total Fast RAM in system */ |
struct MemHeader *mnp; |
struct ConfigDev *cdp = NULL; |
char *kernel_name = "vmlinux"; |
char *ramdisk_name = NULL; |
char *memfile = NULL; |
u_long memreq; |
void (*startfunc)(void); |
long startcodesize; |
u_long *stack, text_offset; |
unsigned char *rb3_reg = NULL, *piccolo_reg = NULL, *sd64_reg = NULL; |
|
/* print the greet message */ |
puts("Linux/68k Amiga Bootstrap version 1.11"); |
puts("Copyright 1993,1994 by Hamish Macdonald and Greg Harp\n"); |
|
/* machine is Amiga */ |
bi.machtype = MACH_AMIGA; |
|
/* check arguments */ |
while ((ch = getopt(argc, argv, "dk:r:m:")) != EOF) |
switch (ch) { |
case 'd': |
debugflag = 1; |
break; |
case 'k': |
kernel_name = optarg; |
break; |
case 'r': |
ramdisk_name = optarg; |
break; |
case 'm': |
memfile = optarg; |
break; |
case '?': |
default: |
usage(); |
} |
argc -= optind; |
argv += optind; |
|
SysBase = *(struct ExecBase **)4; |
|
/* Memory & AutoConfig based on 'unix_boot.c' by C= */ |
|
/* open Expansion Library */ |
ExpansionBase = (struct ExpansionBase *)OpenLibrary("expansion.library", 36); |
if (!ExpansionBase) { |
puts("Unable to open expansion.library V36 or greater! Aborting..."); |
exit(EXIT_FAILURE); |
} |
|
/* find all of the autoconfig boards in the system */ |
cdp = (struct ConfigDev *)FindConfigDev(cdp, -1, -1); |
for (i=0; (i < NUM_AUTO) && cdp; i++) { |
/* copy the contents of each structure into our boot info */ |
memcpy(&bi.bi_amiga.autocon[i], cdp, sizeof(struct ConfigDev)); |
|
/* count this device */ |
bi.bi_amiga.num_autocon++; |
|
/* get next device */ |
cdp = (struct ConfigDev *)FindConfigDev(cdp, -1, -1); |
} |
|
/* find out the memory in the system */ |
for (mnp = (struct MemHeader *)SysBase->MemList.l_head; |
(bi.num_memory < NUM_MEMINFO) && mnp->mh_Node.ln_Succ; |
mnp = (struct MemHeader *)mnp->mh_Node.ln_Succ) |
{ |
struct MemHeader mh; |
|
/* copy the information */ |
mh = *mnp; |
|
/* if we suspect that Kickstart is shadowed in an A3000, |
modify the entry to show 512K more at the top of RAM |
Check first for a MapROMmed A3640 board: overwriting the |
Kickstart image causes an infinite lock-up on reboot! */ |
|
if (mh.mh_Upper == (void *)0x07f80000) |
if ((SysBase->AttnFlags & AFF_68040) && Supervisor(maprommed)) |
printf("A3640 MapROM detected.\n"); |
else { |
mh.mh_Upper = (void *)0x08000000; |
printf("A3000 shadowed Kickstart detected.\n"); |
} |
|
/* if we suspect that Kickstart is zkicked, |
modify the entry to show 512K more at the bottom of RAM */ |
if (mh.mh_Lower == (void *)0x00280020) { |
mh.mh_Lower = (void *)0x00200000; |
printf("ZKick detected.\n"); |
} |
|
/* |
* If this machine has "LOCAL" memory between 0x07000000 |
* and 0x080000000, then we'll call it an A3000. |
*/ |
if (mh.mh_Lower >= (void *)0x07000000 && |
mh.mh_Lower < (void *)0x08000000 && |
(mh.mh_Attributes & MEMF_LOCAL)) |
bi.bi_amiga.model = AMI_3000; |
|
/* mask the memory limit values */ |
mh.mh_Upper = (void *)((u_long)mh.mh_Upper & 0xfffff000); |
mh.mh_Lower = (void *)((u_long)mh.mh_Lower & 0xfffff000); |
|
/* if fast memory */ |
if (mh.mh_Attributes & MEMF_FAST) { |
unsigned long size; |
|
/* record the start */ |
bi.memory[bi.num_memory].addr = (u_long)mh.mh_Lower; |
|
/* set the size value to the size of this block */ |
size = (u_long)mh.mh_Upper - (u_long)mh.mh_Lower; |
|
/* mask off to a 256K increment */ |
size &= 0xfffc0000; |
|
fast_total += size; |
|
if (size > 0) |
/* count this block */ |
bi.memory[bi.num_memory++].size = size; |
|
} else if (mh.mh_Attributes & MEMF_CHIP) { |
/* if CHIP memory, record the size */ |
bi.bi_amiga.chip_size = |
(u_long)mh.mh_Upper; /* - (u_long)mh.mh_Lower; */ |
} |
} |
|
CloseLibrary((struct Library *)ExpansionBase); |
|
/* |
* if we have a memory file, read the memory information from it |
*/ |
if (memfile) { |
FILE *fp; |
int i; |
|
if ((fp = fopen (memfile, "r")) == NULL) { |
perror ("open memory file"); |
fprintf (stderr, "Cannot open memory file %s\n", memfile); |
exit (EXIT_FAILURE); |
} |
|
if (fscanf (fp, "%lu", &bi.bi_amiga.chip_size) != 1) { |
fprintf (stderr, "memory file does not contain chip memory size\n"); |
fclose (fp); |
exit (EXIT_FAILURE); |
} |
|
for (i = 0; i < NUM_MEMINFO; i++) { |
if (fscanf (fp, "%lx %lu", &bi.memory[i].addr, |
&bi.memory[i].size) != 2) |
break; |
} |
|
fclose (fp); |
|
if (i != bi.num_memory && i > 0) |
bi.num_memory = i; |
} |
|
/* get info from ExecBase */ |
bi.bi_amiga.vblank = SysBase->VBlankFrequency; |
bi.bi_amiga.psfreq = SysBase->PowerSupplyFrequency; |
bi.bi_amiga.eclock = SysBase->EClockFrequency; |
|
/* open graphics library */ |
GfxBase = (struct GfxBase *)OpenLibrary ("graphics.library", 0); |
|
/* determine chipset */ |
bi.bi_amiga.chipset = CS_STONEAGE; |
if(GfxBase) |
{ |
if(GfxBase->ChipRevBits0 & GFXG_AGA) |
{ |
bi.bi_amiga.chipset = CS_AGA; |
/* |
* we considered this machine to be an A3000 because of its |
* local memory just beneath $8000000; now if it has AGA, it |
* must be an A4000 |
* except the case no RAM is installed on the motherboard but |
* on an additional card like FastLane Z3 or on the processor |
* board itself. Gotta check this out. |
*/ |
bi.bi_amiga.model = |
(bi.bi_amiga.model == AMI_3000) ? AMI_4000 : AMI_1200; |
} |
else if(GfxBase->ChipRevBits0 & GFXG_ECS) |
bi.bi_amiga.chipset = CS_ECS; |
else if(GfxBase->ChipRevBits0 & GFXG_OCS) |
bi.bi_amiga.chipset = CS_OCS; |
} |
|
/* Display amiga model */ |
switch (bi.bi_amiga.model) { |
case AMI_UNKNOWN: |
break; |
case AMI_500: |
printf ("Amiga 500 "); |
break; |
case AMI_2000: |
printf ("Amiga 2000 "); |
break; |
case AMI_3000: |
printf ("Amiga 3000 "); |
break; |
case AMI_4000: |
printf ("Amiga 4000 "); |
break; |
case AMI_1200: /* this implies an upgraded model */ |
printf ("Amiga 1200 "); /* equipped with at least 68030 !!! */ |
break; |
} |
|
/* display and set the CPU <type */ |
printf("CPU: "); |
if (SysBase->AttnFlags & AFF_68040) { |
printf("68040"); |
bi.cputype = CPU_68040; |
if (SysBase->AttnFlags & AFF_FPU40) { |
printf(" with internal FPU"); |
bi.cputype |= FPU_68040; |
} else |
printf(" without FPU"); |
} else { |
if (SysBase->AttnFlags & AFF_68030) { |
printf("68030"); |
bi.cputype = CPU_68030; |
} else if (SysBase->AttnFlags & AFF_68020) { |
printf("68020 (Do you have an MMU?)"); |
bi.cputype = CPU_68020; |
} else { |
puts("Insufficient for Linux. Aborting..."); |
printf("SysBase->AttnFlags = %#x\n", SysBase->AttnFlags); |
exit (EXIT_FAILURE); |
} |
if (SysBase->AttnFlags & AFF_68882) { |
printf(" with 68882 FPU"); |
bi.cputype |= FPU_68882; |
} else if (SysBase->AttnFlags & AFF_68881) { |
printf(" with 68881 FPU"); |
bi.cputype |= FPU_68881; |
} else |
printf(" without FPU"); |
} |
|
switch(bi.bi_amiga.chipset) |
{ |
case CS_STONEAGE: |
printf(", old or unknown chipset"); |
break; |
case CS_OCS: |
printf(", OCS"); |
break; |
case CS_ECS: |
printf(", ECS"); |
break; |
case CS_AGA: |
printf(", AGA chipset"); |
break; |
} |
|
putchar ('\n'); |
putchar ('\n'); |
|
/* |
* Copy command line options into the kernel command line. |
*/ |
i = 0; |
while (argc--) { |
if ((i+strlen(*argv)+1) < CL_SIZE) { |
i += strlen(*argv) + 1; |
if (bi.command_line[0]) |
strcat (bi.command_line, " "); |
strcat (bi.command_line, *argv++); |
} |
} |
printf ("Command line is '%s'\n", bi.command_line); |
|
/* display the clock statistics */ |
printf("Vertical Blank Frequency: %dHz\nPower Supply Frequency: %dHz\n", |
bi.bi_amiga.vblank, bi.bi_amiga.psfreq); |
printf("EClock Frequency: %7.5fKHz\n\n", |
(float)bi.bi_amiga.eclock / 1000); |
|
/* display autoconfig devices */ |
if (bi.bi_amiga.num_autocon) { |
printf("Found %d AutoConfig Device%s", bi.bi_amiga.num_autocon, |
(bi.bi_amiga.num_autocon > 1)?"s\n":"\n"); |
for (i=0; i<bi.bi_amiga.num_autocon; i++) |
{ |
printf("Device %d: addr = %08lx\n", i, |
(u_long)bi.bi_amiga.autocon[i].cd_BoardAddr); |
/* check for a Rainbow 3 and prepare to reset it if there is one */ |
if ( (bi.bi_amiga.autocon[i].cd_Rom.er_Manufacturer == MANUF_HELFRICH1) && |
(bi.bi_amiga.autocon[i].cd_Rom.er_Product == PROD_RAINBOW3) ) |
{ |
printf("(Found a Rainbow 3 board - will reset it at kernel boot time)\n"); |
rb3_reg = (unsigned char *)(bi.bi_amiga.autocon[i].cd_BoardAddr + 0x01002000); |
} |
|
/* check for a Piccolo and prepare to reset it if there is one */ |
if ( (bi.bi_amiga.autocon[i].cd_Rom.er_Manufacturer == MANUF_HELFRICH2) && |
(bi.bi_amiga.autocon[i].cd_Rom.er_Product == PROD_PICCOLO_REG) ) |
{ |
printf("(Found a Piccolo board - will reset it at kernel boot time)\n"); |
piccolo_reg = (unsigned char *)(bi.bi_amiga.autocon[i].cd_BoardAddr + 0x8000); |
} |
|
/* check for a SD64 and prepare to reset it if there is one */ |
if ( (bi.bi_amiga.autocon[i].cd_Rom.er_Manufacturer == MANUF_HELFRICH2) && |
(bi.bi_amiga.autocon[i].cd_Rom.er_Product == PROD_SD64_REG) ) |
{ |
printf("(Found a SD64 board - will reset it at kernel boot time)\n"); |
sd64_reg = (unsigned char *)(bi.bi_amiga.autocon[i].cd_BoardAddr + 0x8000); |
} |
|
/* what this code lacks - what if there are several boards of */ |
/* the same brand ? In that case I should reset them one after */ |
/* the other, which is currently not done - a rare case...FN */ |
/* ok, MY amiga currently hosts all three of the above boards ;-) */ |
} |
} else |
puts("No AutoConfig Devices Found"); |
|
/* display memory */ |
if (bi.num_memory) { |
printf("\n%d Block%sof Memory Found\n", bi.num_memory, |
(bi.num_memory > 1)?"s ":" "); |
for (i=0; i<bi.num_memory; i++) { |
printf("Block %d: %08lx to %08lx (%ldKB)\n", |
i, bi.memory[i].addr, |
bi.memory[i].addr + bi.memory[i].size, |
bi.memory[i].size >> 10); |
} |
} else { |
puts("No memory found?! Aborting..."); |
exit(10); |
} |
|
/* display chip memory size */ |
printf ("%ldK of CHIP memory\n", bi.bi_amiga.chip_size >> 10); |
|
start_mem = bi.memory[0].addr; |
mem_size = bi.memory[0].size; |
|
/* tell us where the kernel will go */ |
printf("\nThe kernel will be located at %08lx\n", start_mem); |
|
/* verify that there is enough Chip RAM */ |
if (bi.bi_amiga.chip_size < 512*1024) { |
puts("\nNot enough Chip RAM in this system. Aborting..."); |
exit(10); |
} |
|
/* verify that there is enough Fast RAM */ |
if (fast_total < 2*1024*1024) { |
puts("\nNot enough Fast RAM in this system. Aborting..."); |
exit(10); |
} |
|
/* open kernel executable and read exec header */ |
if ((kfd = open (kernel_name, O_RDONLY)) == -1) { |
fprintf (stderr, "Unable to open kernel file %s\n", kernel_name); |
exit (EXIT_FAILURE); |
} |
|
if (read (kfd, (void *)&kexec, sizeof(kexec)) != sizeof(kexec)) { |
fprintf (stderr, "Unable to read exec header from %s\n", |
kernel_name); |
exit (EXIT_FAILURE); |
} |
|
switch (N_MAGIC(kexec)) { |
case ZMAGIC: |
text_offset = N_TXTOFF(kexec); |
break; |
case QMAGIC: |
text_offset = sizeof(kexec); |
/* the text size includes the exec header; remove this */ |
kexec.a_text -= sizeof(kexec); |
break; |
default: |
fprintf (stderr, "Wrong magic number %lo in kernel header\n", |
N_MAGIC(kexec)); |
exit (EXIT_FAILURE); |
} |
|
/* Load the kernel at one page after start of mem */ |
start_mem += PAGE_SIZE; |
mem_size -= PAGE_SIZE; |
/* Align bss size to multiple of four */ |
kexec.a_bss = (kexec.a_bss + 3) & ~3; |
|
if (ramdisk_name) { |
if ((rfd = open (ramdisk_name, O_RDONLY)) == -1) { |
fprintf (stderr, "Unable to open ramdisk file %s\n", |
ramdisk_name); |
exit (EXIT_FAILURE); |
} |
/* record ramdisk size */ |
bi.ramdisk_size = (lseek (rfd, 0, L_XTND) + 1023) >> 10; |
} else |
bi.ramdisk_size = 0; |
|
rd_size = bi.ramdisk_size << 10; |
bi.ramdisk_addr = (u_long)start_mem + mem_size - rd_size; |
|
memreq = kexec.a_text + kexec.a_data + sizeof(bi) + rd_size; |
if (!(memptr = (char *)AllocMem (memreq, MEMF_FAST | MEMF_CLEAR))) { |
fprintf (stderr, "Unable to allocate memory\n"); |
exit (EXIT_FAILURE); |
} |
|
if (lseek (kfd, text_offset, L_SET) == -1) { |
fprintf (stderr, "Failed to seek to text\n"); |
FreeMem ((void *)memptr, memreq); |
exit (EXIT_FAILURE); |
} |
if (read (kfd, memptr, kexec.a_text) != kexec.a_text) { |
fprintf (stderr, "Failed to read text\n"); |
FreeMem ((void *)memptr, memreq); |
exit (EXIT_FAILURE); |
} |
|
/* data follows immediately after text */ |
if (read (kfd, memptr + kexec.a_text, kexec.a_data) != kexec.a_data) { |
fprintf (stderr, "Failed to read data\n"); |
FreeMem ((void *)memptr, memreq); |
exit (EXIT_FAILURE); |
} |
close (kfd); |
|
/* copy the boot_info struct to the end of the kernel image */ |
memcpy ((void *)(memptr + kexec.a_text + kexec.a_data), &bi, |
sizeof(bi)); |
|
if (rfd != -1) { |
if (lseek (rfd, 0, L_SET) == -1) { |
fprintf (stderr, "Failed to seek to beginning of ramdisk file\n"); |
FreeMem ((void *)memptr, memreq); |
exit (EXIT_FAILURE); |
} |
if (read (rfd, memptr + kexec.a_text + kexec.a_data |
+ sizeof(bi), rd_size) != rd_size) { |
fprintf (stderr, "Failed to read ramdisk file\n"); |
FreeMem ((void *)memptr, memreq); |
exit (EXIT_FAILURE); |
} |
close (rfd); |
} |
|
/* allocate temporary chip ram stack */ |
stack = (u_long *)AllocMem( TEMP_STACKSIZE, MEMF_CHIP|MEMF_CLEAR); |
if (!stack) { |
fprintf (stderr, "Unable to allocate memory for stack\n"); |
FreeMem ((void *)memptr, memreq); |
exit (EXIT_FAILURE); |
} |
|
/* allocate chip ram for copy of startup code */ |
startcodesize = ©allend - ©all; |
startfunc = (void (*)(void))AllocMem( startcodesize, MEMF_CHIP); |
if (!startfunc) { |
fprintf (stderr, "Unable to allocate memory for code\n"); |
FreeMem ((void *)memptr, memreq); |
FreeMem ((void *)stack, TEMP_STACKSIZE); |
exit (EXIT_FAILURE); |
} |
|
/* copy startup code to CHIP RAM */ |
memcpy (startfunc, ©all, startcodesize); |
|
if (debugflag) { |
if (bi.ramdisk_size) |
printf ("RAM disk at %#lx, size is %ldK\n", |
(u_long)memptr + kexec.a_text + kexec.a_data, |
bi.ramdisk_size); |
|
printf ("\nKernel text at %#lx, code size %x\n", |
start_mem, kexec.a_text); |
printf ("Kernel data at %#lx, data size %x\n", |
start_mem + kexec.a_text, kexec.a_data ); |
printf ("Kernel bss at %#lx, bss size %x\n", |
start_mem + kexec.a_text + kexec.a_data, |
kexec.a_bss ); |
printf ("boot info at %#lx\n", start_mem + kexec.a_text |
+ kexec.a_data + kexec.a_bss); |
|
printf ("\nKernel entry is %#x\n", kexec.a_entry ); |
|
printf ("ramdisk dest top is %#lx\n", start_mem + mem_size); |
printf ("ramdisk lower limit is %#lx\n", |
(u_long)(memptr + kexec.a_text + kexec.a_data)); |
printf ("ramdisk src top is %#lx\n", |
(u_long)(memptr + kexec.a_text + kexec.a_data) |
+ rd_size); |
|
printf ("Type a key to continue the Linux boot..."); |
fflush (stdout); |
getchar(); |
} |
|
/* wait for things to settle down */ |
sleep(2); |
|
/* FN: If a Rainbow III board is present, reset it to disable */ |
/* its (possibly activated) vertical blank interrupts as the */ |
/* kernel is not yet prepared to handle them (level 6). */ |
if (rb3_reg != NULL) |
{ |
/* set RESET bit in special function register */ |
*rb3_reg = 0x01; |
/* actually, only a few cycles delay are required... */ |
sleep(1); |
/* clear reset bit */ |
*rb3_reg = 0x00; |
} |
|
/* the same stuff as above, for the Piccolo board. */ |
/* this also has the side effect of resetting the board's */ |
/* output selection logic to use the Amiga's display in single */ |
/* monitor systems - which is currently what we want. */ |
if (piccolo_reg != NULL) |
{ |
/* set RESET bit in special function register */ |
*piccolo_reg = 0x01; |
/* actually, only a few cycles delay are required... */ |
sleep(1); |
/* clear reset bit */ |
*piccolo_reg = 0x51; |
} |
|
/* the same stuff as above, for the SD64 board. */ |
/* just as on the Piccolo, this also resets the monitor switch */ |
if (sd64_reg != NULL) |
{ |
/* set RESET bit in special function register */ |
*sd64_reg = 0x1f; |
/* actually, only a few cycles delay are required... */ |
sleep(1); |
/* clear reset bit AND switch monitor bit (0x20) */ |
*sd64_reg = 0x4f; |
} |
|
if (GfxBase) { |
/* set graphics mode to a nice normal one */ |
LoadView (NULL); |
CloseLibrary ((struct Library *)GfxBase); |
} |
|
Disable(); |
|
/* Turn off all DMA */ |
custom.dmacon = DMAF_ALL | DMAF_MASTER; |
|
/* turn off caches */ |
CacheControl (0L, ~0L); |
|
/* Go into supervisor state */ |
SuperState (); |
|
/* setup stack */ |
change_stack ((char *) stack + TEMP_STACKSIZE); |
|
/* turn off any mmu translation */ |
disable_mmu (); |
|
/* execute the copy-and-go code (from CHIP RAM) */ |
startfunc(); |
|
/* NOTREACHED */ |
} |