flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Comand Line Start

Goto page Previous  1, 2, 3, 4  Next
Author
Thread Post new topic Reply to topic
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
First thing, is you need to do this :
Code:
        mov al, 0x20        out 0x20, al  ; quiet screaming irq chip.    

At the end of your IRQ interrupts.


Last edited by Dex4u on 10 Oct 2006, 01:12; edited 1 time in total
Post 10 Oct 2006, 01:01
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Okay, inside of this quote I will point to it, it's in interrupts.inc.

rhyno_dagreat wrote:
Okay, here it goes:

rhynload.asm
Code:
;BOOTSTART
org 7C00h

jmp start

message db 'Loading RhynOS...',13,10,0

start:
        xor ax, ax
        mov ds, ax

        mov si, message
        call bios_print

load_os:
        mov ax, 0060h
        mov es, ax
        mov bx, 0000h
        mov ah, 02h
        mov al, 5
        mov ch, 0
        mov cl, 2
        mov dh, 0
        ;mov dl, 0  ; Not sure if needed, been told that dl already contains the drive that was booted on
        int 13h
        jmp 0060h:0000h

bios_print:
        lodsb
        or al, al
        jz done
        mov ah, 0x0E
        int 0x10
        jmp bios_print

done:
        call load_os

;BOOTEND
        times 510-($-$$) db 0
        dw 0xAA55                     
    


rhynos.asm
Code:
org 0000h
use16
cli

mov ax, 0060h
mov ds, ax
add dword [gdt_descriptor+2], 600h

lgdt [gdt_descriptor]

mov eax, cr0
or eax, 1
mov cr0, eax

jmp 08h:clear_pipe

gdt:
dd 0, 0
gdt_code:
db 0FFh, 0FFh, 0, 0, 0, 10011010b, 11001111b, 0
gdt_data:
db 0FFh, 0FFh, 0, 0, 0, 10010010b, 11001111b, 0
gdt_end:

gdt_descriptor:
    dw gdt_end - gdt - 1
    dd gdt

org 0600h+$
use32
clear_pipe:
mov ax, 10h
mov ds, ax
mov ss, ax

mov esp, 090000h

;ACTUAL KERNEL CODE STARTS HERE
mov si, WelMsg
call PrintFunc

call Reroute_PICs
lidt [idtp]
sti

GetInput:
        int 0x21
        cmp al, 02
        je DoClrScrn
        jmp GetInput

DoClrScrn:
        call ClrScrn

call CmdPrintFunc
;KERNEL CODE ENDS HERE
infinite_loop:
        jmp infinite_loop

times 571-($-$$) db 0
include 'interrupts.inc'
WelMsg db "Welcome to RhynOS! Press 1 To Continue.", 0             
    


interrupts.inc
Code:
;INTERRUPTS!!! YAY

PrintFunc:
        mov ax, 10h
        mov ds, ax
        mov ebx, 0B8000h
        strloop:
                lodsb
                mov byte [ds:ebx], al
                inc ebx
                mov byte [ds:ebx], 1Bh
                cmp ax, 0
                je done
                inc ebx
                inc ax
                jmp strloop

done:
        ret

ClrScrn:
        mov ax, 10h
        mov ds, ax
        mov ebx, 0B8000h
        mov ax, 0
        clrloop:
                cmp ax, 2000
                je done
                mov byte [ds:ebx], ' '
                inc ebx
                mov byte [ds:ebx], 1Bh
                inc ebx
                inc ax
                jmp clrloop

CmdPrintFunc:
        mov ax, 10h
        mov es, ax
        mov edi, 0B8000h
        xor ebx, ebx
        cmdloop:
                int 0x21
                mov bl, al
                cmp bl, 1Ch
                je done
                mov esi, ebx
                mov cl, [esi+KeyBoard]
                mov byte [ds:edi],cl
                inc edi
                mov byte [ds:edi], 1Bh
                inc edi
                jmp cmdloop

Reroute_PICs:
        ;send ICW1(Interrupt Control Word1)
        mov al, 11h
        ;out PIC1, ICW1
        out 20h, al
        ;out PIC2 ICW1
        out 0A0h, al

        ;send ICW2
        mov al, 20h
        ;out PIC1 + 1, IRQ0 start point
        out 21h, al
        mov al, 28h
        ;out PIC2 + 1, IRQ8 start point
        out 0A1h, al

        ;send ICW3
        ;IRQ2 to Connection to Slave PIC
        mov al, 04h
        out 21h, al
        mov al, 02h
        out 0A1h, al

        ;send ICW4
        mov al, 01h
        out 21h, al
        out 0A1h, al

        ;disable IRQs
        mov al, 0FFh
        out 021h, al
        ret

isr0:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err00
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr1:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err01
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr2:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err02
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr3:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err03
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr4:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err04
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr5:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err05
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr6:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err06
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr7:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err07
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr8:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err08
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr9:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err09
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr10:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err10
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr11:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err11
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr12:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err12
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr13:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err13
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr14:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err14
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr15:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err15
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr16:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err16
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr17:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err17
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr18:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err18
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr19:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr20:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr21:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr22:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr23:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr24:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr25:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr26:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr27:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr28:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr29:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr30:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr31:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintFunc
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

