unsigned

Bran的内核开发教程(bkerndev)-04 创建main函数和链接C文件

非 Y 不嫁゛ 提交于 2019-11-26 18:53:08
目录 创建main函数和链接C文件 PS: 下面是我自己写的 Win10安装gcc编译器 本节教程对应的Linux下的编译脚本 _main的问题 创建main函数和链接C文件   一般C语言使用main()函数作为程序的入口点, 为了符合我们平时的编程习惯, 这里我们也使用main()函数作为C代码的入口点, 并在"start.asm"文件中添加中断服务程序来调用C函数。   在这一节教程,我们将尝试创建一个"main.c"文件和一个包含常用函数原型的头文件"system.h"。"main.c"中包含mian()函数, 它将作为你C代码的入口。在内核开发中, 我们一般不从main()函数返回。多数操作系统在main中初始化内核和子程序、加载shell, 然后main函数会进入空循环中。在多任务系统中, 当没有其他需要运行的任务时, 将一直执行这个空循环。下面是"main.c"文件的示例,其中包含了最基本的main()函数和一些我们以后会用到的函数体。 main.c #include <system.h> /* 你将要自己完成这些代码 */ unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count) { /* 在此处添加代码, 将'src'中count字节的数据复制到'dest'中,

Bran的内核开发教程(bkerndev)-06 全局描述符表(GDT)

醉酒当歌 提交于 2019-11-26 18:52:27
全局描述符表(GDT)   在386平台各种保护措施中最重要的就是全局描述符表(GDT)。GDT为内存的某些部分定义了基本的访问权限。我们可以使用GDT中的一个索引来生成段冲突异常, 让内核终止执行异常的进程。现代操作系统大多使用"分页"的内存模式来实现该功能, 它更具通用性和灵活性。GDT还定义了内存中的的某个部分是可执行程序还是实际的数据。GDT还可定义任务状态段(TSS)。TSS一般在基于硬件的多任务处理中使用, 所以我们在此并不做讨论。需要注意的是TSS并不是启用多任务的唯一方法。   注意GRUB已经为你安装了一个GDT, 如果我们重写了加载GRUB的内存区域, 将会丢弃它的GDT, 这会导致"三重错误(Triple fault)"。简单的说, 它将重置机器。为了防止该问题的发生, 我们应该在已知可以访问的内存中构建自己的GDT, 并告诉处理器它在哪里, 最后使用我们的新索引加载处理器的CS、DS、ES、FS和GS寄存器。CS寄存器就是代码段, 它告诉处理器执行当前代码的访问权限在GDT中的偏移量。DS寄存器的作用类似, 但是数据段, 定义了当前数据的访问权限的偏移量。ES、FS和GS是备用的DS寄存器, 对我们并不重要。   GDT本身是64位的长索引列表。这些索引定义了内存中可访问区域的起始位置和大小界限, 以及与该索引关联的访问权限。通常第一个索引,

performance of unsigned vs signed integers

拜拜、爱过 提交于 2019-11-26 18:46:59
Is there any performance gain/loss by using unsigned integers over signed integers? If so, does this goes for short and long as well? Division by powers of 2 is faster with unsigned int , because it can be optimized into a single shift instruction. With signed int , it usually requires more machine instructions, because division rounds towards zero , but shifting to the right rounds down . Example: int foo(int x, unsigned y) { x /= 8; y /= 8; return x + y; } Here is the relevant x part (signed division): movl 8(%ebp), %eax leal 7(%eax), %edx testl %eax, %eax cmovs %edx, %eax sarl $3, %eax And

Unsigned Integer in Javascript

