My 3 little task dosent work ok at all.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Kemp

Re:My 3 little task dosent work ok at all.

Post by Kemp »

Thanks for showing me that, you inspired me to write a program that takes my source files and outputs nicely coloured html pages with links from label/variable references to where they are actually defined. It's working quite well :)
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:My 3 little task dosent work ok at all.

Post by Brendan »

Hi,
Kemp wrote: Thanks for showing me that, you inspired me to write a program that takes my source files and outputs nicely coloured html pages with links from label/variable references to where they are actually defined. It's working quite well :)
For assembly or C? :)

My utility is free (public domain I guess) and works well for NASM/assembly. I was intending to make it work on C too but only got half way - C syntax is much harder to parse so it doesn't cross-link C much (I think it only does "#define" and "#include"). It won't handle complex makefiles either...

Anway, if you're interested the C source code (and html generated from the source) and a manual for it is online at:

http://bcos.hopto.org/source.html


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Kemp

Re:My 3 little task dosent work ok at all.

Post by Kemp »

For my asm source code. It's quite basic right now and it only resolves references within the same source file, but it works for my purposes (making my source easier to read on my site). It makes comments red, text strings blue, and makes references into links to the appropriate place. Example output:
http://www.iualdii.net/boot.asm.html

Though as that code needs ripping apart it'd probably be a bad idea to take ideas from it :P
hgb

Re:My 3 little task dosent work ok at all.

Post by hgb »

Tought I still without find the error.. lol.

I have rewrited the interrupt handler.

Code: Select all

%macro WRAPPER 1
isr_%1_wrapper:
   push bx
   cmp byte[exc_has_error+bx], 0
   pop bx
   jz .has_error
      push 0
   .has_error
   push ax
   mov ax, %1
   jmp exc_common16
%endmacro


exc_common16:
   invk exc_handler16
   add sp, 2
   pop ax
   iret


exc_handler16:
%define e_AX bp+4
%define e_Error bp+6
%define e_CS bp+8
%define e_IP bp+10
%define e_Flags bp+12
push bp
mov bp, sp
   push dx
   push ds
   mov dx, 0x10
   mov ds, dx
   invk Ax2Eax
   mov [.e_number], eax
   mov ax, [e_CS]
   invk Ax2Eax
   mov [.e_cs], eax
   mov ax, [e_IP]
   invk Ax2Eax
   mov [.e_ip], eax
   mov ax, [e_Error]
   invk Ax2Eax
   mov [.e_error_number], eax
   mov di, 180*17
   mov si, .e_msg
   mov ah, 0x50
   invk WriteMsg
   invk shut_down
   pop ds
   pop dx
pop bp
ret

.e_msg db "Exception "
.e_number db 0,0,0,0
.e_addr db " At Address "
.e_cs db 0,0,0,0
db ":"
.e_ip db " "," "," "," "
;.e_msg_cont db " "
.e_error db " Error("
.e_error_number db 0,0,0,0
db ")", 0
I only have one question this is pm16... is suposed? that in a interruption will be pushed, Flags, then IP, then CS and a posible error depending on the interruption (in that order), why for print correctly the CS:IP I need change the order in the arguments of

exc_handler16:
%define e_CS bp+8
%define e_IP bp+10

I was thinking that e_CS will be bp+10 and e_IP bp+8.


By the way, I have put like first instruction jmp $ to each task and the error CS:IP is printed in reverse... or the order I think it should be... then, there is a diference I guess that Im doing some uncorrect?.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:My 3 little task dosent work ok at all.

Post by Brendan »

Hi,

Because you're using stubs you'd get EIP on the stack twice.

With an error code your stack should look like:

%define e_CS bp+16
%define e_IP bp+14
%define e_Flags bp+10
%define e_Error bp+6
%define e_AX bp+4
%define stub_IP bp+2
%define old_BP bp

Also, your wrapper is broken because BX could be anything on entry, and the error code is 32 bit. I think you want:

Code: Select all

%macro WRAPPER 1
isr_%1_wrapper:
   cmp byte[exc_has_error+%1], 0
   jnz .has_error
   push dword 0
.has_error
   push ax
   mov ax, %1
   jmp exc_common16
%endmacro
However, I'd recommend using 2 different macros and removing the "[exc_has_error+?]" thing completely:

Code: Select all

%macro WRAPPER_without_error 1
isr_%1_wrapper:
   push dword 0
   push ax
   mov ax, %1
   jmp exc_common16
