Beiträge anzeigen

Diese Sektion erlaubt es dir alle Beiträge dieses Mitglieds zu sehen. Beachte, dass du nur solche Beiträge sehen kannst, zu denen du auch Zugriffsrechte hast.


Themen - BadBeu

Seiten: [1]
1
Lowlevel-Coding / Probleme mit Bochs/BIOS disk read
« am: 19. July 2006, 14:44 »
Hallo Leute,

ich habe ein kleines Problem mit meinem Bootloader.

Eigentlich soll er nur einen erweiterten Bootloader in den Speicher laden und ausführen, da das BIOS ja nur 512 bytes läd.
Eigentlich funktioniert das alles auch ganz prima, jedenfalls spuckt er keine Fehler aus. Aber er läd nichts in den Speicher.
Ich weiß jetzt nicht wo der Fehler liegt?
Im Debugger läd er alles in die richtigen Register machten den BIOS int und macht dann normal weiter. Nur das ich an der Speicherstelle nur Nullen hab anstatt mein Programm.

Hier mal mein Code. Ich weiß ... ist ein bischen umfangreich


_start:

;; essential initialization
cli

;; setup a stack
mov ax, 0x9000
mov ss, ax
mov sp, 0xFFFE

sti

;; load boot up message
push cs
pop ds
mov si, msg_bootup
;; print boot up message
call print_string

;; load loaction of position structure
push cs
pop ds
mov si, pos_struct
;; load stage two behind stage one
push 0x7E00
pop es
xor di, di
call load_stage2

;; jump into stage two
push es
push ax
retf

;; loads stage two of the bootloader
;; INPUT:
;; [DS:SI] - location of position structure pointing to bootloader on disk
;; [ES:DI] - location of the bootloader in memory
;; OUTPUT:
;; [ES:DI] - location of the bootloader in memory
;; [AX] - entry point offset of the bootloader
;; AFFECT:
load_stage2:
;; store location of position structure
push si
push ds

;; read header
call read_header

;; restore location of position structure
pop ds
pop si

;; store entry point
push ax

;; load bootloader into memory
mov ax, bx
call disk_read

;; restore entry point
pop ax

;; return to caller
ret

;; loads, verifies and reads values from bootloader header
;; INPUT:
;; [DS:SI] - location of position structure pointing to bootloader header on disk
;; [ES:DI] - location of data buffer
;; OUTPUT:
;; [AX] - entry point
;; [BX] - size of bootloader (in sectors)
;; AFFECT:
;; [AX] - entry point
;; [BX] - size of bootloader (in sectors)
;; [DX] - calculation issue
;; [DS:SI] - end of header
read_header:
;; read header into memory
;; read just one sector
mov ax, 0x0001

;; read from disk
call disk_read

;; move output to input
push di
push es
pop ds
pop si

;; get size of bootloader
lodsw
;; calculate sector count
xor dx, dx
mov bx, 0x0020
div bx
or dx, dx
;; do not increment if even division
jz .no_inc
inc ax

.no_inc:
;; store size
mov bx, ax

;; verify magic number
;; first part
lodsw
xor ax, word [cs:magic_number]
jnz .invalid_header
;; second part
lodsw
xor ax, word [cs:magic_number+2]
jnz .invalid_header

;; get entry point
lodsw

;; return to caller
ret

.invalid_header:
;; load invalid header message
push cs
pop ds
mov si, msg_inv_header
;; panic
call panic

;; reads sectors from disk
;; INPUT:
;; [AX] - number of sectors to read
;; [DS:SI] - location of position structure
;; [ES:DI] - location of data buffer
;; OUTPUT:
;; [AX] - sectors actually read
;; [ES:DI] - location of data
;; AFFECT:
;; [AX] - through function call
;; [ES:DI] - through function call
;; [DS:SI] - through function call
;; [BX] - through function call
disk_read:
;; store number of sectors to read on stack
push ax

;; load drive number from position structure
lodsb
mov dl, al

;; check for floppy
and al, 10000000b
jz .read_floppy

;; read from hard disk
.read_disk:
;; [DS:SI] now already pointing to LBA and [DL] is set correctly
;; restore number of sectors to read from stack
pop ax

;; read from disk
call disk_read_lba

;; return to caller
ret

;; read from floppy disk
.read_floppy:
;; [DL] now already holding drive number

;; [DS:SI] now pointing to CHS value

;; load cylinder number
lodsw
mov bx, ax

