Skip to content

Latest commit

 

History

History
87 lines (64 loc) · 2.32 KB

File metadata and controls

87 lines (64 loc) · 2.32 KB

Code: AssemblyUtility.asm, Descriptor.c and Main.c

;; part of AssemblyUtility.asm that is related to interrupt

;; interrupt related functions

; function that activates interrupt
kEnableInterrupt:
    sti
    ret

; function that deactivates interrupt
kDisableInterrupt:
    cli
    ret

; function that returns RFLAGS
kReadRFLAGS:
    pushfq   ; push RFLAGS to stack
    pop rax
    ret
// Descriptor.c
// Inside Descriptor.c, every gate descriptor references functions defined in ISR.asm
// part of Main.c that initializes PIC 

/* Initialize PIC controller */

kPrintString(0, 16, "PIC Controller And Interrupt Initialize.....[     ]");
kInitializePIC();
// unmask all interrupts
kMaskPICInterrupt(0);
// interrupt was deactivated in 01.Kernel32/EntryPoint.s 
kEnableInterrupt();
kPrintString(45, 16, "Pass");    

Explanation

What does the code do?

Until now, PIC initialization function and interrupt handlers are implemented. This time, the handlers are hooked up to IDT gate descriptors and PIC is initialized in Main.c

Assembly

  1. cli and sti clear and store interrupts

    • In 01.Kernel32/Sources/EntryPoint.s, there is cli instruction because interrupt handlers were not set
  2. pushfq pushes Rflags to stack.

    • Rflags is not accessible by mov instruction

MINT64OS Characteristics

  1. Memory Layout up to CH13

    • start(inclusive) ~ end(exclusive)
    • 0x00000 ~ 0x00400 (Interrupt Vector Table for real mode)
    • 0x07C00 ~ 0x07E00 (Bootloader)
    • 0x07E00 ~ 0x10000 (Stack for real mode and protected mode)
    • 0x10000 ~ 0x10400 (32 bit code of OS; EntryPoint.S + Main.c + ...)
    • 0xA0000 ~ ... (video memory for graphic mode)
    • 0xB8000 ~ ... (video memory for text mode)
    • 0x100000(1MB) ~ 0x142000 (IA-32 mode page table tree structure, 264KB)
    • 0x142000 ~ 0x142010 (GDTR, 16 bytes)
    • 0x142010 ~ 0x142038 (GDT, 40 bytes = 3 * 8 bytes + 1 * 16 bytes)
    • 0x142038 ~ 0x1420A0 (TSS, 104 bytes = 1 * 104 bytes)
    • 0x1420A0 ~ 0x1420B0 (IDTR, 16 bytes)
    • 0x1420B0 ~ 0x1426F0 (IDT, 1600 bytes = 100 * 16 bytes)
    • 0x200000(2MB) ~ ... (64 bit code of OS; EntryPoint.S + Main.c + ...)
    • 0x600000(6MB) ~ 0x700000(7MB) (Stack for long mode)
    • 0x700000(7MB) ~ 0x800000(8MB) (IST1 stack area)