inline-assembly

Help in building an 16 bit os

霸气de小男生 提交于 2019-12-04 14:10:06
I am trying to build an old 16 bit DOS like OS. My example kernel code: asm(".code16\n"); void putchar(char); int main() { putchar('A'); return 0; } void putchar(char val) { asm("movb %0, %%al\n" "movb $0x0E, %%ah\n" "int $0x10\n" : :"r"(val) ) ; } This is how I compile it : nasm -f bin -o ./bin/boot.bin ./source/boot.asm gcc -nostdinc -fno-builtin -I./include -c -o ./bin/kernel.o ./source/kernel.c ld -Ttext=0x9000 -o ./bin/kernel.bin ./bin/kernel.o -e 0x0 dd if=/dev/zero of=./bin/empty.bin bs=1440K count=1 cat ./bin/boot.bin ./bin/kernel.bin ./bin/empty.bin|head -c 1440K > ./bin/os rm ./bin

Keyboard interrupt handler for own kernel (C)

孤街浪徒 提交于 2019-12-04 13:15:04
I am writing a tiny OS as part of an assigment for school,but I got stuck when it comes to get keyboard input (press a key -> display it on screen). I am using the Bare Bones tutorial from osdev.org (gcc cross-compiler, GRUB bootloader, ld linker) and since I am in protected mode I can not use BIOS interrupts for input, that's why I have to write my own interrupt handler (?) but I'm not sure how to do that even after I read some osdev articles and forum discussions. Very similar problem ( http://forum.osdev.org/viewtopic.php?f=1&t=9746 ) except that I don't know how to "set up the interrupts".

Compile an asm bootloader with external c code

寵の児 提交于 2019-12-04 12:49:27
问题 I write a boot loader in asm and want to add some compiled C code in my project. I created a test function here: test.c __asm__(".code16\n"); void print_str() { __asm__ __volatile__("mov $'A' , %al\n"); __asm__ __volatile__("mov $0x0e, %ah\n"); __asm__ __volatile__("int $0x10\n"); } And here is the asm code (the boot loader): hw.asm [org 0x7C00] [BITS 16] [extern print_str] ;nasm tip start: mov ax, 0 mov ds, ax mov es, ax mov ss, ax mov sp, 0x7C00 mov si, name call print_string mov al, ' '

`ldm/stm` in gcc inline ARM assembly

孤者浪人 提交于 2019-12-04 10:11:42
I am trying to create an ldm (resp. stm ) instruction with inline assembly but have problems to express the operands (especially: their order). A trivial void *ptr; unsigned int a; unsigned int b; __asm__("ldm %0!,{%1,%2}" : "+&r"(ptr), "=r"(a), "=r"(b)); does not work because it might put a into r1 and b into r0 : ldm ip!, {r1, r0} ldm expects registers in ascending order (as they are encoded in a bitfield) so I need a way to say that the register used for a is lower than this of b . A trivial way is the fixed assignment of registers: register unsigned int a asm("r0"); register unsigned int b

arm Inline assembly in gcc

孤人 提交于 2019-12-04 09:56:16
I have some trouble with some inline assembly code. I know what should be done but I miss the "how" ! I have this checksum function that is "almost" working : static unsigned long cksum_unroll( unsigned short **w, int *mlen) { int len; unsigned short *w0; unsigned long sum=0; len = *mlen; w0 = *w; while( len >= 8) { asm volatile ( "ldmia %[w0]!, {v1, v2}\n\t" "adds %[sum], %[sum], v1\n\t" "adcs %[sum], %[sum], v2\n\t" "adcs %[sum], %[sum], #0" : [sum] "+r" (sum) : [w0] "r" (w0) ); len -= 8; } *mlen = len; *w = w0; return (sum); } My problem, I believe, is on the line " : [sum] "+r" (sum) : [w0

GCC INLINE ASSEMBLY Won't Let Me Overwrite $esp

二次信任 提交于 2019-12-04 07:38:37
I'm writing code to temporarily use my own stack for experimentation. This worked when I used literal inline assembly. I was hardcoding the variable locations as offsets off of ebp. However, I wanted my code to work without haivng to hard code memory addresses into it, so I've been looking into GCC's EXTENDED INLINE ASSEMBLY. What I have is the following: volatile intptr_t new_stack_ptr = (intptr_t) MY_STACK_POINTER; volatile intptr_t old_stack_ptr = 0; asm __volatile__("movl %%esp, %0\n\t" "movl %1, %%esp" : "=r"(old_stack_ptr) /* output */ : "r"(new_stack_ptr) /* input */ ); The point of

Impossible constraint with cmpxchg16b in extended assembly

一笑奈何 提交于 2019-12-04 06:51:55
问题 I am trying to write inline assembly with my C code to perform compare and swap operation. My code is: typedef struct node { int data; struct node * next; struct node * backlink; int flag; int mark; } node_lf; typedef struct searchfrom { node_lf * current; node_lf * next; } return_sf; typedef struct csArg { node_lf * node; int mark; int flag; } cs_arg; typedef struct return_tryFlag { node_lf * node; int result; } return_tf; static inline node_lf cs(node_lf * address, cs_arg *old_val, cs_arg

How to determine values saved on the stack?

匆匆过客 提交于 2019-12-04 06:35:26
I'm doing some experimenting and would like to be able to see what is saved on the stack during a system call (the saved state of the user land process). According to http://lxr.linux.no/#linux+v2.6.30.1/arch/x86/kernel/entry_32.S it shows that the various values of registers are saved at those particular offsets to the stack pointer. Here is the code I have been trying to use to examine what is saved on the stack (this is in a custom system call I have created): asm("movl 0x1C(%esp), %ecx"); asm("movl %%ecx, %0" : "=r" (value)); where value is an unsigned long. As of right now, this value is

a Simple “Hello World” Inline Assembly language Program in C/C++

我们两清 提交于 2019-12-04 06:00:09
i use devcpp and borland c compiler.... asm { mov ax,4 // (I/O Func.) mov bx,1 // (Output func) mov cx,&name // (address of the string) mov dx,6 // (length of the string) int 0x21 // system call } in the above code snippets i want to print a string with the help of assembly language... but how can i put the address of the string in register cx.... is there something wrong in code??? I don't have the Borland compiler on hand, so I might be misremembering its syntax, but have you tried this: asm { mov ax,4 // (I/O Func.) mov bx,1 // (Output func) lds cx,"Hello, world" // (address of the string)

Converting C code to x86-64 assembly

青春壹個敷衍的年華 提交于 2019-12-04 05:52:05
问题 I'm trying to convert my C code to x86-64. My goal is to reverse a linked list. The two parameters that are passed in are the head ptr and the offset to to get the address of the pointer field (i.e. the pointer to the next node in the list). From what I understand, the head ptr is passed in through the rdi register, and the offset is passed in through the rsi register. I keep getting a segmentation fault when it reaches the line "mov rcx, [rbx]." The segmentation fault goes away when it's