;; load head number
lodsb
mov dh, al

;; load sector number
lodsb
mov cl, al

;; restore number of sectors to read
pop ax

;; read from disk
call disk_read_chs

;; return to caller
ret

;; reads sectors from disk via CHS referencing
;; INPUT:
;; [AL] - number of sectors to read
;; [BX] - cylinder number (only bit 0-9 used)
;; [DH] - head number
;; [CL] - sector number (only bit 0-6 used)
;; [DL] - drive number to access
;; [ES:DI] - location of data buffer
;; OUTPUT:
;; [AX] - sectors actually read
;; [ES:DI] - location of data
;; AFFECT:
;; [AX] - sectors actually read
;; [ES:DI] - location of data
;; [BX] - offset of data
disk_read_chs:
;; protect against false input
and bx, 0000001111111111b
and cl, 00111111b

;; pack cylinder and sector number correctly
mov ch, bl
sal bh, 0x06
or cl, bh

;; store data buffer offset in [BX] for function call
mov bx, di

;; select DISK function (READ SECTOR(S) INTO MEMORY)
mov ah, 0x02

;; reset disk
call disk_reset

;; read disk
.read_disk:
;; BIOS interrupt
int 0x13

;; store flags
pushf

;; check for read error
xor ah, 0x04
jz .read_error

;; restore flags
popf

;; retry on error
jc .read_disk

.end_read:
;; store sectors read into [AX]
xor ah, ah

;; return to caller
ret

.read_error:
;; load read error message
push cs
pop ds
mov si, msg_readerror
call print_warning

;; complete function call
jmp .end_read

;; reads sectors from disk via LBA referencing
;; INPUT:
;; [DS:SI] - location of 64 bit LBA
;; [AX] - number of sectors to read into memory
;; [DL] - drive to access
;; [ES:DI] - location of data buffer
;; OUTPUT:
;; [AX] - sectors actually read
;; [ES:DI] - location of data
;; AFFECT:
;; [AX] - sectors actually read
;; [DS:SI] - location of the disk address packet
disk_read_lba:
;; fill in number of sectors to read into DAP
mov [dap_sec2read], ax

;; fill in LBA into DAP
lodsw
mov [dap_lba], ax
lodsw
mov [dap_lba+2], ax
lodsw
mov [dap_lba+4], ax
lodsw
mov [dap_lba+6], ax

;; fill in location of data buffer into DAP
mov [dap_data_buf], di
mov [dap_data_buf+2], es

;; load DAP
push cs
pop ds
mov si, dap

;; reset disk
call disk_reset

;; select DISK function (EXTENDED READ SECTOR(S))
mov ah, 0x42

;; read data from disk
.read_disk:
;; BIOS interrupt (DISK)
int 0x13

;; store flags
pushf

;; check for function error
push ax
xor ah, 0x01
jz .not_available
pop ax

;; check for read error
xor ah, 0x04
jz .read_error

;; restore flags
popf

;; retry on error
jc .read_disk

;; return to caller
.end_read:
;; store sectors actually read to [AX]
mov ax, [dap_sec2read]
;; return
ret

.not_available:
;; load error message
push cs
pop ds
mov si, msg_int13_ex_abs
;; panic
call panic

.read_error:
;; load read error message
push cs
pop ds
mov si, msg_readerror
;; print read error message
call print_warning

;; complete function call
jmp .end_read

;; resets disk drive
;; INPUT:
;; [DL] - dirve number to reset
;; OUTPUT:
;; [AH] - status of operation
;; AFFECT:
;; [AX] - status of operation
disk_reset:
;; select DISK function (RESET DISK SYSTEM)
mov ah, 0x00

.reset_disk:
;; BIOS interrupt (DISK)
int 0x13

;; retry on  error
jc .reset_disk

;; return to caller
ret

;; prints error message to screen and halts CPU
;; INPUT:
;; [DS:SI] - location of error message
;; OUTPUT:
;; none
;; AFFECT:
;; [AX] - through function call
;; [BX] - through function call
;; [SI] - through function call
panic:
;; store location of error message to stack
push si
push ds

;; load panic sign
push cs
pop ds
mov si, msg_panic
;; output panic sign
call print_string

;; restore location of error message from stack
pop ds
pop si
;; output error message
call print_string

;; halt CPU
.halt:
hlt
jmp .halt