%endmacro

%macro WRAPPER_with_error 1
isr_%1_wrapper:
   push ax
   mov ax, %1
   jmp exc_common16
%endmacro
The reason for this is that DS might be wrong. For example, if some code did "MOV DS,0" and caused a general protection fault, then your general protection fault handler will need to handle the exception (instead of causing a double fault, then triple fault).

The common exception handler also needs to remove a 32 bit error code from the stack, e.g.:

Code: Select all

exc_common16:
   call exc_handler16
   add sp, 4
   pop ax
   iret
Your exception handler ("exc_handler16") will trash DI and SI (and possibly the highest 16 bits of EAX) because they aren't saved and restored (like DX is) - I'm not sure about the other registers (I don't know what Ax2Eax and WriteMsg do). This probably doesn't matter yet, but it might if the exception handlers start being used like they would in a kernel (where different exception handlers do different things, and can return to the interrupted code).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
mystran

Re:My 3 little task dosent work ok at all.

Post by mystran »

Brendan: Linux kernel is pretty clear and well commented if you compare it with most other open source C code. Most of the big projects actually tend to be easier to read (once you get the general architecture) than many smaller. That's probably because without relatively clear and well commented code it becomes more or less impossible to grow the code big.
hgb

Re:My 3 little task dosent work ok at all.

Post by hgb »

Hi people, I have finally working, I have rewrited all form scratch.

I attach the source, make it typing in the uncompresed folder "do t7".


I dont know really what was the error, I will take later a look again at my old code, but sure that I miss something there.


Ok, also I write, because I have watched a little extrange behaviour, tought the programm run in quemu and bochs ok (havent tested on computer), if I move the las two lines of t7.asm that are string declarations, there is a error there that is catched in some way by the exception handler... by the way, if you look at the exception handler

Code: Select all

%macro WRAPPERHE 1 ; Have error
isr_%1_wrapper:
   push ax
   mov ax, %1
   jmp exc_common16
%endmacro

%macro WRAPPERNE 1
isr_%1_wrapper:
   push word 0
   push ax
   mov ax, %1
   jmp exc_common16
%endmacro

exc_common16:
   invk exc_handler16
   pop ax
   add sp, 4
   iret


exc_handler16:
%define e_BP bp
%define e_RetAddr bp+2
%define e_AX bp+4
%define e_Error bp+6
%define e_EIP bp+8
%define e_CS bp+ 10
%define e_Flags bp+ 12
That is because it is PM16 and not 32 I guess (I see that I have missed in rename e_EIP to e_IP). About the error code, I have watchd that is only pushed if the interrupt is generated by the CPU, for example the exception 0x0D have error, but if I do int 0xD, the exception will be generated, but the error code will not be inserted, causing that the stack frame refer to incorrect displacements respec bp, and also because it is assumed that there will be a push (the error code), then add sp, 2 will fail and trash for the instruction iret.... (this is correct.. isnt it?)


By the way, in the tut, the guy put that exception 0x12 have a error code (in the list of errors have a 1 there), but in http://osdever.net/bkerndev/index.php?the_id=90 say 18 (0x12) Machine Check Exception (Pentium/586+) No (have error code). You know wich of this two is right?


OK, returning to the behaviour if I move the lines at the end of t7.asm
msgWelcome db ...., 10, 0
msgTimer db "Ti...", ..., 0
to any place above a exception 3 is generated at 0x8:ffef, by the way, the size of the code are at much 13 sectors (if Im not wrong), and that is far from 0xFFFF... I dont understand this behaviour, if some one of you know what is, pleca dont doubt in say it :).




Apart, the only rude code that I hae tried to read is the source of the mesa lib some day, I have finding things extrange to me ... :), bye the way, 35Mb the src of Linux, where I start?, do you have a place where I can download src for kernels (like a list?) ?
hgb

Re:My 3 little task dosent work ok at all.

Post by hgb »

Solved the problem, like I say the size was 13 sectors, and I was thinking than my file d.asm have been loading 14 sectors at one, well, it was loading 12 sectors only.


I have a question related to the next tutorial, in a line is used malloc:
block=(dword *)malloc(8192+4)
I can put at the enf of my file a mark ENDFILE and use from that label (because after this place is free??) to get "allocated" space, or should I do at the end of the file some like block times 8192+4 db 0 ???
Post Reply