Message Printing problem [N00B Question, sorta]

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.
Post Reply
LdaXy
Posts: 1
Joined: Sun Nov 20, 2011 9:02 pm

Message Printing problem [N00B Question, sorta]

Post by LdaXy »

ok. i'm new to programming an OS, but have a good amount of experience coding for other languages.

anyways, i created a simple bootloader with about 12 lines of text, to be displayed on separate lines.

Code: Select all

;xOS Version 0.001 by LdaXy (Alexander Frankland) & Matthew Cartier 2011
;Do not use outside of an emulator!
;Do not redistribute without permission!

[BITS 16]
[ORG 0x7C00]

MOV SI, TITLE1
CALL PrintString
MOV SI, TITLE2
CALL PrintString
MOV SI, TITLE3
CALL PrintString
MOV SI, TITLE4
CALL PrintString
CALL PrintVersionInfo
HLT

PrintCharacter:
MOV AH, 0x0E
MOV BH, 0x00
MOV BL, 0x07

INT 0x10
RET

PrintString:
MOV AL, [SI]
INC SI
OR AL, AL
JZ ExitFunc
CALL PrintCharacter
JMP PrintString

ExitFunc:
RET

PrintVersionInfo:
MOV SI, ProductLine1
CALL PrintString
MOV SI, ProductLine2
CALL PrintString
MOV SI, ProductLine3
CALL PrintString
MOV SI, ProductLine4
CALL PrintString
MOV SI, ProductLine5
CALL PrintString
MOV SI, ProductLine6
CALL PrintString
MOV SI, ProductLine7
CALL PrintString
MOV SI, ProductLine8
CALL PrintString
MOV SI, ProductLine9
CALL PrintString
MOV SI, ProductLine10
CALL PrintString
RET

;Data

TITLE1 db 'xOS Kernel Version 0.013B Codename: Dexter',0Dh, 0Ah
TITLE2 db 'Developed by LdaXy (Alexander Frankland) and  Matthew Cartier 2011', 0Dh, 0Ah
TITLE3 db 'Do not redistribute without permission! Do not use outside of an emulator!', 0Dh, 0Ah
TITLE4 db '====================================================================================', 0Dh, 0Ah

ProductLine1 db 'Changelog for V.0.013', 0Dh, 0Ah
ProductLine2 db '====================================================================================', 0Dh, 0Ah
ProductLine3 db '(Removed for now)Implemented CPUID Checking (May Not Work!)', 0Dh, 0Ah
ProductLine4 db 'To be added', 0Dh, 0Ah
ProductLine5 db '====================================================================================', 0Dh, 0Ah
ProductLine6 db  'Keyboard Drivers in development', 0Dh, 0Ah
ProductLine7 db '(Almost Complete) Simple Text Editor(NO SAVING)', 0Dh, 0Ah
ProductLine8 db '(Somewhat implimented) Memory testing. will halt on memsize < 128MB.', 0Dh, 0Ah
ProductLine9 db '(Future) GUI MODE. (Have not started yet. not untill kernel cmdline is done)', 0Dh, 0Ah
ProductLine10 db 'Network Drivers for P2p Connectivity. (NOT TORRENTING, FILE SHARING AND PC CONNECTIVITY)', 0Dh, 0Ah

DW 0xAA55
anyways, some part of the code here doesn't run correctly and instead of halting at the HLT function, it repeats forever.

could somebody please explian where my error is? thanks.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Message Printing problem [N00B Question, sorta]

Post by Brendan »

Hi,
LdaXy wrote:anyways, some part of the code here doesn't run correctly and instead of halting at the HLT function, it repeats forever.
The HLT instruction halts the CPU until an IRQ occurs. You can expect at least one IRQ from the timer every 55ms.

The solution is simple:

Code: Select all

.stop:
    hlt
    jmp .stop
There's other problems in that code though. You assume that the BIOS left DS set zero when you shouldn't. You assume there's a usable stack somewhere when you shouldn't. You print each character of the string until you reach a zero terminator, but there are no zero terminators at the ends of any of the strings.

I'd also make a few suggestions. Rather than printing each line separately you could print multiple lines with one "CALL PrintString". Also, don't forget that you've only got 512 bytes to work with (and some of that should be either a BPB or a partition table), which isn't enough space for an entire OS - those 512 bytes need to load more code and data from disk, and "loading more from disk" (with decent error handling, etc) doesn't leave room for much else in the boot sector.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: Message Printing problem [N00B Question, sorta]

Post by turdus »

Other problems:
- you forget to set up the stack
- no string terminator characters at the end of strings, so printint TITLE1 will print TITLE2, TITLE3 etc. One terminator at the end enough, but this case no need the call print for every line.

Code: Select all

mov si, title1
call printstring
...
title1: db "something1",0dh,0ah
title2: db "something2",0dh,0ah
title3: db "something3",0dh,0ah[b],0[/b]
or

Code: Select all

mov si, title1
call printstring
mov si, title2
call printstring
mov si, title3
call printstring
...
title1: db "something1",0dh,0ah[b],0[/b]
title2: db "something2",0dh,0ah[b],0[/b]
title3: db "something3",0dh,0ah[b],0[/b]
This also could result in output that similar to "repeating".
Post Reply