;; prints a warning message to screen
;; INPUT:
;; [DS:SI] - location of warning message
;; OUTPUT:
;; none
;; AFFECT:
;; [AX] - through function call
;; [BX] - through function call
;; [SI] - through function call
print_warning:
;; store location of warning message to stack
push si
push ds

;; load warning sign
push cs
pop ds
mov si, msg_warning
;; print warning sign
call print_string

;; restore warning message
pop ds
pop si
;; print warning message
call print_string

;; return to caller
ret

;; prints a zero-terminated, teletype formated string to screen
;; INPUT:
;; [DS:SI] - location of string
;; OUTPUT:
;; none
;; AFFECT:
;; [AX] - BIOS function and character
;; [BX] - page and color selection
;; [SI] - advances during execution
print_string:
;; select VIDEO function (TELETYPE OUTPUT)
mov ah, 0x0E
;; select active page and default color
mov bx, 0x0007

;; process characters
.process_char:
;; load character into [AL]
lodsb

;; check for zero termination
or al, al
jz .end_process

;; BIOS interrupt (VIDEO)
int 0x10

;; process next character
jmp .process_char

;; return to caller
.end_process:
ret

;; data

;; magic number for header verification
magic_number dw 0xE64D, 0xBB40

;; Disk Address Packet for LBA disk access
dap:
dap_size db 0x10
dap_reserved db 0
dap_sec2read dw 0
dap_data_buf dw 0, 0
dap_lba dw 0, 0, 0, 0

;; messages
msg_bootup db "DSMOS bootloader starting...", 13, 10, 0
msg_panic db "BOOTLOADER PANIC: ", 0
msg_warning db "BOOTLOADER WARNING: ", 0
msg_readerror db "Read error encountered!", 13, 10, 0
msg_int13_ex_abs db "BIOS INT13h extensions not available!", 13, 10, 0
msg_inv_header db "Invalid header encountered!", 13, 10, 0

;; fill up to one sector (512 bytes)
times 512-($-$$)-11 db 0

;; position structure pointing to bootloader stage two
pos_struct:
db 0
dw 0
db 0, 0x02
dw 0, 0

;; boot signature
dw 0xAA55


Von besonderem Interesse wird wohl disk_read_chs sein. Da disk_read_lba ja nicht ausgeführt wird bei Disketten.

Ich hoffe der Code ist nicht zu umfangreich.

Schonmal danke für die Hilfe.
2
Lowlevel-Coding / Die INT 13h extensions
« am: 13. July 2006, 12:46 »
Hallo Leute,

ich bin grade dabei einen netten Bootloader zu coden. Da ich möchte, dass der viel kann möchte ich, dass er sich Module laden kann.
Als Vorraussetzung sei gesagt, dass er weiß, wo seine Module liegen (LBA-Sector-Referenzierung) und dass er weiß, wie viel er laden muss und wohin.
Nun ist mein Problem, dass diese Module vielleicht nicht in den unteren 8 GByte der Platte liegen.
Nun hab ich von den INT 13h extensions gelesen, bin aber nicht so ganz schlau aus dem geworden, was Google mir da ausgespuckt hat.

1. Ist das wirklich eine BIOS Funktion oder ist das ein OS Treiber, der eben auf dem INT 13h liegt.

2. Ist das ein Standard auf modernen Systemen oder spezifisch für eine BIOS-Software bzw. Kann ich abfragen, ob die Verfügbar sind.

3. Gibt es irgendwo Informationen zum Aufruf, also was für Parameter diese Funktion haben will, etc.

Schonmal Danke für Eure Hilfe.
3
Offtopic / Bootproblem bei VMWare Player
« am: 12. July 2006, 11:47 »
Hallo,
ich verzweifel so langsam.
Ich versuche einfach nur ein Boot-Disketten-Image zu erzeugen, dass ich mit VMWare Player starten kann. Das Ding macht noch nicht einmal viel


org 0x7c00

jmp $

times 512-($-$$)-2 db 0
dw 0xAA55


Das ist schon alles. Ist auch mehr zum testen von VMWare gedacht. Aber der liest mein Image nicht. Hab es erst mit der einfach 512 byte bootloader Datei probiert. Klappt unter Bochs nicht unter VMWare.
Dann einfach unter Linux mit /dev/zero zusammengelegt und auf 1.44M gebracht. Das hat auch nix geholfen.
Bei Google finde ich nur Sachen, wie ich Images von Diskette bzw. auf Diskette schreibe. Ich habe aber kein Disketten-Laufwerk und versuche "einfach so" ein Image zu erstellen, das ich mit VMWare booten kann.
Vielleicht kann mir ja einer von Euch dabei helfen.

