Confusion on bootsector

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
Ruxbin
Posts: 8
Joined: Tue Oct 30, 2007 2:24 am
Location: Shanghai,China

Confusion on bootsector

Post by Ruxbin »

Hi,all
We all know that the bootsector often dump some text like "booting..."on the screen. I'm thinking about adding some sounds while booting. So I googled and found http://www.delphi3000.com/articles/article_3773.asp?SK= useful.Using 8253/8254 channel2 ,PPI and speaker can produce sounds :roll:.After compiling,I use bochs to test the codes. But there is no sound at all :( . I use bochs to trace every lines of codes and found that the codes themselves should be all right(no errors like write %ax to (%ax))
Anyone know the reason? Thanks!
Here are my codes:(at&t style)
#bootsect.s

Code: Select all

.text
	.global start
	.code16
Freq=100
start:
	mov $0x0b6,%al
	out %al,$0x43
	mov $0x14,%dx
	mov $0x4f38,%ax 	 #dx:ax=0x144f38=1331000
	mov $Freq,%bx
	div %bx				   #ax=1331000/Freq
	out %al,$0x42		  #write low byte
	mov %ah,%al
	out %al,$0x42		 #write high byte

	mov $100,%dx		   #dx is the loop times
	in $0x61,%al		  #read the PPI's state
	and $0xfd,%al	     #do some bits operation
							           #set bit 0-->use the 8253/8254
							          #clear bit 1-->turn speaker off
sound:
	xor $2,%al			         #converse bit 1
	out %al,$0x61
	mov $0x140,%cx                 #loop some time
wait:
	loop wait
	dec %dx
	jne sound
end:jmp end
.org 0x1fe,0x90
.word 0xaa55
and the link scripts :ld--oformat binary -s -x -N -e start -Ttext 0x7c00 bootsect.o -o bootsect :idea:
User avatar
Ruxbin
Posts: 8
Joined: Tue Oct 30, 2007 2:24 am
Location: Shanghai,China

Post by Ruxbin »

I am in China. And the time is 1:18 am :shock:
need some sleep now :D
Hope when I wake up my problem will be fixed. :lol:
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Ruxbin wrote:I am in China. And the time is 1:18 am :shock:
need some sleep now :D
Hope when I wake up my problem will be fixed. :lol:
Apparently you didn't read the rules - otherwise you'd know posting this is a _bad_ idea
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

Code: Select all

    outportb(0x43, 0xB6);
    Freq = 0x1D4C0/Freq;
    Freq_Hi = (Freq >> 8) & 0x00FF;
    Freq_Lo = Freq & 0x00FF;
    outportb(0x42, Freq_Hi);
    outportb(0x42, Freq_Lo);

    /* Turn the speaker on */
    outportb(0x61, inportb(0x61) | 3 );
User avatar
Ruxbin
Posts: 8
Joined: Tue Oct 30, 2007 2:24 am
Location: Shanghai,China

Post by Ruxbin »

Combuster wrote:
Ruxbin wrote:I am in China. And the time is 1:18 am :shock:
need some sleep now :D
Hope when I wake up my problem will be fixed. :lol:
Apparently you didn't read the rules - otherwise you'd know posting this is a _bad_ idea
:P yes,you are right. All these words are useless and I'm sorry about that.They don't relate to OS development.
Still I want some help. 8)
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post by Brendan »

Hi,

Here's some code from my boot loader:

Code: Select all

;Note: The frequency of "middle C" is 261.63 Hz, so the timer count is set to
;      [i1193180 / 261.63] to get this tone (middle C was chosen as it's in the middle
;      of the audible frequency range). This works out to a count of 4561, or 0x11D1.

	mov al,10110110b			;al = counter 2, low then high, square wave, 16 bit
	cli
	out 0x43,al				;Set timer channel 2 mode
	jmp $+2
	jmp $+2
	mov al,0xD1				;al = low count
	out 0x42,al				;Set timer channel 2 low count
	jmp $+2
	jmp $+2
	mov al,0x11				;al = high count
	out 0x42,al				;Set timer channel 2 high count
	sti

	in al,0x61				;al = system control port
	or al,00000011b				;Set speaker enable and PIT to speaker enable bits
	out 0x61,al				;Set system control port
If you compare my code, 01000101's code and your code you'll notice a few differences...

Note: I run Bochs on a server that doesn't have any sound card, so I don't know if this works on Bochs or not. I do know my code works on all real machines I've tried it on...


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
Ruxbin
Posts: 8
Joined: Tue Oct 30, 2007 2:24 am
Location: Shanghai,China

Post by Ruxbin »

01000101 wrote:

Code: Select all

    outportb(0x43, 0xB6);
    Freq = 0x1D4C0/Freq;
    Freq_Hi = (Freq >> 8) & 0x00FF;
    Freq_Lo = Freq & 0x00FF;
    outportb(0x42, Freq_Hi);
    outportb(0x42, Freq_Lo);

    /* Turn the speaker on */
    outportb(0x61, inportb(0x61) | 3 );
Thanks.
I've tried your code. But still there is no sound. Is that because Vmware or Bochs dosen't support this raw method to generate some sounds?
User avatar
Ruxbin
Posts: 8
Joined: Tue Oct 30, 2007 2:24 am
Location: Shanghai,China

Post by Ruxbin »

to Brendan:
Thanks a lot for your help.:D
I've tried out your codes and bochs still doesn't responded to them. :(
I doubt this may be bochs's problem. Thanks anyway and I'll try the codes in real machine. 8)
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

yeah the code above has only been tested by me on a real machine.
User avatar
zaleschiemilgabriel
Member
Member
Posts: 232
Joined: Mon Feb 04, 2008 3:58 am

Post by zaleschiemilgabriel »

Are you by any chance trying to make an alarm clock? :)
DeviOuS - what a stupid name
User avatar
Ruxbin
Posts: 8
Joined: Tue Oct 30, 2007 2:24 am
Location: Shanghai,China

Post by Ruxbin »

zaleschiemilgabriel wrote:Are you by any chance trying to make an alarm clock? :)
yes,my system has timer interrupt and it is generated by 8253. Here I use 8254 to control the speaker. I've tried all the codes in real machine and everything went on quite well. :D
Post Reply