Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 6a05a73

Browse files
committed
initial release (v1)
ye
0 parents  commit 6a05a73

12 files changed

+401
-0
lines changed

.perms

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env shell
2+
chmod +x compile.sh
3+
chmod +x run.sh
4+
chmod +x test.sh

BisOS.img

1.41 MB
Binary file not shown.

README

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# bisos
2+
real mode, 16 bit operating system
3+
4+
started off as a small project to see how small i can make a bootloader
5+
6+
## dependencies
7+
nasm, qemu-system-x86
8+
9+
## how do i get it running
10+
clone the repo
11+
12+
run `sudo apt install nasm qemu-system-x86 -y` to install dependencies and then run `source .perms` and now you can use any of the 3 scripts, `./compile.sh`, `./run.sh` and `./test.sh`
13+
14+
or just plug the preassembled "BisOS.img" into the repo
15+
16+
### note
17+
you can add the `-r` flag to remove the files created in the compilation process
18+
19+
if you really want to
20+
21+
but i suggest atleast looking through a couple of them in a hex editor or sumn

boot.asm

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
org 0x7c00
2+
bits 16
3+
4+
jmp 0x0000:start
5+
nop
6+
7+
; macros
8+
%include "macros.asm"
9+
10+
; constants
11+
KERNEL_OFFSET equ 0x500 ; where to load the kernel to
12+
13+
; symbols
14+
BOOT_DRIVE:
15+
db 0
16+
db 0
17+
msg_hello_world: db "Hello, world!", CRLFNULL
18+
msg_bad_time: db ENDL, ENDL, "you're going to have a BAAD time", CRLFNULL
19+
20+
; includes
21+
includes:
22+
db " included "
23+
.put:
24+
db " put.asm "
25+
%include "put.asm"
26+
.disk:
27+
db " disk.asm "
28+
%include "disk.asm"
29+
30+
; entry point
31+
start:
32+
xor ax, ax
33+
mov ds, ax
34+
mov es, ax
35+
36+
; BIOS sets boot drive in 'dl'; store for later use
37+
mov [BOOT_DRIVE], dl
38+
39+
; setup stack
40+
mov bp, 0x9000
41+
mov sp, bp
42+
43+
; print messages
44+
push msg_hello_world
45+
call puts
46+
push msg_bad_time
47+
call puts
48+
49+
; setup registers for disk load call
50+
mov bx, KERNEL_OFFSET ; bx -> destination
51+
mov dh, 2 ; dh -> num sectors
52+
mov dl, [BOOT_DRIVE] ; dl -> disk
53+
mov cl, 0x02 ; start from sector 2
54+
; (as sector 1 is our boot sector)
55+
56+
; load sector to disk
57+
call disk_load
58+
59+
60+
call KERNEL_OFFSET
61+
jmp $
62+
63+
; padding to 510 to fit the last two bytes
64+
times (510-($-$$)) db 0
65+
; magic bytes
66+
dw 0xaa55

compile.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
nasm boot.asm -f bin -o boot.bin
2+
nasm kernel.asm -f bin -o kernel.bin
3+
cat boot.bin kernel.bin > OS.bin
4+
cp OS.bin BisOS.img
5+
truncate -s 1440k BisOS.img
6+
7+
if [ $1 ]
8+
9+
then
10+
11+
if [ $1 = -r ]
12+
13+
then
14+
15+
rm boot.bin
16+
rm kernel.bin
17+
rm OS.bin
18+
19+
fi
20+
21+
fi

disk.asm

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
disk_load:
3+
pusha
4+
push dx
5+
6+
mov ah, 0x02 ; read mode
7+
mov al, dh ; read dh number of sectors
8+
mov ch, 0x00 ; cylinder 0
9+
mov dh, 0x00 ; head 0
10+
11+
; dl = drive number is set as input to disk_load
12+
; es:bx = buffer pointer is set as input as well
13+
14+
int 0x13 ; BIOS interrupt
15+
jc disk_error ; check carry bit for error
16+
17+
pop dx ; get back original number of sectors to read
18+
cmp al, dh ; BIOS sets 'al' to the # of sectors actually read
19+
; compare it to 'dh' and error out if they are !=
20+
jne sectors_error
21+
popa
22+
ret
23+
24+
disk_error:
25+
jmp disk_loop
26+
27+
sectors_error:
28+
jmp disk_loop
29+
30+
disk_loop:
31+
jmp $
32+