irq0:
        mov si, TimerEnabled
        call PrintFunc
        iret

irq1:                              <==============================
        in al, 60h               <=========== Interrupt 21h =========
        iret                        <==============================

idt_start:

        ;Interrupt Example
        ; dw start_address
        ; dw code_selector where ISR is being held
        ; dw type_settings for ISRs
        ; dw start_address2(bits 31-16)
        ; start_address2 should be 0 because the
        ; start address should be no more than 1
        ; word value.


        ;FOR HISTORIC REFERENCE PURPOSES ONLY
        ;Original ISRS looked like the following
        ;
        ;dw 0x0000
        ;dw 0x08
        ;dw 0x8E00
        ;dw 0x08
        ;
        ;END OF HISTORIC REFERENCE

        ;SERVICE REQUEST INTS
        ;int0
        dw isr0
        dw 0x08
        dw 0x8E00
        dw 0x0
        ;int1
        dw isr1
        dw 0x08
        dw 0x8E00
        dw 0x0
        ;int2
        dw isr2
        dw 0x08
        dw 0xE00
        dw 0x0
        ;int3
        dw isr3
        dw 0x08
        dw 0x8E00
        dw 0x0
        ;int4
        dw isr4
        dw 0x08
        dw 0x8E00
        dw 0x0
        ;int5
        dw isr5
        dw 0x08
        dw 0x8E00
        dw 0x0
        ;int6
        dw isr6
        dw 0x08
        dw 0x8E00
        dw 0x0
        ;int7
        dw isr7
        dw 0x08
        dw 0x8E00
        dw 0x0
        ;int8
        dw isr8
        dw 0x08
        dw 0x8E00
        dw 0x0
        ;int9
        dw isr9
        dw 0x08
        dw 0x8E00
        dw 0x0
        ;int10
        dw isr10
        dw 0x08
        dw 0x8E00
        dw 0x0
        ;int11
        dw isr11
        dw 0x08
        dw 0x8E00
        dw 0x0
        ;int12
        dw isr12
        dw 0x08
        dw 0x8E00
        dw 0x0
        ;int13
        dw isr13
        dw 0x08
        dw 0x8E00
        dw 0x0
        ;int14
        dw isr14
        dw 0x08
        dw 0x8E00
        dw 0x0
        ;int15
        dw isr15
        dw 0x08
        dw 0xE00
        dw 0x0
        ;int16
        dw isr16
        dw 0x08
        dw 0xE00
        dw 0x0
        ;int17
        dw isr17
        dw 0x08
        dw 0xE00
        dw 0x0
        ;int18
        dw isr18
        dw 0x08
        dw 0xE00
        dw 0x0
       ;int19
        dw isr19
        dw 0x08
        dw 0xE00
        dw 0x0
       ;int20
        dw isr20
        dw 0x08
        dw 0xE00
        dw 0x0
       ;int21
        dw isr21
        dw 0x08
        dw 0xE00
        dw 0x0
       ;int22
        dw isr22
        dw 0x08
        dw 0xE00
        dw 0x0
       ;int23
        dw isr23
        dw 0x08
        dw 0xE00
        dw 0x0
       ;int24
        dw isr24
        dw 0x08
        dw 0xE00
        dw 0x0
       ;int25
        dw isr25
        dw 0x08
        dw 0xE00
        dw 0x0
       ;int26
        dw isr26
        dw 0x08
        dw 0xE00
        dw 0x0
       ;int27
        dw isr27
        dw 0x08
        dw 0xE00
        dw 0x0
       ;int28
        dw isr28
        dw 0x08
        dw 0xE00
        dw 0x0
       ;int29
        dw isr29
        dw 0x08
        dw 0xE00
        dw 0x0
       ;int30
        dw isr30
        dw 0x08
        dw 0xE00
        dw 0x0
       ;int31
        dw isr31
        dw 0x08
        dw 0xE00
        dw 0x0

       ;HARDWARE INTERRUPT REQUESTS
       ;int32
        dw irq0
        dw 0x08
        dw 0x8E00
        dw 0x0
       ;int33
        dw irq1
        dw 0x08
        dw 0x8E00
        dw 0x0

idt_end:

idtp:
        dw idt_end - idt_start - 1
        dd idt_start

