Page 1 of 2

My 3 little task dosent work ok at all.

Posted: Tue May 24, 2005 12:34 pm
by hgb
Im not able to use my task completely...

I attach a resume of my code of the things I supose are important for this, if you need the real code, say me.


Also for the ones that dosent whant to take a look here is a resume of the resume ;).

Code: Select all

jump start2
.
jump_to_tss:
   jmp far [bx]
ret

%define MAX_TASK 3

gdt_label: times ((5+MAX_TASK)*DESCR_SEG_size) db 0
gdtr_label: times DESCR_GDTR_size db 0
idt_label: times (0x22 * DESCR_INT_size) db 0
idtr_label: times DESCR_IDTR_size db 0
.
scancode db "@"
.
taskList: times MAX_TASK*DESCR_TSS_size db 0
total_task dw MAX_TASK
cur_task dw 0
task_sel times MAX_TASK dw 0
%define STACK_SIZE 1024
task_stack times STACK_SIZE db 0
.
setup_GDT:
.
; /* 0x28 -- TSS for main() */
   mov ax, ds
   mov bx, ds
   shl ax, 4
   shr bx, 12
   add ax, taskList
   adc bx, 0
   invk setup_GDT_entry, (gdt_label +5*DESCR_SEG_size), ax, bx, DESCR_TSS_size, 0, byte ACS_TSS,  byte 0
   mov word[task_sel], 0x28
; /* 0x30 -- TSS for task() */
.
; /* 0x38 -- TSS for task() */
.
   invk setup_GDT_entry, (gdt_label + 7*DESCR_SEG_size), ax, bx, DESCR_TSS_size, 0, byte ACS_TSS, byte 0
   mov word[task_sel], 0x38
.
ret


; void setup_PMode()
setup_pmode:
    ; /* disable interrupts so that IRQs don't cause exceptions */
   ; /* disable NMIs as well */
   call setup_GDT
   call setup_IDT

   ; /* save IRQ masks */
   ; /* setup PIC */
   ; setup_PIC (0x20, 0x28);
   ; /* set new IRQ masks */
   ; /* saving real mode segment addresses */
   ; /* WOW!!! This switches us to PMode just setting up CR0.PM bit to 1 */
   ; /* loading segment registers with PMode selectors */
   invk update_cs, 0x8
   mov ax, 0x10
   mov ds, ax
   mov es, ax
   mov ax, 0x18
   mov ss, ax

   ; /* if we don't load fs and gs with valid selectors, task switching may fail. */
   invk load_fs, 0x10
   invk load_gs, 0x10

   ; /* due to the same reason, let's clear ldtr */
   invk load_ldt, gdt_label ;(selector zero)
......
   xor cx, cx
   mov bx, taskList
   xor edx, edx
   mov dx, task_stack
   .again:
      mov eax, 0
      mov [bx+DESCR_TSS.trace], ax
      mov word[bx + DESCR_TSS.io_map_addr], DESCR_TSS_size


      or cx, cx
      jz .check
         mov [bx+DESCR_TSS.ldtr], eax
         mov [bx+ DESCR_TSS.fs], eax
         mov [bx+ DESCR_TSS.gs], eax

            mov eax, ds
         mov [bx + DESCR_TSS.ds], eax
         mov [bx + DESCR_TSS.es], eax
         mov [bx + DESCR_TSS.ss], eax

         mov eax, cs
         mov [bx + DESCR_TSS.cs], eax

         mov dword[bx+DESCR_TSS.eflags], 0x202
         mov [bx+DESCR_TSS.esp], edx
         add edx, STACK_SIZE
      .check
      add bx, DESCR_TSS_size
      inc cx
      cmp cx, 3
      jb .again
   mov dword[taskList+1*DESCR_TSS_size+DESCR_TSS.eip], task1
   mov dword[taskList+2*DESCR_TSS_size+DESCR_TSS.eip], task2

   ; /* load the TR register */
   mov ax, [task_sel]
   invk load_ltr, ax
   sti
ret

......

