Skip to content
Permalink
Browse files

Load entire binary at memory

- Load binary programs greater then 1KB
  • Loading branch information...
rene committed May 28, 2018
1 parent ec885fd commit f9a035d016cbc7354e0f2a7dbe5e6627ab0b8f2c
Showing with 38 additions and 28 deletions.
  1. +3 −0 .gitignore
  2. +4 −4 kernel/fs/ext2/ext2.c
  3. +1 −1 kernel/include/tempos/sched.h
  4. +22 −21 kernel/kernel/fork.c
  5. +8 −2 kernel/kernel/kernel.c
@@ -1 +1,4 @@
tags
*.o
*.swp
*.gen
@@ -279,7 +279,7 @@ int ext2_get_inode(vfs_inode *inode)
char *ext2_get_fs_block(vfs_superblock *sb, uint32_t blocknum)
{
/* Maximum blocks = (for 4KB)*/
buff_header_t *blks[4096/SECTOR_SIZE];
buff_header_t *blk;
ext2_fsdriver_t *fs;
int i, nb;
uint64_t baddr;
@@ -295,9 +295,9 @@ char *ext2_get_fs_block(vfs_superblock *sb, uint32_t blocknum)

nb = get_block_size(*fs->sb) / SECTOR_SIZE;
for (i = 0; i < nb; i++, baddr++) {
blks[i] = bread(sb->device.major, sb->device.minor, baddr);
memcpy(&block[(i * SECTOR_SIZE)], blks[i]->data, SECTOR_SIZE);
brelse(sb->device.major, sb->device.minor, blks[i]);
blk = bread(sb->device.major, sb->device.minor, baddr);
memcpy(&block[(i * SECTOR_SIZE)], blk->data, SECTOR_SIZE);
brelse(sb->device.major, sb->device.minor, blk);
}

return block;
@@ -128,7 +128,7 @@

pid_t _fork(task_t *thread);

void _exec_init(char *init_data);
void _exec_init(char *init_data, size_t size);

/* These are Architecture specific */
void arch_init_scheduler(void (*start_routine)(void*));
@@ -48,18 +48,7 @@ _pushargs void sys_fork(void)
/**
* This is just for test
*/
static uint32_t get_phy_addr(void *ptr)
{
extern pagedir_t *kerneldir;
mregion *mem_area = (mregion *)((void*)ptr - sizeof(mregion));
uint32_t index = mem_area->initial_addr >> TABLE_SHIFT;
uint32_t ffpage = mem_area->initial_addr - (TABLE_SIZE * index);
uint32_t *table;

table = kerneldir->tables[index];
return (table[ffpage] & 0xFFFFF000);
}
void _exec_init(char *init_data)
void _exec_init(char *init_data, size_t size)
{
task_t *newth = NULL;
char *new_stack = NULL;
@@ -89,7 +78,7 @@ void _exec_init(char *init_data)
kfree(new_stack);
return;
}

/* Set process structure */
newth->state = TASK_READY_TO_RUN;
newth->priority = DEFAULT_PRIORITY;
@@ -122,7 +111,7 @@ void _exec_init(char *init_data)
ptable_addr = alloc_page(GFP_NORMAL_Z);
dtable_addr = alloc_page(GFP_NORMAL_Z);

/* Map dtable at 0x1000000 */
/* Map dtable at 0x1000000 to fill data */
kerneldir->tables[4][0] = MAKE_ENTRY(dtable_addr, (PAGE_WRITABLE | PAGE_PRESENT | PAGE_USER));
dtable = (uint32_t*)0x1000000;
for (i = 0; i < 1024; i++) {
@@ -131,18 +120,30 @@ void _exec_init(char *init_data)
}
dtable[3] = MAKE_ENTRY(ptable_addr, (PAGE_WRITABLE | PAGE_PRESENT | PAGE_USER));

/* Now, map ptable at 0xC00000 just for fill data */
/* Now, map ptable at 0xC00000 (12MB) which is the process start point */
kerneldir->tables[3][0] = MAKE_ENTRY(ptable_addr, (PAGE_WRITABLE | PAGE_PRESENT | PAGE_USER));
ptable = (uint32_t*)0xC00000;
ptable[0] = MAKE_ENTRY(get_phy_addr(init_data), (PAGE_WRITABLE | PAGE_PRESENT | PAGE_USER));

pg_pdir->tables_phy_addr = dtable; //(uint32_t*)dtable_addr;
/* Get location where init_data are mapped on the kernel */
mregion *mem_area = (mregion *)((void*)init_data - sizeof(mregion));
uint32_t index = mem_area->initial_addr >> TABLE_SHIFT;
uint32_t ffpage = mem_area->initial_addr - (TABLE_SIZE * index);
uint32_t *pktable = kerneldir->tables[index];

uint32_t npages = (size / PAGE_SIZE);
if ( (size % PAGE_SIZE) != 0) npages++;

for (i = 0; i < npages; i++) {
ptable[i] = pktable[ffpage++] | PAGE_USER;
if (ffpage >= TABLE_SIZE) {
ffpage = 0;
pktable = kerneldir->tables[++index];
}
}

pg_pdir->tables_phy_addr = dtable;
pg_pdir->dir_phy_addr = dtable_addr;

/* 12MB : start point */
//kerneldir->tables[3][0] = MAKE_ENTRY(get_phy_addr(init_data), (PAGE_PRESENT));
//pg_pdir->dir_phy_addr = kerneldir->dir_phy_addr;

newth->arch_tss.cr3 = pg_pdir->dir_phy_addr;

/* Configure thread's stack */
@@ -169,7 +169,13 @@ void kernel_main_thread(void *arg)
vfs_inode *arq = vfs_namei(init);
vfs_bmap_t bk;

size_t fblocks = (arq->i_size/arq->sb->s_log_block_size);

if (arq == NULL) {
kprintf(KERN_DEBUG "%s: not found!\n", init);
panic("init file not found!\n");
}

size_t fblocks = (arq->i_size / arq->sb->s_log_block_size);
if ((arq->i_size % arq->sb->s_log_block_size) != 0) fblocks++;

char *blocks = kmalloc(fblocks*arq->sb->s_log_block_size, GFP_NORMAL_Z);
@@ -182,7 +188,7 @@ void kernel_main_thread(void *arg)
pos += arq->sb->s_log_block_size;
}

_exec_init(blocks);
_exec_init(blocks, arq->i_size);

/* TEST: Read root directory */
/*kprintf("DEBUG:\n");

0 comments on commit f9a035d

Please sign in to comment.
You can’t perform that action at this time.