TimerEnabled db "Timer Interrupt Enabled!", 0
Err00 db "Error 00 - Division By Zero",0
Err01 db "Error 01 - Debug",0
Err02 db "Error 02 - Non Maskable Interrupt",0
Err03 db "Error 03 - Breakpoint Exception",0
Err04 db "Error 04 - Into Detected Overflow",0
Err05 db "Error 05 - Out of Bounds",0
Err06 db "Error 06 - Invalid Opcode",0
Err07 db "Error 07 - No Coprocessor",0
Err08 db "Error 08 - Double Fault",0
Err09 db "Error 09 - Coprocessor Segment Overrun",0
Err10 db "Error 10 - Bad TSS",0
Err11 db "Error 11 - Segment Not Present",0
Err12 db "Error 12 - Stack Fault",0
Err13 db "Error 13 - General Protection Fault",0
Err14 db "Error 14 - Page Fault",0
Err15 db "Error 15 - Unknown Interrupt",0
Err16 db "Error 16 - Coprocessor Fault",0
Err17 db "Error 17 - Alignment Check",0
Err18 db "Error 18 - Machine Check",0
ErrRes db "Error - Reserved",0

KeyBoard db 0, 0, "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", 0, 0, "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", 0, 0, "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", "`", 0, "\", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", 0, "*", 0
ScanCode db 0                                     
    
Post 10 Oct 2006, 01:11
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
That ok i found it but you need to do the above
Post 10 Oct 2006, 01:13
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
And weres your Done and ret ?
Post 10 Oct 2006, 01:15
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Ah, why's that?
Post 10 Oct 2006, 01:15
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Between the PrintFunc and ClrScrn Functions
Post 10 Oct 2006, 01:16
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
That to say you have acknowledged the IRQ.
But it still shoud not fill the screen with 1 etc.
Post 10 Oct 2006, 01:20
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Well, I did what you said and it's still filling the screen with ones. Is it possibly a bug in BOCHs? I'm not using real hardware yet.
Post 10 Oct 2006, 01:24
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Where do you unmask irq's ?
Post 10 Oct 2006, 01:32
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
What do you mean unmask?
Post 10 Oct 2006, 01:35
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Try changing this
Code:
      ;disable IRQs        mov al, 0FFh        out 021h, al        ret    

To this
Code:
      ;disable IRQs       mov  al,255                                       ; mask all irqs        out  0xa1,al        out  0x21,al        ret    

And you should call this
Code:
unmask_irqs:        mov  al,0                                         ; unmask irq's        out  0xA1,al        out  0x21,al        sti        ret    

instead of doing just this
Code:
sti    
Post 10 Oct 2006, 01:42
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Okay, I'm about to give it a shot
Post 11 Oct 2006, 01:52
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
I've tried it and it's now flashing two ascii characters in the same place continuously, and when I hit enter it stopped (like it should). But instead of creating an unmask_irqs subroutine, this is what I did:

Code:
org 0000h
use16
cli

mov ax, 0060h
mov ds, ax
add dword [gdt_descriptor+2], 600h

lgdt [gdt_descriptor]

mov eax, cr0
or eax, 1
mov cr0, eax

jmp 08h:clear_pipe

gdt:
dd 0, 0
gdt_code:
db 0FFh, 0FFh, 0, 0, 0, 10011010b, 11001111b, 0
gdt_data:
db 0FFh, 0FFh, 0, 0, 0, 10010010b, 11001111b, 0
gdt_end:

gdt_descriptor:
    dw gdt_end - gdt - 1
    dd gdt

org 0600h+$
use32
clear_pipe:
mov ax, 10h
mov ds, ax
mov ss, ax

mov esp, 090000h

;ACTUAL KERNEL CODE STARTS HERE
mov si, WelMsg
call PrintFunc

call Reroute_PICs
lidt [idtp]
push ax
mov al, 0
out 0A1h, al
out 21h, al
sti
pop ax

GetInput:
        int 0x21
        cmp bl, 02
        je DoClrScrn
        jmp GetInput

DoClrScrn:
        call ClrScrn

call CmdPrintFunc
;KERNEL CODE ENDS HERE
infinite_loop:
        jmp infinite_loop

times 561-($-$$) db 0
include 'interrupts.inc'
WelMsg db "Welcome to RhynOS! Press 1 To Continue.", 0
    
Post 11 Oct 2006, 02:02
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Note: your IRQ1 should be some thing like this
Code:
irq1:
        pushad
        push  es
        push  ds
        in al,60h
        mov  byte[scan],al

        mov   al,0x20
        out   0x20,al           
                        
        pop   ds
        pop   es
        popad
        mov  al,byte[scan]
        iret

scan db 0
    
Post 11 Oct 2006, 16:41
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
At the risk of sounding ignorant, I'm going to ask: What are you doing and why do you need to do it? Smile
Post 11 Oct 2006, 17:20
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Oh, and one other thing: You do the pushad and then popad and afterwards you still move scan into al. I thought the reason for pushing stuff on the stack and popping it off was to save the value in the register for later?
Post 11 Oct 2006, 17:22
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Yes we save all regs, but we need return the scan code, so we put it in al, as that is where it is expected to be returned.
Post 11 Oct 2006, 17:30
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Ah, I see... so you did pushad just to save all the other regs in a faster, less bulky manner.
Post 11 Oct 2006, 17:33
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Yes thats right.
Post 11 Oct 2006, 18:52
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thanks for all the help! I'm gonna try it when I get home.
Post 11 Oct 2006, 20:22
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.