Skip to content

Commit 87ef2e6

Browse files
committed
adding files
0 parents  commit 87ef2e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3185
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/test/
2+
**/tools/

Makefile

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
ARCH=i386
2+
ARCHDIR=arch/$(ARCH)
3+
4+
CC=i686-elf-gcc
5+
CPP=i686-elf-g++
6+
LD=i686-elf-ld -O3
7+
AS=nasm
8+
9+
INCLUDES=-Iinclude -Iinclude/libc
10+
CFLSHARED=-ffreestanding -Wall -Wextra -fstack-protector -fno-builtin -fno-leading-underscore -mfpmath=387
11+
CFLAGS=-std=gnu11 $(CFLSHARED) $(INCLUDES)
12+
CPPFLAGS=-std=gnu++11 -fno-exceptions -fno-rtti -fno-use-cxa-atexit $(CFLSHARED) $(INCLUDES)
13+
LDFLAGS=-melf_i386 -nostdlib -L.
14+
ASFLAGS=-felf32
15+
16+
CRT_BEGIN=$(shell $(CC) $(CFLAGS) -print-file-name=crtbegin.o)
17+
CRT_END=$(shell $(CC) $(CFLAGS) -print-file-name=crtend.o)
18+
19+
objects_arch_c =$(patsubst $(ARCHDIR)/%.c,$(ARCHDIR)/%.o,$(wildcard $(ARCHDIR)/*.c))
20+
objects_arch_cpp=$(patsubst $(ARCHDIR)/%.cpp,$(ARCHDIR)/%.o,$(wildcard $(ARCHDIR)/*.cpp))
21+
objects_arch_asm=$(patsubst $(ARCHDIR)/%.asm,$(ARCHDIR)/%.o,$(wildcard $(ARCHDIR)/*.asm))
22+
objects_arch=$(objects_arch_c) $(objects_arch_cpp) $(objects_arch_asm)
23+
24+
objects_kernel_c =$(patsubst kernel/%.c,kernel/%.o,$(wildcard kernel/*.c))
25+
objects_kernel_cpp=$(patsubst kernel/%.cpp,kernel/%.o,$(wildcard kernel/*.cpp))
26+
objects_kernel=$(objects_kernel_c) $(objects_kernel_cpp)
27+
28+
objects_lib_c =$(patsubst lib/%.c,lib/%.o,$(wildcard lib/*.c))
29+
objects_lib_cpp=$(patsubst lib/%.cpp,lib/%.o,$(wildcard lib/*.cpp))
30+
objects_lib=$(objects_lib_c) $(objects_lib_cpp)
31+
32+
objects=crti.o $(objects_arch) $(objects_kernel) $(objects_lib) crtn.o
33+
34+
kernel.bin: $(objects)
35+
$(LD) -Tlinker.ld -o $@ $(LDFLAGS) $(CRT_BEGIN) $(objects) $(CRT_END) -lgcc
36+
37+
%.o: %.asm
38+
nasm -felf32 -o $@ $<
39+
40+
$(ARCHDIR)/%.o: $(ARCHDIR)/%.c
41+
$(CC) -c -o $@ $< $(CFLAGS)
42+
$(ARCHDIR)/%.o: $(ARCHDIR)/%.cpp
43+
$(CPP) -c -o $@ $< $(CPPFLAGS)
44+
$(ARCHDIR)/%.o: $(ARCHDIR)/%.asm
45+
$(AS) -o $@ $< $(ASFLAGS)
46+
47+
kernel/%.o: kernel/%.c
48+
$(CC) -c -o $@ $< $(CFLAGS)
49+
kernel/%.o: kernel/%.cpp
50+
$(CPP) -c -o $@ $< $(CPPFLAGS)
51+
52+
53+
lib/%.o: lib/%.c
54+
$(CC) -c -o $@ $< $(CFLAGS)
55+
lib/%.o: lib/%.cpp
56+
$(CPP) -c -o $@ $< $(CPPFLAGS)
57+
58+
clean:
59+
rm -rf $(objects) iso/
60+
61+
run: kernel.bin
62+
qemu-system-i386 -kernel kernel.bin -m 64M # -no-reboot-d int,cpu_reset
63+
runvbox: benos.iso
64+
virtualbox --startvm BenOS
65+
66+
benos.iso: kernel.bin grub.cfg
67+
mkdir -p iso/boot/grub
68+
cp kernel.bin iso/boot/kernel.bin
69+
cp grub.cfg iso/boot/grub/grub.cfg
70+
grub-mkrescue -o $@ iso/
71+
install: kernel.bin
72+
sudo cp $< /boot/benos.bin
73+
74+
device ?= "100101"
75+
burn: benos.iso
76+
if [ "$(device)" = "100101" ]; then echo device is empty; exit 1; fi
77+
sudo dd bs=4M if=$< of=$(device) conv=fdatasync
78+
79+
.PHONY: clean run runvbox install burn

arch/i386/cmath.asm

+193
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
section .text
2+
global sqrt:function (sqrt.end - sqrt)
3+
global sqrtf:function (sqrtf.end - sqrtf)
4+
global sin:function (sin.end - sin)
5+
global sinf:function (sinf.end - sinf)
6+
global cos:function (cos.end - cos)
7+
global cosf:function (cosf.end - cosf)
8+
global fabs:function (fabs.end - fabs)
9+
global fabsf:function (fabsf.end - fabsf)
10+
global tan:function (tan.end - tan)
11+
global tanf:function (tanf.end - tanf)
12+
global rad2deg:function (rad2deg.end - rad2deg)
13+
global deg2rad:function (deg2rad.end - deg2rad)
14+
global round:function (round.end - round)
15+
global roundf:function (roundf.end - roundf)
16+
global fmin:function (fmin.end - fmin)
17+
global fminf:function (fminf.end - fminf)
18+
global fmax:function (fmax.end - fmax)
19+
global fmaxf:function (fmaxf.end - fmaxf)
20+
21+
; +4 x
22+
sqrt:
23+
fld qword [esp + 4]
24+
fsqrt
25+
ret
26+
.end:
27+
28+
; +4 x
29+
sqrtf:
30+
fld dword [esp + 4]
31+
fsqrt
32+
ret
33+
.end:
34+
35+
; +4 x
36+
sin:
37+
fld qword [esp + 4]
38+
fsin
39+
ret
40+
.end:
41+
42+
; +4 x
43+
sinf:
44+
fld dword [esp + 4]
45+
fsin
46+
ret
47+
.end:
48+
49+
; +4 x
50+
cos:
51+
fld qword [esp + 4]
52+
fcos
53+
ret
54+
.end:
55+
56+
; +4 x
57+
cosf:
58+
fld dword [esp + 4]
59+
fcos
60+
ret
61+
.end:
62+
63+
fabs:
64+
fld qword [esp + 4]
65+
fabs
66+
ret
67+
.end:
68+
69+
fabsf:
70+
fld dword [esp + 4]
71+
fabs
72+
ret
73+
.end:
74+
75+
; +4 x
76+
tan:
77+
fld qword [esp + 4]
78+
fcos
79+
fld qword [esp + 4]
80+
fsin
81+
fdiv st0, st1
82+
ret
83+
.end:
84+
85+
tanf:
86+
fld dword [esp + 4]
87+
fsincos
88+
fdiv
89+
ret
90+
.end:
91+
92+
_180_pi: dd 57.2958
93+
; +4 x
94+
rad2deg:
95+
fld qword [esp + 4]
96+
fmul dword [_180_pi]
97+
ret
98+
.end:
99+
100+
pi_180: dd 0.0174533
101+
; +4 x
102+
deg2rad:
103+
fld qword [esp + 4]
104+
fmul dword [pi_180]
105+
ret
106+
.end:
107+
108+
; +8 x
109+
round:
110+
push ebp
111+
mov ebp, esp
112+
sub esp, byte 8
113+
114+
fld qword [ebp + 8]
115+
fistp qword [esp]
116+
fild qword [esp]
117+
118+
add esp, byte 8
119+
pop ebp
120+
ret
121+
.end:
122+
123+
; +8 x
124+
roundf:
125+
push ebp
126+
mov ebp, esp
127+
sub esp, byte 4
128+
129+
fld dword [ebp + 8]
130+
fistp dword [esp]
131+
fild dword [esp]
132+
133+
add esp, byte 4
134+
pop ebp
135+
ret
136+
.end:
137+
138+
; + 4 a
139+
; +12 b
140+
fmin:
141+
; y = a < b ? a : b;
142+
fld qword [esp + 4]
143+
fld qword [esp + 12]
144+
fcompp
145+
jl .l1
146+
fld qword [esp + 12]
147+
ret
148+
.l1:
149+
fld qword [esp + 4]
150+
ret
151+
.end:
152+
153+
; +4 a
154+
; +8 b
155+
fminf:
156+
fld dword [esp + 4]
157+
fld dword [esp + 8]
158+
fcompp
159+
jl .l1
160+
fld dword [esp + 8]
161+
ret
162+
.l1:
163+
fld dword [esp + 4]
164+
ret
165+
.end:
166+
167+
; + 4 a
168+
; +12 b
169+
fmax:
170+
fld qword [esp + 4]
171+
fld qword [esp + 8]
172+
fcompp
173+
jg .l1
174+
fld qword [esp + 8]
175+
ret
176+
.l1:
177+
fld qword [esp + 4]
178+
ret
179+
.end:
180+
181+
; +4 a
182+
; +8 b
183+
fmaxf:
184+
fld dword [esp + 4]
185+
fld dword [esp + 8]
186+
fcompp
187+
jg .l1
188+
fld dword [esp + 8]
189+
ret
190+
.l1:
191+
fld dword [esp + 4]
192+
ret
193+
.end:

arch/i386/cstdlib.asm

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
global rand:function (rand.end - rand)
2+
global srand:function (srand.end - srand)
3+
global div:function (div.end - div)
4+
global ldiv:function (div.end - div)
5+
global lldiv:function (lldiv.end - lldiv)
6+
7+
rand_seed: dd 1
8+
rand:
9+
push edx
10+
; next = next * 1103515245 + 12345
11+
mov eax, 1103515245
12+
mul dword [rand_seed]
13+
add eax, 12345
14+
mov dword [rand_seed], eax
15+
16+
shr eax, byte 16
17+
mov ecx, 32768
18+
xor edx, edx
19+
div ecx
20+
mov eax, edx
21+
22+
pop edx
23+
ret
24+
.end:
25+
26+
; +4 seed
27+
srand:
28+
mov eax, dword [esp + 4]
29+
mov dword [rand_seed], eax
30+
ret
31+
.end:
32+
33+
; +16 denom
34+
; +12 number
35+
; + 8 return value ptr
36+
ldiv:
37+
div:
38+
push ebp
39+
mov ebp, esp
40+
41+
mov ecx, dword [ebp + 8]
42+
xor edx, edx
43+
mov eax, dword [ebp + 12]
44+
div dword [ebp + 16]
45+
mov dword [ecx], eax
46+
mov dword [ecx + 4], edx
47+
48+
pop ebp
49+
ret 4
50+
.end:
51+
52+
; +20 denom
53+
; +12 number
54+
; + 8 return value ptr
55+
unsupported: db "lldiv() is unsupported!", 10, 0
56+
extern printk
57+
lldiv:
58+
push ebp
59+
mov ebp, esp
60+
61+
push unsupported
62+
call printk
63+
add esp, byte 4
64+
65+
pop ebp
66+
ret
67+
.end:
68+

0 commit comments

Comments
 (0)