Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FILES = ./build/kernel.asm.o ./build/kernel.o ./build/idt/idt.asm.o ./build/idt/idt.o ./build/memory/memory.o ./build/io/io.asm.o ./build/memory/heap/heap.o ./build/memory/heap/kheap.o ./build/memory/paging/paging.o ./build/memory/paging/paging.asm.o ./build/disk/disk.o ./build/string/string.o ./build/fs/pparser.o ./build/disk/streamer.o ./build/fs/file.o ./build/fs/fat/fat16.o ./build/gdt/gdt.o ./build/gdt/gdt.asm.o ./build/task/tss.asm.o ./build/task/task.o
FILES = ./build/kernel.asm.o ./build/kernel.o ./build/idt/idt.asm.o ./build/idt/idt.o ./build/memory/memory.o ./build/io/io.asm.o ./build/memory/heap/heap.o ./build/memory/heap/kheap.o ./build/memory/paging/paging.o ./build/memory/paging/paging.asm.o ./build/disk/disk.o ./build/string/string.o ./build/fs/pparser.o ./build/disk/streamer.o ./build/fs/file.o ./build/fs/fat/fat16.o ./build/gdt/gdt.o ./build/gdt/gdt.asm.o ./build/task/tss.asm.o ./build/task/task.o ./build/task/process.o ./build/task/task.asm.o ./build/isr80h/isr80h.o ./build/isr80h/misc.o ./build/isr80h/io.o
INCLUDES = -I./src
FLAGS = -g -ffreestanding -falign-jumps -falign-functions -falign-lables -falign-loops -fstrength-reduce -fomit-frame-pointer -finline-functions -Wno-unused-function -fno-builtin -Werror -Wno-cpp -Wno-unused-parameter -nostdlib -nostartfiles -nodefaultlibs -Wall -O0 -Iinc

all: ./bin/boot.bin ./bin/kernel.bin
all: ./bin/boot.bin ./bin/kernel.bin user_programs
rm -rf ./bin/os.bin
dd if=./bin/boot.bin >> ./bin/os.bin
dd if=./bin/kernel.bin >> ./bin/os.bin
Expand All @@ -15,6 +15,7 @@ all: ./bin/boot.bin ./bin/kernel.bin

# copy a file over
sudo cp ./hello.txt /mnt/d
sudo cp ./programs/blank/blank.bin /mnt/d
sudo unmount /mnt/d

./bin/kernel.bin: $(FILES)
Expand Down Expand Up @@ -84,7 +85,28 @@ all: ./bin/boot.bin ./bin/kernel.bin
./build/task/task.o: ./src/task/task.c
i686-elf-gcc $(INCLUDES) -I./src/task $(FLAGS) -std=gnu99 -c ./src/task/task.c -o ./build/task/task.o

clean:
./build/task/process.o: ./src/task/process.c
i686-elf-gcc $(INCLUDES) -I./src/task $(FLAGS) -std=gnu99 -c ./src/task/process.c -o ./build/task/process.o

./build/task/task.asm.o: ./src/task/task.asm
nasm -f elf -g ./src/task/task.asm -o ./build/task/task.asm.o

./build/isr80h/isr80h.o: ./src/isr80h/isr80h.c
i686-elf-gcc $(INCLUDES) -I./src/isr80h $(FLAGS) -std=gnu99 -c ./src/isr80h/isr80h.c -o ./build/isr80h/isr80h.o

./build/isr80h/misc.o: ./src/isr80h/misc.c
i686-elf-gcc $(INCLUDES) -I./src/isr80h $(FLAGS) -std=gnu99 -c ./src/isr80h/misc.c -o ./build/isr80h/misc.o

./build/isr80h/io.o: ./src/isr80h/io.c
i686-elf-gcc $(INCLUDES) -I./src/isr80h $(FLAGS) -std=gnu99 -c ./src/isr80h/io.c -o ./build/isr80h/io.o

user_programs:
cd ./programs/blank && $(MAKE) all

user_programs_clean:
cd ./programs/blank && $(MAKE) clean

clean: user_programs_clean
rm -rf ./bin/boot.bin
rm -rf ./bin/kernel.bin
rm -rf ./bin/os.bin
Expand Down
Binary file modified OS_n_Booting.docx
Binary file not shown.
1 change: 1 addition & 0 deletions build/isr80h/to_keep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
as
19 changes: 19 additions & 0 deletions programs/blank/blank.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%%if 0
creating the first program where it will jump in to itself
%%endif
[BITS 32]

section .asm

global _start

_start:
push message
mov eax, 1 ; command print
int 0x80
add esp, 4

jmp $

section .data
message: db 'This is from user space', 0
6 changes: 6 additions & 0 deletions programs/blank/build/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
all:
nasm -f elf ./blank.asm -o ./build/blank.o
i686-elf-gcc -g -T ./linker.ld -o ./blank.bin -ffreestanding -O0 -nostdlib -fpic -g ./build/blank.o

clean:
rm -rf ./build/blank.o
46 changes: 46 additions & 0 deletions programs/blank/linker.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Here we are specifing the sections that which section is doing which part
and so on.

Here in SECTIONS '. = 1M' means (1024x1024=100000 (in hex))
So we are telling that after the boot go to this location where the
kernel.bin is saved and start running from that part.

Here we are aligning everything properly as we are now coding in C.
During assmebly we need not wrry for the alignment but for both
asm and C we need to align otherwise code not work properly.

So we added times 512 at the end of kernel.asm and here.
*/

