21
Lowlevel-Coding / Problem mit GCC Inline Assembly
« am: 22. March 2005, 20:04 »
ausserdem statt %0 $0 falls du 0 ins cs haben willst (warum eignetlich?)
17. September 2024, 01:42
Diese Sektion erlaubt es dir alle Beiträge dieses Mitglieds zu sehen. Beachte, dass du nur solche Beiträge sehen kannst, zu denen du auch Zugriffsrechte hast.
[global _timer_int]
[extern _task_scheduler]
_timer_int:
cli
pusha ;Save registers
push ds
push es
push fs
push gs
call _task_scheduler ;Call C Scheduler
mov esp, eax ;Put return value(eax) into esp
;Send EOI to PIC
mov al, 0x20
out 0x20, al
pop gs
pop fs
pop es
pop ds
popa
sti
iret
/*-------------------------------------------------------------------------------------------
Delta Nanocore
This file is part of the implementation of Delta Nanocore.
You may use this code to understand how things work, but
you may NOT copy/use this code for your own purposes.
If you want to, you need permission by the Author of this code (Clemens Brust).
You may distribute the binaries for free. If you want to sell them, ask the Author
for permission.
Copyright (C) 2005 by Clemens-Alexander Brust
-------------------------------------------------------------------------------------------*/
struct task
{
unsigned long t_esp;
unsigned long t_id;
unsigned long t_cr3;
char* t_descriptor;
};
struct task_node
{
struct task t_task;
struct task_node* prev;
struct task_node* next;
};
struct task_node* task_current;
unsigned long task_enable=0;
unsigned long esptarget;
unsigned long cr3target;
// Prototypes:
struct task_node* task_init();
unsigned long task_add(unsigned long t_eip, unsigned long t_esp, unsigned long t_id, unsigned long t_cr3, char* descriptor);
struct task_node* task_last();
struct task_node* task_first();
void task_unlink(struct task_node* tnode);
void task_attach(struct task_node* tnode);
void task_next();
unsigned long task_scheduler();
void task_store_data();
//Implementations
struct task_node* task_init()
{
task_current=kmalloc(sizeof(struct task_node));
if(task_current==0)
return 0;
task_current->prev=0;
task_current->next=0;
task_current->t_task.t_id=0;
task_current->t_task.t_esp=read_esp();
task_current->t_task.t_cr3=read_cr3();
task_current->t_task.t_descriptor="Nanocore";
task_enable=1;
return task_current;
}
unsigned long task_add(unsigned long t_eip, unsigned long t_esp, unsigned long t_id, unsigned long t_cr3, char* descriptor)
{
struct task_node* tnode=0;
tnode=kmalloc(sizeof(struct task_node));
if(tnode==0)
{
return 0;
}
tnode->t_task.t_esp=t_esp;
*(unsigned long*)t_esp=t_eip;
asm("cli");
unsigned long tmp_esp=read_esp();
write_esp(t_esp-4);
asm("pushal");
asm("push %ds");
asm("push %es");
asm("push %fs");
asm("push %gs");
write_esp(tmp_esp);
tnode->t_task.t_id=t_id;
tnode->t_task.t_cr3=t_cr3;
tnode->t_task.t_descriptor=descriptor;
tnode->prev=task_current;
task_attach(tnode);
asm("sti");
return;
}
struct task_node* task_last()
{
struct task_node* p=task_current;
while(p->next)
{
p=p->next;
}
return p;
}
struct task_node* task_first()
{
struct task_node* p=task_current;
while(p->prev)
{
p=p->prev;
}
return p;
}
void task_unlink(struct task_node* tnode)
{
if(tnode)
{
if(tnode->next)
tnode->next->prev=tnode->prev;
if(tnode->prev)
tnode->prev->next=tnode->next;
}
return;
}
void task_attach(struct task_node* tnode)
{
task_last()->next=tnode;
return;
}
void task_next()
{
if(task_current->next)
{
task_current=task_current->next;
}
else
{
task_current=task_first();
}
return;
}
unsigned long task_scheduler()
{
printm("task_scheduler","test");
if(task_enable)
{
task_store_data(); // Save
task_next(); // All the logic is in there
printm("using task",task_current->t_task.t_descriptor);
char esp_d[8];
itoa(esp_d,'x',task_current->t_task.t_esp);
printm("esp",esp_d);
return task_current->t_task.t_esp; //<<<<<------ ERROR!
}
printm("task_scheduler","done");
return read_esp();
}
void task_store_data()
{
task_current->t_task.t_esp=read_esp();
task_current->t_task.t_cr3=read_cr3();
return;
}
align 4
_ncvesa_bits:
resb 4
align 4
_ncvesa_fbaddr:
resb 4
align 4
_ncvem_w:
resb 4
align 4
_ncvem_h:
resb 4
_ncvesa_init:
push ebp
mov ebp, esp
mov eax, DWORD PTR [ebp+8]
mov DWORD PTR _ncvem_w, eax
mov eax, DWORD PTR [ebp+12]
mov DWORD PTR _ncvem_h, eax
mov eax, DWORD PTR [ebp+20]
mov DWORD PTR _ncvesa_bits, eax
mov eax, DWORD PTR [ebp+16]
mov DWORD PTR _ncvesa_fbaddr, eax
pop ebp
ret
_setpixel:
push ebp
mov ebp, esp
push ebx
sub esp, 36
mov eax, DWORD PTR _ncvem_w
mov DWORD PTR [esp+8], eax
mov eax, DWORD PTR [ebp+12]
mov DWORD PTR [esp+4], eax
mov eax, DWORD PTR [ebp+8]
mov DWORD PTR [esp], eax
call _pixelpos
add eax, DWORD PTR _ncvesa_fbaddr
mov DWORD PTR [ebp-8], eax
mov eax, DWORD PTR [ebp-8]
mov DWORD PTR [ebp-12], eax
cmp DWORD PTR _ncvesa_bits, 32
jne L3
mov edx, DWORD PTR [ebp-12]
movzx eax, BYTE PTR [ebp+16]
mov BYTE PTR [edx], al
lea eax, [ebp-12]
inc DWORD PTR [eax]
mov edx, DWORD PTR [ebp-12]
movzx eax, BYTE PTR [ebp+17]
mov BYTE PTR [edx], al
lea eax, [ebp-12]
inc DWORD PTR [eax]
mov edx, DWORD PTR [ebp-12]
movzx eax, BYTE PTR [ebp+18]
mov BYTE PTR [edx], al
lea eax, [ebp-12]
inc DWORD PTR [eax]
mov eax, DWORD PTR [ebp-12]
mov BYTE PTR [eax], 0
L3:
cmp DWORD PTR _ncvesa_bits, 24
jne L4
mov edx, DWORD PTR [ebp-12]
movzx eax, BYTE PTR [ebp+16]
mov BYTE PTR [edx], al
lea eax, [ebp-12]
inc DWORD PTR [eax]
mov edx, DWORD PTR [ebp-12]
movzx eax, BYTE PTR [ebp+17]
mov BYTE PTR [edx], al
lea eax, [ebp-12]
inc DWORD PTR [eax]
mov edx, DWORD PTR [ebp-12]
movzx eax, BYTE PTR [ebp+18]
mov BYTE PTR [edx], al
L4:
cmp DWORD PTR _ncvesa_bits, 16
jne L2
mov eax, DWORD PTR [ebp-12]
mov DWORD PTR [ebp-16], eax
mov ebx, DWORD PTR [ebp-16]
movzx eax, BYTE PTR [ebp+18]
shr al, 3
movzx eax, al
mov edx, eax
sal edx, 7
movzx eax, BYTE PTR [ebp+17]
shr al, 2
movzx eax, al
lea eax, [eax+edx]
mov ecx, eax
sal ecx, 4
movzx eax, BYTE PTR [ebp+16]
shr al, 3
movzx dx, al
mov eax, ecx
add eax, edx
mov WORD PTR [ebx], ax
L2:
add esp, 36
pop ebx
pop ebp
ret
_pixelpos:
push ebp
mov ebp, esp
mov eax, DWORD PTR [ebp+12]
imul eax, DWORD PTR [ebp+16]
add eax, DWORD PTR [ebp+8]
pop ebp
ret
long pixelpos(unsigned long x, unsigned long y, unsigned long w);
void setpixel(unsigned long x, unsigned long y, nc_color c);
void ncvesa_init(long w, long h, char* framebuffer,long bits);
typedef struct{
unsigned char r,
unsigned char g,
unsigned char b} nc_colorTAG nc_color;
long ncvesa_bits=0;
char* ncvesa_fbaddr=0;
long ncvem_w=0;
long ncvem_h=0;
/*16-Bit-Farben
/°5°\/°°6°\/°5°\
RRRRRGGGGGGBBBBB
BBBBBBBBBBBBBBBB*/
void ncvesa_init(long w, long h, char* framebuffer,long bits)
{
ncvem_w=w;
ncvem_h=h;
ncvesa_bits=bits;
ncvesa_fbaddr=framebuffer;
}
void setpixel(unsigned long x, unsigned long y, nc_color c)
{
char* pixeladdr=pixelpos(x,y,ncvem_w)+ncvesa_fbaddr;
if(ncvesa_bits==32)
{
*pixeladdr=c.r;
pixeladdr++;
*pixeladdr=c.g;
pixeladdr++;
*pixeladdr=c.b;
pixeladdr++;
*pixeladdr=0;
}
if(ncvesa_bits==24)
{
*pixeladdr=c.r;
pixeladdr++;
*pixeladdr=c.g;
pixeladdr++;
*pixeladdr=c.b;
}
if(ncvesa_bits==16)
{
short* hpixeladdr=pixeladdr;
*hpixeladdr=(r/8)+((g/4)*16)+((b)/8)*2048);
}
}
char* pixelpos(long x, long y, long w)
{
return((char*)(y*w)+x);
}
debug_print:
mov es,0xB800
xor di,di
mov cx, 80*2*25
xor ax, ax
rep stosb
mov es,0xB800
xor di,di
debug_print.1:
lodsb
or al, al
jz debug_print.2
stosb
mov al, 12
stosb
jmp debug_print.1
debug_print.2:
ret