Mercurial > lcfOS
changeset 28:47b7df514243
Moved Makefiles
author | windel |
---|---|
date | Wed, 28 Dec 2011 13:38:43 +0100 |
parents | 7f74363f4c82 |
children | 7e3bdcb391dc |
files | cos/Makefile cos/kernel/Makefile cos/kernel/asmcode.asm cos/kernel/kernel.c cos/kernel/kernel.h cos/kernel/klib.c cos/kernel/link.ld cos/kernel/malloc.c cos/kernel/mm.c cos/kernel/task.c cos/kernel/timer.c cos/linker.ld cos/utils/bin2c.py |
diffstat | 13 files changed, 138 insertions(+), 86 deletions(-) [+] |
line wrap: on
line diff
--- a/cos/Makefile Tue Dec 27 18:59:02 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -# vim: set noexpandtab: - -all: bootdisk.img Makefile - -bootdisk.img: lcfosc.bin grub/menu.lst Makefile - cp grub/emptybootdisk.img bootdisk.img - mcopy -D o -i bootdisk.img lcfosc.bin :: - mcopy -D o -i bootdisk.img grub/menu.lst ::/grub - -CRT0 = kernel/goto64.o - -CFLAGS = -m64 \ - -nostdinc \ - -nostdlib \ - -nostartfiles \ - -mno-red-zone \ - -fno-builtin \ - -mcmodel=large \ - -Ipython/Include - -OBJECTS = \ - kernel/video.o \ - kernel/snprintf.o \ - kernel/kernel.o \ - kernel/asmcode.o \ - kernel/handlers.o \ - kernel/keyboard.o \ - kernel/klib.o \ - kernel/malloc.o \ - kernel/task.o \ - kernel/mm.o \ - kernel/timer.o - -lcfosc.bin: $(CRT0) $(OBJECTS) linker.ld - ld -T linker.ld -s -o lcfosc.bin $(CRT0) $(OBJECTS) - -%.o : %.asm Makefile - nasm -f elf64 -o $@ $< - -%.o : %.c Makefile - gcc $(CFLAGS) -o $@ -c $< -Wall -Wextra -Werror - -clean: - rm $(OBJECTS) $(CRT0) lcfosc.bin -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cos/kernel/Makefile Wed Dec 28 13:38:43 2011 +0100 @@ -0,0 +1,29 @@ +# vim: set noexpandtab: + +all: bootdisk.img Makefile + +bootdisk.img: lcfosc.bin grub/menu.lst Makefile + cp grub/emptybootdisk.img bootdisk.img + mcopy -D o -i bootdisk.img lcfosc.bin :: + mcopy -D o -i bootdisk.img grub/menu.lst ::/grub + +CRT0 = goto64.o + +CFLAGS = -m64 -nostdinc -nostdlib -nostartfiles -mno-red-zone \ + -fno-builtin -mcmodel=large -Wall -Wextra -Werror + +OBJECTS = video.o snprintf.o kernel.o asmcode.o handlers.o keyboard.o \ + klib.o malloc.o task.o mm.o timer.o + +lcfosc.bin: $(CRT0) $(OBJECTS) link.ld + ld -T link.ld -s -o lcfosc.bin $(CRT0) $(OBJECTS) + +%.o : %.asm Makefile + nasm -f elf64 -o $@ $< + +%.o : %.c Makefile + gcc $(CFLAGS) -o $@ -c $< + +clean: + rm $(OBJECTS) $(CRT0) lcfosc.bin +
--- a/cos/kernel/asmcode.asm Tue Dec 27 18:59:02 2011 +0100 +++ b/cos/kernel/asmcode.asm Wed Dec 28 13:38:43 2011 +0100 @@ -5,11 +5,6 @@ section .text align 4 -global halt -halt: - cli - hlt - ; Function to read the current instruction pointer value: global read_rip read_rip: @@ -25,7 +20,6 @@ loadIDT: extern idtP ; TODO: make this pointer thing more insightfull: - ;xchg bx, bx ; For debugging with bochs lidt [idtP] ret
--- a/cos/kernel/kernel.c Tue Dec 27 18:59:02 2011 +0100 +++ b/cos/kernel/kernel.c Wed Dec 28 13:38:43 2011 +0100 @@ -23,6 +23,9 @@ setupIDT(); init_heap(); + //new_task(hello_program); + + // TODO: make below a user space program! printf("Welcome!\n"); while (1==1) @@ -44,6 +47,8 @@ { printf("Help\n Try one of these commands:\n"); printf(" x: print system time in ms\n"); + printf(" r: reboot\n"); + printf(" t: test\n"); } if (strncmp(buffer, "r", 1)) {
--- a/cos/kernel/kernel.h Tue Dec 27 18:59:02 2011 +0100 +++ b/cos/kernel/kernel.h Wed Dec 28 13:38:43 2011 +0100 @@ -31,6 +31,8 @@ void* kmalloc(uint64_t size); void kfree(void* ptr); +void* kmalloc_int(uint64_t size); + // task related functions: void initialize_tasking(); void new_task(); @@ -38,8 +40,8 @@ // STDout funcs: void printf(const char* fmt, ... ); -void memset(void* ptr, uint32_t value, uint32_t num); -void memcpy(void* dst, void* src, uint32_t num); +void memset(void* ptr, uint8_t value, uint64_t num); +void memcpy(void* dst, void* src, uint64_t num); int strncmp(const char* s1, const char* s2, int size); // Screen related: @@ -151,5 +153,12 @@ console_t *console; } task_t; +// Memory manager functions: +typedef struct +{ + // TODO: other members here. + uint64_t frame; +} page_t; + #endif
--- a/cos/kernel/klib.c Tue Dec 27 18:59:02 2011 +0100 +++ b/cos/kernel/klib.c Wed Dec 28 13:38:43 2011 +0100 @@ -17,6 +17,12 @@ outb(0x64, 0xFE); } +void halt() +{ + asm volatile("cli"); + asm volatile("hlt"); +} + // IO port helpers: void outb(uint16_t port, uint8_t value) { @@ -48,3 +54,14 @@ return 1; } +// mem functions: +void memset(void* data, uint8_t value, uint64_t size) +{ + uint64_t i; + uint8_t *data2 = (uint8_t*)data; + for (i = 0; i < size; i++) + { + data2[i] = value; + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cos/kernel/link.ld Wed Dec 28 13:38:43 2011 +0100 @@ -0,0 +1,25 @@ +OUTPUT_FORMAT("binary") + +SECTIONS { + .text 0x100000: + { + *(.text) + } + + .rodata ALIGN (4096) : + { + *(.rodata) + } + + .data ALIGN (4096) : + { + *(.data) + } + + .bss : { + *(.bss) + } + + end = .; +} +
--- a/cos/kernel/malloc.c Tue Dec 27 18:59:02 2011 +0100 +++ b/cos/kernel/malloc.c Wed Dec 28 13:38:43 2011 +0100 @@ -1,5 +1,32 @@ #include "kernel.h" +// ================= Placement malloc: +extern uint64_t end; +uint64_t placement_address = (uint64_t)&end; + +void* kmalloc_int(uint64_t size) +{ + uint64_t tmp = placement_address; + placement_address += size; + return (void*)tmp; +} + +void* kmalloc_aligned_int(uint64_t size) +{ + if ( (placement_address | 0xFFF) != 0 ) + { + placement_address &= ~(0xFFF); + placement_address += 0x1000; + } + uint64_t tmp = placement_address; + placement_address += size; + return (void*)tmp; +} + + +// ================= Other malloc +// TODO: move this to user space? + #define HEAP_MAGIC 0xc0ffee #define HEAP_START 0x400000 #define HEAP_SIZE 0x200000 @@ -17,6 +44,7 @@ of the kernel into smaller parts. The heap is located at: 0x */ + static heap_t* kernel_heap = (heap_t*) 0x400000; // 4 MB - 6 MB is heap /* Allocates 'size' bytes and returns the pointer if succesfull. Kernelpanic in case of failure..
--- a/cos/kernel/mm.c Tue Dec 27 18:59:02 2011 +0100 +++ b/cos/kernel/mm.c Wed Dec 28 13:38:43 2011 +0100 @@ -1,12 +1,14 @@ -/* Memory manager */ +/* Memory manager functions, + * + * Uses a bitmap to keep track of 4k pages that are in use. + * + * */ #include "kernel.h" -// BITMAP functions: -#define NFRAMES 1000 -// Bit mask to check what frames are in use and which are free: -uint64_t frames[NFRAMES]; // NFRAMES*64*4kB frames. +uint64_t *frames = 0; +uint64_t nframes = 0; void set_frame(uint64_t frame) { @@ -32,7 +34,7 @@ uint64_t first_frame() { uint64_t i, j; - for (i = 0; i < NFRAMES / 64; i++) + for (i = 0; i < nframes / 64; i++) { if (frames[i] != 0xFFFFFFFFFFFFFFFF) { @@ -50,6 +52,11 @@ } // Memory manager functions: +void init_memory(uint64_t total_mem_size) +{ + frames = (uint64_t*)kmalloc_int( ( total_mem_size / 4096 ) / 8 ); +} + void alloc_frame() { uint64_t idx = first_frame(); @@ -60,4 +67,9 @@ set_frame(idx); } +void free_frame(page_t *page) +{ + clear_frame(page->frame / 0x1000); + page->frame = 0; +}
--- a/cos/kernel/task.c Tue Dec 27 18:59:02 2011 +0100 +++ b/cos/kernel/task.c Wed Dec 28 13:38:43 2011 +0100 @@ -1,3 +1,5 @@ +/* Scheduler functions */ + #include "kernel.h" // global variables:
--- a/cos/kernel/timer.c Tue Dec 27 18:59:02 2011 +0100 +++ b/cos/kernel/timer.c Wed Dec 28 13:38:43 2011 +0100 @@ -4,8 +4,8 @@ void timerDriverUpdate() { - ticks++; - task_scheduler(); + ticks++; + task_scheduler(); } uint64_t getTimeMS()
--- a/cos/linker.ld Tue Dec 27 18:59:02 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -OUTPUT_FORMAT("binary") - -SECTIONS { - .text 0x100000: - { - *(.text) - } - - .rodata ALIGN (4096) : - { - *(.rodata) - } - - .data ALIGN (4096) : - { - *(.data) - } - - .bss : { - *(.bss) - } - -} -
--- a/cos/utils/bin2c.py Tue Dec 27 18:59:02 2011 +0100 +++ b/cos/utils/bin2c.py Wed Dec 28 13:38:43 2011 +0100 @@ -10,7 +10,7 @@ data = f.read() s = ', '.join(hex(b) for b in data) -output = 'unsigned char[] data = {{{0}}};'.format(s) +output = 'unsigned char data[] = {{{0}}};'.format(s) if len(sys.argv) < 3: print(output) else: