diff --git a/trace_lbr.c b/trace_lbr.c index 06ab2de..e551eb0 100644 --- a/trace_lbr.c +++ b/trace_lbr.c @@ -57,24 +57,7 @@ void handle_sigtrap() { wrmsr(MSR_IA32_DEBUGCTLMSR, 3); } -uint32_t set_eflags_tf(uint32_t tf) { - uint32_t prev; - __asm__ __inline__ __volatile__ ( - "pushfd;" - "pop eax;" - "ror eax, 8;" - "mov edx, eax;" - "and edx, 1;" - "and eax, ~1;" - "or eax, ecx;" - "rol eax, 8;" - "push eax;" - "popfd" - : "=d"(prev) - : "c"(tf) - : "eax", "memory"); - return prev; -} +uint32_t set_eflags_tf(uint32_t tf); void trace_lbr_begin() { struct sigaction action; diff --git a/umka.asm b/umka.asm index a97f1f2..294ec1b 100644 --- a/umka.asm +++ b/umka.asm @@ -71,7 +71,7 @@ public new_sys_threads as 'kos_new_sys_threads' public osloop as 'kos_osloop' public set_mouse_data as 'kos_set_mouse_data' public scheduler_current as 'kos_scheduler_current' -public eth_input as 'kos_eth_input' +public kos_eth_input public net_buff_alloc as 'kos_net_buff_alloc' public mem_block_list @@ -328,6 +328,63 @@ proc umka._.check_alignment ret endp +public i40_asm + +;void i40_asm(uint32_t _eax, +; uint32_t _ebx, +; uint32_t _ecx, +; uint32_t _edx, +; uint32_t _esi, +; uint32_t _edi, +; uint32_t _ebp, +; uint32_t *_eax_out, +; uint32_t _ebx_out) +i40_asm: + ; Return address: esp + ; First argument: esp + 4 + push eax ebx ecx edx esi edi ebp + ; First argument: esp + 4 + 7 * sizeof(dword) = esp + 8 + 7 * 4 = esp + 4 + 28 = esp + 32 + mov eax, [esp + 32] + mov ebx, [esp + 36] + mov ecx, [esp + 40] + mov edx, [esp + 44] + mov esi, [esp + 48] + mov edi, [esp + 52] + mov ebp, [esp + 56] + call i40 + mov edi, [esp + 60] + mov [edi], eax + mov edi, [esp + 64] + mov [edi], ebx + pop ebp edi esi edx ecx ebx eax + ret + +public set_eflags_tf + +proc set_eflags_tf c uses ebx esi edi ebp, tf + mov ecx, [tf] + pushfd + pop eax + ror eax, 8 + mov edx, eax + and edx, 1 + and eax, 0xfffffffe + or eax, ecx + rol eax, 8 + push eax + popfd + mov eax, edx + ret +endp + +proc kos_eth_input c uses ebx esi edi ebp, buffer_ptr + push .retaddr + push [buffer_ptr] + jmp eth_input +.retaddr: + ret +endp + proc umka_init c uses ebx esi edi ebp mov [umka_initialized], 1 call umka._.check_alignment diff --git a/umka.h b/umka.h index a830212..5a0fc52 100644 --- a/umka.h +++ b/umka.h @@ -449,13 +449,13 @@ static inline size_t umka_new_sys_threads(uint32_t flags, void (*entry)(), void *stack) { size_t tid; __asm__ __inline__ __volatile__ ( - "push ebx;" - "push esi;" - "push edi;" + "push %%ebx;" + "push %%esi;" + "push %%edi;" "call kos_new_sys_threads;" - "pop edi;" - "pop esi;" - "pop ebx" + "pop %%edi;" + "pop %%esi;" + "pop %%ebx" : "=a"(tid) : "b"(flags), "c"(entry), @@ -467,9 +467,9 @@ umka_new_sys_threads(uint32_t flags, void (*entry)(), void *stack) { static inline void kos_enable_acpi() { __asm__ __inline__ __volatile__ ( - "pushad;" + "pusha;" "call enable_acpi;" - "popad" + "popa" : : : "memory", "cc"); @@ -478,11 +478,11 @@ kos_enable_acpi() { static inline void kos_acpi_call_name(void *ctx, const char *name) { __asm__ __inline__ __volatile__ ( - "pushad;" + "pusha;" "push %[name];" "push %[ctx];" "call acpi.call_name;" - "popad" + "popa" : : [ctx] "r"(ctx), [name] "r"(name) : "memory", "cc"); @@ -555,6 +555,8 @@ extern void *kos_acpi_dev_data; extern size_t kos_acpi_dev_size; extern void *kos_acpi_dev_next; +void kos_eth_input(void *buf); + STDCALL void* kos_kernel_alloc(size_t len); @@ -577,9 +579,9 @@ typedef struct { static inline void umka_stack_init() { __asm__ __inline__ __volatile__ ( - "pushad;" + "pusha;" "call kos_stack_init;" - "popad" + "popa" : : : "memory", "cc"); @@ -888,8 +890,8 @@ umka_find_next_task(int32_t priority) { find_next_task_t fnt; __asm__ __inline__ __volatile__ ( "call find_next_task;" - "setz al;" - "movzx eax, al" + "setz %%al;" + "movzx %%eax, %%al" : "=b"(fnt.appdata), "=D"(fnt.taskdata), "=a"(fnt.same) @@ -898,23 +900,27 @@ umka_find_next_task(int32_t priority) { return fnt; } +void i40_asm(uint32_t eax, + uint32_t ebx, + uint32_t ecx, + uint32_t edx, + uint32_t esi, + uint32_t edi, + uint32_t ebp, + uint32_t *eax_out, + uint32_t *ebx_out); + static inline void umka_i40(pushad_t *regs) { - __asm__ __inline__ __volatile__ ( - "push ebp;" - "mov ebp, %[ebp];" - "call i40;" - "pop ebp" - : "=a"(regs->eax), - "=b"(regs->ebx) - : "a"(regs->eax), - "b"(regs->ebx), - "c"(regs->ecx), - "d"(regs->edx), - "S"(regs->esi), - "D"(regs->edi), - [ebp] "Rm"(regs->ebp) - : "memory"); + i40_asm(regs->eax, + regs->ebx, + regs->ecx, + regs->edx, + regs->esi, + regs->edi, + regs->ebp, + ®s->eax, + ®s->ebx); } static inline void @@ -1338,20 +1344,15 @@ static inline void umka_sys_put_image_palette(void *image, size_t xsize, size_t ysize, size_t x, size_t y, size_t bpp, void *palette, size_t row_offset) { - __asm__ __inline__ __volatile__ ( - "push ebp;" - "mov ebp, %[row_offset];" - "call i40;" - "pop ebp" - : - : "a"(65), - "b"(image), - "c"((xsize << 16) + ysize), - "d"((x << 16) + y), - "S"(bpp), - "D"(palette), - [row_offset] "Rm"(row_offset) - : "memory"); + pushad_t regs = { 0 }; + regs.eax = 65; + regs.ebx = (uintptr_t)image; + regs.ecx = (xsize << 16) + ysize; + regs.edx = (x << 16) + y; + regs.esi = bpp; + regs.edi = (uintptr_t)palette; + regs.ebp = row_offset; + umka_i40(®s); } static inline void diff --git a/vnet.c b/vnet.c index 0e44e75..b00cb0b 100644 --- a/vnet.c +++ b/vnet.c @@ -93,15 +93,5 @@ void vnet_receive_frame(net_device_t *dev, void *data, size_t size) { buf->device = dev; buf->offset = offsetof(net_buff_t, data); memcpy(buf->data, data, size); - __asm__ __inline__ __volatile__ ( - "pushad;" - "lea ecx, 1f;" - "push ecx;" - "push eax;" - "jmp kos_eth_input;" - "1:" - "popad" - : - : "a"(buf) - : "memory", "ecx"); + kos_eth_input(buf); }