( uid_4672 | 2024. 08. 12., h – 18:42 )

a nagy pofádra, oda... 

tessék: 

itt van ez a projekt: https://github.com/mckev/bootstrap

kicheckoutolod, ráteszed a patchemet, lásd lennebb... felsetupolja a 77-es idt entry-t, semmi assembly...

úgy kell indítani, hogy: qemu-system-i386 -cdrom myos.iso

 

minden kbhitre szépen meghívja a megszakítást, a "terminál" pedig megy tovább... a megszakítás handler meg sima C-ben van írva, és minden billentyűre kiírja, hogy "nagypofaju bztnek..." a handlerből...

szerk: nincs ott semmiféle "verem gatyába rázása"... assemblyből... a C függvény meg van adva magában az idt-ben...

 

screencast itt

 

lehet tippelni, hogy mi lesz erre bzt reakciója... hogy HAZUG vagyok-e vagy TANULATLAN TUSKÓ... SEGGARC, maybe... esetleg mindhárom?

 

 

patch:

diff --git a/src/compile.sh b/src/compile.sh
old mode 100644
new mode 100755
index 2f20d7d..ae62d30
--- a/src/compile.sh
+++ b/src/compile.sh
@@ -3,8 +3,8 @@
set -e
 
 
-AS=~/opt/cross/bin/i686-elf-as
-GCC=~/opt/cross/bin/i686-elf-gcc
+AS=i686-elf-as
+GCC=i686-elf-gcc
GCC_OPTIONS="-std=gnu99 -ffreestanding -O2 -Wall -Wextra -masm=intel"
OBJ_FILES=""
 
@@ -54,7 +54,7 @@ rm -f timer.o
$GCC $GCC_OPTIONS -c timer.c -o timer.o
OBJ_FILES="$OBJ_FILES timer.o"
rm -f trap.o
-$GCC $GCC_OPTIONS -c trap.c -o trap.o
+$GCC $GCC_OPTIONS -c trap.c -o trap.o -mgeneral-regs-only
OBJ_FILES="$OBJ_FILES trap.o"
rm -f util.o
$GCC $GCC_OPTIONS -c util.c -o util.o
diff --git a/src/kernel.c b/src/kernel.c
index 3aa19db..633ada1 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -28,6 +28,6 @@ void kernel_main() {
       STI();
 
       // Call main
-       main_starfield();
-       // main_terminal();
+       //main_starfield();
+       main_terminal();
}
diff --git a/src/main_terminal.c b/src/main_terminal.c
index eb4ef36..db89500 100644
--- a/src/main_terminal.c
+++ b/src/main_terminal.c
@@ -17,6 +17,7 @@ int main_terminal() {
               if (kbhit()) {
                       char ch = getch();
                       terminal_writechar(ch);
+                       asm volatile("int 77");
               }
       }
 
diff --git a/src/trap.c b/src/trap.c
index 09500af..fa07d15 100644
--- a/src/trap.c
+++ b/src/trap.c
@@ -83,10 +83,34 @@ extern uint32_t trap_vectors[];     // in trap_vectors.s
       (gate).off_31_16 = (uint32_t)(off) >> 16;                       \
}
 
+#define VGA_BUFFER (uint16_t*)0xb8000
+#define VGA_WIDTH 80
+
+void print_string(int line, int offset, const char* str, uint8_t color)
+{
+       uint16_t*       vga = VGA_BUFFER;
+       int             i = 0;
+
+       while (str[i] != '\0') {
+               vga[i + line * VGA_WIDTH + offset] = (color << 8) | str[i];
+               i++;
+       }
+}
+
+void __attribute__((interrupt)) my_isr(void *)
+{
+       static int line = 0;
+       const char *str = "nagypofaju bztnek...";
+
+       print_string(line, 40, str, 0x0f);
+       line++;
+}
+
void trap_vectors_init() {
       for (int i = 0; i < 256; i++) {
               SETGATE(idt[i], 0, SEG_KCODE << 3, trap_vectors[i], 0);
       }
+       SETGATE(idt[77], 1, SEG_KCODE << 3, my_isr, 0);
}
 

a generált kód pedig (objdump, at&t assembly syntax, a gyengébbek kedvéert):

00000000 <my_isr>:
  0:   55                      push   %ebp
  1:   89 e5                   mov    %esp,%ebp
  3:   53                      push   %ebx
  4:   8b 1d 00 08 00 00       mov    0x800,%ebx
  a:   51                      push   %ecx
  b:   52                      push   %edx
  c:   ba 01 00 00 00          mov    $0x1,%edx
 11:   50                      push   %eax
 12:   8d 04 9b                lea    (%ebx,%ebx,4),%eax
 15:   c1 e0 04                shl    $0x4,%eax
 18:   8d 8c 00 50 80 0b 00    lea    0xb8050(%eax,%eax,1),%ecx
 1f:   b8 6e 00 00 00          mov    $0x6e,%eax
 24:   8d b4 26 00 00 00 00    lea    0x0(%esi,%eiz,1),%esi
 2b:   8d 74 26 00             lea    0x0(%esi,%eiz,1),%esi
 2f:   90                      nop
 30:   80 cc 0f                or     $0xf,%ah
 33:   83 c1 02                add    $0x2,%ecx
 36:   83 c2 01                add    $0x1,%edx
 39:   66 89 41 fe             mov    %ax,-0x2(%ecx)
 3d:   66 0f be 42 ff          movsbw -0x1(%edx),%ax
 42:   84 c0                   test   %al,%al
 44:   75 ea                   jne    30 <my_isr+0x30>
 46:   83 c3 01                add    $0x1,%ebx
 49:   58                      pop    %eax
 4a:   5a                      pop    %edx
 4b:   89 1d 00 08 00 00       mov    %ebx,0x800
 51:   59                      pop    %ecx
 52:   5b                      pop    %ebx
 53:   5d                      pop    %ebp
 54:   cf                      iret