scheduler:
; ret ; If I uncomment this ret, the message "X Task 0" is printed  and handled OK
   mov si, [cur_task]
   inc si
   cmp si, MAX_TASK
   jb .cont
      xor si, si
   .cont
   mov [cur_task], si
   shl si, 1
   mov bx, [task_sel+si]
   invk jump_to_tss
ret
; void timer_handler()
timer_handler:
   mov ebx, [ticks]
   add ebx, 1
   mov [ticks], ebx

   mov ax, 0x20
   mov fs, ax
   mov bl, [fs:80*40+8*2]
   inc bl
   mov [fs:80*40+8*2], bl
   mov al, EOI
   out PORT_8259M, al
   invk scheduler
   ret

; void kbd_handler()
kbd_handler:
   in al, PORT_KBD_A
   mov [scancode], al
   mov al, EOI
   out PORT_8259M, al
   ret

mt0 db "  Task 0", 0
mt1 db "  Task 1", 0
mt2 db "  Task 2", 0

task1:
   .again
      mov al, [scancode]
      mov [mt1], al
      mov di, 80 * 8
      mov si, mt1
      invk write_msg
      jmp .again
ret
task2:
   .again
      mov al, [scancode]
      mov [mt2], al
      mov di, 80 * 8
      mov si, mt2
      invk write_msg
      jmp .again
ret
...
start2:
....
   call setup_pmode

; db 0xea, 0,0, 0x28, 0
;jmp 0x30:0 ; If I uncomment this, it is called ok :)
;jmp 0x38:0 ; If I uncomment this, task bussy "jump_protected: JUMP to busy 386 TSS unsupported." msg by Bochs

   .again
      mov al, [scancode]
      mov [mt0], al
      mov di, 80 * 6
      mov si, mt0
      push ax
      invk write_msg
      pop ax
      cmp al, 0x81
      je .end
; jmp 0x30:0 ; If I uncomment this, is only executed one time??? and task 0 is continued...
; jmp 0x38:0 ; If I uncomment this, task bussy "jump_protected: JUMP to busy 386 TSS unsupported."
      jmp .again
   .end
......
Running my code with the first ret commented in scheduler code, cause that my exception handler raise this

Code: Select all

Out Of PM
      exception Number 000D        At address 0FBA:00080002 ERROR B810
tought The exception can be correct, perhaps the address not... :).

I also have added a error for the exception... (dont know if is correct...)??

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

Posted: Tue May 24, 2005 10:53 pm
by hgb
OK, I have watched my first error... from the above.

Code: Select all

invk setup_GDT_entry, (gdt_label +5*DESCR_SEG_size), ax, bx, DESCR_TSS_size, 0, byte ACS_TSS,  byte 0
  mov word[task_sel], 0x28
; /* 0x30 -- TSS for task() */
.
; /* 0x38 -- TSS for task() */
.
  invk setup_GDT_entry, (gdt_label + 7*DESCR_SEG_size), ax, bx, DESCR_TSS_size, 0, byte ACS_TSS, byte 0
  mov word[task_sel], 0x38
I have moved to the first task_sel the values 0x28, 0x30 and 0x38

By the way, now I have checked that I can at less jump one time to task1 and task2, I have changed it like this:


Code: Select all

scheduler:
ret
   mov si, [cur_task]
   inc si
   cmp si, MAX_TASK
   jb .cont
      xor si, si
   .cont
   mov [cur_task], si
   shl si, 1
   mov bx, [task_sel+si]
   OFFSETHERE JMP FAR [BX] ;this print [4064]
   jmp far [bx]
   ;invk jump_to_tss
ret

task1:
   .again
      mov al, [scancode]
      cmp al, 0x81
      je .end
      mov [mt1], al
      mov di, 80 * 8
      mov si, mt1
      invk write_msg
      jmp .again
   .end
   mov [mt1], al
   mov di, 80 * 8
   mov si, mt1
   invk write_msg
   jmp 0x38:0
ret
task2:
   .again
      mov al, [scancode]
      mov [mt2], al
      mov di, 80 * 9
      mov si, mt2
      invk write_msg
      jmp .again
