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/>.
28 #include "partition.h"
32 #include "../drivers/char/video/video.h"
37 /* kernel attributes */
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
56 partition_t
*curr_part
;
58 unsigned int fd_count
;
62 #define KBD_MAX_QUAUE 16
65 char key
[KBD_MAX_QUAUE
];
67 unsigned state
[KBD_MAX_QUAUE
];
71 unsigned short mem_ext
;
73 /* This defines what the stack looks like after an ISR was running */
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
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. */
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 */
97 #define _set_gate(gate_addr, type, dpl, addr) \
98 __asm__ ("movw %%dx,%%ax\n\t" \
100 "movl %%eax,%1\n\t" \
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 */
121 unsigned char *file_cache
;
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 ();
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
);
141 extern unsigned int init_console ();
142 extern void console (int i
);
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 ();
149 extern bool exec (unsigned char *fi
);
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 ();
156 extern void idt_set_gate (unsigned char num
, unsigned long base
, unsigned short sel
, unsigned char flags
);
157 extern unsigned int idt_install ();
160 extern unsigned int isrs_install ();
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 ();
168 extern void timer_wait (int ticks
);
169 extern unsigned int timer_install ();
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);
185 extern void read_dir (int aa
);
186 extern unsigned long read_file (int aa
);
189 extern int ls (unsigned char* fi
);
192 extern int cd (unsigned char* fi
);
195 extern int cat (partition_t
*p
, unsigned char *fi
);
197 extern int read (unsigned fd
, void *buf
, unsigned len
);
200 extern FILE *fopen (const char *filename
, const char *mode
);
203 extern char *fgets (char *string
, int n
, FILE *file
);
206 extern int fclose (FILE *file
);
209 extern tm
*rtc_getcurrtime ();