aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-05-07 00:16:52 +0200
committerMarvin Borner2020-05-07 00:16:52 +0200
commit31767b532e69c5a63df0106fa08e137e3106a449 (patch)
treeea7a91347e030c0b120361b7d9975547a5af19d1
parent8083536f321ad8a12ad4668c2bf41a65c3e3b2f6 (diff)
Some fixes here and there...
Also implemented serial console in userspace
-rwxr-xr-xrun6
-rw-r--r--src/kernel/cmos/rtc.h2
-rw-r--r--src/kernel/gdt/gdt.c24
-rw-r--r--src/kernel/graphics/vesa.c14
-rw-r--r--src/kernel/graphics/vesa.h2
-rw-r--r--src/kernel/input/ps2/mouse.c2
-rw-r--r--src/kernel/interrupts/idt.c4
-rw-r--r--src/kernel/interrupts/interrupts.h10
-rw-r--r--src/kernel/lib/memory.c4
-rw-r--r--src/kernel/multiboot.h8
-rw-r--r--src/kernel/syscall/actions/sys_map.c2
-rw-r--r--src/kernel/syscall/syscall.c2
-rw-r--r--src/kernel/syscall/syscall.h2
-rw-r--r--src/kernel/system.h6
-rw-r--r--src/userspace/libc/stdio/putch.c16
-rw-r--r--src/userspace/programs/init.c19
16 files changed, 68 insertions, 55 deletions
diff --git a/run b/run
index c2d83df..4ab5e85 100755
--- a/run
+++ b/run
@@ -186,8 +186,7 @@ make_font() {
}
make_clean() {
- #rm -rf ./build ./iso
- rm -rf ./iso ./build/*.img ./build/*.o ./build/*.bin
+ rm -rf ./iso ./build/
}
if [ "${mode}" = "cross" ]; then
@@ -200,7 +199,6 @@ elif [ "${mode}" = "clean" ]; then
make_clean
elif [ "${mode}" = "test" ]; then
make_cross
- make_clean
make_build
make_test
elif [ "${mode}" = "again" ]; then
@@ -214,7 +212,6 @@ elif [ "${mode}" = "image_debug" ]; then
make_image_debug
elif [ "${mode}" = "image" ]; then
make_cross
- make_clean
make_build
make_image
elif [ "${mode}" = "sync" ]; then
@@ -230,7 +227,6 @@ elif [ "${mode}" = "help" ]; then
echo "./run {cross | build | clean | test | debug | image | sync | tidy | font} [-y]"
else # TODO: Prevent code duplication in build script via functions?
make_cross
- make_clean
make_build
make_test
fi
diff --git a/src/kernel/cmos/rtc.h b/src/kernel/cmos/rtc.h
index 3e52793..a277dd5 100644
--- a/src/kernel/cmos/rtc.h
+++ b/src/kernel/cmos/rtc.h
@@ -8,7 +8,7 @@ u8 minute;
u8 hour;
u8 day;
u8 month;
-unsigned int year;
+u32 year;
void read_rtc();
diff --git a/src/kernel/gdt/gdt.c b/src/kernel/gdt/gdt.c
index 616fb25..c6b329a 100644
--- a/src/kernel/gdt/gdt.c
+++ b/src/kernel/gdt/gdt.c
@@ -5,16 +5,16 @@
#include <memory/alloc.h>
struct gdt_entry {
- unsigned short limit_low;
- unsigned short base_low;
- unsigned char base_middle;
- unsigned char access;
- unsigned char granularity;
- unsigned char base_high;
+ u16 limit_low;
+ u16 base_low;
+ u8 base_middle;
+ u8 access;
+ u8 granularity;
+ u8 base_high;
} __attribute__((packed));
struct gdt_ptr {
- unsigned short limit;
+ u16 limit;
void *base;
} __attribute__((packed));
@@ -58,13 +58,13 @@ extern void gdt_flush();
void gdt_set_gate(s32 num, u32 base, u32 limit, u8 access, u8 gran)
{
// Set descriptor base address
- gdt[num].base_low = (unsigned short)(base & 0xFFFF);
- gdt[num].base_middle = (unsigned char)((base >> 16) & 0xFF);
- gdt[num].base_high = (unsigned char)((base >> 24) & 0xFF);
+ gdt[num].base_low = (u16)(base & 0xFFFF);
+ gdt[num].base_middle = (u8)((base >> 16) & 0xFF);
+ gdt[num].base_high = (u8)((base >> 24) & 0xFF);
// Set descriptor limits
- gdt[num].limit_low = (unsigned short)(limit & 0xFFFF);
- gdt[num].granularity = (unsigned char)((limit >> 16) & 0x0F);
+ gdt[num].limit_low = (u16)(limit & 0xFFFF);
+ gdt[num].granularity = (u8)((limit >> 16) & 0x0F);
// Set granularity and access flags
gdt[num].granularity |= (gran & 0xF0);
diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c
index 176b46f..b2a31d7 100644
--- a/src/kernel/graphics/vesa.c
+++ b/src/kernel/graphics/vesa.c
@@ -13,7 +13,7 @@ void vbe_error()
halt_loop();
}
-void vbe_set_mode(unsigned short mode)
+void vbe_set_mode(u16 mode)
{
regs16_t regs;
regs.ax = 0x4F02;
@@ -109,7 +109,7 @@ void set_optimal_resolution()
vbe_height = mode_info->height;
vbe_pitch = mode_info->pitch;
vbe_bpl = mode_info->bpp >> 3;
- fb = (unsigned char *)mode_info->framebuffer;
+ fb = (u8 *)mode_info->framebuffer;
}
kfree(mode_info);
}
@@ -150,7 +150,7 @@ void set_optimal_resolution()
vbe_height = mode_info->height;
vbe_pitch = mode_info->pitch;
vbe_bpl = mode_info->bpp >> 3;
- fb = (unsigned char *)mode_info->framebuffer;
+ fb = (u8 *)mode_info->framebuffer;
}
kfree(mode_info);
}
@@ -164,11 +164,11 @@ void set_optimal_resolution()
vbe_set_mode(highest);
- u32 fb_size = vbe_width * vbe_height * vbe_bpl;
+ /* u32 fb_size = vbe_width * vbe_height * vbe_bpl; */
/* cursor_buffer = kmalloc(fb_size); */
- for (u32 z = 0; z < fb_size; z += PAGE_S) {
- paging_map_user(paging_root_directory, (u32)fb + z, (u32)fb + z);
- }
+ /* for (u32 z = 0; z < fb_size; z += PAGE_S) { */
+ /* paging_map_user(paging_root_directory, (u32)fb + z, (u32)fb + z); */
+ /* } */
/* dev_make("fb", NULL, (write)fb_write); */
/* struct fs_node *node = (struct fs_node *)kmalloc(sizeof(struct fs_node)); */
diff --git a/src/kernel/graphics/vesa.h b/src/kernel/graphics/vesa.h
index c557e95..82b7553 100644
--- a/src/kernel/graphics/vesa.h
+++ b/src/kernel/graphics/vesa.h
@@ -80,7 +80,7 @@ struct vbe_mode_info {
* a video mode code
* @param mode The requested video mode code from 0x4F00 call
*/
-void vbe_set_mode(unsigned short mode);
+void vbe_set_mode(u16 mode);
/**
* Find the highest resolution using 0x4F00 and call
diff --git a/src/kernel/input/ps2/mouse.c b/src/kernel/input/ps2/mouse.c
index ce3158e..d0a0861 100644
--- a/src/kernel/input/ps2/mouse.c
+++ b/src/kernel/input/ps2/mouse.c
@@ -60,7 +60,7 @@ void mouse_handler(struct regs *r)
void mouse_wait(u8 a_type)
{
- unsigned int time_out = 100000;
+ u32 time_out = 100000;
if (a_type == 0) {
while (time_out--)
if ((inb(0x64) & 1) == 1)
diff --git a/src/kernel/interrupts/idt.c b/src/kernel/interrupts/idt.c
index 532435a..a01f1c1 100644
--- a/src/kernel/interrupts/idt.c
+++ b/src/kernel/interrupts/idt.c
@@ -10,7 +10,7 @@ struct idt_entry {
} __attribute__((packed));
struct idt_ptr {
- unsigned short limit;
+ u16 limit;
void *base;
} __attribute__((packed));
@@ -21,7 +21,7 @@ struct idt_ptr idtp;
// Defined in idt.asm
extern void idt_load();
-void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags)
+void idt_set_gate(u8 num, unsigned long base, u16 sel, u8 flags)
{
// Specify the interrupt routine's base address
idt[num].base_low = (u16)(base & 0xFFFF);
diff --git a/src/kernel/interrupts/interrupts.h b/src/kernel/interrupts/interrupts.h
index f7b5846..50fd437 100644
--- a/src/kernel/interrupts/interrupts.h
+++ b/src/kernel/interrupts/interrupts.h
@@ -16,16 +16,16 @@ void idt_install();
* @param sel The kernel code segment (0x08)
* @param flags The IDT access byte entry (P DPL 01110)
*/
-void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags);
+void idt_set_gate(u8 num, unsigned long base, u16 sel, u8 flags);
/**
* Registers that get passed into an IRQ handler
*/
struct regs {
- unsigned int gs, fs, es, ds;
- unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;
- unsigned int int_no, err_code;
- unsigned int eip, cs, eflags, useresp, ss;
+ u32 gs, fs, es, ds;
+ u32 edi, esi, ebp, esp, ebx, edx, ecx, eax;
+ u32 int_no, err_code;
+ u32 eip, cs, eflags, useresp, ss;
};
/**
diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c
index d990e6b..192e08d 100644
--- a/src/kernel/lib/memory.c
+++ b/src/kernel/lib/memory.c
@@ -24,8 +24,8 @@ void *memset(void *dest, char val, u32 count)
int memcmp(const void *a_ptr, const void *b_ptr, u32 size)
{
- const unsigned char *a = (const unsigned char *)a_ptr;
- const unsigned char *b = (const unsigned char *)b_ptr;
+ const u8 *a = (const u8 *)a_ptr;
+ const u8 *b = (const u8 *)b_ptr;
for (u32 i = 0; i < size; i++) {
if (a[i] < b[i])
return -1;
diff --git a/src/kernel/multiboot.h b/src/kernel/multiboot.h
index 19ca504..8570e69 100644
--- a/src/kernel/multiboot.h
+++ b/src/kernel/multiboot.h
@@ -18,6 +18,8 @@
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+#include <stdint.h>
+
#ifndef MULTIBOOT_HEADER
#define MULTIBOOT_HEADER 1
@@ -88,9 +90,9 @@
#ifndef ASM_FILE
-typedef unsigned char multiboot_u8;
-typedef unsigned short multiboot_u16;
-typedef unsigned int multiboot_u32;
+typedef u8 multiboot_u8;
+typedef u16 multiboot_u16;
+typedef u32 multiboot_u32;
typedef unsigned long long multiboot_u64;
struct multiboot_header {
diff --git a/src/kernel/syscall/actions/sys_map.c b/src/kernel/syscall/actions/sys_map.c
index 63bfd9d..441722e 100644
--- a/src/kernel/syscall/actions/sys_map.c
+++ b/src/kernel/syscall/actions/sys_map.c
@@ -1,7 +1,7 @@
#include <stdint.h>
#include <events/event.h>
-u32 sys_map(u32 id, u32 *function)
+u32 sys_map(u32 id, u8 *function)
{
event_map(id, function);
return -1;
diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c
index 820afc7..958428a 100644
--- a/src/kernel/syscall/syscall.c
+++ b/src/kernel/syscall/syscall.c
@@ -35,7 +35,7 @@ void syscall_handler(struct regs *r)
log("[SYSCALL] %d at [0x%x] with 0x%x 0x%x 0x%x 0x%x", r->eax, location, r->ebx, r->ecx,
r->edx, r->esi, r->edi);
- if (r->eax == 2) // TODO: Fix hardcoded fork parameters
+ if (r->eax == SYS_FORK) // TODO: Fix hardcoded fork parameters
r->eax = location(r);
else
r->eax = location(r->ebx, r->ecx, r->edx, r->esi, r->edi);
diff --git a/src/kernel/syscall/syscall.h b/src/kernel/syscall/syscall.h
index 0cfa3a7..bc52e74 100644
--- a/src/kernel/syscall/syscall.h
+++ b/src/kernel/syscall/syscall.h
@@ -26,6 +26,6 @@ u32 sys_free(u32 ptr);
u32 sys_get(u32 id);
-u32 sys_map(u32 id, u32 *function);
+u32 sys_map(u32 id, u8 *function);
#endif \ No newline at end of file
diff --git a/src/kernel/system.h b/src/kernel/system.h
index 4c2673d..29d0f31 100644
--- a/src/kernel/system.h
+++ b/src/kernel/system.h
@@ -9,8 +9,8 @@
* The ASM registers as packed structure
*/
typedef struct __attribute__((packed)) {
- unsigned short di, si, bp, sp, bx, dx, cx, ax;
- unsigned short gs, fs, es, ds, eflags;
+ u16 di, si, bp, sp, bx, dx, cx, ax;
+ u16 gs, fs, es, ds, eflags;
} regs16_t;
/**
@@ -18,7 +18,7 @@ typedef struct __attribute__((packed)) {
* @param intnum The interrupt number (e.g. 0x10)
* @param regs The ASM registers
*/
-extern void int32(unsigned char intnum, regs16_t *regs);
+extern void int32(u8 intnum, regs16_t *regs);
/**
* Display a general log message
diff --git a/src/userspace/libc/stdio/putch.c b/src/userspace/libc/stdio/putch.c
index f87680e..2dad6dc 100644
--- a/src/userspace/libc/stdio/putch.c
+++ b/src/userspace/libc/stdio/putch.c
@@ -1,8 +1,22 @@
#include <syscall.h>
+int is_transmit_empty()
+{
+ u8 value;
+ asm volatile("inb %1, %0" : "=a"(value) : "Nd"(0x3f8 + 5));
+ return value & 0x20;
+}
+
void putch(char ch)
{
+ while (is_transmit_empty() == 0)
+ ;
+ asm volatile("outb %0, %1" ::"a"(ch), "Nd"(0x3f8));
+}
+
+/*void putch(char ch)
+{
// TODO: Implement framebuffer writing
//if (ch != 0)
//syscall_putch(ch);
-} \ No newline at end of file
+}*/ \ No newline at end of file
diff --git a/src/userspace/programs/init.c b/src/userspace/programs/init.c
index 5ff1864..68d025c 100644
--- a/src/userspace/programs/init.c
+++ b/src/userspace/programs/init.c
@@ -5,17 +5,18 @@
#include <unistd.h>
#include <gui.h>
-void test(u8 *data)
-{
- syscall_halt();
-}
-
void main()
{
- /* gui_init(); */
- /* gui_screen_clear(); */
- //printf("Initializing userspace...\n");
- syscall_map(MAP_KEYBOARD, (u8 *)&test);
+ // TODO: Fix page fault when mallocing
+ printf("Initializing userspace...\n");
+
+ // TODO: Implement wait syscall
+ int x;
+ int f = fork();
+ if (f == 0)
+ ; //wait(&x);
+ else
+ exec("/bin/sh");
//syscall_exec("/bin/sh");