ret

start2:
....
   .again
      mov al, [scancode]
      mov [mt0], al
      mov di, 80 * 6
      mov si, mt0
      push ax
      invk write_msg
      pop ax
      cmp al, 0x81
      je .end
      jmp .again
   .end

   jmp 0x30:0
...
That print

Code: Select all

Hi. Welcome to the 5th PMode tutorial!  Protected mode is OK
We are in Protected Mode

? Task 0
? Task 1                                ? Task 2
That mean taht hae passed to task 0, 1, and 2. 1 is passed very fast... and imediate jump to 2.

If I delete the jump 0x30:0 and jump 0x38 and if I comment the first ret in
scheduler:
;ret
I get this error....

Code: Select all

00000652162p[CPU  ] >>PANIC<< fetch_raw_descriptor: LDTR.valid=0
00000652162i[SYS  ] Last time is 1116996020
00000652162i[CPU  ] protected mode
00000652162i[CPU  ] CS.d_b = 16 bit
00000652162i[CPU  ] SS.d_b = 16 bit
00000652162i[CPU  ] | EAX=00000020  EBX=00000030  ECX=00170003  EDX=00000d0c
00000652162i[CPU  ] | ESP=0000f7ce  EBP=00000000  ESI=00000002  EDI=000000ac
00000652162i[CPU  ] | IOPL=0 NV UP DI PL NZ NA PO NC
00000652162i[CPU  ] | SEG selector     base    limit G D
00000652162i[CPU  ] | SEG sltr(index|ti|rpl)     base    limit G D
00000652162i[CPU  ] |  DS:0010( 0002| 0|  0) 00010000 0000ffff 0 0
00000652162i[CPU  ] |  ES:0010( 0002| 0|  0) 00010000 0000ffff 0 0
00000652162i[CPU  ] |  FS:0020( 0004| 0|  0) 000b8000 0000ffff 0 0
00000652162i[CPU  ] |  GS:0020( 0004| 0|  0) 000b8000 0000ffff 0 0
00000652162i[CPU  ] |  SS:0018( 0003| 0|  0) 00010000 0000ffff 0 0
00000652162i[CPU  ] |  CS:0008( 0001| 0|  0) 00010000 0000ffff 0 0
00000652162i[CPU  ] | EIP=00000fe2 (00000fe0)
00000652162i[CPU  ] | CR0=0x60000011 CR1=0x00000000 CR2=0x00000000
00000652162i[CPU  ] | CR3=0x00000000 CR4=0x00000000
00000652162i[     ] restoring default signal behavior
00000652162i[CTRL ] quit_sim called with exit code 1
EIP = (Fe0 == 4064) -> OFFSETHERE JMP FAR [BX] ;this print [4064]
jmp far [bx]

I dont understand, If I can access at less one time with jumps, why I cant access, see that ESI=00000002 and EBX=00000030 that I think is correct....

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

Posted: Thu May 26, 2005 10:15 am
by hgb
Is the same jump far [bx] than jump 0x30:0 ???? if bx contain 0x30???

-----------------------------------

Ok, I have changed a little my code for check the thing about the far jump with [bx] and replace with a direct jump xxx:x, and aparently it work ok (for very short time...).

scheduler:

Code: Select all

scheduler:
   mov si, [cur_task]
   inc si
   cmp si, MAX_TASK
   jb .cont
      xor si, si
   .cont
   mov [cur_task], si
   jnz .nextcase1
      jmp 0x28:0
   .nextcase1
   cmp si, 1
   jnz .nextcase2
      jmp 0x30:0
   .nextcase2
      jmp 0x38:0
ret
tasks....

Code: Select all

mt0 db "  Task 0", 0
mt1 db "  Task 1", 0
mt2 db "  Task 2", 0
;couters
ct1 db "A"
ct2 db "A"
ct0 db "A"

task1:
   .again
      mov al, [ct1]
         inc al
      mov [ct1], al
      mov [mt1], al
      mov di, 80 * 8
      mov si, mt1
      invk write_msg
      jmp .again
