Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anomalous CR generation under Cygwin #174

Closed
spotlessmind1975 opened this issue Oct 28, 2021 · 1 comment
Closed

Anomalous CR generation under Cygwin #174

spotlessmind1975 opened this issue Oct 28, 2021 · 1 comment
Labels
6809 Motorola 6809 enhancement New feature or request
Milestone

Comments

@spotlessmind1975
Copy link
Owner

spotlessmind1975 commented Oct 28, 2021

Summarized from forum.system-cfg.com

Under cygwin, git is doing an end-of-line conversion in the "Windows" convention. Result: the ASM files under src/hw/ all have the windows "\r\n" convention for end of lines. So far everything is good.

Then in the makefile the rules like

 SOURCES_6809 := $(subst src/hw/6809/,src-generated/6809_,$(MODULES_6809:.asm=.c))

 src-generated/6809_%.c: $(MODULES_6809)
     @xxd -i $(subst src-generated/6809_,src/hw/6809/,$(@:.c=.asm)) >$@

convert, via xxd, ASM files to a character array so that they can be written "as is" in ASM files so we find a trace of the "\r\n" in this binary "dump" of the text files.

Further in the code when we have to write these modules we ultimately use the macro outembedded0, which roughly makes a fwrite () of the "bulk" array.

Since the "asmFile" is a file opened in text mode, and contrary to popular belief, fwrite() performs (again!) a line conversion on this type of file. Result is that the final "\n" of "\r\n" is itself output as "\r\n". This is very surprising since fwrite()rite binary, including text files. But under cygwin we got a different behaviour.

Solutions:

  • the C library should be told not to interpret line endings in fwrite();
  • we define outembedded0(e) to jump over the '\r', and so '\n' can be extended by the routines;

Original comment:

Compiling one of the test file under asm6809 generates the following error:

 $ asm6809 -H -e 7168 /tmp/out.asm -o /tmp/out.hex -s /tmp/out.sym -l /tmp/out.lis -v  
 syntax error: /tmp/out.asm:710:

By examing the source code:
image

By using the od -tc /tmp/out.asm command, it shows that the file contains double \r:

By removing it:

   sed -e 's/\r\r/\r/g' /tmp/out.asm >out.asm

now it assembles correctly.

@spotlessmind1975 spotlessmind1975 added enhancement New feature or request 6809 Motorola 6809 labels Oct 28, 2021
@spotlessmind1975 spotlessmind1975 added this to the 1.6 milestone Oct 28, 2021
@spotlessmind1975 spotlessmind1975 changed the title Remove double CR before processing Anomalous CR generation under Cygwin Oct 29, 2021
@spotlessmind1975
Copy link
Owner Author

spotlessmind1975 commented Oct 29, 2021

Wanting to solve the problem, we have various ways:

  1. the C library must be told not to interpret line endings in fwrite();
  2. we define outembedded0(e) to jump over "\r", and so "\n" can be extended by routines;
  3. remove the abnormal character sequence from the output file, post-processing (it was the initial solution);
  4. open all the files in binary mode, even if they are text files;
  5. put a .gitattribute in the project so that * .asm files are considered with linux-style end of lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6809 Motorola 6809 enhancement New feature or request
Projects
Development

No branches or pull requests

1 participant