/kernel/trunk/arch/ppc32/src/mm/frame.c |
---|
27,7 → 27,6 |
*/ |
#include <arch/mm/frame.h> |
#include <arch/mm/memory_init.h> |
#include <mm/frame.h> |
#include <config.h> |
#include <panic.h> |
34,7 → 33,9 |
void frame_arch_init(void) |
{ |
ppc_init_zones(); |
/* First is exception vector, second is 'implementation specific' */ |
/* First page is exception vector, |
* second is 'implementation specific', evade it too |
*/ |
zone_create(0, SIZE2FRAMES(config.memory_size), 2, 0); |
frame_mark_unavailable(0, 2); |
} |
/kernel/trunk/arch/ppc32/src/mm/memory_init.c |
---|
29,8 → 29,6 |
#include <arch/mm/memory_init.h> |
#include <genarch/ofw/ofw.h> |
#include <panic.h> |
#include <mm/frame.h> |
#include <align.h> |
#define MEMMAP_MAX_RECORDS 32 |
39,52 → 37,25 |
__u32 size; |
} memmap_t; |
static memmap_t memmap[MEMMAP_MAX_RECORDS]; |
size_t total_mem = 0; |
static void init_memmap(void) |
size_t get_memory_size(void) |
{ |
int i; |
phandle handle = ofw_find_device("/memory"); |
if (handle == -1) |
panic("No RAM\n"); |
memmap_t memmap[MEMMAP_MAX_RECORDS]; |
size_t ret = ofw_get_property(handle, "reg", &memmap, sizeof(memmap)); |
if (ret == -1) |
panic("Device /memory has no reg property\n"); |
size_t total = 0; |
int i; |
for (i = 0; i < MEMMAP_MAX_RECORDS; i++) { |
if (memmap[i].size == 0) |
break; |
total_mem += memmap[i].size; |
total += memmap[i].size; |
} |
} |
void preboot_read_config(void) |
{ |
init_memmap(); |
return total; |
} |
size_t get_memory_size(void) |
{ |
return total_mem; |
} |
void ppc_init_zones(void) |
{ |
int i; |
pfn_t confdata; |
for (i = 0; i < MEMMAP_MAX_RECORDS; i++) { |
if (memmap[i].size == 0) |
break; |
confdata = ADDR2PFN(memmap[i].start); |
if (confdata == 0) |
confdata = 2; |
zone_create(ADDR2PFN(memmap[i].start), |
SIZE2FRAMES(ALIGN_DOWN(memmap[i].size,PAGE_SIZE)), |
confdata, 0); |
} |
} |
/kernel/trunk/arch/ppc32/src/console.c |
---|
30,12 → 30,24 |
#include <genarch/ofw/ofw.h> |
#include <console/chardev.h> |
#include <console/console.h> |
#include <genarch/fb/fb.h> |
/** Print one character. |
* |
* @param ch Character to be printed. |
*/ |
static void ofw_ppc32_putchar(chardev_t *d, const char ch) |
{ |
ofw_putchar(ch); |
} |
static chardev_t ofw_ppc32_console; |
static chardev_operations_t ofw_ppc32_console_ops = { |
.write = ofw_ppc32_putchar |
}; |
/** Initialize console to use ofw output */ |
void ppc32_console_init(void) |
void ofw_ppc32_console_init(void) |
{ |
/* TODO: PCI detection etc. etc. - this is fine in PearPC for now */ |
fb_init(0x84000000,800,600,4); |
chardev_initialize("ofw_out", &ofw_ppc32_console, &ofw_ppc32_console_ops); |
stdout = &ofw_ppc32_console; |
} |
/kernel/trunk/arch/ppc32/src/ppc32.c |
---|
31,7 → 31,7 |
void arch_pre_mm_init(void) |
{ |
ppc32_console_init(); |
ofw_ppc32_console_init(); |
} |
void arch_post_mm_init(void) |
/kernel/trunk/arch/ppc32/src/start.S |
---|
27,71 → 27,16 |
# |
#include <arch/asm/macro.h> |
#include <arch/asm/spr.h> |
.section K_TEXT_START |
.global kernel_image_start |
.org 0x0 |
/* 256 bytes of some data */ |
/* exception table - must use 'ba' instructions for branches, |
* because it is elsewhere than the linker thinks |
*/ |
.space 4096 |
kernel_image_start: |
/* Initialize OFW, might be needed before relocate_kernel? */ |
lis r4, ofw@ha |
addi r4, r4, ofw@l |
stw r5, 0(r4) |
bl ofw_init |
bl preboot_read_config |
bl relocate_kernel |
__after_reloc: |
/* Set stack to some more meaningful value */ |
/* TODO: This is hardcoded for PearPC, must be changed later */ |
lis r1, 0x70 |
b main_bsp |
relocate_kernel: |
/* TODO: We _know_ that pearpc loads it to 8MB, and |
* but it should be really generic |
*/ |
lis r4, 0x80 /* r4 is where data was loaded - 8MB */ |
bl to_real_mode |
/* Now we are in real mode, copy first block and jump to it, |
* we are running in the loaded kernel now |
* We still have in r3 physical load kernel address |
*/ |
b __after_reloc /* We know in pearpc we are ok, so return, |
* otherwise we should relocate kernel |
* here |
*/ |
/* Turn off page translation |
* - assume that physical-loaded address is in r4 |
*/ |
to_real_mode: |
mflr r0 |
lis r5, ktext_start@ha // Expected start of kernel |
addi r5, r5, ktext_start@l |
add r0, r4, r0 |
sub r0, r0, r5 // r0 now contains physical return address |
mfmsr r3 |
andis. r3, r3, (~MSR_DR | MSR_IR) >> 16 |
mtspr SPRN_SRR0, r0 |
mtspr SPRN_SRR1, r3 |
sync // Really needed? RFI should do it as well? |
RFI |