get HOS building again on Ubuntu 17.04 with GCC 6
This commit is contained in:
parent
0aaf5db5ad
commit
509009d134
@ -8,15 +8,16 @@ NASM=nasm
|
|||||||
NASM_FLAGS=-f aout
|
NASM_FLAGS=-f aout
|
||||||
|
|
||||||
# C/C++ Information:
|
# 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
|
# -S -masm=intel
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CXX=g++
|
CXX=g++
|
||||||
CXXFLAGS=-fno-rtti -fno-exceptions -D_HOS_CPP_
|
CXXFLAGS=-fno-rtti -fno-exceptions -D_HOS_CPP_ -std=gnu++98
|
||||||
|
|
||||||
# Linker Information:
|
# Linker Information:
|
||||||
LD=ld
|
LD=gcc
|
||||||
LDFLAGS=-nodefaultlibs -nostdlib --no-demangle -T link.ld
|
LDFLAGS=-ffreestanding -fno-builtin -nostartfiles -nodefaultlibs -nostdlib -Wl,--no-demangle -T link.ld -m32
|
||||||
|
LIBS=-static-libgcc
|
||||||
|
|
||||||
# Files
|
# Files
|
||||||
OBJS=boot.o lang/lang_a.o \
|
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
|
.PHONY: all depend clean html
|
||||||
|
|
||||||
all: $(OBJS)
|
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
|
@echo ' Kernel built: ' `ls -sk kernel.bin | cut -d' ' -f1`kb
|
||||||
|
|
||||||
depend:
|
depend:
|
||||||
|
@ -25,23 +25,23 @@
|
|||||||
%define KERNEL_P PHYS_START+0x8000 ;1mb+32kb - the kernel's physical address
|
%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
|
%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]
|
[bits 32]
|
||||||
|
|
||||||
[global _start]
|
[global start]
|
||||||
_start:
|
start:
|
||||||
|
|
||||||
multiboot_header:
|
multiboot_header:
|
||||||
dd MULTIBOOT_MAGIC ;magic
|
dd MULTIBOOT_MAGIC ;magic
|
||||||
dd MULTIBOOT_FLAGS ;flags
|
dd MULTIBOOT_FLAGS ;flags
|
||||||
dd -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS) ;checksum
|
dd -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS) ;checksum
|
||||||
|
|
||||||
dd multiboot_header-VIRT_OFFSET ;header_addr
|
dd 0x100000000+multiboot_header-VIRT_OFFSET ;header_addr
|
||||||
dd _start-VIRT_OFFSET ;load_addr
|
dd 0x100000000+start-VIRT_OFFSET ;load_addr
|
||||||
dd 0 ;load_end_addr
|
dd 0 ;load_end_addr
|
||||||
dd _end-VIRT_OFFSET ;bss_end_addr
|
dd 0x100000000+end-VIRT_OFFSET ;bss_end_addr
|
||||||
dd multiboot_entry-VIRT_OFFSET ;entry_addr
|
dd 0x100000000+multiboot_entry-VIRT_OFFSET ;entry_addr
|
||||||
|
|
||||||
; dd 1 ;mode_type
|
; dd 1 ;mode_type
|
||||||
; dd 80 ;width
|
; dd 80 ;width
|
||||||
@ -53,7 +53,7 @@ multiboot_entry:
|
|||||||
;This is where the kernel begins execution from the bootloader.
|
;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.
|
;At this point, a temporary gdt is set up to "map" 0xC000_0000 to 0x0.
|
||||||
cli ;should already be off...
|
cli ;should already be off...
|
||||||
lgdt [gdtrbs32-VIRT_OFFSET]
|
lgdt [0x100000000+gdtrbs32-VIRT_OFFSET]
|
||||||
jmp KERNEL_CODE_BS32:segmented_start
|
jmp KERNEL_CODE_BS32:segmented_start
|
||||||
segmented_start:
|
segmented_start:
|
||||||
mov cx, KERNEL_DATA_BS32
|
mov cx, KERNEL_DATA_BS32
|
||||||
@ -68,7 +68,7 @@ segmented_start:
|
|||||||
add ebx, VIRT_OFFSET
|
add ebx, VIRT_OFFSET
|
||||||
push eax
|
push eax
|
||||||
push ebx ;pointer to multiboot info structure
|
push ebx ;pointer to multiboot info structure
|
||||||
call _k_mbsave ;save multiboot info structures
|
call k_mbsave ;save multiboot info structures
|
||||||
add esp, 8
|
add esp, 8
|
||||||
|
|
||||||
cmp eax, 0 ; eax = pointer to mb_module_t struct for rmmod
|
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
|
rep movsd ; copy rmmod to first 1mb
|
||||||
|
|
||||||
mov ebx, pm_return ; return address
|
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
|
sub ecx, VIRT_OFFSET
|
||||||
|
|
||||||
jmp 0xC0005010 ; jump to rmmod
|
jmp 0xC0005010 ; jump to rmmod
|
||||||
@ -161,8 +161,8 @@ newgdtcontinue:
|
|||||||
lidt [idtr] ;load idt
|
lidt [idtr] ;load idt
|
||||||
mov [PDBR_V], dword 0 ;unmap 0x0, we are running completely paged at 0xC000_0000
|
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 edi, GDT_V + TSS0_SEG + 2 ; copy tss0 base address
|
||||||
mov eax, _tss0 ; into the GDT descrtiptor
|
mov eax, tss0 ; into the GDT descrtiptor
|
||||||
stosw ; for TSS0
|
stosw ; for TSS0
|
||||||
shr eax, 16
|
shr eax, 16
|
||||||
stosb
|
stosb
|
||||||
@ -170,7 +170,7 @@ newgdtcontinue:
|
|||||||
shr eax, 8
|
shr eax, 8
|
||||||
stosb
|
stosb
|
||||||
|
|
||||||
call _k_init ;C kernel initialization
|
call k_init ;C kernel initialization
|
||||||
|
|
||||||
mov ax, TSS0_SEG
|
mov ax, TSS0_SEG
|
||||||
ltr ax
|
ltr ax
|
||||||
@ -187,7 +187,7 @@ idle_loop: ; system idle loop
|
|||||||
;-------------------------------------------------------
|
;-------------------------------------------------------
|
||||||
gdtrbs32:
|
gdtrbs32:
|
||||||
dw gdt_endbs32-gdtbs32-1
|
dw gdt_endbs32-gdtbs32-1
|
||||||
dd gdtbs32-VIRT_OFFSET
|
dd 0x100000000+gdtbs32-VIRT_OFFSET
|
||||||
gdtbs32: ; 0 = null descriptor
|
gdtbs32: ; 0 = null descriptor
|
||||||
dd 0
|
dd 0
|
||||||
dd 0
|
dd 0
|
||||||
|
@ -29,7 +29,7 @@ Ext2OpenFile::Ext2OpenFile(Ext2fs *fs, u32_t inum, int mode)
|
|||||||
myBlockCacheStatus = 0; /* 0: invalid; 1: valid; 2: dirty */
|
myBlockCacheStatus = 0; /* 0: invalid; 1: valid; 2: dirty */
|
||||||
fs->readInode(inum, &myInode);
|
fs->readInode(inum, &myInode);
|
||||||
myCache = new Ext2BlockCache(fs, 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_RW_MASK) == VFS_MODE_WRITE)
|
||||||
{
|
{
|
||||||
if ((mode & VFS_MODE_WRITE_MASK) == VFS_MODE_TRUNCATE)
|
if ((mode & VFS_MODE_WRITE_MASK) == VFS_MODE_TRUNCATE)
|
||||||
@ -62,7 +62,7 @@ Ext2OpenFile::Ext2OpenFile(Ext2fs *fs, u32_t inum, int mode)
|
|||||||
Ext2OpenFile::~Ext2OpenFile()
|
Ext2OpenFile::~Ext2OpenFile()
|
||||||
{
|
{
|
||||||
/* remove ourselves from the open file list */
|
/* remove ourselves from the open file list */
|
||||||
lock(&Ext2OpenFileListLock);
|
lockit(&Ext2OpenFileListLock);
|
||||||
u32_t size = Ext2OpenFileList->size();
|
u32_t size = Ext2OpenFileList->size();
|
||||||
for (u32_t i = 0; i < size; i++)
|
for (u32_t i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
|
@ -9,9 +9,15 @@
|
|||||||
#include "hos_defines.h"
|
#include "hos_defines.h"
|
||||||
#include "sys/io.h"
|
#include "sys/io.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
extern u32_t _code;
|
extern u32_t _code;
|
||||||
extern u32_t _bss;
|
extern u32_t _bss;
|
||||||
extern u32_t _end;
|
extern u32_t _end;
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//Enables (SeTs) Interrupt Flag on the processor
|
//Enables (SeTs) Interrupt Flag on the processor
|
||||||
static inline void enable_ints()
|
static inline void enable_ints()
|
||||||
|
@ -44,9 +44,15 @@ typedef unsigned char u8_t;
|
|||||||
typedef unsigned char byte;
|
typedef unsigned char byte;
|
||||||
typedef int lock_t;
|
typedef int lock_t;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
extern u32_t _end;
|
extern u32_t _end;
|
||||||
extern u32_t _bss;
|
extern u32_t _bss;
|
||||||
extern u32_t start;
|
extern u32_t start;
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ isr_main_nodup:
|
|||||||
|
|
||||||
push esp
|
push esp
|
||||||
push eax ;interrupt number
|
push eax ;interrupt number
|
||||||
call _isr
|
call isr
|
||||||
add esp, 8
|
add esp, 8
|
||||||
|
|
||||||
pop gs
|
pop gs
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
%endmacro
|
%endmacro
|
||||||
|
|
||||||
;implements a lock
|
;implements a lock
|
||||||
[global _lock]
|
[global lockit]
|
||||||
_lock:
|
lockit:
|
||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
push eax
|
push eax
|
||||||
@ -35,8 +35,8 @@ _lock_loop0:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
;releases a lock
|
;releases a lock
|
||||||
[global _unlock]
|
[global unlock]
|
||||||
_unlock:
|
unlock:
|
||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
push esi
|
push esi
|
||||||
@ -50,15 +50,15 @@ _unlock:
|
|||||||
|
|
||||||
;returns the value in the CR0 register
|
;returns the value in the CR0 register
|
||||||
;extern dword read_cr0();
|
;extern dword read_cr0();
|
||||||
[global _read_cr0]
|
[global read_cr0]
|
||||||
_read_cr0:
|
read_cr0:
|
||||||
mov eax, cr0;
|
mov eax, cr0;
|
||||||
ret
|
ret
|
||||||
|
|
||||||
;stores the parameter to the CR0 register
|
;stores the parameter to the CR0 register
|
||||||
;extern dword write_cr0(dword cr0);
|
;extern dword write_cr0(dword cr0);
|
||||||
[global _write_cr0]
|
[global write_cr0]
|
||||||
_write_cr0:
|
write_cr0:
|
||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
mov eax, [ebp+8]
|
mov eax, [ebp+8]
|
||||||
@ -68,8 +68,8 @@ _write_cr0:
|
|||||||
|
|
||||||
;returns the value in the CR2 register
|
;returns the value in the CR2 register
|
||||||
;extern dword read_cr2();
|
;extern dword read_cr2();
|
||||||
[global _read_cr2]
|
[global read_cr2]
|
||||||
_read_cr2:
|
read_cr2:
|
||||||
mov eax, cr2;
|
mov eax, cr2;
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -77,16 +77,16 @@ _read_cr2:
|
|||||||
|
|
||||||
;returns the value in the CR3 register
|
;returns the value in the CR3 register
|
||||||
;extern dword read_cr3();
|
;extern dword read_cr3();
|
||||||
[global _read_cr3]
|
[global read_cr3]
|
||||||
_read_cr3:
|
read_cr3:
|
||||||
mov eax, cr3;
|
mov eax, cr3;
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
;stores the parameter to the CR3 register
|
;stores the parameter to the CR3 register
|
||||||
;extern dword write_cr3(dword cr3);
|
;extern dword write_cr3(dword cr3);
|
||||||
[global _write_cr3]
|
[global write_cr3]
|
||||||
_write_cr3:
|
write_cr3:
|
||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
mov eax, [ebp+8]
|
mov eax, [ebp+8]
|
||||||
@ -96,16 +96,16 @@ _write_cr3:
|
|||||||
|
|
||||||
|
|
||||||
; read ss register
|
; read ss register
|
||||||
[global _read_ss]
|
[global read_ss]
|
||||||
_read_ss:
|
read_ss:
|
||||||
mov ax, ss
|
mov ax, ss
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
;copies a string from the source to the destination parameter
|
;copies a string from the source to the destination parameter
|
||||||
;extern void strcpy(char *dest, char *src);
|
;extern void strcpy(char *dest, char *src);
|
||||||
[global _strcpy]
|
[global strcpy]
|
||||||
_strcpy:
|
strcpy:
|
||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
push esi
|
push esi
|
||||||
@ -124,8 +124,8 @@ strcpyloop:
|
|||||||
|
|
||||||
;copies memory of n bytes from src to destination
|
;copies memory of n bytes from src to destination
|
||||||
;void memcpy(void *dest, void *src, dword n);
|
;void memcpy(void *dest, void *src, dword n);
|
||||||
[global _memcpy]
|
[global memcpy]
|
||||||
_memcpy:
|
memcpy:
|
||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
push esi
|
push esi
|
||||||
@ -147,8 +147,8 @@ _memcpy:
|
|||||||
|
|
||||||
;copies memory of n words (n*2 bytes) from src to destination
|
;copies memory of n words (n*2 bytes) from src to destination
|
||||||
;void memcpyw(void *dest, void *src, dword n);
|
;void memcpyw(void *dest, void *src, dword n);
|
||||||
[global _memcpyw]
|
[global memcpyw]
|
||||||
_memcpyw:
|
memcpyw:
|
||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
push esi
|
push esi
|
||||||
@ -170,8 +170,8 @@ _memcpyw:
|
|||||||
|
|
||||||
;copies memory of n dwords (n*4 bytes) from src to destination
|
;copies memory of n dwords (n*4 bytes) from src to destination
|
||||||
;void memcpyd(void *dest, void *src, dword n);
|
;void memcpyd(void *dest, void *src, dword n);
|
||||||
[global _memcpyd]
|
[global memcpyd]
|
||||||
_memcpyd:
|
memcpyd:
|
||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
push esi
|
push esi
|
||||||
@ -193,8 +193,8 @@ _memcpyd:
|
|||||||
|
|
||||||
;sets num bytes at buffer to the value of c
|
;sets num bytes at buffer to the value of c
|
||||||
;void *memset(void *buffer, int c, int num);
|
;void *memset(void *buffer, int c, int num);
|
||||||
[global _memset]
|
[global memset]
|
||||||
_memset:
|
memset:
|
||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
push edi
|
push edi
|
||||||
@ -215,8 +215,8 @@ _memset:
|
|||||||
|
|
||||||
;sets num words at buffer to the value of c
|
;sets num words at buffer to the value of c
|
||||||
;void *memsetw(void *buffer, int c, int num);
|
;void *memsetw(void *buffer, int c, int num);
|
||||||
[global _memsetw]
|
[global memsetw]
|
||||||
_memsetw:
|
memsetw:
|
||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
push edi
|
push edi
|
||||||
@ -237,8 +237,8 @@ _memsetw:
|
|||||||
|
|
||||||
;sets num dwords at buffer to the value of c
|
;sets num dwords at buffer to the value of c
|
||||||
;void *memsetd(void *buffer, int c, int num);
|
;void *memsetd(void *buffer, int c, int num);
|
||||||
[global _memsetd]
|
[global memsetd]
|
||||||
_memsetd:
|
memsetd:
|
||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
push edi
|
push edi
|
||||||
@ -259,8 +259,8 @@ _memsetd:
|
|||||||
|
|
||||||
;returns the number of characters in a string
|
;returns the number of characters in a string
|
||||||
;extern dword strlen(char *str);
|
;extern dword strlen(char *str);
|
||||||
[global _strlen]
|
[global strlen]
|
||||||
_strlen:
|
strlen:
|
||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
push esi
|
push esi
|
||||||
@ -284,8 +284,8 @@ strlendone:
|
|||||||
;this function invalidates the page directory/table entry that
|
;this function invalidates the page directory/table entry that
|
||||||
; would be used to access the memory address given in the parameter
|
; would be used to access the memory address given in the parameter
|
||||||
;extern void invlpg_(dword addr);
|
;extern void invlpg_(dword addr);
|
||||||
[global _invlpg_]
|
[global invlpg_]
|
||||||
_invlpg_:
|
invlpg_:
|
||||||
mov eax, [esp+4]
|
mov eax, [esp+4]
|
||||||
invlpg [eax]
|
invlpg [eax]
|
||||||
ret
|
ret
|
||||||
@ -294,8 +294,8 @@ _invlpg_:
|
|||||||
;
|
;
|
||||||
;void writeCursorPosition(word pos)
|
;void writeCursorPosition(word pos)
|
||||||
;
|
;
|
||||||
[global _writeCursorPosition]
|
[global writeCursorPosition]
|
||||||
_writeCursorPosition:
|
writeCursorPosition:
|
||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
|
|
||||||
@ -333,8 +333,8 @@ _writeCursorPosition:
|
|||||||
;
|
;
|
||||||
;word getCursorPosition()
|
;word getCursorPosition()
|
||||||
;
|
;
|
||||||
[global _getCursorPosition]
|
[global getCursorPosition]
|
||||||
_getCursorPosition:
|
getCursorPosition:
|
||||||
push ebx
|
push ebx
|
||||||
push edx
|
push edx
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include "hos_defines.h"
|
#include "hos_defines.h"
|
||||||
|
|
||||||
/* lang.asm */
|
/* lang.asm */
|
||||||
void lock(lock_t *addr);
|
void lockit(lock_t *addr);
|
||||||
void unlock(lock_t *addr);
|
void unlock(lock_t *addr);
|
||||||
u32_t read_cr0();
|
u32_t read_cr0();
|
||||||
u32_t write_cr0(u32_t cr0);
|
u32_t write_cr0(u32_t cr0);
|
||||||
|
@ -15,6 +15,8 @@ template<typename type>
|
|||||||
class vector
|
class vector
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
typedef type * type_ptr_t;
|
||||||
|
|
||||||
/* Pointers to vector elements */
|
/* Pointers to vector elements */
|
||||||
type **myData;
|
type **myData;
|
||||||
|
|
||||||
@ -25,127 +27,80 @@ protected:
|
|||||||
unsigned int myAllocated;
|
unsigned int myAllocated;
|
||||||
|
|
||||||
/* Causes the vector to double in its allocated size */
|
/* Causes the vector to double in its allocated size */
|
||||||
void grow();
|
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()
|
|
||||||
{
|
|
||||||
myAllocated <<= 1;
|
myAllocated <<= 1;
|
||||||
if (myAllocated == 0)
|
if (myAllocated == 0)
|
||||||
myAllocated = 1;
|
myAllocated = 1;
|
||||||
type **data_new = new (type *)[myAllocated];
|
type **data_new = new type_ptr_t[myAllocated];
|
||||||
for (unsigned int i = 0; i < mySize; i++)
|
for (unsigned int i = 0; i < mySize; i++)
|
||||||
data_new[i] = myData[i];
|
data_new[i] = myData[i];
|
||||||
if (myData)
|
if (myData)
|
||||||
delete[] myData;
|
delete[] myData;
|
||||||
myData = data_new;
|
myData = data_new;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename type>
|
public:
|
||||||
vector<type> & vector<type>::remove(unsigned int index)
|
/* 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)
|
if (index < mySize)
|
||||||
{
|
{
|
||||||
delete myData[index];
|
delete myData[index];
|
||||||
@ -154,11 +109,11 @@ vector<type> & vector<type>::remove(unsigned int index)
|
|||||||
mySize--;
|
mySize--;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename type>
|
/* Insert an element into a position in the vector */
|
||||||
vector<type> & vector<type>::insert(type elem, unsigned int position)
|
vector<type> & insert(type elem, unsigned int position)
|
||||||
{
|
{
|
||||||
if (position <= mySize)
|
if (position <= mySize)
|
||||||
{
|
{
|
||||||
if (mySize >= myAllocated)
|
if (mySize >= myAllocated)
|
||||||
@ -169,13 +124,24 @@ vector<type> & vector<type>::insert(type elem, unsigned int position)
|
|||||||
mySize++;
|
mySize++;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Direct access operators */
|
||||||
|
const type & operator[](unsigned int index) const
|
||||||
|
{
|
||||||
|
return *myData[index];
|
||||||
|
}
|
||||||
|
|
||||||
template<typename type>
|
type & operator[](unsigned int index)
|
||||||
type **vector<type>::data()
|
{
|
||||||
{
|
return *myData[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns pointer to data */
|
||||||
|
type **data()
|
||||||
|
{
|
||||||
return myData;
|
return myData;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
OUTPUT_FORMAT("binary")
|
OUTPUT_FORMAT("binary")
|
||||||
ENTRY(_start)
|
ENTRY(start)
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
.text 0xC0108000 : {
|
.text 0xC0108000 : {
|
||||||
code = .; _code = .; __code = .;
|
code = .; _code = .; __code = .;
|
||||||
*(.text)
|
*(.text)
|
||||||
|
*(.eh_frame*)
|
||||||
}
|
}
|
||||||
.gnulinkonce : {
|
.gnulinkonce : {
|
||||||
*(.gnu.linkonce*)
|
*(.gnu.linkonce*)
|
||||||
@ -12,8 +13,8 @@ SECTIONS
|
|||||||
}
|
}
|
||||||
.data : {
|
.data : {
|
||||||
data = .; _data = .; __data = .;
|
data = .; _data = .; __data = .;
|
||||||
*(.data)
|
*(.data*)
|
||||||
*(.rodata)
|
*(.rodata*)
|
||||||
. = ALIGN(4096);
|
. = ALIGN(4096);
|
||||||
}
|
}
|
||||||
.bss : {
|
.bss : {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user