The source code for the BeOS operating system has surfaced on the Internet, this is a very interesting source code leak.
This is part of the source code for the BIOS functionality of the BeOS operating system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | #include <drivers/KernelExport.h> #include <apm.h> #include "bios.h" #include "cpu_asm.h" #include "platform.h" struct regs { uint32 eax, ecx, edx, ebx, ebp, esi, edi; }; extern int int86(uchar intnum, struct regs *in, struct regs *out); #define CF 0x0001 #define ZF 0x0040 uchar *scratch; void set_video_mode(uchar modenum) { struct regs r; r.eax = modenum; int86(0x10, &r, &r); } int bios_key_hit(void) { struct regs r; r.eax = 0x100; /* ZF clear if key available */ return (int86(0x16, &r, &r) & ZF) ? 0 : (r.eax & 0xffff); } int bios_get_key(void) { struct regs r; r.eax = 0; int86(0x16, &r, &r); return (r.eax & 0xffff); } int bios_shift_state(void) { struct regs r; r.eax = 0x200; int86(0x16, &r, &r); return (r.eax & 0xff); } void bios_move_cursor(int x, int y) { struct regs r; r.eax = 0x200; r.ebx = 0; r.edx = y * 0x100 + x; int86(0x10, &r, &r); } status_t bios_get_number_hard_drives(void) { struct regs r; r.eax = 0x800; r.edx = 0x80; if (int86(0x13, &r, &r) & CF) { dprintf("Error fetching drive parameters\n"); return B_ERROR; } return (r.edx & 0xff); } status_t get_drive_geometry(uint32 id, device_geometry *geometry) { struct regs r; r.eax = 0x800; r.edx = id & 0xff; if (int86(0x13, &r, &r) & CF) { dprintf("Error getting drive geometry for 0x%lx\n", id); return B_ERROR; } geometry->cylinder_count = ((r.ecx & 0xff00) >> 8) + ((r.ecx & 0xc0) << 2) + 1; geometry->sectors_per_track = r.ecx & 0x3f; geometry->head_count = ((r.edx & 0xff00) >> 8) + 1; geometry->bytes_per_sector = 0x200; /* workaround for bad CD-floppy emulation geometry reported by ACER * TravelMate 512T laptop (cx = 0x5012, dh = 0x02) */ if ( (geometry->cylinder_count == 81) && (geometry->sectors_per_track == 18) && (geometry->head_count == 3)) { geometry->cylinder_count--; geometry->head_count--; } return B_OK; } #if 0 status_t get_extended_drive_geometry(uint32 device_cookie, device_geometry *geometry) { struct regs r; r.eax = 0x4800; r.edx = device_cookie & 0xff; r.esi = 0x1000; if ((int86(0x13, &r, &r) & CF) == 0) { geometry->cylinder_count = *(uint64 *)(scratch + 0x10); geometry->sectors_per_track = 1; geometry->head_count = 1; geometry->bytes_per_sector = *(uint16 *)(scratch + 0x18); /* vyt: more sanity checking */ if (geometry->cylinder_count && geometry->bytes_per_sector) return B_OK; } return get_normal_drive_geometry(device_cookie, geometry); } #endif |
Some assembly routines that are related to the boot process.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | /***** Copyright (C) 1996-97 Intel Corporation. All rights reserved. *** *** The information and source code contained herein is the exclusive *** property of Intel Corporation and may not be disclosed, examined *** or reproduced in whole or in part without explicit written authorization *** from the company. **/ /* * cpu_asm.S contains cpu dependent assembly routines * taken mostly from the kernel cpu_asm.S, minus APIC stuff. */ #include <asm.h> .text ENTRY(enable_interrupts) sti ret ENTRY(disable_interrupts) pushf /* push the eflags register */ popl %eax /* and pop it into eax */ movl $0x200, %ecx /* load the IF (interrupt flag) mask */ andl %ecx, %eax /* mask out the IF bit (as a return value) */ cli /* disable interrupts */ ret ENTRY(restore_interrupts) movl 4(%esp), %eax /* load the old IF status */ cmpl $0, %eax /* if it was zero, skip restoring IF */ je restore_interrupts1 pushf /* push the eflags register */ popl %eax /* pop it into eax */ orl $0x200, %eax /* OR in the IF bit */ pushl %eax /* push eax on the stack */ popf /* and pop it back into eflags */ restore_interrupts1: ret /* * get_cpu_id */ ENTRY(get_cpu_id) xorl %eax, %eax ret ENTRY(read_io_8) xorl %eax, %eax movl 4(%esp), %edx /* get I/O port address in edx */ inb %dx, %al ret ENTRY(write_io_8) xorl %eax, %eax movl 4(%esp), %edx /* I/O port address */ movl 8(%esp), %eax /* value */ outb %al, %dx ret ENTRY(read_io_16) xorl %eax, %eax movl 4(%esp), %edx /* get I/O port address in edx */ inw %dx, %ax ret ENTRY(write_io_16) xorl %eax, %eax movl 4(%esp), %edx /* I/O port address */ movl 8(%esp), %eax /* value */ outw %ax, %dx ret ENTRY(read_io_32) xorl %eax, %eax movl 4(%esp), %edx /* get I/O port address in edx */ inl %dx, %eax ret ENTRY(write_io_32) xorl %eax, %eax movl 4(%esp), %edx /* I/O port address */ movl 8(%esp), %eax /* value */ outl %eax, %dx ret ENTRY(set_stack_and_jump) movl 8(%esp), %edx movl 4(%esp), %eax movl %eax, %esp movl $0, %ebp jmp *%edx /* never returns */ /* ~~~~~~~~~~ system_time - return the number of usec since <whenever> -- INTEGER version entry: <ret> exit: [%edx,%eax] = time ~~~~~ */ ENTRY(system_time) /* load 64-bit factor into %eax (low), %edx (high) */ /* hand-assemble rdtsc -- read time stamp counter */ rdtsc /* time in %edx,%eax */ /* This tail code is common to this and previous routine. */ system_time_common: pushl %ebx pushl %ecx movl EXTERN(cv_factor), %ebx movl %edx, %ecx /* save high half */ mull %ebx /* truncate %eax, but keep %edx */ movl %ecx, %eax movl %edx, %ecx /* save high half of low */ mull %ebx /*, %eax*/ /* now compute [%edx, %eax] + [%ecx], propagating carry */ subl %ebx, %ebx /* need zero to propagate carry */ addl %ecx, %eax adc %ebx, %edx popl %ecx popl %ebx ret |
There are some very nice fonts included in the source tree. Some Truetype fonts. Pity I can not find any wallpapers.
Some source code for the NTFS filesystem support. There is also support for CIFS, Ext2, and CFS. Also iso9660. The Be File System (BFS) is the native file system for the BeOS operating system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | #include "ntfs.h" #include "extent.h" extern int sprintf(char *s, const char *format, ...); uint8 ntfs_debuglevels[] = { 0, // ALL 0, // IO 0, // FILE 0, // DIR 0, // EXTENT 0, // ALLOC 4, // FS 0, // VNODE 0, // ATT 0, // MALLOC 0, // MFT 0, // DIRWALK 0, // RUNLIST 0 // ATTR }; ntfs_fs_struct *create_ntfs_fs_struct() { ntfs_fs_struct *ptr; char text[128]; int i; ptr = ntfs_malloc(sizeof(ntfs_fs_struct)); if(!ptr) { ERRPRINT(("create_ntfs_fs_struct failed to allocate memory for structure.\n")); return NULL; } memset(ptr, 0, sizeof(ntfs_fs_struct)); sprintf(text, "ntfsdirlock 0x%x\n", (unsigned int)ptr); new_lock(&ptr->dir_lock, text); if (ptr->dir_lock.s <= 0) { goto semerror; } set_sem_owner(ptr->dir_lock.s, B_SYSTEM_TEAM); // Set up the decompression buffers for(i=0; i<DECOMPRESSION_BUFFERS; i++) { ptr->dbuf[i].index = i; sprintf(text, "ntfsdbuf%dsem 0x%x\n", i, (unsigned int)ptr); new_lock(&ptr->dbuf[i].buf_lock, text); if (ptr->dbuf[i].buf_lock.s <= 0) { goto semerror; } set_sem_owner(ptr->dbuf[i].buf_lock.s, B_SYSTEM_TEAM); } sprintf(text, "ntfsdbufsem 0x%x\n", (unsigned int)ptr); new_mlock(&ptr->d_buf_mlock, DECOMPRESSION_BUFFERS, text); if (ptr->d_buf_mlock.s <= 0) { goto semerror; } set_sem_owner(ptr->d_buf_mlock.s, B_SYSTEM_TEAM); sprintf(text, "ntfsdsearchsem 0x%x\n", (unsigned int)ptr); new_lock(&ptr->d_search_lock, text); if (ptr->d_search_lock.s <= 0) { goto semerror; } set_sem_owner(ptr->d_search_lock.s, B_SYSTEM_TEAM); return ptr; semerror: remove_ntfs_fs_struct(ptr); return NULL; } status_t remove_ntfs_fs_struct(ntfs_fs_struct *ntfs) { int i; DEBUGPRINT(FS, 5, ("remove_ntfs_fs_struct entry.\n")); if(ntfs->device_name) ntfs_free(ntfs->device_name); ntfs_deallocate_vnode(ntfs->UpCase); ntfs_deallocate_vnode(ntfs->BITMAP); ntfs_deallocate_vnode(ntfs->VOL); ntfs_deallocate_vnode(ntfs->MFT); DEBUGPRINT(FS, 6, ("\tfreeing all decompression buffers...\n")); for(i=0; i<DECOMPRESSION_BUFFERS; i++) { if(ntfs->dbuf[i].buf_lock.s > 0) free_lock(&ntfs->dbuf[i].buf_lock); if(ntfs->dbuf[i].buf) ntfs_free(ntfs->dbuf[i].buf); if(ntfs->dbuf[i].compressed_buf) ntfs_free(ntfs->dbuf[i].compressed_buf); } DEBUGPRINT(FS, 6, ("\tremoving semaphores...\n")); // Remove the semaphores if(ntfs->dir_lock.s > 0) free_lock(&ntfs->dir_lock); if(ntfs->d_buf_mlock.s > 0) free_mlock(&ntfs->d_buf_mlock); if(ntfs->d_search_lock.s > 0) free_lock(&ntfs->d_search_lock); DEBUGPRINT(FS, 6, ("\tdeallocating cache and closing device...\n")); // Deallocate the cache if ((ntfs->cache_initialized)) remove_cached_device_blocks(ntfs->fd, NO_WRITES); // Close the device if(ntfs->fd>0) close(ntfs->fd); ntfs_free(ntfs); DEBUGPRINT(FS, 5, ("remove_ntfs_fs_struct exit.\n")); return B_NO_ERROR; } |
A portion of the Be FS source code, this code is related to mounting filesystems. I wonder if you could even compile the source code tree and get a working version of BeOS today. But I guess everyone uses either Linux or Windows and not alternative operating systems like this. There was a version of Ubuntu once that used the FreeBSD kernel and was using Ubuntu packages, but I wonder what happened to that. Using a UNIX kernel to power an Ubuntu variant would be very interesting. Actually, I found the project, it was called UbuntuBSD but it is dead now. A pity, this would have been very interesting to use. Even more interesting would be using Darwin UNIX and then using apt on top of it. That would be a great operating system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <sys/types.h> #include <time.h> #include <fcntl.h> #include <unistd.h> #include <Errors.h> #include "bfs.h" #include "btlib/btree.h" #ifndef USER #include "bfs_vnops.h" #endif int super_block_is_sane(bfs_info *bfs) { dr9_off_t num_dev_blocks; int block_size; if (bfs->dsb.magic1 != SUPER_BLOCK_MAGIC1 || bfs->dsb.magic2 != SUPER_BLOCK_MAGIC2 || bfs->dsb.magic3 != SUPER_BLOCK_MAGIC3) { printf("warning: super block magic numbers are wrong:\n"); printf("0x%x (0x%x) 0x%x (0x%x) 0x%x (0x%x)\n", bfs->dsb.magic1, SUPER_BLOCK_MAGIC1, bfs->dsb.magic2, SUPER_BLOCK_MAGIC2, bfs->dsb.magic3, SUPER_BLOCK_MAGIC3); return EBADF; } if ((bfs->dsb.block_size % bfs->dev_block_size) != 0) { printf("warning: fs block size %d not a multiple of ", bfs->dsb.block_size); printf(" device block size %d\n", bfs->dev_block_size); return EBADF; } block_size = get_device_block_size(bfs->fd); if (block_size == 0) { printf("warning: could not fetch block size\n"); return EBADF; } /* make sure that the partition is as big as the super block says it is */ num_dev_blocks = get_num_device_blocks(bfs->fd); if (bfs->dsb.num_blocks * bfs->dsb.block_size > num_dev_blocks * block_size) { printf("warning: fs blocks %Lx larger than device blocks %Lx\n", bfs->dsb.num_blocks * (bfs->dsb.block_size/block_size), num_dev_blocks); return B_PARTITION_TOO_SMALL; } if (bfs->dsb.block_size != (1 << bfs->dsb.block_shift)) { int i; printf("warning: block_shift %d does not match block size %d\n", bfs->dsb.block_shift, bfs->dsb.block_size); if (bfs->dsb.block_shift > 8 && bfs->dsb.block_shift < 16) { printf("setting block_size to %d\n", (1 << bfs->dsb.block_shift)); bfs->dsb.block_size = (1 << bfs->dsb.block_shift); } else { for(i=0; i < sizeof(int) * 8; i++) if ((1 << i) == bfs->dsb.block_size) break; if (i >= sizeof(int) * 8 || i > 16) { printf("neither block_size nor block_shift make sense!\n"); return EBADF; } bfs->dsb.block_shift = i; printf("setting block_shift to %d\n", i); } } /* XXXdbg - need more super-block sanity checks here */ return B_OK; } void check_for_vol_id(bfs_info *bfs, bfs_inode *bi) { long long volid; off_t offset = 0; size_t len = sizeof(volid); status_t x; x = internal_read_attr(bfs, bi, "be:volume_id",B_UINT64_TYPE,&volid,&len,0); if (x == ENOENT) { volid = (system_time() + (bi->create_time * 1000000)) ^ bi->create_time; len = sizeof(volid); x = bfs_write_attr(bfs, bi, "be:volume_id", B_UINT64_TYPE, &volid, &len, 0); } } int bfs_mount(nspace_id nsid, const char *device, ulong flags, void *parms, size_t len, void **data, vnode_id *vnid) { int ret = 0, oflags = O_RDWR, is_removable; char buff[128]; bfs_info *bfs; struct stat st; bfs = (bfs_info *)calloc(sizeof(bfs_info), 1); if (bfs == NULL) { printf("no memory for bfs structure!\n"); return ENOMEM; } bfs->nsid = nsid; *data = (void *)bfs; sprintf(buff, "bfs:%s", device); bfs->sem = create_sem(MAX_READERS, buff); if (bfs->sem < 0) { printf("could not create bfs sem!\n"); ret = ENOMEM; goto error0; } if ((flags & B_MOUNT_READ_ONLY) || device_is_read_only(device)) { printf("bfs: %s is read-only!\n", device); oflags = O_RDONLY; bfs->flags |= FS_READ_ONLY; } bfs->fd = open(device, oflags); if (bfs->fd < 0) { printf("could not open %s to try and mount a bfs\n", device); ret = ENODEV; goto error1; } if(oflags != O_RDONLY) { /* check that we can actually write to the device, in case it did not report itself as read-only */ uint8 *bitmap_block; off_t test_pos = 1024; int dev_block_size = get_device_block_size(bfs->fd); if(test_pos < dev_block_size) test_pos = dev_block_size; bitmap_block = malloc(dev_block_size); if(bitmap_block == NULL) { ret = ENOMEM; goto error1_1; } if(read_pos(bfs->fd, test_pos, bitmap_block, dev_block_size) < dev_block_size) { printf("could not read from %s!\n", device); ret = EBADF; free(bitmap_block); goto error1_1; } if(write_pos(bfs->fd, test_pos, bitmap_block, dev_block_size) < dev_block_size) { printf("could not write to %s, mount as read only instead\n", device); oflags = O_RDONLY; bfs->flags |= FS_READ_ONLY; close(bfs->fd); bfs->fd = open(device, oflags); if (bfs->fd < 0) { printf("could not open %s to try and mount a bfs\n", device); ret = ENODEV; free(bitmap_block); goto error1; } } free(bitmap_block); } if (fstat(bfs->fd, &st) < 0) { printf("could not stat %s to determine if it is a device!\n", device); ret = EBADF; goto error1_1; } #if defined(__BEOS__) && !defined(USER) if (S_ISREG(st.st_mode)) { /* it's a reglar file: make access to it uncached! */ if (ioctl(bfs->fd, 10000, NULL) < 0) { printf("bfs mount warning: could not make file access uncached\n"); printf("\tthis could be dangerous...\n"); } } #endif |
Maybe you would be interested in Debian/KFreeBsd (https://www.debian.org/ports/kfreebsd-gnu/index.html)
But, i don’t know is someone use it or not.