我怕爱的太早我们不能终老 提交于 2019-11-26 18:40:47
I'm working on a page that processes IP address information, but it's choking on the fact that integers are signed. I am using bitwise operators to speed it up, but the 64th bit (signed/unsigned flag) is messing it up. Is there any way to force a number to be unsigned in Javascript? It seems to work fine, until subnet is greater than 30, or less than 2. Try this: <html> <body> <script type='text/javascript'> document.write( (1 << 30) +"<br/>"); document.write( (1 << 31) +"<br/>"); document.write( (1 << 32) +"<br/>"); </script> </body> </html> Result: 1073741824 -2147483648 1 document.write( (1

How to use the unsigned Integer in Java 8 and Java 9?

此生再无相见时 提交于 2019-11-26 18:38:09
In the Oracle "Primitive data types" page , it mentions that Java 8 adds support for unsigned ints and longs: int : By default, the int data type is a 32-bit signed two's complement integer, which has a minimum value of −2 31 and a maximum value of 2 31 −1. In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 2 32 −1. Use the Integer class to use int data type as an unsigned integer. See the section The Number Classes for more information. Static methods like compareUnsigned , divideUnsigned etc

linux环境下 C++性能测试工具 gprof + kprof + gprof2dot【转】

岁酱吖の 提交于 2019-11-26 18:31:26
原文: http://www.cnblogs.com/rocketfan/archive/2009/11/15/1603465.html 1.gprof 很有名了,google下很多教程 g++ -pg -g -o test test.cc ./test //会生成gmon.out gprof ./test > prof.log 看一下对于我前面提到的huffman编码压缩+解码解压缩全部过程的一个程序 对于生成的prof.log ,wow, 很有用处的但是看起来有点累,不是吗:) Code Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 32.51 1.71 1.71 13127166 0.00 0.00 glzip::HuffTree<unsigned char, glzip::decode_hufftree>::decode_byte(unsigned char, glzip::Buffer&, glzip::HuffNode<unsigned char>*&, int) 18.73 2.69 0.98 105017328 0.00 0.00 glzip::Buffer:

Java equivalent of unsigned long long?

我是研究僧i 提交于 2019-11-26 18:25:18
In C++, I enjoyed having access to a 64 bit unsigned integer, via unsigned long long int , or via uint64_t . Now, in Java longs are 64 bits, I know. However, they are signed. Is there an unsigned long (long) available as a Java primitive? How do I use it? Sean Bright I don't believe so. Once you want to go bigger than a signed long, I think BigInteger is the only (out of the box) way to go. Starting Java 8, there is support for unsigned long (unsigned 64 bits). The way you can use it is: Long l1 = Long.parseUnsignedLong("17916881237904312345"); To print it, you can not simply print l1, but you

bit shifting with unsigned long type produces wrong results

随声附和 提交于 2019-11-26 17:51:52
I'm a bit confused because I wanted to initialize a variable of type unsigned long whose size is 8 bytes on my system (on every modern system I suppose). When I want to assign 1 << 63 to the variable, I get a compiler warning however and the number is in fact 0. When I do 1 << 30 I get the expected result of 2 ^ 30 = 1073741824 . Yet when I do 1 << 31 , I get the result of 2 ^ 64 (I think; actually this shouldn't be possible) which prints 18446744071562067968 . Can anyone explain this behaviour to me? 1 << 63 will be computed in int arithmetic, and your int is probably 32 bit. Remedy this by

How does an adder perform unsigned integer subtraction?

拜拜、爱过 提交于 2019-11-26 17:16:01
问题 Suppose that A and B are signed positive integers, then for A-B , it's calculated using A+2 's complement of B . For example, in a 4-bit binary system, for signed integers, we have 7-3=0111-0011=0111+1101=(1)0100 , the 1 in the bracket is the carry bit. According to the overflow rule for signed integer, we know there is no overflow and the result is therefore correct. However, for unsigned integers, what will happen if we calculate 7-3 ? If we use the same way we mentioned above: 7-3=0111

测试

倾然丶 夕夏残阳落幕 提交于 2019-11-26 17:15:06
目录  物理内存 物理内存描述 节点 pg_data_t 管理区zone  page 页表 物理内存初始化 memblock 页表建立 ARM32 页表映射 ARM64 页表映射 内存布局 ARM32 内存布局 ARM64 内存布局 物内存分配 linux内存管理 2019-05-05 by jinliang  物理内存 内存结构: 物理内存描述 内存模型: UMA 一致性内存访问 NUMA 非一致性内存访问 查看手机发现CONFIG_NUMA未定义,所以当前手机为UMA模型 节点 pg_data_t pg_data_t用于表示节点的基本元素,定义如下: ./include/linux/mmzone.h typedef struct pglist_data { //包含了节点中各个内存域的数据结构,最大3个,不足的话,其余数组用0填充. struct zone node_zones[MAX_NR_ZONES]; //制定了备用节点机器内存域的列表,以便在当前节点没有可用空间时,在备用节点分配内存. struct zonelist node_zonelists[MAX_ZONELISTS]; //节点中不同内存域的数目保存在nr_zones中. int nr_zones; #ifdef CONFIG_FLAT_NODE_MEM_MAP /* means !SPARSEMEM */