Jeg har for nylig sluppet af med den irriterende fejl, at min processor genstarter sig selv, da den prøvede at skifte til protected-mode i Assembly.
MEN, min lykke var kort, for da jeg skulle videre med at udføre et hop til en hukommelses-adresse, hvor min C kode til min kerne er blevet loadet ind, crasher CPU'en. IGEN
.
Jeg bruger Bochs's virtuelle maskine og får følgende fejl besked når jeg kører følgende kode:
00000000000i[ ] Bochs x86 Emulator 2.4.2
00000000000i[ ] Build from CVS snapshot on November 12, 2009
00000000000i[ ] System configuration
00000000000i[ ] processors: 1 (cores=1, HT threads=1)
00000000000i[ ] A20 line support: yes
00000000000i[ ] CPU configuration
00000000000i[ ] level: 6
00000000000i[ ] SMP support: no
00000000000i[ ] APIC support: yes
00000000000i[ ] FPU support: yes
00000000000i[ ] MMX support: yes
00000000000i[ ] SSE support: 2
00000000000i[ ] CLFLUSH support: yes
00000000000i[ ] 3dnow! support: no
00000000000i[ ] 1G paging support: no
00000000000i[ ] x86-64 support: yes
00000000000i[ ] SEP support: yes
00000000000i[ ] MWAIT support: no
00000000000i[ ] XSAVE support: no
00000000000i[ ] AES support: no
00000000000i[ ] VMX support: no
00000000000i[ ] Optimization configuration
00000000000i[ ] RepeatSpeedups support: yes
00000000000i[ ] Trace cache support: yes
00000000000i[ ] Fast function calls: yes
00000000000i[ ] Devices configuration
00000000000i[ ] ACPI support: yes
00000000000i[ ] NE2000 support: yes
00000000000i[ ] PCI support: yes, enabled=yes
00000000000i[ ] SB16 support: yes
00000000000i[ ] USB support: yes
00000000000i[ ] VGA extension support: vbe cirrus
00000000000i[MEM0 ] allocated memory at 03DE0020. after alignment, vector=03DE1000
00000000000i[MEM0 ] 32,00MB
00000000000i[MEM0 ] mem block size = 0x00100000, blocks=32
00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('C:\Users\Benjamin\Desktop\Languages\Assembly\Downloads\Bochs-2.4.2/BIOS-bochs-latest')
00000000000i[MEM0 ] rom at 0xc0000/40448 ('C:\Users\Benjamin\Desktop\Languages\Assembly\Downloads\Bochs-2.4.2/VGABIOS-lgpl-latest')
00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Mon Mar 15 15:27:14 2010 (time0=1268663234)
00000000000i[DMA ] channel 4 used by cascade
00000000000i[DMA ] channel 2 used by Floppy Drive
00000000000i[FDD ] fd0: 'os.img' ro=0, h=2,t=80,spt=18
00000000000i[PCI ] 440FX Host bridge present at device 0, function 0
00000000000i[PCI ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[MEM0 ] Register memory access handlers: 0x000a0000 - 0x000bffff
00000000000i[WGUI ] Desktop Window dimensions: 1280 x 1024
00000000000i[WGUI ] Number of Mouse Buttons = 5
00000000000i[WGUI ] IME disabled
00000000000i[MEM0 ] Register memory access handlers: 0xe0000000 - 0xe0ffffff
00000000000i[CLVGA] VBE Bochs Display Extension Enabled
00000000000i[CLVGA] interval=50000
00000000000i[ ] init_dev of 'unmapped' plugin device by virtual method
00000000000i[ ] init_dev of 'biosdev' plugin device by virtual method
00000000000i[ ] init_dev of 'speaker' plugin device by virtual method
00000000000i[ ] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[ ] init_dev of 'gameport' plugin device by virtual method
00000000000i[ ] init_dev of 'pci_ide' plugin device by virtual method
00000000000i[PCI ] PIIX3 PCI IDE controller present at device 1, function 1
00000000000i[ ] init_dev of 'acpi' plugin device by virtual method
00000000000i[PCI ] ACPI Controller present at device 1, function 3
00000000000i[ ] init_dev of 'ioapic' plugin device by virtual method
00000000000i[IOAP ] initializing I/O APIC
00000000000i[MEM0 ] Register memory access handlers: 0xfec00000 - 0xfec00fff
00000000000i[ ] init_dev of 'keyboard' plugin device by virtual method
00000000000i[KBD ] will paste characters every 1000 keyboard ticks
00000000000i[ ] init_dev of 'harddrv' plugin device by virtual method
00000000000i[HD ] Using boot sequence floppy, none, none
00000000000i[HD ] Floppy boot signature check is enabled
00000000000i[ ] init_dev of 'serial' plugin device by virtual method
00000000000i[SER ] com1 at 0x03f8 irq 4
00000000000i[ ] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR ] parallel port 1 at 0x0378 irq 7
00000000000i[ ] register state of 'unmapped' plugin device by virtual method
00000000000i[ ] register state of 'biosdev' plugin device by virtual method
00000000000i[ ] register state of 'speaker' plugin device by virtual method
00000000000i[ ] register state of 'extfpuirq' plugin device by virtual method
00000000000i[ ] register state of 'gameport' plugin device by virtual method
00000000000i[ ] register state of 'pci_ide' plugin device by virtual method
00000000000i[ ] register state of 'acpi' plugin device by virtual method
00000000000i[ ] register state of 'ioapic' plugin device by virtual method
00000000000i[ ] register state of 'keyboard' plugin device by virtual method
00000000000i[ ] register state of 'harddrv' plugin device by virtual method
00000000000i[ ] register state of 'serial' plugin device by virtual method
00000000000i[ ] register state of 'parallel' plugin device by virtual method
00000000000i[SYS ] bx_pc_system_c::Reset(HARDWARE) called
00000000000i[CPU0 ] cpu hardware reset
00000000000i[APIC0] allocate APIC id=0 (MMIO enabled) to 0xfee00000
00000000000i[ ] reset of 'unmapped' plugin device by virtual method
00000000000i[ ] reset of 'biosdev' plugin device by virtual method
00000000000i[ ] reset of 'speaker' plugin device by virtual method
00000000000i[ ] reset of 'extfpuirq' plugin device by virtual method
00000000000i[ ] reset of 'gameport' plugin device by virtual method
00000000000i[ ] reset of 'pci_ide' plugin device by virtual method
00000000000i[ ] reset of 'acpi' plugin device by virtual method
00000000000i[ ] reset of 'ioapic' plugin device by virtual method
00000000000i[ ] reset of 'keyboard' plugin device by virtual method
00000000000i[ ] reset of 'harddrv' plugin device by virtual method
00000000000i[ ] reset of 'serial' plugin device by virtual method
00000000000i[ ] reset of 'parallel' plugin device by virtual method
00000003305i[BIOS ] $Revision: 1.235 $ $Date: 2009/09/28 16:36:02 $
00000200000i[WGUI ] dimension update x=720 y=400 fontheight=16 fontwidth=9 bpp=8
00000318060i[KBD ] reset-disable command received
00000444780i[VBIOS] VGABios $Id: vgabios.c,v 1.69 2009/04/07 18:18:20 vruppert Exp $
00000444851i[CLVGA] VBE known Display Interface b0c0
00000444883i[CLVGA] VBE known Display Interface b0c5
00000447808i[VBIOS] VBE Bios $Id: vbe.c,v 1.62 2009/01/25 15:46:25 vruppert Exp $
00000754369i[BIOS ] Starting rombios32
00000754866i[BIOS ] Shutdown flag 0
00000755547i[BIOS ] ram_size=0x02000000
00000756025i[BIOS ] ram_end=32MB
00000796633i[BIOS ] Found 1 cpu(s)
00000815758i[BIOS ] bios_table_addr: 0x000fba98 end=0x000fcc00
00000815866i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
00001143563i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
00001471491i[P2I ] PCI IRQ routing: PIRQA# set to 0x0b
00001471512i[P2I ] PCI IRQ routing: PIRQB# set to 0x09
00001471533i[P2I ] PCI IRQ routing: PIRQC# set to 0x0b
00001471554i[P2I ] PCI IRQ routing: PIRQD# set to 0x09
00001471564i[P2I ] write: ELCR2 = 0x0a
00001472449i[BIOS ] PIIX3/PIIX4 init: elcr=00 0a
00001480407i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237 class=0x0600
00001482969i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000 class=0x0601
00001485370i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010 class=0x0101
00001485600i[PIDE ] new BM-DMA address: 0xc000
00001486304i[BIOS ] region 4: 0x0000c000
00001488614i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113 class=0x0680
00001488852i[ACPI ] new irq line = 11
00001488866i[ACPI ] new irq line = 9
00001488896i[ACPI ] new PM base address: 0xb000
00001488910i[ACPI ] new SM base address: 0xb100
00001488938i[PCI ] setting SMRAM control register to 0x4a
00001653032i[CPU0 ] Enter to System Management Mode
00001653042i[CPU0 ] RSM: Resuming from System Management Mode
00001817062i[PCI ] setting SMRAM control register to 0x0a
00001826231i[BIOS ] MP table addr=0x000fbb70 MPC table addr=0x000fbaa0 size=0xd0
00001828173i[BIOS ] SMBIOS table addr=0x000fbb80
00001830557i[BIOS ] ACPI tables: RSDP addr=0x000fbc90 ACPI DATA addr=0x01ff0000 size=0x988
00001833796i[BIOS ] Firmware waking vector 0x1ff00cc
00001844909i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
00001845753i[BIOS ] bios_table_cur_addr: 0x000fbcb4
00014041523i[BIOS ] Booting from 0000:7c00
00014220082e[CPU0 ] write_virtual_checks(): no write access to seg
00014220082e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
00014220082e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
00014220082i[CPU0 ] CPU is in protected mode (active)
00014220082i[CPU0 ] CS.d_b = 32 bit
00014220082i[CPU0 ] SS.d_b = 32 bit
00014220082i[CPU0 ] EFER = 0x00000000
00014220082i[CPU0 ] | RAX=0000000000000000 RBX=0000000000000000
00014220082i[CPU0 ] | RCX=0000000000000000 RDX=0000000000000000
00014220082i[CPU0 ] | RSP=0000000000090020 RBP=0000000000000000
00014220082i[CPU0 ] | RSI=0000000000000000 RDI=0000000000000000
00014220082i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
00014220082i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
00014220082i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
00014220082i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
00014220082i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf ZF af PF cf
00014220082i[CPU0 ] | SEG selector base limit G D
00014220082i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00014220082i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
00014220082i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00014220082i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00014220082i[CPU0 ] | ES:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00014220082i[CPU0 ] | FS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00014220082i[CPU0 ] | GS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00014220082i[CPU0 ] | MSR_FS_BASE:0000000000000000
00014220082i[CPU0 ] | MSR_GS_BASE:0000000000000000
00014220082i[CPU0 ] | RIP=000000000000100c (000000000000100c)
00014220082i[CPU0 ] | CR0=0x60000011 CR2=0x0000000000000000
00014220082i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00014220082i[CPU0 ] 0x000000000000100c>> add byte ptr cs:[eax], al : 65642E2E0000
00014220082e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
00014220082i[SYS ] bx_pc_system_c::Reset(HARDWARE) called
00014220082i[CPU0 ] cpu hardware reset
00014220082i[APIC0] allocate APIC id=0 (MMIO enabled) to 0xfee00000
00014220082i[ ] reset of 'unmapped' plugin device by virtual method
00014220082i[ ] reset of 'biosdev' plugin device by virtual method
00014220082i[ ] reset of 'speaker' plugin device by virtual method
00014220082i[ ] reset of 'extfpuirq' plugin device by virtual method
00014220082i[ ] reset of 'gameport' plugin device by virtual method
00014220082i[ ] reset of 'pci_ide' plugin device by virtual method
00014220082i[ ] reset of 'acpi' plugin device by virtual method
00014220082i[ ] reset of 'ioapic' plugin device by virtual method
00014220082i[ ] reset of 'keyboard' plugin device by virtual method
00014220082i[ ] reset of 'harddrv' plugin device by virtual method
00014220082i[ ] reset of 'serial' plugin device by virtual method
00014220082i[ ] reset of 'parallel' plugin device by virtual method
00014223388i[BIOS ] $Revision: 1.235 $ $Date: 2009/09/28 16:36:02 $
00014538067i[KBD ] reset-disable command received
00014664787i[VBIOS]
VGABios $Id: vgabios.c,v 1.69 2009/04/07 18:18:20 vruppert Exp $
00014664858i[CLVGA] VBE known Display Interface b0c0
00014664890i[CLVGA] VBE known Display Interface b0c5
00014667815i[VBIOS] VBE Bios $Id: vbe.c,v 1.62 2009/01/25 15:46:25 vruppert Exp $
00014974376i[BIOS ] Starting rombios32
00014974873i[BIOS ] Shutdown flag 0
00014975554i[BIOS ] ram_size=0x02000000
00014976032i[BIOS ] ram_end=32MB
00015016628i[BIOS ] Found 1 cpu(s)
00015035753i[BIOS ] bios_table_addr: 0x000fba98 end=0x000fcc00
00015035861i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
00015363558i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
00015691486i[P2I ] PCI IRQ routing: PIRQA# set to 0x0b
00015691507i[P2I ] PCI IRQ routing: PIRQB# set to 0x09
00015691528i[P2I ] PCI IRQ routing: PIRQC# set to 0x0b
00015691549i[P2I ] PCI IRQ routing: PIRQD# set to 0x09
00015691559i[P2I ] write: ELCR2 = 0x0a
00015692444i[BIOS ] PIIX3/PIIX4 init: elcr=00 0a
00015700402i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237 class=0x0600
00015702964i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000 class=0x0601
00015705365i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010 class=0x0101
00015706299i[BIOS ] region 4: 0x0000c000
00015708609i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113 class=0x0680
00015708847i[ACPI ] new irq line = 11
00015708861i[ACPI ] new irq line = 9
00015708933i[PCI ] setting SMRAM control register to 0x4a
00015873027i[CPU0 ] Enter to System Management Mode
00015873037i[CPU0 ] RSM: Resuming from System Management Mode
00016037057i[PCI ] setting SMRAM control register to 0x0a
00016046226i[BIOS ] MP table addr=0x000fbb70 MPC table addr=0x000fbaa0 size=0xd0
00016048168i[BIOS ] SMBIOS table addr=0x000fbb80
00016050552i[BIOS ] ACPI tables: RSDP addr=0x000fbc90 ACPI DATA addr=0x01ff0000 size=0x988
00016053791i[BIOS ] Firmware waking vector 0x1ff00cc
00016064904i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
00016065748i[BIOS ] bios_table_cur_addr: 0x000fbcb4
Dette er Assembly koden:
[bits 16]
[org 0x7c00]
booter:
mov ax, 0x0000
mov ds, ax
call clearScreen
mov bp, bootingSystem
mov dh, 0x0000
mov dl, 0x0000
call output
mov bp, resetting
mov dh, 0x0001
mov dl, 0x0000
call output
call reset
mov bp, switching
mov dh, 0x0003
mov dl, 0x0000
call output
call switch
reset:
mov ah, 0x0000
int 0x0013
or ah, ah
jnz reset
mov ax, 0x0000
mov es, ax
mov bx, 0x1000
mov ah, 0x0002
mov al, 0x0002
mov ch, 0x0000
mov cl, 0x0002
mov dh, 0x0000
int 0x0013
or ah, ah
jnz reset
mov bp, drivesReset
mov dh, 0x0002
mov dl, 0x0000
call output
ret
clearScreen:
mov ax, 0x0600
mov cx, 0x0000
mov dx, 0x174f
mov bh, 0x0007
int 0x0010
ret
output:
mov ah, 0x0013
mov al, 0x0000
mov bx, 0x0007
mov cx, 0x001d
int 0x0010
ret
enableA20:
in al, 0x0092
or al, 0x0002
out 0x0092, al
ret
switch:
call enableA20
cli
xor ax, ax
mov ds, ax
lgdt[gdtDesc]
mov eax, cr0
or eax, 0x0001
mov cr0, eax
jmp 0x0008:protectedMode
[bits 32]
protectedMode:
mov ax, 0x0010
mov ds, ax
mov ss, ax
mov esp, 0x090000
jmp 0x0008:0x01000
gdt:
gdtNull:
dd 0
dd 0
gdtCode:
dw 0x0ffff
dw 0
db 0
db 10011010b
db 11001111b
db 0
gdtData:
dw 0x0ffff
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdtEnd:
gdtDesc:
dw gdtEnd - gdt - 1
dd gdt
bootingSystem db "Booting process started.. ", 0
resetting db "Resetting drives.. ", 0
drivesReset db "Drives reset.. ", 0
switching db "Switching to protected mode..", 0
times 510 - ($ - $$) db 0
dw 0xaa55
Dette er main.c:
const char* kernel;
void main(){
clearScreen();
print(kernel);
for(;;);
}
const char* kernel = "Kernel started..";
video.c:
void clearScreen(){
unsigned char *videoMemory = (unsigned char *)0xb8000;
const long size = 80 * 25;
long i;
for(i = 0; i < size; i++){
*videoMemory++ = 0;
*videoMemory++ = 0xf;
}
out(0x3d4, 14);
out(0x3d5, 0);
out(0x3d4, 15);
out(0x3d5, 0);
}
void print(const char* message){
unsigned short offset;
unsigned long i;
unsigned char *videoMemory = (unsigned char *)0xb8000;
out(0x3d4, 14);
offset = in(0x3d5) << 8;
out(0x3d4, 15);
offset |= in(0x3d5);
videoMemory += offset * 2;
i = 0;
while(message[i] != 0){
*videoMemory = message[i++];
videoMemory += 2;
}
offset += i;
out(0x3d5, (unsigned char)(offset));
out(0x3d4, 14);
out(0x3d5, (unsigned char)(offset >> 8));
}
ports.c:
unsigned char in(unsigned short port){
unsigned char result;
__asm__("in %%dx, %%al" : "=a" (result) : "d" (port));
return result;
}
void out(unsigned short port, unsigned char data){
__asm__("out %%al, %%dx" : :"a" (data), "d" (port));
}
Dette er kommandoerne jeg bruger til at compile:
nasm -f bin bootloader.asm -o bootloader.bin
gcc -ffreestanding -c main.c -o main.o
gcc -c video.c -o video.o
gcc -c ports.c -o ports.o
ld -e _main -Ttext 0x1000 -o kernel.o main.o video.o ports.o
ld -i -e _main -Ttext 0x1000 -o kernel.o main.o video.o ports.o
objcopy -R .note -R .comment -S -O binary kernel.o kernel.bin
makeboot os.img bootloader.bin kernel.bin
Og dette er outputtet, der kommer frem når jeg kører denne *.cmd fil:
main.c:9:41: warning: no newline at end of file
video.c:42:2: warning: no newline at end of file
ports.c:11:2: warning: no newline at end of file
main.o:main.c:(.text+0x21): undefined reference to `_alloca'
main.o:main.c:(.text+0x26): undefined reference to `__main'
1 sectors, 512 bytes read from file bootloader.bin...
9 sectors, 4604 bytes read from file kernel.bin...
Press any key to continue . . .
Og det var vidst det hele
.
Jeg ved godt at der er meget kode og meget tekst men jeg ville stadig sætte STOR pris på hjælp
.