OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:31 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Printing new line on boot
PostPosted: Tue Sep 19, 2017 4:35 am 
Offline

Joined: Sat Sep 02, 2017 11:34 am
Posts: 7
I tested a simple program on ASM that receives the user input and echoes back the message using the BIOS interrupt calls.
All works fine in QEMU, but when I test this loader on real hardware doesn't shows the newline.
The function that shows the newline is the following:
Code:
newline:              ; Adds a new line
    mov al, 13        ; Set AL to the CR character
    call printc       ; Show the character
    mov al, 10        ; Set AL to the vertical tab character
    call printc       ; Show the character
    ret

(printc prints the caracter on the AL register)
Anyone knows why it doesn't works on real hardware?
Thanks! :)


Last edited by mondelob on Tue Sep 19, 2017 8:51 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Printing new line on boot
PostPosted: Tue Sep 19, 2017 5:34 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
My guess is something along these lines.

I can't be more specific without seeing more code.


Top
 Profile  
 
 Post subject: Re: Printing new line on boot
PostPosted: Tue Sep 19, 2017 6:06 am 
Offline

Joined: Sat Sep 02, 2017 11:34 am
Posts: 7
Thanks! I will search for an error there. The full code is in https://github.com/mondelob/OrigamiSystem/blob/master/One/Bootloader/boot.asm
Could be that there's no 16 Bits statement?


Last edited by mondelob on Tue Sep 19, 2017 8:51 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Printing new line on boot
PostPosted: Tue Sep 19, 2017 6:37 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
NASM and YASM default to generating 16-bit code when the output format is flat binary. You don't need "bits 16" but it's a good idea to include it for clarity.

Are you sure you're calling this BIOS function correctly?


Top
 Profile  
 
 Post subject: Re: Printing new line on boot
PostPosted: Tue Sep 19, 2017 7:13 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Are you sure that you are handling the CR/LF and TAB characters correctly, rather than just trying to echo the character to the screen?


Top
 Profile  
 
 Post subject: Re: Printing new line on boot
PostPosted: Tue Sep 19, 2017 7:31 am 
Offline
Member
Member

Joined: Sat Mar 01, 2014 2:59 pm
Posts: 1146
iansjack wrote:
Are you sure that you are handling the CR/LF and TAB characters correctly, rather than just trying to echo the character to the screen?
It looks like they are. They're using a BIOS function that's supposed to interpret these characters.

To OP: I'm not sure what's wrong with your code as it looks OK to me. Please be aware that "vertical tab" and "line feed" are not the same thing.

_________________
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing


Top
 Profile  
 
 Post subject: Re: Printing new line on boot
PostPosted: Tue Sep 19, 2017 7:42 am 
Offline

Joined: Sat Sep 02, 2017 11:34 am
Posts: 7
Actually I'm first showing a CR character (13) and after a LF character (10), those are the supposed to show a new line.
Maybe it's a BIOS problem? :O
Sorry for my questions, I'm a bit new with Assembly and BIOS programming


Last edited by mondelob on Tue Sep 19, 2017 8:50 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Printing new line on boot
PostPosted: Tue Sep 19, 2017 8:37 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2646
Location: Devon, UK
Please don't use coloured text - some of us are using dark themes where your posts are only visible by highlighting the text.

Cheers,
Adam


Top
 Profile  
 
 Post subject: Re: Printing new line on boot
PostPosted: Tue Sep 19, 2017 9:42 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Taking another look at your code, I see that you're using LODSB without CLD. You need to make sure the direction flag is set correctly before you use any string instructions.

Did you look at this documentation yet? Here's a hint: which registers must you set before using that function?


Top
 Profile  
 
 Post subject: Re: Printing new line on boot
PostPosted: Tue Sep 19, 2017 2:34 pm 
Offline
Member
Member

Joined: Sat Mar 01, 2014 2:59 pm
Posts: 1146
mondelob wrote:
Maybe it's a BIOS problem? :O
Try it on another computer. This will rule out any BIOS bugs specific to your computer.

_________________
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing


Top
 Profile  
 
 Post subject: Re: Printing new line on boot
PostPosted: Thu Sep 21, 2017 12:54 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 671
Just thinking out loud.

I'm curious if you are booting this on real hardware using USB with Floppy emulation. I only ask because if this is the scenario then it is possible that the BIOS is overwriting some of the code and data in your program when it updates the BIOS Parameter Block (BPB). If this is the type of environment you are running in, I'd create a BPB just to allocate the space that may be overwritten by the BIOS.


Top
 Profile  
 
 Post subject: Re: Printing new line on boot
PostPosted: Mon Oct 02, 2017 3:21 am 
Offline

Joined: Sat Sep 02, 2017 11:34 am
Posts: 7
onlyonemac wrote:
Try it on another computer. This will rule out any BIOS bugs specific to your computer.

Tested on other machine and worked correctly.. still didn't know why on my BIOS doesn't show it


Top
 Profile  
 
 Post subject: Re: Printing new line on boot
PostPosted: Mon Oct 02, 2017 10:44 am 
Offline
Member
Member

Joined: Sat Mar 01, 2014 2:59 pm
Posts: 1146
mondelob wrote:
onlyonemac wrote:
Try it on another computer. This will rule out any BIOS bugs specific to your computer.

Tested on other machine and worked correctly.. still didn't know why on my BIOS doesn't show it
Try pushing everything to the stack before calling the BIOS function and then popping it afterwards. If this works then I'm guessing that the BIOS function is corrupting a register that you aren't expecting it to. Check the documentation for the function that you're using and see what registers are supposed to be preserved, if you're expecting it to preserve registers that it isn't supposed to preserve then it's possible that it might work on some BIOSes that happen to preserve those registers but not on others that don't, otherwise your BIOS is evidently corrupting a register that it's supposed to preserve.

_________________
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing


Top
 Profile  
 
 Post subject: Re: Printing new line on boot
PostPosted: Mon Oct 02, 2017 11:51 am 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 671
I'll ask again. Are you testing this on real hardware using a USB device as a boot device?


Top
 Profile  
 
 Post subject: Re: Printing new line on boot
PostPosted: Mon Oct 02, 2017 12:02 pm 
Offline

Joined: Sat Sep 02, 2017 11:34 am
Posts: 7
MichaelPetch wrote:
I'll ask again. Are you testing this on real hardware using a USB device as a boot device?

Yes

onlyonemac wrote:
Try pushing everything to the stack before calling the BIOS function and then popping it afterwards. If this works then I'm guessing that the BIOS function is corrupting a register that you aren't expecting it to. Check the documentation for the function that you're using and see what registers are supposed to be preserved, if you're expecting it to preserve registers that it isn't supposed to preserve then it's possible that it might work on some BIOSes that happen to preserve those registers but not on others that don't, otherwise your BIOS is evidently corrupting a register that it's supposed to preserve.

Im a bit new in ASM, you push every register before calling the function, and then once I entered in for example printc or newline; pop all the registers?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot] and 63 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