Skip to content
This repository has been archived by the owner on Nov 4, 2020. It is now read-only.

Commit

Permalink
mutex update + vga_text sync start
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin authored and Valentin committed Jul 12, 2018
1 parent aca09fc commit f31aa88
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
22 changes: 21 additions & 1 deletion sync/mutex.s
Expand Up @@ -19,14 +19,34 @@
.extern mutex_unlock_wakeup
.global mutex_lock
mutex_lock:
/* get argument (mutex pointer) into eax */
mov 4(%esp), %eax

/* clear interrupts to lock the mutex, and cache flags in edx */
pushf
popl %edx
cli
movl (%eax), %ecx
movl (%eax), %ecx # move the process into ecx

/* check if mutex is already locked by current process, if so return good */
cmp %ecx, current_process
je lock_end

/* check if mutex is locked by another process (!=0), if so return bad */
test %ecx, %ecx
jnz lock_end_bad

/* lock the mutex : put current process addr in struct */
movl current_process, %ecx
movl %ecx, (%eax)

lock_end:
test $0x200, %edx
jz no_int

sti

no_int:
movl $0, %eax
ret

Expand Down
2 changes: 1 addition & 1 deletion tasking/processes/syscalls.c
Expand Up @@ -54,7 +54,7 @@ void syscall_open(u32 ebx, u32 ecx, u32 edx)
}

fd_t* file = open_file(path, (u8) ecx);
kprintf("%lSYS_OPEN : %s = 0x%X\n", 3, path, file);
//kprintf("%lSYS_OPEN : %s = 0x%X\n", 3, path, file);
if(!file) {asm("mov $0, %%eax ; mov %0, %%ecx"::"N"(ERROR_FILE_NOT_FOUND):"%eax", "%ecx"); return;}

if(current_process->files_count == current_process->files_size)
Expand Down
21 changes: 18 additions & 3 deletions video/vga_text.c
Expand Up @@ -16,6 +16,7 @@
*/

#include "video.h"
#include "tasking/task.h"

#define VIDEO_TYPE_NONE 0x0
#define VIDEO_TYPE_COLOR 0x20
Expand Down Expand Up @@ -52,6 +53,8 @@ u8 g_80x25_text[] =
0x0C, 0x00, 0x0F, 0x08, 0x00
};

mutex_t screen_mutex = {0};

bool vga_setup(void)
{
//Set video_mode to VGA_TEXT 80*25
Expand All @@ -75,6 +78,15 @@ bool vga_setup(void)
return true;
}

void vga_text_mutex_lock()
{
if(!scheduler_started) return;
while(mutex_lock(&screen_mutex) != ERROR_NONE)
{
mutex_wait(&screen_mutex);
}
}

void vga_text_cls()
{
u32 i = 0;
Expand All @@ -94,8 +106,7 @@ void vga_text_reset()
TEXT_CURSOR_Y = 0;
}

//static
void vga_text_scroll_up()
static void vga_text_scroll_up()
{
if(get_video_mode() != VIDEO_MODE_VGA_TEXT) return;
if(VIDEO_TYPE == VIDEO_TYPE_NONE) return;
Expand All @@ -122,7 +133,7 @@ void vga_text_reset()
}

if(TEXT_CURSOR_Y > 0)
TEXT_CURSOR_Y = (u8) (TEXT_CURSOR_Y - 1);
TEXT_CURSOR_Y = (u8) (TEXT_CURSOR_Y - 1);
}

static void vga_text_update_cursor()
Expand Down Expand Up @@ -153,6 +164,8 @@ void vga_text_putc(unsigned char c, u8 color)
if(get_video_mode() != VIDEO_MODE_VGA_TEXT) return;
if(VIDEO_TYPE == VIDEO_TYPE_NONE) return;

vga_text_mutex_lock();

if(c == '\n'){TEXT_CURSOR_X = 0; TEXT_CURSOR_Y++;}
else if(c == '\t')
{
Expand Down Expand Up @@ -200,6 +213,8 @@ void vga_text_putc(unsigned char c, u8 color)

//update vga cursor
vga_text_update_cursor();

mutex_unlock(&screen_mutex);
}

void vga_text_puts(unsigned char* str, u8 color)
Expand Down

0 comments on commit f31aa88

Please sign in to comment.