5 Commits
Author SHA1 Message Date
josh 1f5e3507ba change nasm output format to elf32 2020-10-02 10:21:10 -04:00
josh a9a6f6f4d4 avoid make jobserver warnings 2020-10-02 10:17:32 -04:00
josh 2d009273a1 add readme.txt 2017-07-26 13:51:58 -04:00
josh 2b936758ff add .gitignore 2017-07-26 13:42:21 -04:00
josh 509009d134 get HOS building again on Ubuntu 17.04 with GCC 6 2017-07-26 13:41:23 -04:00
13 changed files with 267 additions and 192 deletions

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
/hos.flp
/hos_initrd
/hos_initrd.gz
*.lst
*.map
*.bin
+6 -6
View File
@@ -19,16 +19,16 @@ MAKEFLAGS += --no-print-directory
.PHONY: all clean initrd apps grub_image install install_img depend copy_image bochs bochsq
all:
make -C kernel
make -C rmmod
${MAKE} -C kernel
${MAKE} -C rmmod
clean:
-make -C kernel clean
-make -C rmmod clean
-${MAKE} -C kernel clean
-${MAKE} -C rmmod clean
-rm -f *~ *.out hos.flp \#* hos_initrd hos_initrd.gz
apps:
make -C apps
${MAKE} -C apps
grub_image:
dd if=/dev/zero of=$(GRUB_IMAGE) bs=1024 seek=1440 count=0
@@ -75,7 +75,7 @@ initrd:
gzip -c $(INITRD) > $(INITRD).gz
depend:
make -C kernel depend
${MAKE} -C kernel depend
bochs:
bochs
+7 -6
View File
@@ -5,18 +5,19 @@
# Assembler Information:
NASM=nasm
NASM_FLAGS=-f aout
NASM_FLAGS=-f elf32
# C/C++ Information:
CPPFLAGS=-fleading-underscore -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -I. -Wall
CPPFLAGS=-ffreestanding -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -I. -Wall -m32 -fno-pic
# -S -masm=intel
CC=gcc
CXX=g++
CXXFLAGS=-fno-rtti -fno-exceptions -D_HOS_CPP_
CXXFLAGS=-fno-rtti -fno-exceptions -D_HOS_CPP_ -std=gnu++98
# Linker Information:
LD=ld
LDFLAGS=-nodefaultlibs -nostdlib --no-demangle -T link.ld
LD=gcc
LDFLAGS=-ffreestanding -fno-builtin -nostartfiles -nodefaultlibs -nostdlib -Wl,--no-demangle -T link.ld -m32
LIBS=-static-libgcc
# Files
OBJS=boot.o lang/lang_a.o \
@@ -43,7 +44,7 @@ CXXSRC=lang/string.cpp lang/new.cpp char/misc_char.cpp char/vconsole.cpp \
.PHONY: all depend clean html
all: $(OBJS)
$(LD) $(LDFLAGS) -Map kernel.map $(OBJS) -o kernel.bin
$(LD) $(LDFLAGS) -Wl,-Map -Wl,kernel.map $(OBJS) -o kernel.bin $(LIBS)
@echo ' Kernel built: ' `ls -sk kernel.bin | cut -d' ' -f1`kb
depend:
+14 -14
View File
@@ -25,23 +25,23 @@
%define KERNEL_P PHYS_START+0x8000 ;1mb+32kb - the kernel's physical address
%define KERNEL_V KERNEL_P+VIRT_OFFSET ;3gb+1mb+32kb, the virtual address of the kernel
extern _k_init, _isr, _k_mbsave, _end, _rm_params, _initrd, _tss0
extern k_init, isr, k_mbsave, end, rm_params, initrd, tss0
[bits 32]
[global _start]
_start:
[global start]
start:
multiboot_header:
dd MULTIBOOT_MAGIC ;magic
dd MULTIBOOT_FLAGS ;flags
dd -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS) ;checksum
dd multiboot_header-VIRT_OFFSET ;header_addr
dd _start-VIRT_OFFSET ;load_addr
dd 0x100000000+multiboot_header-VIRT_OFFSET ;header_addr
dd 0x100000000+start-VIRT_OFFSET ;load_addr
dd 0 ;load_end_addr
dd _end-VIRT_OFFSET ;bss_end_addr
dd multiboot_entry-VIRT_OFFSET ;entry_addr
dd 0x100000000+end-VIRT_OFFSET ;bss_end_addr
dd 0x100000000+multiboot_entry-VIRT_OFFSET ;entry_addr
; dd 1 ;mode_type
; dd 80 ;width
@@ -53,7 +53,7 @@ multiboot_entry:
;This is where the kernel begins execution from the bootloader.
;At this point, a temporary gdt is set up to "map" 0xC000_0000 to 0x0.
cli ;should already be off...
lgdt [gdtrbs32-VIRT_OFFSET]
lgdt [0x100000000+gdtrbs32-VIRT_OFFSET]
jmp KERNEL_CODE_BS32:segmented_start
segmented_start:
mov cx, KERNEL_DATA_BS32
@@ -68,7 +68,7 @@ segmented_start:
add ebx, VIRT_OFFSET
push eax
push ebx ;pointer to multiboot info structure
call _k_mbsave ;save multiboot info structures
call k_mbsave ;save multiboot info structures
add esp, 8
cmp eax, 0 ; eax = pointer to mb_module_t struct for rmmod
@@ -86,7 +86,7 @@ segmented_start:
rep movsd ; copy rmmod to first 1mb
mov ebx, pm_return ; return address
mov ecx, _rm_params ; put real mode params here (video mode etc...)
mov ecx, rm_params ; put real mode params here (video mode etc...)
sub ecx, VIRT_OFFSET
jmp 0xC0005010 ; jump to rmmod
@@ -161,8 +161,8 @@ newgdtcontinue:
lidt [idtr] ;load idt
mov [PDBR_V], dword 0 ;unmap 0x0, we are running completely paged at 0xC000_0000
mov edi, GDT_V + TSS0_SEG + 2 ; copy _tss0 base address
mov eax, _tss0 ; into the GDT descrtiptor
mov edi, GDT_V + TSS0_SEG + 2 ; copy tss0 base address
mov eax, tss0 ; into the GDT descrtiptor
stosw ; for TSS0
shr eax, 16
stosb
@@ -170,7 +170,7 @@ newgdtcontinue:
shr eax, 8
stosb
call _k_init ;C kernel initialization
call k_init ;C kernel initialization
mov ax, TSS0_SEG
ltr ax
@@ -187,7 +187,7 @@ idle_loop: ; system idle loop
;-------------------------------------------------------
gdtrbs32:
dw gdt_endbs32-gdtbs32-1
dd gdtbs32-VIRT_OFFSET
dd 0x100000000+gdtbs32-VIRT_OFFSET
gdtbs32: ; 0 = null descriptor
dd 0
dd 0
+2 -2
View File
@@ -29,7 +29,7 @@ Ext2OpenFile::Ext2OpenFile(Ext2fs *fs, u32_t inum, int mode)
myBlockCacheStatus = 0; /* 0: invalid; 1: valid; 2: dirty */
fs->readInode(inum, &myInode);
myCache = new Ext2BlockCache(fs, inum, &myInode);
lock(&Ext2OpenFileListLock);
lockit(&Ext2OpenFileListLock);
if ((mode & VFS_MODE_RW_MASK) == VFS_MODE_WRITE)
{
if ((mode & VFS_MODE_WRITE_MASK) == VFS_MODE_TRUNCATE)
@@ -62,7 +62,7 @@ Ext2OpenFile::Ext2OpenFile(Ext2fs *fs, u32_t inum, int mode)
Ext2OpenFile::~Ext2OpenFile()
{
/* remove ourselves from the open file list */
lock(&Ext2OpenFileListLock);
lockit(&Ext2OpenFileListLock);
u32_t size = Ext2OpenFileList->size();
for (u32_t i = 0; i < size; i++)
{
+6
View File
@@ -9,9 +9,15 @@
#include "hos_defines.h"
#include "sys/io.h"
#ifdef __cplusplus
extern "C" {
#endif
extern u32_t _code;
extern u32_t _bss;
extern u32_t _end;
#ifdef __cplusplus
}
#endif
//Enables (SeTs) Interrupt Flag on the processor
static inline void enable_ints()
+6
View File
@@ -44,9 +44,15 @@ typedef unsigned char u8_t;
typedef unsigned char byte;
typedef int lock_t;
#ifdef __cplusplus
extern "C" {
#endif
extern u32_t _end;
extern u32_t _bss;
extern u32_t start;
#ifdef __cplusplus
}
#endif
#endif
+1 -1
View File
@@ -97,7 +97,7 @@ isr_main_nodup:
push esp
push eax ;interrupt number
call _isr
call isr
add esp, 8
pop gs
+38 -38
View File
@@ -13,8 +13,8 @@
%endmacro
;implements a lock
[global _lock]
_lock:
[global lockit]
lockit:
push ebp
mov ebp, esp
push eax
@@ -35,8 +35,8 @@ _lock_loop0:
ret
;releases a lock
[global _unlock]
_unlock:
[global unlock]
unlock:
push ebp
mov ebp, esp
push esi
@@ -50,15 +50,15 @@ _unlock:
;returns the value in the CR0 register
;extern dword read_cr0();
[global _read_cr0]
_read_cr0:
[global read_cr0]
read_cr0:
mov eax, cr0;
ret
;stores the parameter to the CR0 register
;extern dword write_cr0(dword cr0);
[global _write_cr0]
_write_cr0:
[global write_cr0]
write_cr0:
push ebp
mov ebp, esp
mov eax, [ebp+8]
@@ -68,8 +68,8 @@ _write_cr0:
;returns the value in the CR2 register
;extern dword read_cr2();
[global _read_cr2]
_read_cr2:
[global read_cr2]
read_cr2:
mov eax, cr2;
ret
@@ -77,16 +77,16 @@ _read_cr2:
;returns the value in the CR3 register
;extern dword read_cr3();
[global _read_cr3]
_read_cr3:
[global read_cr3]
read_cr3:
mov eax, cr3;
ret
;stores the parameter to the CR3 register
;extern dword write_cr3(dword cr3);
[global _write_cr3]
_write_cr3:
[global write_cr3]
write_cr3:
push ebp
mov ebp, esp
mov eax, [ebp+8]
@@ -96,16 +96,16 @@ _write_cr3:
; read ss register
[global _read_ss]
_read_ss:
[global read_ss]
read_ss:
mov ax, ss
ret
;copies a string from the source to the destination parameter
;extern void strcpy(char *dest, char *src);
[global _strcpy]
_strcpy:
[global strcpy]
strcpy:
push ebp
mov ebp, esp
push esi
@@ -124,8 +124,8 @@ strcpyloop:
;copies memory of n bytes from src to destination
;void memcpy(void *dest, void *src, dword n);
[global _memcpy]
_memcpy:
[global memcpy]
memcpy:
push ebp
mov ebp, esp
push esi
@@ -147,8 +147,8 @@ _memcpy:
;copies memory of n words (n*2 bytes) from src to destination
;void memcpyw(void *dest, void *src, dword n);
[global _memcpyw]
_memcpyw:
[global memcpyw]
memcpyw:
push ebp
mov ebp, esp
push esi
@@ -170,8 +170,8 @@ _memcpyw:
;copies memory of n dwords (n*4 bytes) from src to destination
;void memcpyd(void *dest, void *src, dword n);
[global _memcpyd]
_memcpyd:
[global memcpyd]
memcpyd:
push ebp
mov ebp, esp
push esi
@@ -193,8 +193,8 @@ _memcpyd:
;sets num bytes at buffer to the value of c
;void *memset(void *buffer, int c, int num);
[global _memset]
_memset:
[global memset]
memset:
push ebp
mov ebp, esp
push edi
@@ -215,8 +215,8 @@ _memset:
;sets num words at buffer to the value of c
;void *memsetw(void *buffer, int c, int num);
[global _memsetw]
_memsetw:
[global memsetw]
memsetw:
push ebp
mov ebp, esp
push edi
@@ -237,8 +237,8 @@ _memsetw:
;sets num dwords at buffer to the value of c
;void *memsetd(void *buffer, int c, int num);
[global _memsetd]
_memsetd:
[global memsetd]
memsetd:
push ebp
mov ebp, esp
push edi
@@ -259,8 +259,8 @@ _memsetd:
;returns the number of characters in a string
;extern dword strlen(char *str);
[global _strlen]
_strlen:
[global strlen]
strlen:
push ebp
mov ebp, esp
push esi
@@ -284,8 +284,8 @@ strlendone:
;this function invalidates the page directory/table entry that
; would be used to access the memory address given in the parameter
;extern void invlpg_(dword addr);
[global _invlpg_]
_invlpg_:
[global invlpg_]
invlpg_:
mov eax, [esp+4]
invlpg [eax]
ret
@@ -294,8 +294,8 @@ _invlpg_:
;
;void writeCursorPosition(word pos)
;
[global _writeCursorPosition]
_writeCursorPosition:
[global writeCursorPosition]
writeCursorPosition:
push ebp
mov ebp, esp
@@ -333,8 +333,8 @@ _writeCursorPosition:
;
;word getCursorPosition()
;
[global _getCursorPosition]
_getCursorPosition:
[global getCursorPosition]
getCursorPosition:
push ebx
push edx
+1 -1
View File
@@ -9,7 +9,7 @@
#include "hos_defines.h"
/* lang.asm */
void lock(lock_t *addr);
void lockit(lock_t *addr);
void unlock(lock_t *addr);
u32_t read_cr0();
u32_t write_cr0(u32_t cr0);
+87 -121
View File
@@ -15,6 +15,8 @@ template<typename type>
class vector
{
protected:
typedef type * type_ptr_t;
/* Pointers to vector elements */
type **myData;
@@ -25,127 +27,80 @@ protected:
unsigned int myAllocated;
/* Causes the vector to double in its allocated size */
void grow();
public:
/* Constructors/Destructor */
vector<type>();
vector<type>(unsigned int size);
vector<type>(const vector<type> & v1);
~vector<type>();
/* Assignment operator */
vector<type> & operator=(const vector<type> & v1);
/* Returns the size of the vector */
unsigned int size() const;
/* Add an element to the end of the vector */
vector<type> & add(type elem);
/* Remove an element from the vector */
vector<type> & remove(unsigned int index);
/* Insert an element into a position in the vector */
vector<type> & insert(type elem, unsigned int position);
/* Direct access operators */
const type & operator[](unsigned int index) const;
type & operator[](unsigned int index);
/* Returns pointer to data */
type **data();
};
template<typename type>
vector<type>::vector<type>()
{
myData = NULL;
mySize = 0;
myAllocated = 0;
}
template<typename type>
vector<type>::vector<type>(unsigned int size)
{
myData = new (type *)[size];
mySize = 0;
myAllocated = size;
}
template<typename type>
vector<type>::vector<type>(const vector<type> & v1)
{
mySize = v1.mySize;
myAllocated = v1.myAllocated;
myData = new (type *)[myAllocated];
for (u32_t i = 0; i < mySize; i++)
myData[i] = new type(*v1.myData[i]);
}
template<typename type>
vector<type>::~vector<type>()
{
for (unsigned int i = 0; i < mySize; i++)
delete myData[i];
delete[] myData;
}
template<typename type>
vector<type> & vector<type>::operator=(const vector<type> & v1)
{
mySize = v1.mySize;
myAllocated = v1.myAllocated;
myData = new (type *)[myAllocated];
for (u32_t i = 0; i < mySize; i++)
myData[i] = new type(*v1.myData[i]);
return *this;
}
template<typename type>
u32_t vector<type>::size() const
{
return mySize;
}
template<typename type>
const type & vector<type>::operator[](unsigned int index) const
{
return *myData[index];
}
template<typename type>
type & vector<type>::operator[](unsigned int index)
{
return *myData[index];
}
template<typename type>
vector<type> & vector<type>::add(type elem)
{
while (mySize >= myAllocated)
grow();
myData[mySize++] = new type(elem);
return *this;
}
template<typename type>
void vector<type>::grow()
{
void grow()
{
myAllocated <<= 1;
if (myAllocated == 0)
myAllocated = 1;
type **data_new = new (type *)[myAllocated];
type **data_new = new type_ptr_t[myAllocated];
for (unsigned int i = 0; i < mySize; i++)
data_new[i] = myData[i];
if (myData)
delete[] myData;
myData = data_new;
}
}
template<typename type>
vector<type> & vector<type>::remove(unsigned int index)
{
public:
/* Constructors/Destructor */
vector<type>()
{
myData = NULL;
mySize = 0;
myAllocated = 0;
}
vector<type>(unsigned int size)
{
myData = new type_ptr_t[size];
mySize = 0;
myAllocated = size;
}
vector<type>(const vector<type> & v1)
{
mySize = v1.mySize;
myAllocated = v1.myAllocated;
myData = new type_ptr_t[myAllocated];
for (u32_t i = 0; i < mySize; i++)
myData[i] = new type(*v1.myData[i]);
}
~vector<type>()
{
for (unsigned int i = 0; i < mySize; i++)
delete myData[i];
delete[] myData;
}
/* Assignment operator */
vector<type> & operator=(const vector<type> & v1)
{
mySize = v1.mySize;
myAllocated = v1.myAllocated;
myData = new type_ptr_t[myAllocated];
for (u32_t i = 0; i < mySize; i++)
myData[i] = new type(*v1.myData[i]);
return *this;
}
/* Returns the size of the vector */
unsigned int size() const
{
return mySize;
}
/* Add an element to the end of the vector */
vector<type> & add(type elem)
{
while (mySize >= myAllocated)
grow();
myData[mySize++] = new type(elem);
return *this;
}
/* Remove an element from the vector */
vector<type> & remove(unsigned int index)
{
if (index < mySize)
{
delete myData[index];
@@ -154,11 +109,11 @@ vector<type> & vector<type>::remove(unsigned int index)
mySize--;
}
return *this;
}
}
template<typename type>
vector<type> & vector<type>::insert(type elem, unsigned int position)
{
/* Insert an element into a position in the vector */
vector<type> & insert(type elem, unsigned int position)
{
if (position <= mySize)
{
if (mySize >= myAllocated)
@@ -169,13 +124,24 @@ vector<type> & vector<type>::insert(type elem, unsigned int position)
mySize++;
}
return *this;
}
}
/* Direct access operators */
const type & operator[](unsigned int index) const
{
return *myData[index];
}
template<typename type>
type **vector<type>::data()
{
type & operator[](unsigned int index)
{
return *myData[index];
}
/* Returns pointer to data */
type **data()
{
return myData;
}
}
};
#endif
+4 -3
View File
@@ -1,10 +1,11 @@
OUTPUT_FORMAT("binary")
ENTRY(_start)
ENTRY(start)
SECTIONS
{
.text 0xC0108000 : {
code = .; _code = .; __code = .;
*(.text)
*(.eh_frame*)
}
.gnulinkonce : {
*(.gnu.linkonce*)
@@ -12,8 +13,8 @@ SECTIONS
}
.data : {
data = .; _data = .; __data = .;
*(.data)
*(.rodata)
*(.data*)
*(.rodata*)
. = ALIGN(4096);
}
.bss : {
+89
View File
@@ -0,0 +1,89 @@
HOS - Holtrop's Operating System
--------------------------------
HOS is (in the process of becoming) a 32-bit, protected mode, graphical, multitasking operating system.
It was written by me, Josh Holtrop, with help from a few others along the way.
Goals: (A = accomplished, P = in progress, T = todo)
----------------------------------------------------
(A) Custom bootloader to load kernel from FAT-formatted boot media, options for video mode/ram disk
(A) Multiboot compliance - kernel can be loaded by GRUB
(A) 32-bit protected mode environment
(A) VESA Support for graphics modes
(A) PS/2 keyboard & mouse drivers
(A) Utilize x86's paging architecture for virtual memory management
(P) Console Manager
(P) VFS abstraction layer for a single file system
(P) ram disk driver
(P) devfs file system driver
(P) ext2 file system support
(T) vfat file system support
(T) Multitasking support
(T) HASH command shell
(T) Window Manager
(T) Various other utilities/applications
(T) Hard Drive (ATA) driver
(T) cdrom (ATAPI) driver
Change Log
----------
0.16
12/16/04 - initrd going to be loaded as a gzipped ext2 image (kernel module) - faster loading!
0.15
07/10/04 - Multiboot support added, loadable by GRUB
0.14
05/21/04 - C++ support in kernel, can use classes & templates
04/04/04 - video_line function for diagonal lines
03/16/04 - new VFS design with support for a loop device
03/01/04 - Thanks to Ben Meyer for helping me get a Makefile working and building on linux to work!
0.13
01/26/04 - functions added to read/write CMOS clock date and time
01/19/04 - fixed bug GDTR/IDTR pointing to physical rather than linear table base address
01/07/04 - fixed bug not reading sectors correctly from floppy
12/28/03 - fixed bug not storing eax on interrupt
12/25/03 - fixed bug in mm_palloc()
12/25/03 - incorporated output functions as regular functions rather than as part of a linked library
12/23/03 - re-written physical memory manager using bitmap instead of stack
12/22/03 - kernel relocated to 3gb linear / 1mb+24kb physical to allow for app. address space
0.12
12/21/03 - sample bmp loader tested, works (tests loading a kernel of size ~ 932kb)
12/20/03 - GDT/IDT now located at 1mb physical, before kernel
10/30/03 - turns floppy motor off
10/30/03 - keyboard LEDs working
10/29/03 - paging functions working
10/15/03 - physical memory management page allocators working
0.11
10/09/03 - PS/2 mouse driver
0.10
09/11/03 - Rewritten C and assembly kernel with VESA GUI mode support, keyboard driver
0.05
05/14/03 - HGUI24/HGUI32 commands finished for testing GUI on both 24bpp and 32bpp graphics cards
05/14/03 - first web release!
0.04
03/09/03 - added VM shortcut command
03/09/03 - press up to fill retrieve last inputted command for Nate Scholten
03/08/03 - press clear to clear console input
03/07/03 - added "shortcut" commands PC, IC, ? for Nate Scholten
03/06/03 - added PROMPTC, INPUTC commands
0.03
12/30/02 - Command Line Interface working, accepting basic commands
0.02
12/11/02 - Assembly bootsector can load stage2 ("console")
0.01
12/01/02 - Real mode assembly bootsector boots from floppy disk successfully