Merge pull request #2 from xamidev/cleanup
Codebase cleanup & harmonization
This commit was merged in pull request #2.
This commit is contained in:
36
README.md
36
README.md
@@ -2,26 +2,9 @@
|
|||||||
|
|
||||||
# BlankOS
|
# BlankOS
|
||||||
|
|
||||||
Rewritten monolithic, ring 0, lower-half, singletasking kernel for the x86 processor architecture, using GRUB (eltorito) as bootloader. Emulation was tested on QEMU using Arch Linux 6.9.7-arch1-1, and on real hardware too.
|
Rewritten monolithic, ring 0, lower-half, singletasking kernel for the x86 processor architecture, using GRUB 2 as bootloader. Emulation was tested on QEMU using Arch Linux 6.9.7-arch1-1, and on real hardware too.
|
||||||
The long-term goal of this OS is to be capable of running user programs and having its own complete kernel C library so that users can write their own C programs and expand the system!
|
The long-term goal of this OS is to be capable of running user programs and having its own complete kernel C library so that users can write their own C programs and expand the system!
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- Serial port driver (output & debug)
|
|
||||||
- Framebuffer driver (output)
|
|
||||||
- PS/2 Keyboard and PIC driver (input)
|
|
||||||
- PIT (system clock/timer) driver
|
|
||||||
- Working IDT, GDT, ISRs, and IRQs
|
|
||||||
- Kernel panicking (exception handling)
|
|
||||||
- A kernel-space shell
|
|
||||||
- Cool color output!!
|
|
||||||
- Some small working kernel-space programs, such as...
|
|
||||||
- A brainfuck interpreter
|
|
||||||
- An arithmetic calculator
|
|
||||||
- ROT13 and Morse cipher programs
|
|
||||||
- Conway's Game of Life
|
|
||||||
- And some more...
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Download the latest BlankOS disk image from the "Releases" tab, and start it using the QEMU emulator:
|
Download the latest BlankOS disk image from the "Releases" tab, and start it using the QEMU emulator:
|
||||||
@@ -54,19 +37,6 @@ sudo dd bs=4M if=blankos.iso of=/dev/sdX status=progress oflag=sync
|
|||||||
Replace `sdX` with your USB drive name (you can find it by doing `sudo fdisk -l`).
|
Replace `sdX` with your USB drive name (you can find it by doing `sudo fdisk -l`).
|
||||||
Tada! You now have a working BlankOS USB stick. Go ahead and try it out!
|
Tada! You now have a working BlankOS USB stick. Go ahead and try it out!
|
||||||
|
|
||||||
## Debugging (QEMU w/ GDB)
|
|
||||||
|
|
||||||
```
|
|
||||||
make debug
|
|
||||||
```
|
|
||||||
|
|
||||||
In another shell:
|
|
||||||
|
|
||||||
```
|
|
||||||
gdb kernel.elf
|
|
||||||
(gdb) target remote localhost:1234
|
|
||||||
```
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
Two other documents are available to help you understand the project better. One is the User's Manual, labelled [USERS.md](docs/USERS.md), and the other one is the Developer's Manual, labelled [DEVELOPERS.md](docs/DEVELOPERS.md). They are full of useful resources around Blank OS. You'll learn how to use the system and how to contribute to it. *(The docs might not always be up-to-date)*
|
Two other documents are available to help you understand the project better. One is the User's Manual, labelled [USERS.md](docs/USERS.md), and the other one is the Developer's Manual, labelled [DEVELOPERS.md](docs/DEVELOPERS.md). They are full of useful resources around Blank OS. You'll learn how to use the system and how to contribute to it. *(The docs might not always be up-to-date)*
|
||||||
@@ -82,7 +52,7 @@ Two other documents are available to help you understand the project better. One
|
|||||||
- Ralf Brown's Interrupt List
|
- Ralf Brown's Interrupt List
|
||||||
- the [little book about OS development](https://littleosbook.github.io/) by Erik Helin and Adam Renberg
|
- the [little book about OS development](https://littleosbook.github.io/) by Erik Helin and Adam Renberg
|
||||||
|
|
||||||
### Roadmap
|
### Features / Roadmap
|
||||||
|
|
||||||
- [X] Booting with GRUB
|
- [X] Booting with GRUB
|
||||||
- [X] Common basic structures (IDT, GDT, ISRs, IRQs)
|
- [X] Common basic structures (IDT, GDT, ISRs, IRQs)
|
||||||
@@ -95,7 +65,7 @@ Two other documents are available to help you understand the project better. One
|
|||||||
- [ ] Getting to Ring-3 (userspace)
|
- [ ] Getting to Ring-3 (userspace)
|
||||||
- [ ] Multitasking (via round robin scheduling)
|
- [ ] Multitasking (via round robin scheduling)
|
||||||
- [ ] Advanced/other drivers (video, SB16, RTC, Ethernet)
|
- [ ] Advanced/other drivers (video, SB16, RTC, Ethernet)
|
||||||
- [ ] UEFI support
|
- [X] UEFI support
|
||||||
- [ ] ELF parsing
|
- [ ] ELF parsing
|
||||||
- [ ] System calls
|
- [ ] System calls
|
||||||
- [ ] GUI
|
- [ ] GUI
|
||||||
|
|||||||
@@ -14,6 +14,19 @@ The source code is available in folder `src`. You will find subfolders correspon
|
|||||||
|
|
||||||
No system calls are available, as the OS runs in kernel-space.
|
No system calls are available, as the OS runs in kernel-space.
|
||||||
|
|
||||||
|
## Debugging the kernel (QEMU w/ GDB)
|
||||||
|
|
||||||
|
```
|
||||||
|
make debug
|
||||||
|
```
|
||||||
|
|
||||||
|
In another shell:
|
||||||
|
|
||||||
|
```
|
||||||
|
gdb kernel.elf
|
||||||
|
(gdb) target remote localhost:1234
|
||||||
|
```
|
||||||
|
|
||||||
## Making programs for the OS
|
## Making programs for the OS
|
||||||
|
|
||||||
### Step 1 - Making the program and the entry point
|
### Step 1 - Making the program and the entry point
|
||||||
|
|||||||
@@ -2,6 +2,25 @@
|
|||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
|
First, let me introduce you some features of this project.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Serial port driver (output & debug)
|
||||||
|
- Framebuffer driver (output)
|
||||||
|
- PS/2 Keyboard and PIC driver (input)
|
||||||
|
- PIT (system clock/timer) driver
|
||||||
|
- Working IDT, GDT, ISRs, and IRQs
|
||||||
|
- Kernel panicking (exception handling)
|
||||||
|
- A kernel-space shell
|
||||||
|
- Cool color output!!
|
||||||
|
- Some small working kernel-space programs, such as...
|
||||||
|
- A brainfuck interpreter
|
||||||
|
- An arithmetic calculator
|
||||||
|
- ROT13 and Morse cipher programs
|
||||||
|
- Conway's Game of Life
|
||||||
|
- And some more...
|
||||||
|
|
||||||
### Installation and emulation/execution
|
### Installation and emulation/execution
|
||||||
|
|
||||||
Please refer to the relevant sections in the project `README.md` available in the root folder.
|
Please refer to the relevant sections in the project `README.md` available in the root folder.
|
||||||
|
|||||||
2
makefile
2
makefile
@@ -1,5 +1,5 @@
|
|||||||
CC = i386-elf-7.5.0-Linux-x86_64/bin/i386-elf-gcc
|
CC = i386-elf-7.5.0-Linux-x86_64/bin/i386-elf-gcc
|
||||||
CFLAGS = -g -Wall -Wextra -Wno-builtin-declaration-mismatch -c -I src/
|
CFLAGS = -ffreestanding -g -Wall -Wextra -Wno-builtin-declaration-mismatch -c -I src/
|
||||||
LDFLAGS = -T link.ld -melf_i386
|
LDFLAGS = -T link.ld -melf_i386
|
||||||
AS = nasm
|
AS = nasm
|
||||||
ASFLAGS = -f elf
|
ASFLAGS = -f elf
|
||||||
|
|||||||
@@ -1,27 +1,12 @@
|
|||||||
#include "../libc/stdint.h"
|
// ATA PIO driver implementation
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include "../kernel/io.h"
|
#include "../kernel/io.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
|
#include "ata.h"
|
||||||
#define ATA_PRIMARY_IO 0x1F0
|
|
||||||
#define ATA_PRIMARY_CTRL 0x3F6
|
|
||||||
#define ATA_CMD_READ_PIO 0x20
|
|
||||||
#define ATA_CMD_WRITE_PIO 0x30
|
|
||||||
#define ATA_IDENTIFY 0xEC
|
|
||||||
|
|
||||||
#define ATA_REG_DATA 0x00
|
|
||||||
#define ATA_REG_ERROR 0x01
|
|
||||||
#define ATA_REG_SECCOUNT0 0x02
|
|
||||||
#define ATA_REG_LBA0 0x03
|
|
||||||
#define ATA_REG_LBA1 0x04
|
|
||||||
#define ATA_REG_LBA2 0x05
|
|
||||||
#define ATA_REG_HDDEVSEL 0x06
|
|
||||||
#define ATA_REG_COMMAND 0x07
|
|
||||||
#define ATA_REG_STATUS 0x07
|
|
||||||
|
|
||||||
#define ATA_SR_BSY 0x80
|
|
||||||
#define ATA_SR_DRDY 0x40
|
|
||||||
#define ATA_SR_DRQ 0x08
|
|
||||||
#define ATA_SR_ERR 0x01
|
|
||||||
|
|
||||||
static inline uint16_t inw(uint16_t port) {
|
static inline uint16_t inw(uint16_t port) {
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
|
|||||||
@@ -1,6 +1,34 @@
|
|||||||
|
// ATA PIO driver implementation header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#ifndef ATA_H
|
#ifndef ATA_H
|
||||||
#define ATA_H
|
#define ATA_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define ATA_PRIMARY_IO 0x1F0
|
||||||
|
#define ATA_PRIMARY_CTRL 0x3F6
|
||||||
|
#define ATA_CMD_READ_PIO 0x20
|
||||||
|
#define ATA_CMD_WRITE_PIO 0x30
|
||||||
|
#define ATA_IDENTIFY 0xEC
|
||||||
|
|
||||||
|
#define ATA_REG_DATA 0x00
|
||||||
|
#define ATA_REG_ERROR 0x01
|
||||||
|
#define ATA_REG_SECCOUNT0 0x02
|
||||||
|
#define ATA_REG_LBA0 0x03
|
||||||
|
#define ATA_REG_LBA1 0x04
|
||||||
|
#define ATA_REG_LBA2 0x05
|
||||||
|
#define ATA_REG_HDDEVSEL 0x06
|
||||||
|
#define ATA_REG_COMMAND 0x07
|
||||||
|
#define ATA_REG_STATUS 0x07
|
||||||
|
|
||||||
|
#define ATA_SR_BSY 0x80
|
||||||
|
#define ATA_SR_DRDY 0x40
|
||||||
|
#define ATA_SR_DRQ 0x08
|
||||||
|
#define ATA_SR_ERR 0x01
|
||||||
|
|
||||||
void ata_read_sector(uint32_t lba, uint8_t* buffer);
|
void ata_read_sector(uint32_t lba, uint8_t* buffer);
|
||||||
void test_read_sector();
|
void test_read_sector();
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
#include "../libc/stdint.h"
|
// Framebuffer driver
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include "framebuffer.h"
|
#include "framebuffer.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "../kernel/system.h"
|
#include "../kernel/system.h"
|
||||||
|
|
||||||
//extern uint32_t *g_framebuffer;
|
extern char* framebuffer;
|
||||||
|
|
||||||
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color) // framebuffer pointer, x, y, color
|
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color)
|
||||||
{
|
{
|
||||||
if (bpp == 32) {
|
if (bpp == 32) {
|
||||||
uint32_t* pixel_addr = (uint32_t*)((uint8_t*)fb + y * pitch + x *(bpp / 8));
|
uint32_t* pixel_addr = (uint32_t*)((uint8_t*)fb + y * pitch + x *(bpp / 8));
|
||||||
@@ -13,14 +18,6 @@ void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color) //
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern char* framebuffer;
|
|
||||||
extern int scanline;
|
|
||||||
extern char _binary_include_fonts_UniCyr_8x16_psf_start;
|
|
||||||
uint16_t* unicode;
|
|
||||||
|
|
||||||
#define PIXEL uint32_t
|
|
||||||
|
|
||||||
// Character, cursor X, cursor Y, foreground, background
|
|
||||||
void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg)
|
void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg)
|
||||||
{
|
{
|
||||||
PSF_font *font = (PSF_font*)&_binary_include_fonts_UniCyr_8x16_psf_start;
|
PSF_font *font = (PSF_font*)&_binary_include_fonts_UniCyr_8x16_psf_start;
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
|
// Framebuffer driver header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#ifndef FRAMEBUFFER_H
|
#ifndef FRAMEBUFFER_H
|
||||||
#define FRAMEBUFFER_H
|
#define FRAMEBUFFER_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
extern int scanline;
|
||||||
|
extern char _binary_include_fonts_UniCyr_8x16_psf_start;
|
||||||
|
uint16_t* unicode;
|
||||||
|
|
||||||
|
#define PIXEL uint32_t
|
||||||
|
|
||||||
#define PSF1_FONT_MAGIC 0x0436
|
#define PSF1_FONT_MAGIC 0x0436
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -9,7 +22,6 @@ typedef struct {
|
|||||||
uint8_t characterSize; // PSF character size.
|
uint8_t characterSize; // PSF character size.
|
||||||
} PSF1_Header;
|
} PSF1_Header;
|
||||||
|
|
||||||
|
|
||||||
#define PSF_FONT_MAGIC 0x864ab572
|
#define PSF_FONT_MAGIC 0x864ab572
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -23,7 +35,6 @@ typedef struct {
|
|||||||
uint32_t width; /* width in pixels */
|
uint32_t width; /* width in pixels */
|
||||||
} PSF_font;
|
} PSF_font;
|
||||||
|
|
||||||
//extern const unsigned char font[512][64];
|
|
||||||
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color);
|
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color);
|
||||||
void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg);
|
void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg);
|
||||||
void scroll();
|
void scroll();
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
|
// Keyboard driver
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../kernel/io.h"
|
#include "../kernel/io.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "../kernel/system.h"
|
#include "../kernel/system.h"
|
||||||
|
#include "kb.h"
|
||||||
#define KEYBOARD_BUFFER_SIZE 256
|
|
||||||
|
|
||||||
#define LEFT_SHIFT_PRESSED 0x2A
|
|
||||||
#define RIGHT_SHIFT_PRESSED 0x36
|
|
||||||
#define LEFT_SHIFT_RELEASED 0xAA
|
|
||||||
#define RIGHT_SHIFT_RELEASED 0xB6
|
|
||||||
|
|
||||||
unsigned char kbdus[128] =
|
unsigned char kbdus[128] =
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,18 @@
|
|||||||
|
// Keyboard driver header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#ifndef KB_H
|
#ifndef KB_H
|
||||||
#define KB_H
|
#define KB_H
|
||||||
|
|
||||||
|
#define KEYBOARD_BUFFER_SIZE 256
|
||||||
|
|
||||||
|
#define LEFT_SHIFT_PRESSED 0x2A
|
||||||
|
#define RIGHT_SHIFT_PRESSED 0x36
|
||||||
|
#define LEFT_SHIFT_RELEASED 0xAA
|
||||||
|
#define RIGHT_SHIFT_RELEASED 0xB6
|
||||||
|
|
||||||
char keyboard_getchar();
|
char keyboard_getchar();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
// Serial I/O driver
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../kernel/io.h"
|
#include "../kernel/io.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
@@ -279,4 +284,3 @@ void serial_printf(int errlevel, const char* fmt, ...)
|
|||||||
}
|
}
|
||||||
serial_puts("\n");
|
serial_puts("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
#ifndef INCLUDE_SERIAL_H
|
// Serial I/O driver header
|
||||||
#define INCLUDE_SERIAL_H
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
|
#ifndef SERIAL_H
|
||||||
|
#define SERIAL_H
|
||||||
|
|
||||||
#define PORT 0x3f8 //COM1
|
#define PORT 0x3f8 //COM1
|
||||||
|
|
||||||
@@ -9,4 +14,5 @@ void write_serial(const char a);
|
|||||||
void serial_puts(const char* str);
|
void serial_puts(const char* str);
|
||||||
void log(const char* str, const int errlevel);
|
void log(const char* str, const int errlevel);
|
||||||
void serial_printf(int errlevel, const char* fmt, ...);
|
void serial_printf(int errlevel, const char* fmt, ...);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
// Programmable Interval Timer channel 0 driver
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../kernel/system.h"
|
#include "../kernel/system.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,11 @@
|
|||||||
|
// Global descriptor table setup
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "gdt.h"
|
#include "gdt.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
|
|
||||||
struct gdt_entry
|
|
||||||
{
|
|
||||||
unsigned short limit_low;
|
|
||||||
unsigned short base_low;
|
|
||||||
unsigned char base_middle;
|
|
||||||
unsigned char access;
|
|
||||||
unsigned char granularity;
|
|
||||||
unsigned char base_high;
|
|
||||||
} __attribute__((packed));
|
|
||||||
|
|
||||||
struct gdt_ptr
|
|
||||||
{
|
|
||||||
unsigned short limit;
|
|
||||||
unsigned int base;
|
|
||||||
} __attribute__((packed));
|
|
||||||
|
|
||||||
struct gdt_entry gdt[3];
|
struct gdt_entry gdt[3];
|
||||||
struct gdt_ptr gp;
|
struct gdt_ptr gp;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,28 @@
|
|||||||
|
// Global descriptor table setup header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#ifndef GDT_H
|
#ifndef GDT_H
|
||||||
#define GDT_H
|
#define GDT_H
|
||||||
|
|
||||||
void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
|
struct gdt_entry
|
||||||
|
{
|
||||||
|
unsigned short limit_low;
|
||||||
|
unsigned short base_low;
|
||||||
|
unsigned char base_middle;
|
||||||
|
unsigned char access;
|
||||||
|
unsigned char granularity;
|
||||||
|
unsigned char base_high;
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
struct gdt_ptr
|
||||||
|
{
|
||||||
|
unsigned short limit;
|
||||||
|
unsigned int base;
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
|
||||||
void gdt_install();
|
void gdt_install();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,22 +1,12 @@
|
|||||||
|
// Interrupt descriptor table setup
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "idt.h"
|
#include "idt.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
|
|
||||||
struct idt_entry
|
|
||||||
{
|
|
||||||
unsigned short base_lo;
|
|
||||||
unsigned short sel;
|
|
||||||
unsigned char always0;
|
|
||||||
unsigned char flags;
|
|
||||||
unsigned short base_hi;
|
|
||||||
} __attribute__((packed));
|
|
||||||
|
|
||||||
struct idt_ptr
|
|
||||||
{
|
|
||||||
unsigned short limit;
|
|
||||||
unsigned int base;
|
|
||||||
} __attribute__((packed));
|
|
||||||
|
|
||||||
struct idt_entry idt[256];
|
struct idt_entry idt[256];
|
||||||
struct idt_ptr idtp;
|
struct idt_ptr idtp;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,27 @@
|
|||||||
|
// Interrupt descriptor table setup header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#ifndef IDT_H
|
#ifndef IDT_H
|
||||||
#define IDT_H
|
#define IDT_H
|
||||||
|
|
||||||
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags);
|
struct idt_entry
|
||||||
|
{
|
||||||
|
unsigned short base_lo;
|
||||||
|
unsigned short sel;
|
||||||
|
unsigned char always0;
|
||||||
|
unsigned char flags;
|
||||||
|
unsigned short base_hi;
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
struct idt_ptr
|
||||||
|
{
|
||||||
|
unsigned short limit;
|
||||||
|
unsigned int base;
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags);
|
||||||
void idt_install();
|
void idt_install();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
#ifndef INCLUDE_IO_H
|
// Raw CPU port I/O kernel module header
|
||||||
#define INCLUDE_IO_H
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../libc/stdint.h"
|
#ifndef IO_H
|
||||||
|
#define IO_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
void outb(unsigned short port, unsigned char data);
|
void outb(unsigned short port, unsigned char data);
|
||||||
unsigned char inb(unsigned short port);
|
unsigned char inb(unsigned short port);
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
; Raw CPU port I/O kernel module
|
||||||
|
; Author: xamidev
|
||||||
|
; Licensed under the Unlicense. See the repo below.
|
||||||
|
; https://github.com/xamidev/blankos
|
||||||
|
|
||||||
global outb
|
global outb
|
||||||
|
|
||||||
outb:
|
outb:
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
// Interrupt Requests setup
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "idt.h"
|
#include "idt.h"
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
// Interrupt service routines setup
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "idt.h"
|
#include "idt.h"
|
||||||
@@ -37,7 +42,6 @@ extern void isr31();
|
|||||||
|
|
||||||
void isr_install()
|
void isr_install()
|
||||||
{
|
{
|
||||||
|
|
||||||
idt_set_gate(0, (unsigned)isr0, 0x08, 0x8E);
|
idt_set_gate(0, (unsigned)isr0, 0x08, 0x8E);
|
||||||
idt_set_gate(1, (unsigned)isr1, 0x08, 0x8E);
|
idt_set_gate(1, (unsigned)isr1, 0x08, 0x8E);
|
||||||
idt_set_gate(2, (unsigned)isr2, 0x08, 0x8E);
|
idt_set_gate(2, (unsigned)isr2, 0x08, 0x8E);
|
||||||
@@ -116,4 +120,3 @@ void fault_handler(struct regs *r)
|
|||||||
for (;;);
|
for (;;);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
#include "kheap.h"
|
// Kernel heap management
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../libc/stdint.h"
|
#include "kheap.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
extern uint32_t end;
|
extern uint32_t end;
|
||||||
uint32_t placement_address = (uint32_t)&end;
|
uint32_t placement_address = (uint32_t)&end;
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
|
// Kernel heap management header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#ifndef KHEAP_H
|
#ifndef KHEAP_H
|
||||||
#define KHEAP_H
|
#define KHEAP_H
|
||||||
|
|
||||||
#include "../libc/stdint.h"
|
#include <stdint.h>
|
||||||
|
|
||||||
uint32_t kmalloc_a(uint32_t sz);
|
uint32_t kmalloc_a(uint32_t sz);
|
||||||
uint32_t kmalloc_p(uint32_t sz, uint32_t *phys);
|
uint32_t kmalloc_p(uint32_t sz, uint32_t *phys);
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
// Kernel entry point
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "../drivers/serial.h"
|
#include "../drivers/serial.h"
|
||||||
#include "gdt.h"
|
#include "gdt.h"
|
||||||
@@ -5,40 +10,12 @@
|
|||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "paging.h"
|
#include "paging.h"
|
||||||
#include "../drivers/ata.h"
|
#include "../drivers/ata.h"
|
||||||
#include "../libc/stdint.h"
|
#include <stdint.h>
|
||||||
#include "../drivers/framebuffer.h"
|
#include "../drivers/framebuffer.h"
|
||||||
|
#include "kmain.h"
|
||||||
typedef struct {
|
|
||||||
uint32_t type;
|
|
||||||
uint32_t size;
|
|
||||||
uint64_t framebuffer_addr;
|
|
||||||
uint32_t framebuffer_pitch;
|
|
||||||
uint32_t framebuffer_width;
|
|
||||||
uint32_t framebuffer_height;
|
|
||||||
uint8_t framebuffer_bpp;
|
|
||||||
uint8_t framebuffer_type;
|
|
||||||
uint16_t reserved;
|
|
||||||
} multiboot2_tag_framebuffer;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint32_t total_size;
|
|
||||||
uint32_t reserved;
|
|
||||||
uint8_t tags[0];
|
|
||||||
} multiboot2_info;
|
|
||||||
|
|
||||||
unsigned int g_multiboot_info_address;
|
|
||||||
|
|
||||||
uint32_t* framebuffer;
|
|
||||||
int scanline;
|
|
||||||
|
|
||||||
// in characters, not pixels
|
|
||||||
uint32_t VGA_WIDTH;
|
|
||||||
uint32_t VGA_HEIGHT;
|
|
||||||
|
|
||||||
|
|
||||||
void kmain(multiboot2_info *mb_info)
|
void kmain(multiboot2_info *mb_info)
|
||||||
{
|
{
|
||||||
|
|
||||||
multiboot2_tag_framebuffer *fb_info = NULL;
|
multiboot2_tag_framebuffer *fb_info = NULL;
|
||||||
|
|
||||||
uint8_t *tags = mb_info->tags;
|
uint8_t *tags = mb_info->tags;
|
||||||
@@ -60,38 +37,23 @@ uint8_t *tags = mb_info->tags;
|
|||||||
serial_printf(3, "Framebuffer Pitch: %u\r\n", fb_info->framebuffer_pitch);
|
serial_printf(3, "Framebuffer Pitch: %u\r\n", fb_info->framebuffer_pitch);
|
||||||
serial_printf(3, "Framebuffer BPP: %u\r\n", fb_info->framebuffer_bpp);
|
serial_printf(3, "Framebuffer BPP: %u\r\n", fb_info->framebuffer_bpp);
|
||||||
|
|
||||||
|
|
||||||
if (fb_info) {
|
if (fb_info) {
|
||||||
framebuffer = (uint32_t *)(uintptr_t) fb_info->framebuffer_addr;
|
framebuffer = (uint32_t *)(uintptr_t) fb_info->framebuffer_addr;
|
||||||
|
|
||||||
uint32_t width = fb_info->framebuffer_width;
|
uint32_t width = fb_info->framebuffer_width;
|
||||||
uint32_t height = fb_info->framebuffer_height;
|
uint32_t height = fb_info->framebuffer_height;
|
||||||
//uint32_t pitch = fb_info->framebuffer_pitch;
|
|
||||||
uint32_t bpp = fb_info->framebuffer_bpp;
|
uint32_t bpp = fb_info->framebuffer_bpp;
|
||||||
|
|
||||||
|
|
||||||
//8x16 font, not padded
|
//8x16 font, not padded
|
||||||
VGA_WIDTH = width/8;
|
VGA_WIDTH = width/8;
|
||||||
VGA_HEIGHT = height/16;
|
VGA_HEIGHT = height/16;
|
||||||
|
|
||||||
scanline = width * (bpp/8);
|
scanline = width * (bpp/8);
|
||||||
|
|
||||||
|
|
||||||
/* TEST print charset
|
|
||||||
int y_offset = 2;
|
|
||||||
for (int i=0; i<512; i++)
|
|
||||||
{
|
|
||||||
if (i%(width/9)==0) y_offset++;
|
|
||||||
draw_char(0+i, 0+i, y_offset, white, black);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("[kernel] multiboot2 info at 0x%x, size=%u\n", mb_info, mb_info->total_size);
|
printf("[kernel] multiboot2 info at 0x%x, size=%u\n", mb_info, mb_info->total_size);
|
||||||
printf("[kernel] framebuffer discovered at 0x%x\n", fb_info->framebuffer_addr);
|
printf("[kernel] framebuffer discovered at 0x%x\n", fb_info->framebuffer_addr);
|
||||||
printf("[kernel] fb0: width=%u, height=%u, pitch=%u, bpp=%u\n", fb_info->framebuffer_width, fb_info->framebuffer_height, fb_info->framebuffer_pitch, fb_info->framebuffer_bpp);
|
printf("[kernel] fb0: width=%u, height=%u, pitch=%u, bpp=%u\n", fb_info->framebuffer_width, fb_info->framebuffer_height, fb_info->framebuffer_pitch, fb_info->framebuffer_bpp);
|
||||||
|
|
||||||
|
|
||||||
init_serial();
|
init_serial();
|
||||||
gdt_install();
|
gdt_install();
|
||||||
idt_install();
|
idt_install();
|
||||||
@@ -100,9 +62,7 @@ uint8_t *tags = mb_info->tags;
|
|||||||
__asm__ __volatile__("sti");
|
__asm__ __volatile__("sti");
|
||||||
|
|
||||||
//init_paging();
|
//init_paging();
|
||||||
|
|
||||||
//test_read_sector();
|
//test_read_sector();
|
||||||
|
|
||||||
//uint32_t *ptr = (uint32_t*)0xA0000000;
|
//uint32_t *ptr = (uint32_t*)0xA0000000;
|
||||||
//uint32_t do_page_fault = *ptr;
|
//uint32_t do_page_fault = *ptr;
|
||||||
|
|
||||||
@@ -110,5 +70,4 @@ uint8_t *tags = mb_info->tags;
|
|||||||
keyboard_install();
|
keyboard_install();
|
||||||
printf("[kernel] spawning shell...\n");
|
printf("[kernel] spawning shell...\n");
|
||||||
shell_install();
|
shell_install();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
36
src/kernel/kmain.h
Normal file
36
src/kernel/kmain.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// Kernel entry point header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
|
#ifndef KMAIN_H
|
||||||
|
#define KMAIN_H
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t type;
|
||||||
|
uint32_t size;
|
||||||
|
uint64_t framebuffer_addr;
|
||||||
|
uint32_t framebuffer_pitch;
|
||||||
|
uint32_t framebuffer_width;
|
||||||
|
uint32_t framebuffer_height;
|
||||||
|
uint8_t framebuffer_bpp;
|
||||||
|
uint8_t framebuffer_type;
|
||||||
|
uint16_t reserved;
|
||||||
|
} multiboot2_tag_framebuffer;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t total_size;
|
||||||
|
uint32_t reserved;
|
||||||
|
uint8_t tags[0];
|
||||||
|
} multiboot2_info;
|
||||||
|
|
||||||
|
unsigned int g_multiboot_info_address;
|
||||||
|
|
||||||
|
uint32_t* framebuffer;
|
||||||
|
int scanline;
|
||||||
|
|
||||||
|
// in characters, not pixels
|
||||||
|
uint32_t VGA_WIDTH;
|
||||||
|
uint32_t VGA_HEIGHT;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
|
; Kernel loader assembly stub and multiboot2 header
|
||||||
|
; Author: xamidev
|
||||||
|
; Licensed under the Unlicense. See the repo below.
|
||||||
|
; https://github.com/xamidev/blankos
|
||||||
|
|
||||||
global loader
|
global loader
|
||||||
|
|
||||||
section .multiboot_header
|
section .multiboot_header
|
||||||
@@ -44,8 +49,6 @@ extern kmain
|
|||||||
|
|
||||||
loader:
|
loader:
|
||||||
cli
|
cli
|
||||||
; mov eax, 0xCAFEBABE
|
|
||||||
; push dword 42
|
|
||||||
push ebx
|
push ebx
|
||||||
call kmain
|
call kmain
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
#include "../libc/stdint.h"
|
// Paging kernel module
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include "paging.h"
|
#include "paging.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "kheap.h"
|
#include "kheap.h"
|
||||||
|
|
||||||
|
|
||||||
uint32_t *frames;
|
uint32_t *frames;
|
||||||
uint32_t nframes;
|
uint32_t nframes;
|
||||||
|
|
||||||
extern uint32_t placement_address;
|
extern uint32_t placement_address;
|
||||||
|
|
||||||
#define INDEX_FROM_BIT(a) (a/(8*4))
|
|
||||||
#define OFFSET_FROM_BIT(a) (a%(8*4))
|
|
||||||
|
|
||||||
static void set_frame(uint32_t frame_addr)
|
static void set_frame(uint32_t frame_addr)
|
||||||
{
|
{
|
||||||
uint32_t frame = frame_addr/0x1000;
|
uint32_t frame = frame_addr/0x1000;
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
|
// Paging kernel module header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#ifndef PAGING_H
|
#ifndef PAGING_H
|
||||||
#define PAGING_H
|
#define PAGING_H
|
||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "../libc/stdint.h"
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define INDEX_FROM_BIT(a) (a/(8*4))
|
||||||
|
#define OFFSET_FROM_BIT(a) (a%(8*4))
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t present : 1;
|
uint32_t present : 1;
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
|
// Basic shell and commands kernel module
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "../libc/string.h"
|
#include "../libc/string.h"
|
||||||
#include "../programs/programs.h"
|
#include "../programs/programs.h"
|
||||||
#include "../libc/stdint.h"
|
#include <stdint.h>
|
||||||
|
|
||||||
#define BUFFER_SIZE 256
|
#define BUFFER_SIZE 256
|
||||||
#define MAX_COMMANDS 16
|
#define MAX_COMMANDS 16
|
||||||
#define MAX_ARGS 64
|
#define MAX_ARGS 64
|
||||||
|
|
||||||
|
|
||||||
char* ascii_title =
|
char* ascii_title =
|
||||||
"\n"
|
"\n"
|
||||||
"----------------------------------------------\n"
|
"----------------------------------------------\n"
|
||||||
@@ -17,7 +21,6 @@ char* ascii_title =
|
|||||||
"----------------------------------------------\n"
|
"----------------------------------------------\n"
|
||||||
"\n";
|
"\n";
|
||||||
|
|
||||||
|
|
||||||
typedef void (*command_func_t)(int argc, char *argv[]);
|
typedef void (*command_func_t)(int argc, char *argv[]);
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
// System information kernel module
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "../libc/string.h"
|
#include "../libc/string.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
// System information kernel module header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#ifndef SYSINFO_H
|
#ifndef SYSINFO_H
|
||||||
#define SYSINFO_H
|
#define SYSINFO_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
|
// System utilities and routines kernel module
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "../libc/stdint.h"
|
#include <stdint.h>
|
||||||
|
|
||||||
void *memset(void *dest, char val, size_t count)
|
void *memset(void *dest, char val, size_t count)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
|
// System utilities and routines kernel module header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#ifndef SYSTEM_H
|
#ifndef SYSTEM_H
|
||||||
#define SYSTEM_H
|
#define SYSTEM_H
|
||||||
|
|
||||||
#include "../libc/stdint.h"
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef int size_t;
|
typedef int size_t;
|
||||||
|
#define NULL ((void*)0)
|
||||||
|
|
||||||
void *memset(void *dest, char val, size_t count);
|
void *memset(void *dest, char val, size_t count);
|
||||||
void *memmove(void* dest, const void* src, size_t n);
|
void *memmove(void* dest, const void* src, size_t n);
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
|
// Cryptography routines for blankos/libc
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
#include "../libc/stdint.h"
|
#include <stdint.h>
|
||||||
|
|
||||||
int lcg(int seed)
|
int lcg(int seed)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
|
// Cryptography routines for blankos/libc header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#ifndef CRYPTO_H
|
#ifndef CRYPTO_H
|
||||||
#define CRYPTO_H
|
#define CRYPTO_H
|
||||||
|
|
||||||
#define RAND_MAX 1024
|
#define RAND_MAX 1024
|
||||||
|
|
||||||
#include "../libc/stdint.h"
|
#include <stdint.h>
|
||||||
|
|
||||||
int lcg(int seed);
|
int lcg(int seed);
|
||||||
int randint(int seed);
|
int randint(int seed);
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
|
// Ctype implementation for blankos/libc
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "stdint.h"
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
bool isdigit(char c)
|
bool isdigit(char c)
|
||||||
{
|
{
|
||||||
return c >= '0' && c <= '9';
|
return c >= '0' && c <= '9';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool isspace(char c)
|
bool isspace(char c)
|
||||||
{
|
{
|
||||||
return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r';
|
return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r';
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
|
// Ctype implementation for blankos/libc header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#ifndef CTYPE_H
|
#ifndef CTYPE_H
|
||||||
#define CTYPE_H
|
#define CTYPE_H
|
||||||
|
|
||||||
#include "stdint.h"
|
#include <stdbool.h>
|
||||||
|
|
||||||
bool isdigit(char c);
|
bool isdigit(char c);
|
||||||
bool isspace(char c);
|
bool isspace(char c);
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
#ifndef INCLUDE_STDINT_H
|
|
||||||
#define INCLUDE_STDINT_H
|
|
||||||
|
|
||||||
typedef signed char int8_t;
|
|
||||||
typedef unsigned char uint8_t;
|
|
||||||
|
|
||||||
typedef signed short int16_t;
|
|
||||||
typedef unsigned short uint16_t;
|
|
||||||
|
|
||||||
typedef signed long int int32_t;
|
|
||||||
typedef unsigned long int uint32_t;
|
|
||||||
|
|
||||||
typedef signed long long int int64_t;
|
|
||||||
typedef unsigned long long int uint64_t;
|
|
||||||
|
|
||||||
typedef uint8_t bool;
|
|
||||||
#define true 1
|
|
||||||
#define false 0
|
|
||||||
|
|
||||||
#define NULL ((void*)0)
|
|
||||||
|
|
||||||
typedef unsigned int uintptr_t;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
|
// Standard input/output implementation for blankos/libc
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../kernel/io.h"
|
#include "../kernel/io.h"
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "stdint.h"
|
#include <stdint.h>
|
||||||
#include "../kernel/system.h"
|
#include "../kernel/system.h"
|
||||||
#include "../drivers/framebuffer.h"
|
#include "../drivers/framebuffer.h"
|
||||||
#include "../drivers/serial.h"
|
#include "../drivers/serial.h"
|
||||||
@@ -10,9 +15,6 @@ extern uint32_t* framebuffer;
|
|||||||
extern uint32_t VGA_WIDTH;
|
extern uint32_t VGA_WIDTH;
|
||||||
extern uint32_t VGA_HEIGHT;
|
extern uint32_t VGA_HEIGHT;
|
||||||
unsigned int VGA_X = 0, VGA_Y = 0;
|
unsigned int VGA_X = 0, VGA_Y = 0;
|
||||||
|
|
||||||
#define CURSOR_WIDTH 8
|
|
||||||
#define CURSOR_HEIGHT 16
|
|
||||||
extern int scanline;
|
extern int scanline;
|
||||||
|
|
||||||
void draw_cursor(uint32_t color)
|
void draw_cursor(uint32_t color)
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
#ifndef INCLUDE_STDIO_H
|
// Standard input/output implementation for blankos/libc header
|
||||||
#define INCLUDE_STDIO_H
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "stdint.h"
|
#ifndef STDIO_H
|
||||||
|
#define STDIO_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define FB_GREEN 2
|
#define FB_GREEN 2
|
||||||
#define FB_DARK_GREY 8
|
#define FB_DARK_GREY 8
|
||||||
@@ -11,6 +17,8 @@
|
|||||||
#define FB_HIGH_BYTE_CMD 14
|
#define FB_HIGH_BYTE_CMD 14
|
||||||
#define FB_LOW_BYTE_CMD 15
|
#define FB_LOW_BYTE_CMD 15
|
||||||
|
|
||||||
|
#define CURSOR_WIDTH 8
|
||||||
|
#define CURSOR_HEIGHT 16
|
||||||
|
|
||||||
void draw_cursor(uint32_t color);
|
void draw_cursor(uint32_t color);
|
||||||
void erase_cursor();
|
void erase_cursor();
|
||||||
@@ -43,7 +51,6 @@ void printf(const char* fmt, ...);
|
|||||||
int* printf_number(int* argp, int length, bool sign, int radix, int width, char pad_char);
|
int* printf_number(int* argp, int length, bool sign, int radix, int width, char pad_char);
|
||||||
int getch();
|
int getch();
|
||||||
void get_input(char *buffer, int size);
|
void get_input(char *buffer, int size);
|
||||||
|
|
||||||
void dtostrf(double val, char *buffer, int precision);
|
void dtostrf(double val, char *buffer, int precision);
|
||||||
|
|
||||||
enum Colors
|
enum Colors
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
#include "stdint.h"
|
// String operations implementation for blankos/libc
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "../kernel/system.h"
|
||||||
|
|
||||||
int strlen(const char* str)
|
int strlen(const char* str)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
#ifndef INCLUDE_STRING_H
|
// String operations implementation for blankos/libc header
|
||||||
#define INCLUDE_STRING_H
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
|
#ifndef STRING_H
|
||||||
|
#define STRING_H
|
||||||
|
|
||||||
int strlen(const char* str);
|
int strlen(const char* str);
|
||||||
int strcmp(const char* str1, const char* str2);
|
int strcmp(const char* str1, const char* str2);
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// Simple brainfuck interpreter program
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../kernel/system.h"
|
#include "../kernel/system.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
|
// Cipher programs
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "ciphers.h"
|
#include "ciphers.h"
|
||||||
|
#include "../libc/string.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
void rot13(char* input, char* output)
|
void rot13(char* input, char* output)
|
||||||
{
|
{
|
||||||
@@ -32,9 +39,6 @@ void program_rot13()
|
|||||||
printf("\n%s\n", output);
|
printf("\n%s\n", output);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "../libc/string.h"
|
|
||||||
#include "../libc/stdint.h"
|
|
||||||
|
|
||||||
const char* morse_alphabet[] = {
|
const char* morse_alphabet[] = {
|
||||||
".-", // A
|
".-", // A
|
||||||
"-...", // B
|
"-...", // B
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
// Cipher programs header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#ifndef CIPHERS_H
|
#ifndef CIPHERS_H
|
||||||
#define CIPHERS_H
|
#define CIPHERS_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
|
// Conway's Game of Life program
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "conway.h"
|
#include "conway.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "../kernel/system.h"
|
#include "../kernel/system.h"
|
||||||
#include "../libc/crypto.h"
|
#include "../libc/crypto.h"
|
||||||
#include "../libc/stdint.h"
|
#include <stdint.h>
|
||||||
#include "../drivers/serial.h"
|
#include "../drivers/serial.h"
|
||||||
#include "../libc/string.h"
|
#include "../libc/string.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
// Conway's Game of Life program header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#ifndef CONWAY_H
|
#ifndef CONWAY_H
|
||||||
#define CONWAY_H
|
#define CONWAY_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
// Math expression lexer and parser
|
// Basic math expression lexer and parser program
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../libc/stdint.h"
|
#include <stdint.h>
|
||||||
#include "../kernel/system.h"
|
#include "../kernel/system.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "../libc/ctype.h"
|
#include "../libc/ctype.h"
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
// Miscellaneous small programs
|
// Miscellaneous small programs
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "../kernel/system.h"
|
#include "../kernel/system.h"
|
||||||
@@ -30,7 +33,7 @@ void program_rainbow()
|
|||||||
|
|
||||||
void program_clear()
|
void program_clear()
|
||||||
{
|
{
|
||||||
for (int i=0; i<ROWS; i++) scroll();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get uptime in ticks
|
// Get uptime in ticks
|
||||||
@@ -38,7 +41,7 @@ void program_clear()
|
|||||||
void program_uptime()
|
void program_uptime()
|
||||||
{
|
{
|
||||||
int ticks = uptime();
|
int ticks = uptime();
|
||||||
double seconds = ticks/18.2065; // PIC channel 0 freq
|
double seconds = ticks/18.2065; // PIT channel 0 freq
|
||||||
printf("%d ticks\t%f seconds\n", ticks, seconds);
|
printf("%d ticks\t%f seconds\n", ticks, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
#include "../libc/stdint.h"
|
// Prime number computation program
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "../kernel/system.h"
|
#include "../kernel/system.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
// Global program entry points header
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#ifndef PROGRAMS_H
|
#ifndef PROGRAMS_H
|
||||||
#define PROGRAMS_H
|
#define PROGRAMS_H
|
||||||
|
|
||||||
@@ -22,4 +27,5 @@ void program_uptime();
|
|||||||
void program_panic();
|
void program_panic();
|
||||||
void program_help();
|
void program_help();
|
||||||
void program_echo();
|
void program_echo();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// System information program
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../kernel/sysinfo.h"
|
#include "../kernel/sysinfo.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// Pseudo-random word generation program
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "../libc/crypto.h"
|
#include "../libc/crypto.h"
|
||||||
@@ -37,7 +41,7 @@ char* words[] =
|
|||||||
|
|
||||||
int words_size = sizeof(words)/sizeof(words[0]);
|
int words_size = sizeof(words)/sizeof(words[0]);
|
||||||
|
|
||||||
// Generates 5 random words
|
// Generates random words
|
||||||
void program_words()
|
void program_words()
|
||||||
{
|
{
|
||||||
for (int i=0; i<10; i++)
|
for (int i=0; i<10; i++)
|
||||||
|
|||||||
Reference in New Issue
Block a user