Schon mal Danke.
4
OS-Design / Idee zum 36 bzw. 64 bit großen Addressraum
« am: 06. July 2006, 14:35 »
Hallo,

im Buch von Tanenbaum habe ich eine interessante Idee gelesen.
Da ja ab dem Pentium II (oder III - muss ich nochmal nachlesen) ja lineare Addressräume bis 64 GByte unterstützt werden bzw. bei 64 bit CPUs sogar einige tausend Terrabyte, habe ich mir gedacht, da ich sowieso auf moderne Architekturen setzen wollte, dass ich Dateien nicht nur lese, sondern einfach komplett in den Addressraum des Programs lade, das diese Datei öffnet.
Durch Paging kann ich ja dann, wenn darauf zugegriffen wird, den entsprechenden Teil laden - geht ja dann einfach von Festplatte - und das Programm ließt dann nur noch aus dem RAM. Falls dann irgendwann weitergelesen wird, brauch ich gar kein I/O mehr, da ich ja einfach aus meinem Addressraum lese - es sei denn, ich muss eine neue Page laden.
Es gibt da nur zwei Probleme, die mir jetzt eingefallen sind:

1. Der Page-Daemon muss das Dateiformat verstehen, in welchem die Dateien vorliegen. Wenn man also mehrere Datei-Format unterstützt müsste dann immer zunächst der Treiber für dieses Format aufgerufen werden - d.h. mehr Overhead

2. Der Programmierstil ändert sich gravierend gegenüber anderen OS. Ich bekomme dann nicht mehr meine Bytes, die ich auslesen wollte, sondern einen Pointer zum Begin der Datei, die in meinem Addressraum liegt. Durch einfach Pointerarithmetik komme ich dann zu meinen Bytes, die ich haben möchte, aber es ist eine Umstellung.

Haltet ihr sowas für realisierbar. Eben einmal OS-technisch und einmal User-technisch?

Schonmal Danke für die Antworten
5
OS-Design / Frage zu UDI
« am: 04. July 2006, 14:53 »
Hallo,

ich habe mal die UDI-Spezifikationen unter http://www.projectudi.org überflogen.
Nun habe ich ein paar generelle Fragen dazu, falls sich wer damit auskennt:

1. Ist es wert, dies in sein eigenes OS zu implementieren?
Also sich damit auseinanderzusetzen und sein Treiber darauf aufzubauen.

2. Ist die Spezifikation schon so weit, dass sie sicher ist?
Ich versuche ein sicheres Desktop-System zu schreiben. Deshalb ist mir wichtig, dass wenn ich es implementiere da keine Schlupflöcher sind.

Vielleicht kennt sich ja jemand damit aus.
Wenn nicht muss ich wohl mal durchlesen.

Schon mal Danke im Vorraus.
6
OS-Design / Architektur im OS-Design
« am: 29. June 2006, 10:30 »
Hallo,

da ich relativ neu in dieser Materie bin ist es möglich, dass meine Frage vielleicht etwas banal ist.

Ich habe mir den Tanenbaum (Operating Systems) gekauft und fast durchgelesen. Nun bin ich parallel angefangen das IA-32 Manual vol. 3 (System Programming) zu lesen.
Da Tanenbaum versucht alles auf einer sehr abstrakten Art und Weise darzustellen und das Intel Manual natürlich sehr spezifisch ist, stellt sich mir nun eine Frage:

Sollte man die Prozessor-Architektur in ein grundlegendes OS-Design (nicht Implementation - die ist selbstverständlich architektur-spezifisch) mit einbeziehen oder - z.B. auf Grund von Komptibilität - aussen vor lassen.

Es ist ja so, dass die IA-32 einige Features besitzen, die z.B. Task-Wechsel vereinfachen oder Paging unterstüzen. Dies könnte ja auf anderen Platformen vielleicht nicht der Fall sein und man müsste dies per Software emulieren oder komplett weglassen, was sich natürlich auf Performance und Aufbau des OS auswirkt.
Sachen, die man beim Design berücksichtigen sollte.

Ich hoffe, ich habe meine Frage klar formuliert und hoffe auf baldige Antworten.

Mit freundlichen Grüßen

    Michael Beuse
Seiten: [1]

Einloggen