ret
task2:
   .again
      mov al, [ct2];mov al, [scancode]
         inc al
      mov [ct2], al
      mov [mt2], al ; mov [scancode], al
      mov di, 80 * 9
      mov si, mt2
      invk write_msg
      jmp .again
ret


start2:
....
   call setup_pmode
      .again
      mov al, [ct0]
      inc al
      mov [mt0], al
      mov [ct0], al
      mov di, 80 * 6
      mov si, mt0
      push ax
      invk write_msg
      pop ax
      cmp al, 0x81
      je .end
      jmp .again
   .end
   invk shut_down
   ret
The error that bochs give is:

Code: Select all

00000653811p[CPU  ] >>PANIC<< task_switch: CS NULL
00000653811i[SYS  ] Last time is 1117123995
00000653811i[CPU  ] protected mode
00000653811i[CPU  ] CS.d_b = 16 bit
00000653811i[CPU  ] SS.d_b = 16 bit
00000653811i[CPU  ] | EAX=00000020  EBX=00000022  ECX=00000000  EDX=00000000
00000653811i[CPU  ] | ESP=000008dc  EBP=00000000  ESI=101b0000  EDI=028601aa
00000653811i[CPU  ] | IOPL=0 NV UP DI PL ZR NA PE NC
00000653811i[CPU  ] | SEG selector     base    limit G D
00000653811i[CPU  ] | SEG sltr(index|ti|rpl)     base    limit G D
00000653811i[CPU  ] |  DS:0000( 0000| 0|  0) 00010000 0000ffff 0 0
00000653811i[CPU  ] |  ES:0000( 0000| 0|  0) 00010000 0000ffff 0 0
00000653811i[CPU  ] |  FS:0000( 0000| 0|  0) 000b8000 0000ffff 0 0
00000653811i[CPU  ] |  GS:0000( 0000| 0|  0) 000b8000 0000ffff 0 0
00000653811i[CPU  ] |  SS:0000( 0000| 0|  0) 00010000 0000ffff 0 0
00000653811i[CPU  ] |  CS:0000( 0000| 0|  0) 00010000 0000ffff 0 0
00000653811i[CPU  ] | EIP=00000fe1 (00000fe1)
00000653811i[CPU  ] | CR0=0x60000019 CR1=0x00000000 CR2=0x00000000
00000653811i[CPU  ] | CR3=0x00000000 CR4=0x00000000
00000653811i[     ] restoring default signal behavior
00000653811i[CTRL ] quit_sim called with exit code 1
But there is printed the following in the screen.

Code: Select all

Hi. Welcome to the 5th PMode tutorial! Protected mode is OK
We are in Protected Mode

F Task 0
I Task 1                                             I task2

If all the c(ounter)t(ask)N are initializate to "A", task 0 as incremented 6 times and task1 and task2 8 times. But if there exist switch in that moment, what change the execution for cause that exception???

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

Posted: Thu May 26, 2005 1:01 pm
by Brendan
Hi,

It's late at night here, so I've only had a brief look, but..

The instruction "JMP far [BX]" is not the same as "JMP 0x30:0" if BX = 0x30. It jumps to the address stored at DS:BX, so if DS:BX = 0x0000:0x1234, and the address 0x0000:0x1234 contained the value 0x0030:0x????? (where the offset is ignored for a task switch) then you'd get the same result as "JMP far [BX]".

IRQ handlers need to end with an "IRET" instruction, rather than a "RET". Using RET instead would cause 2 values to be left on the interrupted task's stack each IRQ. Not sure if this is a bug, or if there's some other code somewhere else that calls these handlers.

There isn't enough code to figure out exactly what's going on - things like "invk write_msg" make me wonder what the "invk" macro is hiding..

Traditionally, assembly language is written with 3 completely seperate columns, one for labels, another for the instructions and the last for comments. Making labels line up with the instructions makes them difficult to find.

