Added a x86_64 port. doesn't work as of yet

This commit is contained in:
Morten Delenk 2016-08-03 22:02:04 +02:00
parent e2a334bb44
commit ca34003648
No known key found for this signature in database
GPG key ID: 3F818D0F65DCB490
15 changed files with 710 additions and 17 deletions

View file

@ -3,9 +3,9 @@ CC=$(PREFIX)gcc
LD=$(PREFIX)ld
SRCS = $(shell find . -name '*.[cS]')
OBJS = $(addsuffix .o,$(basename $(SRCS)))
ASFLAGS = -m32
CFLAGS += -m32 -fno-stack-protector -nostdinc -ffreestanding -std=c11 -fno-builtin -w -Werror -nostdlib -fpie
LDFLAGS = -T loader.ld
ASFLAGS =
CFLAGS += -fno-stack-protector -nostdinc -ffreestanding -std=c11 -fno-builtin -w -Werror -nostdlib -fpie
LDFLAGS += -T loader.ld
all: $(OBJS)
$(LD) $(LDFLAGS) -o loader.bin $(OBJS)

View file

@ -1,13 +1,14 @@
ENTRY(_start)
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386:i386)
SECTIONS
{
. = 0x100000;
kernel_start = .;
.text : {
.bootstrap : {
*(multiboot)
*(.text)
boot.S (.text)
}
.text : {
*(EXCLUDE_FILE(*boot.S) .text)
}
.data : {
start_ctors = .;

16
boot/x86_64/Makefile Normal file
View file

@ -0,0 +1,16 @@
include ../../kernel.settings
CC=$(PREFIX)gcc
LD=$(PREFIX)ld
SRCS = $(shell find . -name '*.[cS]')
OBJS = $(addsuffix .o,$(basename $(SRCS)))
ASFLAGS =
CFLAGS += -fno-stack-protector -nostdinc -ffreestanding -std=c11 -fno-builtin -w -Werror -nostdlib -fpie
LDFLAGS += -T loader.ld
all: $(OBJS)
$(LD) $(LDFLAGS) -o loader.bin $(OBJS)
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $^
%.o: %.S
$(CC) $(ASFLAGS) -c -o $@ $^

147
boot/x86_64/boot.S Normal file
View file

@ -0,0 +1,147 @@
.code32
.section multiboot
#define MB_MAGIC 0x1BADB002
#define MB_FLAGS 0x0
#define MB_CHECKSUM -(MB_MAGIC + MB_FLAGS)
.align 4
.int MB_MAGIC
.int MB_FLAGS
.int MB_CHECKSUM
.int 0,0,0,0,0
.int 0
.int 1024, 768, 32
.section .text
.extern init
.global _start
_start:
cli
finit
mov $mb_ptr, %edi
stosl
mov %ebx, %eax
stosl //Temponarily store both multiboot header pointer and multiboot
mov $kernel_stack, %esp
mov $0x80000001, %eax //Check if Long Mode is supported
cpuid
and $0x20000000, %edx
jz x86_64_err
xor %eax, %eax //Check if PAE is supported
inc %eax
cpuid
and $0x40, %dl
jz x86_64_err
jmp x86_64_OK
x86_64_err:
cli
hlt
jmp x86_64_err
x86_64_OK:
//Fill one entry of both the pagemap L4 and the Pagedir PT
mov $pmfill, %esi
mov $pagemapL4, %edi
lodsl
stosl
lodsl
stosl
mov $pagedirPT, %edi
lodsl
stosl
lodsl
stosl
lodsl
stosl
lodsl
stosl
lodsl
stosl
lodsl
stosl
lodsl
stosl
lodsl
stosl
//Activate PAE
mov %cr4, %eax
or $0x20, %al
mov %eax, %cr4
//Activate x86_64
mov $0xC0000080, %ecx
rdmsr
or $0x00000100, %eax
wrmsr
//Load Page Table
mov $pagemapL4, %eax
mov %eax, %cr3
//Activate Paging
mov %cr0, %eax
bswap %eax
or $0x80, %al
bswap %eax
mov %eax, %cr0
//Jump to x86_64loader
lgdt gdtr
jmp $0x18, $start
.code64
//extern "C" void init(uint32_t eax, multiboot_info * ebx, uint64_t **** pt);
.global init
start:
xor %rax, %rax
mov $mb_ptr, %rsi
lodsl
mov %rax, %rdi
lodsl
mov %rax, %rsi
mov $pagemapL4, %rdx
call init
stop:
cli
hlt
jmp stop
.section .data
gdt:
//NULL-descriptor
.quad 0
//32-bit code
.word 0xFFFF
.word 0x0000
.byte 0x00
.byte 0x98
.byte 0xCF
.byte 0x00
//data
.word 0xFFFF
.word 0x0000
.byte 0x00
.byte 0x92
.byte 0xCF
.byte 00
//64-bit code
.int 0
.byte 0
.byte 0x98
.byte 0x20
.byte 0
gdtr:
.word 4 * 8
.int gdt
pmfill:
.int pagedirPT + 0x7
.int 0
pdptfill:
.quad 0x87
.quad 0x40000087
.quad 0x80000087
.quad 0xC0000087
.section .bss
mb_ptr:
// These 8 Bytes will never be used when the stack comes near it
.space 4096
kernel_stack:
.align 4096
pagemapL4:
.space 4096
pagedirPT:
.space 4096

60
boot/x86_64/init.c Normal file
View file

@ -0,0 +1,60 @@
// firmloader for x86
#include "multiboot.h"
/**
* \struct FIRM_sect
* \brief Contains one section of the FIRM format
*/
struct FIRM_sect {
unsigned int offset; //! Offset in file (bytes)
unsigned int physical; //! Physical address, where the section is copied to
unsigned int size; //! Size of section
unsigned int arm11; //! currently unused
unsigned char SHA256[0x20]; //! Currently unused
}__attribute__((packed));
/**
* \struct FIRM_header
* \brief Contains the first sector of every FIRM file.
*/
struct FIRM_header {
char magic[4]; //! Magic "FIRM" string (not-null terminated)
int version; //! Version. Currently 1
unsigned int entrypoint; //! Address where the processor jumps to after loading
unsigned int reserved[0xD];
struct FIRM_sect sections[4]; //! The four internal sections
unsigned char RSA2048[0x100]; //! Currently unused
}__attribute__((packed));
/**
* \brief Module table for the kernel (Up to 1024 mods)
*/
void *modtable[1024];
/**
* \fn init(int, struct multiboot_info*)
* \brief This routine is called by boot.S
* This routine is called by boot.S.
* It loads and jumps to a FIRM binary.
*/
void init(int eax, struct multiboot_info* mb_info) {
multiboot_module_t *mods = (multiboot_module_t *) mb_info->mods_addr;
for(unsigned int i=0;i<mb_info->mods_count;i++) { //Get modules
modtable[i]=(void*)mods[i].mod_start;
}
modtable[mb_info->mods_count]=0;
for(unsigned int i=0;i<mb_info->mods_count;i++) {
struct FIRM_header *firm=(struct FIRM_header*)(mods[i].mod_start);
if((firm->magic[0]!='F')||(firm->magic[1]!='I')||(firm->magic[2]!='R')||(firm->magic[3]!='M'))
continue;
//We found a FIRM!
for(int j=0;j<4;j++) {
if(!firm->sections[j].size)
continue;
unsigned char* from=(char*)(mods[i].mod_start+firm->sections[j].offset);
unsigned char* to=(char*)(firm->sections[j].physical);
unsigned int size=firm->sections[j].size;
while(size--) {
*to++=*from++;
}
}
void(*entry)(void**)=(void(*)(void**))firm->entrypoint;
entry(modtable); //Jump to kernel
}
}

30
boot/x86_64/loader.ld Normal file
View file

@ -0,0 +1,30 @@
ENTRY(_start)
OUTPUT_FORMAT(elf64-x86-64)
OUTPUT_ARCH(i386:x86-64)
SECTIONS
{
. = 0x100000;
kernel_start = .;
.text : {
*(multiboot)
*(.text)
}
.data : {
start_ctors = .;
KEEP(*( .init_array ));
KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* )));
*(.ctors)
end_ctors = .;
start_dtors = .;
*(.dtors)
end_dtors = .;
*(.data)
}
.rodata : {
*(.rodata)
}
.bss : {
*(.bss)
}
kernel_end = .;
}

