Permalink
Browse files

stuffff

  • Loading branch information...
1 parent 60398f5 commit 5e0e21b1f88cc953c4a6cc88e22520e67675cdfd @charliesome committed Apr 9, 2011
View
@@ -10,7 +10,7 @@ floppy_bootsig_check: disabled=0
# no floppya
# no floppyb
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
-ata0-master: type=disk, mode=flat, translation=auto, path="hdd.img", cylinders=65, heads=16, spt=63, biosdetect=auto, model="Generic 1234"
+ata0-master: type=disk, mode=flat, translation=auto, path="ramdrive/hdd.img", cylinders=65, heads=16, spt=63, biosdetect=auto, model="Generic 1234"
ata2: enabled=0
ata3: enabled=0
parport1: enabled=1, file=""
View
113 build.sh
@@ -1,87 +1,92 @@
#!/bin/bash
-rm bin/*
+rm kbin/*
for f in $(find build | grep "/\."); do
rm $f
done
-CFLAGS="-std=c99 -iquote kinc -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-stack-protector -c -masm=intel $1"
+CFLAGS="-std=c99 -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-stack-protector -c -masm=intel "
+KCFLAGS="-iquote kinc $CFLAGS $1"
+USERCFLAGS="-Iuinc $CFLAGS"
-nasm -f elf -o bin/aaa_loader_asm.o ksrc/loader.asm
-nasm -f elf -o bin/helper_asm.o ksrc/helper.asm
-nasm -f elf -o bin/panic_asm.o ksrc/panic.asm
-nasm -f elf -o bin/isrs_asm.o ksrc/isrs.asm
-nasm -f elf -o bin/task_asm.o ksrc/task.asm
-nasm -f elf -o bin/syscall_asm.o ksrc/syscall.asm
+nasm -f elf -o kbin/aaa_loader_asm.o ksrc/loader.asm
+nasm -f elf -o kbin/helper_asm.o ksrc/helper.asm
+nasm -f elf -o kbin/panic_asm.o ksrc/panic.asm
+nasm -f elf -o kbin/isrs_asm.o ksrc/isrs.asm
+nasm -f elf -o kbin/task_asm.o ksrc/task.asm
+nasm -f elf -o kbin/syscall_asm.o ksrc/syscall.asm
+
+#build the CRT
+nasm -f elf -o user/crt.o user/crt/csos.asm
#user mode crap
-nasm -f bin -o build/init.bin user/init.asm
-nasm -f bin -o build/a.bin user/a.asm
-nasm -f bin -o build/b.bin user/b.asm
+ rm ubin/*
+ gcc $USERCFLAGS user/init.c -o ubin/init.o
+ ld -T user_linker.ld -o build/init.bin ubin/*.o
gcc -std=c99 -o util/bin2nasm util/bin2nasm.c
# custom binaries to include in image!!
# realmode.bin
- nasm -f bin -o bin/realmode_asm.bin ksrc/realmode/realmode.asm
- util/bin2nasm code16 < bin/realmode_asm.bin > bin/tmp.asm
- nasm -f elf -o bin/realmode_asm.o bin/tmp.asm
- rm bin/tmp.asm
+ nasm -f bin -o kbin/realmode_asm.bin ksrc/realmode/realmode.asm
+ util/bin2nasm code16 < kbin/realmode_asm.bin > kbin/tmp.asm
+ nasm -f elf -o kbin/realmode_asm.o kbin/tmp.asm
+ rm kbin/tmp.asm
# ata.bin
- nasm -f bin -o bin/realmode_ata.bin ksrc/realmode/ata.asm
- util/bin2nasm ata16 < bin/realmode_ata.bin > bin/tmp.asm
- nasm -f elf -o bin/realmode_ata.o bin/tmp.asm
- rm bin/tmp.asm
+ nasm -f bin -o kbin/realmode_ata.bin ksrc/realmode/ata.asm
+ util/bin2nasm ata16 < kbin/realmode_ata.bin > kbin/tmp.asm
+ nasm -f elf -o kbin/realmode_ata.o kbin/tmp.asm
+ rm kbin/tmp.asm
# int.bin
- nasm -f bin -o bin/realmode_int.bin ksrc/realmode/int.asm
- util/bin2nasm int16 < bin/realmode_int.bin > bin/tmp.asm
- nasm -f elf -o bin/realmode_int.o bin/tmp.asm
- rm bin/tmp.asm
-
-gcc $CFLAGS ksrc/main.c -o bin/main.o
-gcc $CFLAGS ksrc/console.c -o bin/console.o
-gcc $CFLAGS ksrc/string.c -o bin/string.o
-gcc $CFLAGS ksrc/io.c -o bin/io.o
-gcc $CFLAGS ksrc/util.c -o bin/util.o
-gcc $CFLAGS ksrc/gdt.c -o bin/gdt.o
-gcc $CFLAGS ksrc/idt.c -o bin/idt.o
-gcc $CFLAGS ksrc/io.c -o bin/io.o
-gcc $CFLAGS ksrc/panic.c -o bin/panic.o
-gcc $CFLAGS ksrc/kmalloc.c -o bin/kmalloc.o
-gcc $CFLAGS ksrc/realmode.c -o bin/realmode.o
-gcc $CFLAGS ksrc/ata.c -o bin/ata.o
-gcc $CFLAGS ksrc/kb.c -o bin/kb.o
-gcc $CFLAGS ksrc/part.c -o bin/part.o
-gcc $CFLAGS ksrc/fs/fat.c -o bin/fs_fat.o
-gcc $CFLAGS ksrc/fs/vfs.c -o bin/fs_vfs.o
-gcc $CFLAGS ksrc/task.c -o bin/task.o
-gcc $CFLAGS ksrc/trap.c -o bin/trap.o
-gcc $CFLAGS ksrc/paging.c -o bin/paging.o
-gcc $CFLAGS ksrc/syscall.c -o bin/syscall.o
-
-ld -T linker.ld -o build/kernel.sys bin/*.o
+ nasm -f bin -o kbin/realmode_int.bin ksrc/realmode/int.asm
+ util/bin2nasm int16 < kbin/realmode_int.bin > kbin/tmp.asm
+ nasm -f elf -o kbin/realmode_int.o kbin/tmp.asm
+ rm kbin/tmp.asm
+
+gcc $KCFLAGS ksrc/main.c -o kbin/main.o
+gcc $KCFLAGS ksrc/console.c -o kbin/console.o
+gcc $KCFLAGS ksrc/string.c -o kbin/string.o
+gcc $KCFLAGS ksrc/io.c -o kbin/io.o
+gcc $KCFLAGS ksrc/util.c -o kbin/util.o
+gcc $KCFLAGS ksrc/gdt.c -o kbin/gdt.o
+gcc $KCFLAGS ksrc/idt.c -o kbin/idt.o
+gcc $KCFLAGS ksrc/io.c -o kbin/io.o
+gcc $KCFLAGS ksrc/panic.c -o kbin/panic.o
+gcc $KCFLAGS ksrc/kmalloc.c -o kbin/kmalloc.o
+gcc $KCFLAGS ksrc/realmode.c -o kbin/realmode.o
+gcc $KCFLAGS ksrc/ata.c -o kbin/ata.o
+gcc $KCFLAGS ksrc/kb.c -o kbin/kb.o
+gcc $KCFLAGS ksrc/part.c -o kbin/part.o
+gcc $KCFLAGS ksrc/fs/fat.c -o kbin/fs_fat.o
+gcc $KCFLAGS ksrc/fs/vfs.c -o kbin/fs_vfs.o
+gcc $KCFLAGS ksrc/task.c -o kbin/task.o
+gcc $KCFLAGS ksrc/trap.c -o kbin/trap.o
+gcc $KCFLAGS ksrc/paging.c -o kbin/paging.o
+gcc $KCFLAGS ksrc/syscall.c -o kbin/syscall.o
+
+ld -T kernel_linker.ld -o build/kernel.sys kbin/*.o
gcc -std=c99 -o util/inject_symbols util/inject_symbols.c
perl util/find_symbols.pl build/kernel.sys | util/inject_symbols build/kernel.sys
-nasm -f bin -o build/r3task.bin user/ring3.asm
+HDDIMG=ramdrive/hdd.img
-dd if=/dev/zero of=hdd.img bs=33546240 count=1 status=noxfer &>/dev/null
+dd if=/dev/zero of=$HDDIMG bs=33546240 count=1 status=noxfer &>/dev/null
-parted --script hdd.img mklabel msdos
-parted --script hdd.img mkpartfs primary fat16 0 31 &> /dev/null
-parted --script hdd.img mkfs 1 fat16 &> /dev/null
-parted --script hdd.img set 1 boot on
+parted --script $HDDIMG mklabel msdos
+parted --script $HDDIMG mkpartfs primary fat16 0 31 &> /dev/null
+parted --script $HDDIMG mkfs 1 fat16 &> /dev/null
+parted --script $HDDIMG set 1 boot on
rm -rf mnt
mkdir mnt
-mount -o loop,offset=512 hdd.img mnt
+mount -o loop,offset=512 $HDDIMG mnt
cp -r build/* mnt
umount mnt
rm -rf mnt
grub --device-map=/dev/null --batch < grubscript &> /dev/null
-gzip -c -9 hdd.img > hdd.img.gz
+#gzip -c -9 $HDDIMG > hdd.img.gz
View
Binary file not shown.
View
@@ -1,4 +1,4 @@
-device (hd0) hdd.img
+device (hd0) ramdrive/hdd.img
root (hd0,0)
setup (hd0,0)
View
Binary file not shown.
View
0 linker.ld → kernel_linker.ld 100644 → 100755
File renamed without changes.
View
@@ -2,6 +2,7 @@
#define CONSOLE_H
#include "stddef.h"
+#include "fs/vfs.h"
typedef enum color
{
@@ -24,6 +25,8 @@ typedef enum color
}
color_t;
+vfs_stream_t* console_stdout();
+
void kprint(char* str);
void kprintc(color_t bg, color_t fg, char* str);
void kprintf(char* fmt, ...);
View
@@ -12,18 +12,23 @@ typedef enum vfs_type
}
vfs_type_t;
-typedef struct vfs_file
+typedef enum vfs_seek
{
- char* name;
- size_t size;
+ VFS_SEEK_SET,
+ VFS_SEEK_CUR,
+ VFS_SEEK_END,
}
-vfs_file_t;
+vfs_seek_t;
-typedef struct vfs_dir
+typedef struct vfs_stream
{
- char* name;
+ void* state;
+ void(*seek)(void*, int /* signed offset */, vfs_seek_t);
+ uint(*read)(void*, uint /* len */, void* /* buffer */);
+ uint(*write)(void*, uint /* len */, void* /* buffer */);
+ void(*close)(void*);
}
-vfs_dir_t;
+vfs_stream_t;
typedef struct vfs_provider
{
@@ -42,6 +47,8 @@ void vfs_init(vfs_provider_t* root_fs);
bool vfs_exists(char* path);
vfs_type_t vfs_type(char* path);
size_t vfs_size(char* path);
+vfs_stream_t* vfs_open(char* path);
+void vfs_close(vfs_stream_t* stream);
uint vfs_readdir(char* dir, void* state, bool(*callback)(void*, char*, vfs_type_t));
uint vfs_readfile(char* path, uint offset, size_t length, void* buffer);
View
@@ -3,6 +3,18 @@
#include "task.h"
+void sys_alloc_page(regs_t* registers);
+void sys_free_page(regs_t* registers);
+void sys_exit(regs_t* registers);
+void sys_kill(regs_t* registers);
+void sys_get_pid(regs_t* registers);
+void sys_fork(regs_t* registers);
+void sys_write(regs_t* registers);
+void sys_read(regs_t* registers);
+void sys_open(regs_t* registers);
+void sys_close(regs_t* registers);
+void sys_write_ebx(regs_t* registers);
+
void syscall_handler(regs_t* registers);
void syscall_isr();
View
@@ -3,6 +3,9 @@
#include "stddef.h"
#include "stdbool.h"
+#include "fs/vfs.h"
+
+#define MAX_FDS 64
typedef struct tss
{
@@ -66,6 +69,8 @@ typedef enum task_state
{
SLEEPING,
RUNNING,
+ IO_WAIT,
+ KILLED,
}
task_state_t;
@@ -77,6 +82,7 @@ typedef struct task
uint* page_directory;
task_state_t state;
char kernel_stack[8192];
+ vfs_stream_t* fds[MAX_FDS];
}
__attribute__((__packed__)) /* so i can access the struct straight from assembly */ task_t;
@@ -101,6 +107,7 @@ void task_init(uint base_physical, uint high_memory);
uint alloc_page();
void free_page(uint page);
task_t* task_create(uint size, void* code, uint stack_size);
+void task_kill_and_free(task_t* task);
uint task_add_page(task_t* task);
void task_del_page(task_t* task, uint virtual);
void task_add_virtual(task_t*, uint virtual);
View
@@ -3,4 +3,29 @@
void trap_init();
+typedef enum trap
+{
+ TRAP_DIVIDE_BY_ZERO = 0,
+ TRAP_DEBUG = 1,
+ TRAP_NMI = 2,
+ TRAP_BREAKPOINT = 3,
+ TRAP_OVERFLOW = 4,
+ TRAP_BOUND_RANGE_EXCEEDED = 5,
+ TRAP_INVALID_OPCODE = 6,
+ TRAP_DEVICE_NOT_AVAILABLE = 7,
+ TRAP_DOUBLE_FAULT = 8,
+ TRAP_COPROCESSOR_SEG_OVERRUN = 9,
+ TRAP_INVALID_TSS = 10,
+ TRAP_SEGMENT_NOT_PRESENT = 11,
+ TRAP_STACK_SEG_FAULT = 12,
+ TRAP_GPF = 13,
+ TRAP_PAGE_FAULT = 14,
+ TRAP_FLOAT_X87 = 16,
+ TRAP_ALIGN = 17,
+ TRAP_MACHINE = 18,
+ TRAP_FLOAT_SIMD = 19,
+ TRAP_SECURITY = 30,
+}
+trap_t;
+
#endif
View
@@ -2,6 +2,9 @@
#include "string.h"
#include "io.h"
#include "stdarg.h"
+#include "kmalloc.h"
+
+#define UNUSED __attribute__((unused))
static uint col = 0;
static uint row = 0;
@@ -13,6 +16,37 @@ static char* vram = (char*)0xb8000;
//extern char bin_console16[];
//extern size_t bin_console16_len;
+vfs_stream_t console_stdout_stream;
+vfs_stream_t* console_stdout()
+{
+ return &console_stdout_stream;
+}
+
+static uint console_vfs_read(UNUSED void* state, UNUSED uint len, UNUSED void* buffer)
+{
+ return 0;
+}
+
+static uint console_vfs_write(UNUSED void* state, uint len, void* buffer)
+{
+ for(uint i = 0; i < len; i++)
+ {
+ if(((char*)buffer)[i] == 0)
+ {
+ kprint(buffer);
+ return len;
+ }
+ }
+ char* new = (char*)kmalloc(len + 1);
+ memcpy(new, buffer, len);
+ new[len] = 0;
+ kprint(buffer);
+ return len;
+}
+
+static void console_vfs_seek(UNUSED void* state, UNUSED int offset, UNUSED vfs_seek_t seek) { }
+static void console_vfs_close(UNUSED void* state) { }
+
static void console_cursor(uint col, uint row)
{
ushort pos = (row * width) + col;
@@ -28,6 +62,10 @@ static void console_cursor(uint col, uint row)
void console_init()
{
console_cursor(col, row);
+ console_stdout_stream.read = console_vfs_read;
+ console_stdout_stream.write = console_vfs_write;
+ console_stdout_stream.seek = console_vfs_seek;
+ console_stdout_stream.close = console_vfs_close;
}
void console_gotoxy(uint x, uint y)
Oops, something went wrong.

0 comments on commit 5e0e21b

Please sign in to comment.