Hier der Versprochene Code
pic.asm (Mein PIC ASM-Code)
init_pic:
; Master-PIC initialisieren
mov dx, 0x20
mov al, 0x11
out dx, al ; Initialisierungsbefehl fuer den PIC
mov dx, 0x21
mov al, 0x20
out dx, al ; Interruptnummer fuer IRQ 0
mov al, 0x04
out dx, al ; An IRQ 2 haengt der Slave
mov al, 0x01
out dx, al ; ICW 4
; Slave-PIC initialisieren
mov dx, 0xA0
mov al, 0x11
out dx, al ; Initialisierungsbefehl fuer den PIC
mov dx, 0xA1
mov al, 0x28
out dx, al ; Interruptnummer fuer IRQ 8
mov al, 0x02
out dx, al ; An IRQ 2 haengt der Slave
mov al, 0x01
out dx, al ; ICW 4
; Alle IRQs aktivieren (demaskieren)
mov dx, 0x20
xor eax, eax
out dx, al
mov dx, 0xA0
out dx, al
ret
pic.c (Mein PIC C-Code)
#define PORT_PIC1_COMMAND 0x0020
#define PORT_PIC1_DATA 0x0021
#define PORT_PIC2_COMMAND 0x00A0
#define PORT_PIC2_DATA 0x00A1
static inline void outb(unsigned short port, unsigned char data)
{
__asm__ volatile ("outb %0, %1" :: "a" (data), "Nd" (port));
}
void init_pic(void)
{
// Master-PIC initialisieren
outb(PORT_PIC1_COMMAND, 0x11); // Initialisierungsbefehl fuer den PIC
outb(PORT_PIC1_DATA, 0x20); // Interruptnummer fuer IRQ 0
outb(PORT_PIC1_DATA, 0x04); // An IRQ 2 haengt der Slave
outb(PORT_PIC1_DATA, 0x01); // ICW 4
// Slave-PIC initialisieren
outb(PORT_PIC2_COMMAND, 0x11); // Initialisierungsbefehl fuer den PIC
outb(PORT_PIC2_DATA, 0x28); // Interruptnummer fuer IRQ 8
outb(PORT_PIC2_DATA, 0x02); // An IRQ 2 hängt der Slave
outb(PORT_PIC2_DATA, 0x01); // ICW 4
// Alle IRQs aktivieren (demaskieren)
outb(PORT_PIC1_COMMAND, 0x0);
outb(PORT_PIC2_COMMAND, 0x0);
}
pic.s (ausgabe von gcc)
.file "pic.c"
.stabs "C:\\Dokumente und Einstellungen\\Admin\\Desktop/",100,0,2,.Ltext0
.stabs "pic.c",100,0,2,.Ltext0
.text
.Ltext0:
.stabs "gcc2_compiled.",60,0,0,0
.stabs "int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,1,0
.stabs "char:t(0,2)=r(0,2);0;127;",128,0,1,0
.stabs "long int:t(0,3)=r(0,3);-2147483648;2147483647;",128,0,1,0
.stabs "unsigned int:t(0,4)=r(0,4);0;037777777777;",128,0,1,0
.stabs "long unsigned int:t(0,5)=r(0,5);0;037777777777;",128,0,1,0
.stabs "long long int:t(0,6)=@s64;r(0,6);01000000000000000000000;0777777777777777777777;",128,0,1,0
.stabs "long long unsigned int:t(0,7)=@s64;r(0,7);0;01777777777777777777777;",128,0,1,0
.stabs "short int:t(0,8)=@s16;r(0,8);-32768;32767;",128,0,1,0
.stabs "short unsigned int:t(0,9)=@s16;r(0,9);0;65535;",128,0,1,0
.stabs "signed char:t(0,10)=@s8;r(0,10);-128;127;",128,0,1,0
.stabs "unsigned char:t(0,11)=@s8;r(0,11);0;255;",128,0,1,0
.stabs "float:t(0,12)=r(0,1);4;0;",128,0,1,0
.stabs "double:t(0,13)=r(0,1);8;0;",128,0,1,0
.stabs "long double:t(0,14)=r(0,1);12;0;",128,0,1,0
.stabs "void:t(0,15)=(0,15)",128,0,1,0
.align 16
.stabs "init_pic:F(0,15)",36,0,11,init_pic
.globl init_pic
.type init_pic, @function
init_pic:
.stabd 46,0,0
.stabn 68,0,12,.LM0-.LFBB1
.LM0:
.LFBB1:
pushl %ebp
.LBB22:
.LBB23:
.stabn 68,0,8,.LM1-.LFBB1
.LM1:
movb $17, %al
.LBE23:
.LBE22:
.stabn 68,0,12,.LM2-.LFBB1
.LM2:
movl %esp, %ebp
.LBB25:
.LBB24:
.stabn 68,0,8,.LM3-.LFBB1
.LM3:
/APP
/ 8 "pic.c" 1
outb %al, $32
/ 0 "" 2
/NO_APP
.LBE24:
.LBE25:
.LBB26:
.LBB27:
movb $32, %al
/APP
/ 8 "pic.c" 1
outb %al, $33
/ 0 "" 2
/NO_APP
.LBE27:
.LBE26:
.LBB28:
.LBB29:
movb $4, %al
/APP
/ 8 "pic.c" 1
outb %al, $33
/ 0 "" 2
/NO_APP
.LBE29:
.LBE28:
.LBB30:
.LBB31:
movb $1, %al
/APP
/ 8 "pic.c" 1
outb %al, $33
/ 0 "" 2
/NO_APP
.LBE31:
.LBE30:
.LBB32:
.LBB33:
movb $17, %al
/APP
/ 8 "pic.c" 1
outb %al, $160
/ 0 "" 2
/NO_APP
.LBE33:
.LBE32:
.LBB34:
.LBB35:
movb $40, %al
/APP
/ 8 "pic.c" 1
outb %al, $161
/ 0 "" 2
/NO_APP
.LBE35:
.LBE34:
.LBB36:
.LBB37:
movb $2, %al
/APP
/ 8 "pic.c" 1
outb %al, $161
/ 0 "" 2
/NO_APP
.LBE37:
.LBE36:
.LBB38:
.LBB39:
movb $1, %al
/APP
/ 8 "pic.c" 1
outb %al, $161
/ 0 "" 2
/NO_APP
.LBE39:
.LBE38:
.LBB40:
.LBB41:
xorl %eax, %eax
/APP
/ 8 "pic.c" 1
outb %al, $32
/ 0 "" 2
/NO_APP
.LBE41:
.LBE40:
.LBB42:
.LBB43:
/APP
/ 8 "pic.c" 1
outb %al, $160
/ 0 "" 2
/NO_APP
.LBE43:
.LBE42:
.stabn 68,0,28,.LM4-.LFBB1
.LM4:
popl %ebp
ret
.size init_pic, .-init_pic
.Lscope1:
.stabs "",36,0,0,.Lscope1-.LFBB1
.stabd 78,0,0
.stabs "",100,0,0,.Letext0
.Letext0:
.ident "GCC: (GNU) 4.4.0"
Aufruf
nasm -fbin pic.asm -o pic
i586-elf-gcc pic.c -c -m32 -Wall -ffreestanding -fno-stack-protector -nostdinc -I include -std=c99 -Wextra -Werror -g -O3 -S
i586-elf-ld -b binary pic.o -o pic.bin -T link.ld
link.ld
ENTRY(init_pic)
SECTIONS
{
.text :
{
*(.text*)
*(.rodata*)
*(.data*)
*(.bss*)
}
}
Programm Noob