#15 Kernel size limit ('...not within region RAM' error)


I have built a mindstorms sensor that uses a
microcontroller to send a serial data stream into the
RCX, containing data packets with sensor readings. A
few lines of assembly and C source code had to be added
to dsensor.c to make this work. The kernel compiled
fine with gcc 2.95, but with version 3.01 the image
gets a few bytes larger, which seemed to be too big.
Compiling any of the demo applications resulted in a
linker error message '...not within region ram'.

I have tried to investigate the problem. It is caused
by the fixed addresses that application programs are
compiled for before they are made relocatable.
Makefile.common sets them to constant values:

BASE1 = 0xb000
BASE2 = 0xb210

This limits the kernel image size to 12KB:
0x8000+12KB=0xb000. If the image is only one byte
larger, it will intersect with the application's
address space. This setting also limits the maximum
size of applications: if a user program is a few bytes
too large to fit into this static frame, it is useless
to disable kernel features to free some memory: the
program would still not compile. It should be better to
set BASE1 and BASE2 based on the actual kernel size.
This seems to be easy to do: 'boot/brickOS.lds'
contains all needed values.

kern : o = 0x8000, l = 0x2eac

The first free address behind the kernel is
0x8000+0x2eac=0xaeac. Rounded up (just to be on the
save side) results in BASE1=0xAEB0 and
BASE2=BASE1+0x210=0xB0C0. I use some perl code inside
Makefile.user to calculate these values on the fly:

BASE1=$(shell perl -e 'while (<>) { if (/^ kern *: *o
*= *(0x[0-9a-f]*), *l *= * * (0x[0-9a-f]*)/i) {
$$o=eval($$1); $$l=eval($$2); $$b=$$o+$$l+0xf;
$$b-=$$b%16; $$b=0xb000 if ($$b<0x8000); printf
"0x%x\n", $$b
; } }' $(KERNEL).lds)
BASE2=$(shell perl -e 'while (<>) { if (/^ kern *: *o
*= *(0x[0-9a-f]*), *l *= * * (0x[0-9a-f]*)/i) {
$$o=eval($$1); $$l=eval($$2); $$b=$$o+$$l+0x21f;
$$b-=$$b%16; $$b=0xb210 if ($$b<0x8000); printf "0x%x\n", $
$b; } }' $(KERNEL).lds)

Another possibility is to generate a text file with
these values during the kernel compilation and to
include this file from Makefile.user.

I have attached a patch that implements the solution
with perl code inside Makefile.user.


  • Stephan Höhrmann

    Patch to calculate BASE1 and BASE2 during compile time

  • mesheets

    mesheets - 2011-11-15
    • status: open --> closed-fixed
  • mesheets

    mesheets - 2011-11-15

    Dynamic calculation of the values for BASE1 and BASE2 has been added to the Bibo Release 0.04-ms2 listed under the "Patches" section.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks