Skip to content

Commit

Permalink
Merge branch 'release/1.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
csoren committed Feb 6, 2020
2 parents 26a2dcf + b2f1035 commit 6ac61b3
Show file tree
Hide file tree
Showing 41 changed files with 1,280 additions and 756 deletions.
15 changes: 8 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "Debug xlink",
"type": "cppdbg",
"request": "launch",
"preLaunchTask": "make",
"program": "${workspaceFolder}/build/cmake/debug/xlink/xlink",
"args": ["-tb", "-oamigaobj.68k.bin", "amigaobj.68k.obj"],
"args": ["-mtest.sym", "-otest.sms", "-tms32", "vectors.obj", "entry.obj", "initialize.obj", "joypad.obj", "background.obj", "player.obj", "sprites.obj", "camera.obj", "memoryblocks.obj", "objects.obj", "missile.obj"],
"stopAtEntry": true,
"cwd": "${workspaceFolder}/test/680x0",
"cwd": "${workspaceFolder}/../mastersystem-test",
"environment": [],
"externalConsole": true,
"externalConsole": false,
"MIMode": "lldb"
},
{
"name": "Debug motorz80",
"type": "cppdbg",
"request": "launch",
"preLaunchTask": "make",
"program": "${workspaceFolder}/build/cmake/debug/xasm/z80/motorz80",
"args": ["-mcz", "-ms1", "-mu1", "-z0", "-oobjects.obj", "objects.asm"],
"stopAtEntry": true,
"args": ["-g", "-d.d/entry.Td", "-mcz", "-ms1", "-mu1", "-z0", "-oentry.obj", "entry.asm"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/../mastersystem-test",
"environment": [],
"externalConsole": true,
"externalConsole": false,
"MIMode": "lldb"
},
{
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"project.h": "c",
"expression.h": "c",
"dependency.h": "c",
"strbuf.h": "c"
"strbuf.h": "c",
"strcoll.h": "c"
},
"files.exclude": {
"**/.git": true,
Expand Down
2 changes: 1 addition & 1 deletion build/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.3
1.0.4
1 change: 1 addition & 0 deletions doc/Assembler.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Depending on the target ISA, the executable to invoke will be named motor, follo

## Command line options
```
-a<n> Section alignment when writing binary file
-b<AS> Change the two characters used for binary constants
(default is 01)
-e(l|b) Change endianness
Expand Down
2 changes: 1 addition & 1 deletion util
Submodule util updated 14 files
+8 −0 CMakeLists.txt
+123 −0 crc32.c
+13 −0 crc32.h
+18 −0 file.c
+5 −0 file.h
+134 −0 map.c
+51 −0 map.h
+1 −0 mem.c
+218 −0 set.c
+74 −0 set.h
+19 −0 str.c
+8 −0 str.h
+50 −0 strcoll.c
+66 −0 strcoll.h
2 changes: 2 additions & 0 deletions xasm/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ add_library (xasm
lexer_constants.h
lexer_variadics.c
lexer_variadics.h
linemap.c
linemap.h
object.c
object.h
options.c
Expand Down
17 changes: 9 additions & 8 deletions xasm/common/amigaobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ writeReloc32(FILE* fileHandle, SPatch** patchesPerSection, uint32_t totalSection
}

static bool
writeSection(FILE* fileHandle, SSection* section, bool writeDebugInfo, uint32_t totalSections, bool isLinkObject) {
writeSection(FILE* fileHandle, SSection* section, bool enableDebugInfo, uint32_t totalSections, bool isLinkObject) {
if (section->group->value.groupType == GROUP_TEXT) {
SPatch** patchesPerSection = mem_Alloc(sizeof(SPatch*) * totalSections);
for (uint32_t i = 0; i < totalSections; ++i)
Expand Down Expand Up @@ -286,16 +286,17 @@ writeSection(FILE* fileHandle, SSection* section, bool writeDebugInfo, uint32_t
writeExtHunk(fileHandle, section, NULL, 0);
}

if (writeDebugInfo)
if (enableDebugInfo) {
writeSymbolHunk(fileHandle, section);
}

fputbl(HUNK_END, fileHandle);
return true;
}

static void
writeSectionNames(FILE* fileHandle, bool writeDebugInfo) {
if (writeDebugInfo) {
writeSectionNames(FILE* fileHandle) {
if (opt_Current->enableDebugInfo) {
for (const SSection* section = sect_Sections; section != NULL; section = list_GetNext(section)) {
fputstr(section->name, fileHandle, 0);
}
Expand Down Expand Up @@ -331,16 +332,16 @@ ami_WriteObject(string* destFilename, string* sourceFilename) {
return r;
}

bool
ami_WriteExecutable(string* destFilename, bool writeDebugInfo) {
extern bool
ami_WriteExecutable(string* destFilename) {
bool r = true;

FILE* fileHandle = fopen(str_String(destFilename), "wb");
if (fileHandle == NULL)
return false;

fputbl(HUNK_HEADER, fileHandle);
writeSectionNames(fileHandle, writeDebugInfo);
writeSectionNames(fileHandle);

uint32_t totalSections = sect_TotalSections();
fputbl(totalSections, fileHandle);
Expand All @@ -355,7 +356,7 @@ ami_WriteExecutable(string* destFilename, bool writeDebugInfo) {
}

for (SSection* section = sect_Sections; section != NULL; section = list_GetNext(section)) {
if (!writeSection(fileHandle, section, writeDebugInfo, totalSections, false)) {
if (!writeSection(fileHandle, section, opt_Current->enableDebugInfo, totalSections, false)) {
r = false;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion xasm/common/amigaobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ extern bool
ami_WriteObject(string* destFilename, string* sourceFilename);

extern bool
ami_WriteExecutable(string* destFilename, bool writeDebugInfo);
ami_WriteExecutable(string* destFilename);

#endif /* XASM_COMMON_AMIGAOBJECT_H_INCLUDED_ */
27 changes: 15 additions & 12 deletions xasm/common/binaryobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,46 @@
#include "symbol.h"
#include "patch.h"

static bool
static SPatch*
needsOrg() {
for (const SSection* section = sect_Sections; section != NULL; section = list_GetNext(section)) {
if (section->patches != NULL)
return true;
return section->patches;
}
return false;
return NULL;
}

static bool
commonPatch() {
SPatch* firstPatch;

if (sect_Sections == NULL)
return false;

// Check first section
if (needsOrg() && (sect_Sections->flags & SECTF_LOADFIXED) == 0) {
err_Error(ERROR_SECTION_MUST_LOAD);
if ((firstPatch = needsOrg()) != NULL && (sect_Sections->flags & SECTF_LOADFIXED) == 0) {
err_PatchError(firstPatch, ERROR_SECTION_MUST_LOAD);
return false;
}

uint32_t nAddress = sect_Sections->imagePosition;
uint32_t imagePos = sect_Sections->imagePosition;
SSection* section = sect_Sections;
do {
uint32_t alignment = xasm_Configuration->sectionAlignment - 1u;
nAddress += (section->usedSpace + alignment) & ~alignment;
section = list_GetNext(section);
if (section != NULL) {
if (section->flags & SECTF_LOADFIXED) {
if (section->imagePosition < nAddress) {
if (section->imagePosition < imagePos) {
err_Error(ERROR_SECTION_LOAD, section->name, section->cpuOrigin);
return false;
}
nAddress = section->imagePosition;
imagePos = section->imagePosition;
} else {
uint32_t alignment = opt_Current->sectionAlignment - 1u;
imagePos += (section->usedSpace + alignment) & ~alignment;

section->flags |= SECTF_LOADFIXED;
section->imagePosition = nAddress;
section->cpuOrigin = nAddress / xasm_Configuration->minimumWordSize;
section->imagePosition = imagePos;
section->cpuOrigin = imagePos / xasm_Configuration->minimumWordSize;
}
}
} while (section != NULL);
Expand Down
77 changes: 41 additions & 36 deletions xasm/common/dependency.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,62 +20,67 @@
#include "file.h"
#include "mem.h"
#include "str.h"
#include "strcoll.h"

typedef struct Dependency {
string* filename;
struct Dependency* next;
} SDependency;

/* Internal variables */

static string* g_outputFilename = NULL;
static string* g_mainOutput = NULL;
static SDependency* g_dependencies = NULL;
static SDependency** g_nextDependency = &g_dependencies;
static string* g_mainDependency = NULL;
static set_t * g_dependencySet = NULL;


/* Internal functions */

void
dep_SetOutputFilename(const char* filename) {
g_outputFilename = str_Create(filename);
static void
writeDependency(intptr_t element, intptr_t data) {
FILE* fileHandle = (FILE*) data;
string* str = (string*) element;
fprintf(fileHandle, " %s", str_String(str));
}

extern void
dep_SetMainOutput(string* filename) {
g_mainOutput = str_Copy(filename);
static void
writeTarget(intptr_t element, intptr_t data) {
FILE* fileHandle = (FILE*) data;
string* str = (string*) element;
fprintf(fileHandle, "%s:\n\n", str_String(str));
}

static bool
hasDependency(string* filename) {
for (SDependency* dependency = g_dependencies; dependency != NULL; dependency = dependency->next) {
if (str_Equal(filename, dependency->filename))
return true;
}

return false;
/* Exported functions */

extern void
dep_Initialize(const char* outputFileName) {
g_outputFilename = str_Create(outputFileName);
g_dependencySet = strset_Create();
}

extern void
dep_SetMainOutput(string* filename) {
g_mainOutput = str_Copy(filename);
}

extern void
dep_AddDependency(string* filename) {
if (!hasDependency(filename)) {
SDependency* dependency = (SDependency*) mem_Alloc(sizeof(SDependency));
dependency->filename = str_Copy(filename);
dependency->next = NULL;
*g_nextDependency = dependency;
g_nextDependency = &dependency->next;
if (g_dependencySet != NULL) {
if (g_mainDependency == NULL) {
g_mainDependency = str_Copy(filename);
}
strset_Insert(g_dependencySet, filename);
}
}

extern void
dep_WriteDependencyFile(void) {
FILE* fileHandle = fopen(str_String(g_outputFilename), "wt");
if (fileHandle != NULL) {
fprintf(fileHandle, "%s:", str_String(g_mainOutput));
for (SDependency* dependency = g_dependencies; dependency != NULL; dependency = dependency->next) {
fprintf(fileHandle, " %s", str_String(dependency->filename));
}
fprintf(fileHandle, "\n\n");
for (SDependency* dependency = g_dependencies->next; dependency != NULL; dependency = dependency->next) {
fprintf(fileHandle, "%s:\n\n", str_String(dependency->filename));
if (g_dependencySet != NULL) {
FILE* fileHandle = fopen(str_String(g_outputFilename), "wt");
if (fileHandle != NULL) {
fprintf(fileHandle, "%s:", str_String(g_mainOutput));
set_ForEachElement(g_dependencySet, writeDependency, (intptr_t) fileHandle);

fprintf(fileHandle, "\n\n");
strset_Remove(g_dependencySet, g_mainDependency);
set_ForEachElement(g_dependencySet, writeTarget, (intptr_t) fileHandle);
}
}
}

2 changes: 1 addition & 1 deletion xasm/common/dependency.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define XASM_COMMON_DEPENDENCY_H_INCLUDED_

extern void
dep_SetOutputFilename(const char* filename);
dep_Initialize(const char* outputFileName);

extern void
dep_SetMainOutput(string* filename);
Expand Down
26 changes: 20 additions & 6 deletions xasm/common/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,14 @@ err_Accept(void) {
}

static void
printError(const SPatch* patch, char severity, size_t errorNumber, uint32_t* count, va_list args) {
printError(const SPatch* patch, const SSymbol* symbol, char severity, size_t errorNumber, uint32_t* count, va_list args) {
string_buffer* buf = strbuf_Create();

strbuf_AppendFormat(buf, "%c%04d ", severity, (int) errorNumber);
if (patch != NULL) {
strbuf_AppendFormat(buf, "%s(%d): ", str_String(patch->filename), patch->lineNumber);
} else if (symbol != NULL) {
strbuf_AppendFormat(buf, "%s(%d): ", str_String(symbol->fileInfo->fileName), symbol->lineNumber);
} else {
string* stack = fstk_Dump();
strbuf_AppendString(buf, stack);
Expand Down Expand Up @@ -231,7 +233,7 @@ err_Warn(uint32_t errorNumber, ...) {
va_list args;

va_start(args, errorNumber);
printError(NULL, 'W', errorNumber, &xasm_TotalWarnings, args);
printError(NULL, NULL, 'W', errorNumber, &xasm_TotalWarnings, args);
va_end(args);
}
return true;
Expand All @@ -242,7 +244,7 @@ err_Error(int n, ...) {
va_list args;

va_start(args, n);
printError(NULL, 'E', n, &xasm_TotalErrors, args);
printError(NULL, NULL, 'E', n, &xasm_TotalErrors, args);
va_end(args);

return false;
Expand All @@ -253,7 +255,19 @@ err_PatchError(const SPatch* patch, int n, ...) {
va_list args;

va_start(args, n);
printError(patch, 'E', n, &xasm_TotalErrors, args);
printError(patch, NULL, 'E', n, &xasm_TotalErrors, args);
va_end(args);

++xasm_TotalErrors;
return false;
}

bool
err_SymbolError(const SSymbol* symbol, int n, ...) {
va_list args;

va_start(args, n);
printError(NULL, symbol, 'E', n, &xasm_TotalErrors, args);
va_end(args);

++xasm_TotalErrors;
Expand All @@ -265,7 +279,7 @@ err_Fail(int n, ...) {
va_list args;

va_start(args, n);
printError(NULL, 'F', n, &xasm_TotalErrors, args);
printError(NULL, NULL, 'F', n, &xasm_TotalErrors, args);
va_end(args);

printf("Bailing out.\n");
Expand All @@ -277,7 +291,7 @@ err_PatchFail(SPatch* patch, int n, ...) {
va_list args;

va_start(args, n);
printError(patch, 'F', n, &xasm_TotalErrors, args);
printError(patch, NULL, 'F', n, &xasm_TotalErrors, args);
va_end(args);

printf("Bailing out.\n");
Expand Down
3 changes: 3 additions & 0 deletions xasm/common/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ err_Error(uint32_t errorNumber, ...);
extern bool
err_Fail(uint32_t errorNumber, ...);

extern bool
err_SymbolError(const SSymbol* patch, uint32_t errorNumber, ...);

extern bool
err_PatchError(const SPatch* patch, uint32_t errorNumber, ...);

Expand Down
Loading

0 comments on commit 6ac61b3

Please sign in to comment.