ENTRY(_start)
OUTPUT_FORMAT(binary)
SECTIONS
{
. = 0x400000;
.text : ALIGN(4096)
{
*(.text)
}

.asm : ALIGN(4096)
{
*(.asm)
}

.rodata : ALIGN(4096)
{
*(.rodata)
}

.data : ALIGN(4096)
{
*(.data)
}

.bss : ALIGN(4096)
{
*(COMMON)
*(.bss)
}
}
40 changes: 20 additions & 20 deletions src/boot/boot.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
%%if 0
First we need to specify the origin so that Os knows the offset needed for the data
Ideally the origin should be 0x0000 and then the system should jump to the
designated location in the case of this system is 0x7c00.
Expand All @@ -18,9 +18,9 @@
are not enough to fill 510 bytes then it will pad it with 0's.

Now then providing the boot signature which is 0x55AA, but we are writing here 0xAA55 due to endianess.
*/
%%endif

/*
%%if 0
Use Makefile1 for build

Now to run this in the system using qemu we will first create a binary file '.bin'.
Expand All @@ -34,9 +34,9 @@

Now to run on qemu use this cmd
cmd - 'qemu-system-x86_64 -hda ./boot.bin'
*/
%%endif

/*
%%if 0
ORG 0x7c00
BITS 16

Expand All @@ -50,10 +50,10 @@ start:

times 510-($ - $$) db 0
dw 0xAA55
*/
%%endif


/*
%%if 0
Use Makefile1 for build

To print custom message on the booting screen we will use the below code.
Expand Down Expand Up @@ -87,10 +87,10 @@ message: db 'Hello World!', 0
times 510-($ - $$) db 0
dw 0xAA55

*/
%%endif


/*
%%if 0
Use Makefile1 for build

Ideally we place our start point 0x0000 and we jump from that to the desired location.
Expand Down Expand Up @@ -148,10 +148,10 @@ message: db 'Hello World!', 0

times 510-($ - $$) db 0
dw 0xAA55
*/
%%endif


/*
%%if 0
Use Makefile1 for build

This section we will write and call custom interrupts for Real Mode.
Expand Down Expand Up @@ -231,11 +231,11 @@ message: db 'Hello World!', 0

times 510-($ - $$) db 0
dw 0xAA55
*/
%%endif



/*
%%if 0
Use Makefile1 for build

Removing the unnecessary things from the code like interrupts and able to read the message.txt
Expand Down Expand Up @@ -305,10 +305,10 @@ times 510-($ - $$) db 0
dw 0xAA55

buffer:
*/
%%endif


/*
%%if 0
For here use Makefile2 and earlier use Makefile1

To start the processor in the protected mode after the real mode.
Expand Down Expand Up @@ -410,10 +410,10 @@ load32:

times 510-($ - $$) db 0
dw 0xAA55
*/
%%endif


/*
%%if 0
From here use Makefile and earlier use Makefile1

Now we are creating another file called kernel.asm so we are using this
Expand Down Expand Up @@ -554,14 +554,14 @@ ata_lba_read:

times 510-($ - $$) db 0
dw 0xAA55
*/
%%endif

/*
%%if 0
From here use Makefile and earlier use Makefile1

In this we are adding FAT16 system to our booting
part so that kernel knows how to read the files.
*/
%%endif
ORG 0x7c00
BITS 16

Expand Down
5 changes: 5 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@
#define USER_DATA_SEGMENT 0x23
#define USER_CODE_SEGMEnt 0x1b

#define PEACHOS_MAX_PROGRAM_ALLOCATIONS 1024
#define PEACHOS_MAX_PROCESSES 12

#define PEACHOS_MAX_ISR80H_COMMANDS 1024

#endif
2 changes: 1 addition & 1 deletion src/gdt/gdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct gdt{
uint8_t access;
uint8_t high_flags;
uint8_t base_24_31_bits;
};
} __attribute__((packed));

/*
create another sturcture which will use the gdt struct
Expand Down
42 changes: 37 additions & 5 deletions src/idt/idt.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ section .asm

extern int21g_handler
extern no_interrupt_handler
extern isr80h_handler

global int21h
global idt_load
global no_interrupt
global enable_interrupts
global disable_interrupts
global isr80h_wrapper

enable_interrupts:
sti
Expand All @@ -31,19 +33,49 @@ idt_load:
ret

int21h:
cli
pushad
call int21h_handler
popad
sti
iret

; we write this interrupt bcoz we dont want the kernel to do anything else if keyboard
; interrupt occurs otherwise it will loop in bios mode continously
no_interrupt:
cli
pushad
call no_interrupt_handler
popad
sti
iret
iret

; calling kernel from the userspace
; selecting 0x80 as interrupt to give control to kernel from userspace
isr80h_wrapper:
; interrupt frame start
; already pushed to us by the processor upon entry to this interrupt
; uint32_t ip;
; uint32_t cs;
; uint32_t flags
; uint32_t sp;
; uint32_t ss;
; pushes the general purpose regs to the stack
pushad

; interrupt frame end

; push the stack pointer so that we are pointing to
; the interrupt frame
push esp

; EAX holds our cmd lets push it to the stack for isr80h_handler
push eax
call isr80h_handler
mov dword[tmp_res], eax
add esp, 8

; restore general purpose regs for user land
popad
mov eax, [tmp_res]
iretd

section .data
; inside here is stored the return result from isr80h_handler
tmp_res dd 0
Loading