diff options
author | Marvin Borner | 2021-04-02 16:17:50 +0200 |
---|---|---|
committer | Marvin Borner | 2021-04-02 16:17:50 +0200 |
commit | b62b9d1f33a4911feb9f318ece0c1565f27abf8d (patch) | |
tree | aecea9f7b5bf651b584911cf90c61258b9564556 /kernel | |
parent | d055495f3dbb62f74809d31a84621d6e86d61d0a (diff) |
Replaced target macros
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/Makefile | 2 | ||||
-rw-r--r-- | kernel/drivers/interrupts.c | 2 | ||||
-rw-r--r-- | kernel/features/mm.c | 1 | ||||
-rw-r--r-- | kernel/features/proc.c | 12 | ||||
-rw-r--r-- | kernel/inc/proc.h | 8 |
5 files changed, 18 insertions, 7 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index e9c7b09..392665d 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -23,7 +23,7 @@ LD = ccache ../cross/opt/bin/i686-elf-ld OC = ccache ../cross/opt/bin/i686-elf-objcopy AS = ccache nasm -CFLAGS = $(CFLAGS_DEFAULT) -Wno-address-of-packed-member -ffreestanding -Wl,-ekernel_main -I../libs/libc/inc/ -Iinc/ -Dkernel +CFLAGS = $(CFLAGS_DEFAULT) -Wno-address-of-packed-member -ffreestanding -Wl,-ekernel_main -I../libs/libc/inc/ -Iinc/ -DKERNEL ASFLAGS = -f elf32 all: compile diff --git a/kernel/drivers/interrupts.c b/kernel/drivers/interrupts.c index 917733f..0189b6c 100644 --- a/kernel/drivers/interrupts.c +++ b/kernel/drivers/interrupts.c @@ -173,7 +173,7 @@ void isr_uninstall_handler(int isr) void isr_panic(struct regs *r) { printf("%s Exception (%x) at 0x%x (ring %d), exiting!\n", isr_exceptions[r->int_no], - r->err_code, r->eip, r->cs & 3); + r->err_code, r->eip, RING(r)); struct proc *proc = proc_current(); if (proc) { printf("\t-> Exception occurred in %s at addr 0x%x (offset 0x%x)\n", proc->name, diff --git a/kernel/features/mm.c b/kernel/features/mm.c index afee468..064f78c 100644 --- a/kernel/features/mm.c +++ b/kernel/features/mm.c @@ -377,7 +377,6 @@ void *memory_alloc_identity(struct page_dir *dir, u32 flags) return NULL; } -// TODO: Free by address instead of vrange (combine with shmem map?) void memory_free(struct page_dir *dir, struct memory_range vrange) { assert(PAGE_ALIGNED(vrange.base) && PAGE_ALIGNED(vrange.size)); diff --git a/kernel/features/proc.c b/kernel/features/proc.c index 2b2d2d2..8625e7d 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -31,7 +31,10 @@ HOT FLATTEN void scheduler(struct regs *regs) { spinlock(&locked); - PROC(current)->ticks++; + if (RING(regs) == 3) + PROC(current)->ticks.user++; + else + PROC(current)->ticks.kernel++; if (PROC(current)->quantum.cnt >= PROC(current)->quantum.val) { PROC(current)->quantum.cnt = 0; @@ -93,14 +96,14 @@ struct proc *proc_from_pid(u32 pid) iterator = proc_list_blocked->head; while (iterator) { - if (((struct proc *)iterator->data)->pid == pid) + if (PROC(iterator)->pid == pid) return iterator->data; iterator = iterator->next; } iterator = proc_list_running->head; while (iterator) { - if (((struct proc *)iterator->data)->pid == pid) + if (PROC(iterator)->pid == pid) return iterator->data; iterator = iterator->next; } @@ -152,12 +155,15 @@ void proc_exit(struct proc *proc, struct regs *r, s32 status) if (proc->memory->head) { printf("Process leaked memory:\n"); + u32 total = 0; struct node *iterator = proc->memory->head; while (iterator) { struct memory_proc_link *link = iterator->data; printf("\t-> 0x%x: %dB\n", link->vrange.base, link->vrange.size); + total += link->vrange.size; iterator = iterator->next; } + printf("\tTOTAL: %dB (%dKiB)\n", total, total >> 10); } else { printf("Process didn't leak memory!\n"); } diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h index c9dadaa..8a172c9 100644 --- a/kernel/inc/proc.h +++ b/kernel/inc/proc.h @@ -19,6 +19,8 @@ #define GDT_USER_CODE_OFFSET 0x1b // User code segment offset in GDT (with ring3 mask) #define GDT_USER_DATA_OFFSET 0x23 // User data segment offset in GDT (with ring3 mask) +#define RING(regs) ((regs->cs) & 3) + #define PROC_MAX_BLOCK_IDS 16 #define PROC_BLOCK_MAGIC 0x00528491 @@ -60,7 +62,11 @@ struct proc { struct stack *messages; struct list *memory; - u32 ticks; + struct { + u32 user; + u32 kernel; + } ticks; + struct { u8 val; u8 cnt; |