Skip to content
Snippets Groups Projects
Commit c5c39856 authored by kexu6's avatar kexu6
Browse files

simplify syntax

parent 5fc841c4
No related branches found
No related tags found
No related merge requests found
#include "syscall.h"
f_table dir_jumptable = { open_dir, close_dir, read_dir, write_dir };
f_table file_jumptable = { open_file, close_file, read_file, write_file };
f_table rtc_jumptable = { rtc_open, rtc_close, rtc_read, rtc_write };
......@@ -8,7 +7,6 @@ f_table stdin_jumptable = { terminal_open, terminal_close, terminal_read, termi
f_table stdout_jumptable = { terminal_open, terminal_close, terminal_read, terminal_write };
f_table no_jumptable = { fail , fail , fail , fail };
/*
*The halt system call
*
......
......@@ -52,7 +52,7 @@
#define IF_FLAG 0x200
#define IF_FLAG 0x200
/* Global variables */
//extern int32_t prog_count;
......
#define ASM 1
#include "x86_desc.h"
#define STACK 0x8400000
#define IF_FLAG 0x200
# Assembly linkage functions
.globl syscall_linkage
.globl context_switch
.globl flush_tlb
#.globl exec_ret
.globl sys_execute_leave
# syscall_linage:
# Description: System call interrupt handler
# Jumps to C function and IRETS to user spaces
# Registers: Saves all (interrupt context)
#syscall_linkage:
#
# # Save flags
# PUSHFL
#
# # Save registers
# pushl %ebx
# pushl %ecx
# pushl %edx
# pushl %esp
# pushl %ebp
# pushl %esi
# pushl %edi
#
#
# # Check for valid system call value
# cmpl $0, %eax
# jbe done
# cmpl $10, %eax
# ja done
#
# # Push arguments on stack
# pushl %edx # 3rd argument
# pushl %ecx # 2nd argument
# pushl %ebx # 1st argument
#
# dec %eax
# # Jump to C function
# call *syscall_jumptable(,%eax,4)
#
# # Pop arguments of stack
# addl $12, %esp
#
#done:
#exec_ret:
# # Restore registers
# popl %edi
# popl %esi
# popl %ebp
# popl %esp
# popl %edx
# popl %ecx
# popl %ebx
#
# # Restore flags
# POPFL
#
## Return to user space
#IRET
syscall_linkage:
# Save flags
pushl $0
PUSHFL
# Save registers
#pushl %eax
# Save registers, do not save eax ???
pushl %ebx
pushl %ecx
pushl %edx
......@@ -98,19 +23,18 @@ syscall_linkage:
pushl %esi
pushl %edi
# Check for valid system call value
# Check for valid system call value (1 through 10)
cmpl $0, %eax
jbe done_invalid
cmpl $10, %eax
ja done_invalid
# Push arguments on stack
pushl %edx # 3rd argument
pushl %ecx # 2nd argument
pushl %ebx # 1st argument
pushl %edx # 3rd argument
pushl %ecx # 2nd argument
pushl %ebx # 1st argument
dec %eax
dec %eax # 1-10 -> 0-9
# Jump to C function
call *syscall_jumptable(,%eax,4)
......@@ -122,8 +46,8 @@ syscall_linkage:
done_invalid:
xorl %eax, %eax
dec %eax
xorl %eax, %eax # set eax to 0
dec %eax # set eax to -1
done:
......@@ -135,7 +59,6 @@ done:
popl %edx
popl %ecx
popl %ebx
#popl %eax
# Restore flags
POPFL
......@@ -154,8 +77,7 @@ sys_execute_leave:
# flush_tlb:
# Description: Reloads CR3
# Required when switching processes
# Registers: Saves callee-saved registers
# Registers: Save callee-saved registers
flush_tlb:
pushl %ebp
......@@ -165,6 +87,7 @@ flush_tlb:
pushl %edi
pushl %esi
# ???
movl %cr3, %eax
movl %eax, %cr3
......@@ -176,38 +99,38 @@ leave
ret
# context_switch:
# Description: Sets up stack for IRET to user program
# Description: Sets up stack for IRET to user program ???
context_switch:
# Load entry point in EBX
movl 4(%esp),%ebx
# Load entry point in EBX
movl 4(%esp),%ebx
# Push SS on stack
xorl %eax, %eax
movw $USER_DS, %ax
pushl %eax
# Push SS on stack
xorl %eax, %eax
movw $USER_DS, %ax
pushl %eax
# Push ESP value for user stack
movl $STACK, %eax
pushl %eax
# Push ESP value for user stack
movl $STACK, %eax
pushl %eax
# Push eflags on stack
pushfl
# Push eflags on stack
pushfl
# Set IF flag in eflags
popl %eax
orl $IF_FLAG,%eax
pushl %eax
# Set IF flag in eflags
popl %eax
orl $IF_FLAG,%eax
pushl %eax
# Push CS on stack
pushl $USER_CS
# Push CS on stack
pushl $USER_CS
# Push EIP for user program
pushl %ebx
# Push EIP for user program
pushl %ebx
# Swicth to user space
iret
IRET
# Jump table for system call C functions
syscall_jumptable:
.long halt, execute, read, write, open, close, getargs, vidmap
.long halt, execute, read, write, open, close, getargs, vidmap
......@@ -123,15 +123,13 @@ typedef struct f_table {
/* File Object structure - for PCB */
typedef struct file_object {
f_table fileop_ptr;/* Only valid for data file */
f_table fileop_ptr; /* Only valid for data file */
uint32_t inode_index;
uint32_t file_pos;/* Current position in file, updated by system calls */
uint32_t flags;/* If flag is set, file object is in use */
uint32_t file_pos; /* Current position in file, updated by system calls */
uint32_t flags; /* If flag is set, file object is in use */
} file_object_t;
/* Process control block structure */
typedef struct pcb {
......@@ -157,7 +155,7 @@ typedef struct pcb {
/* Terminal structure - Upto 3 terminals supported */
typedef struct terminal {
pcb_t * pcb;
pcb_t* pcb;
int32_t terminal_x;
int32_t terminal_y;
......@@ -170,9 +168,6 @@ volatile int32_t buffer_index;
} terminal_t;
/*----------------------------- Process Structure ----------------------------*/
typedef struct control {
......@@ -186,7 +181,6 @@ typedef struct control {
} control_t;
/*---------------------------- Global variable -------------------------------*/
/* Godlike--- */
......@@ -194,5 +188,4 @@ control_t control;
#endif /* ASM */
#endif /* _TYPES_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment