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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
Welcome to FoolOS
=================
Disclaimer
----------
THIS IS A WORK IN PROGRESS.
This is a simple and useless "operating system", with very basic
features, sorry. It is the fruit of my fundamental explorations of
the x86 architectures, 32-bit protected mode, interrupt handling,
memory management, schedulung the floppy disk controller, networking
as well as VESA and a couple of other things.

Copyright M.Idziorek 2014 <m.i@gmx.at> unless stated otherwise!
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Supported Platforms
-------------------
FoolOS is tested/developed on the following emlators/machines
* bochs 2.6.6 (compiled with: ./configure --enable-clgd54xx --enable-a20-pin --enable-debugger --enable-disasm --enable-e1000 --with-x --with-x11 --enable-smp)
* qemu 1.1.2
* virtual box 4.1.18
* Acer Aspire 1810TZ (Notebook)
* Q6600 on Asus p5n32-e sli plus (Desktop PC)
Features
--------
All features are only very rudiemntary and buggy.
* PIT support / Timing
* PIC support & Interrupt handling framework
* PCI bus scanning
* Physical memory management
* Virtual memory managment (Paging)
* Multitasking (2 tasks so far)
* Multiple processors (hardcoded 2)
* Floppy disk driver
* VESA
Todos
-----
Some things I would like to add someday:
* Filesystem (probably ext2)
* e1000 driver
* drivers to read/write usb sticks
* networking stack / webserver
* port c lib and gcc
* user space / ring3 / ELF binaries support
* mouse support
* simple window manager
* 64-bit support
* alternatively grub as bootloader
* implement a real shell (in user mode)
* kernel should run in high memory (~3gb) virutal mem. why? except v86 tasks?
* let processors sleep if there is no work
* use ACPI instead of MP spec.
Issues
------
* memory map and some other locations are hardcoded.
* the first ~4mb of physical mem are reserved by mem manager (hardcoded)
* bootloader loads only 52 sectors of kernel into mem. ~25KB!
* size of bitmap to track free blocks of physical memory is hardcoded to max.
* Assumed suport for VESA mode 0x114 with linear addressing!
* My Acer Aspire seems to lack MP tables, switch to ACPI
MEMORY LAYOUT
=============
floppy image
------------
* 0x0000 - MASTER BOOT RECORD
* 0x0200 - kernel image (contains sotrage for interrupt desc. table)
* 0x6400 - fool-font binary
* 0x8000 - file system will go here?
ram
---
0x1000
boot loader puts the kernel binary here.
0x7000
entry point for APs (Application Processors).
0x7c00
first stage boot loader (loaded by bios) boot/mbr.asm
includes initial Global Descriptor Table!
0x7c00 + 3 (after jmp boot_16)
boot loader puts number of boot floppy disk here.
0x7c00 + 0x600
boot loader puts number of records in memory map in here!
0x7c00 + 0x400
the boot loader puts the memory map obtained from the
bios here before switching to protected mode.
0x8300
boot loader puts the vesa modes here!
0x9000
esp (stack counts down)
0x9000
physical memory manager bitmap!!!
0xb000
memory above this is used for dma (by our floppy.c driver)
REFERENCES
==========
* LINUX KERNEL
* GNU HURD
* MINIX
* FreeBSD etc.
* xv6
* distributed OS?
* e1000 driver
* http://www.brokenthorn.com/Resources/OSDev17.html
* http://www.jamesmolloy.co.uk/tutorial_html/9.-Multitasking.html
* http://pdos.csail.mit.edu/6.828/2011/labs/lab6/
* http://wiki.osdev.org/Virtual_8086_Mode
* http://pdos.csail.mit.edu/6.828/2011/xv6.html
* http://www.nongnu.org/ext2-doc/
* http://www.osdever.net/tutorials/view/multiprocessing-support-for-hobby-oses-explained
* http://wiki.xomb.org/index.php?title=ACPI_Tables
* Intel 386 Programmes Ref.
* http://forum.osdev.org/viewtopic.php?f=1&t=10944
* man syscalls (posix syscalls?)
MY NOTES BELOW THIS LINE
========================
Keyboard Driver
---------------
//some thoughts on redesign of the keyboard driver
//use uint8_t for proc_pos and buff_pos and a BUF_SIZE of 256 for auto wrap!?
// kb input ringbuffer
kb_scancode kb_buff[BUF_SIZE];
buff_pos=0;
proc_pos=0;
buffered=0;
void kb_irq()
{
cli
//we get one interrupt for EACH scancode!
kb_scancode val=get_scancode();
// think about race condition if called while inside kb_proc();
if(buffered+1<BUF_SIZE)
{
kb_buff[buff_pos]=val;
buff_pos++;
buffered++;
}
else
{
//kb ring buffer is full;
}
sti
}
void kb_proc()
{
if(proc_pos!=buff_pos)
{
kb_scancode val=kb_buff[proc_pos];
proc_pos++;
buffered--;
stdin(scancode_to_char(val));
}
}
Linux Startup x86
-----------------
~ ontogeny recapitulates phylogeny ~
Some notes on the Linux statup process, or at least how I understand it.
1. arch/x86/boot/header.S
Contains the header and linux 16 bit code.
This code should be entered with a bootloader at the address specified
within the header (as _start) which will put us at 'start_of_setup'
Direct loading will put us at 'start2' at the very start which will
show an error message
If everyhing goes right we will enter the 16-bit real mode C module
with:
call main ; should not return
2. arch/x86/boot/main.c
void main(void) will do some checks and detections (cpu,mem,..) and
invoke: go_to_protected_mode();
3. arch/x86/boot/pm.c
go_to_protected_mode() - will disable interrupts and set up the initial
idt and gdt descriptor tables before calling: protected_mode_jump() and
passing the address of code32_start.
4. arch/x86/boot/pmjump.S
back in assembly-world the actual transition is made inside
'protected_mode_jump' and we move on to 'in_pm32' where the data segment
is set up and we jmpl to the 32-bit entry point of the kernel.
5. arch/x86/kernel/head32.c (assumption!?)
void i386_start_kernel(void)
6. init/main.c
start_kernel(void)
setup_arch()!!
Interrupts: arch/x86/include/asm/irq_vectors.h each entry is 8 bytes
|