Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 563 → Rev 564

/kernel/trunk/generic/include/align.h
29,6 → 29,18
#ifndef __ALIGN_H__
#define __ALIGN_H__
 
#define ALIGN(s, a) ((s) % (a) ? (((s) / (a)) + 1) * (a) : (s))
/** Align to the nearest higher address.
*
* @param s Address or size to be aligned.
* @param a Size of alignment.
*/
#define ALIGN_UP(s, a) ((s) % (a) ? (((s) / (a)) + 1) * (a) : (s))
 
/** Align to the nearest lower address.
*
* @param s Address or size to be aligned.
* @param a Size of alignment.
*/
#define ALIGN_DOWN(s, a) ((s) & ~((a)-1))
 
#endif
/kernel/trunk/generic/include/mm/frame.h
45,7 → 45,9
#define ADDR2FRAME(zone, addr) (&((zone)->frames[((addr) - (zone)->base) / FRAME_SIZE]))
#define FRAME_INDEX(zone, frame) ((index_t)((frame) - (zone)->frames))
#define FRAME_INDEX_VALID(zone, index) (((index) >= 0) && ((index) < ((zone)->free_count + (zone)->busy_count)))
#define IS_BUDDY_LEFT_BLOCK(zone, frame) ((FRAME_INDEX((zone), (frame)) & ~(((__native) -1)<<((frame)->buddy_order + 1))) == 0)
#define IS_BUDDY_ORDER_OK(index, order) ((~(((__native) -1) << (order)) & (index)) == 0)
#define IS_BUDDY_LEFT_BLOCK(zone, frame) (((FRAME_INDEX((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
#define IS_BUDDY_RIGHT_BLOCK(zone, frame) (((FRAME_INDEX((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
 
#define ZONE_BLACKLIST_SIZE 3
 
/kernel/trunk/generic/src/main/main.c
141,7 → 141,7
config.memory_size = get_memory_size();
 
heap_size = CONFIG_HEAP_SIZE + (config.memory_size/FRAME_SIZE)*sizeof(frame_t);
kernel_size = ALIGN(hardcoded_ktext_size + hardcoded_kdata_size + heap_size, PAGE_SIZE);
kernel_size = ALIGN_UP(hardcoded_ktext_size + hardcoded_kdata_size + heap_size, PAGE_SIZE);
heap_delta = kernel_size - (hardcoded_ktext_size + hardcoded_kdata_size + heap_size);
config.kernel_size = kernel_size + CONFIG_STACK_SIZE;
/kernel/trunk/generic/src/mm/frame.c
1,5 → 1,6
/*
* Copyright (C) 2001-2004 Jakub Jermar
* Copyright (C) 2001-2005 Jakub Jermar
* Copyright (C) 2005 Sergey Bondari
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
225,11 → 226,11
index = zone_blacklist_count++;
 
/* Force base to the nearest lower address frame boundary. */
base &= ~(FRAME_SIZE - 1);
base = ALIGN_DOWN(base, FRAME_SIZE);
/* Align size to frame boundary. */
size = ALIGN(size, FRAME_SIZE);
size = ALIGN_UP(size, FRAME_SIZE);
 
ASSERT(zone_blacklist_count <= ZONE_BLACKLIST_SIZE);
ASSERT(index < ZONE_BLACKLIST_SIZE);
zone_blacklist[index].base = base;
zone_blacklist[index].size = size;
}
284,7 → 285,7
z = zone_create(base, size, 0);
 
if (!z) {
panic("Cannot allocate zone (%dB).\n", size);
panic("Cannot allocate zone (base=%P, size=%d).\n", base, size);
}
zone_attach(z);
393,18 → 394,19
link_t * zone_buddy_find_buddy(buddy_system_t *b, link_t * block) {
frame_t * frame;
zone_t * zone;
count_t index;
index_t index;
bool is_left, is_right;
 
frame = list_get_instance(block, frame_t, buddy_link);
zone = (zone_t *) b->data;
ASSERT(IS_BUDDY_ORDER_OK(FRAME_INDEX(zone, frame), frame->buddy_order));
is_left = IS_BUDDY_LEFT_BLOCK(zone, frame);
is_right = !is_left;
is_right = IS_BUDDY_RIGHT_BLOCK(zone, frame);
/*
* test left buddy
*/
ASSERT(is_left ^ is_right);
if (is_left) {
index = (FRAME_INDEX(zone, frame)) + (1 << frame->buddy_order);
} else if (is_right) {
430,8 → 432,10
*/
link_t * zone_buddy_bisect(buddy_system_t *b, link_t * block) {
frame_t * frame_l, * frame_r;
 
frame_l = list_get_instance(block, frame_t, buddy_link);
frame_r = (frame_l + (1 << (frame_l->buddy_order - 1)));
return &frame_r->buddy_link;
}
 
445,8 → 449,10
*/
link_t * zone_buddy_coalesce(buddy_system_t *b, link_t * block_1, link_t * block_2) {
frame_t * frame1, * frame2;
frame1 = list_get_instance(block_1, frame_t, buddy_link);
frame2 = list_get_instance(block_2, frame_t, buddy_link);
return frame1 < frame2 ? block_1 : block_2;
}