Can't Show Text in Operational System

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
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Can't Show Text in Operational System

Post by Nathan »

Hello,
I'm trying to do an OS that shows a message(msg1 = Hello, World) for the user, but when the OS boots up on Bochs, it don't shows nothing than the boot process. Here is my code:

Code: Select all

[BITS 16]	 ; 16 bit code generation
[ORG 0x7C00]	 ; ORGin location is 7C00

main:
MOV AH, 0Eh
MOV BH, 00h
MOV BL, 07h
MOV AL, 1
MOV BP, msg1
MOV AH, 13h
INT 10h
JMP msg1                                    

msg1 DB "Hello, World!"

; Boot things
times 510-($-$$) db 0	; Fill the rest of the sector with zeros
dw 0xAA55		; Boot signature
But when i boot up it with Bochs it only shows me nothing.
I compiled and write at the floppy correct.

Thanks,
Nathan Paulino Campos
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Can't Show Text in Operational System

Post by gravaera »

So: how does this Operational System stuff work? *snicker snicker* 8) (Couldn't resist)

Hi: First result in google for "Bios int 10h" = wikipedia, which states that you are using the wrong BIOS interrupt subfunction.
Wikipedia wrote: AH = 13h : Output a string.

AL = Write mode, BH = Page, BL = Color, CX = String length, DH = Row, DL = Column, ES:BP = Offset of string
Wikipedia wrote: AH = 0Eh : Output a character

AL = Character
According to the listed expected values, you would get nothing, since you're calling a function to print one char, and the char you set is null, or garbage, depending on what was left over in your AL reg. That was easily debuggable... [-X
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Re: Can't Show Text in Operational System

Post by Nathan »

Ok, now a part is fixed, but how i can put the "Hello, World" printed in the screen.
I'm reading this.

Thanks!
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Can't Show Text in Operational System

Post by neon »

I see you are already able to display a single character. To display a string, just loop it until a string-terminating character (usually 0 but can be anything.)

Quick example function:

Code: Select all

; Prints a string DS=>SI: 0 terminated string
Print:
			lodsb
			or	al, al
			jz	.done
			mov	ah, 0eh
			int	10h
			jmp	Print
	.done
			ret
Just put the address of a null-terminating string in DS:SI and call the function to print a string.

Also, your boot loader should crash. You have a JMP msg1 instruction that will cause the processor to execute your string as machine instructions.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Re: Can't Show Text in Operational System

Post by Nathan »

Hello neon,
DS : SI?, like this:

Code: Select all

MOV DS, SI
MOV BP, msg1

msg1 DB "Hello, World!"
Thanks,
Nathan Paulino Campos
User avatar
Andr3w
Member
Member
Posts: 76
Joined: Tue Jun 09, 2009 4:09 am
Location: Somewhere

Re: Can't Show Text in Operational System

Post by Andr3w »

Nathan wrote: Hello neon,
DS : SI?, like this:

Code: Select all

MOV DS, SI
MOV BP, msg1

msg1 DB "Hello, World!"
Use neon's function to display a string.

Code: Select all


mov [ds:si], msg1
call Print
jmp $

msg1 db "hello, world!", 0     ; null-terminate our string

Hope this helps!

--Andrew
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Re: Can't Show Text in Operational System

Post by Nathan »

Hello Andrew,
Thanks for this, but see my code now, it's working:

Code: Select all

[BITS 16]	 ; 16 bit code generation
[ORG 0x7C00]	 ; ORGin location is 7C00

main:
MOV BH, 00h
MOV BL, 07h
MOV AL, 1
MOV BH, 0
MOV BL, 0011_1011b
MOV CX, osmsgend - os_msg ; calculate message size. 
MOV DL, 30
MOV DH, 0
PUSH CS
POP ES
MOV BP, os_msg
MOV AH, 13h
INT 10h
JMP wel

wel:
MOV BH, 00h
MOV BL, 07h
MOV AL, 1
MOV BH, 0
MOV BL, 0011_1011b 
MOV CX, welcome_end - welcome ; calculate message size. 
MOV DL, 32
MOV DH, 2
PUSH CS
POP ES
MOV BP, welcome
MOV AH, 13h
INT 10h
JMP osmsgend
                         
welcome DB "Welcome !"
welcome_end:
                         
os_msg DB "BerlOS v0.0.1"
osmsgend:
JMP $
; Boot things
TIMES 510-($-$$) DB 0	; Fill the rest of the sector with zeros
DW 0xAA55		; Boot signature
Thanks,
Nathan Paulino Campos
User avatar
Andr3w
Member
Member
Posts: 76
Joined: Tue Jun 09, 2009 4:09 am
Location: Somewhere

Re: Can't Show Text in Operational System

Post by Andr3w »

I checked and tried your code.
You should place BIOS Parameters Block at the top of your code, like this:

Code: Select all

[BITS 16]    ; 16 bit code generation
[ORG 0x7C00]    ; ORGin location is 7C00

	jmp short main	; Jump past disk description section
	nop				; Pad out before disk description


; ------------------------------------------------------------------
; Disk description table, to make it a valid floppy
; Note: some of these values are hard-coded in the source!
; Values are those used by IBM for 1.44 MB, 3.5" diskette

OEMLabel		db "BERL OS "	; Disk label - 8 chars
BytesPerSector		dw 512		; Bytes per sector
SectorsPerCluster	db 1		; Sectors per cluster
ReservedForBoot		dw 1		; Reserved sectors for boot record
NumberOfFats		db 2		; Number of copies of the FAT
RootDirEntries		dw 224		; Number of entries in root dir
					; (224 * 32 = 7168 = 14 sectors to read)
LogicalSectors		dw 2880		; Number of logical sectors
MediumByte		db 0F0h		; Medium descriptor byte
SectorsPerFat		dw 9		; Sectors per FAT
SectorsPerTrack		dw 18		; Sectors per track (36/cylinder)
Sides			dw 2		; Number of sides/heads
HiddenSectors		dd 0		; Number of hidden sectors
LargeSectors		dd 0		; Number of LBA sectors
DriveNo			dw 0		; Drive No: 0
Signature		db 41		; Drive signature: 41 for floppy
VolumeID		dd 00000000h	; Volume ID: any number
VolumeLabel		db "BERL OS    "; Volume Label: any 11 chars
FileSystem		db "FAT12   "	; File system type: don't change!


main:
MOV BH, 00h
MOV BL, 07h
MOV AL, 1
MOV BH, 0
MOV BL, 0011_1011b
MOV CX, osmsgend - os_msg ; calculate message size.
MOV DL, 30
MOV DH, 0
PUSH CS
POP ES
MOV BP, os_msg
MOV AH, 13h
INT 10h
JMP wel

wel:
MOV BH, 00h
MOV BL, 07h
MOV AL, 1
MOV BH, 0
MOV BL, 0011_1011b
MOV CX, welcome_end - welcome ; calculate message size.
MOV DL, 32
MOV DH, 2
PUSH CS
POP ES
MOV BP, welcome
MOV AH, 13h
INT 10h
JMP osmsgend
                         
welcome DB "Welcome !"
welcome_end:
                         
os_msg DB "BerlOS v0.0.1"
osmsgend:
JMP $
; Boot things
TIMES 510-($-$$) DB 0   ; Fill the rest of the sector with zeros
DW 0xAA55      ; Boot signature
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Re: Can't Show Text in Operational System

Post by Nathan »

Hello Andrew,
Thanks for the very good help, but what those things do of difference in my OS, i know about BIOS, but why i have to declare this all?

Thanks,
Nathan Paulino Campos
User avatar
Andr3w
Member
Member
Posts: 76
Joined: Tue Jun 09, 2009 4:09 am
Location: Somewhere

Re: Can't Show Text in Operational System

Post by Andr3w »

Nathan wrote:Hello Andrew,
Thanks for the very good help, but what those things do of difference in my OS, i know about BIOS, but why i have to declare this all?
EDIT: You need BPB (BIOS Parameters Block) if your file system requires it.
FAT12 needs this BPB.


Best regards,
-- Andrew
Last edited by Andr3w on Sun Aug 23, 2009 12:05 pm, edited 1 time in total.
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Re: Can't Show Text in Operational System

Post by Nathan »

Hum, thanks i'm going to see!
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Can't Show Text in Operational System

Post by neon »

Hello,
Nathan wrote:Hello neon,
DS : SI?, like this:

Code: Select all

MOV DS, SI
MOV BP, msg1

msg1 DB "Hello, World!"
Learn about segments and the segment:offset addressing that is used in real mode.

The above code will not work. DS is the data segment register (do to your ORG statement, this should be 0) and SI is the offset to your string.

Also, you only need the Bios Parameter Block (BPB) if the filesystem you plan to use (if any) requires it.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Re: Can't Show Text in Operational System

Post by Nathan »

Thanks neon!
Post Reply