309
boot/x86_64/multiboot.h Normal file
View file

@ -0,0 +1,309 @@
/* multiboot.h - Multiboot header file. */
/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
* DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef MULTIBOOT_HEADER
#define MULTIBOOT_HEADER 1
/* How many bytes from the start of the file we search for the header. */
#define MULTIBOOT_SEARCH 8192
#define MULTIBOOT_HEADER_ALIGN 4
/* The magic field should contain this. */
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
/* This should be in %eax. */
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
/* Alignment of multiboot modules. */
#define MULTIBOOT_MOD_ALIGN 0x00001000
/* Alignment of the multiboot info structure. */
#define MULTIBOOT_INFO_ALIGN 0x00000004
/* Flags set in the 'flags' member of the multiboot header. */
/* Align all boot modules on i386 page (4KB) boundaries. */
#define MULTIBOOT_PAGE_ALIGN 0x00000001
/* Must pass memory information to OS. */
#define MULTIBOOT_MEMORY_INFO 0x00000002
/* Must pass video information to OS. */
#define MULTIBOOT_VIDEO_MODE 0x00000004
/* This flag indicates the use of the address fields in the header. */
#define MULTIBOOT_AOUT_KLUDGE 0x00010000
/* Flags to be set in the 'flags' member of the multiboot info structure. */
/* is there basic lower/upper memory information? */
#define MULTIBOOT_INFO_MEMORY 0x00000001
/* is there a boot device set? */
#define MULTIBOOT_INFO_BOOTDEV 0x00000002
/* is the command-line defined? */
#define MULTIBOOT_INFO_CMDLINE 0x00000004
/* are there modules to do something with? */
#define MULTIBOOT_INFO_MODS 0x00000008
/* These next two are mutually exclusive */
/* is there a symbol table loaded? */
#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010
/* is there an ELF section header table? */
#define MULTIBOOT_INFO_ELF_SHDR 0X00000020
/* is there a full memory map? */
#define MULTIBOOT_INFO_MEM_MAP 0x00000040
/* Is there drive info? */
#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080
/* Is there a config table? */
#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100
/* Is there a boot loader name? */
#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200
/* Is there a APM table? */
#define MULTIBOOT_INFO_APM_TABLE 0x00000400
/* Is there video information? */
#define MULTIBOOT_INFO_VBE_INFO 0x00000800
#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000
#ifndef ASM_FILE
typedef unsigned char multiboot_uint8_t;
typedef unsigned short multiboot_uint16_t;
typedef unsigned int multiboot_uint32_t;
typedef unsigned long long multiboot_uint64_t;
struct multiboot_header
{
/* Must be MULTIBOOT_MAGIC - see above. */
multiboot_uint32_t magic;
/* Feature flags. */
multiboot_uint32_t flags;
/* The above fields plus this one must equal 0 mod 2^32. */
multiboot_uint32_t checksum;
/* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
multiboot_uint32_t header_addr;
multiboot_uint32_t load_addr;
multiboot_uint32_t load_end_addr;
multiboot_uint32_t bss_end_addr;
multiboot_uint32_t entry_addr;
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
multiboot_uint32_t mode_type;
multiboot_uint32_t width;
multiboot_uint32_t height;
multiboot_uint32_t depth;
};
/* The symbol table for a.out. */
struct multiboot_aout_symbol_table
{
multiboot_uint32_t tabsize;
multiboot_uint32_t strsize;
multiboot_uint32_t addr;
multiboot_uint32_t reserved;
};
typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
/* The section header table for ELF. */
struct multiboot_elf_section_header_table
{
multiboot_uint32_t num;
multiboot_uint32_t size;
multiboot_uint32_t addr;
multiboot_uint32_t shndx;
};
typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
struct multiboot_info
{
/* Multiboot info version number */
multiboot_uint32_t flags;
/* Available memory from BIOS */
multiboot_uint32_t mem_lower;
multiboot_uint32_t mem_upper;
/* "root" partition */
multiboot_uint32_t boot_device;
/* Kernel command line */
multiboot_uint32_t cmdline;
/* Boot-Module list */
multiboot_uint32_t mods_count;
multiboot_uint32_t mods_addr;
union
{
multiboot_aout_symbol_table_t aout_sym;
multiboot_elf_section_header_table_t elf_sec;
} u;
/* Memory Mapping buffer */
multiboot_uint32_t mmap_length;
multiboot_uint32_t mmap_addr;
/* Drive Info buffer */
multiboot_uint32_t drives_length;
multiboot_uint32_t drives_addr;
/* ROM configuration table */
multiboot_uint32_t config_table;
/* Boot Loader Name */
multiboot_uint32_t boot_loader_name;
/* APM table */
multiboot_uint32_t apm_table;
/* Video */
multiboot_uint32_t vbe_control_info;
multiboot_uint32_t vbe_mode_info;
multiboot_uint16_t vbe_mode;
multiboot_uint16_t vbe_interface_seg;
multiboot_uint16_t vbe_interface_off;
multiboot_uint16_t vbe_interface_len;
multiboot_uint64_t framebuffer_addr;
multiboot_uint32_t framebuffer_pitch;
multiboot_uint32_t framebuffer_width;
multiboot_uint32_t framebuffer_height;
multiboot_uint8_t framebuffer_bpp;
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
multiboot_uint8_t framebuffer_type;
union
{
struct
{
multiboot_uint32_t framebuffer_palette_addr;
multiboot_uint16_t framebuffer_palette_num_colors;
};
struct
{
multiboot_uint8_t framebuffer_red_field_position;
multiboot_uint8_t framebuffer_red_mask_size;
multiboot_uint8_t framebuffer_green_field_position;
multiboot_uint8_t framebuffer_green_mask_size;
multiboot_uint8_t framebuffer_blue_field_position;
multiboot_uint8_t framebuffer_blue_mask_size;
};
};
};
typedef struct multiboot_info multiboot_info_t;
struct multiboot_color
{
multiboot_uint8_t red;
multiboot_uint8_t green;
multiboot_uint8_t blue;
};
struct multiboot_mmap_entry
{
multiboot_uint32_t size;
multiboot_uint64_t addr;
multiboot_uint64_t len;
#define MULTIBOOT_MEMORY_AVAILABLE 1
#define MULTIBOOT_MEMORY_RESERVED 2
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
#define MULTIBOOT_MEMORY_NVS 4
#define MULTIBOOT_MEMORY_BADRAM 5
multiboot_uint32_t type;
} __attribute__((packed));
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
struct multiboot_mod_list
{
/* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
multiboot_uint32_t mod_start;
multiboot_uint32_t mod_end;
/* Module command line */
multiboot_uint32_t cmdline;
/* padding to take it to 16 bytes (must be zero) */
multiboot_uint32_t pad;
};
typedef struct multiboot_mod_list multiboot_module_t;
/* APM BIOS info. */
struct multiboot_apm_info
{
multiboot_uint16_t version;
multiboot_uint16_t cseg;
multiboot_uint32_t offset;
multiboot_uint16_t cseg_16;
multiboot_uint16_t dseg;
multiboot_uint16_t flags;
multiboot_uint16_t cseg_len;
multiboot_uint16_t cseg_16_len;
multiboot_uint16_t dseg_len;
};
struct MODE_INFO
{
unsigned short ModeAttributes ;
unsigned char WinAAttributes ;
unsigned char WinBAttributes ;
unsigned short WinGranularity ;
unsigned short WinSize ;
unsigned short WinASegment ;
unsigned short WinBSegment ;
unsigned int WinFuncPtr ;
unsigned short BytesPerScanLine ;
unsigned short XResolution ;
unsigned short YResolution ;
unsigned char XCharSize ;
unsigned char YCharSize ;
unsigned char NumberOfPlanes ;
unsigned char BitsPerPixel ;
unsigned char NumberOfBanks ;
unsigned char MemoryModel ;
unsigned char BankSize ;
unsigned char NumberOfImagePages ;
unsigned char Reserved_page ;
unsigned char RedMaskSize ;
unsigned char RedMaskPos ;
unsigned char GreenMaskSize ;
unsigned char GreenMaskPos ;
unsigned char BlueMaskSize ;
unsigned char BlueMaskPos ;
unsigned char ReservedMaskSize ;
unsigned char ReservedMaskPos ;
unsigned char DirectColorModeInfo ;
unsigned int PhysBasePtr ;
unsigned int OffScreenMemOffset ;
unsigned short OffScreenMemSize ;
unsigned char Reserved[206] ;
}__attribute__ ((packed));
#endif /* ! ASM_FILE */
#endif /* ! MULTIBOOT_HEADER */

View file

@ -1,15 +1,17 @@
arch = x86
arch = x86_64
MODE = debug
export PATH := $(HOME)/opt/bin:$(PATH)
LDFLAGS =
ifeq ($(arch),x86)
PREFIX = i686-mtgos-
libpath = i686-mtgos
ARCHFLAGS = -m32
else
ifeq ($(arch),x86_64)
PREFIX = x86_64-elf-
libpath = x86_64-elf
ARCHFLAGS = -m64
PREFIX = x86_64-mtgos-
libpath = x86_64-mtgos
ARCHFLAGS = -m64 -mno-red-zone
LDFLAGS += -z max-page-size=0x1000
else
ifeq ($(arch),3ds)
PREFIX = arm-none-eabi-

View file

@ -6,9 +6,9 @@ CPP = $(PREFIX)g++
CC = $(PREFIX)gcc
LD = $(PREFIX)g++
CFLAGS += -m32 -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../c_include -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpie
CPPFLAGS += -m32 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -I../c_include -I../include -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fno-pie -Wno-reorder -fdump-class-hierarchy
LDFLAGS = -nostdlib -nodefaultlibs -nostdlib -fno-builtin $(ARCHFLAGS) -T loader.ld
CFLAGS += -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../c_include -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpie
CPPFLAGS += -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -I../c_include -I../include -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fno-pie -Wno-reorder -fdump-class-hierarchy
LDFLAGS += -nostdlib -nodefaultlibs -nostdlib -fno-builtin -T loader.ld
all: $(OBJS)
$(LD) $(LDFLAGS) -o mtgos.elf $(OBJS) -lgcc
%.o: %.cpp

View file

@ -6,9 +6,9 @@ CPP = $(PREFIX)g++
CC = $(PREFIX)gcc
LD = $(PREFIX)g++
CFLAGS += -m32 -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../../../../c_include -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpic
CPPFLAGS += -m32 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -I../../../../c_include -I../../../../include -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fpic -Wno-reorder -fdump-class-hierarchy
LDFLAGS = -nostdlib -nodefaultlibs -nostdlib -fno-builtin $(ARCHFLAGS) -T ../../link.ld
CFLAGS += -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../../../../c_include -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpic
CPPFLAGS += -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -I../../../../c_include -I../../../../include -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fpic -Wno-reorder -fdump-class-hierarchy
LDFLAGS += -nostdlib -nodefaultlibs -nostdlib -fno-builtin -T ../../link.ld
all: $(OBJS)
$(LD) $(LDFLAGS) -o ../../../../dsp_txt.elf $(OBJS) -lgcc
%.o: %.cpp

5
modules/x86_64/Makefile Normal file
View file

@ -0,0 +1,5 @@
SUBDIRS = dsp
all:
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir; \
done

View file

@ -0,0 +1,5 @@
SUBDIRS = txt
all:
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir; \
done

View file

@ -0,0 +1,26 @@
include ../../../../kernel.settings
SRCS = $(shell find . -name '*.cpp' -o -name '*.[cS]')
OBJS = $(addsuffix .o,$(basename $(SRCS)))
CPP = $(PREFIX)g++
CC = $(PREFIX)gcc
LD = $(PREFIX)g++
CFLAGS += -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../../../../c_include -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpic
CPPFLAGS += -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -I../../../../c_include -I../../../../include -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fpic -Wno-reorder -fdump-class-hierarchy
LDFLAGS += -nostdlib -nodefaultlibs -nostdlib -fno-builtin -T ../../link.ld
all: $(OBJS)
$(LD) $(LDFLAGS) -o ../../../../dsp_txt.elf $(OBJS) -lgcc
%.o: %.cpp
$(CPP) $(CPPFLAGS) -c -o $@ $^
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $^
%.o: %.S
$(CC) $(CFLAGS) -c -o $@ $^
clean:
rm -rf $(OBJS)
.PHONY: clean all

View file

@ -0,0 +1,67 @@
#include <moduleinterface.h>
#include <base/output.hpp>
#include <modstubs.h>
int x=0,y=0;
uint16_t* vmem = (uint16_t*)0xB8000;
namespace MTGos {
namespace {
/**
* \class Screen
* \brief Text output to the screen
*/
class Screen: public Base::Output {
public:
Screen() {}
auto scroll() -> void {
for(int p=0;p<80*25;p++)
vmem[p]=vmem[p+80];
for(int p=80*25; p<81*25; p++)
vmem[p]=0x0700;
y--;
}
private:
virtual auto putChar(int c) -> void{
switch(c) {
case '\n':
x=0; y++;
break;
case '\r':
x=0;
break;
case '\b':
if(x==0)
break;
x--;
putChar(' '),
x--;
break;
case '\0':
break;
default:
vmem[y*80+(x++)]=((uint16_t)0x0700) | ((uint8_t)c);
if(x==80) {
x=0; y++;
}
break;
}
if(y>25)
scroll();
}
};
}
}
void(*tbl[3])()={(void(*)())&getType,(void(*)())&size_of,(void(*)())&spawnAt};
table_type getTable() {
doCtors();
return (void(**)())&tbl;
}
auto getType() -> ModType {
return ModType::output_text;
}
auto spawnAt(void* pos) -> bool {
new(pos) MTGos::Screen;
return true;
}
auto size_of() -> size_t {
return sizeof(MTGos::Screen);
}

25
modules/x86_64/link.ld Normal file
View file

@ -0,0 +1,25 @@
ENTRY(getTable)
OUTPUT_FORMAT(elf32-little)
OUTPUT_ARCH(i386:x86-64)
SECTIONS
{
. = 0x108000;
module_start = .;
.text : {
*(.text)
*(.text.*)
start_ctors = .;
KEEP(*( .init_array ));
KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* )));
*(.ctors)
end_ctors = .;
start_dtors = .;
*(.dtors)
end_dtors = .;
*(.data)
*(.data.*)
*(.rodata)
*(.bss)
}
module_end = .;
}