Your scheduler is messed up, as after doing a task switch the CPU will return to the instruction after the "JMP 0x??:0". Try something like this:

Code: Select all

;IRQ 0 - Switch to the next task

scheduler:
    cmp word [cur_task],1
    jb .task1
    je .task2

    mov word [cur_task],0
    jmp 0x28:0
    iret

.task1
    mov word [cur_task],1
    jmp 0x30:0
    iret

.task2
    mov word [cur_task],2
    jmp 0x38:0
    iret

Cheers,

Brendan

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

Posted: Thu May 26, 2005 6:55 pm
by hgb
A ya, I get the thing about the jmp [bx], but when I see that my code dosent work and cant figure out where the problem is I start changing things here and there, and perhaps moving more than the necesary... :S. My head was not clear for see the real diference :D.


And yes, there is other code that call the handlers :).


mmm the thing about assembly is the way that I organize it (sorry for that), it help me visualize the depth with a single look, tought some times is dificult because not always is posible and Im also unclear in some rules that I follow (that I forget time to time), and I havent cleaned it (a more strict way...).

I attach the source code like is now, for example it have a lot of comments and code comment out (I dont like them).

You only need do (if you whant to reconstruct the program)

nasmw t1.asm
nasmw disk.asm
or nasmw disk.asm -D emu for generate a file about the floppy size.

Actually I have returned somethings to near the start....

Code: Select all

%macro invk 1-*
   %rep %0-1
      %rotate -1
      push %1
   %endrep
   %rotate -1
   call %1
%endmacro


scheduler:
   mov si, [cur_task]
   inc si
   cmp si, MAX_TASK
   jb .cont
      xor si, si
   .cont
   mov [cur_task], si
   shl si, 1
   mov bx, [task_sel+si]
   push bx
   invk jump_to_tss
ret

jump_to_tss:
   push bp
   mov bp, sp
   jmp far [bp+2]
   pop bp
   ret 2
The error that I get nowis diferent from the anterior..., the anterior was ">>PANIC<< task_switch: CS NULL", now Im obtaining ">>PANIC<< load_seg_reg: GDT: SS: index(0200*8+7) > limit(00003f)" And eip is poiting aparently to a instruction that has been passed sometime ago... is the like the same result I obtain (in an anterior post) when I put SS=0x9000 in real mode and SS= 0x20 (the stack selector with a diferent base), I dont know why IP is trying execute those instructions, I havent pushed a address.. also why is there some switch before this happend???


Here are some guide (line numbers for functions finding)

120 jump_to_tss
154 taskList:
236 setup_GDT_entry
276 setup_IDT_entry
306 setup_GDT
469 setup_pmode
642 scheduler
677 timer_handler
708 task1

753 start2

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

Posted: Fri May 27, 2005 7:01 am
by Brendan
Hi,

I tried to find some bugs, but to be honest I think the best thing you could do is throw it all in the bin and start again - it looks like something a diseased dog vomitted up (sorry if this sounds harsh!).

Some questions:
- why are you using 16 bit protected mode instead of 32 bit protected mode?
- why are you using Pascal calling conventions when it's all in assembly?
- why do you use an assembly stub to call an assembly IRQ handler?
- how many different tutorials got squished together here?
- what is the intended purpose of the code?

The code in tutorials is mostly only meant to be read, and is provided to show the reader an example of how things work. Typically the reader would learn from them and then use this knowledge to implement (or add features to) their own code. Tutorials tend to skip things for the sake of simplicity - things that actual code would need to take into account (like writing memory managers before bothering with multi-tasking, and creating TSSs dynamically).

IMHO writing readable source is often more important than writing code that actually works - being readable makes it much easier to debug (and avoid bugs in the first place), and also makes it easier to maintain. Things like seperating unrelated source code into seperate files can help a lot, and IMHO using the same style throughout all source code is a must.

To show what I mean here I've attached some code I wrote ages ago. The attached code isn't perfect or very useful, but compare it with your code and tell me which would be easier to figure out in 5 years time....


Cheers,

Brendan

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

