rename
This commit is contained in:
9
boot/Makefile
Executable file
9
boot/Makefile
Executable file
@ -0,0 +1,9 @@
|
||||
# $Id: Makefile 956 2008-10-19 22:24:23Z hsc $
|
||||
|
||||
all: bootsect setup
|
||||
|
||||
% : %.asm
|
||||
nasm -f bin $<
|
||||
|
||||
clean:
|
||||
rm -f *~ bootsect setup
|
BIN
boot/bootsect
Executable file
BIN
boot/bootsect
Executable file
Binary file not shown.
324
boot/bootsect.asm
Executable file
324
boot/bootsect.asm
Executable file
@ -0,0 +1,324 @@
|
||||
; $Id: bootsect.asm 5001 2012-10-12 11:34:05Z os $
|
||||
|
||||
;******************************************************************************
|
||||
;* Betriebssysteme *
|
||||
;*----------------------------------------------------------------------------*
|
||||
;* *
|
||||
;* B O O T S E C T *
|
||||
;* *
|
||||
;*----------------------------------------------------------------------------*
|
||||
;* Code fuer den Disketten-Bootblock des System-Images. Das BIOS laedt den *
|
||||
;* ersten Block einer Diskette (den Bootblock) beim Starten des Rechner in *
|
||||
;* den Hauptspeicher und fuehrt ihn aus. Der Programmcode des Bootblocks *
|
||||
;* laedt nun das restliche System und fuehrt es aus. *
|
||||
;******************************************************************************
|
||||
|
||||
;
|
||||
; Konstanten
|
||||
;
|
||||
BIOSSEG equ 0x07c0 ; Hierher wird der Bootsector
|
||||
; vom BIOS geladen
|
||||
BOOTSEG equ 0x0060 ; Hierher verschiebt sich der
|
||||
; Boot-Code
|
||||
SETUPSEG equ 0x9000 ; Hierher laedt der Boot-Code den
|
||||
; Setup-Code (max. 64K inkl. Stack)
|
||||
SYSTEMSEG equ 0x1000 ; System-Code (max. 512K)
|
||||
SECTORSZ equ 512 ; Groesse eines Sektors in Bytes
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
;
|
||||
; Boot-Code
|
||||
;
|
||||
bootsector:
|
||||
jmp skip_data
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
;
|
||||
; Datenbereich, der von 'build' beim Erzeugen der Boot-Diskette
|
||||
; gefuellt wird.
|
||||
;
|
||||
pad:
|
||||
times 4+bootsector-$ db 0 ; Bytes zum Auffuellen, damit 'total_tracks' an einer
|
||||
; geraden und tools/build.c bekannten Adresse liegt
|
||||
total_tracks:
|
||||
dw 0 ; Anzahl der Tracks der Diskette
|
||||
total_heads:
|
||||
dw 0 ; Anzahl der Seiten der Diskette
|
||||
total_sectors:
|
||||
dw 0 ; Anzahl der Sektoren pro Track
|
||||
setup_sectors:
|
||||
dw 0 ; Anzahl der Sektoren, die der Setup-Code einnimmt
|
||||
system_sectors:
|
||||
dw 0 ; Anzahl der Sektoren, die das System einnimmt
|
||||
bootdevice:
|
||||
db 0 ; BIOS Geraetecode: 00: Disk A, 01: Disk B, ..., 0x80 HD0, ...
|
||||
curr_track:
|
||||
db 0 ; Track, bei dem die Diskette/Partition beginnt
|
||||
curr_head:
|
||||
db 0 ; Head, bei dem die Diskette/Partition beginnt
|
||||
curr_sector:
|
||||
db 0 ; Sector, bei dem die Diskette/Partition beginnt
|
||||
|
||||
;-----------------------------------------------------------------------
|
||||
|
||||
;
|
||||
; Kopieren des Bootsectors
|
||||
;
|
||||
skip_data:
|
||||
mov bl,dl ; vom BIOS uebergebenes Boot-Device sichern
|
||||
|
||||
mov ax,BIOSSEG
|
||||
mov ds,ax
|
||||
xor si,si
|
||||
mov ax,BOOTSEG
|
||||
mov es,ax
|
||||
xor di,di
|
||||
mov cx,SECTORSZ/2
|
||||
rep movsw
|
||||
;
|
||||
; Ausfuehrung durch die Kopie fortsetzen
|
||||
;
|
||||
jmp BOOTSEG:start
|
||||
;
|
||||
; Segmentregister initialisieren und Platz fuer den Stack schaffen
|
||||
;
|
||||
start:
|
||||
mov ax,cs ; Daten-, Stack- und Codesegment sollen
|
||||
mov ds,ax ; hierher zeigen.
|
||||
mov ss,ax
|
||||
mov sp,4*SECTORSZ ; Drei Sektoren als Stack freilassen
|
||||
|
||||
mov [bootdevice],bl ; zuvor gesichertes Boot-Device permanent ablegen
|
||||
|
||||
;
|
||||
; Ausgabe einer Meldung mit Hilfe eines BIOS-Aufrufs
|
||||
;
|
||||
mov ah,0x03 ; Feststellen der Cursor-Position
|
||||
xor bh,bh
|
||||
int 0x10
|
||||
|
||||
mov cx,13
|
||||
mov bx,0x0007 ; page 0, attribute 7 (normal)
|
||||
mov ax,ds
|
||||
mov es,ax
|
||||
mov bp,bootmessage
|
||||
mov ax,0x1301 ; Ausgabe des Textes, Cursor bewegen
|
||||
int 0x10
|
||||
;
|
||||
; Nachladen des Setup-Codes und des Systems selbst.
|
||||
;
|
||||
xor ah,ah ; Reset des Disketten-/Plattencontrollers
|
||||
mov dl,[bootdevice]
|
||||
int 0x13
|
||||
;
|
||||
; Informationen ueber die Laufwerksgeometrie holen
|
||||
;
|
||||
hdd_probe:
|
||||
mov dl,[bootdevice]
|
||||
test dl,0x80
|
||||
jz load_setup ; Floppy mit den Standardparametern laden
|
||||
mov ah,0x8
|
||||
int 0x13
|
||||
jc load_setup ; CF bei Fehler gesetzt
|
||||
mov [total_heads],dh
|
||||
mov ax,cx ; CX sichern
|
||||
and ax,0x3f
|
||||
mov [total_sectors],ax
|
||||
mov ax,cx
|
||||
shr ax,6
|
||||
mov [total_tracks],ax
|
||||
|
||||
;
|
||||
; Weiterstellen der Disketten-/Plattenposition um 1 (Bootblock)
|
||||
;
|
||||
load_setup:
|
||||
call step_disk
|
||||
|
||||
;
|
||||
; Laden des Setup-Codes
|
||||
;
|
||||
mov word [curr_segment],SETUPSEG
|
||||
mov word [curr_offset],0
|
||||
mov ax,[setup_sectors]
|
||||
call load
|
||||
;
|
||||
; Laden des Kernels
|
||||
;
|
||||
mov word [curr_segment],SYSTEMSEG
|
||||
mov word [curr_offset],0
|
||||
mov ax,[system_sectors]
|
||||
call load
|
||||
;
|
||||
; Floppy wieder abschalten
|
||||
;
|
||||
call stop_floppy_motor
|
||||
;
|
||||
; Start des Setup-Codes
|
||||
;
|
||||
mov ax, [system_sectors] ; Speichere Anzahl an System-Sektoren in AX.
|
||||
jmp SETUPSEG:0
|
||||
|
||||
;
|
||||
; load
|
||||
;
|
||||
; Die 'ax' Sektoren von der Diskette in den Hauptspeicher. Die Position auf
|
||||
; der Diskette muss vorher in curr_head/curr_track/curr_sector und die
|
||||
; Position im Hauptspeicher in curr_segment/curr_offset stehen. Die Positionen
|
||||
; werden entsprechend der geladenen Sektoren weitergestellt.
|
||||
;
|
||||
load:
|
||||
mov [to_load],ax
|
||||
l_next_part:
|
||||
mov al,[curr_head]
|
||||
mov [last_head],al
|
||||
mov al,[curr_track]
|
||||
mov [last_track],al
|
||||
mov al,[curr_sector]
|
||||
mov [last_sector],al
|
||||
mov ax,[curr_segment]
|
||||
mov [last_segment],ax
|
||||
mov ax,[curr_offset]
|
||||
mov [last_offset],ax
|
||||
|
||||
mov al,0
|
||||
|
||||
l_loop: call step
|
||||
|
||||
cmp byte [curr_sector],0x01
|
||||
je l_now
|
||||
cmp word [curr_offset],0x0000
|
||||
je l_now
|
||||
cmp al,[to_load]
|
||||
jne l_loop
|
||||
|
||||
l_now:
|
||||
push ax
|
||||
mov dl,[bootdevice]
|
||||
mov dh,[last_head]
|
||||
mov ch,[last_track]
|
||||
mov cl,[last_sector]
|
||||
mov bx,[last_segment]
|
||||
mov es,bx
|
||||
mov bx,[last_offset]
|
||||
mov ah,0x02 ; Funktionscode fuer 'Lesen'
|
||||
int 0x13
|
||||
pop ax
|
||||
|
||||
push ax
|
||||
call print_dot
|
||||
pop ax
|
||||
|
||||
mov ah,0
|
||||
sub [to_load],ax
|
||||
jne l_next_part
|
||||
ret
|
||||
|
||||
;
|
||||
; step
|
||||
;
|
||||
; Stellt die aktuelle Position im Hauptspeicher und auf der Diskette
|
||||
; um einen Sektor (512 Byte) weiter.
|
||||
;
|
||||
step: add al,1
|
||||
call step_disk
|
||||
call step_memory
|
||||
ret
|
||||
|
||||
step_disk:
|
||||
mov bl,[curr_sector]
|
||||
add bl,1
|
||||
mov [curr_sector],bl
|
||||
cmp bl,[total_sectors]
|
||||
jle l_1
|
||||
mov byte [curr_sector],1
|
||||
|
||||
mov bl,[curr_head]
|
||||
add bl,1
|
||||
mov [curr_head],bl
|
||||
cmp bl,[total_heads]
|
||||
jne l_1
|
||||
mov byte [curr_head],0
|
||||
|
||||
mov bl,[curr_track]
|
||||
add bl,1
|
||||
mov [curr_track],bl
|
||||
|
||||
l_1: ret
|
||||
|
||||
step_memory:
|
||||
mov bx,[curr_offset]
|
||||
add bx,SECTORSZ
|
||||
mov [curr_offset],bx
|
||||
test bx,0xffff
|
||||
jne l_2
|
||||
mov bx,[curr_segment]
|
||||
add bx,0x1000 ; 64 KByte weiterstellen
|
||||
mov [curr_segment],bx
|
||||
|
||||
l_2 ret
|
||||
|
||||
;
|
||||
; Ausgabe eines Stern ('*') mit Hilfe eines BIOS-Aufrufs
|
||||
;
|
||||
print_dot:
|
||||
mov ah,0x03 ; Feststellen der Cursor-Position
|
||||
xor bh,bh
|
||||
int 0x10
|
||||
|
||||
mov cx,1
|
||||
mov bx,0x0007 ; page 0, attribute 7 (normal)
|
||||
mov ax,ds
|
||||
mov es,ax
|
||||
mov bp,dot
|
||||
mov ax,0x1301 ; Ausgabe des Textes, Cursor bewegen
|
||||
int 0x10
|
||||
|
||||
ret
|
||||
|
||||
;
|
||||
; stop_floppy_motor
|
||||
;
|
||||
; Stopt den Motor der Floppy, da das BIOS dazu in Kuerze nicht mehr in
|
||||
; der Lage sein wird. Egal, ob von Floppy oder Platte gebootet wurde.
|
||||
;
|
||||
stop_floppy_motor:
|
||||
mov dx,0x3f2
|
||||
xor al,al
|
||||
out dx,al
|
||||
ret
|
||||
|
||||
;
|
||||
; Datenbereich
|
||||
;
|
||||
|
||||
bootmessage:
|
||||
db 13,10
|
||||
db 'booting ... '
|
||||
|
||||
dot:
|
||||
db '*'
|
||||
|
||||
to_load:
|
||||
dw 0
|
||||
curr_segment:
|
||||
dw 0
|
||||
curr_offset:
|
||||
dw 0
|
||||
|
||||
last_head:
|
||||
db 0
|
||||
last_track:
|
||||
db 0
|
||||
last_sector:
|
||||
db 0
|
||||
last_segment:
|
||||
dw 0
|
||||
last_offset:
|
||||
dw 0
|
||||
|
||||
unused:
|
||||
times bootsector+510-$ db 0
|
||||
|
||||
mark:
|
||||
dw 0xaa55
|
BIN
boot/setup
Executable file
BIN
boot/setup
Executable file
Binary file not shown.
195
boot/setup.asm
Executable file
195
boot/setup.asm
Executable file
@ -0,0 +1,195 @@
|
||||
; $Id: setup.asm 1484 2009-02-11 21:03:19Z hsc $
|
||||
|
||||
;******************************************************************************
|
||||
;* Betriebssysteme *
|
||||
;*----------------------------------------------------------------------------*
|
||||
;* *
|
||||
;* S E T U P *
|
||||
;* *
|
||||
;*----------------------------------------------------------------------------*
|
||||
;* Der Setup-Code liegt im System-Image direkt hinter dem Bootsektor und wird *
|
||||
;* von diesem direkt nach dem Laden aktiviert. Der Code wird noch im *
|
||||
;* 'Real-Mode' gestartet, so dass zu Beginn auch noch BIOS-Aufrufe erlaubt *
|
||||
;* sind. Dann werden jedoch alle Interrupts verboten, die Adressleitung A20 *
|
||||
;* aktiviert und die Umschaltung in den 'Protected-Mode' vorgenommen. Alles *
|
||||
;* weitere uebernimmt der Startup-Code des Systems. *
|
||||
;******************************************************************************
|
||||
|
||||
;
|
||||
; Konstanten
|
||||
;
|
||||
SETUPSEG equ 0x9000 ; Setup-Code (max. 64K inkl. Stack)
|
||||
SYSTEMSEG equ 0x1000 ; System-Code (max. 512K)
|
||||
SECTORSZ equ 512 ; Groesse eines Sektors in Bytes
|
||||
SYSTEMSTART equ 0x100000 ; Hierhin wird das System nach Umschalten in den
|
||||
; Protected Mode kopiert, da GRUB das auch tut
|
||||
; (und GRUB kann nur an Adressen >1M laden).
|
||||
|
||||
[SECTION .text]
|
||||
[BITS 16]
|
||||
;
|
||||
; Segmentregister initialisieren
|
||||
;
|
||||
start:
|
||||
mov dx, ax ; Anzahl Systemsektoren in DX sichern.
|
||||
|
||||
mov ax,cs ; Daten-, Code- und Stacksegment sollen
|
||||
mov ds,ax ; hierher zeigen.
|
||||
mov ss,ax ; Alle drei Segment duerfen nicht mehr
|
||||
mov sp,0xfffe ; als 64 KByte einnehmen (zusammen).
|
||||
|
||||
mov [system_sectors], dx ; Anzahl der Systemsektoren im Speicher ablegen
|
||||
|
||||
;
|
||||
; Ausgabe einer Meldung mit Hilfe eines BIOS-Aufrufs
|
||||
;
|
||||
mov ah,0x03 ; Feststellen der Cursor-Position
|
||||
xor bh,bh
|
||||
int 0x10
|
||||
|
||||
mov cx,14
|
||||
mov bx,0x0007 ; page 0, attribute 7 (normal)
|
||||
mov ax,ds
|
||||
mov es,ax
|
||||
mov bp,setupmessage
|
||||
mov ax,0x1301 ; Ausgabe des Textes, Cursor bewegen
|
||||
int 0x10
|
||||
;
|
||||
; So, jetzt werden die Interrupts abgeschaltet
|
||||
;
|
||||
cli ; Maskierbare Interrupts verbieten
|
||||
mov al,0x80 ; NMI verbieten
|
||||
out 0x70,al
|
||||
;
|
||||
; IDT und GDT setzen
|
||||
;
|
||||
lidt [idt_48]
|
||||
lgdt [gdt_48]
|
||||
;
|
||||
; Aktivieren der Adressleitung A20
|
||||
;
|
||||
call empty_8042
|
||||
mov al,0xd1
|
||||
out 0x64,al
|
||||
call empty_8042
|
||||
mov al,0xdf
|
||||
out 0x60,al
|
||||
call empty_8042
|
||||
mov al,0xff
|
||||
out 0x64,al
|
||||
call empty_8042
|
||||
;
|
||||
; Moeglichen Koprozessor zuruecksetzen
|
||||
;
|
||||
xor ax,ax
|
||||
out 0xf0,al
|
||||
call delay
|
||||
out 0xf1,al
|
||||
call delay
|
||||
;
|
||||
; Umschalten in den Protected Mode
|
||||
;
|
||||
mov eax,cr0 ; Setze PM-Bit im Kontrollregister 1
|
||||
or eax,1
|
||||
mov cr0,eax
|
||||
|
||||
jmp dword 0x08:SETUPSEG*0x10+copy_system ; Far-Jump, um
|
||||
; a) fetch Pipeline zu leeren
|
||||
; b) CS Register sinnvoll zu belegen
|
||||
[BITS 32]
|
||||
; Arbeite jetzt im Protected Mode
|
||||
copy_system:
|
||||
;
|
||||
; Systemcode von 0x10000 nach 0x100000 kopieren.
|
||||
;
|
||||
|
||||
mov ax, 0x10 ; 0x10 entspricht dem Data-Eintrag in der GDT.
|
||||
mov ds, ax ; DS und ES werden von movsd benoetigt.
|
||||
mov es, ax
|
||||
|
||||
xor ecx, ecx ; Anzahl Systemsektoren laden
|
||||
mov cx, [SETUPSEG*0x10+system_sectors]
|
||||
|
||||
imul ecx, SECTORSZ/4
|
||||
|
||||
mov esi, SYSTEMSEG*0x10 ; Hier liegt der Systemcode noch ...
|
||||
mov edi, SYSTEMSTART ; ... und hierhin moechten wir ihn verschieben
|
||||
|
||||
cld ; Nach jedem movsb ESI,EDI inkrementieren
|
||||
rep movsd ; Kopiere 4 Byte von [ESI] nach [EDI] ecx male
|
||||
|
||||
|
||||
;
|
||||
; Sprung in den Startup-Code des Systems
|
||||
;
|
||||
|
||||
jmp dword 0x08:SYSTEMSTART
|
||||
|
||||
error:
|
||||
hlt
|
||||
[BITS 16]
|
||||
; Ab hier wieder Real-Mode Code fuer die Codeteile
|
||||
; vor der Umschaltung in den Protected Mode
|
||||
|
||||
;
|
||||
; empty_8042
|
||||
;
|
||||
; Ein- und Ausgabepuffer des Tastaturcontrollers leeren
|
||||
;
|
||||
empty_8042:
|
||||
call delay
|
||||
in al,0x64 ; 8042 Status Port
|
||||
test al,1 ; Ausgabepuffer voll?
|
||||
jz no_output
|
||||
call delay
|
||||
in al,0x60 ; wenn ja: ueberlesen
|
||||
jmp empty_8042
|
||||
no_output:
|
||||
test al,2 ; Eingabepuffer voll?
|
||||
jnz empty_8042 ; wenn ja, noch mal testen, irgendwann
|
||||
ret ; muss es weg sein.
|
||||
;
|
||||
; delay:
|
||||
;
|
||||
; Kurze Verzoegerung fuer in/out-Befehle
|
||||
;
|
||||
delay:
|
||||
out 0x80,al
|
||||
ret
|
||||
|
||||
;
|
||||
; Datenbereich
|
||||
;
|
||||
[SECTION .data]
|
||||
|
||||
; Meldung
|
||||
|
||||
system_sectors:
|
||||
dw 0
|
||||
|
||||
setupmessage:
|
||||
db 13,10
|
||||
db 'setup active'
|
||||
;
|
||||
; Descriptor-Tabellen
|
||||
;
|
||||
gdt:
|
||||
dw 0,0,0,0 ; NULL Deskriptor
|
||||
|
||||
dw 0xFFFF ; 4Gb - (0x100000*0x1000 = 4Gb)
|
||||
dw 0x0000 ; base address=0
|
||||
dw 0x9A00 ; code read/exec
|
||||
dw 0x00CF ; granularity=4096, 386 (+5th nibble of limit)
|
||||
|
||||
dw 0xFFFF ; 4Gb - (0x100000*0x1000 = 4Gb)
|
||||
dw 0x0000 ; base address=0
|
||||
dw 0x9200 ; data read/write
|
||||
dw 0x00CF ; granularity=4096, 386 (+5th nibble of limit)
|
||||
|
||||
idt_48:
|
||||
dw 0 ; idt limit=0
|
||||
dw 0,0 ; idt base=0L
|
||||
|
||||
gdt_48:
|
||||
dw 0x18 ; GDT Limit=24, 3 GDT Eintraege
|
||||
dd SETUPSEG*0x10+gdt; Physikalische Adresse der GDT
|
Reference in New Issue
Block a user