Is memory space above RTEMS workspace free to use?

Ian Jiang ianjiang.cn at gmail.com
Thu Dec 6 03:34:20 UTC 2007


After reading the related codes
rtems-4.7.1/c/src/lib/libbsp/i386/pc386/vi startup/linkcmds
rtems-4.7.1/c/src/lib/libbsp/i386/pc386/vi startup/bspstart.c
rtems-4.7.1/cpukit/score/src/wkspace.c
rtems-4.7.1/cpukit/sapi/src/exinit.c
especially the functions bsp_start_default(), bsp_pretasking_hook(),
_Workspace_Handler_initialization() and
rtems_initialize_executive_early(), I found that most of the memory
space above the RTEMS space is used as a heap and it is not free to
directly use.

Now, in my opinion, to get a piece of memory space which would not be
used by RTEMS but could be managed by myself, I might allocate it
statically from the data section, or dynamically from the heap. A
piece of codes was used to demonstrate this.
It was built under RTEMS-4.7.1 ARCH i386 BSP pc386  and ran well on a
VMware virtual box with 32MB memory.

#include <bsp.h>

#include <stdlib.h>
#include <stdio.h>

#include <rtems/libcsupport.h>
#include <errno.h>
#include <string.h>

extern char *_text_start;
extern char *_data_start;
extern char *_bss_start;
extern char *_end;

extern uint32_t _stack_size;
extern uint32_t _heap_size;


extern rtems_configuration_table BSP_Configuration;
extern uint32_t rtemsFreeMemStart;

#define SERIAL_PORT_PATH_NAME "/dev/ttyS1"


#define STATIC_BUF_LEN (1024*1024)
unsigned char static_buf[STATIC_BUF_LEN] = "STATIC-BUFFER-MARK";

rtems_task Init(rtems_task_argument ignored)
{
        void *buf_start = NULL;
        uint32_t buf_len = 0;

        uint32_t system_data_len = 0;


        /* Initial statistic */
        printk("== Initial Statistic ==\n");
        printk("Section start: .text = %lu, .data = %lu, .bss = %lu,
.end = %lu\n",
                        &_text_start, &_data_start, &_bss_start, &_end);
        printk("\t\tsize: .text = %lu, .data = %lu, .bss = %lu\n",
                        ((unsigned int)(&_data_start) - (unsigned
int)(&_text_start)),
                        ((unsigned int)(&_bss_start) - (unsigned
int)(&_data_start)),
                        ((unsigned int)(&_end) - (unsigned int)(&_bss_start)));
        printk("_heap_size = %u, ", _heap_size);
        printk("_stack_size = %u\n", _stack_size);
        printk("work_space: start = %u, ", BSP_Configuration.work_space_start);
        printk("end = %u, ", BSP_Configuration.work_space_start
                        + BSP_Configuration.work_space_size - 1);
        printk("size = %u\n", BSP_Configuration.work_space_size);
        printk("FreeMemStart = %u\n", rtemsFreeMemStart);
        system_data_len = BSP_Configuration.work_space_start
                        + BSP_Configuration.work_space_size
                        - (uint32_t)(&_data_start);
        printk("system data len = %u\n", system_data_len);
        printk("staic buffer start %u, size %u\n", static_buf, STATIC_BUF_LEN);
        printk("Free dynamic memory: %lu Bytes\n", (unsigned long)
malloc_free_space());

        /* Allocate a small segment of memory, give its info., then free */
        printk("== Allocate a small segment of memory ==\n");
        buf_len = 64;
        buf_start = malloc(buf_len);
        if (buf_start == NULL) {
                printk("Allocate memory of length %u failed.\n", buf_len);
                return;
        }
        printk("new buffer: start = %lu, len = %u\n", buf_start, buf_len);
        printk("Free dynamic memory: %lu Bytes\n", (unsigned long)
malloc_free_space());
        free(buf_start);

        /* Allocate a segment of memory with length of system_data_len, give its
         * info., then free */
        printk("== Allocate a segment of memory for system data ==\n");
        buf_len = system_data_len;
        buf_start = malloc(buf_len);
        if (buf_start == NULL) {
                printk("Allocate memory of length %u failed.\n", buf_len);
                return;
        }
        printk("new buffer: start = %lu, len = %u\n", buf_start, buf_len);
        printk("Free dynamic memory: %lu Bytes\n", (unsigned long)
malloc_free_space());
        free(buf_start);
}

/* configuration information */

#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_MAXIMUM_TASKS 2

#define CONFIGURE_INIT

#include <rtems/confdefs.h>

/* end of file */




On Dec 4, 2007 10:09 PM, Ian Jiang <ianjiang.cn at gmail.com> wrote:
>         In order to save some system status to a hard disk, I want to transmit the content between the start of the data section and the end of the RTEMS workspace in the memory space to a disk file, using the memory space above the RTEMS workspace. However, writting to the disk file failed. (In fact, it was failed to open the file.)
>


-- 
Ian Jiang



More information about the users mailing list