Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 853 → Rev 854

/kernel/branches/kolibri_pe/boot/init.asm
File deleted
/kernel/branches/kolibri_pe/boot/boot
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/kernel/branches/kolibri_pe/boot/boot.asm
12,6 → 12,11
include "../kglobals.inc"
include "../lang.inc"
 
CR0_PE equ 0x00000001 ;protected mode
CR0_WP equ 0x00010000 ;write protect
CR0_PG equ 0x80000000 ;paging
 
 
public _enter_bootscreen
public _leave_bootscreen
 
60,7 → 65,7
cli
 
mov eax, cr0
or eax, 0x80000001
or eax, CR0_PG+CR0_WP+CR0_PE
mov cr0, eax
 
jmp pword 0x08:__setvars
/kernel/branches/kolibri_pe/boot/start.asm
0,0 → 1,135
 
format MS COFF
 
include '../macros.inc'
 
$Revision: 849 $
 
include "../const.inc"
 
public __start
 
extrn _high_code
extrn __os_stack
extrn _boot_mbi
extrn _sys_pdbr
 
extrn _gdts
extrn __edata
 
section '.start' code readable align 16
 
use32
 
align 4
 
mboot:
dd 0x1BADB002
dd 0x00010003
dd -(0x1BADB002 + 0x00010003)
dd mboot
dd 0x100000
dd __edata; - OS_BASE
dd LAST_PAGE
dd __start
 
align 16
__start:
cld
 
mov esp, __os_stack +(0x100000000-OS_BASE)
push 0
popf
 
cmp eax, 0x2BADB002
mov ecx, sz_invboot
jne .fault
 
bt dword [ebx], 3
mov ecx, sz_nomods
jnc .fault
 
bt dword [ebx], 6
mov ecx, sz_nommap
jnc .fault
 
mov [_boot_mbi+(0x100000000-OS_BASE)], ebx
 
xor eax, eax
cpuid
cmp eax, 0
mov ecx, sz_nopse
jbe .fault
 
mov eax, 1
cpuid
bt edx, 3
mov ecx, sz_nopse
jnc .fault
 
; ENABLE PAGING
 
mov ecx, 32
mov edi, _sys_pdbr+(OS_BASE shr 20)+(0x100000000-OS_BASE)
mov eax, PG_LARGE+PG_SW
@@:
stosd
add eax, 4*1024*1024
loop @B
 
mov dword [_sys_pdbr+(0x100000000-OS_BASE)], PG_LARGE+PG_SW
mov dword [_sys_pdbr+(0x100000000-OS_BASE)+4], PG_LARGE+PG_SW+4*1024*1024
mov dword [_sys_pdbr+(0x100000000-OS_BASE)+(page_tabs shr 20)], _sys_pdbr+PG_SW+(0x100000000-OS_BASE)
 
mov ebx, cr4
or ebx, CR4_PSE
and ebx, not CR4_PAE
mov cr4, ebx
 
mov eax, _sys_pdbr+(0x100000000-OS_BASE)
mov ebx, cr0
or ebx,CR0_PG+CR0_WP
 
mov cr3, eax
mov cr0, ebx
 
mov ebx, [_boot_mbi+(0x100000000-OS_BASE)]
 
mov edx, [ebx+20]
mov esi, [ebx+24]
mov ecx, LAST_PAGE
test edx, edx
jz .no_mods
.scan_mod:
mov ecx, [esi+4]
add esi, 16
dec edx
jnz .scan_mod
 
.no_mods:
add ecx, 4095
and ecx, not 4095
 
lgdt [_gdts+(0x100000000-OS_BASE)]
jmp pword 0x08:_high_code
 
 
.fault:
; push ecx
; call _lcls
; call __bprintf
_hlt:
hlt
jmp _hlt
 
sz_invboot db 'Invalid multiboot loader magic value',0x0A
db 'Halted',0
 
sz_nomods db 'No modules loaded',0x0A
db 'Halted',0
 
sz_nommap db 'No memory table', 0x0A
db 'Halted',0
 
sz_nopse db 'Page size extensions not supported',0x0A
db 'Halted',0
/kernel/branches/kolibri_pe/const.inc
214,7 → 214,7
CDDataBuf equ (OS_BASE+0x0007000)
FLOPPY_BUFF equ (OS_BASE+0x0008000)
ACTIVE_PROC_STACK equ (OS_BASE+0x000A400) ;unused
idts equ (OS_BASE+0x000B100)
 
WIN_STACK equ (OS_BASE+0x000C000)
WIN_POS equ (OS_BASE+0x000C400)
FDD_BUFF equ (OS_BASE+0x000D000)
/kernel/branches/kolibri_pe/core/mm.asm
File deleted
/kernel/branches/kolibri_pe/core/init.asm
File deleted
/kernel/branches/kolibri_pe/core/export.inc
17,16 → 17,16
forward
count = count+1
common
dd 0,0,0, (module-OS_BASE) , 1
dd count,count,(addresses-OS_BASE),(names-OS_BASE),(ordinal-OS_BASE)
dd 0,0,0, (module+(0x100000000-OS_BASE)) , 1
dd count,count,(addresses+(0x100000000-OS_BASE)),(names+(0x100000000-OS_BASE)),(ordinal+(0x100000000-OS_BASE))
addresses:
forward
dd (label-OS_BASE)
dd (label+(0x100000000-OS_BASE))
common
names:
forward
local name
dd (name-OS_BASE)
dd (name+(0x100000000-OS_BASE))
common
ordinal: count = 0
forward
/kernel/branches/kolibri_pe/core/exports.inc
103,8 → 103,8
dd szPciWrite16 , pci_write16
dd szPciWrite32 , pci_write32
 
dd szAllocPage , alloc_page ;stdcall
dd szAllocPages , alloc_pages ;stdcall
dd szAllocPage , _alloc_page ;stdcall
dd szAllocPages , _alloc_pages ;stdcall
dd szFreePage , free_page
dd szMapPage , map_page ;stdcall
dd szMapSpace , map_space
/kernel/branches/kolibri_pe/core/heap.inc
575,7 → 575,7
 
