-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added usermode support. Usermode code added in a seperate section nam…
…ed "um" and copied into a page frame. The pagetables are built for usermode code and stack at 1GB. Interrupt, exception and system call handlers are using register frames now. Fixed GDT entry for based address. Adding support for kernel memory heap.
- Loading branch information
Showing
15 changed files
with
501 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/*****************************************************************************/ | ||
/* File: memory.c */ | ||
/* */ | ||
/* Description: Source file for memory allocation code. */ | ||
/* */ | ||
/* Author: Shoily O Rahman <[email protected]> */ | ||
/* */ | ||
/* Date: July 9, 2020 */ | ||
/* */ | ||
/*****************************************************************************/ | ||
|
||
#include "memory.h" | ||
|
||
extern int _kernel_heap_start; | ||
|
||
char* heap_ptr; | ||
|
||
void init_memory() { | ||
|
||
heap_ptr = (char*)_kernel_heap_start; | ||
} | ||
|
||
void *alloc_mem(int size, int alignment) { | ||
|
||
char *mem_start = (char*)heap_ptr; | ||
|
||
mem_start = (char*)(((int)heap_ptr + (alignment-1)) & ~(alignment-1)); | ||
heap_ptr = mem_start + size; | ||
|
||
return mem_start; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/*****************************************************************************/ | ||
/* File: memory.h */ | ||
/* */ | ||
/* Description: Header file for memory allocation code. */ | ||
/* */ | ||
/* Author: Shoily O Rahman <[email protected]> */ | ||
/* */ | ||
/* Date: July 9, 2020 */ | ||
/* */ | ||
/*****************************************************************************/ | ||
|
||
#ifndef MEMORY_H | ||
#define MEMORY_H | ||
|
||
void init_memory(); | ||
void *alloc_mem(int size, int alignment); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*****************************************************************************/ | ||
/* File: page32.c */ | ||
/* */ | ||
/* Description: Source file for 32 bit page table handling code. */ | ||
/* */ | ||
/* Author: Shoily O Rahman <[email protected]> */ | ||
/* */ | ||
/* Date: July 9, 2020 */ | ||
/* */ | ||
/*****************************************************************************/ | ||
|
||
#include "page32.h" | ||
#include "system.h" | ||
|
||
void build_pagetable(pgd_t *pgdir, pte_t **pgtable, int phys_addr, int start, int length, int pgd_flags, int pte_flags) { | ||
|
||
int idx = 0; | ||
pgd_t *pgd = pgdir + ((start >> 22) & 0x3ff); | ||
pte_t *pte = pgtable[idx] + ((start >> 12) & 0x3ff); | ||
pte_t *last_pte = (pte_t*)(((int)pte + PAGE_SIZE) & ~(PAGE_SIZE-1)); | ||
int end = start + length; | ||
|
||
if (!*pgd) { | ||
*pgd = ((int)pgtable[idx] - KERNEL_VIRT_ADDR) | pgd_flags; | ||
} | ||
|
||
while(start < end) { | ||
|
||
if (pte == last_pte) { | ||
|
||
idx++; | ||
pte = pgtable[idx]; | ||
last_pte = pte + (PAGE_SIZE/sizeof(pte_t)); | ||
pgd++; | ||
|
||
if (!*pgd) { | ||
*pgd = (((int)pgtable[idx] - KERNEL_VIRT_ADDR) | pgd_flags); | ||
} | ||
} | ||
|
||
*pte = (phys_addr | pte_flags); | ||
|
||
pte++; | ||
start += 0x1000; | ||
phys_addr += 0x1000; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* File: page32.h */ | ||
/* */ | ||
/* Description: Header file for 32 bit page table handling code. */ | ||
/* */ | ||
/* Author: Shoily O Rahman <[email protected]> */ | ||
/* */ | ||
/* Date: July 9, 2020 */ | ||
/* */ | ||
/*****************************************************************************/ | ||
|
||
#ifndef PAGE32_H | ||
#define PAGE32_H | ||
|
||
typedef int pte_t; | ||
typedef int pgd_t; | ||
|
||
#define PAGE_SIZE 4096 | ||
|
||
#define PGD_PRESENT 1 | ||
#define PGD_WRITE 2 | ||
#define PGD_USER 4 | ||
|
||
#define PTE_PRESENT 1 | ||
#define PTE_WRITE 2 | ||
#define PTE_USER 4 | ||
|
||
void build_pagetable(pgd_t *pgdir, pte_t **pgtable, int phys_addr, int start, int length, int pgd_flags, int pte_flags); | ||
|
||
#endif |
Oops, something went wrong.