Fri, 24 Mar 2023 23:57:14 +0100
6 files changed,
78 insertions(+),
64 deletions(-)
M
src/apps/fibonacci.c
→
src/apps/fibonacci.c
@@ -1,4 +1,5 @@
-#include "cedos.h" +#include "common/cedos.h" +#include "common/stdio.h" #include <stdint.h>
M
src/apps/link.txt
→
src/apps/link.txt
@@ -1,6 +1,8 @@
OUTPUT_ARCH(i386) OUTPUT_FORMAT(elf32-i386) +ENTRY(_start) + MEMORY { HEADER : ORIGIN = 0x00000000, LENGTH = 0x10000000
M
src/apps/shell.c
→
src/apps/shell.c
@@ -1,4 +1,5 @@
-#include "cedos.h" +#include "common/cedos.h" +#include "common/stdio.h" #include <stdint.h>@@ -20,14 +21,13 @@ }
void main(void) { uint32_t a = 0, b = 1, i = 0; + printf("\n"); + printf("CeDOS shell\n"); + while (1) { - uint32_t tmp = a + b; - a = b; - b = tmp; - printf("fib (%i) = %i\n", i, a); - i++; - char c = 0; - - printf("[%c]\n", (int)(uint32_t)c);//yield(); + printf("/> "); + + char buffer[256]; + read_line(buffer); } }
M
src/kernel/elf.c
→
src/kernel/elf.c
@@ -7,6 +7,12 @@ #include "cedos/sched/process.h"
#include "assert.h" +#ifdef DEBUG +#define PRINT_DBG(...) printk("[" __FILE__ "] " __VA_ARGS__) +#else +#define PRINT_DBG(...) {} +#endif + typedef struct { uint8_t e_ident[16]; uint16_t type;@@ -60,38 +66,38 @@
void elf_infodump(VIRT_ADDR elf_pointer, uint32_t size) { ELF_HEADER *header = (ELF_HEADER*)elf_pointer; - printk("Reading ELF file from location %p of length %i\n", elf_pointer, size); - printk("\n"); + PRINT_DBG("Reading ELF file from location %p of length %i\n", elf_pointer, size); + PRINT_DBG("\n"); - printk("ELF header size: %i\n", sizeof(ELF_HEADER)); + PRINT_DBG("ELF header size: %i\n", sizeof(ELF_HEADER)); assert(sizeof(ELF_HEADER) == 52); - printk("\n"); + PRINT_DBG("\n"); - printk("ELF header hexdump:\n"); + PRINT_DBG("ELF header hexdump:\n"); memdump(elf_pointer, 52); - printk("\n"); + PRINT_DBG("\n"); - printk("ELF header magic number:\n"); - printk("%s\n", &(header->e_ident)); - printk("\n"); + PRINT_DBG("ELF header magic number:\n"); + PRINT_DBG("%s\n", &(header->e_ident)); + PRINT_DBG("\n"); - printk("ELF header infodump:\n"); - printk("- machine: %i\n", header->machine); - printk("- version: %i\n", header->version); - printk("- entry: %p\n", header->entry); - printk("\n"); - printk("- program headers:\n"); - printk(" - offset: %i\n", header->proghead_offset); - printk(" - entries: %i\n", header->ph_num); - printk(" - entry size: %i\n", header->ph_entry_size); - printk("\n"); - printk("- section headers:\n"); - printk(" - offset: %i\n", header->secthead_offset); - printk(" - entries: %i\n", header->sh_num); - printk(" - entry size: %i\n", header->sh_entry_size); - printk("\n"); + PRINT_DBG("ELF header infodump:\n"); + PRINT_DBG("- machine: %i\n", header->machine); + PRINT_DBG("- version: %i\n", header->version); + PRINT_DBG("- entry: %p\n", header->entry); + PRINT_DBG("\n"); + PRINT_DBG("- program headers:\n"); + PRINT_DBG(" - offset: %i\n", header->proghead_offset); + PRINT_DBG(" - entries: %i\n", header->ph_num); + PRINT_DBG(" - entry size: %i\n", header->ph_entry_size); + PRINT_DBG("\n"); + PRINT_DBG("- section headers:\n"); + PRINT_DBG(" - offset: %i\n", header->secthead_offset); + PRINT_DBG(" - entries: %i\n", header->sh_num); + PRINT_DBG(" - entry size: %i\n", header->sh_entry_size); + PRINT_DBG("\n"); - printk("Enumerating sections:\n"); + PRINT_DBG("Enumerating sections:\n"); int sh_offset = header->secthead_offset; SECT_HEADER *sect_headers = (SECT_HEADER*)(elf_pointer + sh_offset);@@ -108,18 +114,18 @@ for (int i = 0; i < num_sections; i++) {
SECT_HEADER sh = sect_headers[i]; char *name = (char*)(sect_names_addr + sh.name); - printk("Section: %s\n", name); - printk("- type: %i\n", sh.type); - printk("- offset: %i\n", sh.offset); - printk("- size: %i\n", sh.size); - printk("- addr: %i\n", sh.addr); - printk("- addr_align: %i\n", sh.addr_align); - printk("\n"); + PRINT_DBG("Section: %s\n", name); + PRINT_DBG("- type: %i\n", sh.type); + PRINT_DBG("- offset: %i\n", sh.offset); + PRINT_DBG("- size: %i\n", sh.size); + PRINT_DBG("- addr: %i\n", sh.addr); + PRINT_DBG("- addr_align: %i\n", sh.addr_align); + PRINT_DBG("\n"); } } PROCESS_ID elf_exec(const char *fname, char *args) { - printk("Loading ELF executable \"%s\".\n", fname); + PRINT_DBG("Loading ELF executable \"%s\".\n", fname); VIRT_ADDR elf_addr = (VIRT_ADDR*)(0xA0000000); // TODO: needs to change when we have other file systems int size = FAT_read_file(fname, elf_addr);@@ -146,7 +152,7 @@
assert(sizeof(SECT_HEADER) == section_size); // go through all sections and copy/allocate memory as necessary - printk("Enumerating %i sections:\n", num_sections); + PRINT_DBG("Enumerating %i sections:\n", num_sections); for (int i = 0; i < num_sections; i++) { SECT_HEADER sh = sect_headers[i]; char *name = (char*)(sect_names_addr + sh.name);@@ -155,26 +161,26 @@ if ((sh.flags & SHF_ALLOC) && (sh.flags & SHF_EXECINSTR)) {
VIRT_ADDR lma = elf_addr + sh.offset; VIRT_ADDR vma = sh.addr; uint32_t size = sh.size; - printk("%p\n", sh.flags); - printk("Copying code section %s to its destination ", name); - printk("(LMA: %p, VMA: %p)\n", lma, vma); + PRINT_DBG("%p\n", sh.flags); + PRINT_DBG("Copying code section %s to its destination ", name); + PRINT_DBG("(LMA: %p, VMA: %p)\n", lma, vma); memcpy(vma, lma, size); } else if (sh.flags & SHF_ALLOC) { VIRT_ADDR lma = elf_addr + sh.offset; VIRT_ADDR vma = sh.addr; - printk("Allocating space for section %s ", name); - printk("(LMA: %p, VMA: %p)\n", lma, vma); + PRINT_DBG("Allocating space for section %s ", name); + PRINT_DBG("(LMA: %p, VMA: %p)\n", lma, vma); /* TODO: alloc */ } else { - printk("Skipping section %s\n", name); + PRINT_DBG("Skipping section %s\n", name); } } - printk("\n"); + PRINT_DBG("\n"); - printk("Entry point: %p\n", header->entry); + PRINT_DBG("Entry point: %p\n", header->entry); // enter the process PROCESS_MAIN *entry = header->entry;
M
src/kernel/main.c
→
src/kernel/main.c
@@ -20,6 +20,12 @@ #include "linker.h"
#include "assert.h" #include "string.h" +#ifdef DEBUG +#define PRINT_DBG(...) printk("[" __FILE__ "] " __VA_ARGS__) +#else +#define PRINT_DBG(...) {} +#endif + int os_init(void) { core_init(); printk("Core functions initialized.\n");@@ -149,29 +155,22 @@
i = FAT_root_dir_next(i, buffer, &first_cluster, &file_size); if (i <= 0) { break; } - printk("%s (start: %i, size: %i)\n", buffer, first_cluster, file_size); + PRINT_DBG("%s (start: %i, size: %i)\n", buffer, first_cluster, file_size); uint16_t cluster = first_cluster; if (cluster == 0xFFF || cluster == 0x000) { continue; } - printk(" clusters: "); + PRINT_DBG(" clusters: \n"); while (1) { - printk("%x", cluster); + PRINT_DBG(" %x\n", cluster); //char *sect = FAT_read_cluster(cluster); //hexdump(sect, 512 * 8); cluster = FAT_next_cluster(cluster); if (cluster == 0xFFF || cluster == 0x000) { break; } - printk(", "); } - printk("\n"); - } - - while (1) { - int c = std_kb->read(); - printk("a"); } // create test tasks
M
src/kernel/mm/paging.c
→
src/kernel/mm/paging.c
@@ -26,6 +26,12 @@ #define PAGE_DIR_ALT_MAPPED_ADDR \
((PAGE_DIR_ENTRY*)(PAGE_TABLE_ALT_MAPPED_ADDR(PAGE_ENTRY_COUNT - 1))) #define PAGE_TABLE_FLAGS 0b000000000011 + +#ifdef DEBUG +#define PRINT_DBG(...) printk("[" __FILE__ "] " __VA_ARGS__) +#else +#define PRINT_DBG(...) {} +#endif __attribute__((always_inline)) inline int is_present(uint32_t entry) { return (entry & 0b000000000001);@@ -120,7 +126,7 @@
uint32_t offset = ((uint32_t)dest % PAGE_SIZE); uint32_t part_length = (offset + length <= PAGE_SIZE) ? length : PAGE_SIZE - offset; - printk("src=%p dest=%p length=%i offset=%i plen=%i\n", src, dest, length, offset, part_length); + PRINT_DBG("src=%p dest=%p length=%i offset=%i plen=%i\n", src, dest, length, offset, part_length); for (uint32_t i = 0; i < part_length; i++) { ((uint8_t*)mount_dest)[offset + i] = ((uint8_t*)src)[i];@@ -196,7 +202,7 @@ EXCEPTION(page_fault_isr, frame, error_code) {
volatile VIRT_ADDR faulty_addr; __asm__ volatile ("mov %%cr2, %0" : "=a" (faulty_addr)); //if (PAGE_DIR_INDEX(faulty_addr) >= PAGE_ENTRY_COUNT - 2) { return; } - printk("PAGE FAULT: %X\n", faulty_addr); + PRINT_DBG("PAGE FAULT: %X\n", faulty_addr); PHYS_ADDR new_page = get_free_page(); force_map_page_to_this(new_page, PAGE_DIR_INDEX(faulty_addr), PAGE_TABLE_INDEX(faulty_addr), PAGE_TABLE_FLAGS); // dump registers to stdout