and ebx, not 7
push ebx
stdcall alloc_pages, ebx
stdcall _alloc_pages, ebx
pop ecx ; yes ecx!!!
test eax, eax
jz .err
594,7 → 594,7
jz .end
@@:
push ecx
call alloc_page
call _alloc_page
pop ecx
test eax, eax
jz .err
/kernel/branches/kolibri_pe/core/init.c
0,0 → 1,95
 
 
#include <types.h>
#include <core.h>
 
#include "multiboot.h"
 
extern u32_t pg_balloc;
 
extern u32_t mem_amount;
extern u32_t rd_base;
extern u32_t rd_fat ;
extern u32_t rd_fat_end ;
extern u32_t rd_root ;
extern u32_t rd_root_end ;
 
extern multiboot_info_t *boot_mbi;
 
/* Check if the bit BIT in FLAGS is set. */
#define CHECK_FLAG(flags,bit) ((flags) & (1 << (bit)))
 
void init()
{
u32_t last_page = 0;
 
if (CHECK_FLAG (boot_mbi->flags, 1))
printf ("boot_device = 0x%x\n", (unsigned) boot_mbi->boot_device);
 
/* Is the command line passed? */
if (CHECK_FLAG (boot_mbi->flags, 2))
printf ("cmdline = %s\n", (char *) boot_mbi->cmdline);
 
/* Are mods_* valid? */
if (CHECK_FLAG (boot_mbi->flags, 3))
{
module_t *mod;
int i;
 
printf ("mods_count = %d, mods_addr = 0x%x\n",
(u32_t) boot_mbi->mods_count, (u32_t) boot_mbi->mods_addr);
for (i = 0, mod = (module_t *) boot_mbi->mods_addr;
i < boot_mbi->mods_count;i++, mod++)
{
pg_balloc = mod->mod_end;
printf (" mod_start = 0x%x, mod_end = 0x%x, string = %s\n",
(u32_t) mod->mod_start,(u32_t) mod->mod_end, (char *) mod->string);
};
mod--;
rd_base = mod->mod_start+OS_BASE;
rd_fat = rd_base + 512;
rd_fat_end = rd_base + 512 + 4278;
rd_root = rd_base + 512*19;
rd_root_end = rd_base + 512*33;
printf(" rd_base = %x\n", rd_base);
}
 
if (CHECK_FLAG (boot_mbi->flags, 6))
{
memory_map_t *mmap;
u32_t page;
 
printf ("mmap_addr = 0x%x, mmap_length = 0x%x\n",
(unsigned) boot_mbi->mmap_addr, (unsigned) boot_mbi->mmap_length);
 
for (mmap = (memory_map_t *) boot_mbi->mmap_addr;
(u32_t) mmap < boot_mbi->mmap_addr + boot_mbi->mmap_length;
mmap = (memory_map_t *) ((u32_t) mmap
+ mmap->size + sizeof (mmap->size)))
{
u32_t page;
 
printf (" size = 0x%x, base_addr = 0x%x%x,"
" length = 0x%x%x, type = 0x%x\n",
(unsigned) mmap->size,
(unsigned) mmap->base_addr_high,
(unsigned) mmap->base_addr_low,
(unsigned) mmap->length_high,
(unsigned) mmap->length_low,
(unsigned) mmap->type);
 
if( mmap->type != 1)
continue;
page = (mmap->base_addr_low+mmap->length_low)&(~4095);
if(page > last_page)
last_page = page;
}
}
 
if(last_page > 256*1024*1024)
last_page = 256*1024*1024;
 
mem_amount = last_page;
 
};
 
/kernel/branches/kolibri_pe/core/memory.inc
231,7 → 231,7
cmp dword [LFBAddress], -1
jne @f
mov [BOOT_VAR+0x901c],byte 2
stdcall alloc_pages, 0x280000 shr 12
stdcall _alloc_pages, 0x280000 shr 12
add eax, OS_BASE
mov [LFBAddress], eax
ret
325,7 → 325,7
xchg esi, edi
 
@@:
call alloc_page
call _alloc_page
test eax, eax
jz .exit
 
347,7 → 347,7
pop edi
pop esi
@@:
call alloc_page
call _alloc_page
test eax, eax
jz .exit
stdcall map_page,esi,eax,dword PG_UW
477,17 → 477,21
align 4
.kernel_heap:
 
mov ecx, ebx
shr ebx, 22
mov edx, [master_tab + ebx*4]
test edx, PG_MAP
jz .check_ptab ;òàáëèöà ñòðàíèö íå ñîçäàíà
 
shr ecx, 12
mov eax, [page_tabs+ecx*4]
 
.check_ptab:
mov edx, [_sys_pdbr + ebx*4]
test edx, PG_MAP
jnz @F
 
call alloc_page
call _alloc_page
test eax, eax
jz .fail
 
522,7 → 526,7
jz .fail ;àäðåñ íå çàðåçåðâèðîâàí äëÿ ;
;èñïîëüçîâàíèÿ. Îøèáêà
.alloc:
call alloc_page
call _alloc_page
test eax, eax
jz .fail
 
566,7 → 570,7
; io permission map
; copy-on-write protection
 
call alloc_page
call _alloc_page
test eax, eax
jz .fail
 
1180,7 → 1184,7
shr ebx, 12
push ebx
 
stdcall alloc_pages, ebx
stdcall _alloc_pages, ebx
pop ecx
 
test eax, eax
/kernel/branches/kolibri_pe/core/mm.c
0,0 → 1,644
 
#include <types.h>
#include <core.h>
#include <spinlock.h>
#include <link.h>
#include <mm.h>
 
extern u32_t pg_balloc;
 
extern u32_t mem_amount;
 
void __fastcall *balloc(u32_t size);
 
zone_t z_core;
 
static inline u32_t save_edx(void)
{
u32_t val;
asm volatile ("mov %0, edx":"=r"(val));
return val;
};
 
static inline void restore_edx(u32_t val)
{
asm volatile (""::"d" (val) );
};
 
static void buddy_system_create(zone_t *z);
static void __fastcall buddy_system_free(zone_t *z, link_t *block);
static void zone_mark_unavailable(zone_t *zone, index_t frame_idx);
 
static addr_t __fastcall zone_alloc(zone_t *zone, u32_t order);
 
size_t buddy_conf_size(int max_order);
 
static inline void frame_initialize(frame_t *frame);
 
static inline u32_t fnzb(u32_t arg);
 
