Printing new line on boot

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
mondelob
Posts: 7
Joined: Sat Sep 02, 2017 11:34 am

Printing new line on boot

Post by mondelob »

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: Select all

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.
Octocontrabass
Member
Member
Posts: 5218
Joined: Mon Mar 25, 2013 7:01 pm

Re: Printing new line on boot

Post by Octocontrabass »

My guess is something along these lines.

I can't be more specific without seeing more code.
mondelob
Posts: 7
Joined: Sat Sep 02, 2017 11:34 am

Re: Printing new line on boot

Post by mondelob »

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.
Octocontrabass
Member
Member
Posts: 5218
Joined: Mon Mar 25, 2013 7:01 pm

Re: Printing new line on boot

Post by Octocontrabass »

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?
User avatar
iansjack
Member
Member
Posts: 4604
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Printing new line on boot

Post by iansjack »

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?
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Printing new line on boot

Post by onlyonemac »

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
mondelob
Posts: 7
Joined: Sat Sep 02, 2017 11:34 am

Re: Printing new line on boot

Post by mondelob »

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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Printing new line on boot

Post by AJ »

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
Octocontrabass
Member
Member
Posts: 5218
Joined: Mon Mar 25, 2013 7:01 pm

Re: Printing new line on boot

Post by Octocontrabass »

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?
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Printing new line on boot

Post by onlyonemac »

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
MichaelPetch
Member
Member
Posts: 712
Joined: Fri Aug 26, 2016 1:41 pm
Freenode IRC: mpetch

Re: Printing new line on boot

Post by MichaelPetch »

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.
mondelob
Posts: 7
Joined: Sat Sep 02, 2017 11:34 am

Re: Printing new line on boot

Post by mondelob »

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
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Printing new line on boot

Post by onlyonemac »

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
MichaelPetch
Member
Member
Posts: 712
Joined: Fri Aug 26, 2016 1:41 pm
Freenode IRC: mpetch

Re: Printing new line on boot

Post by MichaelPetch »

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

Re: Printing new line on boot

Post by mondelob »

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?
Post Reply