-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.c
More file actions
102 lines (81 loc) · 2.56 KB
/
Copy pathsystem.c
File metadata and controls
102 lines (81 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* system.c -
*/
#include <segment.h>
#include <types.h>
#include <interrupt.h>
#include <hardware.h>
#include <system.h>
#include <sched.h>
#include <mm.h>
#include <io.h>
#include <utils.h>
#include <libc.h>
#include <sf.h>
#include <devices.h>
int (*usr_main) (void) = (void *) PH_USER_START;
unsigned int *p_sys_size = (unsigned int *) KERNEL_START;
unsigned int *p_usr_size = (unsigned int *) KERNEL_START + 1;
/************************/
/** Auxiliar functions **/
/************************/
/**************************
** setSegmentRegisters ***
**************************
* Set properly all the registers, used
* at initialization code.
* DS, ES, FS, GS <- DS
* SS:ESP <- DS:DATA_SEGMENT_SIZE
* (the stacks grows towards 0)
*
* cld -> gcc2 wants DF (Direction Flag (eFlags.df))
* always clear.
*/
/*
* This function MUST be 'inline' because it modifies the %esp
*/
inline void
set_seg_regs (Word data_sel, Word stack_sel, DWord esp)
{
esp = esp - 5 * sizeof (DWord); /* To avoid overwriting task 1 */
__asm__ __volatile__ ("cld\n\t" "mov %0,%%ds\n\t" "mov %0,%%es\n\t" "mov %0,%%fs\n\t" "mov %0,%%gs\n\t" "mov %1,%%ss\n\t" "mov %2,%%esp": /* no output */
:"r" (data_sel), "r" (stack_sel), "g" (esp));
}
/*
* Main entry point to ZEOS Operatin System
*/
int __attribute__ ((__section__ (".text.main"))) main (void)
{
int first_ph;
set_eflags ();
/* Define the kernel segment registers */
set_seg_regs (__KERNEL_DS, __KERNEL_DS, KERNEL_ESP);
/* Move user code now, because the following code can overwrite the data section */
copy_data ((void *) KERNEL_START + *p_sys_size, usr_main, *p_usr_size);
printk ("Kernel Carregat!...\n\n");
/* Initialize hardware data */
setGdt (); /* Definicio de la taula de segments de memoria */
setIdt (); /* Definicio del vector de interrupcions */
setTSS (); /* Definicio de la TSS */
/* Initialize Memory */
first_ph = init_mm ();
iniTemps ();
/* Inicialitzem les variables i estructures del scheduler */
init_sched ();
/* Inicialitzem els dispositius */
init_devices ();
/* Inicialitzar tot el sistema de fitxers */
init_filesystem ();
/* Initialize task 0 data */
init_task0 (first_ph);
/* Activem les interrupcions */
enable_int ();
printk ("Entrant en mode usuari...\n");
/*
* We return from a 'theorical' call to a 'call gate' to reduce our privileges
* and going to execute 'magically' at 'usr_main'...
*/
return_gate (__USER_DS, __USER_DS, USER_ESP, __USER_CS, L_USER_START);
/* The execution never arrives to this point */
return 0;
}