Posted: Fri May 27, 2005 7:53 am
by hgb
(sorry if this sounds harsh!)
In fact no, I will say that, but I see that probably you will not download it ;), then I keep silence ;). Also was for that screw in the code I write the line functions that I think you where interested in see.


- why are you using 16 bit protected mode instead of 32 bit protected mode?

Because in the tutorial is like is writed ;), also with this I see more practically the diference between the diferent granularity and such things.

- why are you using Pascal calling conventions when it's all in assembly?

Is more easy for me recognogize it, but I was thinking that it was stdcall :) and also the function called is the one that clean stack.

- why do you use an assembly stub to call an assembly IRQ handler?

It is writed like that in the tut I have watched certain things that confuse me time to time in the tut, for example, the stub in the tuts are terminated with a "iretd" and I think it should be a "iret" because is 16 bits.

- how many different tutorials got squished together here?

Im following only one tut :) (I have terminated another one is C, http://osdever.net/bkerndev/index.php?the_id=90 ) tought I have understood mainly what is explained there, I see the PMtuts by Alexei (writed in C/asm http://osdever.net/tutorials/pmodetuts/ ... ?the_id=36 ) and when I start them, I see that I must need run the programs from DOS box and things like that... and I think, now you know how to write a bootloader that load some sectors in memory, you already know that you will be in real mode, then why not pass the tuts to asm and practice your asm ;) in the run and check if you have understood what you do in the anterior tut, also Im using the CVS locally, tought I dont like how the code is writed, normally I dont use comments... but I was thinking if I give to somebody some day, they can compare the comments with the C code for see the parts taht correspond, now I think that was a bad argument for keep the C comments inline, also... when my program dont work and I dont see what Im doing wrong, I normally start modifying the code for see how it affect the whole (that is for what is there comment out) and perhaps here and there calling to the macro OFFSETHERE in fact you have a piece of code apart of contain C comments in the middle of debugging :S... yes is like look if you dont know where is it and dont have the tools or the knowledge to figure out what is the problem.

- what is the intended purpose of the code?

Im in the tut 7, is suposed to show 3 task running showing like counters.





By the way, good look in the piece of code that you give me, I do normally write functional/logic parts in the same source(when in C), but I was thinking that this code will not be so complicated like look now.







A side note, is suposed to be a raw transcription to asm....

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

Posted: Fri May 27, 2005 10:45 am
by mystran
A few points (I've not been following the thread, just trespassing).

- There's little point in doing a raw translation from a high-level language to ASM, whatever your definition of high-level. Even if the code can't be compiled, it doesn't need to be a big project before writing a new compiler (or macro assembler or whatever) is better idea. It's usually less work and introduces less bugs. You can also compile to C if the source-language allows that, so you get benefits of good C compilers (see below). Ofcourse if you need a general purpose, production quality compiler, then it's much more work, but...

- AFAIK there's some subtle differences between "pascal" and "stdcall" calling conventions. But if you are writing an OS, you should choose (or design) a calling convention based on what you need. Callee-pops is a good idea if (and only if, at least on IA-32) you are going to (1) always know the precise function signature, and (2) want to support general tail-calls. Pascal calling convention isn't really good for tail-calls so I see little point to use that. As for "easy to recognize", as long as you use the "CALL" instruction the calling convention is pretty much irrelevant for recognition.

- Forget about 16-bit protected mode. There's absolutely no good reason to use it. Big, flat heaps are a Good Thing.

- If you dislike comments, you either have never tried to maintain anything (or read someone elses code outside of tutorials), or you don't know how to comment well. Here's a good rule: your comments should say why, and you code should say how. In some case comments for what is also a good idea, especially if the code is "messy on purpose" (heavily optimized or kludgy or whatever) but in most cases a comment describing "what" indicates a problem with the code.

- Even if you absolutely want to write in assembler, it a really good idea to first write the code in some higher level language. Something like Ruby or Python is a good fit, although really low-level details can be prototyped in C. And if you happen to prototype in C, I'm going to laugh out loud when your hand-written code runs slower than the compiled C code. Compilers are quite good these days. In fact the best way to write fast code is most often to write C code, compile, then examine the generated code, and then tweak the C code to produce better assembly. :)

- There is little point to learn assembly programming well unless you plan to write native-code compilers in the future. For OS development purposes it suffices perfectly well to know enough about assembler to be able to read compiler generated assembler (with the original code available), and to be able to write the critical parts (ISRs mainly) that can't be done from C in a sane way.

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

Posted: Fri May 27, 2005 12:18 pm
by hgb
Im not writing my OS, I have other plans for it, but I will take care of the annotations that you guys are giving me. I will continue only with the points about pm in 16 bits for the end of this tutorials.


I have know a way to call that is mainly ok (I supose ;)) is like stdcall (calle "clean" the stack and pushed right to left) but have some benefits that I should take care when I will implement it (if is fast or not)
(1) always know the precise function signature, and (2) want to support general tail-calls.
With 1 you mean no varargs??? and I dont understand completely mean of 2.



About the not like commenting :D. I like a lot debate this thing :). Have you read the code of java? (I not read all only the parts that I was interested) I remember that was more easy read the real code (compact all the comments) and get the idea than read the comments (that was my case), also have readed others persons abusing from comments (x = t; //save t in x and things like WARNING: need to take care in the next ersions of this bad checking) what???, yes I also intend to write an assembler some day, and a feature was that it will not suport documentation or commentation inside the source code, becuse source code IS souce code, I remember a nice definition of a friend numa (I have lost contact with the guy, perhaps I will restore it later), but he say me that there is a intrinsic feature in the languages, he called understability, mean that between more comments or things you need to add to explain your code less understable is (dont remember the exact definition but was something like that). I have developed more my tools (in my mind based in this [like my assembler will not support comments forcing better writing and understandability... but other things will come ;)] and other concepts that I have from some time now) the code should be understanle the "what" and the "why" by itself, tought if you whant to be more clear or explicit for people that dont know about the language, methods and tools should be provided for help this, but please (in my case) not inside the source code. I can continue go on, but for the moment I think now you have the idea for what I dont like comments ;). By the way, when reading the java code, the how is understable in the code and the why looking at the whole, the comments and documentation should be in other place not inside (also in my point of view, is lame to learn diferent types for documentation inside the code for diferent languages... if the other ones have such a "feature" like java has).

I hae changed a program that some people say that is garbage and bad writed, peraphs it is, but some parts are understable.

By the way, another concept that I have take strong in my point of view is one by a guy (perhaps not so guy) called Rene, I only have readed something like "a source/code editor is a source/code editor", not a text editor.

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

Posted: Fri May 27, 2005 1:57 pm
by Kemp
One simple point, assembly is not like java or any other high-level language, past a certain point you can't just say "the code should be readable without comments". For instance, would you rather look at several hundred lines of assembly code and try to figure out what's going on with no help, or look at the same code with a comment every ten lines or so saying what's about to happen?

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

Posted: Fri May 27, 2005 11:09 pm
by hgb
Dont know Im not proeficient in asm (like perhaps you have watched...), but I like those concepts and whant to do more than only like the concepts :).

OK, returning to my things, I have cleaned it a litle, tought I dont have "throw it all" like Brendan say (I havent understood to this last read that say me delete to the recicle bin.. not delete the bin file...), the only one that I dont clean much is the thing about the ISR.. because like I say I where confused, in the tuts he use pushad popad iretd... but this is 16 bit code!!!!... I think the interrupt handler tought print OK the interrupt number and perhaps the argument (if there is), the address (segment:offset) is not printed OK.

In the attached file you only need uncompress and in the root dir type in a console

Code: Select all

do t7
That will create a padded file of about a floppy disk (this can be changed inside do.bat, deleting "-D emu", this is enabled for also test with quemu, quemu dosent recognogize files that are not equal to 1.44, but Bochs can)


That will print some warnings that I think dosent matter (invk setup_GDT_entry,..., byte ACS_CODE) those ACS_... are the ones that show the warnings.

After that and some messges from t7.asm and the files used a "_______________________________" will be printed, after that it will be launched again nasm for assemble d.asm and include automatically the file t7 created in the anterior call (without modify the code like in aterior versions).

I not attach or say more, best try like is now, and you say me if at less the "feel" has becomed a little more clean ;).

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

Posted: Fri May 27, 2005 11:09 pm
by Brendan
Hi,
Kemp wrote:One simple point, assembly is not like java or any other high-level language, past a certain point you can't just say "the code should be readable without comments".
Indeed - with assembly it takes many instructions to do the same work that would be done by a single high level language command, which makes it much harder to see what code is doing by looking at it. For example:

