Kernel 0.5.7-r9; added mutex support, fixed bad bug in system call open
[ZeXOS.git] / kernel / include / system.h
blob52ae193ee3c44f05fd8ee7c6243e4a90cc92cfa0
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef __SYSTEM_H
21 #define __SYSTEM_H
23 #include "fdc.h"
24 #include "mytypes.h"
25 #include "dev.h"
26 #include "user.h"
27 #include <tty.h>
28 #include "partition.h"
29 #include "file.h"
30 #include "time.h"
31 #include "_size_t.h"
32 #include "../drivers/char/video/video.h"
34 /* irq0 timer */
35 #define HZ 1000
37 /* kernel attributes */
38 unsigned kernel_attr;
40 #define KERNEL_LIVE 0x01
41 #define KERNEL_18HZ 0x02
42 #define KERNEL_NOHDD 0x04
43 #define KERNEL_NOATA 0x08
44 #define KERNEL_NOFLOPPY 0x10
45 #define KERNEL_NOCDROM 0x20
48 #define CONSOLE_LOG 16
50 unsigned debug; // developer mode
52 unsigned long long ctps; // cpu ticks per second
54 tty_t *currtty;
56 partition_t *curr_part;
58 unsigned int fd_count;
60 tm *realtime;
62 #define KBD_MAX_QUAUE 16
63 typedef struct
65 char key[KBD_MAX_QUAUE];
66 int p;
67 unsigned state[KBD_MAX_QUAUE];
68 } kbd_quaue;
70 /* memory vars */
71 unsigned short mem_ext;
73 /* This defines what the stack looks like after an ISR was running */
74 struct regs
76 unsigned int ds, es, fs, gs;
77 unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;
78 unsigned int int_no, err_code;
79 unsigned int eip, cs, eflags, useresp, ss;
82 /* registers pushed on the stack by exceptions or interrupts that
83 switch from user privilege to kernel privilege
84 *** WARNING ***
85 The layout of this struct must agree with the order in which
86 registers are pushed and popped in the assembly-language
87 interrupt handler code. */
88 typedef struct
90 unsigned edi, esi, ebp, esp, ebx, edx, ecx, eax; /* PUSHA/POP */
91 unsigned ds, es, fs, gs;
92 unsigned which_int, err_code;
93 unsigned eip, cs, eflags, user_esp, user_ss; /* INT nn/IRET */
94 unsigned v_es, v_ds, v_fs, v_gs; /* V86 mode only */
95 } uregs_t;
97 #define _set_gate(gate_addr, type, dpl, addr) \
98 __asm__ ("movw %%dx,%%ax\n\t" \
99 "movw %0,%%dx\n\t" \
100 "movl %%eax,%1\n\t" \
101 "movl %%edx,%2" \
103 : "i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
104 "o" (*((char *) (gate_addr))), \
105 "o" (*(4+(char *) (gate_addr))), \
106 "d" ((char *) (addr)),"a" (0x00080000))
109 /* fs directory structure */
110 struct dir {
111 char name[10];
112 int read;
113 int hidden;
114 int system;
115 int volume;
116 int dir;
117 int bin;
118 unsigned int start;
119 } dir[223];
121 unsigned char *file_cache;
123 /** externs **/
125 /* init.c */
126 extern int init ();
128 /* memory.c */
129 extern void *malloc (unsigned size);
130 extern void *realloc(void *blk, unsigned size);
131 extern void free (void *blk);
133 extern unsigned int init_mm ();
135 /* protmem.c */
136 extern void *memcpy_to_user (void *dest, const void *src, size_t count);
137 extern void *memcpy_from_user (void *dest, const void *src, size_t count);
138 extern unsigned memtest_data (void *src, void *data, size_t offset);
140 /* console.c */
141 extern unsigned int init_console ();
142 extern void console (int i);
144 /* elf.c */
145 extern int exec_elf (unsigned char *image, unsigned *entry, unsigned *elf_data, unsigned *elf_data_off, unsigned *elf_bss);
146 extern int flush_elf ();
148 /* exec.c */
149 extern bool exec (unsigned char *fi);
151 /* gtd.c */
152 extern void gdt_set_gate (int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
153 extern unsigned int gdt_install ();
155 /* idt.c */
156 extern void idt_set_gate (unsigned char num, unsigned long base, unsigned short sel, unsigned char flags);
157 extern unsigned int idt_install ();
159 /* isrs.c */
160 extern unsigned int isrs_install ();
162 /* irq.c */
163 extern void irq_install_handler (int irq, void (*handler)(struct regs *r));
164 extern void irq_uninstall_handler (int irq);
165 extern unsigned int irq_install ();
167 /* timer.c */
168 extern void timer_wait (int ticks);
169 extern unsigned int timer_install ();
171 /* keyboard.c */
172 extern unsigned int keyboard_install ();
173 extern char getkey ();
174 extern void setkey (char key);
176 extern unsigned int init_tasks (void);
177 extern unsigned sched_lock ();
178 extern unsigned sched_unlock ();
179 extern void schedule (void);
182 extern void uptime (void);
184 /* fat.c */
185 extern void read_dir (int aa);
186 extern unsigned long read_file (int aa);
188 /* ls.c */
189 extern int ls (unsigned char* fi);
191 /* cd.c */
192 extern int cd (unsigned char* fi);
194 /* cat.c */
195 extern int cat (partition_t *p, unsigned char *fi);
197 extern int read (unsigned fd, void *buf, unsigned len);
199 /* fopen.c */
200 extern FILE *fopen (const char *filename, const char *mode);
202 /* fputs.c */
203 extern char *fgets (char *string, int n, FILE *file);
205 /* fclose.c */
206 extern int fclose (FILE *file);
208 /* rtc.c */
209 extern tm *rtc_getcurrtime ();
211 #endif