OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Nov 21, 2017 1:23 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: [BareBones Tutorial] Unrecognized Chars in provided code
PostPosted: Sat Nov 18, 2017 5:14 pm 
Offline

Joined: Sat Nov 18, 2017 4:45 pm
Posts: 2
Hello guys,

I realize I'm a newbie around here (in fact, I made this account to post this. Have been lurking for a couple of weeks. I'm a Software Engineer mainly dealing in C# and Dynamic C every day, so this is a change of pace for me), and hopefully this is not too obvious of a question, but when I try to compile boot.s as in the BareBones tutorial, I get the following errors:

https://ibb.co/cPcAV6
Quote:
boot.s: Assembler messages:
boot.s: Warning: end of file not at end of a line; newline inserted
boot.s:46: Warning: .type pseudo-op used outside of .def/.endef: ignored.
boot.s:46: Error: junk at end of line, first unrecognized character is `_'
boot.s:109: Warning: .size pseudo-op used outside of .def/.endef: ignored.
boot.s:109: Error: junk at end of line, first unrecognized character is `_'



The code is directly pasted (I wanted to be sure it was not a typo on my end) into Visual Studio Code and compiled through Cygwin's Terminal (I'm running W10) / gcc.

The lines referenced in the error can be seen here:
https://ibb.co/cywUq6
https://ibb.co/fJFTiR
Code:
46:    .type _start, @function
109:   .size _start, . - _start


I have read through the BareBones tutorial three times, searched the wiki and forum, as well as stack overflow and general googling. Of course, normally, an error like this is a typo. But removing the _ characters does not fix the problem. I tried removing the _ characters on the start function and its calls, but to no avail.

Thank you!


Top
 Profile  
 
 Post subject: Re: [BareBones Tutorial] Unrecognized Chars in provided code
PostPosted: Sat Nov 18, 2017 6:26 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 81
Your problem is related to using Visual Studio editor which by default saves text files with Windows End of Line characters. That is a Carriage Return followed by a line feed. Unfortunately your GCC in Cygwin expects files to have Unix end of line characters which is just a single Line Feed. GCC is getting confused with the Windows End of Line characters. What you can do is change the default EOL in Visual Studio by use the "file" menu, "Advanced Save Options...", select "Line Endings" and change to "Unix (LF)". Then you'll have to reload your .s file and save it again.

Alternatively you can load your .s file in Visual Studio, then do "File" menu "Save <file> As..." then in the popup box click the down arrow to the right of the "save" button select "Save with encoding" and then "line endings" and change to "Unix (LF)". This process will change it for that file only.

Cygwin may also me able to convert your files with the dos2unix command. specify dos2unix filename.s which should change the end of line characters to be Unix LF.


Top
 Profile  
 
 Post subject: Re: [BareBones Tutorial] Unrecognized Chars in provided code
PostPosted: Sat Nov 18, 2017 7:12 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 209
Location: Ukraine, Bachmut
the problem more probably is not in EOL characters used, gcc builds for Windows understand both EOL and even directory separator specific for it.
First, the warning "end of file not at end of a line; newline inserted" shows GCC wants an empty line at the end of file, put it there for it.
Second, this seems to be the reason of errors:
Quote:
For COFF targets, this directive is permitted only within .def/.endef pairs. It is used like this:

It looks like you use COFF as your target output format. Then you should use .def/.endef pairs and put .type there. But I fear you use gcc compiled for Windows targetting for your OS targetting. That hardly would work with gcc...

You need a cross-compiler for that.

_________________
future big goal: ANT - NT-like OS for mips, arm and x86 (and, possibly, ppc and itanium, hehehe).
current smaller goal: efify - UEFI for a couple of boards (mips and arm).


Top
 Profile  
 
 Post subject: Re: [BareBones Tutorial] Unrecognized Chars in provided code
PostPosted: Sat Nov 18, 2017 9:14 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 81
Ah I removed a post I just made and realized that this wouldn't be EOL related and that this is a result of the format being used not supporting certain directive the same way. So yes, a good reason to use an elf cross compiler. So I do agree with your assessment when I looked at the output again


Top
 Profile  
 
 Post subject: Re: [BareBones Tutorial] Unrecognized Chars in provided code
PostPosted: Sun Nov 19, 2017 2:16 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3010
Location: Chichester, UK
Just to add further explanation.

After ignoring the .type and .size directives (for reasons explained above) the rest of each line is invalid. Hence the errors "junk at end of line".


Top
 Profile  
 
 Post subject: Re: [BareBones Tutorial] Unrecognized Chars in provided code
PostPosted: Mon Nov 20, 2017 6:22 am 
Offline

Joined: Sat Nov 18, 2017 4:45 pm
Posts: 2
Thank you all for the replies. Using Dos2Unix or forcing the correct encoding through either VS Code or VIM didn't do much.
It turned out to be the cross-compiler, indeed. It used the windows one instead of the target one. I rebuilt it and it compiles perfectly fine now (since it uses the correct cross-compiler now)

Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group