void init_mm();
 
 
static void zone_create(zone_t *z, pfn_t start, count_t count);
static void zone_reserve(zone_t *z, pfn_t base, count_t count);
static void zone_release(zone_t *z, pfn_t base, count_t count);
 
 
void init_mm()
{
int i;
 
u32_t base;
u32_t size;
count_t pages;
size_t conf_size;
size_t core_size;
 
pages = mem_amount >> FRAME_WIDTH;
printf("last page = %x total pages = %x\n",mem_amount, pages);
 
conf_size = pages*sizeof(frame_t);
printf("conf_size = %x free mem start =%x\n",conf_size, pg_balloc);
 
zone_create(&z_core, 0, pages);
 
zone_release(&z_core, 0, pages);
zone_reserve(&z_core, 0, pg_balloc >> FRAME_WIDTH);
 
 
#if 0
core_size = (pg_free+conf_size+1024*1024*5)&(-1024*1024*4);
// printf("core size = %x core heap = %x\n",core_size,core_size-conf_size-pg_free);
 
u32_t p0, p1;
u32_t b0, b1;
 
p0 = core_size>>12;
p1 = (last_page-core_size)>>12;
 
b0 = p0*sizeof(frame_t);
b1 = p1*sizeof(frame_t);
 
// printf("buddy_0: %x pages conf_size %x\n", p0, b0);
// printf("buddy_1: %x pages conf_size %x\n", p1, b1);
 
zone_create(&z_core, 0, p0);
zone_create(&z_user, p0, p1);
 
// printf("free mem start = %x\n",pg_balloc);
 
for(i = 0; i < mem_counter; i++)
{
u32_t page;
if( mem_table[i].type != 1)
continue;
page = (mem_table[i].base+mem_table[i].size)&(~4095);
if(page > last_page)
last_page = page;
 
zone_release(&z_core,mem_table[i].base>>12, mem_table[i].size>>12);
zone_release(&z_user,mem_table[i].base>>12, mem_table[i].size>>12);
};
zone_reserve(&z_core, 0x100000>>12,(pg_balloc-OS_BASE-0x100000)>>12);
#endif
};
 
static void zone_create(zone_t *z, pfn_t start, count_t count)
{
unsigned int i;
// int znum;
 
/* Theoretically we could have here 0, practically make sure
* nobody tries to do that. If some platform requires, remove
* the assert
*/
// ASSERT(confframe);
/* If conframe is supposed to be inside our zone, then make sure
* it does not span kernel & init
*/
 
// printf("create zone: base %x count %x\n", start, count);
 
spinlock_initialize(&z->lock);
z->base = start;
z->count = count;
z->free_count = count;
z->busy_count = 0;
 
z->max_order = fnzb(count);
 
ASSERT(z->max_order < BUDDY_SYSTEM_INNER_BLOCK);
 
for (i = 0; i <= z->max_order; i++)
list_initialize(&z->order[i]);
 
z->frames = (frame_t *)balloc(count*sizeof(frame_t));
 
for (i = 0; i < count; i++) {
frame_initialize(&z->frames[i]);
}
}
 
static void zone_reserve(zone_t *z, pfn_t base, count_t count)
{
int i;
pfn_t top = base+count;
 
if( (base+count < z->base)||(base > z->base+z->count))
return;
 
if(base < z->base)
base = z->base;
 
if(top > z->base+z->count)
top = z->base+z->count;
 
printf("zone reserve base %x top %x\n", base, top);
 
for (i = base; i < top; i++)
zone_mark_unavailable(z, i - z->base);
 
};
 
static void zone_release(zone_t *z, pfn_t base, count_t count)
{
int i;
pfn_t top = base+count;
 
if( (base+count < z->base)||(base > z->base+z->count))
return;
 
if(base < z->base)
base = z->base;
 
if(top > z->base+z->count)
top = z->base+z->count;
 
printf("zone release base %x top %x\n", base, top);
 
for (i = base; i < top; i++) {
z->frames[i-z->base].refcount = 0;
buddy_system_free(z, &z->frames[i-z->base].buddy_link);
}
};
 
 
static inline index_t frame_index(zone_t *zone, frame_t *frame)
{
return (index_t) (frame - zone->frames);
}
 
static inline index_t frame_index_abs(zone_t *zone, frame_t *frame)
{
return (index_t) (frame - zone->frames);
}
 
static inline int frame_index_valid(zone_t *zone, index_t index)
{
return (index < zone->count);
}
 
/** Compute pfn_t from frame_t pointer & zone pointer */
static inline index_t make_frame_index(zone_t *zone, frame_t *frame)
{
return (frame - zone->frames);
}
 
static inline void frame_initialize(frame_t *frame)
{
frame->refcount = 1;
frame->buddy_order = 0;
}
 
static inline count_t fnzb(u32_t arg)
{
int n;
asm volatile ("xor %0, %0 \n\t"
"bsr %0, %1"
:"=r" (n)
:"r"(arg)
);
return n;
}
 
static link_t *buddy_find_block(zone_t *zone, link_t *child,
u32_t order)
{
frame_t *frame;
index_t index;
 
frame = (frame_t*)child;
 
index = frame_index(zone, frame);
do {
if (zone->frames[index].buddy_order != order) {
return &zone->frames[index].buddy_link;
}
} while(index-- > 0);
return NULL;
}
 
static inline link_t * buddy_bisect(zone_t *z, link_t *block) {
frame_t *frame_l, *frame_r;
 
frame_l = (frame_t*)block;
frame_r = (frame_l + (1 << (frame_l->buddy_order - 1)));
 
return &frame_r->buddy_link;
}
 
static inline u32_t buddy_get_order(zone_t *z, link_t *block) {
frame_t *frame = (frame_t*)block;
return frame->buddy_order;
}
 
static inline void buddy_set_order(zone_t *z, link_t *block,
u32_t order) {
frame_t *frame = (frame_t*)block;
frame->buddy_order = order;
}
 
static link_t *buddy_coalesce(zone_t *z, link_t *block_1,
link_t *block_2)
{
frame_t *frame1, *frame2;
 
frame1 = (frame_t*)block_1;
frame2 = (frame_t*)block_2;
 
return frame1 < frame2 ? block_1 : block_2;
}
 
static inline void buddy_mark_busy(zone_t *z, link_t * block) {
frame_t * frame = (frame_t*)block;
frame->refcount = 1;
}
 
static inline void buddy_mark_available(zone_t *z, link_t *block) {
frame_t *frame = (frame_t*)block;
frame->refcount = 0;
}
 
#define IS_BUDDY_ORDER_OK(index, order) \
((~(((u32_t) -1) << (order)) & (index)) == 0)
#define IS_BUDDY_LEFT_BLOCK_ABS(zone, frame) \
(((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
 
#define IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame) \
(((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
 
static link_t *find_buddy(zone_t *zone, link_t *block)
{
frame_t *frame;
index_t index;
u32_t is_left, is_right;
 
frame = (frame_t*)block;
ASSERT(IS_BUDDY_ORDER_OK(frame_index_abs(zone, frame),frame->buddy_order));
 
is_left = IS_BUDDY_LEFT_BLOCK_ABS(zone, frame);
is_right = IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame);
 
ASSERT(is_left ^ is_right);
if (is_left) {
index = (frame_index(zone, frame)) + (1 << frame->buddy_order);
} else { /* if (is_right) */
index = (frame_index(zone, frame)) - (1 << frame->buddy_order);
}
 
if (frame_index_valid(zone, index)) {
if (zone->frames[index].buddy_order == frame->buddy_order &&
zone->frames[index].refcount == 0) {
return &zone->frames[index].buddy_link;
}
}
 
return NULL;
}
 
static link_t* __fastcall buddy_system_alloc_block(zone_t *z, link_t *block)
{
link_t *left,*right, *tmp;
u32_t order;
 
left = buddy_find_block(z, block, BUDDY_SYSTEM_INNER_BLOCK);
ASSERT(left);
list_remove(left);
while (1) {
if (! buddy_get_order(z,left)) {
buddy_mark_busy(z, left);
return left;
}
 
order = buddy_get_order(z, left);
 
right = buddy_bisect(z, left);
buddy_set_order(z, left, order-1);
buddy_set_order(z, right, order-1);
 
tmp = buddy_find_block(z, block, BUDDY_SYSTEM_INNER_BLOCK);
 
if (tmp == right) {
right = left;
left = tmp;
}
ASSERT(tmp == left);
buddy_mark_busy(z, left);
buddy_system_free(z, right);
buddy_mark_available(z, left);
}
}
 
static void __fastcall buddy_system_free(zone_t *z, link_t *block)
{
link_t *buddy, *hlp;
u8_t i;
 
/*
* Determine block's order.
*/
i = buddy_get_order(z, block);
 
ASSERT(i <= z->max_order);
 
if (i != z->max_order) {
/*
* See if there is any buddy in the list of order i.
*/
buddy = find_buddy(z, block);
if (buddy) {
 
ASSERT(buddy_get_order(z, buddy) == i);
/*
* Remove buddy from the list of order i.
*/
list_remove(buddy);
 
/*
* Invalidate order of both block and buddy.
*/
buddy_set_order(z, block, BUDDY_SYSTEM_INNER_BLOCK);
buddy_set_order(z, buddy, BUDDY_SYSTEM_INNER_BLOCK);
 
/*
* Coalesce block and buddy into one block.
*/
hlp = buddy_coalesce(z, block, buddy);
 
/*
* Set order of the coalesced block to i + 1.
*/
buddy_set_order(z, hlp, i + 1);
 
/*
* Recursively add the coalesced block to the list of order i + 1.
*/
buddy_system_free(z, hlp);
return;
}
}
 
/*
* Insert block into the list of order i.
*/
list_append(block, &z->order[i]);
 
}
 
static inline frame_t * zone_get_frame(zone_t *zone, index_t frame_idx)
{
ASSERT(frame_idx < zone->count);
return &zone->frames[frame_idx];
}
 
static void zone_mark_unavailable(zone_t *zone, index_t frame_idx)
{
frame_t *frame;
link_t *link;
 
frame = zone_get_frame(zone, frame_idx);
if (frame->refcount)
return;
link = buddy_system_alloc_block(zone, &frame->buddy_link);
ASSERT(link);
zone->free_count--;
}
 
static link_t* __fastcall buddy_system_alloc(zone_t *z, u32_t i)
{
link_t *res, *hlp;
 
ASSERT(i <= z->max_order);
 
/*
* If the list of order i is not empty,
* the request can be immediatelly satisfied.
*/
if (!list_empty(&z->order[i])) {
res = z->order[i].next;
list_remove(res);
buddy_mark_busy(z, res);
return res;
}
/*
* If order i is already the maximal order,
* the request cannot be satisfied.
*/
if (i == z->max_order)
return NULL;
 
/*
* Try to recursively satisfy the request from higher order lists.
*/
hlp = buddy_system_alloc(z, i + 1);
 
/*
* The request could not be satisfied
* from higher order lists.
*/
if (!hlp)
return NULL;
 
res = hlp;
 
/*
* Bisect the block and set order of both of its parts to i.
*/
hlp = buddy_bisect(z, res);
buddy_set_order(z, res, i);
buddy_set_order(z, hlp, i);
 
/*
* Return the other half to buddy system. Mark the first part
* full, so that it won't coalesce again.
*/
buddy_mark_busy(z, res);
buddy_system_free(z, hlp);
 
return res;
 
}
 
 
static __fastcall pfn_t zone_frame_alloc(zone_t *zone, u32_t order)
{
pfn_t v;
link_t *tmp;
frame_t *frame;
 
 
/* Allocate frames from zone buddy system */
tmp = buddy_system_alloc(zone, order);
 
ASSERT(tmp);
 
/* Update zone information. */
zone->free_count -= (1 << order);
zone->busy_count += (1 << order);
 
/* Frame will be actually a first frame of the block. */
frame = (frame_t*)tmp;
 
/* get frame address */
v = make_frame_index(zone, frame);
return v;
}
 
 
/** Set parent of frame */
void __fastcall frame_set_parent(pfn_t pfn, void *data)
{
/* zone_t *zone = find_zone_and_lock(pfn, &hint);
ASSERT(zone);
*/
 
spinlock_lock(&z_core.lock);
zone_get_frame(&z_core, pfn-z_core.base)->parent = data;
spinlock_unlock(&z_core.lock);
}
 
 
static inline int to_order(count_t arg)
{
int n;
asm volatile (
"xor eax, eax \n\t"
"bsr eax, edx \n\t"
"inc eax"
:"=a" (n)
:"d"(arg)
);
return n;
}
 
 
addr_t __fastcall zone_alloc(zone_t *zone, u32_t order)
{
eflags_t efl;
pfn_t v;
 
efl = safe_cli();
spinlock_lock(&zone->lock);
v = zone_frame_alloc(zone, order);
v += zone->base;
spinlock_unlock(&zone->lock);
safe_sti(efl);
 
return (v << FRAME_WIDTH);
}
 
addr_t core_alloc(u32_t order) //__cdecl __dllexport
{
eflags_t efl;
pfn_t v;
 
efl = safe_cli();
spinlock_lock(&z_core.lock);
v = zone_frame_alloc(&z_core, order);
spinlock_unlock(&z_core.lock);
safe_sti(efl);
 
return (v << FRAME_WIDTH);
};
 
addr_t alloc_page() //obsolete
{
eflags_t efl;
u32_t edx;
pfn_t v;
 
edx = save_edx();
efl = safe_cli();
spinlock_lock(&z_core.lock);
v = zone_frame_alloc(&z_core, 0);
spinlock_unlock(&z_core.lock);
safe_sti(efl);
restore_edx(edx);
return (v << FRAME_WIDTH);
};
 
addr_t __stdcall alloc_pages(count_t count) //obsolete
{
eflags_t efl;
u32_t edx;
pfn_t v;
 
count = (count+7)&~7;
 
edx = save_edx();
efl = safe_cli();
spinlock_lock(&z_core.lock);
v = zone_frame_alloc(&z_core, to_order(count));
spinlock_unlock(&z_core.lock);
safe_sti(efl);
restore_edx(edx);
 
return (v << FRAME_WIDTH);
};
 
 
void __fastcall zone_free(zone_t *zone, pfn_t frame_idx)
{
frame_t *frame;
u32_t order;
 
frame = &zone->frames[frame_idx];
 
/* remember frame order */
order = frame->buddy_order;
 
ASSERT(frame->refcount);
 
if (!--frame->refcount) {
buddy_system_free(zone, &frame->buddy_link);
 
/* Update zone information. */
zone->free_count += (1 << order);
zone->busy_count -= (1 << order);
}
}
 
void core_free(addr_t frame) //export
{
eflags_t efl;
 
efl = safe_cli();
spinlock_lock(&z_core.lock);
zone_free(&z_core, frame>>12);
spinlock_unlock(&z_core.lock);
safe_sti(efl);
}
 
void frame_free(addr_t frame) //export
{
eflags_t efl;
zone_t *zone;
 
efl = safe_cli();
spinlock_lock(&z_core.lock);
zone_free(&z_core, frame>>12);
spinlock_unlock(&z_core.lock);
safe_sti(efl);
}
 
/kernel/branches/kolibri_pe/core/multiboot.h
0,0 → 1,119
/* multiboot.h - the header for Multiboot */
/* Copyright (C) 1999, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
/* Macros. */
 
/* The magic number for the Multiboot header. */
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
 
/* The flags for the Multiboot header. */
#ifdef __ELF__
# define MULTIBOOT_HEADER_FLAGS 0x00000003
#else
# define MULTIBOOT_HEADER_FLAGS 0x00010003
#endif
 
/* The magic number passed by a Multiboot-compliant boot loader. */
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
 
/* The size of our stack (16KB). */
#define STACK_SIZE 0x4000
 
/* C symbol format. HAVE_ASM_USCORE is defined by configure. */
#ifdef HAVE_ASM_USCORE
# define EXT_C(sym) _ ## sym
#else
# define EXT_C(sym) sym
#endif
 
#ifndef ASM
/* Do not include here in boot.S. */
 
/* Types. */
 
/* The Multiboot header. */
typedef struct multiboot_header
{
unsigned long magic;
unsigned long flags;
unsigned long checksum;
unsigned long header_addr;
unsigned long load_addr;
unsigned long load_end_addr;
unsigned long bss_end_addr;
unsigned long entry_addr;
} multiboot_header_t;
 
/* The symbol table for a.out. */
typedef struct aout_symbol_table
{
unsigned long tabsize;
unsigned long strsize;
unsigned long addr;
unsigned long reserved;
} aout_symbol_table_t;
 
/* The section header table for ELF. */
typedef struct elf_section_header_table
{
unsigned long num;
unsigned long size;
unsigned long addr;
unsigned long shndx;
} elf_section_header_table_t;
 
/* The Multiboot information. */
typedef struct multiboot_info
{
unsigned long flags;
unsigned long mem_lower;
unsigned long mem_upper;
unsigned long boot_device;
unsigned long cmdline;
unsigned long mods_count;
unsigned long mods_addr;
union
{
aout_symbol_table_t aout_sym;
elf_section_header_table_t elf_sec;
} u;
unsigned long mmap_length;
unsigned long mmap_addr;
} multiboot_info_t;
 
/* The module structure. */
typedef struct module
{
unsigned long mod_start;
unsigned long mod_end;
unsigned long string;
unsigned long reserved;
} module_t;
 
/* The memory map. Be careful that the offset 0 is base_addr_low
but no size. */
typedef struct memory_map
{
unsigned long size;
unsigned long base_addr_low;
unsigned long base_addr_high;
unsigned long length_low;
unsigned long length_high;
unsigned long type;
} memory_map_t;
 
#endif /* ! ASM */
/kernel/branches/kolibri_pe/core/spinlock.c
0,0 → 1,13
 
#include <types.h>
#include <spinlock.h>
#include <core.h>
 
#ifdef USE_SMP
 
void spinlock_initialize(spinlock_t *sl)
{
atomic_set(&sl->val, 0);
}
 
#endif
/kernel/branches/kolibri_pe/core/sys32.inc
13,15 → 13,13
 
$Revision$
 
 
align 4
idtreg:
dw 8*0x41-1
dd idts+8
_init_idt:
push edi
push esi
mov edi, idts
mov dword [idtreg+2], edi
 
build_interrupt_table:
 
mov edi, idts+8
mov esi, sys_int
mov ecx, 0x40
@@:
33,17 → 31,29
add edi, 8
loop @b
 
;mov edi,8*0x40+idts+8
mov dword [edi], (i40 and 0xFFFF) or (os_code shl 16)
mov dword [edi+4], (11101111b shl 8) or (i40 and 0xFFFF0000)
; type: trap gate
mov eax, i40
mov ecx, i40
and eax, 0x0000FFFF
and ecx, 0xFFFF0000
or eax, os_code shl 16
or ecx, (11101111b shl 8)
mov [edi], eax
mov [edi+4], ecx
 
lidt [idtreg]
pop esi
pop edi
ret
 
 
 
iglobal
 
msg_sel_ker db "kernel", 0
msg_sel_app db "application", 0
 
align 4
 
sys_int:
dd e0,debug_exc,e2,e3
dd e4,e5,e6,e7
66,6 → 76,11
times 16 dd unknown_interrupt
 
dd i40
 
idtreg:
dw 8*0x41-1
dd idts
 
endg
 
macro save_ring3_context
/kernel/branches/kolibri_pe/core/taskman.inc
383,7 → 383,7
; cmp eax, [pg_data.pages_free]
; ja .fail
 
call alloc_page
call _alloc_page
test eax, eax
jz .fail
mov [dir_addr], eax
408,7 → 408,7
mov edx, [app_tabs]
xor edi, edi
@@:
call alloc_page
call _alloc_page
test eax, eax
jz .fail
 
450,7 → 450,7
else
 
.alloc:
call alloc_page
call _alloc_page
test eax, eax
jz .fail
 
944,7 → 944,7
pl0_stack dd ?
endl
 
stdcall alloc_pages, (RING0_STACK_SIZE+512) shr 12
stdcall _alloc_pages, (RING0_STACK_SIZE+512) shr 12
add eax, OS_BASE
mov [pl0_stack], eax
 
988,7 → 988,7
add eax, RING0_STACK_SIZE
mov [SLOT_BASE+APPDATA.saved_esp0+ebx], eax
 
call alloc_page
call _alloc_page
add eax, OS_BASE
mov esi,[current_slot]
mov esi,[esi+APPDATA.cur_dir]
/kernel/branches/kolibri_pe/data32.inc
269,12 → 269,9
 
endofcode:
gdte:
edata: ;equ $-OS_BASE
 
section '.bss' code readable align 4096
section '.bss' data writeable align 4096
 
org edata
 
align 4096
 
_sys_pdbr rd 1024
286,6 → 283,9
cur_saved_data rb 4096
fpu_data: rb 512
 
 
idts rq 0x41
 
; device irq owners
irq_owner rd 16 ; process id
 
/kernel/branches/kolibri_pe/include/atomic.h
0,0 → 1,131
/*
* Copyright (c) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
 
#ifndef KERN_ATOMIC_H_
#define KERN_ATOMIC_H_
 
typedef struct atomic {
volatile long count;
} atomic_t;
 
static inline void atomic_inc(atomic_t *val) {
#ifdef USE_SMP
asm volatile ("lock inc %0\n" : "+m" (val->count));
#else
asm volatile ("inc %0\n" : "+m" (val->count));
#endif /* USE_SMP */
}
 
static inline void atomic_dec(atomic_t *val) {
#ifdef USE_SMP
asm volatile ("lock dec %0\n" : "+m" (val->count));
#else
asm volatile ("dec %0\n" : "+m" (val->count));
#endif /* USE_SMP */
}
 
/*
static inline long atomic_postinc(atomic_t *val)
{
long r = 1;
 
asm volatile (
"lock xadd %1, %0\n"
: "+m" (val->count), "+r" (r)
);
 
return r;
}
 
static inline long atomic_postdec(atomic_t *val)
{
long r = -1;
 
asm volatile (
"lock xadd %1, %0\n"
: "+m" (val->count), "+r"(r)
);
 
return r;
}
 
#define atomic_preinc(val) (atomic_postinc(val) + 1)
#define atomic_predec(val) (atomic_postdec(val) - 1)
 
static inline u32_t test_and_set(atomic_t *val) {
uint32_t v;
 
asm volatile (
"movl $1, %0\n"
"xchgl %0, %1\n"
: "=r" (v),"+m" (val->count)
);
 
return v;
}
*/
 
/* ia32 specific fast spinlock */
 
static inline void atomic_lock_arch(atomic_t *val)
{
u32_t tmp;
 
// preemption_disable();
asm volatile (
"0:\n"
"pause\n\t" /* Pentium 4's HT love this instruction */
"mov %1, [%0]\n\t"
"test %1, %1\n\t"
"jnz 0b\n\t" /* lightweight looping on locked spinlock */
 
"inc %1\n\t" /* now use the atomic operation */
"xchg [%0], %1\n\t"
"test %1, %1\n\t"
"jnz 0b\n\t"
: "+m" (val->count), "=r"(tmp)
);
/*
* Prevent critical section code from bleeding out this way up.
*/
// CS_ENTER_BARRIER();
}
 
static inline void atomic_set(atomic_t *val, long i)
{
val->count = i;
}
 
static inline long atomic_get(atomic_t *val)
{
return val->count;
}
 
#endif /* KERN_ATOMIC_H_ */
 
/kernel/branches/kolibri_pe/include/core.h
0,0 → 1,48
 
#define OS_BASE 0xE0000000
 
 
void printf (const char *format, ...);
 
#define CALLER ((addr_t) __builtin_return_address(0))
 
extern void panic_printf(char *fmt, ...) __attribute__((noreturn));
 
#ifdef CONFIG_DEBUG
 
# define panic(format, ...) \
panic_printf("Kernel panic in %s() at %s:%u: " format, __func__, \
__FILE__, __LINE__, ##__VA_ARGS__);
 
# define ASSERT(expr) \
if (!(expr)) { \
panic("assertion failed (%s), caller=%p\n", #expr, CALLER); \
}
#else
# define panic(format, ...) \
panic_printf("Kernel panic: " format, ##__VA_ARGS__);
 
# define ASSERT(expr)
#endif
 
 
static inline eflags_t safe_cli(void)
{
eflags_t tmp;
asm volatile (
"pushf\n\t"
"pop %0\n\t"
"cli\n"
: "=r" (tmp)
);
return tmp;
}
 
static inline void safe_sti(eflags_t efl)
{
asm volatile (
"push %0\n\t"
"popf\n"
: : "r" (efl)
);
}
/kernel/branches/kolibri_pe/include/link.h
0,0 → 1,50
 
typedef struct link
{
struct link *prev;
struct link *next;
}link_t;
 
#define list_get_instance(link, type, member) \
((type *)(((u8_t *)(link)) - ((u8_t *)&(((type *)NULL)->member))))
 
static inline void link_initialize(link_t *link)
{
link->prev = NULL;
link->next = NULL;
}
 
static inline void list_initialize(link_t *head)
{
head->prev = head;
head->next = head;
}
 
static inline void list_append(link_t *link, link_t *head)
{
link->prev = head->prev;
link->next = head;
head->prev->next = link;
head->prev = link;
}
 
static inline void list_remove(link_t *link)
{
link->next->prev = link->prev;
link->prev->next = link->next;
link_initialize(link);
}
 
static inline bool list_empty(link_t *head)
{
return head->next == head ? true : false;
}
 
static inline void list_prepend(link_t *link, link_t *head)
{
link->next = head->next;
link->prev = head;
head->next->prev = link;
head->next = link;
}
 
/kernel/branches/kolibri_pe/include/mm.h
0,0 → 1,59
 
typedef struct
{
link_t buddy_link; /**< link to the next free block inside one order */
count_t refcount; /**< tracking of shared frames */
u32_t buddy_order; /**< buddy system block order */
void *parent; /**< If allocated by slab, this points there */
} frame_t;
 
typedef struct {
SPINLOCK_DECLARE(lock); /**< this lock protects everything below */
pfn_t base; /**< frame_no of the first frame in the frames array */
count_t count; /**< Size of zone */
 
frame_t *frames; /**< array of frame_t structures in this zone */
count_t free_count; /**< number of free frame_t structures */
count_t busy_count; /**< number of busy frame_t structures */
 
u32_t max_order;
link_t order[21];
 
int flags;
} zone_t;
 
 
# define PA2KA(x) (((u32_t) (x)) + OS_BASE)
# define KA2PA(x) (((u32_t) (x)) - OS_BASE)
 
#define PAGE_SIZE 4096
#define FRAME_WIDTH 12
 
#define BUDDY_SYSTEM_INNER_BLOCK 0xff
 
static inline count_t SIZE2FRAMES(size_t size)
{
if (!size)
return 0;
return (count_t) ((size - 1) >> FRAME_WIDTH) + 1;
}
 
static inline addr_t PFN2ADDR(pfn_t frame)
{
return (addr_t) (frame << FRAME_WIDTH);
}
 
static inline pfn_t ADDR2PFN(addr_t addr)
{
return (pfn_t) (addr >> FRAME_WIDTH);
};
 
void init_mm();
 
pfn_t core_alloc(u32_t order);
 
pfn_t alloc_page() __attribute__ ((deprecated));
pfn_t __stdcall alloc_pages(count_t count) __asm__ ("_alloc_pages") __attribute__ ((deprecated));
 
void core_free(pfn_t frame);
void frame_free(pfn_t frame);
/kernel/branches/kolibri_pe/include/spinlock.h
0,0 → 1,65
 
#include <atomic.h>
 
#ifdef USE_SMP
 
typedef struct
{
atomic_t val;
} spinlock_t;
 
/*
* SPINLOCK_DECLARE is to be used for dynamically allocated spinlocks,
* where the lock gets initialized in run time.
*/
 
#define SPINLOCK_DECLARE(slname) spinlock_t slname
 
/*
* SPINLOCK_INITIALIZE is to be used for statically allocated spinlocks.
* It declares and initializes the lock.
*/
 
#define SPINLOCK_INITIALIZE(slname) \
spinlock_t slname = { \
.val = { 0 } \
}
 
extern void spinlock_initialize(spinlock_t *sl);
extern int spinlock_trylock(spinlock_t *sl);
 
#define spinlock_lock(x) atomic_lock_arch(&(x)->val)
 
/** Unlock spinlock
*
* Unlock spinlock.
*
* @param sl Pointer to spinlock_t structure.
*/
static inline void spinlock_unlock(spinlock_t *sl)
{
ASSERT(atomic_get(&sl->val) != 0);
 
/*
* Prevent critical section code from bleeding out this way down.
*/
// CS_LEAVE_BARRIER();
 
atomic_set(&sl->val, 0);
// preemption_enable();
}
 
#else
 
/* On UP systems, spinlocks are effectively left out. */
#define SPINLOCK_DECLARE(name)
#define SPINLOCK_EXTERN(name)
#define SPINLOCK_INITIALIZE(name)
 
#define spinlock_initialize(x)
#define spinlock_lock(x)
#define spinlock_trylock(x)
#define spinlock_unlock(x)
 
#endif
 
/kernel/branches/kolibri_pe/include/types.h
0,0 → 1,24
 
#define NULL (void*)0
 
 
typedef unsigned char u8_t;
typedef unsigned short int u16_t;
typedef unsigned int u32_t;
typedef unsigned long long u64_t;
 
typedef u32_t addr_t;
typedef u32_t pfn_t;
 
typedef u32_t count_t;
typedef u32_t size_t;
typedef u32_t index_t;
typedef u32_t eflags_t;
 
 
typedef int bool;
 
#define true (bool)1
#define false (bool)0
 
 
/kernel/branches/kolibri_pe/kernel.asm
114,78 → 114,50
public _gdts
public _high_code
 
public __hlt
public _panic_printf
public _printf
public _pg_balloc
public _mem_amount
public @balloc@4
 
public __setvars
 
extrn _enter_bootscreen
extrn _leave_bootscreen
 
extrn _init
extrn _init_mm
 
public _rd_base
public _rd_fat
public _rd_fat_end
public _rd_root
public _rd_root_end
 
extrn _alloc_pages
extrn _alloc_page
 
extrn _bx_from_load
 
section '.flat' code readable align 16
section '.flat' code readable align 4096
 
use32
 
org 0xE0102000
 
 
align 4
 
use32
 
 
; CLEAR 0x280000 - HEAP_BASE
 
; xor eax,eax
; mov edi,0x280000
; mov ecx,(0x800000-0x280000) / 4
; cld
; rep stosd
 
; mov edi,0x40000
; mov ecx,(0x90000-0x40000)/4
; rep stosd
 
; CLEAR KERNEL UNDEFINED GLOBALS
; mov edi, endofcode-OS_BASE
; mov ecx, (uglobals_size/4)+4
; rep stosd
 
 
; call test_cpu
bts [cpu_caps-OS_BASE], CAPS_TSC ;force use rdtsc
; bts [cpu_caps-OS_BASE], CAPS_TSC ;force use rdtsc
 
; call init_BIOS32
 
; mov dword [sys_pgdir-OS_BASE], PG_LARGE+PG_SW
; mov dword [sys_pgdir-OS_BASE+4], PG_LARGE+PG_SW+4*1024*1024
 
; mov ecx, 32
; lea edi, [sys_pgdir-OS_BASE+0xE00]
; mov eax, PG_LARGE+PG_SW
;@@:
; stosd
; add eax, 4*1024*1024
; loop @B
 
; mov ebx, cr4
; or ebx, CR4_PSE
; and ebx, not CR4_PAE
; mov cr4, ebx
 
 
; mov eax, sys_pgdir-OS_BASE
; mov ebx, cr0
; or ebx,CR0_PG+CR0_WP
 
; mov cr3, eax
; mov cr0, ebx
 
; lgdt [gdts]
; jmp pword os_code:high_code
 
align 4
bios32_entry dd ?
tmp_page_tabs dd ?
;bios32_entry dd ?
;tmp_page_tabs dd ?
 
 
__DEBUG__ fix 1
197,12 → 169,22
MEM_UC equ 0 ;uncached memory
 
 
include 'printf.inc'
include 'core/mm.asm'
__hlt:
cli
@@:
hlt
jmp @B
 
include 'core/init.asm'
align 4
_panic_printf:
 
mov dword [esp], __hlt
jmp _printf
 
align 4
include 'printf.inc'
 
align 4
proc test_cpu
locals
cpu_type dd ?
303,6 → 285,7
 
align 4
_high_code:
 
mov ax,os_stack
mov dx,app_data
mov ss,ax
313,10 → 296,7
mov fs, dx
mov gs, dx
 
; push ecx
; push ebx
 
 
; bt [cpu_caps], CAPS_PGE
; jnc @F
 
549,11 → 529,9
wrmsr
.noSYSCALL:
; -----------------------------------------
 
; LOAD IDT
 
call build_interrupt_table
lidt [idtreg]
call _init_idt
 
mov [LFBSize], 0x800000
call init_LFB
620,7 → 598,7
stdcall kernel_alloc, [mem_BACKGROUND]
mov [img_background], eax
 
mov [SLOT_BASE + 256 + APPDATA.dir_table], _sys_pdbr - OS_BASE
mov [SLOT_BASE + 256 + APPDATA.dir_table], _sys_pdbr + (0x100000000-OS_BASE)
 
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
 
649,8 → 627,6
include 'detect/disks.inc'
;!!!!!!!!!!!!!!!!!!!!!!!!!!
 
xchg bx, bx
 
call Parser_params
 
; READ RAMDISK IMAGE FROM HD
/kernel/branches/kolibri_pe/ld.x
12,15 → 12,15
.boot . + __image_base__ :
{
*(.boot)
*(.init)
*(.start)
. = ALIGN(4096);
}
 
.flat :
.flat . + 0xE0000000:
{
*(.flat)
*(.flat) *(.text) *(.rdata) *(.data)
}
__edata = .;
__edata = . - 0xE0000000;
 
.bss ALIGN(4096) :
{
/kernel/branches/kolibri_pe/makefile
2,16 → 2,21
CC = gcc
FASM = fasm.exe
 
INCLUDE = include
INCLUDE = include/
 
CFLAGS = -c -O2 -I $(INCLUDE) -fomit-frame-pointer -fno-builtin-printf -masm=intel
DEFS = -DUSE_SMP
 
CFLAGS = -c -O2 -DCONFIG_DEBUG -I $(INCLUDE) -fomit-frame-pointer -fno-builtin-printf -masm=intel
LDFLAGS = -shared -s -Map kernel.map --image-base 0x100000 --file-alignment 32
 
 
KERNEL_SRC:= \
kernel.asm \
init.c \
mm.c \
spinlock.c \
boot/boot.asm \
boot/init.asm
boot/start.asm
 
KERNEL_OBJS = $(patsubst %.s, bin/%.obj, $(patsubst %.asm, bin/%.obj,\
26,12 → 31,12
kernel.mnt: $(KERNEL_OBJS) Makefile ld.x
ld $(LDFLAGS) -T ld.x -o $@ $(KERNEL_OBJS)
bin/%.obj : core/%.c Makefile
$(CC) $(CFLAGS) -o $@ $<
bin/%.obj: %.asm
$(FASM) $< $@
 
bin/%.obj : core/%.c
$(CC) $(CFLAGS) -o $@ -c $<
 
all: $(SUBDIRS)
 
.PHONY: all
/kernel/branches/kolibri_pe/network/eth_drv/drivers/sis900.inc
458,7 → 458,7
;*************** load Transmit Descriptor Register ***************
mov dx, [io_addr] ; base address
add dx, SIS900_txdp ; TX Descriptor Pointer
mov eax, txd - OS_BASE ; First Descriptor
mov eax, txd + (0x100000000-OS_BASE) ; First Descriptor
out dx, eax ; move the pointer
ret
 
486,7 → 486,7
xor ebx, ebx ;
SIS900_init_rxd_Loop_0: ;
imul ebx, 12 ;
add ebx, rxd - OS_BASE ;
add ebx, rxd + (0x100000000-OS_BASE);
mov [rxd+eax], ebx ;save link to next descriptor
mov [rxd+eax+4],dword RX_BUFF_SZ ;status bits init to buf size
mov ebx, ecx ;find where the buf is located
500,7 → 500,7
; descriptor*********
mov dx, [io_addr]
add dx, SIS900_rxdp
mov eax, rxd - OS_BASE
mov eax, rxd + (0x100000000-OS_BASE)
out dx, eax
ret
 
998,7 → 998,7
out dx, eax
;*******load Transmit Descriptor Register *******
lea edx,[ebp+SIS900_txdp]
mov eax, txd - OS_BASE
mov eax, txd + (0x100000000-OS_BASE)
out dx, eax
;******* copy packet to descriptor*******
push esi