OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [mm0/] [mm/] [bootm.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Boot memory allocator
3
 *
4
 * Copyright (C) 2009 Bahadir Balban
5
 */
6
#include <l4/macros.h>
7
#include <l4/config.h>
8
#include <l4/types.h>
9
#include <l4/lib/list.h>
10
#include <l4/lib/math.h>
11
#include <l4/api/thread.h>
12
#include <l4/api/kip.h>
13
#include <l4/api/errno.h>
14
#include INC_GLUE(memory.h)
15
 
16
#include <stdio.h>
17
 
18
/* All memory allocated here is discarded after boot */
19
 
20
#define BOOTMEM_SIZE            SZ_32K
21
 
22
SECTION(".init.bootmem") char bootmem[BOOTMEM_SIZE];
23
SECTION(".stack") char stack[4096];
24
// SECTION("init.data")
25
 
26
extern unsigned long __stack[];         /* Linker defined */
27
 
28
static unsigned long cursor = (unsigned long)&bootmem;
29
 
30
void *alloc_bootmem(int size, int alignment)
31
{
32
        void *ptr;
33
 
34
        /* If alignment is required */
35
        if (alignment) {
36
                /* And cursor is not aligned */
37
                if (!is_aligned(cursor, alignment))
38
                        /* Align the cursor to alignment */
39
                        cursor = align_up(cursor, alignment);
40
        /* Align to 4 byte by default */
41
        } else if (size >= 4) {
42
                /* And cursor is not aligned */
43
                if (!is_aligned(cursor, 4))
44
                        /* Align the cursor to alignment */
45
                        cursor = align_up(cursor, 4);
46
        }
47
 
48
        /* Allocate from cursor */
49
        ptr = (void *)cursor;
50
 
51
        /* Update cursor */
52
        cursor += size;
53
 
54
        /* Check if cursor is passed bootmem area */
55
        if (cursor >= (unsigned long)&bootmem[BOOTMEM_SIZE]) {
56
                printk("Fatal: Insufficient boot memory.\n");
57
                BUG();
58
        }
59
 
60
        return ptr;
61
}
62
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.