Autor Thema: Shell  (Gelesen 9640 mal)

Kyoko12

  • Beiträge: 59
    • Profil anzeigen
Gespeichert
« am: 26. December 2004, 11:04 »
Hi, ich schreibe gerade eine Shell für meine 2. OS, die rein in ASM geschrieben wird.

hier ist der code:


;Dieser Code beschreibt einen kleinen Test-Kernel.


;API anmelden und definieren:


;Die API von AgamOS

_int0x21:


;funktion1:
;gibt einen string aus!
;muss vorher mir varname in si gemovt werden
 _int60x21_ser0x01:
 cmp al, 0x01
 jne _int0x21_ser0x02
 _int0x21_ser0x01_start:
  lodsb                   ; nächstes Byte laden
 or  al, al              ; 0-Byte?
 jz  _int0x21_ser0x01_end
 mov ah, 0x0E            ; BIOS Teletype
 mov bh, 0x00            ; Page 0
 mov bl, 0x07            ; Text-Attribute
 int 0x10                ; BIOS-Call
 jmp _int0x21_ser0x01_start
_int0x21_ser0x01_end:
jmp _int0x21_end


_int0x21_ser0x02:
cmp al, 0x02
jne _int0x21_ser0x03
_int0x21_ser0x02_start:
;hexdump:
db 0Eah
dw 0000h
dw 0FFFFh
_int0x21_ser0x02_end:
jmp _int0x21_end


_int0x21_ser0x03:
cmp al, 0x03
jne _int0x21_ser0x04
_int0x21_ser0x03_start:
_int0x21_ser0x03_loop:
;
loop
_int0x21_ser0x03_end:
jmp _int0x21_end



_int0x21_ser0x04:
cmp al, 0x04
jne _int0x21_end
_int0x21_ser0x04_start:
pusha
mov ax,0xA000
mov es,ax
xor di,di
mov al,0x00
mov cx,0x2000
rep stosb
popa
_int0x21_ser0x04_end:
jmp _int0x21_end



_int0x21_end:
iret





;ints im Interrupt Vektor Table anmelden:

push dx
push es
xor ax, ax
mov es, ax
cli
mov word [es:0x21*4], _int0x21  ; Pointer auf den Handler
mov [es:0x21*4+2], cs           ; Pointer auf CS
sti
pop es
pop dx

jmp _main

;Daten:

hello db "Willkommen bei AgamOS",10,13,0
absatz db 10,13,0
input_ascii db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
input_scan db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

;main-code:
_main:

mov al, 0x01
mov si, hello
int 0x21

mov al, 0x01
mov si, absatz
int 0x21

mov cx, 0

jmp _shell

;Hier startet nun die Shell mit einem Test-Kommando, das den PC rebootet:

_shell:


mov ah, 00h
int 16h

inc cx

mov [input_ascii+cx], al
mov [input_scan+cx], ah

mov ah, 0Eh
mov al, al
mov bl, 0x07
int 10h


;überprüfungen der Eingabe für Zeilenumbruch etc.:


cmp [input_scan+cx], 28
jz _commands
jnz _shell



_commands:

;Hier werden die eingegebenen Kommandos überprüft:

 mov cx, 0

 jmp _com_reboot
 
 
  _com_reboot:
  inc cx
  cmp [input_ascii+cx], "r"
  jnz _commands_end
  inc cx
  cmp [input_ascii+cx], "e"
  jnz _commands_end
  inc cx
  cmp [input_ascii+cx], "b"
  jnz _commands_end
  inc cx
  cmp [input_ascii+cx], "o"
  jnz _commands_end
  inc cx
  cmp [input_ascii+cx], "o"
  jnz _commands_end
  inc cx
  cmp [input_ascii+cx], "t"
  jnz _commands_end
 
  mov al, 0x02
  int 0x21
  jmp commands_end


_commands_end:

mov [input_ascii], 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
mov [input_scan], 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

jmp _main





Mein Problem: bei folgenden Zeilen sgat er mir, "Invalide effictive adresse"


mov [input_ascii+cx], al
mov [input_scan+cx], ah



das sind die Zeilen 126 und 127! Könnt ihr einen Fehler finden?

Danke im Vorraus, cu

elfish_rider

  • Beiträge: 293
    • Profil anzeigen
Gespeichert
« Antwort #1 am: 26. December 2004, 11:23 »
Ich denke, der Prozessor ist nicht in der Lage, CX zu einer Adresse zu addieren.

Brauche stattdessen BX.


PUSH BX
MOV BX, CX
MOV [input_ascii+BX], AL
MOV [input_scan+BX], AH
POP BX

joachim_neu

  • Beiträge: 1 228
    • Profil anzeigen
    • http://www.joachim-neu.de
Gespeichert
« Antwort #2 am: 26. December 2004, 11:54 »
stimmt, und ich würde das mit funktionen machen, (z.B. für stringvergleich) das ist übersichtlicher.
http://www.joachim-neu.de | http://www.orbitalpirates.de | http://www.middleageworld.de

System: 256 RAM, GeForce 2 MX 400, AMD Athlon XP 1600+, Windows XP, 1x Diskette, 1x DVD-ROM, 1x CD-R(W) Brenner,...

 

Einloggen