get HOS building again on Ubuntu 17.04 with GCC 6

This commit is contained in:
Josh Holtrop 2017-07-26 13:41:23 -04:00
parent 0aaf5db5ad
commit 509009d134
10 changed files with 178 additions and 198 deletions

View File

@ -8,15 +8,16 @@ NASM=nasm
NASM_FLAGS=-f aout
# 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:

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

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++)
{

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()

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

View File

@ -97,7 +97,7 @@ isr_main_nodup:
push esp
push eax ;interrupt number
call _isr
call isr
add esp, 8
pop gs

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

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);

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

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 : {