diff options
Diffstat (limited to 'src/kernel/mem/seg.c')
-rw-r--r-- | src/kernel/mem/seg.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/kernel/mem/seg.c b/src/kernel/mem/seg.c index e3eca67..4a33db3 100644 --- a/src/kernel/mem/seg.c +++ b/src/kernel/mem/seg.c @@ -2,6 +2,8 @@ #include "mem.h" #include <core/sys.h> +/* Call this function when mapping a segment to a page directory. + Calls the appropriate map method and updates the segment's and pagedir's information. */ struct segment_map *seg_map(struct segment* seg, struct page_directory *pagedir, size_t offset) { struct segment_map *sm = seg->map(seg, pagedir, offset); if (sm == 0) return 0; @@ -13,6 +15,9 @@ struct segment_map *seg_map(struct segment* seg, struct page_directory *pagedir, return sm; } +/* Call this function when unmapping a segment from a page directory. + The segment will automatically be deleted if it is not mapped. + Calls the appropriate unmap method and updates the segment's and pagedir's information. */ void seg_unmap(struct segment_map *map) { map->seg->unmap(map); if (map->pagedir->mappedSegs == map) { @@ -32,7 +37,14 @@ void seg_unmap(struct segment_map *map) { } // ************************************ SIMPLESEG stuff ************* + +static struct segment_map* simpleseg_map(struct segment* seg, struct page_directory* pagedir, size_t offset); +static void simpleseg_unmap(struct segment_map*); +static void simpleseg_delete(struct segment *seg); +static int simpleseg_handleFault(struct segment_map* map, size_t addr, int write); +/* Call this when creating a simpleseg. + Creates the simpleseg structure and the segment structure and fills them up. */ struct segment* simpleseg_make(size_t start, size_t len, int writable) { struct simpleseg *ss = kmalloc(sizeof(struct simpleseg)); struct segment *se = kmalloc(sizeof(struct segment)); @@ -46,6 +58,7 @@ struct segment* simpleseg_make(size_t start, size_t len, int writable) { return se; } +/* For internal use only. Called when a simpleseg is mapped to a pagedirectory. */ struct segment_map* simpleseg_map(struct segment* seg, struct page_directory* pagedir, size_t offset) { struct segment_map *sm = kmalloc(sizeof(struct segment_map)); sm->start = ((struct simpleseg*)(seg->seg_data))->start; @@ -53,6 +66,8 @@ struct segment_map* simpleseg_map(struct segment* seg, struct page_directory* pa return sm; } +/* For internal use only. Called when a simpleseg is unmapped. + Frees all the allocated pages. */ void simpleseg_unmap(struct segment_map* sm) { size_t i; for (i = sm->start; i < sm->start + sm->len; i += 0x1000) { @@ -60,6 +75,7 @@ void simpleseg_unmap(struct segment_map* sm) { } } +/* For internal use only. Handles a page fault. Can allocate and map a frame if necessary. */ int simpleseg_handleFault(struct segment_map* sm, size_t addr, int write) { struct simpleseg *ss = sm->seg->seg_data; if (write && !ss->writable) return 1; @@ -70,14 +86,16 @@ int simpleseg_handleFault(struct segment_map* sm, size_t addr, int write) { return 0; } +/* For internal use only. Called when the simpleseg is deleted. Does nothing. */ void simpleseg_delete(struct segment* seg) { } +/* Call this to resize a simpleseg. Ajusts the size and frees pages if the new size is smaller.*/ int simpleseg_resize(struct segment_map *map, size_t len) { size_t i; if (map == 0) return -1; - if (map->seg->delete != simpleseg_delete) return -2; + if (map->seg->delete != simpleseg_delete) return -2; //check segment is a simpleseg struct simpleseg *s = (struct simpleseg*)map->seg->seg_data; if (len & 0xFFF) len = (len & 0xFFFFF000) + 0x1000; |