Code: Select all

    mov eax,0x0100
    mov ebx,string
    int 0x80
The above code works on my OS, but it's impossible to figure out what it does without searching through the kernel API reference, which would break your concentration if you're trying to follow something larger.

Also unlike high level languages, "variables" don't have names once they're in general registers. For example, EDI is EDI, not "pointer_to_the_current_position_in_the_video_buffer" or some other suitably descriptive variable name.

Then there's high level languages like C - if you think they're readable without comments you haven't tried to read the Linux kernel source code :). I've never actually seen any C or C++ source code that is readable or well commented. I think there's 2 problems - firstly C/C++ has no seperate column for comments and looks ugly once you add the comments. Secondly most programmers add comments where they think they are needed rather than where they are needed, because the code makes sense when you've just written it (but may not make sense to others, or to yourself later on).

To improve my own code's readability, I went further than plain comments and wrote a utility to convert source code into linked HTML. This helps a lot because you don't need to search through many different files to find where things like macros, variables and called functions are (and it handles things like different font sizes, bold, italic, etc). For an example, see here:

http://bcos.hopto.org/src/boot/boot144/1init-asm.html [edit: corrected]

BTW you can click on the link at the top right to see the raw ASCII source that was used to create the html page.

The problem with this approach is that it takes longer to write source like this, but as you can see it makes the source extremely easy to read and understand - so much so that I'm currently converting all of my publicly available source code to this format in my (lack of) spare time.


Cheers,

Brendan

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

Posted: Sat May 28, 2005 12:09 am
by hgb
link to the page *hotpot* ;).

That is nice but will be more nice if the code editor have that feature :)... imagine that in a way that you dont need to do manual tyiping of format for code, like switch to a diferent editor for documentation, but that let you insert in the place what you whant and keeping "clean" your code (without inserting the lines) also see source or documentation or both easy, and than inside the same editor, you can link like you do with html like intellisense. You will have two options like I see) for "delete the comments" :D, or let at the end of source code a mark that indicate where the documentation and commentation start, or extract the comments and documentation completely from the source code, but keep in coherence. That is a little more like I whant :) but there will be two separate files to maintain, the thing about a code editor is a source editor not a text editor make sense for this :). Also for example things like // WARNING... // TODO and things like that should be handled by external (tought I remember a debate about grep...) but I supose that will be a little arcaic If Im not wrong or I dont whant/know_how to use GREP :) (anyway, hope some day apply what I whant), also the versioning should serve for source code, documentation, errors, warnings, todo, new features, test, deprecated features and a lot of things that are done I supose manually.

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

Posted: Sat May 28, 2005 6:12 am
by Kemp
That link doesn't work btw

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

Posted: Sat May 28, 2005 7:24 am
by Brendan
Hi,
Kemp wrote: That link doesn't work btw
Thanks - I've fixed it now (I missed an 'o' ;) )...

My LAN is painful sometimes - from behind the firewall the IP address is 10.0.0.2 and not what the DNS server returns. I even checked apache's logs afterwards and decided it must be right:
201.138.101.157 - - [28/May/2005:15:04:30 +0930] "GET /src/boot/boot144/1init-asm.html HTTP/1.1" 200 6844 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; es-AR; rv:1.7.7) Gecko/20050414 Firefox/1.0.3"
I guess Rea must have figured it out at least :).


Thanks,

Brendan