diff options
| -rw-r--r-- | include/stdarg.h | 6 | ||||
| -rw-r--r-- | include/stdbool.h | 6 | ||||
| -rw-r--r-- | include/stdint.h | 6 | ||||
| -rw-r--r-- | include/sys/types.h | 20 | ||||
| -rw-r--r-- | kernel/Makefile | 5 | ||||
| -rw-r--r-- | kernel/boot.s | 6 | ||||
| -rw-r--r-- | kernel/kmain.c | 22 | ||||
| -rw-r--r-- | kernel/link.ld | 3 | ||||
| -rw-r--r-- | kernel/usrbin/Makefile | 17 | ||||
| -rw-r--r-- | kernel/usrbin/usrbin.bin | bin | 0 -> 76 bytes | |||
| -rw-r--r-- | kernel/usrbin/usrbin.s | 32 | ||||
| -rw-r--r-- | kernel/usrspace.s | 42 |
12 files changed, 128 insertions, 37 deletions
diff --git a/include/stdarg.h b/include/stdarg.h index 8eb1341..fad14cc 100644 --- a/include/stdarg.h +++ b/include/stdarg.h @@ -1,9 +1,3 @@ -/* - * stdarg.h - * - * Provides va_list and associated functions - */ - #ifndef _STDARG_H #define _STDARG_H diff --git a/include/stdbool.h b/include/stdbool.h index f96b223..84950f3 100644 --- a/include/stdbool.h +++ b/include/stdbool.h @@ -1,9 +1,3 @@ -/* - * stdbool.h - * - * Defines bool, true and false - */ - #ifndef _STDBOOL_H #define _STDBOOL_H diff --git a/include/stdint.h b/include/stdint.h index 3dc068e..544f83c 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -1,9 +1,3 @@ -/* - * stdint.h - * - * Common integer types - */ - #ifndef _STDINT_H #define _STDINT_H diff --git a/include/sys/types.h b/include/sys/types.h new file mode 100644 index 0000000..ace1a62 --- /dev/null +++ b/include/sys/types.h @@ -0,0 +1,20 @@ +#ifndef _SYS_TYPES_H +#define _SYS_TYPES_H + +#include <stdint.h> + +#ifndef NULL +#define NULL ((void*) 0) +#endif + +#ifndef _SIZE_T +#define _SIZE_T +typedef uint32_t size_t; +#endif + +#ifndef _TIME_T +#define _TIME_T +typedef int32_t time_t; +#endif + +#endif diff --git a/kernel/Makefile b/kernel/Makefile index 0f3ac41..3427449 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -2,7 +2,7 @@ TARGET = kernel SRCS = $(wildcard *.c) ASMS = $(wildcard *.s) -OBJS = $(SRCS:.c=.o) $(ASMS:.s=.o) +OBJS = $(SRCS:.c=.o) $(ASMS:.s=.o) usrbin/usrbin.o CFLAGS = -m32 -I../include -ffreestanding -nostdinc -nostdlib -fno-stack-protector -gstabs+ LDFLAGS = -m elf_i386 -Tlink.ld @@ -16,6 +16,9 @@ all: build build: $(TARGET) +usrbin/usrbin.o: usrbin/usrbin.s + make -C usrbin + .s.o: $(ASM) -o $*.o $^ diff --git a/kernel/boot.s b/kernel/boot.s index e41c0b2..024abf0 100644 --- a/kernel/boot.s +++ b/kernel/boot.s @@ -17,11 +17,14 @@ kboot: cli call flush_gdt call flush_idt - call timer_init + ;call timer_init call kmain cli hlt +tss: + times 104 db 0 + gdt: ; null descriptor dq 0 @@ -53,6 +56,7 @@ gdt: db 0xF2 db 0xCF db 0x00 + ; task state segment gdtp: dw ($-gdt-1) diff --git a/kernel/kmain.c b/kernel/kmain.c index 5b10ee1..81fe741 100644 --- a/kernel/kmain.c +++ b/kernel/kmain.c @@ -1,27 +1,17 @@ -#include <asm/io.h> #include <kernel/con.h> #include <stdint.h> +#include <sys/types.h> -uint32_t ticks = 0; -#define millis() \ - (ticks * 10) +uint32_t ticks = 0; -void sleep(int ms) { - uint64_t t = millis() + ms; - while(millis() < t); -} +extern void userspace_init(void); void kmain(void) { con_init(); - printf("Kernel booting...\n"); - printf("Kernel booted!\n"); - - printf("PIC1 Mask: 0x%02x\n", inb(0x21)); + printf("Kernel booting...\n\n"); + printf("\nKernel booted!\n"); - while(1) { - sleep(500); - printf("Reliable 500ms tick!\n"); - } + userspace_init(); } diff --git a/kernel/link.ld b/kernel/link.ld index 67ae357..a97b27f 100644 --- a/kernel/link.ld +++ b/kernel/link.ld @@ -3,7 +3,8 @@ OUTPUT_FORMAT(elf32-i386) ENTRY(kboot) SECTIONS { - . = 0x100000; + /* . = 0x100000; */ + . = 0; .mboothdr : { *(.mboothdr) } .text : { *(.text) } .data : { *(.data) } diff --git a/kernel/usrbin/Makefile b/kernel/usrbin/Makefile new file mode 100644 index 0000000..dfd1b84 --- /dev/null +++ b/kernel/usrbin/Makefile @@ -0,0 +1,17 @@ +TARGET = usrbin.o + +ASM = nasm + +all: build + +build: $(TARGET) + +usrbin.bin: usrbin.s + $(ASM) -f bin -o usrbin.bin usrbin.s + +$(TARGET): usrbin.bin + objcopy -I binary -O elf32-i386 -B i386 usrbin.bin usrbin.o + +clean: + rm -f usrbin.bin + rm -f $(TARGET) diff --git a/kernel/usrbin/usrbin.bin b/kernel/usrbin/usrbin.bin Binary files differnew file mode 100644 index 0000000..a7d7730 --- /dev/null +++ b/kernel/usrbin/usrbin.bin diff --git a/kernel/usrbin/usrbin.s b/kernel/usrbin/usrbin.s new file mode 100644 index 0000000..91dd94a --- /dev/null +++ b/kernel/usrbin/usrbin.s @@ -0,0 +1,32 @@ +bits 32 +org 0x100000 + +main: + push .msg + call puts + add esp, 4 +.loop: + ; loop forever + jmp .loop +.msg: db "Hello World from Userspace!", 0 + +puts: + push ebp + mov ebp, esp + push esi + push edi + mov esi, [ebp+8] + mov edi, 0xB8000 +.loop: + lodsb + cmp al, 0 + je .end + mov [edi], al + mov byte [edi+1], 0x07 + add edi, 2 + jmp .loop +.end: + pop edi + pop esi + pop ebp + ret diff --git a/kernel/usrspace.s b/kernel/usrspace.s new file mode 100644 index 0000000..e52f2e0 --- /dev/null +++ b/kernel/usrspace.s @@ -0,0 +1,42 @@ +global userspace_init +extern _binary_usrbin_bin_start +extern _binary_usrbin_bin_size + +userspace_init: + push ebp + mov ebp, esp + push esi + push edi + mov ecx, _binary_usrbin_bin_size + mov esi, _binary_usrbin_bin_start + mov edi, 0x100000 +.loop: + movsb + dec ecx + jz .end + jmp .loop +.end: + pop edi + pop esi + call usrcall + pop ebp + ret + +usrcall: + push ebp + mov ebp, esp + cli + mov ax, 0x23 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov eax, esp + push dword 0x23 + push eax + pushf + push dword 0x1B + push dword 0x00100000 + iret + pop ebp + ret |
