diff options
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | apps/Makefile | 4 | ||||
-rw-r--r-- | apps/init.c | 8 | ||||
-rw-r--r-- | apps/link.ld | 2 | ||||
-rw-r--r-- | kernel/Makefile | 2 | ||||
-rw-r--r-- | kernel/drivers/keyboard.c | 2 | ||||
-rw-r--r-- | kernel/drivers/vesa.c | 2 | ||||
-rw-r--r-- | kernel/features/proc.asm | 7 | ||||
-rw-r--r-- | kernel/features/proc.c | 13 | ||||
-rw-r--r-- | lib/inc/assert.h | 11 | ||||
-rw-r--r-- | libc/Makefile (renamed from lib/Makefile) | 0 | ||||
-rw-r--r-- | libc/conv.c (renamed from lib/conv.c) | 0 | ||||
-rw-r--r-- | libc/cpu.c (renamed from lib/cpu.c) | 0 | ||||
-rw-r--r-- | libc/inc/arg.h (renamed from lib/inc/arg.h) | 0 | ||||
-rw-r--r-- | libc/inc/assert.h | 14 | ||||
-rw-r--r-- | libc/inc/conv.h (renamed from lib/inc/conv.h) | 0 | ||||
-rw-r--r-- | libc/inc/cpu.h (renamed from lib/inc/cpu.h) | 0 | ||||
-rw-r--r-- | libc/inc/def.h (renamed from lib/inc/def.h) | 0 | ||||
-rw-r--r-- | libc/inc/list.h (renamed from lib/inc/list.h) | 0 | ||||
-rw-r--r-- | libc/inc/math.h (renamed from lib/inc/math.h) | 0 | ||||
-rw-r--r-- | libc/inc/mem.h (renamed from lib/inc/mem.h) | 0 | ||||
-rw-r--r-- | libc/inc/print.h (renamed from lib/inc/print.h) | 0 | ||||
-rw-r--r-- | libc/inc/serial.h (renamed from lib/inc/serial.h) | 0 | ||||
-rw-r--r-- | libc/inc/str.h (renamed from lib/inc/str.h) | 0 | ||||
-rw-r--r-- | libc/inc/sys.h (renamed from lib/inc/sys.h) | 0 | ||||
-rw-r--r-- | libc/list.c (renamed from lib/list.c) | 0 | ||||
-rw-r--r-- | libc/math.c (renamed from lib/math.c) | 0 | ||||
-rw-r--r-- | libc/mem.c (renamed from lib/mem.c) | 0 | ||||
-rw-r--r-- | libc/print.c (renamed from lib/print.c) | 0 | ||||
-rw-r--r-- | libc/serial.c (renamed from lib/serial.c) | 0 | ||||
-rw-r--r-- | libc/str.c (renamed from lib/str.c) | 0 | ||||
-rw-r--r-- | libc/sys.c (renamed from lib/sys.c) | 0 | ||||
-rw-r--r-- | libgui/Makefile | 21 | ||||
-rw-r--r-- | libgui/inc/vesa.h | 57 | ||||
-rw-r--r-- | libgui/vesa.c | 42 | ||||
-rwxr-xr-x | run | 7 |
36 files changed, 174 insertions, 30 deletions
@@ -3,16 +3,18 @@ all: compile clean compile: - @$(MAKE) clean --no-print-directory -C lib/ - @$(MAKE) libc --no-print-directory -C lib/ + @$(MAKE) clean --no-print-directory -C libc/ + @$(MAKE) libc --no-print-directory -C libc/ @echo "Compiled libc" - @$(MAKE) clean --no-print-directory -C lib/ - @$(MAKE) libk --no-print-directory -C lib/ + @$(MAKE) clean --no-print-directory -C libc/ + @$(MAKE) libk --no-print-directory -C libc/ @echo "Compiled libk" + @$(MAKE) --no-print-directory -C libgui/ + @echo "Compiled libgui" @$(MAKE) --no-print-directory -C kernel/ @echo "Compiled kernel" @$(MAKE) --no-print-directory -C apps/ @echo "Compiled apps" clean: - @find kernel/ apps/ lib/ \( -name "*.o" -or -name "*.a" -or -name "*.elf" -or -name "*.bin" \) -type f -delete + @find kernel/ apps/ libc/ \( -name "*.o" -or -name "*.a" -or -name "*.elf" -or -name "*.bin" \) -type f -delete diff --git a/apps/Makefile b/apps/Makefile index 7678a0b..8f9408e 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -8,14 +8,14 @@ OC = ../cross/opt/bin/i686-elf-objcopy # Flags to make the binary smaller TODO: Remove after indirect pointer support! CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os -CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -ffunction-sections -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Wl,-emain -I../lib/inc/ -Wl,-emain -fPIE -Duserspace +CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -ffunction-sections -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Wl,-emain -I../libc/inc/ -I../libgui/inc/ -Wl,-emain -fPIE -Duserspace all: $(COBJS) %.o: %.c @mkdir -p ../build/apps/ @$(CC) -c $(CFLAGS) $< -o $@ - @$(LD) -o $(@:.o=.elf) -Tlink.ld -L../build/ $@ -lc + @$(LD) -o $(@:.o=.elf) -Tlink.ld -L../build/ $@ -lc -lgui @$(OC) -O binary $(@:.o=.elf) ../build/apps/$(@:.o=) # %.o: %.c diff --git a/apps/init.c b/apps/init.c index 5e88eff..0ae4fd9 100644 --- a/apps/init.c +++ b/apps/init.c @@ -5,12 +5,14 @@ #include <mem.h> #include <print.h> #include <sys.h> +#include <vesa.h> -void main() +void main(struct vbe *vbe) { print("Init loaded.\n"); + printf("VBE: %dx%d\n", vbe->width, vbe->height); - exec("/a"); - exec("/b"); + /* exec("/a"); */ + /* exec("/b"); */ exit(); } diff --git a/apps/link.ld b/apps/link.ld index 7a451ba..84b2e2f 100644 --- a/apps/link.ld +++ b/apps/link.ld @@ -4,7 +4,7 @@ ENTRY(main) SECTIONS { - . = 0x00400000; + . = 0x00000000; .text : { *(.text.main) diff --git a/kernel/Makefile b/kernel/Makefile index fa6d790..8544be4 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -22,7 +22,7 @@ AS = nasm # Flags to make the binary smaller TODO: Remove after indirect pointer support! CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os -CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Wl,-ekernel_main -I../lib/inc/ -Iinc/ -Dkernel +CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Wl,-ekernel_main -I../libc/inc/ -Iinc/ -Dkernel ASFLAGS = -f elf32 -O3 diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c index 38ff1f7..d9ac5bb 100644 --- a/kernel/drivers/keyboard.c +++ b/kernel/drivers/keyboard.c @@ -1,3 +1,5 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + #include <cpu.h> #include <def.h> #include <gui.h> diff --git a/kernel/drivers/vesa.c b/kernel/drivers/vesa.c index 9402664..2d3e107 100644 --- a/kernel/drivers/vesa.c +++ b/kernel/drivers/vesa.c @@ -1,3 +1,5 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + #include <def.h> #include <vesa.h> diff --git a/kernel/features/proc.asm b/kernel/features/proc.asm index 3d6bbc4..1a2ba65 100644 --- a/kernel/features/proc.asm +++ b/kernel/features/proc.asm @@ -1,11 +1,14 @@ %define USER_CODE_SEGMENT 0x18 %define USER_DATA_SEGMENT 0x20 %define RING3_MASK 0b11 +%define INTERRUPT_FLAG 0x200 global proc_jump_userspace extern _esp extern _eip proc_jump_userspace: + cli + mov ax, USER_DATA_SEGMENT | RING3_MASK mov ds, ax mov es, ax @@ -17,7 +20,9 @@ proc_jump_userspace: push eax pushf - sti + pop eax + or eax, INTERRUPT_FLAG + push eax push USER_CODE_SEGMENT | RING3_MASK push dword [_eip] diff --git a/kernel/features/proc.c b/kernel/features/proc.c index 40a52f8..76ec16e 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -1,5 +1,6 @@ // MIT License, Copyright (c) 2020 Marvin Borner +#include <assert.h> #include <cpu.h> #include <interrupts.h> #include <load.h> @@ -8,6 +9,7 @@ #include <proc.h> #include <str.h> #include <timer.h> +#include <vesa.h> u32 pid = 0; struct proc *root; @@ -26,11 +28,14 @@ void scheduler(struct regs *regs) else current = root; - while (current->state == PROC_ASLEEP) - if (!current->next) + while (current->state == PROC_ASLEEP) { + if (!current->next) { + assert(root->state == PROC_RUNNING || pid > 1); current = root; - else + } else { current = current->next; + } + } /* proc_print(); */ memcpy(regs, ¤t->regs, sizeof(struct regs)); @@ -104,5 +109,7 @@ void proc_init() _eip = root->regs.eip; _esp = root->regs.esp; + ((u32 *)_esp)[1] = (u32)vbe; // First argument + proc_jump_userspace(); } diff --git a/lib/inc/assert.h b/lib/inc/assert.h deleted file mode 100644 index 2cb095b..0000000 --- a/lib/inc/assert.h +++ /dev/null @@ -1,11 +0,0 @@ -// MIT License, Copyright (c) 2020 Marvin Borner - -#ifndef ASSERT_H -#define ASSERT_H - -#include <print.h> - -#define assert(exp) \ - (exp) ? 0 : printf("%s:%d: %s: Assertion '%s' failed\n", __FILE__, __LINE__, __func__, #exp) - -#endif diff --git a/lib/Makefile b/libc/Makefile index f4286ae..f4286ae 100644 --- a/lib/Makefile +++ b/libc/Makefile diff --git a/lib/inc/arg.h b/libc/inc/arg.h index 73e592d..73e592d 100644 --- a/lib/inc/arg.h +++ b/libc/inc/arg.h diff --git a/libc/inc/assert.h b/libc/inc/assert.h new file mode 100644 index 0000000..91c4ccd --- /dev/null +++ b/libc/inc/assert.h @@ -0,0 +1,14 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#ifndef ASSERT_H +#define ASSERT_H + +#include <print.h> + +#define assert(exp) \ + if (!(exp)) { \ + printf("%s:%d: %s: Assertion '%s' failed\n", __FILE__, __LINE__, __func__, #exp); \ + __asm__ volatile("cli\nhlt"); \ + } + +#endif diff --git a/lib/inc/conv.h b/libc/inc/conv.h index d878deb..d878deb 100644 --- a/lib/inc/conv.h +++ b/libc/inc/conv.h diff --git a/lib/inc/cpu.h b/libc/inc/cpu.h index 2d367cb..2d367cb 100644 --- a/lib/inc/cpu.h +++ b/libc/inc/cpu.h diff --git a/lib/inc/def.h b/libc/inc/def.h index 42939a0..42939a0 100644 --- a/lib/inc/def.h +++ b/libc/inc/def.h diff --git a/lib/inc/list.h b/libc/inc/list.h index 5deaf59..5deaf59 100644 --- a/lib/inc/list.h +++ b/libc/inc/list.h diff --git a/lib/inc/math.h b/libc/inc/math.h index 268e3e7..268e3e7 100644 --- a/lib/inc/math.h +++ b/libc/inc/math.h diff --git a/lib/inc/mem.h b/libc/inc/mem.h index 0030b3d..0030b3d 100644 --- a/lib/inc/mem.h +++ b/libc/inc/mem.h diff --git a/lib/inc/print.h b/libc/inc/print.h index 04668b2..04668b2 100644 --- a/lib/inc/print.h +++ b/libc/inc/print.h diff --git a/lib/inc/serial.h b/libc/inc/serial.h index 6511952..6511952 100644 --- a/lib/inc/serial.h +++ b/libc/inc/serial.h diff --git a/lib/inc/str.h b/libc/inc/str.h index 65774e7..65774e7 100644 --- a/lib/inc/str.h +++ b/libc/inc/str.h diff --git a/lib/inc/sys.h b/libc/inc/sys.h index 16d3c4f..16d3c4f 100644 --- a/lib/inc/sys.h +++ b/libc/inc/sys.h diff --git a/lib/print.c b/libc/print.c index 84c4975..84c4975 100644 --- a/lib/print.c +++ b/libc/print.c diff --git a/lib/serial.c b/libc/serial.c index 28de140..28de140 100644 --- a/lib/serial.c +++ b/libc/serial.c diff --git a/libgui/Makefile b/libgui/Makefile new file mode 100644 index 0000000..89bbb35 --- /dev/null +++ b/libgui/Makefile @@ -0,0 +1,21 @@ +# MIT License, Copyright (c) 2020 Marvin Borner + +COBJS = vesa.o +CC = ../cross/opt/bin/i686-elf-gcc +LD = ../cross/opt/bin/i686-elf-ld +OC = ../cross/opt/bin/i686-elf-ar + +# Flags to make the binary smaller TODO: Remove after indirect pointer support! +CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os + +CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Iinc/ -I../libc/inc/ -Duserspace -fPIE + +%.o: %.c + @$(CC) -c $(CFLAGS) $< -o $@ + +libgui: $(COBJS) + @mkdir -p ../build/ + @$(AR) qc ../build/libgui.a $+ + +clean: + @find . -name "*.o" -type f -delete diff --git a/libgui/inc/vesa.h b/libgui/inc/vesa.h new file mode 100644 index 0000000..e34cdc0 --- /dev/null +++ b/libgui/inc/vesa.h @@ -0,0 +1,57 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#ifndef VBE_H +#define VBE_H + +#include <def.h> + +struct vbe { + u16 attributes; + u8 window_a; + u8 window_b; + u16 granularity; + u16 window_size; + u16 segment_a; + u16 segment_b; + u32 win_func_ptr; + u16 pitch; + u16 width; + u16 height; + u8 w_char; + u8 y_char; + u8 planes; + u8 bpp; + u8 banks; + u8 memory_model; + u8 bank_size; + u8 image_pages; + u8 reserved0; + + u8 red_mask; + u8 red_position; + u8 green_mask; + u8 green_position; + u8 blue_mask; + u8 blue_position; + u8 reserved_mask; + u8 reserved_position; + u8 direct_color_attributes; + + u32 framebuffer; + u32 off_screen_mem_off; + u16 off_screen_mem_size; + u8 reserved1[206]; +}; + +struct vbe *vbe; +int vbe_width; +int vbe_height; +int vbe_bpl; +int vbe_pitch; +u8 *fb; + +void vesa_fill(const u32 color[3]); +void vesa_set_pixel(u16 x, u16 y, const u32 color[3]); +void vesa_init(struct vbe *info); + +#endif diff --git a/libgui/vesa.c b/libgui/vesa.c new file mode 100644 index 0000000..2d3e107 --- /dev/null +++ b/libgui/vesa.c @@ -0,0 +1,42 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#include <def.h> +#include <vesa.h> + +void vesa_draw_rectangle(int x1, int y1, int x2, int y2, const u32 color[3]) +{ + int pos1 = x1 * vbe_bpl + y1 * vbe_pitch; + u8 *draw = &fb[pos1]; + for (int i = 0; i <= y2 - y1; i++) { + for (int j = 0; j <= x2 - x1; j++) { + draw[vbe_bpl * j] = color[2]; + draw[vbe_bpl * j + 1] = color[1]; + draw[vbe_bpl * j + 2] = color[0]; + } + draw += vbe_pitch; + } +} + +void vesa_set_pixel(u16 x, u16 y, const u32 color[3]) +{ + u8 pos = x * vbe_bpl + y * vbe_pitch; + u8 *draw = &fb[pos]; + draw[pos] = (char)color[2]; + draw[pos + 1] = (char)color[1]; + draw[pos + 2] = (char)color[0]; +} + +void vesa_fill(const u32 color[3]) +{ + vesa_draw_rectangle(0, 0, vbe->width - 1, vbe->height - 1, color); +} + +void vesa_init(struct vbe *info) +{ + vbe = info; + vbe_height = vbe->height; + vbe_width = vbe->width; + vbe_bpl = vbe->bpp >> 3; + vbe_pitch = vbe->pitch; + fb = (u8 *)vbe->framebuffer; +} @@ -125,12 +125,13 @@ ${data}" } make_sync() { - ctags -R --exclude=.git --exclude=build --exclude=iso --exclude=cross . + ctags -R --exclude=.git --exclude=build --exclude=disk --exclude=cross --exclude=ext2util . rm -f compile_commands.json output=$(make --always-make --dry-run) - echo "$output" | make_append_commands libc libk lib - echo "$output" | make_append_commands libk kernel kernel + echo "$output" | make_append_commands libc libk libc + echo "$output" | make_append_commands libk libgui libgui + echo "$output" | make_append_commands libgui kernel kernel echo "$output" | make_append_commands kernel apps apps tr <compile_commands.json '\n' '\r' | sed -e 's/\r]\r\[/,/g' | tr '\r' '\n' >tmp mv tmp compile_commands.json |