-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2bfc5e1
Showing
6 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# set magic number to 0x1BADB002 to identified by bootloader | ||
.set MAGIC, 0x1BADB002 | ||
|
||
# set flags to 0 | ||
.set FLAGS, 0 | ||
|
||
# set the checksum | ||
.set CHECKSUM, -(MAGIC + FLAGS) | ||
|
||
# set multiboot enabled | ||
.section .multiboot | ||
|
||
# define type to long for each data defined as above | ||
.long MAGIC | ||
.long FLAGS | ||
.long CHECKSUM | ||
|
||
|
||
# set the stack bottom | ||
stackBottom: | ||
|
||
# define the maximum size of stack to 512 bytes | ||
.skip 1024 | ||
|
||
|
||
# set the stack top which grows from higher to lower | ||
stackTop: | ||
|
||
.section .text | ||
.global _start | ||
.type _start, @function | ||
|
||
|
||
_start: | ||
|
||
# assign current stack pointer location to stackTop | ||
mov $stackTop, %esp | ||
|
||
# call the kernel main source | ||
call kernel_entry | ||
|
||
cli | ||
|
||
|
||
# put system in infinite loop | ||
hltLoop: | ||
|
||
hlt | ||
jmp hltLoop | ||
|
||
.size _start, . - _start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
menuentry "Ritik" { | ||
multiboot /boot/MyOS.bin | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include"kernel.h" | ||
|
||
static UINT16 VGA_DefaultEntry(unsigned char to_print) { | ||
return (UINT16) to_print | (UINT16)WHITE_COLOR << 8; | ||
} | ||
|
||
void KERNEL_MAIN() | ||
{ | ||
TERMINAL_BUFFER = (UINT16*) VGA_ADDRESS; | ||
|
||
TERMINAL_BUFFER[0] = VGA_DefaultEntry('R'); | ||
TERMINAL_BUFFER[1] = VGA_DefaultEntry('i'); | ||
TERMINAL_BUFFER[2] = VGA_DefaultEntry('t'); | ||
TERMINAL_BUFFER[3] = VGA_DefaultEntry('i'); | ||
TERMINAL_BUFFER[4] = VGA_DefaultEntry('k'); | ||
TERMINAL_BUFFER[5] = VGA_DefaultEntry(' '); | ||
TERMINAL_BUFFER[6] = VGA_DefaultEntry('K'); | ||
TERMINAL_BUFFER[7] = VGA_DefaultEntry('e'); | ||
TERMINAL_BUFFER[8] = VGA_DefaultEntry('r'); | ||
TERMINAL_BUFFER[9] = VGA_DefaultEntry('n'); | ||
TERMINAL_BUFFER[10] = VGA_DefaultEntry('e'); | ||
TERMINAL_BUFFER[11] = VGA_DefaultEntry('l'); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef _KERNEL_H_ | ||
#define _KERNEL_H_ | ||
|
||
#define VGA_ADDRESS 0xB8000 | ||
|
||
#define WHITE_COLOR 15 | ||
|
||
typedef unsigned short UINT16; | ||
|
||
UINT16* TERMINAL_BUFFER; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* entry point of our kernel */ | ||
ENTRY(_start) | ||
|
||
SECTIONS | ||
{ | ||
/* we need 1MB of space atleast */ | ||
. = 1M; | ||
|
||
/* text section */ | ||
.text BLOCK(4K) : ALIGN(4K) | ||
{ | ||
*(.multiboot) | ||
*(.text) | ||
} | ||
|
||
/* read only data section */ | ||
.rodata BLOCK(4K) : ALIGN(4K) | ||
{ | ||
*(.rodata) | ||
} | ||
|
||
/* data section */ | ||
.data BLOCK(4K) : ALIGN(4K) | ||
{ | ||
*(.data) | ||
} | ||
|
||
/* bss section */ | ||
.bss BLOCK(4K) : ALIGN(4K) | ||
{ | ||
*(COMMON) | ||
*(.bss) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
|
||
#assemble boot.s file | ||
as boot.s -o boot.o | ||
|
||
#compile kernel.c file | ||
gcc -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra | ||
|
||
#linking the kernel with kernel.o and boot.o files | ||
gcc -T linker.ld -o MyOS.bin -ffreestanding -O2 -nostdlib kernel.o boot.o -lgcc | ||
|
||
#check MyOS.bin file is x86 multiboot file or not | ||
grub-file --is-x86-multiboot MyOS.bin | ||
|
||
#building the iso file | ||
mkdir -p isodir/boot/grub | ||
cp MyOS.bin isodir/boot/MyOS.bin | ||
cp grub.cfg isodir/boot/grub/grub.cfg | ||
grub-mkrescue -o MyOS.iso isodir | ||
|
||
#run it in qemu | ||
qemu-system-x86_64 -cdrom SabMohMayaHai.iso | ||
|
||
|