My Bootsector Problems

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
Kaini
Posts: 3
Joined: Tue Aug 14, 2007 1:51 pm
Location: Austria

My Bootsector Problems

Post by Kaini »

Hello,
I am very interrested in OS-Developing and I have found this forum.
I have read a lot of Tutorials and now I am trying to write my bootsector but I have a problem.
The bootsector should enable the A20 Gate and load the kernel from a FAT12 Flobby.
Now I want to read the FAT-Table - I load it into the RAM but how can I read it from the RAM? And I have another problem, BOCHS show never the 'X' in hang.
Here is the code:

Code: Select all

[BITS 16]
[ORG 0]
%include "fat12bios.inc"
JMP 0x07C0:start
start:
	CLI
	MOV AX,CS
	MOV DS,AX
	MOV ES,AX
	MOV SS,AX
	MOV SP,0xFFFF
a20:
	;...
	STI
lodfat: ;LOAD THE FAT TABEL
	MOV CX,[FATSize]
	lodfattbl_loop:
		MOV AX,[RsvdSecCnt] ;FAT_Start = RsvdSecCnt
		ADD AX,[FATSize] ;Wenn man den Zweiten Sektor einlesem muss, muss...
		SUB AX,CX      ;...man diese Rechnung rechnen
		MOV BX,0x0
		CALL rseclba
	LOOP lodfattbl_loop
	;LOAD THE ROOT-ENTRY
	MOV AX,32 ;(32*RootEntCnt + BytesPerSec–1) / BytesPerSec
	MUL BYTE [RootEntCnt]
	ADD AX,[BytesPerSec]
	DEC AX
	XOR DX,DX
	DIV WORD [BytesPerSec]
	MOV CX,AX
	MOV DX,CX
	lodroottbl_loop:
		;Root-Directory-Startsektor = (FATSize * NumFATs) + ResvdSecCnt
		MOV AX,[FATSize]
		MUL BYTE [NumFATs]
		ADD AX,[RsvdSecCnt]
		;+Größe
		ADD AX,DX
		;-Noch zu erledigen
		SUB AX,CX
		MOV BX,0x0
		CALL rseclba
	LOOP lodroottbl_loop
hang:
	MOV AH,0x0E
	MOV AL,'X'
	MOV BX,0
	INT 0x10
	JMP $
calls:
	;Wartet auf den Tastatur-Controller
	cwait:
		IN AL,0x64
		TEST AL,00000010b
			JNZ cwait
		RET
	;Wartet auf den Chip
	chipwait:
		IN AL,0x64
		TEST AL,00000001b
			JZ chipwait
		RET
	;Liest einen Sektor über die LBA
	;AX -> LBA
	;ES:BX -> Segment:Offset
	;LOAD A SECTOR AND CONVERTS LBA->CHS
	rseclba:
		PUSHA
		PUSH BX
		;Cylinder (LBA/SecPerTrack)/NumHeads
		PUSH AX ;LBA sichern
		XOR DX,DX
		DIV WORD [SecPerTrack] ;DX:AX/SecPerTrack -> AX
		XOR DX,DX
		DIV WORD [NumHeads] ;DX:AX/NumHeads -> AX
		POP BX ;LBA zurück
		PUSH AX ;Cylinder sichern
		XCHG AX,BX
		;Head (LBA/SectorsPerTrack)%NumHeads
		PUSH AX ;LBA sichern
		XOR DX,DX
		DIV WORD [SecPerTrack] ;DX:AX/SecPerTRack -> AX
		XOR DX,DX
		DIV WORD [NumHeads] ;DX:AX%NumHeads -> DX
		POP AX ;LBA zurpck
		PUSH DX ;Head sichern
		;Sector (LBA%SectorsPerTrack)+1
		XOR DX,DX
		DIV WORD [SecPerTrack] ;DX:AX%SecPerTRack -> DX
		INC DX
		PUSH DX
		
		read:
		MOV AH,0x02 ;Funktion
		MOV AL,1 ;Sektoren
		POP CX ;Sektornr.
		POP DX ;Head
		SHR DX,4
		MOV DL,0 ;Laufwerk
		POP BX ;Cylinter - Temp
		MOV CH,BL ;Cylinder
		POP BX ;Offset
		INT 0x13
		JC read;Wenn Fehler (CF=1)
		POPA
		RET
vars:
	TIMES 510-($-$$) DB 0
	DW 0xAA55
I know my English is bad...
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:

Re: My Bootsector Problems

Post by Combuster »

Kaini wrote:how can I read it from the RAM?
To start with, I'm going to give you the cold shower: that line tells me you do not know enough of assembly (or in general the basics of how a computer works) to even write something as difficult as an operating system. I suggest you find some starters tutorials on assembly. Your question will be answered there.

If i'm mistaken and the question was just horribly phrased, try bochs' debugging features.
"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
deadmutex
Member
Member
Posts: 85
Joined: Wed Sep 28, 2005 11:00 pm

Post by deadmutex »

Now I want to read the FAT-Table - I load it into the RAM but how can I read it from the RAM?
There might be a misunderstanding between us somewhere. From what you wrote, it sounds as if you loaded data into RAM and you're asking how to read that data. If so, then you need to relearn how to program in assembly.

If you mean that you loaded the FAT into memory and you want to know how read the entries that indicate the next cluster, then I understand. Each entry is 12 bits wide for FAT12, so every 3 bytes will hold 2 entries.

Code: Select all

             4bits 4bits
+-----------------------------------+
|  entry 1  |  1  |  2  |  entry 2  |
+-----------------------------------+
    1 byte      1 byte     1 byte

Kaini
Posts: 3
Joined: Tue Aug 14, 2007 1:51 pm
Location: Austria

Post by Kaini »

The Problem with the X is solved, I have swapped two variables...
There might be a misunderstanding between us somewhere. From what you wrote, it sounds as if you loaded data into RAM and you're asking how to read that data. If so, then you need to relearn how to program in assembly.
To start with, I'm going to give you the cold shower: that line tells me you do not know enough of assembly (or in general the basics of how a computer works) to even write something as difficult as an operating system. I suggest you find some starters tutorials on assembly. Your question will be answered there.
There istn't a misunderstandung! Ich have read the chapter about adressing hundreds times and it won't work!

Code: Select all

MOV AH,ES:[DI]
That is 1:1 from my Assambler Tutorial but NASM won't compile it :(.
A quote of my Tutorial wouldn't help, because it is German.
I know my English is bad...
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 »

Code: Select all

MOV AH,ES:[DI]
That looks like tasm syntax to me. You are using the wrong assembler for that tutorial.

the proper nasm code will be:

Code: Select all

mov ah, [es:di]
A quote of my Tutorial wouldn't help, because it is German.
Are you assuming you are the only german-speaking person here? A link to a tutorial you are using is always helpful.
"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 ]
Kaini
Posts: 3
Joined: Tue Aug 14, 2007 1:51 pm
Location: Austria

Post by Kaini »

Now it works! Thanks.
A quote of my Tutorial wouldn't help, because it is German.
Are you assuming you are the only german-speaking person here? A link to a tutorial you are using is always helpful.
Sorry. Next time I will post a link.
I know my English is bad...
Post Reply