kernel.asm

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
org 0x500
2+
bits 16
3+
4+
; macros
5+
%include "macros.asm"
6+
7+
jmp _start
8+
nop
9+
10+
global _start
11+
_start:
12+
push 79
13+
push 24
14+
push 0x1F
15+
call clearscreen
16+
push 0x00000000
17+
call movecursor
18+
push msgl_hello_world_len
19+
push msgl_hello_world
20+
call putl
21+
push msgl_how_len
22+
push msgl_how
23+
call putl
24+
jmp typingsimulator2023
25+
26+
typingsimulator2023:
27+
.loop:
28+
call scanc
29+
cmp ah, 0x1c
30+
je .putnewline
31+
cmp ah, 0x49
32+
je .uparrow
33+
cmp ah, 0x0E
34+
je .backspace
35+
push ax ; ah khpm
36+
call putc
37+
pop ax
38+
.returntoloop:
39+
jmp .loop
40+
.putnewline:
41+
push bx
42+
mov bx, 0x0A
43+
push bx
44+
call putc
45+
pop bx
46+
mov bx, 0x0D
47+
push bx
48+
call putc
49+
pop bx
50+
pop bx
51+
jmp .returntoloop
52+
.uparrow:
53+
push dx
54+
call cursorpos
55+
sub dh, 1
56+
push dx
57+
call movecursor
58+
pop dx
59+
pop dx
60+
jmp .returntoloop
61+
.backspace:
62+
push ax
63+
mov al, 0x08
64+
push ax
65+
call putc
66+
mov al, 0x20
67+
push ax
68+
call putc
69+
pop ax
70+
call putc
71+
pop ax
72+
pop ax
73+
jmp .returntoloop
74+
75+
; includes
76+
includes:
77+
db " included "
78+
.put:
79+
db " put.asm "
80+
%include "put.asm"
81+
.disk:
82+
db " stdio.asm "
83+
%include "stdio.asm"
84+
85+
; symbols/constants
86+
msgl_hello_world: db "TYPING SIMULATOR 2023", ENDL
87+
msgl_hello_world_len equ $-msgl_hello_world
88+
msgl_how: db "to exit this mode, type, well, good luck...", ENDL
89+
msgl_how_len equ $-msgl_how
90+
91+
times 1024-($-$$) db 0

macros.asm

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
%define ENDL 0x0D, 0x0A
2+
%define CRLFNULL 0x0D, 0X0A, 0

put.asm

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
putc:
3+
push bp
4+
mov bp, sp
5+
6+
push ax
7+
push bx
8+
9+
mov bx, 0
10+
mov al, [bp+4]
11+
mov ah, 0x0E
12+
int 10h
13+
14+
pop bx
15+
pop ax
16+
17+
mov sp, bp
18+
pop bp
19+
ret
20+
21+
putcfromax:
22+
push bp
23+
mov bp, sp
24+
25+
push bx
26+
27+
mov bx, 0
28+
mov ah, 0x0E
29+
int 10h
30+
31+
pop bx
32+
33+
mov sp, bp
34+
pop bp
35+
ret
36+
37+
puts:
38+
push bp
39+
mov bp, sp
40+
pusha
41+
mov si, [bp+4]
42+
mov bx, 0
43+
mov ah, 0x0e
44+
.char:
45+
mov al, [si] ; get the current char from our pointer position
46+
add si, 1 ; keep incrementing si until we see a null char
47+
or al, 0x00
48+
je .return ; end if the string is done
49+
push ax
50+
call putc
51+
pop ax
52+
jmp .char ; keep looping
53+
.return:
54+
popa
55+
mov sp, bp
56+
pop bp
57+
ret
58+
59+
putd:
60+
push bp
61+
mov bp, sp
62+
pusha
63+
mov al, [bp+4]
64+
push ax
65+
call putc
66+
pop ax
67+
mov al, [bp+6]
68+
push ax
69+
call putc
70+
pop ax
71+
.return:
72+
popa
73+
mov sp, bp
74+
pop bp
75+
ret
76+
77+
putl:
78+
push bp
79+
mov bp, sp
80+
pusha
81+
mov si, [bp+4]
82+
mov bx, [bp+6]
83+
mov cx, 0
84+
.loop:
85+
mov al, [si]
86+
add si, 1
87+
push ax
88+
call putc
89+
pop ax
90+
add cx, 1
91+
cmp cx, bx
92+
jne .loop
93+
.return:
94+
popa
95+
mov sp, bp
96+
pop bp
97+
ret

run.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
qemu-system-i386 -fda OS.bin

0 commit comments

Comments
 (0)