annotate cos/kernel/kernel.h @ 17:f3e3e0e9c4bc

First attempt IDT loader 64 bits. INT13 occurs
author windel
date Sat, 19 Nov 2011 20:01:28 +0100
parents a58904747019
children b1fed2171e1a
rev   line source
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
1 #ifndef KERNEL_H
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
2 #define KERNEL_H
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
3
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
4 // Include common functions, available to all!
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
5 #define NULL ((void*)0)
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
6
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
7 // Type defs:
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
8 typedef unsigned char uint8_t;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
9 typedef unsigned short uint16_t;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
10 typedef unsigned int uint32_t;
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
11 typedef unsigned long int uint64_t;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
12
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
13 // IDT related structures:
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
14 typedef struct {
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
15 uint16_t baseLow;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
16 uint16_t selector;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
17 uint8_t reserved1;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
18 uint8_t flags;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
19 uint16_t baseMid;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
20 uint32_t baseHigh;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
21 uint32_t reserved2;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
22 } __attribute__((packed)) IDT_entry;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
23
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
24 typedef struct {
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
25 uint16_t limit;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
26 uint64_t base;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
27 } __attribute__((packed)) idtPointer;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
28
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
29 // memory alloc functions:
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
30 void* malloc(uint64_t size);
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
31 void free(void* ptr);
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
32
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
33 // STDout funcs:
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
34 void printf(const char* fmt, ... );
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
35 void memset(void* ptr, uint32_t value, uint32_t num);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
36 void memcpy(void* dst, void* src, uint32_t num);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
37
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
38 // Screen related:
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
39 void clear_screen();
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
40 void init_screen();
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
41 void print_string(const char *);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
42
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
43 // For IO ports:
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
44 uint8_t inb(uint16_t);
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
45 uint16_t inw(uint16_t);
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
46 void outb(uint16_t, uint8_t);
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
47
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
48 // Interrupt functions:
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
49 void setupIDT(void);
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
50 void PICremap(void);
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
51
14
a58904747019 Added asm interrupt handler things, not yet working
windel
parents: 13
diff changeset
52 // ASM helper:
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
53 void loadIDT(void);
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
54
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
55 // Panic exit:
14
a58904747019 Added asm interrupt handler things, not yet working
windel
parents: 13
diff changeset
56 void halt(void);
a58904747019 Added asm interrupt handler things, not yet working
windel
parents: 13
diff changeset
57
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
58 // Bochs xchg bx,bx breakpoint:
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
59 void magicBochsBreak();
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
60
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
61 // Assembler util functions:
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
62 void doCPUID(int eax, int *ebx, int *ecx, int *edx);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
63
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
64 // Keyboard driver:
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
65 void keyboardDriverUpdate(unsigned char scancode);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
66 void timerDriverUpdate(void);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
67
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
68 // Memory functions:
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
69 void mappage(uint64_t address);
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
70
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
71 int querymode(void);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
72 int getcs(void);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
73 void loadPageTable(void* tableAddress);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
74 void enablePaging(void);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
75
12
fcdae30b2782 Fixup of variable argument things
windel
parents: 9
diff changeset
76 // Variable argument list things:
fcdae30b2782 Fixup of variable argument things
windel
parents: 9
diff changeset
77 #define va_start(v,l) __builtin_va_start(v,l)
fcdae30b2782 Fixup of variable argument things
windel
parents: 9
diff changeset
78 #define va_end(v) __builtin_va_end(v)
fcdae30b2782 Fixup of variable argument things
windel
parents: 9
diff changeset
79 #define va_arg(v,l) __builtin_va_arg(v,l)
fcdae30b2782 Fixup of variable argument things
windel
parents: 9
diff changeset
80 typedef __builtin_va_list va_list;
fcdae30b2782 Fixup of variable argument things
windel
parents: 9
diff changeset
81
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
82 struct multiboot_aout_symbol_table {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
83 uint32_t tabsize;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
84 uint32_t strsize, addr, reserved;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
85 };
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
86
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
87 struct multiboot_info {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
88 uint32_t flags; // Multiboot flags / version
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
89 uint32_t mem_lower; // available memory from BIOS
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
90 uint32_t mem_upper;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
91 uint32_t boot_device;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
92 uint32_t cmdline; // COmmand line
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
93 uint32_t mods_count;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
94 uint32_t mods_addr;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
95 union {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
96 struct multiboot_aout_symbol_table aout_sym;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
97 } u;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
98
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
99 uint32_t mmap_length;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
100 uint32_t mmap_addr;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
101 };
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
102
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
103 struct memory_map {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
104 uint32_t size;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
105 uint32_t baselow, basehigh;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
106 uint32_t lenlow, lenhigh;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
107 uint32_t type;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
108 };
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
109
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
110 typedef struct {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
111 char name[32]; // Name of the console
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
112 unsigned char screendata[80*25]; // All chars in the console!
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
113 } console_t;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
114
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
115 typedef struct {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
116 uint32_t esp;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
117 uint32_t ss;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
118 uint32_t kstack;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
119 uint32_t ustack;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
120 uint32_t cr3;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
121
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
122 uint32_t number;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
123 uint32_t parent;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
124 uint32_t owner;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
125 uint32_t groups;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
126 uint32_t timetorun;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
127 uint32_t sleep;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
128 uint32_t priority;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
129 uint32_t filehandle;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
130 char naam[32];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
131
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
132 console_t *console;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
133 } programma_t;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
134
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
135 #endif
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
136