aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-10-26 16:36:40 +0100
committerMarvin Borner2020-10-26 16:36:40 +0100
commit197ea3ca20879b29fca41a07cf43e5b04b9c5083 (patch)
treec0e0223e289bde3af7cca995f98d681779bfda26
parent4ae48304b2290b6c835eb3d937bd5e905ce0e5d4 (diff)
Optimizations
-rw-r--r--Makefile6
-rw-r--r--apps/window.c1
-rw-r--r--apps/wm.c6
-rw-r--r--kernel/drivers/fpu.c2
-rw-r--r--kernel/drivers/ide.c2
-rw-r--r--kernel/drivers/interrupts.c17
-rw-r--r--kernel/drivers/timer.c4
-rw-r--r--kernel/features/event.c2
-rw-r--r--kernel/features/fs.c10
-rw-r--r--kernel/features/proc.c7
-rw-r--r--kernel/main.c2
-rw-r--r--libgui/gfx.c46
12 files changed, 51 insertions, 54 deletions
diff --git a/Makefile b/Makefile
index e5dba45..91abfaf 100644
--- a/Makefile
+++ b/Makefile
@@ -3,8 +3,10 @@
# Kernel optimization
OPTIMIZATION = -Ofast
-# Remove tree optimizations for kernel - TODO: Why?
-CFLAGS_EXTRA = -fno-tree-bit-ccp -fno-tree-builtin-call-dce -fno-tree-ccp -fno-tree-ch -fno-tree-coalesce-vars -fno-tree-copy-prop -fno-tree-dce -fno-tree-dominator-opts -fno-tree-dse -fno-tree-fre -fno-tree-pta -fno-tree-sink -fno-tree-slsr -fno-tree-sra -fno-tree-ter
+# Remove tree optimizations for kernel - TODO: Why?!
+CFLAGS_EXTRA = -fno-tree-bit-ccp -fno-tree-builtin-call-dce -fno-tree-ccp -fno-tree-ch -fno-tree-coalesce-vars -fno-tree-copy-prop -fno-tree-dce -fno-tree-dominator-opts -fno-tree-dse -fno-tree-fre -fno-tree-pta -fno-tree-sink -fno-tree-slsr -fno-tree-sra -fno-tree-ter -fno-tree-loop-vectorize -fno-inline-functions -fno-inline-functions-called-once
+# Remove ipa optimizations for kernel - TODO: Why?!?!
+CFLAGS_EXTRA += -fno-inline-functions -fno-inline-functions-called-once -fno-reorder-functions -fno-reorder-blocks -fno-reorder-blocks-and-partition -fno-ipa-profile -fno-ipa-pure-const -fno-ipa-reference -fno-ipa-reference-addressable -fno-merge-constants -fno-ipa-bit-cp -fno-ipa-cp -fno-ipa-icf -fno-ipa-ra -fno-ipa-sra -fno-ipa-vrp -fno-ipa-cp-clone
export
diff --git a/apps/window.c b/apps/window.c
index f8e2723..6c360f8 100644
--- a/apps/window.c
+++ b/apps/window.c
@@ -20,6 +20,7 @@ int main()
struct element *container = gui_init("test", 0, 0);
struct element_button *button =
gui_add_button(container, 10, 10, FONT_24, "Baum!", COLOR_WHITE, COLOR_BLACK);
+ gfx_border(container->ctx, COLOR_FG, 2);
button->on_click = on_click;
diff --git a/apps/wm.c b/apps/wm.c
index 954ec4e..ed1a4dd 100644
--- a/apps/wm.c
+++ b/apps/wm.c
@@ -74,13 +74,15 @@ static void redraw_all()
struct node *iterator = contexts->head;
while (iterator != NULL) {
struct context *ctx = iterator->data;
- if (ctx != focused && !(ctx->flags & WF_RELATIVE))
+ if (ctx != focused && !(ctx->flags & WF_RELATIVE)) {
gfx_ctx_on_ctx(&exchange, ctx, ctx->x, ctx->y);
+ }
iterator = iterator->next;
}
- if (focused)
+ if (focused) {
gfx_ctx_on_ctx(&exchange, focused, focused->x, focused->y);
+ }
memcpy(direct.fb, exchange.fb, exchange.pitch * exchange.height);
}
diff --git a/kernel/drivers/fpu.c b/kernel/drivers/fpu.c
index d8a2b79..f7eeceb 100644
--- a/kernel/drivers/fpu.c
+++ b/kernel/drivers/fpu.c
@@ -10,7 +10,7 @@ void set_fpu_cw(const u16 cw)
void fpu_install()
{
__asm__ volatile("clts");
- u32 t;
+ u32 t = 0;
__asm__ volatile("mov %%cr0, %0" : "=r"(t));
t &= ~(1 << 2);
t |= (1 << 1);
diff --git a/kernel/drivers/ide.c b/kernel/drivers/ide.c
index c1c0227..1a94ae3 100644
--- a/kernel/drivers/ide.c
+++ b/kernel/drivers/ide.c
@@ -16,7 +16,7 @@ int ide_stat()
void ide_wait()
{
- u8 stat;
+ u8 stat = 0;
do
stat = ide_stat();
while ((stat & IDE_BUSY) != 0);
diff --git a/kernel/drivers/interrupts.c b/kernel/drivers/interrupts.c
index 9088915..57b0ab5 100644
--- a/kernel/drivers/interrupts.c
+++ b/kernel/drivers/interrupts.c
@@ -6,6 +6,7 @@
#include <interrupts.h>
#include <mem.h>
#include <print.h>
+#include <proc.h>
#include <serial.h>
/**
@@ -166,18 +167,18 @@ void isr_uninstall_handler(int isr)
void isr_handler(struct regs *r)
{
- void (*handler)(struct regs * r);
-
// Execute fault handler if exists
- handler = isr_routines[r->int_no];
+ void (*handler)(struct regs * r) = isr_routines[r->int_no];
if (handler) {
handler(r);
} else if (r->int_no <= 32) {
- cli();
- printf("\n%s Exception, halting!\n", isr_exceptions[r->int_no]);
- printf("Error code: %d\n", r->err_code);
- while (1) {
- };
+ printf("%s Exception, exiting!\n", isr_exceptions[r->int_no]);
+ struct proc *proc = proc_current();
+ if (proc)
+ proc_exit(proc, 1);
+ else
+ __asm__ volatile("cli\nhlt");
+ proc_yield(r);
}
}
diff --git a/kernel/drivers/timer.c b/kernel/drivers/timer.c
index 812bde7..3bc1811 100644
--- a/kernel/drivers/timer.c
+++ b/kernel/drivers/timer.c
@@ -31,9 +31,7 @@ void timer_handler()
// "Delay" function with CPU sleep
void timer_wait(u32 ticks)
{
- u32 eticks;
-
- eticks = timer_ticks + ticks;
+ u32 eticks = timer_ticks + ticks;
while (timer_ticks < eticks) {
__asm__ volatile("sti//hlt//cli");
}
diff --git a/kernel/features/event.c b/kernel/features/event.c
index 633f633..d79d531 100644
--- a/kernel/features/event.c
+++ b/kernel/features/event.c
@@ -46,7 +46,7 @@ u32 event_trigger(u32 id, void *data)
{
assert(id < sizeof(event_table) / sizeof(*event_table));
- if (memcmp(event_table[id], 0, sizeof(struct list)) == 0 || !event_table[id]->head) {
+ if (!event_table[id] || !event_table[id]->head) {
printf("Event %d not mapped!\n", id);
return 1;
}
diff --git a/kernel/features/fs.c b/kernel/features/fs.c
index 2db0a97..c52a7b6 100644
--- a/kernel/features/fs.c
+++ b/kernel/features/fs.c
@@ -68,10 +68,10 @@ void *read_inode(struct inode *in)
printf("Loading %dKiB\n", sz >> 10);
assert(buf != NULL);
- int indirect;
+ int indirect = 0;
- int blocknum;
- char *data;
+ int blocknum = 0;
+ char *data = 0;
// TODO: Support triply indirect pointers
// TODO: This can be heavily optimized by saving the indirect block lists
for (int i = 0; i < num_blocks; i++) {
@@ -105,7 +105,7 @@ void *read_file(char *path)
path++;
u32 current_inode = EXT2_ROOT;
- int i;
+ int i = 0;
while (1) {
for (i = 0; path[i] != '/' && path[i] != '\0'; i++)
;
@@ -176,7 +176,7 @@ void ls_root()
struct dirent *d = (struct dirent *)buf;
int sum = 0;
- int calc;
+ int calc = 0;
printf("\nRoot directory:\n");
do {
calc = (sizeof(struct dirent) + d->name_len + 4) & ~0x3;
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index b6ed442..5d1a437 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -34,13 +34,14 @@ void scheduler(struct regs *regs)
assert(proc_list->head);
- memcpy(&((struct proc *)current->data)->regs, regs, sizeof(struct regs));
+ if (current)
+ memcpy(&((struct proc *)current->data)->regs, regs, sizeof(struct regs));
if (priority_proc) {
current = list_first_data(proc_list, priority_proc);
priority_proc = NULL;
assert(current);
- } else if (current->next) {
+ } else if (current && current->next) {
current = current->next;
} else {
current = proc_list->head;
@@ -76,7 +77,7 @@ void proc_print()
struct node *node = proc_list->head;
printf("\nPROCESSES\n");
- struct proc *proc;
+ struct proc *proc = NULL;
while (node && (proc = node->data)) {
printf("Process %d: %s\n", proc->pid, proc->name);
node = node->next;
diff --git a/kernel/main.c b/kernel/main.c
index 0c2a513..6e666b5 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -32,7 +32,7 @@ void kernel_main(struct vid_info *vid_info)
acpi_install();
pci_install();
interrupts_install();
- fpu_install();
+ /* fpu_install(); */
timer_install();
keyboard_install();
mouse_install();
diff --git a/libgui/gfx.c b/libgui/gfx.c
index 7e52389..13cdcd3 100644
--- a/libgui/gfx.c
+++ b/libgui/gfx.c
@@ -68,12 +68,8 @@ static void write_char(struct context *ctx, int x, int y, struct font *font, u32
for (int cx = 0; cx < font->width; cx++) {
u8 bits = font->chars[ch * font->char_size + cy * stride + cx / 8];
u8 bit = bits >> (7 - cx % 8) & 1;
- if (bit) {
- draw[bypp * cx] = GET_BLUE(c);
- draw[bypp * cx + 1] = GET_GREEN(c);
- draw[bypp * cx + 2] = GET_RED(c);
- draw[bypp * cx + 3] = GET_ALPHA(c);
- }
+ if (bit)
+ memset(&draw[bypp * cx], c, bypp);
}
draw += ctx->pitch;
}
@@ -84,12 +80,8 @@ static void draw_rectangle(struct context *ctx, int x1, int y1, int x2, int y2,
int bypp = ctx->bpp >> 3;
u8 *draw = &ctx->fb[x1 * bypp + y1 * ctx->pitch];
for (int i = 0; i < y2 - y1; i++) {
- for (int j = 0; j < x2 - x1; j++) {
- draw[bypp * j] = GET_BLUE(c);
- draw[bypp * j + 1] = GET_GREEN(c);
- draw[bypp * j + 2] = GET_RED(c);
- draw[bypp * j + 3] = GET_ALPHA(c);
- }
+ for (int j = 0; j < x2 - x1; j++)
+ memset(&draw[bypp * j], c, bypp);
draw += ctx->pitch;
}
}
@@ -148,7 +140,7 @@ void gfx_copy(struct context *dest, struct context *src, int x, int y, u32 width
u8 *srcfb = &src->fb[x * bypp + y * src->pitch];
u8 *destfb = &dest->fb[x * bypp + y * dest->pitch];
for (u32 cy = 0; cy < height; cy++) {
- memcpy(destfb, srcfb, width * (dest->bpp >> 3));
+ memcpy(destfb, srcfb, width * bypp);
srcfb += src->pitch;
destfb += dest->pitch;
}
@@ -172,16 +164,21 @@ void gfx_ctx_on_ctx(struct context *dest, struct context *src, int x, int y)
u8 *srcfb = src->fb;
u8 *destfb = &dest->fb[x * bypp + y * dest->pitch];
for (u32 cy = 0; cy < src->height && cy + y < dest->height; cy++) {
+ int diff = 0;
+ // TODO: Fix cursor
for (u32 cx = 0; cx < src->width && cx + x < dest->width; cx++) {
- if (srcfb[bypp * cx + 3]) {
- destfb[bypp * cx + 0] = srcfb[bypp * cx + 0];
- destfb[bypp * cx + 1] = srcfb[bypp * cx + 1];
- destfb[bypp * cx + 2] = srcfb[bypp * cx + 2];
- destfb[bypp * cx + 3] = srcfb[bypp * cx + 3];
+ if (srcfb[3]) {
+ destfb[0] = srcfb[0];
+ destfb[1] = srcfb[1];
+ destfb[2] = srcfb[2];
+ destfb[3] = srcfb[3];
+ srcfb += bypp;
+ destfb += bypp;
+ diff += bypp;
}
}
- srcfb += src->pitch;
- destfb += dest->pitch;
+ srcfb += src->pitch - diff;
+ destfb += dest->pitch - diff;
}
}
@@ -207,13 +204,8 @@ void gfx_border(struct context *ctx, u32 c, u32 width)
for (u32 i = 0; i < ctx->height; i++) {
for (u32 j = 0; j < ctx->width; j++) {
if (j <= width - 1 || i <= width - 1 ||
- j - ctx->width + width + 1 <= width ||
- i - ctx->height + width <= width) {
- draw[bypp * j + 0] = GET_BLUE(c);
- draw[bypp * j + 1] = GET_GREEN(c);
- draw[bypp * j + 2] = GET_RED(c);
- draw[bypp * j + 3] = GET_ALPHA(c);
- }
+ j - ctx->width + width + 1 <= width || i - ctx->height + width <= width)
+ memset(&draw[bypp * j], c, bypp);
}
draw += ctx->pitch;
}