80 columns, dammit!

This commit is contained in:
bjh21 2003-04-20 14:21:13 +00:00
parent 2020a72f18
commit ef40902514

View File

@ -1,4 +1,4 @@
/* $NetBSD: boot32.c,v 1.11 2003/01/15 16:29:27 reinoud Exp $ */
/* $NetBSD: boot32.c,v 1.12 2003/04/20 14:21:13 bjh21 Exp $ */
/*-
* Copyright (c) 2002 Reinoud Zandijk
@ -48,7 +48,7 @@ int debug = 1;
/* constants */
#define PODRAM_START (512*1024*1024) /* XXX Kinetic cards XXX */
#define PODRAM_START (512*1024*1024) /* XXX Kinetic cards XXX */
#define MAX_RELOCPAGES 4096
@ -61,63 +61,68 @@ int debug = 1;
/* booter variables */
char scrap[80], twirl_cnt; /* misc */
char scrap[80], twirl_cnt; /* misc */
char booted_file[80];
struct bootconfig *bconfig; /* bootconfig passing */
u_long bconfig_new_phys; /* physical address its bound */
struct bootconfig *bconfig; /* bootconfig passing */
u_long bconfig_new_phys; /* physical address its bound */
u_int monitor_type, monitor_sync, ioeb_flags, lcd_flags; /* computer knowledge */
/* Computer knowledge */
u_int monitor_type, monitor_sync, ioeb_flags, lcd_flags;
u_int superio_flags, superio_flags_basic, superio_flags_extra;
int nbpp, memory_table_size, memory_image_size; /* sizes */
u_long reloc_tablesize, *reloc_instruction_table; /* relocate info */
u_long *reloc_pos; /* current empty entry */
int reloc_entries; /* number of relocations */
int first_mapped_DRAM_page_index; /* offset in RISC OS blob */
int first_mapped_PODRAM_page_index; /* offset in RISC OS blob */
struct page_info *mem_pages_info; /* {nr, virt, phys}* */
struct page_info *free_relocation_page; /* points to the page_info chain*/
struct page_info *relocate_table_pages; /* points to seq. relocate info */
struct page_info *relocate_code_page; /* points to the copied code */
struct page_info *bconfig_page; /* page for passing on settings */
int nbpp, memory_table_size, memory_image_size; /* sizes */
u_long reloc_tablesize, *reloc_instruction_table; /* relocate info */
u_long *reloc_pos; /* current empty entry */
int reloc_entries; /* number of relocations */
int first_mapped_DRAM_page_index; /* offset in RISC OS blob */
int first_mapped_PODRAM_page_index;/* offset in RISC OS blob */
unsigned char *memory_page_types; /* packed array of 4 bit typeId */
struct page_info *mem_pages_info; /* {nr, virt, phys}* */
struct page_info *free_relocation_page; /* points to the page_info chain*/
struct page_info *relocate_table_pages; /* points to seq. relocate info */
struct page_info *relocate_code_page; /* points to the copied code */
struct page_info *bconfig_page; /* page for passing on settings */
u_long *initial_page_tables; /* pagetables to be booted from */
unsigned char *memory_page_types; /* packed array of 4 bit typeId */
u_long *initial_page_tables; /* pagetables to be booted from */
/* XXX rename *_BLOCKS to MEM_BLOCKS */
/* DRAM/VRAM/ROM/IO info */
u_long videomem_start, videomem_pages, display_size; /* where the display is */
u_long videomem_start, videomem_pages, display_size;/* where the display is*/
u_long pv_offset, top_physdram; /* kernel_base - phys. diff */
u_long top_1Mb_dram; /* the lower mapped top 1Mb */
u_long new_L1_pages_phys; /* physical address of L1 pages */
u_long pv_offset, top_physdram; /* kernel_base - phys. diff */
u_long top_1Mb_dram; /* the lower mapped top 1Mb */
u_long new_L1_pages_phys; /* physical address of L1 pages */
u_long total_podram_pages, total_dram_pages, total_vram_pages;/* for bootconfig passing */
int dram_blocks, podram_blocks; /* number of mem. objects/type */
/* for bootconfig passing*/
u_long total_podram_pages, total_dram_pages, total_vram_pages;
int dram_blocks, podram_blocks; /* number of mem. objects/type */
int vram_blocks, rom_blocks, io_blocks;
u_long DRAM_addr[DRAM_BLOCKS], DRAM_pages[DRAM_BLOCKS];
u_long PODRAM_addr[PODRAM_BLOCKS], PODRAM_pages[PODRAM_BLOCKS]; /* processor only RAM */
/* processor only RAM */
u_long PODRAM_addr[PODRAM_BLOCKS], PODRAM_pages[PODRAM_BLOCKS];
u_long VRAM_addr[VRAM_BLOCKS], VRAM_pages[VRAM_BLOCKS];
u_long ROM_addr[ROM_BLOCKS], ROM_pages[ROM_BLOCKS];
u_long IO_addr[IO_BLOCKS], IO_pages[IO_BLOCKS];
/* RISC OS memory pages we claimed */
u_long firstpage, lastpage, totalpages; /* RISC OS pagecounters */
char *memory_image, *bottom_memory, *top_memory; /* RISC OS memory */
u_long firstpage, lastpage, totalpages;/* RISC OS pagecounters */
char *memory_image, *bottom_memory, *top_memory;/* RISC OS memory */
u_long videomem_start_ro; /* for debugging mainly */
u_long videomem_start_ro; /* for debugging mainly */
/* kernel info */
u_long marks[MARK_MAX]; /* loader mark pointers */
u_long kernel_physical_start; /* where does it get relocated */
u_long kernel_free_vm_start; /* where does the free VM start */
u_long scratch_virtualbase, scratch_physicalbase; /* some free space to mess with */
u_long marks[MARK_MAX]; /* loader mark pointers */
u_long kernel_physical_start; /* where does it get relocated */
u_long kernel_free_vm_start; /* where does the free VM start */
/* some free space to mess with */
u_long scratch_virtualbase, scratch_physicalbase;
/* bootprogram identifiers */
@ -139,7 +144,8 @@ void create_configuration(int argc, char **argv, int start_args);
void prepare_and_check_relocation_system(void);
void twirl(void);
int vdu_var(int);
void process_args(int argc, char **argv, int *howto, char *file, int *start_args);
void process_args(int argc, char **argv, int *howto, char *file,
int *start_args);
char *sprint0(int width, char prefix, char base, int value);
struct page_info *get_relocated_page(u_long destination, int size);
@ -161,7 +167,8 @@ void init_datastructures(void) {
/* reserve some space for heap etc... 512 might be bigish though */
memory_image_size = (int) HIMEM - 512*1024;
if (memory_image_size <= 256*1024) panic("I need more memory to boot up; increase Wimp slot");
if (memory_image_size <= 256*1024)
panic("I need more memory to boot up; increase Wimp slot");
memory_image = alloc(memory_image_size);
if (!memory_image) panic("Can't alloc get my memory image ?");
@ -172,20 +179,28 @@ void init_datastructures(void) {
lastpage = ((int) top_memory / nbpp) - 1;
totalpages = lastpage - firstpage;
printf("Got %ld memory pages each %d kilobytes to mess with.\n\n", totalpages, nbpp>>10);
printf("Got %ld memory pages each %d kilobytes to mess with.\n\n",
totalpages, nbpp>>10);
/* allocate some space for the relocation table */
reloc_tablesize = (MAX_RELOCPAGES+1)*3*sizeof(u_long); /* 3 entry table */
/* 3 entry table */
reloc_tablesize = (MAX_RELOCPAGES+1)*3*sizeof(u_long);
reloc_instruction_table = alloc(reloc_tablesize);
if (!reloc_instruction_table) panic("Can't alloc my relocate instructions pages");
if (!reloc_instruction_table)
panic("Can't alloc my relocate instructions pages");
/* set up relocation table. First word gives number of relocations to be done */
/*
* set up relocation table. First word gives number of
* relocations to be done
*/
reloc_entries = 0;
reloc_pos = reloc_instruction_table;
*reloc_pos++ = 0;
/* set up the memory translation info structure; alloc one more for *
* end of list marker; see get_memory_map */
/*
* set up the memory translation info structure; alloc one
* more for end of list marker; see get_memory_map
*/
mem_pages_info = alloc((totalpages + 1)*sizeof(struct page_info));
if (!mem_pages_info) panic("Can't alloc my phys->virt page info");
@ -193,7 +208,7 @@ void init_datastructures(void) {
memory_page_types = alloc(memory_table_size);
if (!memory_page_types) panic("Can't alloc my memory page type block");
initial_page_tables = alloc(16*1024); /* size is 16 kb per definition */
initial_page_tables = alloc(16*1024);/* size is 16 kb per definition */
if (!initial_page_tables) panic("Can't alloc my initial page tables");
}
@ -207,8 +222,13 @@ void prepare_and_check_relocation_system(void) {
/* set the number of relocation entries in the 1st word */
*reloc_instruction_table = reloc_entries;
/* the relocate information needs to be in one sequential physical space */
relocate_size = (reloc_tablesize + nbpp-1) & ~(nbpp-1); /* round space up */
/*
* the relocate information needs to be in one sequential
* physical space
*/
/* round space up */
relocate_size = (reloc_tablesize + nbpp-1) & ~(nbpp-1);
printf("\nPreparing for booting %s ... ", booted_file);
relocate_pages = relocate_size / nbpp;
@ -221,11 +241,16 @@ void prepare_and_check_relocation_system(void) {
if (pages < relocate_pages-1) {
/* check if next page is sequential physically */
if ((relocate_table_pages+pages+1)->physical - (relocate_table_pages+pages)->physical != nbpp) {
/* Ieee! non contigunous relocate area -> try again */
if ((relocate_table_pages+pages+1)->physical -
(relocate_table_pages+pages)->physical != nbpp) {
/*
* Ieee! non contigunous relocate area
* -> try again
*/
printf("*");
relocate_table_pages += pages;
pages = -1; /* will be incremented till zero later */
/* will be incremented till zero later */
pages = -1;
};
};
pages++;
@ -252,7 +277,9 @@ void prepare_and_check_relocation_system(void) {
length = reloc_entry[2];
/* paranoia check */
if ((long) (src - last_src) <= 0) printf("relocation sequence challenged -- booting might fail ");
if ((long) (src - last_src) <= 0)
printf("relocation sequence challenged -- "
"booting might fail ");
last_src = src;
/* check if its gonna be relocated into (PO)DRAM ! */
@ -260,21 +287,24 @@ void prepare_and_check_relocation_system(void) {
found = 0;
for (bank = 0; (bank < dram_blocks) && !found; bank++) {
base = DRAM_addr[bank];
found = (destination >= base) && (extend <= base + DRAM_pages[bank]*nbpp);
found = (destination >= base) &&
(extend <= base + DRAM_pages[bank]*nbpp);
};
for (bank = 0; (bank < podram_blocks) && !found; bank++) {
base = PODRAM_addr[bank];
found = (destination >= base) && (extend <= base + PODRAM_pages[bank]*nbpp);
found = (destination >= base) &&
(extend <= base + PODRAM_pages[bank]*nbpp);
};
if (!found || (extend > top_physdram)) {
panic( "Internal error: relocating range [%lx +%lx => %lx] outside (PO)DRAM banks!",
src, length, destination
);
panic( "Internal error: relocating range "
"[%lx +%lx => %lx] outside (PO)DRAM banks!",
src, length, destination);
};
reloc_entry+=3;
};
if (reloc_entry != reloc_pos) panic("Relocation instruction table is corrupted");
if (reloc_entry != reloc_pos)
panic("Relocation instruction table is corrupted");
printf("OK!\n");
}
@ -290,7 +320,8 @@ void get_memory_configuration(void) {
osmemory_read_arrangement_table(memory_page_types);
/* init counters */
bank = vram_blocks = dram_blocks = rom_blocks = io_blocks = podram_blocks = 0;
bank = vram_blocks = dram_blocks = rom_blocks = io_blocks = 0;
podram_blocks = 0;
current_page_type = -1;
phys_page = 0; /* physical address in pages */
@ -299,36 +330,45 @@ void get_memory_configuration(void) {
/* iterating over a packed array of 2 page types/byte i.e. 8 kb/byte */
while (loop < 2*memory_table_size) {
page = (memory_page_types[loop / 2]); /* read twice */
if (loop & 1) page >>= 4; /* take other nibble */
page = (memory_page_types[loop / 2]); /* read twice */
if (loop & 1) page >>= 4; /* take other nibble */
/* bits 0-2 give type, bit3 means the bit page is allocatable */
page &= 0x7; /* only take bottom 3 bits */
/* bits 0-2 give type, bit3 means the bit page is allocatable*/
page &= 0x7; /* only take bottom 3 bits */
if (page != current_page_type) {
/* passed a boundary ... note this block */
/* splitting in different vars is for compatability reasons*/
/*
* passed a boundary ... note this block
* splitting in different vars is for
* compatability reasons
*/
switch (current_page_type) {
case -1 :
case 0 :
break;
case osmemory_TYPE_DRAM :
if (phys_page < PODRAM_START) {
DRAM_addr[dram_blocks] = phys_page * nbpp;
DRAM_pages[dram_blocks] = page_count;
DRAM_addr[dram_blocks] =
phys_page * nbpp;
DRAM_pages[dram_blocks] =
page_count;
dram_blocks++;
} else {
PODRAM_addr[podram_blocks] = phys_page * nbpp;
PODRAM_pages[podram_blocks] = page_count;
PODRAM_addr[podram_blocks] =
phys_page * nbpp;
PODRAM_pages[podram_blocks] =
page_count;
podram_blocks++;
};
break;
case osmemory_TYPE_VRAM :
VRAM_addr[vram_blocks] = phys_page * nbpp;
VRAM_addr[vram_blocks] =
phys_page * nbpp;
VRAM_pages[vram_blocks] = page_count;
vram_blocks++;
break;
case osmemory_TYPE_ROM :
ROM_addr[rom_blocks] = phys_page * nbpp;
ROM_addr[rom_blocks] =
phys_page * nbpp;
ROM_pages[rom_blocks] = page_count;
rom_blocks++;
break;
@ -338,16 +378,25 @@ void get_memory_configuration(void) {
io_blocks++;
break;
default :
printf("WARNING : found unknown memory object %d ", current_page_type);
printf(" at 0x%s", sprint0(8,'0','x', phys_page * nbpp));
printf(" for %s k\n", sprint0(5,' ','d', (page_count*nbpp)>>10));
printf("WARNING : found unknown "
"memory object %d ",
current_page_type);
printf(" at 0x%s",
sprint0(8,'0','x',
phys_page * nbpp));
printf(" for %s k\n",
sprint0(5,' ','d',
(page_count*nbpp)>>10));
break;
};
current_page_type = page;
phys_page = loop;
page_count = 0;
};
/* smallest unit we recognise is one page ... silly could be upto 64 pages i.e. 256 kb */
/*
* smallest unit we recognise is one page ... silly
* could be upto 64 pages i.e. 256 kb
*/
page_count += 1;
loop += 1;
if ((loop & 31) == 0) twirl();
@ -357,20 +406,22 @@ void get_memory_configuration(void) {
if (VRAM_pages[0] == 0) {
/* map DRAM as video memory */
display_size = (vdu_var(os_VDUVAR_TOTAL_SCREEN_SIZE) & ~(nbpp-1));
display_size =
(vdu_var(os_VDUVAR_TOTAL_SCREEN_SIZE) & ~(nbpp-1));
#if 0
mapped_screen_memory = 1024 * 1024; /* max allowed on RiscPC */
mapped_screen_memory = 1024 * 1024; /* max allowed on RiscPC */
videomem_pages = (mapped_screen_memory / nbpp);
videomem_start = DRAM_addr[0];
DRAM_addr[0] += videomem_pages * nbpp;
DRAM_pages[0] -= videomem_pages;
#else
mapped_screen_memory = display_size;
bank = dram_blocks-1; /* pick last SIMM */
bank = dram_blocks-1; /* pick last SIMM */
videomem_pages = (mapped_screen_memory / nbpp);
/* Map video memory at the end of the SIMM */
videomem_start = DRAM_addr[bank] + (DRAM_pages[bank] - videomem_pages)*nbpp;
videomem_start =
DRAM_addr[bank] + (DRAM_pages[bank] - videomem_pages)*nbpp;
DRAM_pages[bank]-= videomem_pages;
#endif
} else {
@ -383,17 +434,24 @@ void get_memory_configuration(void) {
if (mapped_screen_memory) {
printf("Used %d kb DRAM ", (mapped_screen_memory)/1024);
printf("at 0x%s for video memory\n", sprint0(8,'0','x', videomem_start));
printf("at 0x%s for video memory\n",
sprint0(8,'0','x', videomem_start));
};
/* find top of DRAM pages */
top_physdram = 0;
for (loop = podram_blocks-1; (loop >= 0) && (PODRAM_addr[loop] == 0); loop++);
if (loop >= 0) top_physdram = PODRAM_addr[loop] + PODRAM_pages[loop]*nbpp;
for (loop = podram_blocks-1;
(loop >= 0) && (PODRAM_addr[loop] == 0);
loop++);
if (loop >= 0)
top_physdram = PODRAM_addr[loop] + PODRAM_pages[loop]*nbpp;
if (top_physdram == 0) {
for (loop = dram_blocks-1; (loop >= 0) && (DRAM_addr[loop] == 0); loop++);
if (loop >= 0) top_physdram = DRAM_addr[loop] + DRAM_pages[loop]*nbpp;
for (loop = dram_blocks-1;
(loop >= 0) && (DRAM_addr[loop] == 0);
loop++);
if (loop >= 0)
top_physdram = DRAM_addr[loop] + DRAM_pages[loop]*nbpp;
};
if (top_physdram == 0) panic("reality check: No DRAM in this machine?");
@ -404,13 +462,15 @@ void get_memory_configuration(void) {
for (count = 0; count < rom_blocks; count++) {
printf("Found ROM (%d)", count);
printf(" at 0x%s", sprint0(8,'0','x', ROM_addr[count]));
printf(" for %s k\n", sprint0(5,' ','d', (ROM_pages[count]*nbpp)>>10));
printf(" for %s k\n",
sprint0(5,' ','d', (ROM_pages[count]*nbpp)>>10));
};
for (count = 0; count < io_blocks; count++) {
printf("Found I/O (%d)", count);
printf(" at 0x%s", sprint0(8,'0','x', IO_addr[count]));
printf(" for %s k\n", sprint0(5,' ','d', (IO_pages[count]*nbpp)>>10));
printf(" for %s k\n",
sprint0(5,' ','d', (IO_pages[count]*nbpp)>>10));
};
/* for DRAM/VRAM also count the number of pages */
@ -419,7 +479,8 @@ void get_memory_configuration(void) {
total_dram_pages += DRAM_pages[count];
printf("Found DRAM (%d)", count);
printf(" at 0x%s", sprint0(8,'0','x', DRAM_addr[count]));
printf(" for %s k\n", sprint0(5,' ','d', (DRAM_pages[count]*nbpp)>>10));
printf(" for %s k\n",
sprint0(5,' ','d', (DRAM_pages[count]*nbpp)>>10));
};
total_vram_pages = 0;
@ -427,7 +488,8 @@ void get_memory_configuration(void) {
total_vram_pages += VRAM_pages[count];
printf("Found VRAM (%d)", count);
printf(" at 0x%s", sprint0(8,'0','x', VRAM_addr[count]));
printf(" for %s k\n", sprint0(5,' ','d', (VRAM_pages[count]*nbpp)>>10));
printf(" for %s k\n",
sprint0(5,' ','d', (VRAM_pages[count]*nbpp)>>10));
};
total_podram_pages = 0;
@ -435,7 +497,8 @@ void get_memory_configuration(void) {
total_podram_pages += PODRAM_pages[count];
printf("Found Processor only (S)DRAM (%d)", count);
printf(" at 0x%s", sprint0(8,'0','x', PODRAM_addr[count]));
printf(" for %s k\n", sprint0(5,' ','d', (PODRAM_pages[count]*nbpp)>>10));
printf(" for %s k\n",
sprint0(5,' ','d', (PODRAM_pages[count]*nbpp)>>10));
};
}
@ -446,7 +509,9 @@ void get_memory_map(void) {
int phys_addr;
printf("\nGetting actual memorymapping");
for (page = 0, page_info = mem_pages_info; page < totalpages; page++, page_info++) {
for (page = 0, page_info = mem_pages_info;
page < totalpages;
page++, page_info++) {
page_info->pagenumber = 0; /* not used */
page_info->logical = (firstpage + page) * nbpp;
page_info->physical = 0; /* result comes here */
@ -456,14 +521,18 @@ void get_memory_map(void) {
/* close list */
page_info->pagenumber = -1;
inout = osmemory_GIVEN_LOG_ADDR | osmemory_RETURN_PAGE_NO | osmemory_RETURN_PHYS_ADDR;
inout = osmemory_GIVEN_LOG_ADDR | osmemory_RETURN_PAGE_NO |
osmemory_RETURN_PHYS_ADDR;
osmemory_page_op(inout, mem_pages_info, totalpages);
printf(" ; sorting ");
sort_memory_map();
printf(".\n");
/* get the first DRAM index and show the physical memory fragments we got */
/*
* get the first DRAM index and show the physical memory
* fragments we got
*/
printf("\nFound physical memory blocks :\n");
first_mapped_DRAM_page_index = -1;
first_mapped_PODRAM_page_index = -1;
@ -471,10 +540,12 @@ void get_memory_map(void) {
phys_addr = mem_pages_info[page].physical;
printf("[0x%x", phys_addr);
while (mem_pages_info[page+1].physical - phys_addr == nbpp) {
if ((first_mapped_DRAM_page_index<0) && (phys_addr >= DRAM_addr[0])) {
if ((first_mapped_DRAM_page_index<0) &&
(phys_addr >= DRAM_addr[0])) {
first_mapped_DRAM_page_index = page;
};
if ((first_mapped_PODRAM_page_index<0) && (phys_addr >= PODRAM_addr[0])) {
if ((first_mapped_PODRAM_page_index<0) &&
(phys_addr >= PODRAM_addr[0])) {
first_mapped_PODRAM_page_index = page;
};
page++;
@ -484,9 +555,13 @@ void get_memory_map(void) {
};
printf("\n\n");
if (first_mapped_PODRAM_page_index < 0) {
if (PODRAM_addr[0]) panic("Found no (S)DRAM mapped in the bootloader ... increase Wimpslot!");
if (PODRAM_addr[0])
panic("Found no (S)DRAM mapped in the bootloader ... "
"increase Wimpslot!");
};
if (first_mapped_DRAM_page_index < 0) panic("No DRAM mapped in the bootloader ... increase Wimpslot!");
if (first_mapped_DRAM_page_index < 0)
panic("No DRAM mapped in the bootloader ... "
"increase Wimpslot!");
}
@ -494,21 +569,23 @@ void create_initial_page_tables(void) {
u_long page, section, addr, kpage;
/* mark a section by the following bits and domain 0, AP=01, CB=0 */
/* A P C B section domain */
section = (0<<11) | (1<<10) | (0<<3) | (0<<2) | (1<<4) | (1<<1) | (0) | (0 << 5);
/* A P C B section */
section = (0<<11) | (1<<10) | (0<<3) | (0<<2) | (1<<4) | (1<<1) | (0) |
/* domain */
(0 << 5);
/* first of all a full 1:1 mapping */
for (page = 0; page < 4*1024; page++) {
initial_page_tables[page] = (page<<20) | section;
};
/* video memory is mapped 1:1 in the DRAM section or in VRAM section */
/* video memory is mapped 1:1 in the DRAM section or in VRAM section */
/* map 1Mb from top of memory to bottom 1Mb of virtual memmap */
/* map 1Mb from top of memory to bottom 1Mb of virtual memmap */
top_1Mb_dram = (((top_physdram - 1024*1024) >> 20) << 20);
initial_page_tables[0] = top_1Mb_dram | section;
/* map 16 Mb of kernel space to KERNEL_BASE i.e. marks[KERNEL_START] */
/* map 16 Mb of kernel space to KERNEL_BASE i.e. marks[KERNEL_START] */
for (page = 0; page < 16; page++) {
addr = (kernel_physical_start >> 20) + page;
kpage = (marks[MARK_START] >> 20) + page;
@ -521,15 +598,19 @@ void add_pagetables_at_top(void) {
int page;
u_long src, dst, fragaddr;
/* Special : destination must be on a 16 Kb boundary */
/* get 4 pages on the top of the physical memory and copy PT's in it */
/* Special : destination must be on a 16 Kb boundary */
/* get 4 pages on the top of the physical memory and copy PT's in it */
new_L1_pages_phys = top_physdram - 4*nbpp;
/* If the L1 page tables are not 16 kb aligned, adjust base until it is */
/*
* If the L1 page tables are not 16 kb aligned, adjust base
* until it is
*/
while (new_L1_pages_phys & (16*1024-1)) {
new_L1_pages_phys -= nbpp;
};
if (new_L1_pages_phys & (16*1024-1)) panic("Paranoia : L1 pages not on 16Kb boundary");
if (new_L1_pages_phys & (16*1024-1))
panic("Paranoia : L1 pages not on 16Kb boundary");
dst = new_L1_pages_phys;
src = (u_long) initial_page_tables;
@ -570,7 +651,8 @@ void create_configuration(int argc, char **argv, int start_args) {
/* get some miscelanious info for the bootblock */
os_readsysinfo_monitor_info(NULL, &monitor_type, &monitor_sync);
os_readsysinfo_chip_presence(&ioeb_flags, &superio_flags, &lcd_flags);
os_readsysinfo_superio_features(&superio_flags_basic, &superio_flags_extra);
os_readsysinfo_superio_features(&superio_flags_basic,
&superio_flags_extra);
os_readsysinfo_unique_id(&id_low, &id_high);
/* fill in the bootconfig *bconfig structure : generic version II */
@ -579,10 +661,15 @@ void create_configuration(int argc, char **argv, int start_args) {
bconfig->version = BOOTCONFIG_VERSION;
strcpy(bconfig->kernelname, booted_file);
/* get the kernel base name and update the RiscOS name to a Unix name */
/*
* get the kernel base name and update the RiscOS name to a
* Unix name
*/
i = strlen(bconfig->kernelname);
while ((i >= 0) && (bconfig->kernelname[i] != '.')) i--;
if (i) memcpy(bconfig->kernelname, bconfig->kernelname+i+1, strlen(booted_file)-i);
if (i)
memcpy(bconfig->kernelname, bconfig->kernelname+i+1,
strlen(booted_file)-i);
pos = bconfig->kernelname;
while (*pos) {
@ -608,7 +695,7 @@ void create_configuration(int argc, char **argv, int start_args) {
/* mark kernel pointers */
bconfig->kernvirtualbase = marks[MARK_START];
bconfig->kernphysicalbase = kernel_physical_start;
bconfig->kernsize = kernel_free_vm_start - marks[MARK_START];
bconfig->kernsize = kernel_free_vm_start - marks[MARK_START];
bconfig->ksym_start = marks[MARK_SYM];
bconfig->ksym_end = marks[MARK_SYM] + marks[MARK_NSYM];
@ -619,13 +706,16 @@ void create_configuration(int argc, char **argv, int start_args) {
bconfig->width = vdu_var(os_MODEVAR_XWIND_LIMIT);
bconfig->height = vdu_var(os_MODEVAR_YWIND_LIMIT);
bconfig->log2_bpp = vdu_var(os_MODEVAR_LOG2_BPP);
bconfig->framerate = 56; /* XXX why? better guessing possible? XXX */
/* XXX why? better guessing possible? XXX */
bconfig->framerate = 56;
/* fill in memory info */
bconfig->pagesize = nbpp;
bconfig->drampages = total_dram_pages + total_podram_pages; /* XXX */
/* XXX */
bconfig->drampages = total_dram_pages + total_podram_pages;
bconfig->vrampages = total_vram_pages;
bconfig->dramblocks = dram_blocks + podram_blocks; /* XXX */
/* XXX */
bconfig->dramblocks = dram_blocks + podram_blocks;
bconfig->vramblocks = vram_blocks;
for (i = 0; i < dram_blocks; i++) {
@ -663,12 +753,17 @@ int main(int argc, char **argv) {
get_memory_configuration();
get_memory_map();
/* point to the first free DRAM page guaranteed to be in strict order up */
/*
* point to the first free DRAM page guaranteed to be in
* strict order up
*/
if (first_mapped_PODRAM_page_index) {
free_relocation_page = mem_pages_info + first_mapped_PODRAM_page_index;
free_relocation_page =
mem_pages_info + first_mapped_PODRAM_page_index;
kernel_physical_start = PODRAM_addr[0];
} else {
free_relocation_page = mem_pages_info + first_mapped_DRAM_page_index;
free_relocation_page =
mem_pages_info + first_mapped_DRAM_page_index;
kernel_physical_start = DRAM_addr[0];
};
@ -676,12 +771,16 @@ int main(int argc, char **argv) {
/* first count the kernel to get the markers */
ret = loadfile(booted_file, marks, COUNT_KERNEL);
if (ret == -1) panic("Kernel load failed"); /* lie to the user ... */
if (ret == -1) panic("Kernel load failed"); /* lie to the user ... */
close(ret);
/* calculate how much the difference is between physical and virtual space for the kernel */
/*
* calculate how much the difference is between physical and
* virtual space for the kernel
*/
pv_offset = ((u_long) marks[MARK_START] - kernel_physical_start);
kernel_free_vm_start = (marks[MARK_END] + nbpp-1) & ~(nbpp-1); /* round on a page */
/* round on a page */
kernel_free_vm_start = (marks[MARK_END] + nbpp-1) & ~(nbpp-1);
/* we seem to be forced to clear the marks() ? */
bzero(marks, sizeof(marks[MARK_MAX]));
@ -697,11 +796,15 @@ int main(int argc, char **argv) {
add_pagetables_at_top();
create_configuration(argc, argv, start_args);
/* done relocating and creating information, now update and check the relocation mechanism */
/*
* done relocating and creating information, now update and
* check the relocation mechanism
*/
prepare_and_check_relocation_system();
printf("\nStarting at 0x%lx\n", marks[MARK_ENTRY]);
printf("Will boot in a few secs due to relocation....\nbye bye from RISC OS!");
printf("Will boot in a few secs due to relocation....\n"
"bye bye from RISC OS!");
/* dismount all filesystems */
xosfscontrol_shutdown();
@ -711,9 +814,11 @@ int main(int argc, char **argv) {
start_kernel(
/* r0 relocation code page (V) */ relocate_code_page->logical,
/* r1 relocation pv offset */ relocate_code_page->physical-relocate_code_page->logical,
/* r1 relocation pv offset */
relocate_code_page->physical-relocate_code_page->logical,
/* r2 configuration structure */ bconfig_new_phys,
/* r3 relocation table (P) */ relocate_table_pages->physical, /* one piece! */
/* r3 relocation table (P) */
relocate_table_pages->physical, /* one piece! */
/* r4 L1 page descriptor (P) */ new_L1_pages_phys,
/* r5 kernel entry point */ marks[MARK_ENTRY]
);
@ -729,19 +834,22 @@ ssize_t boot32_read(int f, void *addr, size_t size) {
/* printf("read at %p for %ld bytes\n", addr, size); */
total = 0;
while (size > 0) {
fragsize = nbpp; /* select one page */
if (size < nbpp) fragsize = size; /* clip to size left */
fragsize = nbpp; /* select one page */
if (size < nbpp) fragsize = size;/* clip to size left */
/* get a page for a fragment */
fragaddr = (caddr_t) get_relocated_page((u_long) addr - pv_offset, fragsize)->logical;
fragaddr =
(caddr_t)get_relocated_page((u_long) addr - pv_offset,
fragsize)->logical;
bytes_read = read(f, fragaddr, fragsize);
if (bytes_read < 0) return bytes_read; /* error! */
total += bytes_read; /* account read bytes */
if (bytes_read < 0) return bytes_read; /* error! */
total += bytes_read; /* account read bytes*/
if (bytes_read < fragsize) return total; /* does this happen? */
/* does this happen? */
if (bytes_read < fragsize) return total;
size -= fragsize; /* advance */
size -= fragsize; /* advance */
addr += fragsize;
};
return total;
@ -754,14 +862,16 @@ void *boot32_memcpy(void *dst, const void *src, size_t size) {
/* printf("memcpy to %p from %p for %ld bytes\n", dst, src, size); */
while (size > 0) {
fragsize = nbpp; /* select one page */
if (size < nbpp) fragsize = size; /* clip to size left */
fragsize = nbpp; /* select one page */
if (size < nbpp) fragsize = size;/* clip to size left */
/* get a page for a fragment */
fragaddr = (caddr_t) get_relocated_page((u_long) dst - pv_offset, fragsize)->logical;
fragaddr =
(caddr_t) get_relocated_page((u_long) dst - pv_offset,
fragsize)->logical;
memcpy(fragaddr, src, size);
src += fragsize; /* account copy */
src += fragsize; /* account copy */
dst += fragsize;
size-= fragsize;
};
@ -775,14 +885,16 @@ void *boot32_memset(void *dst, int c, size_t size) {
/* printf("memset %p for %ld bytes with %d\n", dst, size, c); */
while (size > 0) {
fragsize = nbpp; /* select one page */
if (size < nbpp) fragsize = size; /* clip to size left */
fragsize = nbpp; /* select one page */
if (size < nbpp) fragsize = size;/* clip to size left */
/* get a page for a fragment */
fragaddr = (caddr_t) get_relocated_page((u_long) dst - pv_offset, fragsize)->logical;
fragaddr =
(caddr_t) get_relocated_page((u_long) dst - pv_offset,
fragsize)->logical;
memset(fragaddr, c, fragsize);
dst += fragsize; /* account memsetting */
dst += fragsize; /* account memsetting */
size-= fragsize;
};
@ -796,12 +908,19 @@ void sort_memory_map(void) {
struct page_info *out_page, *in_page, temp_page;
count = 0;
for (out = 0, out_page = mem_pages_info; out < totalpages; out++, out_page++) {
for (in = out+1, in_page = out_page+1; in < totalpages; in++, in_page++) {
for (out = 0, out_page = mem_pages_info;
out < totalpages;
out++, out_page++) {
for (in = out+1, in_page = out_page+1;
in < totalpages;
in++, in_page++) {
if (in_page->physical < out_page->physical) {
memcpy(&temp_page, in_page, sizeof(struct page_info));
memcpy(in_page, out_page, sizeof(struct page_info));
memcpy(out_page, &temp_page, sizeof(struct page_info));
memcpy(&temp_page, in_page,
sizeof(struct page_info));
memcpy(in_page, out_page,
sizeof(struct page_info));
memcpy(out_page, &temp_page,
sizeof(struct page_info));
};
count++;
if ((count & 0x3ffff) == 0) twirl();
@ -815,9 +934,11 @@ struct page_info *get_relocated_page(u_long destination, int size) {
/* get a page for a fragment */
page = free_relocation_page;
if (free_relocation_page->pagenumber < 0) panic("\n\nOut of pages; increase Wimpslot and try again");
if (free_relocation_page->pagenumber < 0)
panic("\n\nOut of pages; increase Wimpslot and try again");
reloc_entries++;
if (reloc_entries >= MAX_RELOCPAGES) panic("\n\nToo many relocations! What are you loading ??");
if (reloc_entries >= MAX_RELOCPAGES)
panic("\n\nToo many relocations! What are you loading ??");
/* record the relocation */
*reloc_pos++ = free_relocation_page->physical;
@ -846,7 +967,8 @@ void twirl(void) {
}
void process_args(int argc, char **argv, int *howto, char *file, int *start_args) {
void process_args(int argc, char **argv, int *howto, char *file,
int *start_args) {
int i, j;
static char filename[80];